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

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

Issue 934763003: Refactoring: de-couple Extensions from "script injection System" [render side]:3 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@decouple_brower_isolated_world_routingid_user_script_1
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.h" 5 #include "extensions/renderer/script_injection.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 } 106 }
107 107
108 // static 108 // static
109 void ScriptInjection::RemoveIsolatedWorld(const std::string& host_id) { 109 void ScriptInjection::RemoveIsolatedWorld(const std::string& host_id) {
110 g_isolated_worlds.Get().erase(host_id); 110 g_isolated_worlds.Get().erase(host_id);
111 } 111 }
112 112
113 ScriptInjection::ScriptInjection( 113 ScriptInjection::ScriptInjection(
114 scoped_ptr<ScriptInjector> injector, 114 scoped_ptr<ScriptInjector> injector,
115 blink::WebLocalFrame* web_frame, 115 blink::WebLocalFrame* web_frame,
116 const HostID& host_id, 116 scoped_ptr<const InjectionHost> injection_host,
117 const UserScript::ConsumerInstanceType& consumer_instance_type, 117 const UserScript::ConsumerInstanceType& consumer_instance_type,
118 UserScript::RunLocation run_location, 118 UserScript::RunLocation run_location,
119 int tab_id) 119 int tab_id)
120 : injector_(injector.Pass()), 120 : injector_(injector.Pass()),
121 web_frame_(web_frame), 121 web_frame_(web_frame),
122 host_id_(host_id), 122 injection_host_(injection_host.Pass()),
123 consumer_instance_type_(consumer_instance_type), 123 consumer_instance_type_(consumer_instance_type),
124 run_location_(run_location), 124 run_location_(run_location),
125 tab_id_(tab_id), 125 tab_id_(tab_id),
126 request_id_(kInvalidRequestId), 126 request_id_(kInvalidRequestId),
127 complete_(false) { 127 complete_(false) {
128 CHECK(injection_host_.get());
128 } 129 }
129 130
130 ScriptInjection::~ScriptInjection() { 131 ScriptInjection::~ScriptInjection() {
131 if (!complete_) 132 if (!complete_)
132 injector_->OnWillNotInject(ScriptInjector::WONT_INJECT); 133 injector_->OnWillNotInject(ScriptInjector::WONT_INJECT);
133 } 134 }
134 135
135 bool ScriptInjection::TryToInject(UserScript::RunLocation current_location, 136 bool ScriptInjection::TryToInject(UserScript::RunLocation current_location,
136 const InjectionHost* injection_host, 137 const InjectionHost* injection_host,
137 ScriptsRunInfo* scripts_run_info) { 138 ScriptsRunInfo* scripts_run_info) {
(...skipping 30 matching lines...) Expand all
168 ScriptsRunInfo* scripts_run_info) { 169 ScriptsRunInfo* scripts_run_info) {
169 if (!injection_host) { 170 if (!injection_host) {
170 NotifyWillNotInject(ScriptInjector::EXTENSION_REMOVED); 171 NotifyWillNotInject(ScriptInjector::EXTENSION_REMOVED);
171 return false; 172 return false;
172 } 173 }
173 174
174 Inject(injection_host, scripts_run_info); 175 Inject(injection_host, scripts_run_info);
175 return true; 176 return true;
176 } 177 }
177 178
179 const InjectionHost* ScriptInjection::GetInjectionHost() {
180 if (injection_host_->IsGone())
Devlin 2015/02/17 18:56:52 This won't really work, because you never update t
Xi Han 2015/02/18 21:11:46 As discussed offline, the Dispatcher will notify t
181 return nullptr;
182 return injection_host_.get();
183 }
184
178 void ScriptInjection::RequestPermission() { 185 void ScriptInjection::RequestPermission() {
179 if (host_id_.type() != HostID::EXTENSIONS) 186 if (host_id().type() != HostID::EXTENSIONS)
180 return; 187 return;
181 188
182 content::RenderView* render_view = 189 content::RenderView* render_view =
183 content::RenderView::FromWebView(web_frame()->top()->view()); 190 content::RenderView::FromWebView(web_frame()->top()->view());
184 191
185 // If we are just notifying the browser of the injection, then send an 192 // If we are just notifying the browser of the injection, then send an
186 // invalid request (which is treated like a notification). 193 // invalid request (which is treated like a notification).
187 request_id_ = consumer_instance_type_ == 194 request_id_ = consumer_instance_type_ ==
188 UserScript::ConsumerInstanceType::WEBVIEW || 195 UserScript::ConsumerInstanceType::WEBVIEW ||
189 ShouldNotifyBrowserOfInjections() ? kInvalidRequestId 196 ShouldNotifyBrowserOfInjections() ? kInvalidRequestId
190 : g_next_pending_id++; 197 : g_next_pending_id++;
191 render_view->Send(new ExtensionHostMsg_RequestScriptInjectionPermission( 198 render_view->Send(new ExtensionHostMsg_RequestScriptInjectionPermission(
192 render_view->GetRoutingID(), 199 render_view->GetRoutingID(),
193 host_id_.id(), 200 host_id().id(),
194 injector_->script_type(), 201 injector_->script_type(),
195 request_id_)); 202 request_id_));
196 } 203 }
197 204
198 void ScriptInjection::NotifyWillNotInject( 205 void ScriptInjection::NotifyWillNotInject(
199 ScriptInjector::InjectFailureReason reason) { 206 ScriptInjector::InjectFailureReason reason) {
200 complete_ = true; 207 complete_ = true;
201 injector_->OnWillNotInject(reason); 208 injector_->OnWillNotInject(reason);
202 } 209 }
203 210
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 std::vector<std::string> css_sources = 330 std::vector<std::string> css_sources =
324 injector_->GetCssSources(run_location_); 331 injector_->GetCssSources(run_location_);
325 for (std::vector<std::string>::const_iterator iter = css_sources.begin(); 332 for (std::vector<std::string>::const_iterator iter = css_sources.begin();
326 iter != css_sources.end(); 333 iter != css_sources.end();
327 ++iter) { 334 ++iter) {
328 frame->document().insertStyleSheet(blink::WebString::fromUTF8(*iter)); 335 frame->document().insertStyleSheet(blink::WebString::fromUTF8(*iter));
329 } 336 }
330 } 337 }
331 338
332 } // namespace extensions 339 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698