39baf68790
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com> Co-authored-by: loc <andy@slack-corp.com> Co-authored-by: Robo <hop2deep@gmail.com> Co-authored-by: Jeremy Apthorp <nornagon@nornagon.net>
137 lines
7.9 KiB
Diff
137 lines
7.9 KiB
Diff
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 156ba739a984347135857f8019fda0bfb01c97ad..f4093e9bb8b54d82c6d70375977c0ad91dc90580 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 faa3a77cb545114d9fd8f772d869ba822ad72386..61db7a2e08d5b88587fcd6a0d9ee43027a3f2bf6 100644
|
|
--- a/content/renderer/render_frame_impl.cc
|
|
+++ b/content/renderer/render_frame_impl.cc
|
|
@@ -4919,6 +4919,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 57092be996f10ca650cd291be30b45a2a950d159..1c60c1f7075c622137ab2847c8166fb466be8533 100644
|
|
--- a/content/renderer/render_frame_impl.h
|
|
+++ b/content/renderer/render_frame_impl.h
|
|
@@ -748,6 +748,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 643b63d2ed90362ed615d8003ac02bbba606c5ef..b33fcc64464d5d57177794146854abf6dea627b1 100644
|
|
--- a/third_party/blink/public/web/web_local_frame_client.h
|
|
+++ b/third_party/blink/public/web/web_local_frame_client.h
|
|
@@ -555,6 +555,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 d20d24c0ba6025af06f5f61cefd3e96e687c123d..c6cb7af9c2ec7e812954b7725f8506c1d9d115de 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
|
|
@@ -215,6 +215,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 40422650f8bc6b23d92ac670322585441a147446..e0a3f69ca2a19fdb5860ab6a0d2d4a978d5b699f 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
|
|
@@ -348,6 +348,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 835b91bc46f1b2b0d0d4dbfafaa42c1ce9d6a6ca..b067640f61ed836db62d30b05f379f4aa0b93f82 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
|
|
@@ -80,6 +80,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 c30c58b1ff71cb3a80412143c55e2e67f2ab43ec..f7089b126b5aa35bcc65a6312ed21075c916781c 100644
|
|
--- a/third_party/blink/renderer/core/frame/local_frame_client.h
|
|
+++ b/third_party/blink/renderer/core/frame/local_frame_client.h
|
|
@@ -289,6 +289,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 6d5be783ec5d25efca2aef1c5da48c0cc4704a28..f8c268110047520a03ca78ab5efb8d82ee4e7bdc 100644
|
|
--- a/third_party/blink/renderer/core/loader/empty_clients.h
|
|
+++ b/third_party/blink/renderer/core/loader/empty_clients.h
|
|
@@ -364,6 +364,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; }
|