| 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/chrome_v8_context.h" | 5 #include "chrome/renderer/extensions/chrome_v8_context.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 | 70 |
| 71 GURL ChromeV8Context::GetURL() const { | 71 GURL ChromeV8Context::GetURL() const { |
| 72 return web_frame_ ? | 72 return web_frame_ ? |
| 73 UserScriptSlave::GetDataSourceURLForFrame(web_frame_) : GURL(); | 73 UserScriptSlave::GetDataSourceURLForFrame(web_frame_) : GURL(); |
| 74 } | 74 } |
| 75 | 75 |
| 76 v8::Local<v8::Value> ChromeV8Context::CallFunction( | 76 v8::Local<v8::Value> ChromeV8Context::CallFunction( |
| 77 v8::Handle<v8::Function> function, | 77 v8::Handle<v8::Function> function, |
| 78 int argc, | 78 int argc, |
| 79 v8::Handle<v8::Value> argv[]) const { | 79 v8::Handle<v8::Value> argv[]) const { |
| 80 v8::HandleScope handle_scope(isolate()); | 80 v8::EscapableHandleScope handle_scope(isolate()); |
| 81 v8::Context::Scope scope(v8_context()); | 81 v8::Context::Scope scope(v8_context()); |
| 82 | 82 |
| 83 blink::WebScopedMicrotaskSuppression suppression; | 83 blink::WebScopedMicrotaskSuppression suppression; |
| 84 if (!is_valid()) | 84 if (!is_valid()) { |
| 85 return handle_scope.Close(v8::Undefined()); | 85 return handle_scope.Escape( |
| 86 v8::Local<v8::Primitive>(v8::Undefined(isolate()))); |
| 87 } |
| 86 | 88 |
| 87 v8::Handle<v8::Object> global = v8_context()->Global(); | 89 v8::Handle<v8::Object> global = v8_context()->Global(); |
| 88 if (!web_frame_) | 90 if (!web_frame_) |
| 89 return handle_scope.Close(function->Call(global, argc, argv)); | 91 return handle_scope.Escape(function->Call(global, argc, argv)); |
| 90 return handle_scope.Close( | 92 return handle_scope.Escape( |
| 91 web_frame_->callFunctionEvenIfScriptDisabled(function, | 93 v8::Local<v8::Value>(web_frame_->callFunctionEvenIfScriptDisabled( |
| 92 global, | 94 function, global, argc, argv))); |
| 93 argc, | |
| 94 argv)); | |
| 95 } | 95 } |
| 96 | 96 |
| 97 bool ChromeV8Context::IsAnyFeatureAvailableToContext( | 97 bool ChromeV8Context::IsAnyFeatureAvailableToContext( |
| 98 const std::string& api_name) { | 98 const std::string& api_name) { |
| 99 return ExtensionAPI::GetSharedInstance()->IsAnyFeatureAvailableToContext( | 99 return ExtensionAPI::GetSharedInstance()->IsAnyFeatureAvailableToContext( |
| 100 api_name, | 100 api_name, |
| 101 extension_.get(), | 101 extension_.get(), |
| 102 context_type_, | 102 context_type_, |
| 103 UserScriptSlave::GetDataSourceURLForFrame(web_frame_)); | 103 UserScriptSlave::GetDataSourceURLForFrame(web_frame_)); |
| 104 } | 104 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 v8::String::NewFromUtf8(isolate(), error.c_str()) | 147 v8::String::NewFromUtf8(isolate(), error.c_str()) |
| 148 }; | 148 }; |
| 149 | 149 |
| 150 v8::Handle<v8::Value> retval = module_system_->CallModuleMethod( | 150 v8::Handle<v8::Value> retval = module_system_->CallModuleMethod( |
| 151 "sendRequest", "handleResponse", arraysize(argv), argv); | 151 "sendRequest", "handleResponse", arraysize(argv), argv); |
| 152 | 152 |
| 153 // In debug, the js will validate the callback parameters and return a | 153 // In debug, the js will validate the callback parameters and return a |
| 154 // string if a validation error has occured. | 154 // string if a validation error has occured. |
| 155 if (DCHECK_IS_ON()) { | 155 if (DCHECK_IS_ON()) { |
| 156 if (!retval.IsEmpty() && !retval->IsUndefined()) { | 156 if (!retval.IsEmpty() && !retval->IsUndefined()) { |
| 157 std::string error = *v8::String::AsciiValue(retval); | 157 std::string error = *v8::String::Utf8Value(retval); |
| 158 DCHECK(false) << error; | 158 DCHECK(false) << error; |
| 159 } | 159 } |
| 160 } | 160 } |
| 161 } | 161 } |
| 162 | 162 |
| 163 } // namespace extensions | 163 } // namespace extensions |
| OLD | NEW |