| 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 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 if (!main_frame) { | 400 if (!main_frame) { |
| 400 render_view->Send( | 401 render_view->Send( |
| 401 new ExtensionHostMsg_ExecuteCodeFinished(render_view->GetRoutingID(), | 402 new ExtensionHostMsg_ExecuteCodeFinished(render_view->GetRoutingID(), |
| 402 params.request_id, | 403 params.request_id, |
| 403 "No main frame", | 404 "No main frame", |
| 404 GURL(std::string()), | 405 GURL(std::string()), |
| 405 base::ListValue())); | 406 base::ListValue())); |
| 406 return; | 407 return; |
| 407 } | 408 } |
| 408 | 409 |
| 409 scoped_ptr<const ExtensionInjectionHost> extension_injection_host = | 410 scoped_ptr<const InjectionHost> injection_host; |
| 410 ExtensionInjectionHost::Create(params.extension_id, extensions_); | 411 if (params.host_id.type() == HostID::EXTENSIONS) { |
| 411 | 412 injection_host = ExtensionInjectionHost::Create(params.host_id.id(), |
| 412 if (!extension_injection_host) | 413 extensions_); |
| 413 return; | 414 if (!injection_host) |
| 415 return; |
| 416 } else if (params.host_id.type() == HostID::WEBUI) { |
| 417 injection_host.reset( |
| 418 new WebUIInjectionHost(params.host_id)); |
| 419 } |
| 414 | 420 |
| 415 scoped_ptr<ScriptInjection> injection(new ScriptInjection( | 421 scoped_ptr<ScriptInjection> injection(new ScriptInjection( |
| 416 scoped_ptr<ScriptInjector>( | 422 scoped_ptr<ScriptInjector>( |
| 417 new ProgrammaticScriptInjector(params, main_frame)), | 423 new ProgrammaticScriptInjector(params, main_frame)), |
| 418 main_frame, | 424 main_frame, |
| 419 extension_injection_host.Pass(), | 425 injection_host.Pass(), |
| 420 static_cast<UserScript::RunLocation>(params.run_at), | 426 static_cast<UserScript::RunLocation>(params.run_at), |
| 421 ExtensionHelper::Get(render_view)->tab_id())); | 427 ExtensionHelper::Get(render_view)->tab_id())); |
| 422 | 428 |
| 423 ScriptsRunInfo scripts_run_info; | 429 ScriptsRunInfo scripts_run_info; |
| 424 FrameStatusMap::const_iterator iter = frame_statuses_.find(main_frame); | 430 FrameStatusMap::const_iterator iter = frame_statuses_.find(main_frame); |
| 425 | 431 |
| 426 TryToInject( | 432 TryToInject( |
| 427 injection.Pass(), | 433 injection.Pass(), |
| 428 iter == frame_statuses_.end() ? UserScript::UNDEFINED : iter->second, | 434 iter == frame_statuses_.end() ? UserScript::UNDEFINED : iter->second, |
| 429 &scripts_run_info); | 435 &scripts_run_info); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 | 483 |
| 478 ScriptsRunInfo scripts_run_info; | 484 ScriptsRunInfo scripts_run_info; |
| 479 ScriptInjection::InjectionResult res = injection->OnPermissionGranted( | 485 ScriptInjection::InjectionResult res = injection->OnPermissionGranted( |
| 480 &scripts_run_info); | 486 &scripts_run_info); |
| 481 if (res == ScriptInjection::INJECTION_BLOCKED) | 487 if (res == ScriptInjection::INJECTION_BLOCKED) |
| 482 running_injections_.push_back(injection.Pass()); | 488 running_injections_.push_back(injection.Pass()); |
| 483 scripts_run_info.LogRun(injection->web_frame(), UserScript::RUN_DEFERRED); | 489 scripts_run_info.LogRun(injection->web_frame(), UserScript::RUN_DEFERRED); |
| 484 } | 490 } |
| 485 | 491 |
| 486 } // namespace extensions | 492 } // namespace extensions |
| OLD | NEW |