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 d1e9ad95891487b37e2e03cb2a220eb969e877ab..13bdc6cf7ba4221f0a3219975a0825eb62dd0b78 100644
  12. --- a/content/public/renderer/render_frame_observer.h
  13. +++ b/content/public/renderer/render_frame_observer.h
  14. @@ -139,6 +139,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 54368c4a6ae9e2fb40017ecb31228a035dacf4cb..dceea20dd2a53fa079da7263e3161e1bd86279fe 100644
  25. --- a/content/renderer/render_frame_impl.cc
  26. +++ b/content/renderer/render_frame_impl.cc
  27. @@ -4474,6 +4474,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 bbca34db538e7fcfa54a845485e4c3e93507b754..988dafcd1f22c7e74386308825556f71e1b69ff1 100644
  41. --- a/content/renderer/render_frame_impl.h
  42. +++ b/content/renderer/render_frame_impl.h
  43. @@ -611,6 +611,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 cb4cd28c051c3ac4f97981e44636a6ea7d311c39..8eb2fd06f694c2c390427a0e981960f9292e9659 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. @@ -620,6 +620,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 fbd5c929b323ee9d943615ed8c890d869345165d..af11f266db8d626dfbba6f16d0a906e643e8c337 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. @@ -200,6 +200,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 61acd17afbe3ea1a6c2e40687709deee6b767df5..0413dda58f6de06f2dcd112b912c124626b19f85 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. @@ -321,6 +321,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 65642d9cc3b021acb6b0be310db782514379f627..cd0a381fbe6dc478c8c0779c351270b5b4d818f9 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. @@ -282,6 +282,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 ee4555b8ee7eab9b1ef7ef532fe94649f60c36b1..02b8bd5ce9579b4517f8188cfcb28f60012f6ce1 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. @@ -84,6 +84,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 507d02dc496a2324274e12501cb9ff080a0ed401..abcff9a4020578ef435bfa7c0dc0f9d8330bfa6b 100644
  117. --- a/third_party/blink/renderer/core/loader/empty_clients.h
  118. +++ b/third_party/blink/renderer/core/loader/empty_clients.h
  119. @@ -407,6 +407,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; }