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 "components/crx_file/id_util.h" | 10 #include "components/crx_file/id_util.h" |
11 #include "content/public/renderer/render_view.h" | 11 #include "content/public/renderer/render_view.h" |
12 #include "extensions/common/extension.h" | 12 #include "extensions/common/extension.h" |
13 #include "extensions/common/extension_urls.h" | 13 #include "extensions/common/extension_urls.h" |
14 #include "extensions/renderer/script_context.h" | 14 #include "extensions/renderer/script_context.h" |
15 #include "third_party/WebKit/public/web/WebDocument.h" | 15 #include "third_party/WebKit/public/web/WebDocument.h" |
16 #include "third_party/WebKit/public/web/WebElement.h" | 16 #include "third_party/WebKit/public/web/WebElement.h" |
| 17 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
17 #include "third_party/WebKit/public/web/WebNode.h" | 18 #include "third_party/WebKit/public/web/WebNode.h" |
18 #include "third_party/WebKit/public/web/WebNodeList.h" | 19 #include "third_party/WebKit/public/web/WebNodeList.h" |
19 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | 20 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
20 #include "url/gurl.h" | 21 #include "url/gurl.h" |
21 #include "v8/include/v8.h" | 22 #include "v8/include/v8.h" |
22 | 23 |
23 using blink::WebDocument; | 24 using blink::WebDocument; |
24 using blink::WebElement; | 25 using blink::WebElement; |
25 using blink::WebFrame; | |
26 using blink::WebNode; | 26 using blink::WebNode; |
27 using blink::WebNodeList; | 27 using blink::WebNodeList; |
28 using blink::WebUserGestureIndicator; | 28 using blink::WebUserGestureIndicator; |
29 | 29 |
30 namespace extensions { | 30 namespace extensions { |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 const char kWebstoreLinkRelation[] = "chrome-webstore-item"; | 34 const char kWebstoreLinkRelation[] = "chrome-webstore-item"; |
35 | 35 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 listener_mask |= api::webstore::DOWNLOAD_PROGRESS_LISTENER; | 72 listener_mask |= api::webstore::DOWNLOAD_PROGRESS_LISTENER; |
73 | 73 |
74 std::string preferred_store_link_url; | 74 std::string preferred_store_link_url; |
75 if (!args[2]->IsUndefined()) { | 75 if (!args[2]->IsUndefined()) { |
76 CHECK(args[2]->IsString()); | 76 CHECK(args[2]->IsString()); |
77 preferred_store_link_url = std::string(*v8::String::Utf8Value(args[2])); | 77 preferred_store_link_url = std::string(*v8::String::Utf8Value(args[2])); |
78 } | 78 } |
79 | 79 |
80 std::string webstore_item_id; | 80 std::string webstore_item_id; |
81 std::string error; | 81 std::string error; |
82 WebFrame* frame = context()->web_frame(); | 82 blink::WebLocalFrame* frame = context()->web_frame(); |
83 | 83 |
84 if (!GetWebstoreItemIdFromFrame( | 84 if (!GetWebstoreItemIdFromFrame( |
85 frame, preferred_store_link_url, &webstore_item_id, &error)) { | 85 frame, preferred_store_link_url, &webstore_item_id, &error)) { |
86 args.GetIsolate()->ThrowException( | 86 args.GetIsolate()->ThrowException( |
87 v8::String::NewFromUtf8(args.GetIsolate(), error.c_str())); | 87 v8::String::NewFromUtf8(args.GetIsolate(), error.c_str())); |
88 return; | 88 return; |
89 } | 89 } |
90 | 90 |
91 int install_id = g_next_install_id++; | 91 int install_id = g_next_install_id++; |
92 | 92 |
93 Send(new ExtensionHostMsg_InlineWebstoreInstall(render_view->GetRoutingID(), | 93 Send(new ExtensionHostMsg_InlineWebstoreInstall(render_view->GetRoutingID(), |
94 install_id, | 94 install_id, |
95 GetRoutingID(), | 95 GetRoutingID(), |
96 webstore_item_id, | 96 webstore_item_id, |
97 frame->document().url(), | 97 frame->document().url(), |
98 listener_mask)); | 98 listener_mask)); |
99 | 99 |
100 args.GetReturnValue().Set(static_cast<int32_t>(install_id)); | 100 args.GetReturnValue().Set(static_cast<int32_t>(install_id)); |
101 } | 101 } |
102 | 102 |
103 // static | 103 // static |
104 bool WebstoreBindings::GetWebstoreItemIdFromFrame( | 104 bool WebstoreBindings::GetWebstoreItemIdFromFrame( |
105 WebFrame* frame, const std::string& preferred_store_link_url, | 105 blink::WebLocalFrame* frame, |
106 std::string* webstore_item_id, std::string* error) { | 106 const std::string& preferred_store_link_url, |
| 107 std::string* webstore_item_id, |
| 108 std::string* error) { |
107 if (frame != frame->top()) { | 109 if (frame != frame->top()) { |
108 *error = kNotInTopFrameError; | 110 *error = kNotInTopFrameError; |
109 return false; | 111 return false; |
110 } | 112 } |
111 | 113 |
112 if (!WebUserGestureIndicator::isProcessingUserGesture()) { | 114 if (!WebUserGestureIndicator::isProcessingUserGesture()) { |
113 *error = kNotUserGestureError; | 115 *error = kNotUserGestureError; |
114 return false; | 116 return false; |
115 } | 117 } |
116 | 118 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 v8::Isolate* isolate = context()->isolate(); | 246 v8::Isolate* isolate = context()->isolate(); |
245 v8::HandleScope handle_scope(isolate); | 247 v8::HandleScope handle_scope(isolate); |
246 v8::Context::Scope context_scope(context()->v8_context()); | 248 v8::Context::Scope context_scope(context()->v8_context()); |
247 v8::Handle<v8::Value> argv[] = { | 249 v8::Handle<v8::Value> argv[] = { |
248 v8::Number::New(isolate, percent_downloaded / 100.0)}; | 250 v8::Number::New(isolate, percent_downloaded / 100.0)}; |
249 context()->module_system()->CallModuleMethod( | 251 context()->module_system()->CallModuleMethod( |
250 "webstore", "onDownloadProgress", arraysize(argv), argv); | 252 "webstore", "onDownloadProgress", arraysize(argv), argv); |
251 } | 253 } |
252 | 254 |
253 } // namespace extensions | 255 } // namespace extensions |
OLD | NEW |