| 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 "base/version.h" | 8 #include "base/version.h" |
| 9 #include "chrome/browser/extensions/crx_installer.h" | 9 #include "chrome/browser/extensions/crx_installer.h" |
| 10 #include "chrome/browser/extensions/extension_install_prompt.h" | 10 #include "chrome/browser/extensions/extension_install_prompt.h" |
| 11 #include "chrome/browser/extensions/extension_install_ui_util.h" | 11 #include "chrome/browser/extensions/extension_install_ui_util.h" |
| 12 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "chrome/browser/extensions/install_tracker.h" | 13 #include "chrome/browser/extensions/install_tracker.h" |
| 14 #include "chrome/browser/extensions/webstore_data_fetcher.h" | 14 #include "chrome/browser/extensions/webstore_data_fetcher.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "components/crx_file/id_util.h" | 16 #include "components/crx_file/id_util.h" |
| 17 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 18 #include "extensions/browser/extension_prefs.h" | 18 #include "extensions/browser/extension_prefs.h" |
| 19 #include "extensions/browser/extension_registry.h" | 19 #include "extensions/browser/extension_registry.h" |
| 20 #include "extensions/browser/extension_system.h" | 20 #include "extensions/browser/extension_system.h" |
| 21 #include "extensions/browser/extension_util.h" | |
| 22 #include "extensions/common/extension.h" | 21 #include "extensions/common/extension.h" |
| 23 #include "extensions/common/extension_urls.h" | 22 #include "extensions/common/extension_urls.h" |
| 24 #include "url/gurl.h" | 23 #include "url/gurl.h" |
| 25 | 24 |
| 26 using content::WebContents; | 25 using content::WebContents; |
| 27 | 26 |
| 28 namespace extensions { | 27 namespace extensions { |
| 29 | 28 |
| 30 const char kInvalidWebstoreItemId[] = "Invalid Chrome Web Store item ID"; | 29 const char kInvalidWebstoreItemId[] = "Invalid Chrome Web Store item ID"; |
| 31 const char kWebstoreRequestError[] = | 30 const char kWebstoreRequestError[] = |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 extension_service->GetExtensionById(id_, true /* include disabled */); | 201 extension_service->GetExtensionById(id_, true /* include disabled */); |
| 203 if (installed_extension) { | 202 if (installed_extension) { |
| 204 std::string install_message; | 203 std::string install_message; |
| 205 webstore_install::Result install_result = webstore_install::SUCCESS; | 204 webstore_install::Result install_result = webstore_install::SUCCESS; |
| 206 bool done = true; | 205 bool done = true; |
| 207 | 206 |
| 208 if (ExtensionPrefs::Get(profile_)->IsExtensionBlacklisted(id_)) { | 207 if (ExtensionPrefs::Get(profile_)->IsExtensionBlacklisted(id_)) { |
| 209 // Don't install a blacklisted extension. | 208 // Don't install a blacklisted extension. |
| 210 install_result = webstore_install::BLACKLISTED; | 209 install_result = webstore_install::BLACKLISTED; |
| 211 install_message = kExtensionIsBlacklisted; | 210 install_message = kExtensionIsBlacklisted; |
| 212 } else if (util::IsEphemeralApp(installed_extension->id(), profile_)) { | |
| 213 // If the target extension has already been installed ephemerally and is | |
| 214 // up to date, it can be promoted to a regular installed extension and | |
| 215 // downloading from the Web Store is not necessary. | |
| 216 scoped_refptr<const Extension> extension_to_install = | |
| 217 GetLocalizedExtensionForDisplay(); | |
| 218 if (!extension_to_install.get()) { | |
| 219 CompleteInstall(webstore_install::INVALID_MANIFEST, | |
| 220 kInvalidManifestError); | |
| 221 return; | |
| 222 } | |
| 223 | |
| 224 if (installed_extension->version()->CompareTo( | |
| 225 *extension_to_install->version()) < 0) { | |
| 226 // If the existing extension is out of date, proceed with the install | |
| 227 // to update the extension. | |
| 228 done = false; | |
| 229 } else { | |
| 230 install_ui::ShowPostInstallUIForApproval( | |
| 231 profile_, *approval, installed_extension); | |
| 232 extension_service->PromoteEphemeralApp(installed_extension, false); | |
| 233 } | |
| 234 } else if (!extension_service->IsExtensionEnabled(id_)) { | 211 } else if (!extension_service->IsExtensionEnabled(id_)) { |
| 235 // If the extension is installed but disabled, and not blacklisted, | 212 // If the extension is installed but disabled, and not blacklisted, |
| 236 // enable it. | 213 // enable it. |
| 237 extension_service->EnableExtension(id_); | 214 extension_service->EnableExtension(id_); |
| 238 } // else extension is installed and enabled; no work to be done. | 215 } // else extension is installed and enabled; no work to be done. |
| 239 | 216 |
| 240 if (done) { | 217 if (done) { |
| 241 CompleteInstall(install_result, install_message); | 218 CompleteInstall(install_result, install_message); |
| 242 return; | 219 return; |
| 243 } | 220 } |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 void WebstoreStandaloneInstaller::OnWebStoreDataFetcherDone() { | 412 void WebstoreStandaloneInstaller::OnWebStoreDataFetcherDone() { |
| 436 // An instance of this class is passed in as a delegate for the | 413 // An instance of this class is passed in as a delegate for the |
| 437 // WebstoreInstallHelper, ExtensionInstallPrompt and WebstoreInstaller, and | 414 // WebstoreInstallHelper, ExtensionInstallPrompt and WebstoreInstaller, and |
| 438 // therefore needs to remain alive until they are done. Clear the webstore | 415 // therefore needs to remain alive until they are done. Clear the webstore |
| 439 // data fetcher to avoid calling Release in AbortInstall while any of these | 416 // data fetcher to avoid calling Release in AbortInstall while any of these |
| 440 // operations are in progress. | 417 // operations are in progress. |
| 441 webstore_data_fetcher_.reset(); | 418 webstore_data_fetcher_.reset(); |
| 442 } | 419 } |
| 443 | 420 |
| 444 } // namespace extensions | 421 } // namespace extensions |
| OLD | NEW |