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/browser/extensions/webstore_inline_installer.h" | 5 #include "chrome/browser/extensions/webstore_inline_installer.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/extensions/crx_installer.h" | 12 #include "chrome/browser/extensions/crx_installer.h" |
13 #include "chrome/browser/extensions/extension_install_dialog.h" | 13 #include "chrome/browser/extensions/extension_install_dialog.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/common/chrome_utility_messages.h" | 15 #include "chrome/common/chrome_utility_messages.h" |
16 #include "chrome/common/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
17 #include "chrome/common/extensions/extension_constants.h" | 17 #include "chrome/common/extensions/extension_constants.h" |
| 18 #include "chrome/common/extensions/url_pattern.h" |
18 #include "content/browser/tab_contents/tab_contents.h" | 19 #include "content/browser/tab_contents/tab_contents.h" |
19 #include "content/browser/utility_process_host.h" | 20 #include "content/browser/utility_process_host.h" |
20 #include "googleurl/src/gurl.h" | |
21 #include "net/base/escape.h" | 21 #include "net/base/escape.h" |
22 #include "net/url_request/url_request_status.h" | 22 #include "net/url_request/url_request_status.h" |
23 | 23 |
24 const char kManifestKey[] = "manifest"; | 24 const char kManifestKey[] = "manifest"; |
25 const char kIconUrlKey[] = "icon_url"; | 25 const char kIconUrlKey[] = "icon_url"; |
26 const char kLocalizedNameKey[] = "localized_name"; | 26 const char kLocalizedNameKey[] = "localized_name"; |
27 const char kLocalizedDescriptionKey[] = "localized_description"; | 27 const char kLocalizedDescriptionKey[] = "localized_description"; |
28 const char kUsersKey[] = "users"; | 28 const char kUsersKey[] = "users"; |
29 const char kAverageRatingKey[] = "average_rating"; | 29 const char kAverageRatingKey[] = "average_rating"; |
30 const char kRatingCountKey[] = "rating_count"; | 30 const char kRatingCountKey[] = "rating_count"; |
| 31 const char kVerifiedSiteKey[] = "verified_site"; |
31 | 32 |
32 const char kInvalidWebstoreItemId[] = "Invalid webstore item ID"; | 33 const char kInvalidWebstoreItemId[] = "Invalid Chrome Web Store item ID"; |
33 const char kWebstoreRequestError[] = "Could not fetch data from webstore"; | 34 const char kWebstoreRequestError[] = |
34 const char kInvalidWebstoreResponseError[] = "Invalid webstore reponse"; | 35 "Could not fetch data from the Chrome Web Store"; |
| 36 const char kInvalidWebstoreResponseError[] = "Invalid Chrome Web Store reponse"; |
35 const char kInvalidManifestError[] = "Invalid manifest"; | 37 const char kInvalidManifestError[] = "Invalid manifest"; |
36 const char kUserCancelledError[] = "User cancelled install"; | 38 const char kUserCancelledError[] = "User cancelled install"; |
| 39 const char kNotFromVerifiedSite[] = |
| 40 "Installs can only be initiated by the Chrome Web Store item's verified " |
| 41 "site"; |
37 | 42 |
38 class SafeWebstoreResponseParser : public UtilityProcessHost::Client { | 43 class SafeWebstoreResponseParser : public UtilityProcessHost::Client { |
39 public: | 44 public: |
40 SafeWebstoreResponseParser(WebstoreInlineInstaller *client, | 45 SafeWebstoreResponseParser(WebstoreInlineInstaller *client, |
41 const std::string& webstore_data) | 46 const std::string& webstore_data) |
42 : client_(client), | 47 : client_(client), |
43 webstore_data_(webstore_data), | 48 webstore_data_(webstore_data), |
44 utility_host_(NULL) {} | 49 utility_host_(NULL) {} |
45 | 50 |
46 void Start() { | 51 void Start() { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 | 125 |
121 std::string webstore_data_; | 126 std::string webstore_data_; |
122 | 127 |
123 UtilityProcessHost* utility_host_; | 128 UtilityProcessHost* utility_host_; |
124 | 129 |
125 std::string error_; | 130 std::string error_; |
126 scoped_ptr<DictionaryValue> parsed_webstore_data_; | 131 scoped_ptr<DictionaryValue> parsed_webstore_data_; |
127 }; | 132 }; |
128 | 133 |
129 WebstoreInlineInstaller::WebstoreInlineInstaller(TabContents* tab_contents, | 134 WebstoreInlineInstaller::WebstoreInlineInstaller(TabContents* tab_contents, |
| 135 int install_id, |
130 std::string webstore_item_id, | 136 std::string webstore_item_id, |
| 137 GURL requestor_url, |
131 Delegate* delegate) | 138 Delegate* delegate) |
132 : tab_contents_(tab_contents), | 139 : tab_contents_(tab_contents), |
| 140 install_id_(install_id), |
133 id_(webstore_item_id), | 141 id_(webstore_item_id), |
| 142 requestor_url_(requestor_url), |
134 delegate_(delegate) {} | 143 delegate_(delegate) {} |
135 | 144 |
136 WebstoreInlineInstaller::~WebstoreInlineInstaller() { | 145 WebstoreInlineInstaller::~WebstoreInlineInstaller() { |
137 } | 146 } |
138 | 147 |
139 void WebstoreInlineInstaller::BeginInstall() { | 148 void WebstoreInlineInstaller::BeginInstall() { |
140 AddRef(); // Balanced in CompleteInstall. | 149 AddRef(); // Balanced in CompleteInstall. |
141 | 150 |
142 if (!Extension::IdIsValid(id_)) { | 151 if (!Extension::IdIsValid(id_)) { |
143 CompleteInstall(kInvalidWebstoreItemId); | 152 CompleteInstall(kInvalidWebstoreItemId); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 return; | 227 return; |
219 } | 228 } |
220 icon_url = GURL(extension_urls::GetWebstoreLaunchURL()).Resolve( | 229 icon_url = GURL(extension_urls::GetWebstoreLaunchURL()).Resolve( |
221 icon_url_string); | 230 icon_url_string); |
222 if (!icon_url.is_valid()) { | 231 if (!icon_url.is_valid()) { |
223 CompleteInstall(kInvalidWebstoreResponseError); | 232 CompleteInstall(kInvalidWebstoreResponseError); |
224 return; | 233 return; |
225 } | 234 } |
226 } | 235 } |
227 | 236 |
| 237 // Verified site is optional |
| 238 if (webstore_data->HasKey(kVerifiedSiteKey)) { |
| 239 std::string verified_site_domain; |
| 240 if (!webstore_data->GetString(kVerifiedSiteKey, &verified_site_domain)) { |
| 241 CompleteInstall(kInvalidWebstoreResponseError); |
| 242 return; |
| 243 } |
| 244 |
| 245 URLPattern verified_site_pattern(URLPattern::SCHEME_ALL); |
| 246 verified_site_pattern.SetScheme("*"); |
| 247 verified_site_pattern.SetHost(verified_site_domain); |
| 248 verified_site_pattern.SetMatchSubdomains(true); |
| 249 verified_site_pattern.SetPath("/*"); |
| 250 |
| 251 if (!verified_site_pattern.MatchesURL(requestor_url_)) { |
| 252 CompleteInstall(kNotFromVerifiedSite); |
| 253 return; |
| 254 } |
| 255 } |
| 256 |
228 scoped_refptr<WebstoreInstallHelper> helper = new WebstoreInstallHelper( | 257 scoped_refptr<WebstoreInstallHelper> helper = new WebstoreInstallHelper( |
229 this, | 258 this, |
230 manifest, | 259 manifest, |
231 "", // We don't have any icon data. | 260 "", // We don't have any icon data. |
232 icon_url, | 261 icon_url, |
233 Profile::FromBrowserContext(tab_contents_->browser_context())-> | 262 Profile::FromBrowserContext(tab_contents_->browser_context())-> |
234 GetRequestContext()); | 263 GetRequestContext()); |
235 // The helper will call us back via OnWebstoreParseSucces or | 264 // The helper will call us back via OnWebstoreParseSucces or |
236 // OnWebstoreParseFailure. | 265 // OnWebstoreParseFailure. |
237 helper->Start(); | 266 helper->Start(); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 // or NOTIFICATION_EXTENSION_INSTALL_ERROR fire). | 334 // or NOTIFICATION_EXTENSION_INSTALL_ERROR fire). |
306 CompleteInstall(""); | 335 CompleteInstall(""); |
307 } | 336 } |
308 | 337 |
309 void WebstoreInlineInstaller::InstallUIAbort(bool user_initiated) { | 338 void WebstoreInlineInstaller::InstallUIAbort(bool user_initiated) { |
310 CompleteInstall(kUserCancelledError); | 339 CompleteInstall(kUserCancelledError); |
311 } | 340 } |
312 | 341 |
313 void WebstoreInlineInstaller::CompleteInstall(const std::string& error) { | 342 void WebstoreInlineInstaller::CompleteInstall(const std::string& error) { |
314 if (error.empty()) { | 343 if (error.empty()) { |
315 delegate_->OnInlineInstallSuccess(); | 344 delegate_->OnInlineInstallSuccess(install_id_); |
316 } else { | 345 } else { |
317 delegate_->OnInlineInstallFailure(error); | 346 delegate_->OnInlineInstallFailure(install_id_, error); |
318 } | 347 } |
319 Release(); // Matches the AddRef in BeginInstall. | 348 Release(); // Matches the AddRef in BeginInstall. |
320 } | 349 } |
OLD | NEW |