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" |
11 #include "base/timer/elapsed_timer.h" | 11 #include "base/timer/elapsed_timer.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "content/public/renderer/render_view.h" | 13 #include "content/public/renderer/render_view.h" |
14 #include "content/public/renderer/v8_value_converter.h" | 14 #include "content/public/renderer/v8_value_converter.h" |
15 #include "extensions/common/extension.h" | |
16 #include "extensions/common/extension_messages.h" | 15 #include "extensions/common/extension_messages.h" |
17 #include "extensions/common/feature_switch.h" | 16 #include "extensions/common/feature_switch.h" |
18 #include "extensions/common/manifest_handlers/csp_info.h" | 17 #include "extensions/common/manifest_handlers/csp_info.h" |
19 #include "extensions/renderer/dom_activity_logger.h" | 18 #include "extensions/renderer/dom_activity_logger.h" |
20 #include "extensions/renderer/extension_groups.h" | 19 #include "extensions/renderer/extension_groups.h" |
20 #include "extensions/renderer/extension_injection_host.h" | |
21 #include "extensions/renderer/extensions_renderer_client.h" | 21 #include "extensions/renderer/extensions_renderer_client.h" |
22 #include "third_party/WebKit/public/platform/WebString.h" | 22 #include "third_party/WebKit/public/platform/WebString.h" |
23 #include "third_party/WebKit/public/web/WebDocument.h" | 23 #include "third_party/WebKit/public/web/WebDocument.h" |
24 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 24 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
25 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" | 25 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" |
26 #include "third_party/WebKit/public/web/WebScriptSource.h" | 26 #include "third_party/WebKit/public/web/WebScriptSource.h" |
27 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 27 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
28 #include "url/gurl.h" | 28 #include "url/gurl.h" |
29 | 29 |
30 namespace extensions { | 30 namespace extensions { |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 typedef std::map<std::string, int> IsolatedWorldMap; | 34 using IsolatedWorldKey = std::pair<HostID, int>; |
Devlin
2015/02/11 00:00:48
Can webuis not share isolated world ids, as extens
Xi Han
2015/02/11 16:00:23
I believe webUIs don't share isolated world ids, e
Devlin
2015/02/11 20:19:44
Yeah, each webui should have its own unique isolat
Xi Han
2015/02/11 21:19:09
I am confused here. <webview> in webui should also
| |
35 using IsolatedWorldMap = std::map<IsolatedWorldKey, int>; | |
35 base::LazyInstance<IsolatedWorldMap> g_isolated_worlds = | 36 base::LazyInstance<IsolatedWorldMap> g_isolated_worlds = |
36 LAZY_INSTANCE_INITIALIZER; | 37 LAZY_INSTANCE_INITIALIZER; |
37 | 38 |
38 const int64 kInvalidRequestId = -1; | 39 const int64 kInvalidRequestId = -1; |
39 | 40 |
40 // The id of the next pending injection. | 41 // The id of the next pending injection. |
41 int64 g_next_pending_id = 0; | 42 int64 g_next_pending_id = 0; |
42 | 43 |
43 bool ShouldNotifyBrowserOfInjections() { | 44 bool ShouldNotifyBrowserOfInjections() { |
44 return !FeatureSwitch::scripts_require_action()->IsEnabled(); | 45 return !FeatureSwitch::scripts_require_action()->IsEnabled(); |
45 } | 46 } |
46 | 47 |
47 // Append all the child frames of |parent_frame| to |frames_vector|. | 48 // Append all the child frames of |parent_frame| to |frames_vector|. |
48 void AppendAllChildFrames(blink::WebFrame* parent_frame, | 49 void AppendAllChildFrames(blink::WebFrame* parent_frame, |
49 std::vector<blink::WebFrame*>* frames_vector) { | 50 std::vector<blink::WebFrame*>* frames_vector) { |
50 DCHECK(parent_frame); | 51 DCHECK(parent_frame); |
51 for (blink::WebFrame* child_frame = parent_frame->firstChild(); child_frame; | 52 for (blink::WebFrame* child_frame = parent_frame->firstChild(); child_frame; |
52 child_frame = child_frame->nextSibling()) { | 53 child_frame = child_frame->nextSibling()) { |
53 frames_vector->push_back(child_frame); | 54 frames_vector->push_back(child_frame); |
54 AppendAllChildFrames(child_frame, frames_vector); | 55 AppendAllChildFrames(child_frame, frames_vector); |
55 } | 56 } |
56 } | 57 } |
57 | 58 |
58 // Gets the isolated world ID to use for the given |extension| in the given | 59 // Gets the isolated world ID to use for the given |injection_host, instance_id| |
59 // |frame|. If no isolated world has been created for that extension, | 60 // in the given |frame|. If no isolated world has been created for that |
60 // one will be created and initialized. | 61 // |injection_host, instance_id| one will be created and initialized. |
61 int GetIsolatedWorldIdForExtension(const Extension* extension, | 62 int GetIsolatedWorldIdForInstance(const InjectionHost* injection_host, |
62 blink::WebLocalFrame* frame) { | 63 int instance_id, |
64 blink::WebLocalFrame* frame) { | |
63 static int g_next_isolated_world_id = | 65 static int g_next_isolated_world_id = |
64 ExtensionsRendererClient::Get()->GetLowestIsolatedWorldId(); | 66 ExtensionsRendererClient::Get()->GetLowestIsolatedWorldId(); |
65 | 67 |
66 IsolatedWorldMap& isolated_worlds = g_isolated_worlds.Get(); | 68 IsolatedWorldMap& isolated_worlds = g_isolated_worlds.Get(); |
67 | 69 |
68 int id = 0; | 70 int id = 0; |
69 IsolatedWorldMap::iterator iter = isolated_worlds.find(extension->id()); | 71 IsolatedWorldKey key(injection_host->id(), instance_id); |
72 IsolatedWorldMap::iterator iter = isolated_worlds.find(key); | |
70 if (iter != isolated_worlds.end()) { | 73 if (iter != isolated_worlds.end()) { |
71 id = iter->second; | 74 id = iter->second; |
72 } else { | 75 } else { |
73 id = g_next_isolated_world_id++; | 76 id = g_next_isolated_world_id++; |
74 // This map will tend to pile up over time, but realistically, you're never | 77 // This map will tend to pile up over time, but realistically, you're never |
75 // going to have enough extensions for it to matter. | 78 // going to have enough injection_hosts for it to matter. |
76 isolated_worlds[extension->id()] = id; | 79 isolated_worlds[key] = id; |
77 } | 80 } |
78 | 81 |
79 // We need to set the isolated world origin and CSP even if it's not a new | 82 // We need to set the isolated world origin and CSP even if it's not a new |
80 // world since these are stored per frame, and we might not have used this | 83 // world since these are stored per frame, and we might not have used this |
81 // isolated world in this frame before. | 84 // isolated world in this frame before. |
82 frame->setIsolatedWorldSecurityOrigin( | 85 frame->setIsolatedWorldSecurityOrigin( |
83 id, blink::WebSecurityOrigin::create(extension->url())); | 86 id, blink::WebSecurityOrigin::create(injection_host->url())); |
84 frame->setIsolatedWorldContentSecurityPolicy( | 87 frame->setIsolatedWorldContentSecurityPolicy( |
85 id, | 88 id, blink::WebString::fromUTF8( |
86 blink::WebString::fromUTF8(CSPInfo::GetContentSecurityPolicy(extension))); | 89 injection_host->GetContentSecurityPolicy())); |
87 frame->setIsolatedWorldHumanReadableName( | 90 frame->setIsolatedWorldHumanReadableName( |
88 id, | 91 id, blink::WebString::fromUTF8(injection_host->name())); |
89 blink::WebString::fromUTF8(extension->name())); | |
90 | 92 |
91 return id; | 93 return id; |
92 } | 94 } |
93 | 95 |
94 } // namespace | 96 } // namespace |
95 | 97 |
96 // static | 98 // static |
97 std::string ScriptInjection::GetExtensionIdForIsolatedWorld( | 99 HostID ScriptInjection::GetHostIdForIsolatedWorld(int isolated_world_id) { |
98 int isolated_world_id) { | 100 const IsolatedWorldMap& isolated_worlds = g_isolated_worlds.Get(); |
99 IsolatedWorldMap& isolated_worlds = g_isolated_worlds.Get(); | |
100 | 101 |
101 for (IsolatedWorldMap::iterator iter = isolated_worlds.begin(); | 102 for (const auto& kv : isolated_worlds) { |
102 iter != isolated_worlds.end(); | 103 if (kv.second == isolated_world_id) |
103 ++iter) { | 104 return kv.first.first; |
104 if (iter->second == isolated_world_id) | |
105 return iter->first; | |
106 } | 105 } |
107 return std::string(); | 106 return HostID(); |
108 } | 107 } |
109 | 108 |
110 // static | 109 // static |
111 void ScriptInjection::RemoveIsolatedWorld(const std::string& extension_id) { | 110 void ScriptInjection::RemoveIsolatedWorld(const HostID& host_id) { |
112 g_isolated_worlds.Get().erase(extension_id); | 111 std::set<IsolatedWorldKey> keys_to_delete; |
112 IsolatedWorldMap& isolated_worlds = g_isolated_worlds.Get(); | |
113 for (const auto& kv: isolated_worlds) { | |
114 const IsolatedWorldKey& key = kv.first; | |
115 if (key.first == host_id) | |
116 keys_to_delete.insert(key); | |
117 } | |
118 for (auto& key : keys_to_delete) | |
119 isolated_worlds.erase(key); | |
113 } | 120 } |
114 | 121 |
115 ScriptInjection::ScriptInjection( | 122 ScriptInjection::ScriptInjection( |
116 scoped_ptr<ScriptInjector> injector, | 123 scoped_ptr<ScriptInjector> injector, |
117 blink::WebLocalFrame* web_frame, | 124 blink::WebLocalFrame* web_frame, |
118 const std::string& extension_id, | 125 const HostID& host_id, |
126 int instance_id, | |
119 UserScript::RunLocation run_location, | 127 UserScript::RunLocation run_location, |
120 int tab_id) | 128 int tab_id) |
121 : injector_(injector.Pass()), | 129 : injector_(injector.Pass()), |
122 web_frame_(web_frame), | 130 web_frame_(web_frame), |
123 extension_id_(extension_id), | 131 host_id_(host_id), |
132 instance_id_(instance_id), | |
124 run_location_(run_location), | 133 run_location_(run_location), |
125 tab_id_(tab_id), | 134 tab_id_(tab_id), |
126 request_id_(kInvalidRequestId), | 135 request_id_(kInvalidRequestId), |
127 complete_(false) { | 136 complete_(false) { |
128 } | 137 } |
129 | 138 |
130 ScriptInjection::~ScriptInjection() { | 139 ScriptInjection::~ScriptInjection() { |
131 if (!complete_) | 140 if (!complete_) |
132 injector_->OnWillNotInject(ScriptInjector::WONT_INJECT); | 141 injector_->OnWillNotInject(ScriptInjector::WONT_INJECT); |
133 } | 142 } |
134 | 143 |
135 bool ScriptInjection::TryToInject(UserScript::RunLocation current_location, | 144 bool ScriptInjection::TryToInject(UserScript::RunLocation current_location, |
136 const Extension* extension, | 145 const InjectionHost* injection_host, |
137 ScriptsRunInfo* scripts_run_info) { | 146 ScriptsRunInfo* scripts_run_info) { |
138 if (current_location < run_location_) | 147 if (current_location < run_location_) |
139 return false; // Wait for the right location. | 148 return false; // Wait for the right location. |
140 | 149 |
141 if (request_id_ != kInvalidRequestId) | 150 if (request_id_ != kInvalidRequestId) |
142 return false; // We're waiting for permission right now, try again later. | 151 return false; // We're waiting for permission right now, try again later. |
143 | 152 |
144 if (!extension) { | 153 if (!injection_host) { |
145 NotifyWillNotInject(ScriptInjector::EXTENSION_REMOVED); | 154 NotifyWillNotInject(ScriptInjector::EXTENSION_REMOVED); |
146 return true; // We're done. | 155 return true; // We're done. |
147 } | 156 } |
148 | 157 |
149 switch (injector_->CanExecuteOnFrame( | 158 switch (injector_->CanExecuteOnFrame(injection_host, web_frame_, tab_id_, |
150 extension, web_frame_, tab_id_, web_frame_->top()->document().url())) { | 159 web_frame_->top()->document().url())) { |
151 case PermissionsData::ACCESS_DENIED: | 160 case PermissionsData::ACCESS_DENIED: |
152 NotifyWillNotInject(ScriptInjector::NOT_ALLOWED); | 161 NotifyWillNotInject(ScriptInjector::NOT_ALLOWED); |
153 return true; // We're done. | 162 return true; // We're done. |
154 case PermissionsData::ACCESS_WITHHELD: | 163 case PermissionsData::ACCESS_WITHHELD: |
155 RequestPermission(); | 164 RequestPermission(); |
156 return false; // Wait around for permission. | 165 return false; // Wait around for permission. |
157 case PermissionsData::ACCESS_ALLOWED: | 166 case PermissionsData::ACCESS_ALLOWED: |
158 Inject(extension, scripts_run_info); | 167 Inject(injection_host, scripts_run_info); |
159 return true; // We're done! | 168 return true; // We're done! |
160 } | 169 } |
161 | 170 |
162 // Some compilers don't realize that we always return from the switch() above. | 171 // Some compilers don't realize that we always return from the switch() above. |
163 // Make them happy. | 172 // Make them happy. |
164 return false; | 173 return false; |
165 } | 174 } |
166 | 175 |
167 bool ScriptInjection::OnPermissionGranted(const Extension* extension, | 176 bool ScriptInjection::OnPermissionGranted(const InjectionHost* injection_host, |
168 ScriptsRunInfo* scripts_run_info) { | 177 ScriptsRunInfo* scripts_run_info) { |
169 if (!extension) { | 178 if (!injection_host) { |
170 NotifyWillNotInject(ScriptInjector::EXTENSION_REMOVED); | 179 NotifyWillNotInject(ScriptInjector::EXTENSION_REMOVED); |
171 return false; | 180 return false; |
172 } | 181 } |
173 | 182 |
174 Inject(extension, scripts_run_info); | 183 Inject(injection_host, scripts_run_info); |
175 return true; | 184 return true; |
176 } | 185 } |
177 | 186 |
178 void ScriptInjection::RequestPermission() { | 187 void ScriptInjection::RequestPermission() { |
179 content::RenderView* render_view = | 188 content::RenderView* render_view = |
180 content::RenderView::FromWebView(web_frame()->top()->view()); | 189 content::RenderView::FromWebView(web_frame()->top()->view()); |
181 | 190 |
182 // 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 |
183 // invalid request (which is treated like a notification). | 192 // invalid request (which is treated like a notification). |
184 request_id_ = ShouldNotifyBrowserOfInjections() ? kInvalidRequestId | 193 request_id_ = ShouldNotifyBrowserOfInjections() ? kInvalidRequestId |
185 : g_next_pending_id++; | 194 : g_next_pending_id++; |
186 render_view->Send(new ExtensionHostMsg_RequestScriptInjectionPermission( | 195 render_view->Send(new ExtensionHostMsg_RequestScriptInjectionPermission( |
187 render_view->GetRoutingID(), | 196 render_view->GetRoutingID(), |
188 extension_id_, | 197 host_id_.id(), |
189 injector_->script_type(), | 198 injector_->script_type(), |
190 request_id_)); | 199 request_id_)); |
191 } | 200 } |
192 | 201 |
193 void ScriptInjection::NotifyWillNotInject( | 202 void ScriptInjection::NotifyWillNotInject( |
194 ScriptInjector::InjectFailureReason reason) { | 203 ScriptInjector::InjectFailureReason reason) { |
195 complete_ = true; | 204 complete_ = true; |
196 injector_->OnWillNotInject(reason); | 205 injector_->OnWillNotInject(reason); |
197 } | 206 } |
198 | 207 |
199 void ScriptInjection::Inject(const Extension* extension, | 208 void ScriptInjection::Inject(const InjectionHost* injection_host, |
200 ScriptsRunInfo* scripts_run_info) { | 209 ScriptsRunInfo* scripts_run_info) { |
201 DCHECK(extension); | 210 DCHECK(injection_host); |
202 DCHECK(scripts_run_info); | 211 DCHECK(scripts_run_info); |
203 DCHECK(!complete_); | 212 DCHECK(!complete_); |
204 | 213 |
205 if (ShouldNotifyBrowserOfInjections()) | 214 if (ShouldNotifyBrowserOfInjections()) |
206 RequestPermission(); | 215 RequestPermission(); |
207 | 216 |
208 std::vector<blink::WebFrame*> frame_vector; | 217 std::vector<blink::WebFrame*> frame_vector; |
209 frame_vector.push_back(web_frame_); | 218 frame_vector.push_back(web_frame_); |
210 if (injector_->ShouldExecuteInChildFrames()) | 219 if (injector_->ShouldExecuteInChildFrames()) |
211 AppendAllChildFrames(web_frame_, &frame_vector); | 220 AppendAllChildFrames(web_frame_, &frame_vector); |
(...skipping 10 matching lines...) Expand all Loading... | |
222 GURL top_url = web_frame_->top()->document().url(); | 231 GURL top_url = web_frame_->top()->document().url(); |
223 for (std::vector<blink::WebFrame*>::iterator iter = frame_vector.begin(); | 232 for (std::vector<blink::WebFrame*>::iterator iter = frame_vector.begin(); |
224 iter != frame_vector.end(); | 233 iter != frame_vector.end(); |
225 ++iter) { | 234 ++iter) { |
226 // TODO(dcheng): Unfortunately, the code as written won't work in an OOPI | 235 // TODO(dcheng): Unfortunately, the code as written won't work in an OOPI |
227 // world. This is just a temporary hack to make things compile. | 236 // world. This is just a temporary hack to make things compile. |
228 blink::WebLocalFrame* frame = (*iter)->toWebLocalFrame(); | 237 blink::WebLocalFrame* frame = (*iter)->toWebLocalFrame(); |
229 | 238 |
230 // We recheck access here in the renderer for extra safety against races | 239 // We recheck access here in the renderer for extra safety against races |
231 // with navigation, but different frames can have different URLs, and the | 240 // with navigation, but different frames can have different URLs, and the |
232 // extension might only have access to a subset of them. | 241 // injection_host might only have access to a subset of them. |
233 // For child frames, we just skip ones the extension doesn't have access | 242 // For child frames, we just skip ones the injection host doesn't have |
234 // to and carry on. | 243 // access to and carry on. |
235 // Note: we don't consider ACCESS_WITHHELD because there is nowhere to | 244 // Note: we don't consider ACCESS_WITHHELD because there is nowhere to |
236 // surface a request for a child frame. | 245 // surface a request for a child frame. |
237 // TODO(rdevlin.cronin): We should ask for permission somehow. | 246 // TODO(rdevlin.cronin): We should ask for permission somehow. |
238 if (injector_->CanExecuteOnFrame(extension, frame, tab_id_, top_url) == | 247 if (injector_->CanExecuteOnFrame(injection_host, frame, tab_id_, top_url) == |
239 PermissionsData::ACCESS_DENIED) { | 248 PermissionsData::ACCESS_DENIED) { |
240 DCHECK(frame->parent()); | 249 DCHECK(frame->parent()); |
241 continue; | 250 continue; |
242 } | 251 } |
243 if (inject_js) | 252 if (inject_js) |
244 InjectJs(extension, frame, execution_results.get()); | 253 InjectJs(injection_host, frame, execution_results.get()); |
245 if (inject_css) | 254 if (inject_css) |
246 InjectCss(frame); | 255 InjectCss(frame); |
247 } | 256 } |
248 | 257 |
249 complete_ = true; | 258 complete_ = true; |
250 injector_->OnInjectionComplete(execution_results.Pass(), | 259 injector_->OnInjectionComplete(execution_results.Pass(), |
251 scripts_run_info, | 260 scripts_run_info, |
Devlin
2015/02/11 00:00:48
We likely don't to log these metrics, either. A T
Xi Han
2015/02/11 16:00:24
Added.
| |
252 run_location_); | 261 run_location_); |
253 } | 262 } |
254 | 263 |
255 void ScriptInjection::InjectJs(const Extension* extension, | 264 void ScriptInjection::InjectJs(const InjectionHost* injection_host, |
256 blink::WebLocalFrame* frame, | 265 blink::WebLocalFrame* frame, |
257 base::ListValue* execution_results) { | 266 base::ListValue* execution_results) { |
258 std::vector<blink::WebScriptSource> sources = | 267 std::vector<blink::WebScriptSource> sources = |
259 injector_->GetJsSources(run_location_); | 268 injector_->GetJsSources(run_location_); |
260 bool in_main_world = injector_->ShouldExecuteInMainWorld(); | 269 bool in_main_world = injector_->ShouldExecuteInMainWorld(); |
261 int world_id = in_main_world | 270 int world_id = in_main_world |
262 ? DOMActivityLogger::kMainWorldId | 271 ? DOMActivityLogger::kMainWorldId |
263 : GetIsolatedWorldIdForExtension(extension, frame); | 272 : GetIsolatedWorldIdForInstance( |
273 injection_host, instance_id_, frame); | |
264 bool expects_results = injector_->ExpectsResults(); | 274 bool expects_results = injector_->ExpectsResults(); |
265 | 275 |
266 base::ElapsedTimer exec_timer; | 276 base::ElapsedTimer exec_timer; |
267 DOMActivityLogger::AttachToWorld(world_id, extension->id()); | 277 if (injection_host->id().type() == HostID::EXTENSIONS) |
278 DOMActivityLogger::AttachToWorld(world_id, injection_host->id().id()); | |
268 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 279 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
269 v8::Local<v8::Value> script_value; | 280 v8::Local<v8::Value> script_value; |
270 if (in_main_world) { | 281 if (in_main_world) { |
271 // We only inject in the main world for javascript: urls. | 282 // We only inject in the main world for javascript: urls. |
272 DCHECK_EQ(1u, sources.size()); | 283 DCHECK_EQ(1u, sources.size()); |
273 | 284 |
274 const blink::WebScriptSource& source = sources.front(); | 285 const blink::WebScriptSource& source = sources.front(); |
275 if (expects_results) | 286 if (expects_results) |
276 script_value = frame->executeScriptAndReturnValue(source); | 287 script_value = frame->executeScriptAndReturnValue(source); |
277 else | 288 else |
278 frame->executeScript(source); | 289 frame->executeScript(source); |
279 } else { // in isolated world | 290 } else { // in isolated world |
280 scoped_ptr<blink::WebVector<v8::Local<v8::Value> > > results; | 291 scoped_ptr<blink::WebVector<v8::Local<v8::Value> > > results; |
281 if (expects_results) | 292 if (expects_results) |
282 results.reset(new blink::WebVector<v8::Local<v8::Value> >()); | 293 results.reset(new blink::WebVector<v8::Local<v8::Value> >()); |
283 frame->executeScriptInIsolatedWorld(world_id, | 294 frame->executeScriptInIsolatedWorld(world_id, |
284 &sources.front(), | 295 &sources.front(), |
285 sources.size(), | 296 sources.size(), |
286 EXTENSION_GROUP_CONTENT_SCRIPTS, | 297 EXTENSION_GROUP_CONTENT_SCRIPTS, |
287 results.get()); | 298 results.get()); |
288 if (expects_results && !results->isEmpty()) | 299 if (expects_results && !results->isEmpty()) |
289 script_value = (*results)[0]; | 300 script_value = (*results)[0]; |
290 } | 301 } |
291 | 302 |
292 UMA_HISTOGRAM_TIMES("Extensions.InjectScriptTime", exec_timer.Elapsed()); | 303 if (injection_host->id().type() == HostID::EXTENSIONS) |
304 UMA_HISTOGRAM_TIMES("Extensions.InjectScriptTime", exec_timer.Elapsed()); | |
293 | 305 |
294 if (expects_results) { | 306 if (expects_results) { |
295 // Right now, we only support returning single results (per frame). | 307 // Right now, we only support returning single results (per frame). |
296 scoped_ptr<content::V8ValueConverter> v8_converter( | 308 scoped_ptr<content::V8ValueConverter> v8_converter( |
297 content::V8ValueConverter::create()); | 309 content::V8ValueConverter::create()); |
298 // It's safe to always use the main world context when converting | 310 // It's safe to always use the main world context when converting |
299 // here. V8ValueConverterImpl shouldn't actually care about the | 311 // here. V8ValueConverterImpl shouldn't actually care about the |
300 // context scope, and it switches to v8::Object's creation context | 312 // context scope, and it switches to v8::Object's creation context |
301 // when encountered. | 313 // when encountered. |
302 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); | 314 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); |
(...skipping 10 matching lines...) Expand all Loading... | |
313 std::vector<std::string> css_sources = | 325 std::vector<std::string> css_sources = |
314 injector_->GetCssSources(run_location_); | 326 injector_->GetCssSources(run_location_); |
315 for (std::vector<std::string>::const_iterator iter = css_sources.begin(); | 327 for (std::vector<std::string>::const_iterator iter = css_sources.begin(); |
316 iter != css_sources.end(); | 328 iter != css_sources.end(); |
317 ++iter) { | 329 ++iter) { |
318 frame->document().insertStyleSheet(blink::WebString::fromUTF8(*iter)); | 330 frame->document().insertStyleSheet(blink::WebString::fromUTF8(*iter)); |
319 } | 331 } |
320 } | 332 } |
321 | 333 |
322 } // namespace extensions | 334 } // namespace extensions |
OLD | NEW |