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/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "content/public/renderer/render_thread.h" | 11 #include "content/public/renderer/render_thread.h" |
12 #include "content/public/renderer/render_view.h" | 12 #include "content/public/renderer/render_view.h" |
13 #include "content/public/renderer/render_view_observer.h" | 13 #include "content/public/renderer/render_view_observer.h" |
14 #include "extensions/common/extension.h" | 14 #include "extensions/common/extension.h" |
15 #include "extensions/common/extension_messages.h" | 15 #include "extensions/common/extension_messages.h" |
16 #include "extensions/common/extension_set.h" | 16 #include "extensions/common/extension_set.h" |
17 #include "extensions/renderer/extension_helper.h" | 17 #include "extensions/renderer/extension_helper.h" |
18 #include "extensions/renderer/extension_injection_host.h" | 18 #include "extensions/renderer/extension_injection_host.h" |
19 #include "extensions/renderer/programmatic_script_injector.h" | 19 #include "extensions/renderer/programmatic_script_injector.h" |
20 #include "extensions/renderer/script_injection.h" | 20 #include "extensions/renderer/script_injection.h" |
21 #include "extensions/renderer/scripts_run_info.h" | 21 #include "extensions/renderer/scripts_run_info.h" |
| 22 #include "extensions/renderer/web_ui_injection_host.h" |
22 #include "ipc/ipc_message_macros.h" | 23 #include "ipc/ipc_message_macros.h" |
23 #include "third_party/WebKit/public/web/WebDocument.h" | 24 #include "third_party/WebKit/public/web/WebDocument.h" |
24 #include "third_party/WebKit/public/web/WebFrame.h" | 25 #include "third_party/WebKit/public/web/WebFrame.h" |
25 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 26 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
26 #include "third_party/WebKit/public/web/WebView.h" | 27 #include "third_party/WebKit/public/web/WebView.h" |
27 #include "url/gurl.h" | 28 #include "url/gurl.h" |
28 | 29 |
29 namespace extensions { | 30 namespace extensions { |
30 | 31 |
31 namespace { | 32 namespace { |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 if (!main_frame) { | 423 if (!main_frame) { |
423 render_view->Send( | 424 render_view->Send( |
424 new ExtensionHostMsg_ExecuteCodeFinished(render_view->GetRoutingID(), | 425 new ExtensionHostMsg_ExecuteCodeFinished(render_view->GetRoutingID(), |
425 params.request_id, | 426 params.request_id, |
426 "No main frame", | 427 "No main frame", |
427 GURL(std::string()), | 428 GURL(std::string()), |
428 base::ListValue())); | 429 base::ListValue())); |
429 return; | 430 return; |
430 } | 431 } |
431 | 432 |
432 scoped_ptr<const ExtensionInjectionHost> extension_injection_host = | 433 scoped_ptr<const InjectionHost> injection_host; |
433 ExtensionInjectionHost::Create(params.extension_id, extensions_); | 434 if (params.host_type == HostID::EXTENSIONS) { |
434 | 435 injection_host = |
435 if (!extension_injection_host.get()) | 436 ExtensionInjectionHost::Create(params.host_id, extensions_).Pass(); |
436 return; | 437 if (!injection_host.get()) |
| 438 return; |
| 439 } else if (params.host_type == HostID::WEBUI) { |
| 440 injection_host = WebUIInjectionHost::Create( |
| 441 HostID(params.host_type, params.host_id)).Pass(); |
| 442 } |
437 | 443 |
438 scoped_ptr<ScriptInjection> injection(new ScriptInjection( | 444 scoped_ptr<ScriptInjection> injection(new ScriptInjection( |
439 scoped_ptr<ScriptInjector>( | 445 scoped_ptr<ScriptInjector>( |
440 new ProgrammaticScriptInjector(params, main_frame)), | 446 new ProgrammaticScriptInjector(params, main_frame)), |
441 main_frame, | 447 main_frame, |
442 extension_injection_host.Pass(), | 448 injection_host.Pass(), |
443 params.is_web_view ? UserScript::ConsumerInstanceType::WEBVIEW | 449 params.is_web_view ? UserScript::ConsumerInstanceType::WEBVIEW |
444 : UserScript::ConsumerInstanceType::TAB, | 450 : UserScript::ConsumerInstanceType::TAB, |
445 static_cast<UserScript::RunLocation>(params.run_at), | 451 static_cast<UserScript::RunLocation>(params.run_at), |
446 ExtensionHelper::Get(render_view)->tab_id())); | 452 ExtensionHelper::Get(render_view)->tab_id())); |
447 | 453 |
448 ScriptsRunInfo scripts_run_info; | 454 ScriptsRunInfo scripts_run_info; |
449 FrameStatusMap::const_iterator iter = frame_statuses_.find(main_frame); | 455 FrameStatusMap::const_iterator iter = frame_statuses_.find(main_frame); |
450 | 456 |
451 if (!injection->TryToInject( | 457 if (!injection->TryToInject( |
452 iter == frame_statuses_.end() ? UserScript::UNDEFINED : iter->second, | 458 iter == frame_statuses_.end() ? UserScript::UNDEFINED : iter->second, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 scoped_ptr<ScriptInjection> injection(*iter); | 504 scoped_ptr<ScriptInjection> injection(*iter); |
499 pending_injections_.weak_erase(iter); | 505 pending_injections_.weak_erase(iter); |
500 | 506 |
501 ScriptsRunInfo scripts_run_info; | 507 ScriptsRunInfo scripts_run_info; |
502 if (injection->OnPermissionGranted(&scripts_run_info)) { | 508 if (injection->OnPermissionGranted(&scripts_run_info)) { |
503 scripts_run_info.LogRun(injection->web_frame(), UserScript::RUN_DEFERRED); | 509 scripts_run_info.LogRun(injection->web_frame(), UserScript::RUN_DEFERRED); |
504 } | 510 } |
505 } | 511 } |
506 | 512 |
507 } // namespace extensions | 513 } // namespace extensions |
OLD | NEW |