add_didinstallconditionalfeatures.patch 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Jeremy Apthorp <[email protected]>
  3. Date: Wed, 15 Jan 2020 16:35:18 -0800
  4. Subject: add DidInstallConditionalFeatures
  5. This adds a hook on script context creation _after conditional features
  6. have been installed_. Electron uses this to run preload scripts and
  7. various other initialization. This is necessary because at the time
  8. DidCreateScriptContext is called, not all JS APIs are available in the
  9. context, which can cause some preload scripts to trip.
  10. diff --git a/content/public/renderer/render_frame_observer.h b/content/public/renderer/render_frame_observer.h
  11. index 3e059605c55d88d52cf2544d6aca3446efee5750..398229becb8fd00022b08cc6afed7d1875766e25 100644
  12. --- a/content/public/renderer/render_frame_observer.h
  13. +++ b/content/public/renderer/render_frame_observer.h
  14. @@ -115,6 +115,8 @@ class CONTENT_EXPORT RenderFrameObserver : public IPC::Listener,
  15. virtual void DidHandleOnloadEvents() {}
  16. virtual void DidCreateScriptContext(v8::Local<v8::Context> context,
  17. int32_t world_id) {}
  18. + virtual void DidInstallConditionalFeatures(v8::Local<v8::Context> context,
  19. + int32_t world_id) {}
  20. virtual void WillReleaseScriptContext(v8::Local<v8::Context> context,
  21. int32_t world_id) {}
  22. virtual void DidClearWindowObject() {}
  23. diff --git a/content/renderer/render_frame_impl.cc b/content/renderer/render_frame_impl.cc
  24. index c9e8e396135befdd67549326daa2ef5c2339f418..1df3376ca5a8fefc926634c197a8bf043a4f3897 100644
  25. --- a/content/renderer/render_frame_impl.cc
  26. +++ b/content/renderer/render_frame_impl.cc
  27. @@ -4796,6 +4796,12 @@ void RenderFrameImpl::DidCreateScriptContext(v8::Local<v8::Context> context,
  28. observer.DidCreateScriptContext(context, world_id);
  29. }
  30. +void RenderFrameImpl::DidInstallConditionalFeatures(
  31. + v8::Local<v8::Context> context, int world_id) {
  32. + for (auto& observer : observers_)
  33. + observer.DidInstallConditionalFeatures(context, world_id);
  34. +}
  35. +
  36. void RenderFrameImpl::WillReleaseScriptContext(v8::Local<v8::Context> context,
  37. int world_id) {
  38. for (auto& observer : observers_)
  39. diff --git a/content/renderer/render_frame_impl.h b/content/renderer/render_frame_impl.h
  40. index eeac74bc62d6c276d31f714e5a1a024c9ec02838..cf6cfe870b63d675e16fc0e8b80914e19c796ae6 100644
  41. --- a/content/renderer/render_frame_impl.h
  42. +++ b/content/renderer/render_frame_impl.h
  43. @@ -738,6 +738,8 @@ class CONTENT_EXPORT RenderFrameImpl
  44. bool ShouldTrackUseCounter(const blink::WebURL& url) override;
  45. void DidCreateScriptContext(v8::Local<v8::Context> context,
  46. int world_id) override;
  47. + void DidInstallConditionalFeatures(v8::Local<v8::Context> context,
  48. + int world_id) override;
  49. void WillReleaseScriptContext(v8::Local<v8::Context> context,
  50. int world_id) override;
  51. void DidChangeScrollOffset() override;
  52. diff --git a/third_party/blink/public/web/web_local_frame_client.h b/third_party/blink/public/web/web_local_frame_client.h
  53. index 54a40d9a90d1dbb13d8234494ab53893ca339ee4..aee9160cba302b394594debfbc8dd0e400efbb46 100644
  54. --- a/third_party/blink/public/web/web_local_frame_client.h
  55. +++ b/third_party/blink/public/web/web_local_frame_client.h
  56. @@ -546,6 +546,9 @@ class BLINK_EXPORT WebLocalFrameClient {
  57. virtual void DidCreateScriptContext(v8::Local<v8::Context>,
  58. int32_t world_id) {}
  59. + virtual void DidInstallConditionalFeatures(v8::Local<v8::Context>,
  60. + int32_t world_id) {}
  61. +
  62. // WebKit is about to release its reference to a v8 context for a frame.
  63. virtual void WillReleaseScriptContext(v8::Local<v8::Context>,
  64. int32_t world_id) {}
  65. 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
  66. index 17ebe5efb8b0bfcf17eda69fe4373b61b213af72..b7296a900c04006812d5f01b05c46a223fb40dc2 100644
  67. --- a/third_party/blink/renderer/bindings/core/v8/local_window_proxy.cc
  68. +++ b/third_party/blink/renderer/bindings/core/v8/local_window_proxy.cc
  69. @@ -201,6 +201,7 @@ void LocalWindowProxy::Initialize() {
  70. }
  71. InstallConditionalFeatures();
  72. + GetFrame()->Client()->DidInstallConditionalFeatures(context, world_->GetWorldId());
  73. if (World().IsMainWorld()) {
  74. GetFrame()->Loader().DispatchDidClearWindowObjectInMainWorld();
  75. 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
  76. index c586e0f7c21060f5f6a088631b5b0b9d57fad4eb..fc0fc331ecd535422eeb15bd831d64946edff3b2 100644
  77. --- a/third_party/blink/renderer/core/exported/local_frame_client_impl.cc
  78. +++ b/third_party/blink/renderer/core/exported/local_frame_client_impl.cc
  79. @@ -391,6 +391,13 @@ void LocalFrameClientImpl::DidCreateScriptContext(
  80. web_frame_->Client()->DidCreateScriptContext(context, world_id);
  81. }
  82. +void LocalFrameClientImpl::DidInstallConditionalFeatures(
  83. + v8::Local<v8::Context> context,
  84. + int32_t world_id) {
  85. + if (web_frame_->Client())
  86. + web_frame_->Client()->DidInstallConditionalFeatures(context, world_id);
  87. +}
  88. +
  89. void LocalFrameClientImpl::WillReleaseScriptContext(
  90. v8::Local<v8::Context> context,
  91. int32_t world_id) {
  92. 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
  93. index b21e7f5ba906d13045f38f986677106d35cc1d60..024188a4365261ba47ac200d15d8c0e52eb80a90 100644
  94. --- a/third_party/blink/renderer/core/exported/local_frame_client_impl.h
  95. +++ b/third_party/blink/renderer/core/exported/local_frame_client_impl.h
  96. @@ -78,6 +78,8 @@ class CORE_EXPORT LocalFrameClientImpl final : public LocalFrameClient {
  97. void DidCreateScriptContext(v8::Local<v8::Context>,
  98. int32_t world_id) override;
  99. + void DidInstallConditionalFeatures(v8::Local<v8::Context>,
  100. + int32_t world_id) override;
  101. void WillReleaseScriptContext(v8::Local<v8::Context>,
  102. int32_t world_id) override;
  103. diff --git a/third_party/blink/renderer/core/frame/local_frame_client.h b/third_party/blink/renderer/core/frame/local_frame_client.h
  104. index 4c6f1b9decbc5292d8349816fbac88dfd22b4774..ab28222f6be19cfc78c410633d20dc8646f98a2c 100644
  105. --- a/third_party/blink/renderer/core/frame/local_frame_client.h
  106. +++ b/third_party/blink/renderer/core/frame/local_frame_client.h
  107. @@ -296,6 +296,8 @@ class CORE_EXPORT LocalFrameClient : public FrameClient {
  108. virtual void DidCreateScriptContext(v8::Local<v8::Context>,
  109. int32_t world_id) = 0;
  110. + virtual void DidInstallConditionalFeatures(v8::Local<v8::Context>,
  111. + int32_t world_id) = 0;
  112. virtual void WillReleaseScriptContext(v8::Local<v8::Context>,
  113. int32_t world_id) = 0;
  114. virtual bool AllowScriptExtensions() = 0;
  115. diff --git a/third_party/blink/renderer/core/loader/empty_clients.h b/third_party/blink/renderer/core/loader/empty_clients.h
  116. index 006c575be0f9a33b0a5833b2d5d7bca6ca7fe2b0..d21901198b3b118b153ae2f77d071775c08574d4 100644
  117. --- a/third_party/blink/renderer/core/loader/empty_clients.h
  118. +++ b/third_party/blink/renderer/core/loader/empty_clients.h
  119. @@ -336,6 +336,8 @@ class CORE_EXPORT EmptyLocalFrameClient : public LocalFrameClient {
  120. void DidCreateScriptContext(v8::Local<v8::Context>,
  121. int32_t world_id) override {}
  122. + void DidInstallConditionalFeatures(v8::Local<v8::Context>,
  123. + int32_t world_id) override {}
  124. void WillReleaseScriptContext(v8::Local<v8::Context>,
  125. int32_t world_id) override {}
  126. bool AllowScriptExtensions() override { return false; }