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/user_script_scheduler.h" | 5 #include "extensions/renderer/user_script_scheduler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "content/public/renderer/render_view.h" | 10 #include "content/public/renderer/render_view.h" |
11 #include "content/public/renderer/v8_value_converter.h" | 11 #include "content/public/renderer/v8_value_converter.h" |
12 #include "extensions/common/error_utils.h" | 12 #include "extensions/common/error_utils.h" |
13 #include "extensions/common/extension_messages.h" | 13 #include "extensions/common/extension_messages.h" |
14 #include "extensions/common/manifest_constants.h" | 14 #include "extensions/common/manifest_constants.h" |
15 #include "extensions/common/permissions/permissions_data.h" | 15 #include "extensions/common/permissions/permissions_data.h" |
16 #include "extensions/renderer/dispatcher.h" | 16 #include "extensions/renderer/dispatcher.h" |
17 #include "extensions/renderer/dom_activity_logger.h" | 17 #include "extensions/renderer/dom_activity_logger.h" |
18 #include "extensions/renderer/extension_groups.h" | 18 #include "extensions/renderer/extension_groups.h" |
19 #include "extensions/renderer/extension_helper.h" | 19 #include "extensions/renderer/extension_helper.h" |
20 #include "extensions/renderer/script_context.h" | 20 #include "extensions/renderer/script_context.h" |
21 #include "extensions/renderer/user_script_slave.h" | 21 #include "extensions/renderer/user_script_slave.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/platform/WebVector.h" | 23 #include "third_party/WebKit/public/platform/WebVector.h" |
24 #include "third_party/WebKit/public/web/WebDocument.h" | 24 #include "third_party/WebKit/public/web/WebDocument.h" |
25 #include "third_party/WebKit/public/web/WebFrame.h" | 25 #include "third_party/WebKit/public/web/WebFrame.h" |
26 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" | 26 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" |
| 27 #include "third_party/WebKit/public/web/WebScriptSource.h" |
27 #include "third_party/WebKit/public/web/WebView.h" | 28 #include "third_party/WebKit/public/web/WebView.h" |
28 #include "v8/include/v8.h" | 29 #include "v8/include/v8.h" |
29 | 30 |
30 namespace { | 31 namespace { |
31 // The length of time to wait after the DOM is complete to try and run user | 32 // The length of time to wait after the DOM is complete to try and run user |
32 // scripts. | 33 // scripts. |
33 const int kUserScriptIdleTimeoutMs = 200; | 34 const int kUserScriptIdleTimeoutMs = 200; |
34 } | 35 } |
35 | 36 |
36 using blink::WebDocument; | 37 using blink::WebDocument; |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 if (child_frame->parent()) { | 204 if (child_frame->parent()) { |
204 continue; | 205 continue; |
205 } else { | 206 } else { |
206 error = ErrorUtils::FormatErrorMessage( | 207 error = ErrorUtils::FormatErrorMessage( |
207 manifest_errors::kCannotAccessPage, document_url.spec()); | 208 manifest_errors::kCannotAccessPage, document_url.spec()); |
208 break; | 209 break; |
209 } | 210 } |
210 } | 211 } |
211 | 212 |
212 if (params.is_javascript) { | 213 if (params.is_javascript) { |
213 WebScriptSource source(WebString::fromUTF8(params.code), params.file_url); | 214 blink::WebScriptSource source( |
| 215 WebString::fromUTF8(params.code), params.file_url); |
214 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 216 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
215 | 217 |
216 scoped_ptr<content::V8ValueConverter> v8_converter( | 218 scoped_ptr<content::V8ValueConverter> v8_converter( |
217 content::V8ValueConverter::create()); | 219 content::V8ValueConverter::create()); |
218 v8::Local<v8::Value> script_value; | 220 v8::Local<v8::Value> script_value; |
219 | 221 |
220 if (params.in_main_world) { | 222 if (params.in_main_world) { |
221 DOMActivityLogger::AttachToWorld(DOMActivityLogger::kMainWorldId, | 223 DOMActivityLogger::AttachToWorld(DOMActivityLogger::kMainWorldId, |
222 extension->id()); | 224 extension->id()); |
223 script_value = child_frame->executeScriptAndReturnValue(source); | 225 script_value = child_frame->executeScriptAndReturnValue(source); |
224 } else { | 226 } else { |
225 blink::WebVector<v8::Local<v8::Value> > results; | 227 blink::WebVector<v8::Local<v8::Value> > results; |
226 std::vector<WebScriptSource> sources; | 228 std::vector<blink::WebScriptSource> sources; |
227 sources.push_back(source); | 229 sources.push_back(source); |
228 int isolated_world_id = | 230 int isolated_world_id = |
229 dispatcher_->user_script_slave()->GetIsolatedWorldIdForExtension( | 231 dispatcher_->user_script_slave()->GetIsolatedWorldIdForExtension( |
230 extension, child_frame); | 232 extension, child_frame); |
231 DOMActivityLogger::AttachToWorld(isolated_world_id, extension->id()); | 233 DOMActivityLogger::AttachToWorld(isolated_world_id, extension->id()); |
232 child_frame->executeScriptInIsolatedWorld( | 234 child_frame->executeScriptInIsolatedWorld( |
233 isolated_world_id, &sources.front(), | 235 isolated_world_id, &sources.front(), |
234 sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS, &results); | 236 sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS, &results); |
235 // We only expect one value back since we only pushed one source | 237 // We only expect one value back since we only pushed one source |
236 if (results.size() == 1 && !results[0].IsEmpty()) | 238 if (results.size() == 1 && !results[0].IsEmpty()) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 | 273 |
272 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame; | 274 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame; |
273 child_frame = child_frame->nextSibling()) { | 275 child_frame = child_frame->nextSibling()) { |
274 frames_vector->push_back(child_frame); | 276 frames_vector->push_back(child_frame); |
275 GetAllChildFrames(child_frame, frames_vector); | 277 GetAllChildFrames(child_frame, frames_vector); |
276 } | 278 } |
277 return true; | 279 return true; |
278 } | 280 } |
279 | 281 |
280 } // namespace extensions | 282 } // namespace extensions |
OLD | NEW |