Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1273)

Side by Side Diff: extensions/renderer/script_injection_manager.cc

Issue 492133002: Renderer changes for wiring up shared memory with declarative injection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 30 matching lines...) Expand all
41 // RenderViewObserver implementation. 41 // RenderViewObserver implementation.
42 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 42 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
43 virtual void DidCreateDocumentElement(blink::WebLocalFrame* frame) OVERRIDE; 43 virtual void DidCreateDocumentElement(blink::WebLocalFrame* frame) OVERRIDE;
44 virtual void DidFinishDocumentLoad(blink::WebLocalFrame* frame) OVERRIDE; 44 virtual void DidFinishDocumentLoad(blink::WebLocalFrame* frame) OVERRIDE;
45 virtual void DidFinishLoad(blink::WebLocalFrame* frame) OVERRIDE; 45 virtual void DidFinishLoad(blink::WebLocalFrame* frame) OVERRIDE;
46 virtual void DidStartProvisionalLoad(blink::WebLocalFrame* frame) OVERRIDE; 46 virtual void DidStartProvisionalLoad(blink::WebLocalFrame* frame) OVERRIDE;
47 virtual void FrameDetached(blink::WebFrame* frame) OVERRIDE; 47 virtual void FrameDetached(blink::WebFrame* frame) OVERRIDE;
48 virtual void OnDestruct() OVERRIDE; 48 virtual void OnDestruct() OVERRIDE;
49 49
50 virtual void OnExecuteCode(const ExtensionMsg_ExecuteCode_Params& params); 50 virtual void OnExecuteCode(const ExtensionMsg_ExecuteCode_Params& params);
51 virtual void OnExecuteDeclarativeScript(int tab_id,
52 const ExtensionId& extension_id,
53 int64 script_id,
54 const GURL& url);
51 virtual void OnPermitScriptInjection(int64 request_id); 55 virtual void OnPermitScriptInjection(int64 request_id);
52 56
53 // Tells the ScriptInjectionManager to run tasks associated with 57 // Tells the ScriptInjectionManager to run tasks associated with
54 // document_idle. 58 // document_idle.
55 void RunIdle(blink::WebFrame* frame); 59 void RunIdle(blink::WebFrame* frame);
56 60
57 // Indicate that the given |frame| is no longer valid because it is starting 61 // Indicate that the given |frame| is no longer valid because it is starting
58 // a new load or closing. 62 // a new load or closing.
59 void InvalidateFrame(blink::WebFrame* frame); 63 void InvalidateFrame(blink::WebFrame* frame);
60 64
(...skipping 19 matching lines...) Expand all
80 ScriptInjectionManager::RVOHelper::~RVOHelper() { 84 ScriptInjectionManager::RVOHelper::~RVOHelper() {
81 } 85 }
82 86
83 bool ScriptInjectionManager::RVOHelper::OnMessageReceived( 87 bool ScriptInjectionManager::RVOHelper::OnMessageReceived(
84 const IPC::Message& message) { 88 const IPC::Message& message) {
85 bool handled = true; 89 bool handled = true;
86 IPC_BEGIN_MESSAGE_MAP(ScriptInjectionManager::RVOHelper, message) 90 IPC_BEGIN_MESSAGE_MAP(ScriptInjectionManager::RVOHelper, message)
87 IPC_MESSAGE_HANDLER(ExtensionMsg_ExecuteCode, OnExecuteCode) 91 IPC_MESSAGE_HANDLER(ExtensionMsg_ExecuteCode, OnExecuteCode)
88 IPC_MESSAGE_HANDLER(ExtensionMsg_PermitScriptInjection, 92 IPC_MESSAGE_HANDLER(ExtensionMsg_PermitScriptInjection,
89 OnPermitScriptInjection) 93 OnPermitScriptInjection)
94 IPC_MESSAGE_HANDLER(ExtensionMsg_ExecuteDeclarativeScript,
95 OnExecuteDeclarativeScript)
90 IPC_MESSAGE_UNHANDLED(handled = false) 96 IPC_MESSAGE_UNHANDLED(handled = false)
91 IPC_END_MESSAGE_MAP() 97 IPC_END_MESSAGE_MAP()
92 return handled; 98 return handled;
93 } 99 }
94 100
95 void ScriptInjectionManager::RVOHelper::DidCreateDocumentElement( 101 void ScriptInjectionManager::RVOHelper::DidCreateDocumentElement(
96 blink::WebLocalFrame* frame) { 102 blink::WebLocalFrame* frame) {
97 manager_->InjectScripts(frame, UserScript::DOCUMENT_START); 103 manager_->InjectScripts(frame, UserScript::DOCUMENT_START);
98 } 104 }
99 105
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 149
144 void ScriptInjectionManager::RVOHelper::OnDestruct() { 150 void ScriptInjectionManager::RVOHelper::OnDestruct() {
145 manager_->RemoveObserver(this); 151 manager_->RemoveObserver(this);
146 } 152 }
147 153
148 void ScriptInjectionManager::RVOHelper::OnExecuteCode( 154 void ScriptInjectionManager::RVOHelper::OnExecuteCode(
149 const ExtensionMsg_ExecuteCode_Params& params) { 155 const ExtensionMsg_ExecuteCode_Params& params) {
150 manager_->HandleExecuteCode(params, render_view()); 156 manager_->HandleExecuteCode(params, render_view());
151 } 157 }
152 158
159 void ScriptInjectionManager::RVOHelper::OnExecuteDeclarativeScript(
160 int tab_id,
161 const ExtensionId& extension_id,
162 int64 script_id,
163 const GURL& url) {
164 blink::WebFrame* main_frame = render_view()->GetWebView()->mainFrame();
165 manager_->HandleExecuteDeclarativeScript(main_frame,
166 tab_id,
167 extension_id,
168 script_id,
169 url);
170 }
171
153 void ScriptInjectionManager::RVOHelper::OnPermitScriptInjection( 172 void ScriptInjectionManager::RVOHelper::OnPermitScriptInjection(
154 int64 request_id) { 173 int64 request_id) {
155 manager_->HandlePermitScriptInjection(request_id); 174 manager_->HandlePermitScriptInjection(request_id);
156 } 175 }
157 176
158 void ScriptInjectionManager::RVOHelper::RunIdle(blink::WebFrame* frame) { 177 void ScriptInjectionManager::RVOHelper::RunIdle(blink::WebFrame* frame) {
159 // Only notify the manager if the frame hasn't either been removed or already 178 // Only notify the manager if the frame hasn't either been removed or already
160 // had idle run since the task to RunIdle() was posted. 179 // had idle run since the task to RunIdle() was posted.
161 if (pending_idle_frames_.count(frame) > 0) { 180 if (pending_idle_frames_.count(frame) > 0) {
162 manager_->InjectScripts(frame, UserScript::DOCUMENT_IDLE); 181 manager_->InjectScripts(frame, UserScript::DOCUMENT_IDLE);
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 ScriptsRunInfo scripts_run_info; 335 ScriptsRunInfo scripts_run_info;
317 FrameStatusMap::const_iterator iter = frame_statuses_.find(main_frame); 336 FrameStatusMap::const_iterator iter = frame_statuses_.find(main_frame);
318 if (!injection->TryToInject( 337 if (!injection->TryToInject(
319 iter == frame_statuses_.end() ? UserScript::UNDEFINED : iter->second, 338 iter == frame_statuses_.end() ? UserScript::UNDEFINED : iter->second,
320 extensions_->GetByID(injection->extension_id()), 339 extensions_->GetByID(injection->extension_id()),
321 &scripts_run_info)) { 340 &scripts_run_info)) {
322 pending_injections_.push_back(injection.release()); 341 pending_injections_.push_back(injection.release());
323 } 342 }
324 } 343 }
325 344
345 void ScriptInjectionManager::HandleExecuteDeclarativeScript(
346 blink::WebFrame* web_frame,
347 int tab_id,
348 const ExtensionId& extension_id,
349 int64 script_id,
350 const GURL& url) {
351 const Extension* extension = extensions_->GetByID(extension_id);
352 scoped_ptr<ScriptInjection> injection =
353 user_script_set_manager_->GetInjectionForScript(
Devlin 2014/08/21 17:06:16 Since this only ever does declarative script injec
Mark Dittmer 2014/08/23 12:21:38 Done.
354 script_id,
355 web_frame,
356 tab_id,
357 UserScript::BROWSER_DRIVEN,
358 url,
359 extension);
360 if (injection.get()) {
361 ScriptsRunInfo scripts_run_info;
362 // TODO(markdittmer): Use return value of TryToInject for error handling.
363 injection->TryToInject(UserScript::BROWSER_DRIVEN,
364 extension,
365 &scripts_run_info);
366 scripts_run_info.LogRun(web_frame, UserScript::BROWSER_DRIVEN);
367 }
368 }
369
326 void ScriptInjectionManager::HandlePermitScriptInjection(int64 request_id) { 370 void ScriptInjectionManager::HandlePermitScriptInjection(int64 request_id) {
327 ScopedVector<ScriptInjection>::iterator iter = 371 ScopedVector<ScriptInjection>::iterator iter =
328 pending_injections_.begin(); 372 pending_injections_.begin();
329 for (; iter != pending_injections_.end(); ++iter) { 373 for (; iter != pending_injections_.end(); ++iter) {
330 if ((*iter)->request_id() == request_id) 374 if ((*iter)->request_id() == request_id)
331 break; 375 break;
332 } 376 }
333 if (iter == pending_injections_.end()) 377 if (iter == pending_injections_.end())
334 return; 378 return;
335 379
336 // At this point, because the request is present in pending_injections_, we 380 // At this point, because the request is present in pending_injections_, we
337 // know that this is the same page that issued the request (otherwise, 381 // know that this is the same page that issued the request (otherwise,
338 // RVOHelper's DidStartProvisionalLoad callback would have caused it to be 382 // RVOHelper's DidStartProvisionalLoad callback would have caused it to be
339 // cleared out). 383 // cleared out).
340 384
341 scoped_ptr<ScriptInjection> injection(*iter); 385 scoped_ptr<ScriptInjection> injection(*iter);
342 pending_injections_.weak_erase(iter); 386 pending_injections_.weak_erase(iter);
343 387
344 ScriptsRunInfo scripts_run_info; 388 ScriptsRunInfo scripts_run_info;
345 if (injection->OnPermissionGranted(extensions_->GetByID( 389 if (injection->OnPermissionGranted(extensions_->GetByID(
346 injection->extension_id()), 390 injection->extension_id()),
347 &scripts_run_info)) { 391 &scripts_run_info)) {
348 scripts_run_info.LogRun(injection->web_frame(), UserScript::RUN_DEFERRED); 392 scripts_run_info.LogRun(injection->web_frame(), UserScript::RUN_DEFERRED);
349 } 393 }
350 } 394 }
351 395
352 } // namespace extensions 396 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698