Commit a79ab9f9 authored by danakj's avatar danakj Committed by Chromium LUCI CQ

Move RunScriptsAtDocumentStart for the empty document to Dispatcher

Extensions code wants to run scripts on the initial empty document,
so instead of adding a duplicate call to all ContentRendererClients
(both RenderFrameCreated and RunScriptsAtDocumentStart) we can have
the extensions code do the right thing with the RenderFrameCreated
signal.

R=dcheng@chromium.org, reillyg@chromium.org

Bug: 1158869
Change-Id: I11a969e8b84933f13a5ceadb6e6d3943a5fb5d9e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2627690Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Reviewed-by: default avatarShimi Zhang <ctzsm@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#844203}
parent a9ed11b6
...@@ -205,14 +205,6 @@ void AwContentRendererClient::RunScriptsAtDocumentStart( ...@@ -205,14 +205,6 @@ void AwContentRendererClient::RunScriptsAtDocumentStart(
content::RenderFrame* render_frame) { content::RenderFrame* render_frame) {
js_injection::JsCommunication* communication = js_injection::JsCommunication* communication =
js_injection::JsCommunication::Get(render_frame); js_injection::JsCommunication::Get(render_frame);
// We will get RunScriptsAtDocumentStart() event even before we received
// RenderFrameCreated() for that |render_frame|. This is because Blink code
// does initialization work on the main frame, which is not related to any
// real navigation. If the communication is nullptr, it means we haven't
// received RenderFrameCreated() yet, we simply ignore this event for
// JsCommunication since that is not the right time to run the script and
// the script may not reach renderer from browser yet.
if (communication)
communication->RunScriptsAtDocumentStart(); communication->RunScriptsAtDocumentStart();
} }
......
...@@ -2069,9 +2069,6 @@ void RenderFrameImpl::Initialize(blink::WebFrame* parent) { ...@@ -2069,9 +2069,6 @@ void RenderFrameImpl::Initialize(blink::WebFrame* parent) {
// We delay calling this until we have the WebFrame so that any observer or // We delay calling this until we have the WebFrame so that any observer or
// embedder can call GetWebFrame on any RenderFrame. // embedder can call GetWebFrame on any RenderFrame.
GetContentClient()->renderer()->RenderFrameCreated(this); GetContentClient()->renderer()->RenderFrameCreated(this);
// Dispatch events for the initial empty document after all frame observers
// have been created.
RunScriptsAtDocumentElementAvailable();
// blink::WebAudioOutputIPCFactory::io_task_runner_ may be null in tests. // blink::WebAudioOutputIPCFactory::io_task_runner_ may be null in tests.
auto& factory = blink::WebAudioOutputIPCFactory::GetInstance(); auto& factory = blink::WebAudioOutputIPCFactory::GetInstance();
......
...@@ -289,6 +289,11 @@ void Dispatcher::OnRenderThreadStarted(content::RenderThread* thread) { ...@@ -289,6 +289,11 @@ void Dispatcher::OnRenderThreadStarted(content::RenderThread* thread) {
void Dispatcher::OnRenderFrameCreated(content::RenderFrame* render_frame) { void Dispatcher::OnRenderFrameCreated(content::RenderFrame* render_frame) {
script_injection_manager_->OnRenderFrameCreated(render_frame); script_injection_manager_->OnRenderFrameCreated(render_frame);
content_watcher_->OnRenderFrameCreated(render_frame); content_watcher_->OnRenderFrameCreated(render_frame);
// The RenderFrame comes with the initial empty document already created.
DidCreateDocumentElement(render_frame->GetWebFrame());
// We run scripts on the empty document.
RunScriptsAtDocumentStart(render_frame);
} }
bool Dispatcher::IsExtensionActive(const std::string& extension_id) const { bool Dispatcher::IsExtensionActive(const std::string& extension_id) const {
......
...@@ -118,9 +118,6 @@ ExtensionFrameHelper::ExtensionFrameHelper(content::RenderFrame* render_frame, ...@@ -118,9 +118,6 @@ ExtensionFrameHelper::ExtensionFrameHelper(content::RenderFrame* render_frame,
// Manages its own lifetime. // Manages its own lifetime.
new AutomationApiHelper(render_frame); new AutomationApiHelper(render_frame);
} }
// The RenderFrame comes with the initial empty document already created, and
// we want to act on it in the same way as a new document.
DidCreateDocumentElement();
} }
ExtensionFrameHelper::~ExtensionFrameHelper() { ExtensionFrameHelper::~ExtensionFrameHelper() {
......
...@@ -174,10 +174,12 @@ class ExtensionFrameHelper ...@@ -174,10 +174,12 @@ class ExtensionFrameHelper
Dispatcher* extension_dispatcher_; Dispatcher* extension_dispatcher_;
// Whether or not the current document element has been created. // Whether or not the current document element has been created. This starts
// true as the initial empty document is already created when this class is
// instantiated.
// TODO(danakj): Does this still need to be tracked? We now have consisitent // TODO(danakj): Does this still need to be tracked? We now have consisitent
// notifications for initial empty documents on all frames. // notifications for initial empty documents on all frames.
bool did_create_current_document_element_ = false; bool did_create_current_document_element_ = true;
// Callbacks to be run at the next RunScriptsAtDocumentStart notification. // Callbacks to be run at the next RunScriptsAtDocumentStart notification.
std::vector<base::OnceClosure> document_element_created_callbacks_; std::vector<base::OnceClosure> document_element_created_callbacks_;
......
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