| 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/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "chrome/common/extensions/extension_error_utils.h" | 9 #include "chrome/common/extensions/extension_error_utils.h" |
| 10 #include "chrome/common/extensions/extension_manifest_constants.h" | 10 #include "chrome/common/extensions/extension_manifest_constants.h" |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 | 196 |
| 197 WebScriptSource source(WebString::fromUTF8(params.code)); | 197 WebScriptSource source(WebString::fromUTF8(params.code)); |
| 198 v8::HandleScope scope; | 198 v8::HandleScope scope; |
| 199 v8::Persistent<v8::Context> persistent_context = v8::Context::New(); | 199 v8::Persistent<v8::Context> persistent_context = v8::Context::New(); |
| 200 v8::Local<v8::Context> context = | 200 v8::Local<v8::Context> context = |
| 201 v8::Local<v8::Context>::New(persistent_context); | 201 v8::Local<v8::Context>::New(persistent_context); |
| 202 persistent_context.Dispose(); | 202 persistent_context.Dispose(); |
| 203 | 203 |
| 204 scoped_ptr<content::V8ValueConverter> v8_converter( | 204 scoped_ptr<content::V8ValueConverter> v8_converter( |
| 205 content::V8ValueConverter::create()); | 205 content::V8ValueConverter::create()); |
| 206 v8_converter->SetUndefinedAllowed(true); | |
| 207 v8::Handle<v8::Value> script_value; | 206 v8::Handle<v8::Value> script_value; |
| 208 if (params.in_main_world) { | 207 if (params.in_main_world) { |
| 209 script_value = child_frame->executeScriptAndReturnValue(source); | 208 script_value = child_frame->executeScriptAndReturnValue(source); |
| 210 } else { | 209 } else { |
| 211 WebKit::WebVector<v8::Local<v8::Value> > results; | 210 WebKit::WebVector<v8::Local<v8::Value> > results; |
| 212 std::vector<WebScriptSource> sources; | 211 std::vector<WebScriptSource> sources; |
| 213 sources.push_back(source); | 212 sources.push_back(source); |
| 214 child_frame->executeScriptInIsolatedWorld( | 213 child_frame->executeScriptInIsolatedWorld( |
| 215 dispatcher_->user_script_slave()-> | 214 dispatcher_->user_script_slave()-> |
| 216 GetIsolatedWorldIdForExtension(extension, child_frame), | 215 GetIsolatedWorldIdForExtension(extension, child_frame), |
| 217 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS, | 216 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS, |
| 218 &results); | 217 &results); |
| 219 // We only expect one value back since we only pushed one source | 218 // We only expect one value back since we only pushed one source |
| 220 if (results.size() == 1 && !results[0].IsEmpty()) | 219 if (results.size() == 1 && !results[0].IsEmpty()) |
| 221 script_value = results[0]; | 220 script_value = results[0]; |
| 222 } | 221 } |
| 223 if (!script_value.IsEmpty()) { | 222 if (!script_value.IsEmpty()) { |
| 224 base::Value* base_val = | 223 base::Value* base_val = |
| 225 v8_converter->FromV8Value(script_value, context); | 224 v8_converter->FromV8Value(script_value, context); |
| 226 execution_results.Append(base_val); | 225 execution_results.Append(base_val ? base_val : |
| 226 base::Value::CreateNullValue()); |
| 227 script_value.Clear(); | 227 script_value.Clear(); |
| 228 } | 228 } |
| 229 } else { | 229 } else { |
| 230 child_frame->document().insertUserStyleSheet( | 230 child_frame->document().insertUserStyleSheet( |
| 231 WebString::fromUTF8(params.code), | 231 WebString::fromUTF8(params.code), |
| 232 // Author level is consistent with WebView::addUserStyleSheet. | 232 // Author level is consistent with WebView::addUserStyleSheet. |
| 233 WebDocument::UserStyleAuthorLevel); | 233 WebDocument::UserStyleAuthorLevel); |
| 234 } | 234 } |
| 235 } | 235 } |
| 236 | 236 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 251 | 251 |
| 252 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame; | 252 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame; |
| 253 child_frame = child_frame->nextSibling()) { | 253 child_frame = child_frame->nextSibling()) { |
| 254 frames_vector->push_back(child_frame); | 254 frames_vector->push_back(child_frame); |
| 255 GetAllChildFrames(child_frame, frames_vector); | 255 GetAllChildFrames(child_frame, frames_vector); |
| 256 } | 256 } |
| 257 return true; | 257 return true; |
| 258 } | 258 } |
| 259 | 259 |
| 260 } // namespace extensions | 260 } // namespace extensions |
| OLD | NEW |