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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 void DidFinishDocumentLoad() override; | 74 void DidFinishDocumentLoad() override; |
75 void DidFinishLoad() override; | 75 void DidFinishLoad() override; |
76 void FrameDetached() override; | 76 void FrameDetached() override; |
77 void OnDestruct() override; | 77 void OnDestruct() override; |
78 | 78 |
79 virtual void OnExecuteCode(const ExtensionMsg_ExecuteCode_Params& params); | 79 virtual void OnExecuteCode(const ExtensionMsg_ExecuteCode_Params& params); |
80 virtual void OnExecuteDeclarativeScript(int tab_id, | 80 virtual void OnExecuteDeclarativeScript(int tab_id, |
81 const ExtensionId& extension_id, | 81 const ExtensionId& extension_id, |
82 int script_id, | 82 int script_id, |
83 const GURL& url); | 83 const GURL& url); |
84 virtual void OnPermitScriptInjection(int64 request_id); | 84 virtual void OnPermitScriptInjection(int64_t request_id); |
85 | 85 |
86 // Tells the ScriptInjectionManager to run tasks associated with | 86 // Tells the ScriptInjectionManager to run tasks associated with |
87 // document_idle. | 87 // document_idle. |
88 void RunIdle(); | 88 void RunIdle(); |
89 | 89 |
90 // Indicate that the frame is no longer valid because it is starting | 90 // Indicate that the frame is no longer valid because it is starting |
91 // a new load or closing. | 91 // a new load or closing. |
92 void InvalidateAndResetFrame(); | 92 void InvalidateAndResetFrame(); |
93 | 93 |
94 // The owning ScriptInjectionManager. | 94 // The owning ScriptInjectionManager. |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 if (render_frame()->GetWebFrame()->document().url() == url) { | 189 if (render_frame()->GetWebFrame()->document().url() == url) { |
190 manager_->HandleExecuteDeclarativeScript(render_frame(), | 190 manager_->HandleExecuteDeclarativeScript(render_frame(), |
191 tab_id, | 191 tab_id, |
192 extension_id, | 192 extension_id, |
193 script_id, | 193 script_id, |
194 url); | 194 url); |
195 } | 195 } |
196 } | 196 } |
197 | 197 |
198 void ScriptInjectionManager::RFOHelper::OnPermitScriptInjection( | 198 void ScriptInjectionManager::RFOHelper::OnPermitScriptInjection( |
199 int64 request_id) { | 199 int64_t request_id) { |
200 manager_->HandlePermitScriptInjection(request_id); | 200 manager_->HandlePermitScriptInjection(request_id); |
201 } | 201 } |
202 | 202 |
203 void ScriptInjectionManager::RFOHelper::RunIdle() { | 203 void ScriptInjectionManager::RFOHelper::RunIdle() { |
204 // Only notify the manager if the frame hasn't either been removed or already | 204 // Only notify the manager if the frame hasn't either been removed or already |
205 // had idle run since the task to RunIdle() was posted. | 205 // had idle run since the task to RunIdle() was posted. |
206 if (should_run_idle_) { | 206 if (should_run_idle_) { |
207 should_run_idle_ = false; | 207 should_run_idle_ = false; |
208 manager_->StartInjectScripts(render_frame(), UserScript::DOCUMENT_IDLE); | 208 manager_->StartInjectScripts(render_frame(), UserScript::DOCUMENT_IDLE); |
209 } | 209 } |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 if (injection.get()) { | 441 if (injection.get()) { |
442 ScriptsRunInfo scripts_run_info(render_frame, UserScript::BROWSER_DRIVEN); | 442 ScriptsRunInfo scripts_run_info(render_frame, UserScript::BROWSER_DRIVEN); |
443 // TODO(markdittmer): Use return value of TryToInject for error handling. | 443 // TODO(markdittmer): Use return value of TryToInject for error handling. |
444 TryToInject(std::move(injection), UserScript::BROWSER_DRIVEN, | 444 TryToInject(std::move(injection), UserScript::BROWSER_DRIVEN, |
445 &scripts_run_info); | 445 &scripts_run_info); |
446 | 446 |
447 scripts_run_info.LogRun(); | 447 scripts_run_info.LogRun(); |
448 } | 448 } |
449 } | 449 } |
450 | 450 |
451 void ScriptInjectionManager::HandlePermitScriptInjection(int64 request_id) { | 451 void ScriptInjectionManager::HandlePermitScriptInjection(int64_t request_id) { |
452 auto iter = pending_injections_.begin(); | 452 auto iter = pending_injections_.begin(); |
453 for (; iter != pending_injections_.end(); ++iter) { | 453 for (; iter != pending_injections_.end(); ++iter) { |
454 if ((*iter)->request_id() == request_id) { | 454 if ((*iter)->request_id() == request_id) { |
455 DCHECK((*iter)->host_id().type() == HostID::EXTENSIONS); | 455 DCHECK((*iter)->host_id().type() == HostID::EXTENSIONS); |
456 break; | 456 break; |
457 } | 457 } |
458 } | 458 } |
459 if (iter == pending_injections_.end()) | 459 if (iter == pending_injections_.end()) |
460 return; | 460 return; |
461 | 461 |
462 // At this point, because the request is present in pending_injections_, we | 462 // At this point, because the request is present in pending_injections_, we |
463 // know that this is the same page that issued the request (otherwise, | 463 // know that this is the same page that issued the request (otherwise, |
464 // RFOHelper's DidStartProvisionalLoad callback would have caused it to be | 464 // RFOHelper's DidStartProvisionalLoad callback would have caused it to be |
465 // cleared out). | 465 // cleared out). |
466 | 466 |
467 scoped_ptr<ScriptInjection> injection(std::move(*iter)); | 467 scoped_ptr<ScriptInjection> injection(std::move(*iter)); |
468 pending_injections_.erase(iter); | 468 pending_injections_.erase(iter); |
469 | 469 |
470 ScriptsRunInfo scripts_run_info(injection->render_frame(), | 470 ScriptsRunInfo scripts_run_info(injection->render_frame(), |
471 UserScript::RUN_DEFERRED); | 471 UserScript::RUN_DEFERRED); |
472 ScriptInjection::InjectionResult res = injection->OnPermissionGranted( | 472 ScriptInjection::InjectionResult res = injection->OnPermissionGranted( |
473 &scripts_run_info); | 473 &scripts_run_info); |
474 if (res == ScriptInjection::INJECTION_BLOCKED) | 474 if (res == ScriptInjection::INJECTION_BLOCKED) |
475 running_injections_.push_back(std::move(injection)); | 475 running_injections_.push_back(std::move(injection)); |
476 scripts_run_info.LogRun(); | 476 scripts_run_info.LogRun(); |
477 } | 477 } |
478 | 478 |
479 } // namespace extensions | 479 } // namespace extensions |
OLD | NEW |