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 // Check that the frame's state is known before invalidating the frame, | |
106 // because it is possible that a script injection was scheduled before the | |
107 // page was loaded, e.g. by navigating to a javascript: URL before the page | |
108 // has loaded. | |
109 if (manager_->frame_statuses_.find(frame) != manager_->frame_statuses_.end()) | |
110 InvalidateFrame(frame); | |
not at google - send to devlin
2014/11/17 22:20:05
Let's just call InvalidateFrame(frame) and forget
| |
111 } | |
112 | |
102 void ScriptInjectionManager::RVOHelper::DidCreateDocumentElement( | 113 void ScriptInjectionManager::RVOHelper::DidCreateDocumentElement( |
103 blink::WebLocalFrame* frame) { | 114 blink::WebLocalFrame* frame) { |
104 manager_->InjectScripts(frame, UserScript::DOCUMENT_START); | 115 manager_->InjectScripts(frame, UserScript::DOCUMENT_START); |
105 } | 116 } |
106 | 117 |
107 void ScriptInjectionManager::RVOHelper::DidFinishDocumentLoad( | 118 void ScriptInjectionManager::RVOHelper::DidFinishDocumentLoad( |
108 blink::WebLocalFrame* frame) { | 119 blink::WebLocalFrame* frame) { |
109 manager_->InjectScripts(frame, UserScript::DOCUMENT_END); | 120 manager_->InjectScripts(frame, UserScript::DOCUMENT_END); |
110 pending_idle_frames_.insert(frame); | 121 pending_idle_frames_.insert(frame); |
111 // We try to run idle in two places: here and DidFinishLoad. | 122 // 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 | 141 // DidFinishDocumentLoad should strictly come before DidFinishLoad, so the |
131 // first posted task to RunIdle() pops it out of the set. This ensures we | 142 // first posted task to RunIdle() pops it out of the set. This ensures we |
132 // don't try to run idle twice. | 143 // don't try to run idle twice. |
133 base::MessageLoop::current()->PostTask( | 144 base::MessageLoop::current()->PostTask( |
134 FROM_HERE, | 145 FROM_HERE, |
135 base::Bind(&ScriptInjectionManager::RVOHelper::RunIdle, | 146 base::Bind(&ScriptInjectionManager::RVOHelper::RunIdle, |
136 weak_factory_.GetWeakPtr(), | 147 weak_factory_.GetWeakPtr(), |
137 frame)); | 148 frame)); |
138 } | 149 } |
139 | 150 |
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) { | 151 void ScriptInjectionManager::RVOHelper::FrameDetached(blink::WebFrame* frame) { |
147 // The frame is closing - invalidate. | 152 // The frame is closing - invalidate. |
148 InvalidateFrame(frame); | 153 InvalidateFrame(frame); |
149 } | 154 } |
150 | 155 |
151 void ScriptInjectionManager::RVOHelper::OnDestruct() { | 156 void ScriptInjectionManager::RVOHelper::OnDestruct() { |
152 manager_->RemoveObserver(this); | 157 manager_->RemoveObserver(this); |
153 } | 158 } |
154 | 159 |
155 void ScriptInjectionManager::RVOHelper::OnExecuteCode( | 160 void ScriptInjectionManager::RVOHelper::OnExecuteCode( |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
400 | 405 |
401 ScriptsRunInfo scripts_run_info; | 406 ScriptsRunInfo scripts_run_info; |
402 if (injection->OnPermissionGranted(extensions_->GetByID( | 407 if (injection->OnPermissionGranted(extensions_->GetByID( |
403 injection->extension_id()), | 408 injection->extension_id()), |
404 &scripts_run_info)) { | 409 &scripts_run_info)) { |
405 scripts_run_info.LogRun(injection->web_frame(), UserScript::RUN_DEFERRED); | 410 scripts_run_info.LogRun(injection->web_frame(), UserScript::RUN_DEFERRED); |
406 } | 411 } |
407 } | 412 } |
408 | 413 |
409 } // namespace extensions | 414 } // namespace extensions |
OLD | NEW |