| 
									
										
										
										
											2020-02-07 09:45:13 -08:00
										 |  |  | 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
 | 
					
						
							| 
									
										
										
										
											2023-04-12 07:37:48 -04:00
										 |  |  | index fef4c8e02067c44ed804c8b53db1007fae2d2a76..b36304ee0a832c5e1e2fd3af6151b7b03fd98ec4 100644
 | 
					
						
							| 
									
										
										
										
											2020-02-07 09:45:13 -08:00
										 |  |  | --- a/content/public/renderer/render_frame_observer.h
 | 
					
						
							|  |  |  | +++ b/content/public/renderer/render_frame_observer.h
 | 
					
						
							| 
									
										
										
										
											2023-04-12 07:37:48 -04:00
										 |  |  | @@ -137,6 +137,8 @@ class CONTENT_EXPORT RenderFrameObserver : public IPC::Listener,
 | 
					
						
							| 
									
										
										
										
											2020-02-07 09:45:13 -08:00
										 |  |  |    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
 | 
					
						
							| 
									
										
										
										
											2023-04-12 07:37:48 -04:00
										 |  |  | index f45f542fa3131036624686cd33a90097e6400ff5..0bdf1012eea9d754e03d9b6d9f05a1939502e6b1 100644
 | 
					
						
							| 
									
										
										
										
											2020-02-07 09:45:13 -08:00
										 |  |  | --- a/content/renderer/render_frame_impl.cc
 | 
					
						
							|  |  |  | +++ b/content/renderer/render_frame_impl.cc
 | 
					
						
							| 
									
										
										
										
											2023-04-12 07:37:48 -04:00
										 |  |  | @@ -4418,6 +4418,12 @@ void RenderFrameImpl::DidCreateScriptContext(v8::Local<v8::Context> context,
 | 
					
						
							| 
									
										
										
										
											2020-02-07 09:45:13 -08:00
										 |  |  |      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
 | 
					
						
							| 
									
										
										
										
											2023-04-12 07:37:48 -04:00
										 |  |  | index 39119f060d6f8bd1707cf9122708e3571d52ecb8..4b501e4602cd3f39e8e26f839f3cc77832ff690c 100644
 | 
					
						
							| 
									
										
										
										
											2020-02-07 09:45:13 -08:00
										 |  |  | --- a/content/renderer/render_frame_impl.h
 | 
					
						
							|  |  |  | +++ b/content/renderer/render_frame_impl.h
 | 
					
						
							| 
									
										
										
										
											2023-04-12 07:37:48 -04:00
										 |  |  | @@ -608,6 +608,8 @@ class CONTENT_EXPORT RenderFrameImpl
 | 
					
						
							| 
									
										
										
										
											2023-01-05 21:35:34 -05:00
										 |  |  |    void DidObserveLayoutShift(double score, bool after_input_or_scroll) override; | 
					
						
							| 
									
										
										
										
											2020-02-07 09:45:13 -08:00
										 |  |  |    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
 | 
					
						
							| 
									
										
										
										
											2023-04-12 07:37:48 -04:00
										 |  |  | index dfd33eede0a8b0935a06eeb8f505a8d0738afa19..06827403830cb730b2521c715ec06aedbf7339c6 100644
 | 
					
						
							| 
									
										
										
										
											2020-02-07 09:45:13 -08:00
										 |  |  | --- a/third_party/blink/public/web/web_local_frame_client.h
 | 
					
						
							|  |  |  | +++ b/third_party/blink/public/web/web_local_frame_client.h
 | 
					
						
							| 
									
										
										
										
											2023-04-12 07:37:48 -04:00
										 |  |  | @@ -606,6 +606,9 @@ class BLINK_EXPORT WebLocalFrameClient {
 | 
					
						
							| 
									
										
										
										
											2020-02-07 09:45:13 -08:00
										 |  |  |    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
 | 
					
						
							| 
									
										
										
										
											2023-03-10 10:07:42 -06:00
										 |  |  | index e7d4256fa96f5bc8ad71bd13b6b33feef32b443f..0dfeda68a4dbfd6b442f8d8f928c8cb871dd6aa4 100644
 | 
					
						
							| 
									
										
										
										
											2020-02-07 09:45:13 -08:00
										 |  |  | --- a/third_party/blink/renderer/bindings/core/v8/local_window_proxy.cc
 | 
					
						
							|  |  |  | +++ b/third_party/blink/renderer/bindings/core/v8/local_window_proxy.cc
 | 
					
						
							| 
									
										
										
										
											2023-03-10 10:07:42 -06:00
										 |  |  | @@ -198,6 +198,7 @@ void LocalWindowProxy::Initialize() {
 | 
					
						
							| 
									
										
										
										
											2020-02-07 09:45:13 -08:00
										 |  |  |    } | 
					
						
							|  |  |  |   | 
					
						
							|  |  |  |    InstallConditionalFeatures(); | 
					
						
							|  |  |  | +  GetFrame()->Client()->DidInstallConditionalFeatures(context, world_->GetWorldId());
 | 
					
						
							|  |  |  |   | 
					
						
							|  |  |  |    if (World().IsMainWorld()) { | 
					
						
							| 
									
										
										
										
											2023-03-10 10:07:42 -06:00
										 |  |  |      probe::DidCreateMainWorldContext(GetFrame()); | 
					
						
							| 
									
										
										
										
											2020-10-27 17:33:04 -07:00
										 |  |  | diff --git a/third_party/blink/renderer/core/frame/local_frame_client.h b/third_party/blink/renderer/core/frame/local_frame_client.h
 | 
					
						
							| 
									
										
										
										
											2023-04-12 07:37:48 -04:00
										 |  |  | index 2c526726ff1ed7008152086210b25103ce308d5b..c62ab44289bf32ac9d40d3df45f6363409f0dea9 100644
 | 
					
						
							| 
									
										
										
										
											2020-10-27 17:33:04 -07:00
										 |  |  | --- a/third_party/blink/renderer/core/frame/local_frame_client.h
 | 
					
						
							|  |  |  | +++ b/third_party/blink/renderer/core/frame/local_frame_client.h
 | 
					
						
							| 
									
										
										
										
											2023-04-12 07:37:48 -04:00
										 |  |  | @@ -315,6 +315,8 @@ class CORE_EXPORT LocalFrameClient : public FrameClient {
 | 
					
						
							| 
									
										
										
										
											2020-10-27 17:33:04 -07:00
										 |  |  |   | 
					
						
							|  |  |  |    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/frame/local_frame_client_impl.cc b/third_party/blink/renderer/core/frame/local_frame_client_impl.cc
 | 
					
						
							| 
									
										
										
										
											2023-04-12 07:37:48 -04:00
										 |  |  | index 56ad2a8f3fabe03b2c285231d0e99dbcbaf2a9d2..130423e45f17998bf5a28c719115715941ae6620 100644
 | 
					
						
							| 
									
										
										
										
											2020-10-27 17:33:04 -07:00
										 |  |  | --- a/third_party/blink/renderer/core/frame/local_frame_client_impl.cc
 | 
					
						
							|  |  |  | +++ b/third_party/blink/renderer/core/frame/local_frame_client_impl.cc
 | 
					
						
							| 
									
										
										
										
											2023-01-05 21:35:34 -05:00
										 |  |  | @@ -283,6 +283,13 @@ void LocalFrameClientImpl::DidCreateScriptContext(
 | 
					
						
							| 
									
										
										
										
											2020-02-07 09:45:13 -08:00
										 |  |  |      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) { | 
					
						
							| 
									
										
										
										
											2020-10-27 17:33:04 -07:00
										 |  |  | diff --git a/third_party/blink/renderer/core/frame/local_frame_client_impl.h b/third_party/blink/renderer/core/frame/local_frame_client_impl.h
 | 
					
						
							| 
									
										
										
										
											2023-04-12 07:37:48 -04:00
										 |  |  | index cd3cc4ea62f8956b87c711362520308f062de76e..75dd52f5eb3e6a06cd6185d590ba20e17b7e4e1d 100644
 | 
					
						
							| 
									
										
										
										
											2020-10-27 17:33:04 -07:00
										 |  |  | --- a/third_party/blink/renderer/core/frame/local_frame_client_impl.h
 | 
					
						
							|  |  |  | +++ b/third_party/blink/renderer/core/frame/local_frame_client_impl.h
 | 
					
						
							| 
									
										
										
										
											2023-04-12 07:37:48 -04:00
										 |  |  | @@ -83,6 +83,8 @@ class CORE_EXPORT LocalFrameClientImpl final : public LocalFrameClient {
 | 
					
						
							| 
									
										
										
										
											2020-02-07 09:45:13 -08:00
										 |  |  |   | 
					
						
							|  |  |  |    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/loader/empty_clients.h b/third_party/blink/renderer/core/loader/empty_clients.h
 | 
					
						
							| 
									
										
										
										
											2023-03-30 22:03:58 -04:00
										 |  |  | index ca0c223d248a2ae247429059be8a6a139006e55b..20439262e08e74318035460a0f92c981fa6758e1 100644
 | 
					
						
							| 
									
										
										
										
											2020-02-07 09:45:13 -08:00
										 |  |  | --- a/third_party/blink/renderer/core/loader/empty_clients.h
 | 
					
						
							|  |  |  | +++ b/third_party/blink/renderer/core/loader/empty_clients.h
 | 
					
						
							| 
									
										
										
										
											2023-03-30 22:03:58 -04:00
										 |  |  | @@ -405,6 +405,8 @@ class CORE_EXPORT EmptyLocalFrameClient : public LocalFrameClient {
 | 
					
						
							| 
									
										
										
										
											2020-02-07 09:45:13 -08:00
										 |  |  |   | 
					
						
							|  |  |  |    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; } |