| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_webstore_bindings.h" | 5 #include "chrome/renderer/extensions/chrome_webstore_bindings.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "chrome/common/extensions/extension.h" | 9 #include "chrome/common/extensions/extension.h" |
| 10 #include "chrome/renderer/extensions/extension_helper.h" | 10 #include "chrome/renderer/extensions/extension_helper.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 const char kNoWebstoreItemLinkFoundError[] = | 43 const char kNoWebstoreItemLinkFoundError[] = |
| 44 "No Chrome Web Store item link found."; | 44 "No Chrome Web Store item link found."; |
| 45 const char kInvalidWebstoreItemUrlError[] = | 45 const char kInvalidWebstoreItemUrlError[] = |
| 46 "Invalid Chrome Web Store item URL."; | 46 "Invalid Chrome Web Store item URL."; |
| 47 | 47 |
| 48 // chrome.webstore.install() calls generate an install ID so that the install's | 48 // chrome.webstore.install() calls generate an install ID so that the install's |
| 49 // callbacks may be fired when the browser notifies us of install completion | 49 // callbacks may be fired when the browser notifies us of install completion |
| 50 // (successful or not) via HandleInstallResponse. | 50 // (successful or not) via HandleInstallResponse. |
| 51 int g_next_install_id = 0; | 51 int g_next_install_id = 0; |
| 52 | 52 |
| 53 base::LazyInstance<WeakV8FunctionMap> g_success_callbacks( | 53 base::LazyInstance<WeakV8FunctionMap> g_success_callbacks = |
| 54 base::LINKER_INITIALIZED); | 54 LAZY_INSTANCE_INITIALIZER; |
| 55 base::LazyInstance<WeakV8FunctionMap> g_failure_callbacks( | 55 base::LazyInstance<WeakV8FunctionMap> g_failure_callbacks = |
| 56 base::LINKER_INITIALIZED); | 56 LAZY_INSTANCE_INITIALIZER; |
| 57 | 57 |
| 58 } // anonymous namespace | 58 } // anonymous namespace |
| 59 | 59 |
| 60 class ExtensionImpl : public v8::Extension { | 60 class ExtensionImpl : public v8::Extension { |
| 61 public: | 61 public: |
| 62 ExtensionImpl() : | 62 ExtensionImpl() : |
| 63 v8::Extension( | 63 v8::Extension( |
| 64 kWebstoreV8ExtensionName, | 64 kWebstoreV8ExtensionName, |
| 65 "var chrome = chrome || {};" | 65 "var chrome = chrome || {};" |
| 66 "if (!chrome.webstore) {" | 66 "if (!chrome.webstore) {" |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 v8::Persistent<v8::Function> function = callback_map.Remove(install_id); | 240 v8::Persistent<v8::Function> function = callback_map.Remove(install_id); |
| 241 if (function.IsEmpty()) | 241 if (function.IsEmpty()) |
| 242 return; | 242 return; |
| 243 | 243 |
| 244 v8::HandleScope handle_scope; | 244 v8::HandleScope handle_scope; |
| 245 v8::Context::Scope context_scope(function->CreationContext()); | 245 v8::Context::Scope context_scope(function->CreationContext()); |
| 246 v8::Handle<v8::Value> argv[1]; | 246 v8::Handle<v8::Value> argv[1]; |
| 247 argv[0] = v8::String::New(error.c_str()); | 247 argv[0] = v8::String::New(error.c_str()); |
| 248 function->Call(v8::Object::New(), arraysize(argv), argv); | 248 function->Call(v8::Object::New(), arraysize(argv), argv); |
| 249 } | 249 } |
| OLD | NEW |