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/browser/extensions/webstore_standalone_installer.h" | 5 #include "chrome/browser/extensions/webstore_standalone_installer.h" |
6 | 6 |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "chrome/browser/extensions/crx_installer.h" | 8 #include "chrome/browser/extensions/crx_installer.h" |
9 #include "chrome/browser/extensions/extension_install_prompt.h" | 9 #include "chrome/browser/extensions/extension_install_prompt.h" |
10 #include "chrome/browser/extensions/extension_install_ui.h" | 10 #include "chrome/browser/extensions/extension_install_ui.h" |
| 11 #include "chrome/browser/extensions/extension_prefs.h" |
11 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "chrome/browser/extensions/extension_system.h" |
12 #include "chrome/browser/extensions/webstore_data_fetcher.h" | 14 #include "chrome/browser/extensions/webstore_data_fetcher.h" |
13 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
14 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
15 #include "extensions/common/extension.h" | 17 #include "extensions/common/extension.h" |
16 #include "url/gurl.h" | 18 #include "url/gurl.h" |
17 | 19 |
18 using content::WebContents; | 20 using content::WebContents; |
19 | 21 |
20 namespace extensions { | 22 namespace extensions { |
21 | 23 |
22 const char kManifestKey[] = "manifest"; | 24 const char kManifestKey[] = "manifest"; |
23 const char kIconUrlKey[] = "icon_url"; | 25 const char kIconUrlKey[] = "icon_url"; |
24 const char kLocalizedNameKey[] = "localized_name"; | 26 const char kLocalizedNameKey[] = "localized_name"; |
25 const char kLocalizedDescriptionKey[] = "localized_description"; | 27 const char kLocalizedDescriptionKey[] = "localized_description"; |
26 const char kUsersKey[] = "users"; | 28 const char kUsersKey[] = "users"; |
27 const char kShowUserCountKey[] = "show_user_count"; | 29 const char kShowUserCountKey[] = "show_user_count"; |
28 const char kAverageRatingKey[] = "average_rating"; | 30 const char kAverageRatingKey[] = "average_rating"; |
29 const char kRatingCountKey[] = "rating_count"; | 31 const char kRatingCountKey[] = "rating_count"; |
30 | 32 |
31 const char kInvalidWebstoreItemId[] = "Invalid Chrome Web Store item ID"; | 33 const char kInvalidWebstoreItemId[] = "Invalid Chrome Web Store item ID"; |
32 const char kWebstoreRequestError[] = | 34 const char kWebstoreRequestError[] = |
33 "Could not fetch data from the Chrome Web Store"; | 35 "Could not fetch data from the Chrome Web Store"; |
34 const char kInvalidWebstoreResponseError[] = "Invalid Chrome Web Store reponse"; | 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"; |
37 | 39 const char kExtensionIsBlacklisted[] = "Extension is blacklisted"; |
38 | 40 |
39 WebstoreStandaloneInstaller::WebstoreStandaloneInstaller( | 41 WebstoreStandaloneInstaller::WebstoreStandaloneInstaller( |
40 const std::string& webstore_item_id, | 42 const std::string& webstore_item_id, |
41 Profile* profile, | 43 Profile* profile, |
42 const Callback& callback) | 44 const Callback& callback) |
43 : id_(webstore_item_id), | 45 : id_(webstore_item_id), |
44 callback_(callback), | 46 callback_(callback), |
45 profile_(profile), | 47 profile_(profile), |
46 install_source_(WebstoreInstaller::INSTALL_SOURCE_INLINE), | 48 install_source_(WebstoreInstaller::INSTALL_SOURCE_INLINE), |
47 show_user_count_(true), | 49 show_user_count_(true), |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 const std::string& error_message) { | 232 const std::string& error_message) { |
231 CompleteInstall(error_message); | 233 CompleteInstall(error_message); |
232 } | 234 } |
233 | 235 |
234 void WebstoreStandaloneInstaller::InstallUIProceed() { | 236 void WebstoreStandaloneInstaller::InstallUIProceed() { |
235 if (!CheckRequestorAlive()) { | 237 if (!CheckRequestorAlive()) { |
236 CompleteInstall(std::string()); | 238 CompleteInstall(std::string()); |
237 return; | 239 return; |
238 } | 240 } |
239 | 241 |
| 242 ExtensionService* extension_service = |
| 243 ExtensionSystem::Get(profile_)->extension_service(); |
| 244 const Extension* extension = |
| 245 extension_service->GetExtensionById(id_, true /* include disabled */); |
| 246 if (extension) { |
| 247 std::string install_result; // Empty string for install success. |
| 248 if (!extension_service->IsExtensionEnabled(id_)) { |
| 249 if (!ExtensionPrefs::Get(profile_)->IsExtensionBlacklisted(id_)) { |
| 250 // If the extension is installed but disabled, and not blacklisted, |
| 251 // enable it. |
| 252 extension_service->EnableExtension(id_); |
| 253 } else { // Don't install a blacklisted extension. |
| 254 install_result = kExtensionIsBlacklisted; |
| 255 } |
| 256 } // else extension is installed and enabled; no work to be done. |
| 257 CompleteInstall(install_result); |
| 258 return; |
| 259 } |
| 260 |
240 scoped_ptr<WebstoreInstaller::Approval> approval = CreateApproval(); | 261 scoped_ptr<WebstoreInstaller::Approval> approval = CreateApproval(); |
241 | 262 |
242 scoped_refptr<WebstoreInstaller> installer = new WebstoreInstaller( | 263 scoped_refptr<WebstoreInstaller> installer = new WebstoreInstaller( |
243 profile_, | 264 profile_, |
244 this, | 265 this, |
245 &(GetWebContents()->GetController()), | 266 &(GetWebContents()->GetController()), |
246 id_, | 267 id_, |
247 approval.Pass(), | 268 approval.Pass(), |
248 install_source_); | 269 install_source_); |
249 installer->Start(); | 270 installer->Start(); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 // Balanced in InstallUIAbort or indirectly in InstallUIProceed via | 326 // Balanced in InstallUIAbort or indirectly in InstallUIProceed via |
306 // OnExtensionInstallSuccess or OnExtensionInstallFailure. | 327 // OnExtensionInstallSuccess or OnExtensionInstallFailure. |
307 AddRef(); | 328 AddRef(); |
308 | 329 |
309 install_ui_ = CreateInstallUI(); | 330 install_ui_ = CreateInstallUI(); |
310 install_ui_->ConfirmStandaloneInstall( | 331 install_ui_->ConfirmStandaloneInstall( |
311 this, localized_extension_for_display_.get(), &icon_, *install_prompt_); | 332 this, localized_extension_for_display_.get(), &icon_, *install_prompt_); |
312 } | 333 } |
313 | 334 |
314 } // namespace extensions | 335 } // namespace extensions |
OLD | NEW |