Commit 4882fea9 authored by Wez's avatar Wez Committed by Commit Bot

[fuchsia] Do not perform API bindings cleanup if Frame is being torn down.

Bug: 1095791, b/152620196
Change-Id: I2f8fc8151d20c1962d311806fb48a87e7dbd144c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2252047
Commit-Queue: Kevin Marshall <kmarshall@chromium.org>
Reviewed-by: default avatarKevin Marshall <kmarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#781974}
parent 49dd1deb
......@@ -33,11 +33,14 @@ ApiBindingsClient::ApiBindingsClient(
});
}
void ApiBindingsClient::OnBindingsReceived(
std::vector<chromium::cast::ApiBinding> bindings) {
bindings_ = std::move(bindings);
bindings_service_.set_error_handler(nullptr);
std::move(on_initialization_complete_).Run();
ApiBindingsClient::~ApiBindingsClient() {
if (connector_ && frame_) {
connector_->Register({});
// Remove all injected scripts using their automatically enumerated IDs.
for (uint64_t i = 0; i < bindings_->size(); ++i)
frame_->RemoveBeforeLoadJavaScript(kBindingsIdStart + i);
}
}
void ApiBindingsClient::AttachToFrame(fuchsia::web::Frame* frame,
......@@ -74,14 +77,14 @@ void ApiBindingsClient::AttachToFrame(fuchsia::web::Frame* frame,
}
}
ApiBindingsClient::~ApiBindingsClient() {
if (connector_ && frame_) {
connector_->Register({});
void ApiBindingsClient::DetachFromFrame(fuchsia::web::Frame* frame) {
DCHECK_EQ(frame, frame_);
frame_ = nullptr;
bindings_service_.set_error_handler(nullptr);
}
// Remove all injected scripts using their automatically enumerated IDs.
for (uint64_t i = 0; i < bindings_->size(); ++i)
frame_->RemoveBeforeLoadJavaScript(kBindingsIdStart + i);
}
bool ApiBindingsClient::HasBindings() const {
return bindings_.has_value();
}
void ApiBindingsClient::OnPortConnected(
......@@ -91,6 +94,9 @@ void ApiBindingsClient::OnPortConnected(
bindings_service_->Connect(port_name.as_string(), std::move(port));
}
bool ApiBindingsClient::HasBindings() const {
return bindings_.has_value();
void ApiBindingsClient::OnBindingsReceived(
std::vector<chromium::cast::ApiBinding> bindings) {
bindings_ = std::move(bindings);
bindings_service_.set_error_handler(nullptr);
std::move(on_initialization_complete_).Run();
}
......@@ -34,6 +34,10 @@ class ApiBindingsClient {
NamedMessagePortConnector* connector,
base::OnceClosure on_error_callback);
// Indicates that the Frame is no longer live, preventing the API bindings
// client from attempting to remove injected bindings from it.
void DetachFromFrame(fuchsia::web::Frame* frame);
// Indicates that bindings were successfully received from
// |bindings_service_|.
bool HasBindings() const;
......
......@@ -163,6 +163,10 @@ void CastComponent::DestroyComponent(int64_t exit_code,
application_context_->OnApplicationExit(exit_code);
}
// frame() is about to be destroyed, so there is no need to perform cleanup
// such as removing before-load JavaScripts.
api_bindings_client_->DetachFromFrame(frame());
WebComponent::DestroyComponent(exit_code, reason);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment