| 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); | 206 v8_converter->SetUndefinedValueBehavior( |
| 207 content::V8ValueConverter::CONVERT_TO_NULL); |
| 207 v8::Handle<v8::Value> script_value; | 208 v8::Handle<v8::Value> script_value; |
| 208 if (params.in_main_world) { | 209 if (params.in_main_world) { |
| 209 script_value = child_frame->executeScriptAndReturnValue(source); | 210 script_value = child_frame->executeScriptAndReturnValue(source); |
| 210 } else { | 211 } else { |
| 211 WebKit::WebVector<v8::Local<v8::Value> > results; | 212 WebKit::WebVector<v8::Local<v8::Value> > results; |
| 212 std::vector<WebScriptSource> sources; | 213 std::vector<WebScriptSource> sources; |
| 213 sources.push_back(source); | 214 sources.push_back(source); |
| 214 child_frame->executeScriptInIsolatedWorld( | 215 child_frame->executeScriptInIsolatedWorld( |
| 215 dispatcher_->user_script_slave()-> | 216 dispatcher_->user_script_slave()-> |
| 216 GetIsolatedWorldIdForExtension(extension, child_frame), | 217 GetIsolatedWorldIdForExtension(extension, child_frame), |
| 217 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS, | 218 &sources.front(), sources.size(), EXTENSION_GROUP_CONTENT_SCRIPTS, |
| 218 &results); | 219 &results); |
| 219 // We only expect one value back since we only pushed one source | 220 // We only expect one value back since we only pushed one source |
| 220 if (results.size() == 1 && !results[0].IsEmpty()) | 221 if (results.size() == 1 && !results[0].IsEmpty()) |
| 221 script_value = results[0]; | 222 script_value = results[0]; |
| 222 } | 223 } |
| 223 if (!script_value.IsEmpty()) { | 224 if (!script_value.IsEmpty()) { |
| 224 base::Value* base_val = | 225 base::Value* base_val = |
| 225 v8_converter->FromV8Value(script_value, context); | 226 v8_converter->FromV8Value(script_value, context); |
| 226 execution_results.Append(base_val); | 227 execution_results.Append(base_val ? base_val : |
| 228 base::Value::CreateNullValue()); |
| 227 script_value.Clear(); | 229 script_value.Clear(); |
| 228 } | 230 } |
| 229 } else { | 231 } else { |
| 230 child_frame->document().insertUserStyleSheet( | 232 child_frame->document().insertUserStyleSheet( |
| 231 WebString::fromUTF8(params.code), | 233 WebString::fromUTF8(params.code), |
| 232 // Author level is consistent with WebView::addUserStyleSheet. | 234 // Author level is consistent with WebView::addUserStyleSheet. |
| 233 WebDocument::UserStyleAuthorLevel); | 235 WebDocument::UserStyleAuthorLevel); |
| 234 } | 236 } |
| 235 } | 237 } |
| 236 | 238 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 251 | 253 |
| 252 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame; | 254 for (WebFrame* child_frame = parent_frame->firstChild(); child_frame; |
| 253 child_frame = child_frame->nextSibling()) { | 255 child_frame = child_frame->nextSibling()) { |
| 254 frames_vector->push_back(child_frame); | 256 frames_vector->push_back(child_frame); |
| 255 GetAllChildFrames(child_frame, frames_vector); | 257 GetAllChildFrames(child_frame, frames_vector); |
| 256 } | 258 } |
| 257 return true; | 259 return true; |
| 258 } | 260 } |
| 259 | 261 |
| 260 } // namespace extensions | 262 } // namespace extensions |
| OLD | NEW |