OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/renderer/extensions/user_script_scheduler.h" | 5 #include "chrome/renderer/extensions/user_script_scheduler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" |
8 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
9 #include "chrome/common/extensions/extension_manifest_constants.h" | 10 #include "chrome/common/extensions/extension_manifest_constants.h" |
10 #include "chrome/common/extensions/extension_messages.h" | 11 #include "chrome/common/extensions/extension_messages.h" |
| 12 #include "chrome/renderer/chrome_render_process_observer.h" |
11 #include "chrome/renderer/extensions/dispatcher.h" | 13 #include "chrome/renderer/extensions/dispatcher.h" |
| 14 #include "chrome/renderer/extensions/dom_activity_logger.h" |
12 #include "chrome/renderer/extensions/extension_groups.h" | 15 #include "chrome/renderer/extensions/extension_groups.h" |
13 #include "chrome/renderer/extensions/extension_helper.h" | 16 #include "chrome/renderer/extensions/extension_helper.h" |
14 #include "chrome/renderer/extensions/user_script_slave.h" | 17 #include "chrome/renderer/extensions/user_script_slave.h" |
15 #include "content/public/renderer/render_view.h" | 18 #include "content/public/renderer/render_view.h" |
16 #include "content/public/renderer/v8_value_converter.h" | 19 #include "content/public/renderer/v8_value_converter.h" |
17 #include "extensions/common/error_utils.h" | 20 #include "extensions/common/error_utils.h" |
18 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" | 21 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" |
19 #include "third_party/WebKit/Source/Platform/chromium/public/WebVector.h" | 22 #include "third_party/WebKit/Source/Platform/chromium/public/WebVector.h" |
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 WebScriptSource source(WebString::fromUTF8(params.code)); | 197 WebScriptSource source(WebString::fromUTF8(params.code)); |
195 v8::HandleScope scope; | 198 v8::HandleScope scope; |
196 v8::Persistent<v8::Context> persistent_context = v8::Context::New(); | 199 v8::Persistent<v8::Context> persistent_context = v8::Context::New(); |
197 v8::Local<v8::Context> context = | 200 v8::Local<v8::Context> context = |
198 v8::Local<v8::Context>::New(persistent_context); | 201 v8::Local<v8::Context>::New(persistent_context); |
199 persistent_context.Dispose(context->GetIsolate()); | 202 persistent_context.Dispose(context->GetIsolate()); |
200 | 203 |
201 scoped_ptr<content::V8ValueConverter> v8_converter( | 204 scoped_ptr<content::V8ValueConverter> v8_converter( |
202 content::V8ValueConverter::create()); | 205 content::V8ValueConverter::create()); |
203 v8::Handle<v8::Value> script_value; | 206 v8::Handle<v8::Value> script_value; |
| 207 |
204 if (params.in_main_world) { | 208 if (params.in_main_world) { |
| 209 DOMActivityLogger::AttachToWorld( |
| 210 DOMActivityLogger::kMainWorldId, |
| 211 extension->id(), |
| 212 UserScriptSlave::GetDataSourceURLForFrame(child_frame), |
| 213 child_frame->document().title()); |
205 script_value = child_frame->executeScriptAndReturnValue(source); | 214 script_value = child_frame->executeScriptAndReturnValue(source); |
206 } else { | 215 } else { |
207 WebKit::WebVector<v8::Local<v8::Value> > results; | 216 WebKit::WebVector<v8::Local<v8::Value> > results; |
208 std::vector<WebScriptSource> sources; | 217 std::vector<WebScriptSource> sources; |
209 sources.push_back(source); | 218 sources.push_back(source); |
| 219 int isolated_world_id = |
| 220 dispatcher_->user_script_slave()->GetIsolatedWorldIdForExtension( |
| 221 extension, child_frame); |
| 222 DOMActivityLogger::AttachToWorld( |
| 223 isolated_world_id, |
| 224 extension->id(), |
| 225 UserScriptSlave::GetDataSourceURLForFrame(child_frame), |
| 226 child_frame->document().title()); |
210 child_frame->executeScriptInIsolatedWorld( | 227 child_frame->executeScriptInIsolatedWorld( |
211 dispatcher_->user_script_slave()-> | 228 isolated_world_id, &sources.front(), |
212 GetIsolatedWorldIdForExtension(extension, child_frame), | 229 sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS, &results); |
213 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS, | |
214 &results); | |
215 // We only expect one value back since we only pushed one source | 230 // We only expect one value back since we only pushed one source |
216 if (results.size() == 1 && !results[0].IsEmpty()) | 231 if (results.size() == 1 && !results[0].IsEmpty()) |
217 script_value = results[0]; | 232 script_value = results[0]; |
218 } | 233 } |
219 if (!script_value.IsEmpty()) { | 234 if (!script_value.IsEmpty()) { |
220 base::Value* base_val = | 235 base::Value* base_val = |
221 v8_converter->FromV8Value(script_value, context); | 236 v8_converter->FromV8Value(script_value, context); |
222 // Always append an execution result (i.e. no result == null result) so | 237 // Always append an execution result (i.e. no result == null result) so |
223 // that |execution_results| lines up with the frames. | 238 // that |execution_results| lines up with the frames. |
224 execution_results.Append(base_val ? base_val : | 239 execution_results.Append(base_val ? base_val : |
(...skipping 25 matching lines...) Expand all Loading... |
250 | 265 |
251 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame; | 266 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame; |
252 child_frame = child_frame->nextSibling()) { | 267 child_frame = child_frame->nextSibling()) { |
253 frames_vector->push_back(child_frame); | 268 frames_vector->push_back(child_frame); |
254 GetAllChildFrames(child_frame, frames_vector); | 269 GetAllChildFrames(child_frame, frames_vector); |
255 } | 270 } |
256 return true; | 271 return true; |
257 } | 272 } |
258 | 273 |
259 } // namespace extensions | 274 } // namespace extensions |
OLD | NEW |