123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
- From: Jeremy Apthorp <[email protected]>
- 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 3e059605c55d88d52cf2544d6aca3446efee5750..398229becb8fd00022b08cc6afed7d1875766e25 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 c9e8e396135befdd67549326daa2ef5c2339f418..1df3376ca5a8fefc926634c197a8bf043a4f3897 100644
- --- a/content/renderer/render_frame_impl.cc
- +++ b/content/renderer/render_frame_impl.cc
- @@ -4796,6 +4796,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 eeac74bc62d6c276d31f714e5a1a024c9ec02838..cf6cfe870b63d675e16fc0e8b80914e19c796ae6 100644
- --- a/content/renderer/render_frame_impl.h
- +++ b/content/renderer/render_frame_impl.h
- @@ -738,6 +738,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 54a40d9a90d1dbb13d8234494ab53893ca339ee4..aee9160cba302b394594debfbc8dd0e400efbb46 100644
- --- a/third_party/blink/public/web/web_local_frame_client.h
- +++ b/third_party/blink/public/web/web_local_frame_client.h
- @@ -546,6 +546,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 17ebe5efb8b0bfcf17eda69fe4373b61b213af72..b7296a900c04006812d5f01b05c46a223fb40dc2 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
- @@ -201,6 +201,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 c586e0f7c21060f5f6a088631b5b0b9d57fad4eb..fc0fc331ecd535422eeb15bd831d64946edff3b2 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
- @@ -391,6 +391,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 b21e7f5ba906d13045f38f986677106d35cc1d60..024188a4365261ba47ac200d15d8c0e52eb80a90 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
- @@ -78,6 +78,8 @@ class CORE_EXPORT 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 4c6f1b9decbc5292d8349816fbac88dfd22b4774..ab28222f6be19cfc78c410633d20dc8646f98a2c 100644
- --- a/third_party/blink/renderer/core/frame/local_frame_client.h
- +++ b/third_party/blink/renderer/core/frame/local_frame_client.h
- @@ -296,6 +296,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 006c575be0f9a33b0a5833b2d5d7bca6ca7fe2b0..d21901198b3b118b153ae2f77d071775c08574d4 100644
- --- a/third_party/blink/renderer/core/loader/empty_clients.h
- +++ b/third_party/blink/renderer/core/loader/empty_clients.h
- @@ -336,6 +336,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; }
|