| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "extensions/renderer/script_injection_manager.h" | 5 #include "extensions/renderer/script_injection_manager.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "content/public/common/browser_side_navigation_policy.h" |
| 15 #include "content/public/renderer/render_frame.h" | 16 #include "content/public/renderer/render_frame.h" |
| 16 #include "content/public/renderer/render_frame_observer.h" | 17 #include "content/public/renderer/render_frame_observer.h" |
| 17 #include "content/public/renderer/render_thread.h" | 18 #include "content/public/renderer/render_thread.h" |
| 18 #include "extensions/common/extension.h" | 19 #include "extensions/common/extension.h" |
| 19 #include "extensions/common/extension_messages.h" | 20 #include "extensions/common/extension_messages.h" |
| 20 #include "extensions/common/extension_set.h" | 21 #include "extensions/common/extension_set.h" |
| 21 #include "extensions/renderer/extension_frame_helper.h" | 22 #include "extensions/renderer/extension_frame_helper.h" |
| 22 #include "extensions/renderer/extension_injection_host.h" | 23 #include "extensions/renderer/extension_injection_host.h" |
| 23 #include "extensions/renderer/programmatic_script_injector.h" | 24 #include "extensions/renderer/programmatic_script_injector.h" |
| 24 #include "extensions/renderer/renderer_extension_registry.h" | 25 #include "extensions/renderer/renderer_extension_registry.h" |
| 25 #include "extensions/renderer/script_injection.h" | 26 #include "extensions/renderer/script_injection.h" |
| 26 #include "extensions/renderer/scripts_run_info.h" | 27 #include "extensions/renderer/scripts_run_info.h" |
| 27 #include "extensions/renderer/web_ui_injection_host.h" | 28 #include "extensions/renderer/web_ui_injection_host.h" |
| 28 #include "ipc/ipc_message_macros.h" | 29 #include "ipc/ipc_message_macros.h" |
| 30 #include "third_party/WebKit/public/platform/WebURLError.h" |
| 29 #include "third_party/WebKit/public/web/WebDocument.h" | 31 #include "third_party/WebKit/public/web/WebDocument.h" |
| 30 #include "third_party/WebKit/public/web/WebFrame.h" | 32 #include "third_party/WebKit/public/web/WebFrame.h" |
| 31 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 33 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 32 #include "third_party/WebKit/public/web/WebView.h" | 34 #include "third_party/WebKit/public/web/WebView.h" |
| 33 #include "url/gurl.h" | 35 #include "url/gurl.h" |
| 34 | 36 |
| 35 namespace extensions { | 37 namespace extensions { |
| 36 | 38 |
| 37 namespace { | 39 namespace { |
| 38 | 40 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 private: | 72 private: |
| 71 // RenderFrameObserver implementation. | 73 // RenderFrameObserver implementation. |
| 72 bool OnMessageReceived(const IPC::Message& message) override; | 74 bool OnMessageReceived(const IPC::Message& message) override; |
| 73 void DidCreateNewDocument() override; | 75 void DidCreateNewDocument() override; |
| 74 void DidCreateDocumentElement() override; | 76 void DidCreateDocumentElement() override; |
| 75 void DidFailProvisionalLoad(const blink::WebURLError& error) override; | 77 void DidFailProvisionalLoad(const blink::WebURLError& error) override; |
| 76 void DidFinishDocumentLoad() override; | 78 void DidFinishDocumentLoad() override; |
| 77 void DidFinishLoad() override; | 79 void DidFinishLoad() override; |
| 78 void FrameDetached() override; | 80 void FrameDetached() override; |
| 79 void OnDestruct() override; | 81 void OnDestruct() override; |
| 82 void OnStop() override; |
| 80 | 83 |
| 81 virtual void OnExecuteCode(const ExtensionMsg_ExecuteCode_Params& params); | 84 virtual void OnExecuteCode(const ExtensionMsg_ExecuteCode_Params& params); |
| 82 virtual void OnExecuteDeclarativeScript(int tab_id, | 85 virtual void OnExecuteDeclarativeScript(int tab_id, |
| 83 const ExtensionId& extension_id, | 86 const ExtensionId& extension_id, |
| 84 int script_id, | 87 int script_id, |
| 85 const GURL& url); | 88 const GURL& url); |
| 86 virtual void OnPermitScriptInjection(int64_t request_id); | 89 virtual void OnPermitScriptInjection(int64_t request_id); |
| 87 | 90 |
| 88 // Tells the ScriptInjectionManager to run tasks associated with | 91 // Tells the ScriptInjectionManager to run tasks associated with |
| 89 // document_idle. | 92 // document_idle. |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 | 201 |
| 199 void ScriptInjectionManager::RFOHelper::FrameDetached() { | 202 void ScriptInjectionManager::RFOHelper::FrameDetached() { |
| 200 // The frame is closing - invalidate. | 203 // The frame is closing - invalidate. |
| 201 InvalidateAndResetFrame(); | 204 InvalidateAndResetFrame(); |
| 202 } | 205 } |
| 203 | 206 |
| 204 void ScriptInjectionManager::RFOHelper::OnDestruct() { | 207 void ScriptInjectionManager::RFOHelper::OnDestruct() { |
| 205 manager_->RemoveObserver(this); | 208 manager_->RemoveObserver(this); |
| 206 } | 209 } |
| 207 | 210 |
| 211 void ScriptInjectionManager::RFOHelper::OnStop() { |
| 212 // With PlzNavigate, we won't get a provisional load failed notification |
| 213 // for 204/205/downloads since these don't notify the renderer. However the |
| 214 // browser does fire the OnStop IPC. So use that signal instead to avoid |
| 215 // keeping the frame in a START state indefinitely which leads to deadlocks. |
| 216 if (content::IsBrowserSideNavigationEnabled()) |
| 217 DidFailProvisionalLoad(blink::WebURLError()); |
| 218 } |
| 219 |
| 208 void ScriptInjectionManager::RFOHelper::OnExecuteCode( | 220 void ScriptInjectionManager::RFOHelper::OnExecuteCode( |
| 209 const ExtensionMsg_ExecuteCode_Params& params) { | 221 const ExtensionMsg_ExecuteCode_Params& params) { |
| 210 manager_->HandleExecuteCode(params, render_frame()); | 222 manager_->HandleExecuteCode(params, render_frame()); |
| 211 } | 223 } |
| 212 | 224 |
| 213 void ScriptInjectionManager::RFOHelper::OnExecuteDeclarativeScript( | 225 void ScriptInjectionManager::RFOHelper::OnExecuteDeclarativeScript( |
| 214 int tab_id, | 226 int tab_id, |
| 215 const ExtensionId& extension_id, | 227 const ExtensionId& extension_id, |
| 216 int script_id, | 228 int script_id, |
| 217 const GURL& url) { | 229 const GURL& url) { |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 ScriptsRunInfo scripts_run_info(injection->render_frame(), | 514 ScriptsRunInfo scripts_run_info(injection->render_frame(), |
| 503 UserScript::RUN_DEFERRED); | 515 UserScript::RUN_DEFERRED); |
| 504 ScriptInjection::InjectionResult res = injection->OnPermissionGranted( | 516 ScriptInjection::InjectionResult res = injection->OnPermissionGranted( |
| 505 &scripts_run_info); | 517 &scripts_run_info); |
| 506 if (res == ScriptInjection::INJECTION_BLOCKED) | 518 if (res == ScriptInjection::INJECTION_BLOCKED) |
| 507 running_injections_.push_back(std::move(injection)); | 519 running_injections_.push_back(std::move(injection)); |
| 508 scripts_run_info.LogRun(activity_logging_enabled_); | 520 scripts_run_info.LogRun(activity_logging_enabled_); |
| 509 } | 521 } |
| 510 | 522 |
| 511 } // namespace extensions | 523 } // namespace extensions |
| OLD | NEW |