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

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

Issue 942533003: Enable <webview>.executeScript outside of Apps and Extensions [1] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@decouple_brower_isolated_world_routingid_user_script_UserScriptSet_non_hostset_2
Patch Set: Created 5 years, 10 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/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 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 if (!main_frame) { 428 if (!main_frame) {
428 render_view->Send( 429 render_view->Send(
429 new ExtensionHostMsg_ExecuteCodeFinished(render_view->GetRoutingID(), 430 new ExtensionHostMsg_ExecuteCodeFinished(render_view->GetRoutingID(),
430 params.request_id, 431 params.request_id,
431 "No main frame", 432 "No main frame",
432 GURL(std::string()), 433 GURL(std::string()),
433 base::ListValue())); 434 base::ListValue()));
434 return; 435 return;
435 } 436 }
436 437
437 scoped_ptr<const ExtensionInjectionHost> extension_injection_host = 438 scoped_ptr<const InjectionHost> injection_host;
438 ExtensionInjectionHost::Create(params.extension_id, extensions_); 439 if (params.host_type == HostID::EXTENSIONS) {
439 440 injection_host = ExtensionInjectionHost::Create(params.host_id,
440 if (!extension_injection_host) 441 extensions_);
441 return; 442 if (!injection_host)
443 return;
444 } else if (params.host_type == HostID::WEBUI) {
445 injection_host.reset(
446 new WebUIInjectionHost(HostID(params.host_type, params.host_id)));
447 }
442 448
443 scoped_ptr<ScriptInjection> injection(new ScriptInjection( 449 scoped_ptr<ScriptInjection> injection(new ScriptInjection(
444 scoped_ptr<ScriptInjector>( 450 scoped_ptr<ScriptInjector>(
445 new ProgrammaticScriptInjector(params, main_frame)), 451 new ProgrammaticScriptInjector(params, main_frame)),
446 main_frame, 452 main_frame,
447 extension_injection_host.Pass(), 453 injection_host.Pass(),
448 params.is_web_view ? UserScript::ConsumerInstanceType::WEBVIEW 454 params.is_web_view ? UserScript::ConsumerInstanceType::WEBVIEW
449 : UserScript::ConsumerInstanceType::TAB, 455 : UserScript::ConsumerInstanceType::TAB,
450 static_cast<UserScript::RunLocation>(params.run_at), 456 static_cast<UserScript::RunLocation>(params.run_at),
451 ExtensionHelper::Get(render_view)->tab_id())); 457 ExtensionHelper::Get(render_view)->tab_id()));
452 458
453 ScriptsRunInfo scripts_run_info; 459 ScriptsRunInfo scripts_run_info;
454 FrameStatusMap::const_iterator iter = frame_statuses_.find(main_frame); 460 FrameStatusMap::const_iterator iter = frame_statuses_.find(main_frame);
455 461
456 if (!injection->TryToInject( 462 if (!injection->TryToInject(
457 iter == frame_statuses_.end() ? UserScript::UNDEFINED : iter->second, 463 iter == frame_statuses_.end() ? UserScript::UNDEFINED : iter->second,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 scoped_ptr<ScriptInjection> injection(*iter); 510 scoped_ptr<ScriptInjection> injection(*iter);
505 pending_injections_.weak_erase(iter); 511 pending_injections_.weak_erase(iter);
506 512
507 ScriptsRunInfo scripts_run_info; 513 ScriptsRunInfo scripts_run_info;
508 if (injection->OnPermissionGranted(&scripts_run_info)) { 514 if (injection->OnPermissionGranted(&scripts_run_info)) {
509 scripts_run_info.LogRun(injection->web_frame(), UserScript::RUN_DEFERRED); 515 scripts_run_info.LogRun(injection->web_frame(), UserScript::RUN_DEFERRED);
510 } 516 }
511 } 517 }
512 518
513 } // namespace extensions 519 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698