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( ...@@ -33,11 +33,14 @@ ApiBindingsClient::ApiBindingsClient(
}); });
} }
void ApiBindingsClient::OnBindingsReceived( ApiBindingsClient::~ApiBindingsClient() {
std::vector<chromium::cast::ApiBinding> bindings) { if (connector_ && frame_) {
bindings_ = std::move(bindings); connector_->Register({});
bindings_service_.set_error_handler(nullptr);
std::move(on_initialization_complete_).Run(); // 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, void ApiBindingsClient::AttachToFrame(fuchsia::web::Frame* frame,
...@@ -74,14 +77,14 @@ void ApiBindingsClient::AttachToFrame(fuchsia::web::Frame* frame, ...@@ -74,14 +77,14 @@ void ApiBindingsClient::AttachToFrame(fuchsia::web::Frame* frame,
} }
} }
ApiBindingsClient::~ApiBindingsClient() { void ApiBindingsClient::DetachFromFrame(fuchsia::web::Frame* frame) {
if (connector_ && frame_) { DCHECK_EQ(frame, frame_);
connector_->Register({}); frame_ = nullptr;
bindings_service_.set_error_handler(nullptr);
}
// Remove all injected scripts using their automatically enumerated IDs. bool ApiBindingsClient::HasBindings() const {
for (uint64_t i = 0; i < bindings_->size(); ++i) return bindings_.has_value();
frame_->RemoveBeforeLoadJavaScript(kBindingsIdStart + i);
}
} }
void ApiBindingsClient::OnPortConnected( void ApiBindingsClient::OnPortConnected(
...@@ -91,6 +94,9 @@ void ApiBindingsClient::OnPortConnected( ...@@ -91,6 +94,9 @@ void ApiBindingsClient::OnPortConnected(
bindings_service_->Connect(port_name.as_string(), std::move(port)); bindings_service_->Connect(port_name.as_string(), std::move(port));
} }
bool ApiBindingsClient::HasBindings() const { void ApiBindingsClient::OnBindingsReceived(
return bindings_.has_value(); 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 { ...@@ -34,6 +34,10 @@ class ApiBindingsClient {
NamedMessagePortConnector* connector, NamedMessagePortConnector* connector,
base::OnceClosure on_error_callback); 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 // Indicates that bindings were successfully received from
// |bindings_service_|. // |bindings_service_|.
bool HasBindings() const; bool HasBindings() const;
......
...@@ -163,6 +163,10 @@ void CastComponent::DestroyComponent(int64_t exit_code, ...@@ -163,6 +163,10 @@ void CastComponent::DestroyComponent(int64_t exit_code,
application_context_->OnApplicationExit(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); 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