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