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/webstore_bindings.h" | 5 #include "chrome/renderer/extensions/webstore_bindings.h" |
6 | 6 |
7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
8 #include "chrome/common/extensions/api/webstore/webstore_api_constants.h" | 8 #include "chrome/common/extensions/api/webstore/webstore_api_constants.h" |
9 #include "chrome/common/extensions/chrome_extension_messages.h" | 9 #include "chrome/common/extensions/chrome_extension_messages.h" |
10 #include "chrome/common/extensions/extension_constants.h" | 10 #include "chrome/common/extensions/extension_constants.h" |
11 #include "chrome/renderer/extensions/chrome_v8_context.h" | |
12 #include "content/public/renderer/render_view.h" | 11 #include "content/public/renderer/render_view.h" |
13 #include "extensions/common/extension.h" | 12 #include "extensions/common/extension.h" |
14 #include "grit/renderer_resources.h" | 13 #include "extensions/renderer/script_context.h" |
15 #include "third_party/WebKit/public/web/WebDocument.h" | 14 #include "third_party/WebKit/public/web/WebDocument.h" |
16 #include "third_party/WebKit/public/web/WebElement.h" | 15 #include "third_party/WebKit/public/web/WebElement.h" |
17 #include "third_party/WebKit/public/web/WebNode.h" | 16 #include "third_party/WebKit/public/web/WebNode.h" |
18 #include "third_party/WebKit/public/web/WebNodeList.h" | 17 #include "third_party/WebKit/public/web/WebNodeList.h" |
19 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | 18 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
20 #include "url/gurl.h" | 19 #include "url/gurl.h" |
21 #include "v8/include/v8.h" | 20 #include "v8/include/v8.h" |
22 | 21 |
23 using blink::WebDocument; | 22 using blink::WebDocument; |
24 using blink::WebElement; | 23 using blink::WebElement; |
(...skipping 17 matching lines...) Expand all Loading... |
42 const char kInvalidWebstoreItemUrlError[] = | 41 const char kInvalidWebstoreItemUrlError[] = |
43 "Invalid Chrome Web Store item URL."; | 42 "Invalid Chrome Web Store item URL."; |
44 | 43 |
45 // chrome.webstore.install() calls generate an install ID so that the install's | 44 // chrome.webstore.install() calls generate an install ID so that the install's |
46 // callbacks may be fired when the browser notifies us of install completion | 45 // callbacks may be fired when the browser notifies us of install completion |
47 // (successful or not) via OnInlineWebstoreInstallResponse. | 46 // (successful or not) via OnInlineWebstoreInstallResponse. |
48 int g_next_install_id = 0; | 47 int g_next_install_id = 0; |
49 | 48 |
50 } // anonymous namespace | 49 } // anonymous namespace |
51 | 50 |
52 WebstoreBindings::WebstoreBindings(Dispatcher* dispatcher, | 51 WebstoreBindings::WebstoreBindings(ScriptContext* context) |
53 ChromeV8Context* context) | 52 : ObjectBackedNativeHandler(context), ChromeV8ExtensionHandler(context) { |
54 : ChromeV8Extension(dispatcher, context), | |
55 ChromeV8ExtensionHandler(context) { | |
56 RouteFunction("Install", | 53 RouteFunction("Install", |
57 base::Bind(&WebstoreBindings::Install, base::Unretained(this))); | 54 base::Bind(&WebstoreBindings::Install, base::Unretained(this))); |
58 } | 55 } |
59 | 56 |
60 void WebstoreBindings::Install( | 57 void WebstoreBindings::Install( |
61 const v8::FunctionCallbackInfo<v8::Value>& args) { | 58 const v8::FunctionCallbackInfo<v8::Value>& args) { |
62 content::RenderView* render_view = GetRenderView(); | 59 content::RenderView* render_view = context()->GetRenderView(); |
63 if (!render_view) | 60 if (!render_view) |
64 return; | 61 return; |
65 | 62 |
66 // The first two arguments indicate whether or not there are install stage | 63 // The first two arguments indicate whether or not there are install stage |
67 // or download progress listeners. | 64 // or download progress listeners. |
68 int listener_mask = 0; | 65 int listener_mask = 0; |
69 CHECK(args[0]->IsBoolean()); | 66 CHECK(args[0]->IsBoolean()); |
70 if (args[0]->BooleanValue()) | 67 if (args[0]->BooleanValue()) |
71 listener_mask |= api::webstore::INSTALL_STAGE_LISTENER; | 68 listener_mask |= api::webstore::INSTALL_STAGE_LISTENER; |
72 CHECK(args[1]->IsBoolean()); | 69 CHECK(args[1]->IsBoolean()); |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 v8::Isolate* isolate = context()->isolate(); | 240 v8::Isolate* isolate = context()->isolate(); |
244 v8::HandleScope handle_scope(isolate); | 241 v8::HandleScope handle_scope(isolate); |
245 v8::Context::Scope context_scope(context()->v8_context()); | 242 v8::Context::Scope context_scope(context()->v8_context()); |
246 v8::Handle<v8::Value> argv[] = { | 243 v8::Handle<v8::Value> argv[] = { |
247 v8::Number::New(isolate, percent_downloaded / 100.0)}; | 244 v8::Number::New(isolate, percent_downloaded / 100.0)}; |
248 context()->module_system()->CallModuleMethod( | 245 context()->module_system()->CallModuleMethod( |
249 "webstore", "onDownloadProgress", arraysize(argv), argv); | 246 "webstore", "onDownloadProgress", arraysize(argv), argv); |
250 } | 247 } |
251 | 248 |
252 } // namespace extensions | 249 } // namespace extensions |
OLD | NEW |