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

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

Issue 906493004: Refactoring: de-couple Extensions from "script injection System" [render side]:2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@decouple_brower_isolated_world_1
Patch Set: Rebase. 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 keys_to_delete.insert(key); 116 keys_to_delete.insert(key);
117 } 117 }
118 for (auto& key : keys_to_delete) 118 for (auto& key : keys_to_delete)
119 isolated_worlds.erase(key); 119 isolated_worlds.erase(key);
120 } 120 }
121 121
122 ScriptInjection::ScriptInjection( 122 ScriptInjection::ScriptInjection(
123 scoped_ptr<ScriptInjector> injector, 123 scoped_ptr<ScriptInjector> injector,
124 blink::WebLocalFrame* web_frame, 124 blink::WebLocalFrame* web_frame,
125 const HostID& host_id, 125 const HostID& host_id,
126 int instance_id, 126 const ConsumerInstanceInfo& consumer_instance_info,
127 UserScript::RunLocation run_location, 127 UserScript::RunLocation run_location,
128 int tab_id) 128 int tab_id)
129 : injector_(injector.Pass()), 129 : injector_(injector.Pass()),
130 web_frame_(web_frame), 130 web_frame_(web_frame),
131 host_id_(host_id), 131 host_id_(host_id),
132 instance_id_(instance_id), 132 consumer_instance_info_(consumer_instance_info),
133 run_location_(run_location), 133 run_location_(run_location),
134 tab_id_(tab_id), 134 tab_id_(tab_id),
135 request_id_(kInvalidRequestId), 135 request_id_(kInvalidRequestId),
136 complete_(false) { 136 complete_(false) {
137 } 137 }
138 138
139 ScriptInjection::~ScriptInjection() { 139 ScriptInjection::~ScriptInjection() {
140 if (!complete_) 140 if (!complete_)
141 injector_->OnWillNotInject(ScriptInjector::WONT_INJECT); 141 injector_->OnWillNotInject(ScriptInjector::WONT_INJECT);
142 } 142 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 ScriptsRunInfo* scripts_run_info) { 177 ScriptsRunInfo* scripts_run_info) {
178 if (!injection_host) { 178 if (!injection_host) {
179 NotifyWillNotInject(ScriptInjector::EXTENSION_REMOVED); 179 NotifyWillNotInject(ScriptInjector::EXTENSION_REMOVED);
180 return false; 180 return false;
181 } 181 }
182 182
183 Inject(injection_host, scripts_run_info); 183 Inject(injection_host, scripts_run_info);
184 return true; 184 return true;
185 } 185 }
186 186
187 void ScriptInjection::RequestPermission() { 187 void ScriptInjection::RequestPermission() {
Devlin 2015/02/11 20:29:01 This should be a no-op if this is from a webui.
Xi Han 2015/02/11 21:57:24 Oh, I see. Even ExtensionHostMsg_RequestScriptInje
188 content::RenderView* render_view = 188 content::RenderView* render_view =
189 content::RenderView::FromWebView(web_frame()->top()->view()); 189 content::RenderView::FromWebView(web_frame()->top()->view());
190 190
191 // If we are just notifying the browser of the injection, then send an 191 // If we are just notifying the browser of the injection, then send an
192 // invalid request (which is treated like a notification). 192 // invalid request (which is treated like a notification).
193 request_id_ = ShouldNotifyBrowserOfInjections() ? kInvalidRequestId 193 request_id_ =
194 : g_next_pending_id++; 194 consumer_instance_info_.type() == ConsumerInstanceInfo::WEBVIEW ||
195 ShouldNotifyBrowserOfInjections()
196 ? kInvalidRequestId
197 : g_next_pending_id++;
195 render_view->Send(new ExtensionHostMsg_RequestScriptInjectionPermission( 198 render_view->Send(new ExtensionHostMsg_RequestScriptInjectionPermission(
196 render_view->GetRoutingID(), 199 render_view->GetRoutingID(),
197 host_id_.id(), 200 host_id_.id(),
198 injector_->script_type(), 201 injector_->script_type(),
199 request_id_)); 202 request_id_));
200 } 203 }
201 204
202 void ScriptInjection::NotifyWillNotInject( 205 void ScriptInjection::NotifyWillNotInject(
203 ScriptInjector::InjectFailureReason reason) { 206 ScriptInjector::InjectFailureReason reason) {
204 complete_ = true; 207 complete_ = true;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 268
266 void ScriptInjection::InjectJs(const InjectionHost* injection_host, 269 void ScriptInjection::InjectJs(const InjectionHost* injection_host,
267 blink::WebLocalFrame* frame, 270 blink::WebLocalFrame* frame,
268 base::ListValue* execution_results) { 271 base::ListValue* execution_results) {
269 std::vector<blink::WebScriptSource> sources = 272 std::vector<blink::WebScriptSource> sources =
270 injector_->GetJsSources(run_location_); 273 injector_->GetJsSources(run_location_);
271 bool in_main_world = injector_->ShouldExecuteInMainWorld(); 274 bool in_main_world = injector_->ShouldExecuteInMainWorld();
272 int world_id = in_main_world 275 int world_id = in_main_world
273 ? DOMActivityLogger::kMainWorldId 276 ? DOMActivityLogger::kMainWorldId
274 : GetIsolatedWorldIdForInstance( 277 : GetIsolatedWorldIdForInstance(
275 injection_host, instance_id_, frame); 278 injection_host, consumer_instance_info_.id(), frame);
276 bool expects_results = injector_->ExpectsResults(); 279 bool expects_results = injector_->ExpectsResults();
277 280
278 base::ElapsedTimer exec_timer; 281 base::ElapsedTimer exec_timer;
279 if (injection_host->id().type() == HostID::EXTENSIONS) 282 if (injection_host->id().type() == HostID::EXTENSIONS)
280 DOMActivityLogger::AttachToWorld(world_id, injection_host->id().id()); 283 DOMActivityLogger::AttachToWorld(world_id, injection_host->id().id());
281 v8::HandleScope scope(v8::Isolate::GetCurrent()); 284 v8::HandleScope scope(v8::Isolate::GetCurrent());
282 v8::Local<v8::Value> script_value; 285 v8::Local<v8::Value> script_value;
283 if (in_main_world) { 286 if (in_main_world) {
284 // We only inject in the main world for javascript: urls. 287 // We only inject in the main world for javascript: urls.
285 DCHECK_EQ(1u, sources.size()); 288 DCHECK_EQ(1u, sources.size());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 std::vector<std::string> css_sources = 330 std::vector<std::string> css_sources =
328 injector_->GetCssSources(run_location_); 331 injector_->GetCssSources(run_location_);
329 for (std::vector<std::string>::const_iterator iter = css_sources.begin(); 332 for (std::vector<std::string>::const_iterator iter = css_sources.begin();
330 iter != css_sources.end(); 333 iter != css_sources.end();
331 ++iter) { 334 ++iter) {
332 frame->document().insertStyleSheet(blink::WebString::fromUTF8(*iter)); 335 frame->document().insertStyleSheet(blink::WebString::fromUTF8(*iter));
333 } 336 }
334 } 337 }
335 338
336 } // namespace extensions 339 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698