| 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/extension_service.h" | 5 #include "chrome/browser/extensions/extension_service.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 } | 608 } |
| 609 } | 609 } |
| 610 | 610 |
| 611 bool ExtensionService::UpdateExtension( | 611 bool ExtensionService::UpdateExtension( |
| 612 const std::string& id, | 612 const std::string& id, |
| 613 const FilePath& extension_path, | 613 const FilePath& extension_path, |
| 614 const GURL& download_url, | 614 const GURL& download_url, |
| 615 CrxInstaller** out_crx_installer) { | 615 CrxInstaller** out_crx_installer) { |
| 616 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 616 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 617 | 617 |
| 618 PendingExtensionInfo pending_extension_info; | 618 const PendingExtensionInfo* pending_extension_info = |
| 619 bool is_pending_extension = pending_extension_manager_.GetById( | 619 pending_extension_manager()->GetById(id); |
| 620 id, &pending_extension_info); | |
| 621 | 620 |
| 622 const Extension* extension = | 621 const Extension* extension = |
| 623 GetExtensionByIdInternal(id, true, true, false); | 622 GetExtensionByIdInternal(id, true, true, false); |
| 624 if (!is_pending_extension && !extension) { | 623 if (!pending_extension_info && !extension) { |
| 625 LOG(WARNING) << "Will not update extension " << id | 624 LOG(WARNING) << "Will not update extension " << id |
| 626 << " because it is not installed or pending"; | 625 << " because it is not installed or pending"; |
| 627 // Delete extension_path since we're not creating a CrxInstaller | 626 // Delete extension_path since we're not creating a CrxInstaller |
| 628 // that would do it for us. | 627 // that would do it for us. |
| 629 if (!BrowserThread::PostTask( | 628 if (!BrowserThread::PostTask( |
| 630 BrowserThread::FILE, FROM_HERE, | 629 BrowserThread::FILE, FROM_HERE, |
| 631 base::Bind( | 630 base::Bind( |
| 632 &extension_file_util::DeleteFile, extension_path, false))) | 631 &extension_file_util::DeleteFile, extension_path, false))) |
| 633 NOTREACHED(); | 632 NOTREACHED(); |
| 634 | 633 |
| 635 return false; | 634 return false; |
| 636 } | 635 } |
| 637 | 636 |
| 638 // We want a silent install only for non-pending extensions and | 637 // We want a silent install only for non-pending extensions and |
| 639 // pending extensions that have install_silently set. | 638 // pending extensions that have install_silently set. |
| 640 ExtensionInstallUI* client = | 639 ExtensionInstallUI* client = |
| 641 (!is_pending_extension || pending_extension_info.install_silently()) ? | 640 (!pending_extension_info || pending_extension_info->install_silently()) ? |
| 642 NULL : new ExtensionInstallUI(profile_); | 641 NULL : new ExtensionInstallUI(profile_); |
| 643 | 642 |
| 644 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(this, client)); | 643 scoped_refptr<CrxInstaller> installer(CrxInstaller::Create(this, client)); |
| 645 installer->set_expected_id(id); | 644 installer->set_expected_id(id); |
| 646 if (is_pending_extension) | 645 if (pending_extension_info) |
| 647 installer->set_install_source(pending_extension_info.install_source()); | 646 installer->set_install_source(pending_extension_info->install_source()); |
| 648 else if (extension) | 647 else if (extension) |
| 649 installer->set_install_source(extension->location()); | 648 installer->set_install_source(extension->location()); |
| 650 if (pending_extension_info.install_silently()) | 649 if (pending_extension_info->install_silently()) |
| 651 installer->set_allow_silent_install(true); | 650 installer->set_allow_silent_install(true); |
| 652 // If the extension was installed from or has migrated to the webstore, or | 651 // If the extension was installed from or has migrated to the webstore, or |
| 653 // if the extension came from sync and its auto-update URL is from the | 652 // if the extension came from sync and its auto-update URL is from the |
| 654 // webstore, treat it as a webstore install. Note that we ignore some older | 653 // webstore, treat it as a webstore install. Note that we ignore some older |
| 655 // extensions with blank auto-update URLs because we are mostly concerned | 654 // extensions with blank auto-update URLs because we are mostly concerned |
| 656 // with restrictions on NaCl extensions, which are newer. | 655 // with restrictions on NaCl extensions, which are newer. |
| 657 int creation_flags = Extension::NO_FLAGS; | 656 int creation_flags = Extension::NO_FLAGS; |
| 658 if ((extension && extension->from_webstore()) || | 657 if ((extension && extension->from_webstore()) || |
| 659 (extension && extension->UpdatesFromGallery()) || | 658 (extension && extension->UpdatesFromGallery()) || |
| 660 (!extension && pending_extension_info.is_from_sync() && | 659 (!extension && pending_extension_info->is_from_sync() && |
| 661 extension_urls::IsWebstoreUpdateUrl( | 660 extension_urls::IsWebstoreUpdateUrl( |
| 662 pending_extension_info.update_url()))) { | 661 pending_extension_info->update_url()))) { |
| 663 creation_flags |= Extension::FROM_WEBSTORE; | 662 creation_flags |= Extension::FROM_WEBSTORE; |
| 664 } | 663 } |
| 665 | 664 |
| 666 // Bookmark apps being updated is kind of a contradiction, but that's because | 665 // Bookmark apps being updated is kind of a contradiction, but that's because |
| 667 // we mark the default apps as bookmark apps, and they're hosted in the web | 666 // we mark the default apps as bookmark apps, and they're hosted in the web |
| 668 // store, thus they can get updated. See http://crbug.com/101605 for more | 667 // store, thus they can get updated. See http://crbug.com/101605 for more |
| 669 // details. | 668 // details. |
| 670 if (extension && extension->from_bookmark()) | 669 if (extension && extension->from_bookmark()) |
| 671 creation_flags |= Extension::FROM_BOOKMARK; | 670 creation_flags |= Extension::FROM_BOOKMARK; |
| 672 | 671 |
| (...skipping 1505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2178 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2177 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2179 | 2178 |
| 2180 // Ensure extension is deleted unless we transfer ownership. | 2179 // Ensure extension is deleted unless we transfer ownership. |
| 2181 scoped_refptr<const Extension> scoped_extension(extension); | 2180 scoped_refptr<const Extension> scoped_extension(extension); |
| 2182 const std::string& id = extension->id(); | 2181 const std::string& id = extension->id(); |
| 2183 // Extensions installed by policy can't be disabled. So even if a previous | 2182 // Extensions installed by policy can't be disabled. So even if a previous |
| 2184 // installation disabled the extension, make sure it is now enabled. | 2183 // installation disabled the extension, make sure it is now enabled. |
| 2185 bool initial_enable = | 2184 bool initial_enable = |
| 2186 !extension_prefs_->IsExtensionDisabled(id) || | 2185 !extension_prefs_->IsExtensionDisabled(id) || |
| 2187 !Extension::UserMayDisable(extension->location()); | 2186 !Extension::UserMayDisable(extension->location()); |
| 2188 PendingExtensionInfo pending_extension_info; | 2187 const PendingExtensionInfo* pending_extension_info = NULL; |
| 2189 if (pending_extension_manager()->GetById(id, &pending_extension_info)) { | 2188 if ((pending_extension_info = pending_extension_manager()->GetById(id))) { |
| 2190 pending_extension_manager()->Remove(id); | 2189 pending_extension_manager()->Remove(id); |
| 2191 | 2190 |
| 2192 if (!pending_extension_info.ShouldAllowInstall(*extension)) { | 2191 if (!pending_extension_info->ShouldAllowInstall(*extension)) { |
| 2193 LOG(WARNING) | 2192 LOG(WARNING) |
| 2194 << "ShouldAllowInstall() returned false for " | 2193 << "ShouldAllowInstall() returned false for " |
| 2195 << id << " of type " << extension->GetType() | 2194 << id << " of type " << extension->GetType() |
| 2196 << " and update URL " << extension->update_url().spec() | 2195 << " and update URL " << extension->update_url().spec() |
| 2197 << "; not installing"; | 2196 << "; not installing"; |
| 2198 | 2197 |
| 2199 content::NotificationService::current()->Notify( | 2198 content::NotificationService::current()->Notify( |
| 2200 chrome::NOTIFICATION_EXTENSION_INSTALL_NOT_ALLOWED, | 2199 chrome::NOTIFICATION_EXTENSION_INSTALL_NOT_ALLOWED, |
| 2201 content::Source<Profile>(profile_), | 2200 content::Source<Profile>(profile_), |
| 2202 content::Details<const Extension>(extension)); | 2201 content::Details<const Extension>(extension)); |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2633 // To coexist with certain unit tests that don't have an IO thread message | 2632 // To coexist with certain unit tests that don't have an IO thread message |
| 2634 // loop available at ExtensionService shutdown, we lazy-initialize this | 2633 // loop available at ExtensionService shutdown, we lazy-initialize this |
| 2635 // object so that those cases neither create nor destroy an | 2634 // object so that those cases neither create nor destroy an |
| 2636 // APIResourceController. | 2635 // APIResourceController. |
| 2637 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 2636 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 2638 if (!api_resource_controller_) { | 2637 if (!api_resource_controller_) { |
| 2639 api_resource_controller_ = new extensions::APIResourceController(); | 2638 api_resource_controller_ = new extensions::APIResourceController(); |
| 2640 } | 2639 } |
| 2641 return api_resource_controller_; | 2640 return api_resource_controller_; |
| 2642 } | 2641 } |
| OLD | NEW |