refactor: saner blink_initialization_order.patch (#22054)

This commit is contained in:
Jeremy Apthorp 2020-02-07 09:45:13 -08:00 committed by GitHub
parent 6a7d722c06
commit e2a5de9248
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 141 additions and 32 deletions

View file

@ -35,7 +35,7 @@ mas_disable_remote_accessibility.patch
mas_disable_custom_window_frame.patch
chrome_key_systems.patch
allow_nested_error_trackers.patch
blink_initialization_order.patch
add_didinstallconditionalfeatures.patch
ssl_security_state_tab_helper.patch
desktop_media_list.patch
proxy_config_monitor.patch

View file

@ -0,0 +1,137 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jeremy Apthorp <nornagon@nornagon.net>
Date: Wed, 15 Jan 2020 16:35:18 -0800
Subject: add DidInstallConditionalFeatures
This adds a hook on script context creation _after conditional features
have been installed_. Electron uses this to run preload scripts and
various other initialization. This is necessary because at the time
DidCreateScriptContext is called, not all JS APIs are available in the
context, which can cause some preload scripts to trip.
diff --git a/content/public/renderer/render_frame_observer.h b/content/public/renderer/render_frame_observer.h
index 68654a3e7d5ec6caddccb667f9f8fa2feabfa71b..650ce53e112bd65e1901a09480452855a0c16dda 100644
--- a/content/public/renderer/render_frame_observer.h
+++ b/content/public/renderer/render_frame_observer.h
@@ -115,6 +115,8 @@ class CONTENT_EXPORT RenderFrameObserver : public IPC::Listener,
virtual void DidHandleOnloadEvents() {}
virtual void DidCreateScriptContext(v8::Local<v8::Context> context,
int32_t world_id) {}
+ virtual void DidInstallConditionalFeatures(v8::Local<v8::Context> context,
+ int32_t world_id) {}
virtual void WillReleaseScriptContext(v8::Local<v8::Context> context,
int32_t world_id) {}
virtual void DidClearWindowObject() {}
diff --git a/content/renderer/render_frame_impl.cc b/content/renderer/render_frame_impl.cc
index 6730d6f6eb8448452991ebf5968a8c5a398b6a88..b87f9c7ac0f31ec33f03c36131c3255c8a31c22c 100644
--- a/content/renderer/render_frame_impl.cc
+++ b/content/renderer/render_frame_impl.cc
@@ -5187,6 +5187,12 @@ void RenderFrameImpl::DidCreateScriptContext(v8::Local<v8::Context> context,
observer.DidCreateScriptContext(context, world_id);
}
+void RenderFrameImpl::DidInstallConditionalFeatures(
+ v8::Local<v8::Context> context, int world_id) {
+ for (auto& observer : observers_)
+ observer.DidInstallConditionalFeatures(context, world_id);
+}
+
void RenderFrameImpl::WillReleaseScriptContext(v8::Local<v8::Context> context,
int world_id) {
for (auto& observer : observers_)
diff --git a/content/renderer/render_frame_impl.h b/content/renderer/render_frame_impl.h
index bc896201057832415b5d54dc8987bb74bf7aa778..5c96af71646722b1108a8d6eafba1adaddf0a05a 100644
--- a/content/renderer/render_frame_impl.h
+++ b/content/renderer/render_frame_impl.h
@@ -773,6 +773,8 @@ class CONTENT_EXPORT RenderFrameImpl
bool ShouldTrackUseCounter(const blink::WebURL& url) override;
void DidCreateScriptContext(v8::Local<v8::Context> context,
int world_id) override;
+ void DidInstallConditionalFeatures(v8::Local<v8::Context> context,
+ int world_id) override;
void WillReleaseScriptContext(v8::Local<v8::Context> context,
int world_id) override;
void DidChangeScrollOffset() override;
diff --git a/third_party/blink/public/web/web_local_frame_client.h b/third_party/blink/public/web/web_local_frame_client.h
index 30638c31e30d98bb23292115b25b528ff8e8f62c..e0f2f786b75f861851d1194f57b253a173053299 100644
--- a/third_party/blink/public/web/web_local_frame_client.h
+++ b/third_party/blink/public/web/web_local_frame_client.h
@@ -652,6 +652,9 @@ class BLINK_EXPORT WebLocalFrameClient {
virtual void DidCreateScriptContext(v8::Local<v8::Context>,
int32_t world_id) {}
+ virtual void DidInstallConditionalFeatures(v8::Local<v8::Context>,
+ int32_t world_id) {}
+
// WebKit is about to release its reference to a v8 context for a frame.
virtual void WillReleaseScriptContext(v8::Local<v8::Context>,
int32_t world_id) {}
diff --git a/third_party/blink/renderer/bindings/core/v8/local_window_proxy.cc b/third_party/blink/renderer/bindings/core/v8/local_window_proxy.cc
index 8095edd988c171a8ad7382d1c2f9fa63ee9e5ffc..510dae593d2a0e2ce13a2879dde5c31e01d21c21 100644
--- a/third_party/blink/renderer/bindings/core/v8/local_window_proxy.cc
+++ b/third_party/blink/renderer/bindings/core/v8/local_window_proxy.cc
@@ -231,6 +231,7 @@ void LocalWindowProxy::Initialize() {
}
InstallConditionalFeatures();
+ GetFrame()->Client()->DidInstallConditionalFeatures(context, world_->GetWorldId());
if (World().IsMainWorld()) {
GetFrame()->Loader().DispatchDidClearWindowObjectInMainWorld();
diff --git a/third_party/blink/renderer/core/exported/local_frame_client_impl.cc b/third_party/blink/renderer/core/exported/local_frame_client_impl.cc
index f8c512c9db0b88904a562b7d4195790d4b0f86a6..d31ef9bd5b98f584a3296638662ae0d27aa37b65 100644
--- a/third_party/blink/renderer/core/exported/local_frame_client_impl.cc
+++ b/third_party/blink/renderer/core/exported/local_frame_client_impl.cc
@@ -267,6 +267,13 @@ void LocalFrameClientImpl::DidCreateScriptContext(
web_frame_->Client()->DidCreateScriptContext(context, world_id);
}
+void LocalFrameClientImpl::DidInstallConditionalFeatures(
+ v8::Local<v8::Context> context,
+ int32_t world_id) {
+ if (web_frame_->Client())
+ web_frame_->Client()->DidInstallConditionalFeatures(context, world_id);
+}
+
void LocalFrameClientImpl::WillReleaseScriptContext(
v8::Local<v8::Context> context,
int32_t world_id) {
diff --git a/third_party/blink/renderer/core/exported/local_frame_client_impl.h b/third_party/blink/renderer/core/exported/local_frame_client_impl.h
index a055f4b0cc1ccc30752b65d6dc54e638e9b63001..0e6501adbf6f9696429c3fa95357de399ee30a9d 100644
--- a/third_party/blink/renderer/core/exported/local_frame_client_impl.h
+++ b/third_party/blink/renderer/core/exported/local_frame_client_impl.h
@@ -79,6 +79,8 @@ class LocalFrameClientImpl final : public LocalFrameClient {
void DidCreateScriptContext(v8::Local<v8::Context>,
int32_t world_id) override;
+ void DidInstallConditionalFeatures(v8::Local<v8::Context>,
+ int32_t world_id) override;
void WillReleaseScriptContext(v8::Local<v8::Context>,
int32_t world_id) override;
diff --git a/third_party/blink/renderer/core/frame/local_frame_client.h b/third_party/blink/renderer/core/frame/local_frame_client.h
index 1d6facb9ec63abebc5b79a57860765bc8b3f6638..0b58cb679ed34c54e39af661d4a432d482db8c3c 100644
--- a/third_party/blink/renderer/core/frame/local_frame_client.h
+++ b/third_party/blink/renderer/core/frame/local_frame_client.h
@@ -303,6 +303,8 @@ class CORE_EXPORT LocalFrameClient : public FrameClient {
virtual void DidCreateScriptContext(v8::Local<v8::Context>,
int32_t world_id) = 0;
+ virtual void DidInstallConditionalFeatures(v8::Local<v8::Context>,
+ int32_t world_id) = 0;
virtual void WillReleaseScriptContext(v8::Local<v8::Context>,
int32_t world_id) = 0;
virtual bool AllowScriptExtensions() = 0;
diff --git a/third_party/blink/renderer/core/loader/empty_clients.h b/third_party/blink/renderer/core/loader/empty_clients.h
index f3f00e7d6ac44d77dd75997abf8b93eb59476eb3..2010792697b3443dd6f5058bed5ccd0026c4a152 100644
--- a/third_party/blink/renderer/core/loader/empty_clients.h
+++ b/third_party/blink/renderer/core/loader/empty_clients.h
@@ -370,6 +370,8 @@ class CORE_EXPORT EmptyLocalFrameClient : public LocalFrameClient {
void DidCreateScriptContext(v8::Local<v8::Context>,
int32_t world_id) override {}
+ void DidInstallConditionalFeatures(v8::Local<v8::Context>,
+ int32_t world_id) override {}
void WillReleaseScriptContext(v8::Local<v8::Context>,
int32_t world_id) override {}
bool AllowScriptExtensions() override { return false; }

View file

@ -1,28 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samuel Attard <samuel.r.attard@gmail.com>
Date: Thu, 20 Sep 2018 17:50:24 -0700
Subject: blink_initialization_order.patch
Backport of https://chromium-review.googlesource.com/c/chromium/src/+/1030530
to fix the order of V8 and Blink initialization. Also fixes order
of DidCreateScriptContext notification with initialization of window globals
to fix electron/electron#13787. The backport landed in Chromium 67 but the
DidCreateScriptContext re-ordering needs to be upstreamed or kept indefinitely
diff --git a/third_party/blink/renderer/bindings/core/v8/local_window_proxy.cc b/third_party/blink/renderer/bindings/core/v8/local_window_proxy.cc
index c845acb8321e94c916798826a168e06df34ffff4..941ca9d3905c0c2f36606655bf60e9e9bd1f9196 100644
--- a/third_party/blink/renderer/bindings/core/v8/local_window_proxy.cc
+++ b/third_party/blink/renderer/bindings/core/v8/local_window_proxy.cc
@@ -211,11 +211,10 @@ void LocalWindowProxy::Initialize() {
GetFrame()->IsMainFrame());
MainThreadDebugger::Instance()->ContextCreated(script_state_, GetFrame(),
origin);
+ InstallConditionalFeatures();
GetFrame()->Client()->DidCreateScriptContext(context, world_->GetWorldId());
}
- InstallConditionalFeatures();
-
if (World().IsMainWorld()) {
GetFrame()->Loader().DispatchDidClearWindowObjectInMainWorld();
}

View file

@ -57,7 +57,7 @@ void ElectronRenderFrameObserver::DidClearWindowObject() {
renderer_client_->DidClearWindowObject(render_frame_);
}
void ElectronRenderFrameObserver::DidCreateScriptContext(
void ElectronRenderFrameObserver::DidInstallConditionalFeatures(
v8::Handle<v8::Context> context,
int world_id) {
if (ShouldNotifyClient(world_id))

View file

@ -45,8 +45,8 @@ class ElectronRenderFrameObserver : public content::RenderFrameObserver {
// content::RenderFrameObserver:
void DidClearWindowObject() override;
void DidCreateScriptContext(v8::Handle<v8::Context> context,
int world_id) override;
void DidInstallConditionalFeatures(v8::Handle<v8::Context> context,
int world_id) override;
void DraggableRegionsChanged() override;
void WillReleaseScriptContext(v8::Local<v8::Context> context,
int world_id) override;