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()); |
| 214 |
205 script_value = child_frame->executeScriptAndReturnValue(source); | 215 script_value = child_frame->executeScriptAndReturnValue(source); |
206 } else { | 216 } else { |
207 WebKit::WebVector<v8::Local<v8::Value> > results; | 217 WebKit::WebVector<v8::Local<v8::Value> > results; |
208 std::vector<WebScriptSource> sources; | 218 std::vector<WebScriptSource> sources; |
209 sources.push_back(source); | 219 sources.push_back(source); |
| 220 |
| 221 int isolated_world_id = |
| 222 dispatcher_->user_script_slave()->GetIsolatedWorldIdForExtension( |
| 223 extension, child_frame); |
| 224 DOMActivityLogger::attachToWorld( |
| 225 isolated_world_id, |
| 226 extension->id(), |
| 227 UserScriptSlave::GetDataSourceURLForFrame(child_frame), |
| 228 child_frame->document().title()); |
| 229 |
210 child_frame->executeScriptInIsolatedWorld( | 230 child_frame->executeScriptInIsolatedWorld( |
211 dispatcher_->user_script_slave()-> | 231 isolated_world_id, &sources.front(), |
212 GetIsolatedWorldIdForExtension(extension, child_frame), | 232 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 | 233 // We only expect one value back since we only pushed one source |
216 if (results.size() == 1 && !results[0].IsEmpty()) | 234 if (results.size() == 1 && !results[0].IsEmpty()) |
217 script_value = results[0]; | 235 script_value = results[0]; |
218 } | 236 } |
219 if (!script_value.IsEmpty()) { | 237 if (!script_value.IsEmpty()) { |
220 base::Value* base_val = | 238 base::Value* base_val = |
221 v8_converter->FromV8Value(script_value, context); | 239 v8_converter->FromV8Value(script_value, context); |
222 // Always append an execution result (i.e. no result == null result) so | 240 // Always append an execution result (i.e. no result == null result) so |
223 // that |execution_results| lines up with the frames. | 241 // that |execution_results| lines up with the frames. |
224 execution_results.Append(base_val ? base_val : | 242 execution_results.Append(base_val ? base_val : |
(...skipping 25 matching lines...) Expand all Loading... |
250 | 268 |
251 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame; | 269 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame; |
252 child_frame = child_frame->nextSibling()) { | 270 child_frame = child_frame->nextSibling()) { |
253 frames_vector->push_back(child_frame); | 271 frames_vector->push_back(child_frame); |
254 GetAllChildFrames(child_frame, frames_vector); | 272 GetAllChildFrames(child_frame, frames_vector); |
255 } | 273 } |
256 return true; | 274 return true; |
257 } | 275 } |
258 | 276 |
259 } // namespace extensions | 277 } // namespace extensions |
OLD | NEW |