| 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 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 if (!main_frame) { | 427 if (!main_frame) { |
| 427 render_view->Send( | 428 render_view->Send( |
| 428 new ExtensionHostMsg_ExecuteCodeFinished(render_view->GetRoutingID(), | 429 new ExtensionHostMsg_ExecuteCodeFinished(render_view->GetRoutingID(), |
| 429 params.request_id, | 430 params.request_id, |
| 430 "No main frame", | 431 "No main frame", |
| 431 GURL(std::string()), | 432 GURL(std::string()), |
| 432 base::ListValue())); | 433 base::ListValue())); |
| 433 return; | 434 return; |
| 434 } | 435 } |
| 435 | 436 |
| 436 scoped_ptr<const ExtensionInjectionHost> extension_injection_host = | 437 scoped_ptr<const InjectionHost> injection_host; |
| 437 ExtensionInjectionHost::Create(params.extension_id, extensions_); | 438 if (params.host_type == HostID::EXTENSIONS) { |
| 438 | 439 injection_host = |
| 439 if (!extension_injection_host) | 440 ExtensionInjectionHost::Create(params.host_id, extensions_).Pass(); |
| 440 return; | 441 if (!injection_host) |
| 442 return; |
| 443 } else if (params.host_type == HostID::WEBUI) { |
| 444 injection_host = WebUIInjectionHost::Create( |
| 445 HostID(params.host_type, params.host_id)).Pass(); |
| 446 } |
| 441 | 447 |
| 442 scoped_ptr<ScriptInjection> injection(new ScriptInjection( | 448 scoped_ptr<ScriptInjection> injection(new ScriptInjection( |
| 443 scoped_ptr<ScriptInjector>( | 449 scoped_ptr<ScriptInjector>( |
| 444 new ProgrammaticScriptInjector(params, main_frame)), | 450 new ProgrammaticScriptInjector(params, main_frame)), |
| 445 main_frame, | 451 main_frame, |
| 446 extension_injection_host.Pass(), | 452 injection_host.Pass(), |
| 447 params.is_web_view ? UserScript::ConsumerInstanceType::WEBVIEW | 453 params.is_web_view ? UserScript::ConsumerInstanceType::WEBVIEW |
| 448 : UserScript::ConsumerInstanceType::TAB, | 454 : UserScript::ConsumerInstanceType::TAB, |
| 449 static_cast<UserScript::RunLocation>(params.run_at), | 455 static_cast<UserScript::RunLocation>(params.run_at), |
| 450 ExtensionHelper::Get(render_view)->tab_id())); | 456 ExtensionHelper::Get(render_view)->tab_id())); |
| 451 | 457 |
| 452 ScriptsRunInfo scripts_run_info; | 458 ScriptsRunInfo scripts_run_info; |
| 453 FrameStatusMap::const_iterator iter = frame_statuses_.find(main_frame); | 459 FrameStatusMap::const_iterator iter = frame_statuses_.find(main_frame); |
| 454 | 460 |
| 455 if (!injection->TryToInject( | 461 if (!injection->TryToInject( |
| 456 iter == frame_statuses_.end() ? UserScript::UNDEFINED : iter->second, | 462 iter == frame_statuses_.end() ? UserScript::UNDEFINED : iter->second, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 scoped_ptr<ScriptInjection> injection(*iter); | 509 scoped_ptr<ScriptInjection> injection(*iter); |
| 504 pending_injections_.weak_erase(iter); | 510 pending_injections_.weak_erase(iter); |
| 505 | 511 |
| 506 ScriptsRunInfo scripts_run_info; | 512 ScriptsRunInfo scripts_run_info; |
| 507 if (injection->OnPermissionGranted(&scripts_run_info)) { | 513 if (injection->OnPermissionGranted(&scripts_run_info)) { |
| 508 scripts_run_info.LogRun(injection->web_frame(), UserScript::RUN_DEFERRED); | 514 scripts_run_info.LogRun(injection->web_frame(), UserScript::RUN_DEFERRED); |
| 509 } | 515 } |
| 510 } | 516 } |
| 511 | 517 |
| 512 } // namespace extensions | 518 } // namespace extensions |
| OLD | NEW |