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.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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 const HostID& host_id, |
117 const UserScript::ConsumerInstanceType& consumer_instance_type, | |
117 UserScript::RunLocation run_location, | 118 UserScript::RunLocation run_location, |
118 int tab_id) | 119 int tab_id) |
119 : injector_(injector.Pass()), | 120 : injector_(injector.Pass()), |
120 web_frame_(web_frame), | 121 web_frame_(web_frame), |
121 host_id_(host_id), | 122 host_id_(host_id), |
123 consumer_instance_type_(consumer_instance_type), | |
122 run_location_(run_location), | 124 run_location_(run_location), |
123 tab_id_(tab_id), | 125 tab_id_(tab_id), |
124 request_id_(kInvalidRequestId), | 126 request_id_(kInvalidRequestId), |
125 complete_(false) { | 127 complete_(false) { |
126 } | 128 } |
127 | 129 |
128 ScriptInjection::~ScriptInjection() { | 130 ScriptInjection::~ScriptInjection() { |
129 if (!complete_) | 131 if (!complete_) |
130 injector_->OnWillNotInject(ScriptInjector::WONT_INJECT); | 132 injector_->OnWillNotInject(ScriptInjector::WONT_INJECT); |
131 } | 133 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 if (!injection_host) { | 169 if (!injection_host) { |
168 NotifyWillNotInject(ScriptInjector::EXTENSION_REMOVED); | 170 NotifyWillNotInject(ScriptInjector::EXTENSION_REMOVED); |
169 return false; | 171 return false; |
170 } | 172 } |
171 | 173 |
172 Inject(injection_host, scripts_run_info); | 174 Inject(injection_host, scripts_run_info); |
173 return true; | 175 return true; |
174 } | 176 } |
175 | 177 |
176 void ScriptInjection::RequestPermission() { | 178 void ScriptInjection::RequestPermission() { |
179 if (host_id_.type() != HostID::EXTENSIONS) | |
Devlin
2015/02/23 20:15:00
I think this needs to be rebased.
Xi Han
2015/02/24 16:19:55
Done.
| |
180 return; | |
181 | |
177 content::RenderView* render_view = | 182 content::RenderView* render_view = |
178 content::RenderView::FromWebView(web_frame()->top()->view()); | 183 content::RenderView::FromWebView(web_frame()->top()->view()); |
179 | 184 |
180 // If we are just notifying the browser of the injection, then send an | 185 // If we are just notifying the browser of the injection, then send an |
181 // invalid request (which is treated like a notification). | 186 // invalid request (which is treated like a notification). |
182 request_id_ = ShouldNotifyBrowserOfInjections() ? kInvalidRequestId | 187 request_id_ = consumer_instance_type_ == |
183 : g_next_pending_id++; | 188 UserScript::ConsumerInstanceType::WEBVIEW || |
189 ShouldNotifyBrowserOfInjections() ? kInvalidRequestId | |
190 : g_next_pending_id++; | |
184 render_view->Send(new ExtensionHostMsg_RequestScriptInjectionPermission( | 191 render_view->Send(new ExtensionHostMsg_RequestScriptInjectionPermission( |
185 render_view->GetRoutingID(), | 192 render_view->GetRoutingID(), |
186 host_id_.id(), | 193 host_id_.id(), |
187 injector_->script_type(), | 194 injector_->script_type(), |
188 request_id_)); | 195 request_id_)); |
189 } | 196 } |
190 | 197 |
191 void ScriptInjection::NotifyWillNotInject( | 198 void ScriptInjection::NotifyWillNotInject( |
192 ScriptInjector::InjectFailureReason reason) { | 199 ScriptInjector::InjectFailureReason reason) { |
193 complete_ = true; | 200 complete_ = true; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
315 std::vector<std::string> css_sources = | 322 std::vector<std::string> css_sources = |
316 injector_->GetCssSources(run_location_); | 323 injector_->GetCssSources(run_location_); |
317 for (std::vector<std::string>::const_iterator iter = css_sources.begin(); | 324 for (std::vector<std::string>::const_iterator iter = css_sources.begin(); |
318 iter != css_sources.end(); | 325 iter != css_sources.end(); |
319 ++iter) { | 326 ++iter) { |
320 frame->document().insertStyleSheet(blink::WebString::fromUTF8(*iter)); | 327 frame->document().insertStyleSheet(blink::WebString::fromUTF8(*iter)); |
321 } | 328 } |
322 } | 329 } |
323 | 330 |
324 } // namespace extensions | 331 } // namespace extensions |
OLD | NEW |