| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "content/public/renderer/render_view.h" | 10 #include "content/public/renderer/render_view.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 } // namespace | 34 } // namespace |
| 35 | 35 |
| 36 class ScriptInjectionManager::RVOHelper : public content::RenderViewObserver { | 36 class ScriptInjectionManager::RVOHelper : public content::RenderViewObserver { |
| 37 public: | 37 public: |
| 38 RVOHelper(content::RenderView* render_view, ScriptInjectionManager* manager); | 38 RVOHelper(content::RenderView* render_view, ScriptInjectionManager* manager); |
| 39 ~RVOHelper() override; | 39 ~RVOHelper() override; |
| 40 | 40 |
| 41 private: | 41 private: |
| 42 // RenderViewObserver implementation. | 42 // RenderViewObserver implementation. |
| 43 bool OnMessageReceived(const IPC::Message& message) override; | 43 bool OnMessageReceived(const IPC::Message& message) override; |
| 44 void DidCreateNewDocument(blink::WebLocalFrame* frame) override; |
| 44 void DidCreateDocumentElement(blink::WebLocalFrame* frame) override; | 45 void DidCreateDocumentElement(blink::WebLocalFrame* frame) override; |
| 45 void DidFinishDocumentLoad(blink::WebLocalFrame* frame) override; | 46 void DidFinishDocumentLoad(blink::WebLocalFrame* frame) override; |
| 46 void DidFinishLoad(blink::WebLocalFrame* frame) override; | 47 void DidFinishLoad(blink::WebLocalFrame* frame) override; |
| 47 void DidStartProvisionalLoad(blink::WebLocalFrame* frame) override; | |
| 48 void FrameDetached(blink::WebFrame* frame) override; | 48 void FrameDetached(blink::WebFrame* frame) override; |
| 49 void OnDestruct() override; | 49 void OnDestruct() override; |
| 50 | 50 |
| 51 virtual void OnExecuteCode(const ExtensionMsg_ExecuteCode_Params& params); | 51 virtual void OnExecuteCode(const ExtensionMsg_ExecuteCode_Params& params); |
| 52 virtual void OnExecuteDeclarativeScript(int tab_id, | 52 virtual void OnExecuteDeclarativeScript(int tab_id, |
| 53 const ExtensionId& extension_id, | 53 const ExtensionId& extension_id, |
| 54 int script_id, | 54 int script_id, |
| 55 const GURL& url); | 55 const GURL& url); |
| 56 virtual void OnPermitScriptInjection(int64 request_id); | 56 virtual void OnPermitScriptInjection(int64 request_id); |
| 57 | 57 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 IPC_MESSAGE_HANDLER(ExtensionMsg_ExecuteCode, OnExecuteCode) | 92 IPC_MESSAGE_HANDLER(ExtensionMsg_ExecuteCode, OnExecuteCode) |
| 93 IPC_MESSAGE_HANDLER(ExtensionMsg_PermitScriptInjection, | 93 IPC_MESSAGE_HANDLER(ExtensionMsg_PermitScriptInjection, |
| 94 OnPermitScriptInjection) | 94 OnPermitScriptInjection) |
| 95 IPC_MESSAGE_HANDLER(ExtensionMsg_ExecuteDeclarativeScript, | 95 IPC_MESSAGE_HANDLER(ExtensionMsg_ExecuteDeclarativeScript, |
| 96 OnExecuteDeclarativeScript) | 96 OnExecuteDeclarativeScript) |
| 97 IPC_MESSAGE_UNHANDLED(handled = false) | 97 IPC_MESSAGE_UNHANDLED(handled = false) |
| 98 IPC_END_MESSAGE_MAP() | 98 IPC_END_MESSAGE_MAP() |
| 99 return handled; | 99 return handled; |
| 100 } | 100 } |
| 101 | 101 |
| 102 void ScriptInjectionManager::RVOHelper::DidCreateNewDocument( |
| 103 blink::WebLocalFrame* frame) { |
| 104 // A new document is going to be shown, so invalidate the old document state. |
| 105 InvalidateFrame(frame); |
| 106 } |
| 107 |
| 102 void ScriptInjectionManager::RVOHelper::DidCreateDocumentElement( | 108 void ScriptInjectionManager::RVOHelper::DidCreateDocumentElement( |
| 103 blink::WebLocalFrame* frame) { | 109 blink::WebLocalFrame* frame) { |
| 104 manager_->InjectScripts(frame, UserScript::DOCUMENT_START); | 110 manager_->InjectScripts(frame, UserScript::DOCUMENT_START); |
| 105 } | 111 } |
| 106 | 112 |
| 107 void ScriptInjectionManager::RVOHelper::DidFinishDocumentLoad( | 113 void ScriptInjectionManager::RVOHelper::DidFinishDocumentLoad( |
| 108 blink::WebLocalFrame* frame) { | 114 blink::WebLocalFrame* frame) { |
| 109 manager_->InjectScripts(frame, UserScript::DOCUMENT_END); | 115 manager_->InjectScripts(frame, UserScript::DOCUMENT_END); |
| 110 pending_idle_frames_.insert(frame); | 116 pending_idle_frames_.insert(frame); |
| 111 // We try to run idle in two places: here and DidFinishLoad. | 117 // We try to run idle in two places: here and DidFinishLoad. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 130 // DidFinishDocumentLoad should strictly come before DidFinishLoad, so the | 136 // DidFinishDocumentLoad should strictly come before DidFinishLoad, so the |
| 131 // first posted task to RunIdle() pops it out of the set. This ensures we | 137 // first posted task to RunIdle() pops it out of the set. This ensures we |
| 132 // don't try to run idle twice. | 138 // don't try to run idle twice. |
| 133 base::MessageLoop::current()->PostTask( | 139 base::MessageLoop::current()->PostTask( |
| 134 FROM_HERE, | 140 FROM_HERE, |
| 135 base::Bind(&ScriptInjectionManager::RVOHelper::RunIdle, | 141 base::Bind(&ScriptInjectionManager::RVOHelper::RunIdle, |
| 136 weak_factory_.GetWeakPtr(), | 142 weak_factory_.GetWeakPtr(), |
| 137 frame)); | 143 frame)); |
| 138 } | 144 } |
| 139 | 145 |
| 140 void ScriptInjectionManager::RVOHelper::DidStartProvisionalLoad( | |
| 141 blink::WebLocalFrame* frame) { | |
| 142 // We're starting a new load - invalidate. | |
| 143 InvalidateFrame(frame); | |
| 144 } | |
| 145 | |
| 146 void ScriptInjectionManager::RVOHelper::FrameDetached(blink::WebFrame* frame) { | 146 void ScriptInjectionManager::RVOHelper::FrameDetached(blink::WebFrame* frame) { |
| 147 // The frame is closing - invalidate. | 147 // The frame is closing - invalidate. |
| 148 InvalidateFrame(frame); | 148 InvalidateFrame(frame); |
| 149 } | 149 } |
| 150 | 150 |
| 151 void ScriptInjectionManager::RVOHelper::OnDestruct() { | 151 void ScriptInjectionManager::RVOHelper::OnDestruct() { |
| 152 manager_->RemoveObserver(this); | 152 manager_->RemoveObserver(this); |
| 153 } | 153 } |
| 154 | 154 |
| 155 void ScriptInjectionManager::RVOHelper::OnExecuteCode( | 155 void ScriptInjectionManager::RVOHelper::OnExecuteCode( |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 | 400 |
| 401 ScriptsRunInfo scripts_run_info; | 401 ScriptsRunInfo scripts_run_info; |
| 402 if (injection->OnPermissionGranted(extensions_->GetByID( | 402 if (injection->OnPermissionGranted(extensions_->GetByID( |
| 403 injection->extension_id()), | 403 injection->extension_id()), |
| 404 &scripts_run_info)) { | 404 &scripts_run_info)) { |
| 405 scripts_run_info.LogRun(injection->web_frame(), UserScript::RUN_DEFERRED); | 405 scripts_run_info.LogRun(injection->web_frame(), UserScript::RUN_DEFERRED); |
| 406 } | 406 } |
| 407 } | 407 } |
| 408 | 408 |
| 409 } // namespace extensions | 409 } // namespace extensions |
| OLD | NEW |