| 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/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
| 10 #include "base/values.h" | 11 #include "base/values.h" |
| 11 #include "chrome/common/extensions/api/extension_api.h" | 12 #include "chrome/common/extensions/api/extension_api.h" |
| 12 #include "chrome/common/extensions/extension.h" | 13 #include "chrome/common/extensions/extension.h" |
| 13 #include "chrome/common/extensions/extension_set.h" | 14 #include "chrome/common/extensions/extension_set.h" |
| 14 #include "chrome/renderer/extensions/chrome_v8_extension.h" | 15 #include "chrome/renderer/extensions/chrome_v8_extension.h" |
| 15 #include "chrome/renderer/extensions/module_system.h" | 16 #include "chrome/renderer/extensions/module_system.h" |
| 16 #include "chrome/renderer/extensions/user_script_slave.h" | 17 #include "chrome/renderer/extensions/user_script_slave.h" |
| 17 #include "content/public/renderer/render_view.h" | 18 #include "content/public/renderer/render_view.h" |
| 19 #include "content/public/renderer/v8_value_converter.h" |
| 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 20 #include "v8/include/v8.h" | 22 #include "v8/include/v8.h" |
| 21 | 23 |
| 24 using content::V8ValueConverter; |
| 25 |
| 22 namespace extensions { | 26 namespace extensions { |
| 23 | 27 |
| 24 namespace { | 28 namespace { |
| 25 | 29 |
| 26 const char kChromeHidden[] = "chromeHidden"; | 30 const char kChromeHidden[] = "chromeHidden"; |
| 27 const char kValidateCallbacks[] = "validateCallbacks"; | 31 const char kValidateCallbacks[] = "validateCallbacks"; |
| 28 const char kValidateAPI[] = "validateAPI"; | 32 const char kValidateAPI[] = "validateAPI"; |
| 29 | 33 |
| 30 } // namespace | 34 } // namespace |
| 31 | 35 |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 case Feature::UNSPECIFIED_CONTEXT: return "UNSPECIFIED"; | 183 case Feature::UNSPECIFIED_CONTEXT: return "UNSPECIFIED"; |
| 180 case Feature::BLESSED_EXTENSION_CONTEXT: return "BLESSED_EXTENSION"; | 184 case Feature::BLESSED_EXTENSION_CONTEXT: return "BLESSED_EXTENSION"; |
| 181 case Feature::UNBLESSED_EXTENSION_CONTEXT: return "UNBLESSED_EXTENSION"; | 185 case Feature::UNBLESSED_EXTENSION_CONTEXT: return "UNBLESSED_EXTENSION"; |
| 182 case Feature::CONTENT_SCRIPT_CONTEXT: return "CONTENT_SCRIPT"; | 186 case Feature::CONTENT_SCRIPT_CONTEXT: return "CONTENT_SCRIPT"; |
| 183 case Feature::WEB_PAGE_CONTEXT: return "WEB_PAGE"; | 187 case Feature::WEB_PAGE_CONTEXT: return "WEB_PAGE"; |
| 184 } | 188 } |
| 185 NOTREACHED(); | 189 NOTREACHED(); |
| 186 return ""; | 190 return ""; |
| 187 } | 191 } |
| 188 | 192 |
| 193 ChromeV8Context* ChromeV8Context::GetContext() { |
| 194 return this; |
| 195 } |
| 196 |
| 197 void ChromeV8Context::OnResponseReceived(const std::string& name, |
| 198 int request_id, |
| 199 bool success, |
| 200 const base::ListValue& response, |
| 201 const std::string& error) { |
| 202 v8::HandleScope handle_scope; |
| 203 |
| 204 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); |
| 205 v8::Handle<v8::Value> argv[] = { |
| 206 v8::Integer::New(request_id), |
| 207 v8::String::New(name.c_str()), |
| 208 v8::Boolean::New(success), |
| 209 converter->ToV8Value(&response, v8_context_.get()), |
| 210 v8::String::New(error.c_str()) |
| 211 }; |
| 212 |
| 213 v8::Handle<v8::Value> retval; |
| 214 CHECK(CallChromeHiddenMethod("handleResponse", arraysize(argv), argv, |
| 215 &retval)); |
| 216 // In debug, the js will validate the callback parameters and return a |
| 217 // string if a validation error has occured. |
| 218 if (DCHECK_IS_ON()) { |
| 219 if (!retval.IsEmpty() && !retval->IsUndefined()) { |
| 220 std::string error = *v8::String::AsciiValue(retval); |
| 221 DCHECK(false) << error; |
| 222 } |
| 223 } |
| 224 } |
| 225 |
| 189 } // namespace extensions | 226 } // namespace extensions |
| OLD | NEW |