add_didinstallconditionalfeatures.patch 7.8 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 44da0544b778d6ff4c14b6f4e8463cb8260d2f0d..8ae8939af4141a684b7a6d50a43e1abb354ea028 100644
  12. --- a/content/public/renderer/render_frame_observer.h
  13. +++ b/content/public/renderer/render_frame_observer.h
  14. @@ -149,6 +149,8 @@ class CONTENT_EXPORT RenderFrameObserver
  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 e995c76b1ecc50502c47862607408d0663e91738..9d675b45688572d3b38d29e7d2074e0fb4b737ac 100644
  25. --- a/content/renderer/render_frame_impl.cc
  26. +++ b/content/renderer/render_frame_impl.cc
  27. @@ -4787,6 +4787,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 398676cc0642115ff825beb1a593c3d14d4a5531..cc7cd3c73d72e933807b8d6f4e9e4ac43cbea00d 100644
  41. --- a/content/renderer/render_frame_impl.h
  42. +++ b/content/renderer/render_frame_impl.h
  43. @@ -654,6 +654,8 @@ class CONTENT_EXPORT RenderFrameImpl
  44. void DidObserveLayoutShift(double score, bool after_input_or_scroll) 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 d0d0ccafdd25cbac7fa7daa8e615b8ca1018a68b..6bf6b6b8a2847d4677383b9ee4574ebe6894c287 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. @@ -665,6 +665,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 f7e0144c74f879e9b29871d7c372b99e127966bb..c3cd7b77ed282f212a56d151dc3fbec36d183701 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. @@ -217,6 +217,7 @@ void LocalWindowProxy::Initialize() {
  70. }
  71. InstallConditionalFeatures();
  72. + GetFrame()->Client()->DidInstallConditionalFeatures(context, world_->GetWorldId());
  73. if (World().IsMainWorld()) {
  74. probe::DidCreateMainWorldContext(GetFrame());
  75. diff --git a/third_party/blink/renderer/core/frame/local_frame_client.h b/third_party/blink/renderer/core/frame/local_frame_client.h
  76. index 8bb6b0465069529f79aaec21792e8b159535b3e9..f9782531c639d07002dda07732750a0007109468 100644
  77. --- a/third_party/blink/renderer/core/frame/local_frame_client.h
  78. +++ b/third_party/blink/renderer/core/frame/local_frame_client.h
  79. @@ -299,6 +299,8 @@ class CORE_EXPORT LocalFrameClient : public FrameClient {
  80. virtual void DidCreateScriptContext(v8::Local<v8::Context>,
  81. int32_t world_id) = 0;
  82. + virtual void DidInstallConditionalFeatures(v8::Local<v8::Context>,
  83. + int32_t world_id) = 0;
  84. virtual void WillReleaseScriptContext(v8::Local<v8::Context>,
  85. int32_t world_id) = 0;
  86. virtual bool AllowScriptExtensions() = 0;
  87. 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
  88. index cfcabe9a443adae146c816419e0845cb6fc18404..717587c2cfe0b0228ae40adce04139cb54a34d0e 100644
  89. --- a/third_party/blink/renderer/core/frame/local_frame_client_impl.cc
  90. +++ b/third_party/blink/renderer/core/frame/local_frame_client_impl.cc
  91. @@ -296,6 +296,13 @@ void LocalFrameClientImpl::DidCreateScriptContext(
  92. web_frame_->Client()->DidCreateScriptContext(context, world_id);
  93. }
  94. +void LocalFrameClientImpl::DidInstallConditionalFeatures(
  95. + v8::Local<v8::Context> context,
  96. + int32_t world_id) {
  97. + if (web_frame_->Client())
  98. + web_frame_->Client()->DidInstallConditionalFeatures(context, world_id);
  99. +}
  100. +
  101. void LocalFrameClientImpl::WillReleaseScriptContext(
  102. v8::Local<v8::Context> context,
  103. int32_t world_id) {
  104. 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
  105. index 4c7375a27a22f04694e14fecc17d633734d4cccc..ea2a32b151aaf07b5704e463d01714eb41680afb 100644
  106. --- a/third_party/blink/renderer/core/frame/local_frame_client_impl.h
  107. +++ b/third_party/blink/renderer/core/frame/local_frame_client_impl.h
  108. @@ -82,6 +82,8 @@ class CORE_EXPORT LocalFrameClientImpl final : public LocalFrameClient {
  109. void DidCreateScriptContext(v8::Local<v8::Context>,
  110. int32_t world_id) override;
  111. + void DidInstallConditionalFeatures(v8::Local<v8::Context>,
  112. + int32_t world_id) override;
  113. void WillReleaseScriptContext(v8::Local<v8::Context>,
  114. int32_t world_id) override;
  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 6b967bd0b430732732ef30fb404e615a55c7c364..6bba885bca8f65744bcd03efcb98725649687856 100644
  117. --- a/third_party/blink/renderer/core/loader/empty_clients.h
  118. +++ b/third_party/blink/renderer/core/loader/empty_clients.h
  119. @@ -415,6 +415,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; }