Chromium Code Reviews| 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/renderer/render_frame.h" | 15 #include "content/public/renderer/render_frame.h" |
| 16 #include "content/public/renderer/render_frame_observer.h" | 16 #include "content/public/renderer/render_frame_observer.h" |
| 17 #include "content/public/renderer/render_thread.h" | 17 #include "content/public/renderer/render_thread.h" |
| 18 #include "extensions/common/extension.h" | 18 #include "extensions/common/extension.h" |
| 19 #include "extensions/common/extension_messages.h" | 19 #include "extensions/common/extension_messages.h" |
| 20 #include "extensions/common/extension_set.h" | 20 #include "extensions/common/extension_set.h" |
| 21 #include "extensions/renderer/extension_frame_helper.h" | 21 #include "extensions/renderer/extension_frame_helper.h" |
| 22 #include "extensions/renderer/extension_injection_host.h" | 22 #include "extensions/renderer/extension_injection_host.h" |
| 23 #include "extensions/renderer/programmatic_script_injector.h" | 23 #include "extensions/renderer/programmatic_script_injector.h" |
| 24 #include "extensions/renderer/renderer_extension_registry.h" | 24 #include "extensions/renderer/renderer_extension_registry.h" |
| 25 #include "extensions/renderer/script_injection.h" | 25 #include "extensions/renderer/script_injection.h" |
| 26 #include "extensions/renderer/scripts_run_info.h" | 26 #include "extensions/renderer/scripts_run_info.h" |
| 27 #include "extensions/renderer/web_ui_injection_host.h" | 27 #include "extensions/renderer/web_ui_injection_host.h" |
| 28 #include "ipc/ipc_message_macros.h" | 28 #include "ipc/ipc_message_macros.h" |
| 29 #include "third_party/WebKit/public/platform/WebURLError.h" | |
| 29 #include "third_party/WebKit/public/web/WebDocument.h" | 30 #include "third_party/WebKit/public/web/WebDocument.h" |
| 30 #include "third_party/WebKit/public/web/WebFrame.h" | 31 #include "third_party/WebKit/public/web/WebFrame.h" |
| 31 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 32 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 32 #include "third_party/WebKit/public/web/WebView.h" | 33 #include "third_party/WebKit/public/web/WebView.h" |
| 33 #include "url/gurl.h" | 34 #include "url/gurl.h" |
| 34 | 35 |
| 35 namespace extensions { | 36 namespace extensions { |
| 36 | 37 |
| 37 namespace { | 38 namespace { |
| 38 | 39 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 void DidFinishLoad() override; | 78 void DidFinishLoad() override; |
| 78 void FrameDetached() override; | 79 void FrameDetached() override; |
| 79 void OnDestruct() override; | 80 void OnDestruct() override; |
| 80 | 81 |
| 81 virtual void OnExecuteCode(const ExtensionMsg_ExecuteCode_Params& params); | 82 virtual void OnExecuteCode(const ExtensionMsg_ExecuteCode_Params& params); |
| 82 virtual void OnExecuteDeclarativeScript(int tab_id, | 83 virtual void OnExecuteDeclarativeScript(int tab_id, |
| 83 const ExtensionId& extension_id, | 84 const ExtensionId& extension_id, |
| 84 int script_id, | 85 int script_id, |
| 85 const GURL& url); | 86 const GURL& url); |
| 86 virtual void OnPermitScriptInjection(int64_t request_id); | 87 virtual void OnPermitScriptInjection(int64_t request_id); |
| 88 void OnSet204Or205Error(); | |
| 87 | 89 |
| 88 // Tells the ScriptInjectionManager to run tasks associated with | 90 // Tells the ScriptInjectionManager to run tasks associated with |
| 89 // document_idle. | 91 // document_idle. |
| 90 void RunIdle(); | 92 void RunIdle(); |
| 91 | 93 |
| 92 void StartInjectScripts(UserScript::RunLocation run_location); | 94 void StartInjectScripts(UserScript::RunLocation run_location); |
| 93 | 95 |
| 94 // Indicate that the frame is no longer valid because it is starting | 96 // Indicate that the frame is no longer valid because it is starting |
| 95 // a new load or closing. | 97 // a new load or closing. |
| 96 void InvalidateAndResetFrame(); | 98 void InvalidateAndResetFrame(); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 116 | 118 |
| 117 bool ScriptInjectionManager::RFOHelper::OnMessageReceived( | 119 bool ScriptInjectionManager::RFOHelper::OnMessageReceived( |
| 118 const IPC::Message& message) { | 120 const IPC::Message& message) { |
| 119 bool handled = true; | 121 bool handled = true; |
| 120 IPC_BEGIN_MESSAGE_MAP(ScriptInjectionManager::RFOHelper, message) | 122 IPC_BEGIN_MESSAGE_MAP(ScriptInjectionManager::RFOHelper, message) |
| 121 IPC_MESSAGE_HANDLER(ExtensionMsg_ExecuteCode, OnExecuteCode) | 123 IPC_MESSAGE_HANDLER(ExtensionMsg_ExecuteCode, OnExecuteCode) |
| 122 IPC_MESSAGE_HANDLER(ExtensionMsg_PermitScriptInjection, | 124 IPC_MESSAGE_HANDLER(ExtensionMsg_PermitScriptInjection, |
| 123 OnPermitScriptInjection) | 125 OnPermitScriptInjection) |
| 124 IPC_MESSAGE_HANDLER(ExtensionMsg_ExecuteDeclarativeScript, | 126 IPC_MESSAGE_HANDLER(ExtensionMsg_ExecuteDeclarativeScript, |
| 125 OnExecuteDeclarativeScript) | 127 OnExecuteDeclarativeScript) |
| 128 IPC_MESSAGE_HANDLER(ExtensionMsg_Set204Or205Error, OnSet204Or205Error) | |
| 126 IPC_MESSAGE_UNHANDLED(handled = false) | 129 IPC_MESSAGE_UNHANDLED(handled = false) |
| 127 IPC_END_MESSAGE_MAP() | 130 IPC_END_MESSAGE_MAP() |
| 128 return handled; | 131 return handled; |
| 129 } | 132 } |
| 130 | 133 |
| 131 void ScriptInjectionManager::RFOHelper::DidCreateNewDocument() { | 134 void ScriptInjectionManager::RFOHelper::DidCreateNewDocument() { |
| 132 // A new document is going to be shown, so invalidate the old document state. | 135 // A new document is going to be shown, so invalidate the old document state. |
| 133 // Check that the frame's state is known before invalidating the frame, | 136 // Check that the frame's state is known before invalidating the frame, |
| 134 // because it is possible that a script injection was scheduled before the | 137 // because it is possible that a script injection was scheduled before the |
| 135 // page was loaded, e.g. by navigating to a javascript: URL before the page | 138 // page was loaded, e.g. by navigating to a javascript: URL before the page |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 script_id, | 228 script_id, |
| 226 url); | 229 url); |
| 227 } | 230 } |
| 228 } | 231 } |
| 229 | 232 |
| 230 void ScriptInjectionManager::RFOHelper::OnPermitScriptInjection( | 233 void ScriptInjectionManager::RFOHelper::OnPermitScriptInjection( |
| 231 int64_t request_id) { | 234 int64_t request_id) { |
| 232 manager_->HandlePermitScriptInjection(request_id); | 235 manager_->HandlePermitScriptInjection(request_id); |
| 233 } | 236 } |
| 234 | 237 |
| 238 void ScriptInjectionManager::RFOHelper::OnSet204Or205Error() { | |
| 239 DidFailProvisionalLoad(blink::WebURLError()); | |
|
Devlin
2016/10/31 17:24:00
In a non-plznavigate world, would a 204/205 cause
Devlin
2016/10/31 17:28:14
For more context, I'm asking because of the case o
| |
| 240 } | |
| 241 | |
| 235 void ScriptInjectionManager::RFOHelper::RunIdle() { | 242 void ScriptInjectionManager::RFOHelper::RunIdle() { |
| 236 // Only notify the manager if the frame hasn't either been removed or already | 243 // Only notify the manager if the frame hasn't either been removed or already |
| 237 // had idle run since the task to RunIdle() was posted. | 244 // had idle run since the task to RunIdle() was posted. |
| 238 if (should_run_idle_) { | 245 if (should_run_idle_) { |
| 239 should_run_idle_ = false; | 246 should_run_idle_ = false; |
| 240 manager_->StartInjectScripts(render_frame(), UserScript::DOCUMENT_IDLE); | 247 manager_->StartInjectScripts(render_frame(), UserScript::DOCUMENT_IDLE); |
| 241 } | 248 } |
| 242 } | 249 } |
| 243 | 250 |
| 244 void ScriptInjectionManager::RFOHelper::StartInjectScripts( | 251 void ScriptInjectionManager::RFOHelper::StartInjectScripts( |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 502 ScriptsRunInfo scripts_run_info(injection->render_frame(), | 509 ScriptsRunInfo scripts_run_info(injection->render_frame(), |
| 503 UserScript::RUN_DEFERRED); | 510 UserScript::RUN_DEFERRED); |
| 504 ScriptInjection::InjectionResult res = injection->OnPermissionGranted( | 511 ScriptInjection::InjectionResult res = injection->OnPermissionGranted( |
| 505 &scripts_run_info); | 512 &scripts_run_info); |
| 506 if (res == ScriptInjection::INJECTION_BLOCKED) | 513 if (res == ScriptInjection::INJECTION_BLOCKED) |
| 507 running_injections_.push_back(std::move(injection)); | 514 running_injections_.push_back(std::move(injection)); |
| 508 scripts_run_info.LogRun(activity_logging_enabled_); | 515 scripts_run_info.LogRun(activity_logging_enabled_); |
| 509 } | 516 } |
| 510 | 517 |
| 511 } // namespace extensions | 518 } // namespace extensions |
| OLD | NEW |