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 ad0092ef2e13853e4bb8b923481559a043b00ab7..1c2dfd23f18733e21312992877ae1499634d3849 100644
  12. --- a/content/public/renderer/render_frame_observer.h
  13. +++ b/content/public/renderer/render_frame_observer.h
  14. @@ -150,6 +150,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 ee688da4100412ff58bffa1b266a4c823486dd56..2a53ebc1be32c537e9325cb851f50188f037da0b 100644
  25. --- a/content/renderer/render_frame_impl.cc
  26. +++ b/content/renderer/render_frame_impl.cc
  27. @@ -4719,6 +4719,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 b47f9d4e51e64888301061f081a0515ae4f254d0..3d45f8a9de9a726f011791f3f61d79af98fb740d 100644
  41. --- a/content/renderer/render_frame_impl.h
  42. +++ b/content/renderer/render_frame_impl.h
  43. @@ -643,6 +643,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 85cd5b277088c61a6bf83589a2698d279771ab18..f774939483b91875f012cb74d5a58d35fdfe3866 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. @@ -647,6 +647,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 ccb1ab9c1eefbdf4f73e50d390c897dbbbc7061e..3382f434b75fb1acced2f67ad41fc70a44949578 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. @@ -300,6 +300,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 1f99493c7e50fe44a58c9e4db34cb99780863c86..4a65887071650678efea4adb3d1e55c132d454d8 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. @@ -294,6 +294,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 a3661daf705b0b161da88433b46d410dfa96227d..bbd905415520bb4507580817e78134b09ce01631 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. @@ -83,6 +83,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 f3a081d7230c10d12f7e14311930efc3df1ad870..7e8b97c7e901a2ba5ca32037a938749806243dac 100644
  117. --- a/third_party/blink/renderer/core/loader/empty_clients.h
  118. +++ b/third_party/blink/renderer/core/loader/empty_clients.h
  119. @@ -408,6 +408,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; }