Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <iterator> | 8 #include <iterator> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 #include "content/public/browser/url_data_source.h" | 75 #include "content/public/browser/url_data_source.h" |
| 76 #include "extensions/browser/app_sorting.h" | 76 #include "extensions/browser/app_sorting.h" |
| 77 #include "extensions/browser/event_router.h" | 77 #include "extensions/browser/event_router.h" |
| 78 #include "extensions/browser/extension_registry.h" | 78 #include "extensions/browser/extension_registry.h" |
| 79 #include "extensions/browser/extensions_browser_client.h" | 79 #include "extensions/browser/extensions_browser_client.h" |
| 80 #include "extensions/browser/external_provider_interface.h" | 80 #include "extensions/browser/external_provider_interface.h" |
| 81 #include "extensions/browser/management_policy.h" | 81 #include "extensions/browser/management_policy.h" |
| 82 #include "extensions/browser/pending_extension_manager.h" | 82 #include "extensions/browser/pending_extension_manager.h" |
| 83 #include "extensions/browser/pref_names.h" | 83 #include "extensions/browser/pref_names.h" |
| 84 #include "extensions/browser/process_manager.h" | 84 #include "extensions/browser/process_manager.h" |
| 85 #include "extensions/browser/runtime_data.h" | |
| 85 #include "extensions/browser/update_observer.h" | 86 #include "extensions/browser/update_observer.h" |
| 86 #include "extensions/common/constants.h" | 87 #include "extensions/common/constants.h" |
| 87 #include "extensions/common/error_utils.h" | 88 #include "extensions/common/error_utils.h" |
| 88 #include "extensions/common/extension.h" | 89 #include "extensions/common/extension.h" |
| 89 #include "extensions/common/extensions_client.h" | 90 #include "extensions/common/extensions_client.h" |
| 90 #include "extensions/common/feature_switch.h" | 91 #include "extensions/common/feature_switch.h" |
| 91 #include "extensions/common/manifest.h" | 92 #include "extensions/common/manifest.h" |
| 92 #include "extensions/common/manifest_constants.h" | 93 #include "extensions/common/manifest_constants.h" |
| 93 #include "extensions/common/manifest_handlers/background_info.h" | 94 #include "extensions/common/manifest_handlers/background_info.h" |
| 94 #include "extensions/common/manifest_handlers/incognito_info.h" | 95 #include "extensions/common/manifest_handlers/incognito_info.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 return IsCWSSharedModule(extension); | 182 return IsCWSSharedModule(extension); |
| 182 } | 183 } |
| 183 | 184 |
| 184 private: | 185 private: |
| 185 DISALLOW_COPY_AND_ASSIGN(SharedModuleProvider); | 186 DISALLOW_COPY_AND_ASSIGN(SharedModuleProvider); |
| 186 }; | 187 }; |
| 187 | 188 |
| 188 | 189 |
| 189 } // namespace | 190 } // namespace |
| 190 | 191 |
| 191 ExtensionService::ExtensionRuntimeData::ExtensionRuntimeData() | |
| 192 : background_page_ready(false), | |
| 193 being_upgraded(false), | |
| 194 has_used_webrequest(false) { | |
| 195 } | |
| 196 | |
| 197 ExtensionService::ExtensionRuntimeData::~ExtensionRuntimeData() { | |
| 198 } | |
| 199 | |
| 200 // ExtensionService. | 192 // ExtensionService. |
| 201 | 193 |
| 202 void ExtensionService::CheckExternalUninstall(const std::string& id) { | 194 void ExtensionService::CheckExternalUninstall(const std::string& id) { |
| 203 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 195 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 204 | 196 |
| 205 // Check if the providers know about this extension. | 197 // Check if the providers know about this extension. |
| 206 extensions::ProviderCollection::const_iterator i; | 198 extensions::ProviderCollection::const_iterator i; |
| 207 for (i = external_extension_providers_.begin(); | 199 for (i = external_extension_providers_.begin(); |
| 208 i != external_extension_providers_.end(); ++i) { | 200 i != external_extension_providers_.end(); ++i) { |
| 209 DCHECK(i->get()->IsReady()); | 201 DCHECK(i->get()->IsReady()); |
| (...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 732 if (host && DevToolsAgentHost::HasFor(host->render_view_host())) { | 724 if (host && DevToolsAgentHost::HasFor(host->render_view_host())) { |
| 733 // Look for an open inspector for the background page. | 725 // Look for an open inspector for the background page. |
| 734 scoped_refptr<DevToolsAgentHost> agent_host = | 726 scoped_refptr<DevToolsAgentHost> agent_host = |
| 735 DevToolsAgentHost::GetOrCreateFor(host->render_view_host()); | 727 DevToolsAgentHost::GetOrCreateFor(host->render_view_host()); |
| 736 agent_host->DisconnectRenderViewHost(); | 728 agent_host->DisconnectRenderViewHost(); |
| 737 orphaned_dev_tools_[extension_id] = agent_host; | 729 orphaned_dev_tools_[extension_id] = agent_host; |
| 738 } | 730 } |
| 739 | 731 |
| 740 path = current_extension->path(); | 732 path = current_extension->path(); |
| 741 // BeingUpgraded is set back to false when the extension is added. | 733 // BeingUpgraded is set back to false when the extension is added. |
| 742 SetBeingUpgraded(current_extension, true); | 734 system_->runtime_data()->SetBeingUpgraded(current_extension, true); |
| 743 DisableExtension(extension_id, Extension::DISABLE_RELOAD); | 735 DisableExtension(extension_id, Extension::DISABLE_RELOAD); |
| 744 reloading_extensions_.insert(extension_id); | 736 reloading_extensions_.insert(extension_id); |
| 745 } else { | 737 } else { |
| 746 path = unloaded_extension_paths_[extension_id]; | 738 path = unloaded_extension_paths_[extension_id]; |
| 747 } | 739 } |
| 748 | 740 |
| 749 if (delayed_installs_.Contains(extension_id)) { | 741 if (delayed_installs_.Contains(extension_id)) { |
| 750 FinishDelayedInstallation(extension_id); | 742 FinishDelayedInstallation(extension_id); |
| 751 return; | 743 return; |
| 752 } | 744 } |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 971 | 963 |
| 972 extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED); | 964 extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED); |
| 973 extension_prefs_->AddDisableReason(extension_id, disable_reason); | 965 extension_prefs_->AddDisableReason(extension_id, disable_reason); |
| 974 | 966 |
| 975 int include_mask = | 967 int include_mask = |
| 976 ExtensionRegistry::EVERYTHING & ~ExtensionRegistry::DISABLED; | 968 ExtensionRegistry::EVERYTHING & ~ExtensionRegistry::DISABLED; |
| 977 extension = registry_->GetExtensionById(extension_id, include_mask); | 969 extension = registry_->GetExtensionById(extension_id, include_mask); |
| 978 if (!extension) | 970 if (!extension) |
| 979 return; | 971 return; |
| 980 | 972 |
| 981 // Reset the background_page_ready flag | 973 // Reset the background_page_ready flag. |
| 982 if (extensions::BackgroundInfo::HasBackgroundPage(extension)) | 974 if (extensions::BackgroundInfo::HasBackgroundPage(extension)) |
| 983 extension_runtime_data_[extension->id()].background_page_ready = false; | 975 system_->runtime_data()->SetBackgroundPageReady(extension, false); |
| 984 | 976 |
| 985 // Move it over to the disabled list. Don't send a second unload notification | 977 // Move it over to the disabled list. Don't send a second unload notification |
| 986 // for terminated extensions being disabled. | 978 // for terminated extensions being disabled. |
| 987 registry_->AddDisabled(make_scoped_refptr(extension)); | 979 registry_->AddDisabled(make_scoped_refptr(extension)); |
| 988 if (registry_->enabled_extensions().Contains(extension->id())) { | 980 if (registry_->enabled_extensions().Contains(extension->id())) { |
| 989 registry_->RemoveEnabled(extension->id()); | 981 registry_->RemoveEnabled(extension->id()); |
| 990 NotifyExtensionUnloaded(extension, UnloadedExtensionInfo::REASON_DISABLE); | 982 NotifyExtensionUnloaded(extension, UnloadedExtensionInfo::REASON_DISABLE); |
| 991 } else { | 983 } else { |
| 992 registry_->RemoveTerminated(extension->id()); | 984 registry_->RemoveTerminated(extension->id()); |
| 993 } | 985 } |
| (...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1583 } | 1575 } |
| 1584 | 1576 |
| 1585 // Keep information about the extension so that we can reload it later | 1577 // Keep information about the extension so that we can reload it later |
| 1586 // even if it's not permanently installed. | 1578 // even if it's not permanently installed. |
| 1587 unloaded_extension_paths_[extension->id()] = extension->path(); | 1579 unloaded_extension_paths_[extension->id()] = extension->path(); |
| 1588 | 1580 |
| 1589 // Clean up if the extension is meant to be enabled after a reload. | 1581 // Clean up if the extension is meant to be enabled after a reload. |
| 1590 reloading_extensions_.erase(extension->id()); | 1582 reloading_extensions_.erase(extension->id()); |
| 1591 | 1583 |
| 1592 // Clean up runtime data. | 1584 // Clean up runtime data. |
| 1593 extension_runtime_data_.erase(extension_id); | 1585 system_->runtime_data()->Erase(extension); |
|
not at google - send to devlin
2014/01/18 01:09:04
I would expect RuntimeData to be able to manage cl
James Cook
2014/01/18 02:01:18
I didn't do that because NOTIFICATION_EXTENSION_UN
not at google - send to devlin
2014/01/21 18:47:47
Ah right. I think the solution to this would be to
| |
| 1594 | 1586 |
| 1595 if (registry_->disabled_extensions().Contains(extension->id())) { | 1587 if (registry_->disabled_extensions().Contains(extension->id())) { |
| 1596 registry_->RemoveDisabled(extension->id()); | 1588 registry_->RemoveDisabled(extension->id()); |
| 1597 // Make sure the profile cleans up its RequestContexts when an already | 1589 // Make sure the profile cleans up its RequestContexts when an already |
| 1598 // disabled extension is unloaded (since they are also tracking the disabled | 1590 // disabled extension is unloaded (since they are also tracking the disabled |
| 1599 // extensions). | 1591 // extensions). |
| 1600 system_->UnregisterExtensionWithRequestContexts(extension_id, reason); | 1592 system_->UnregisterExtensionWithRequestContexts(extension_id, reason); |
| 1601 } else { | 1593 } else { |
| 1602 // Remove the extension from the enabled list. | 1594 // Remove the extension from the enabled list. |
| 1603 registry_->RemoveEnabled(extension->id()); | 1595 registry_->RemoveEnabled(extension->id()); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1713 if (old) { | 1705 if (old) { |
| 1714 is_extension_installed = true; | 1706 is_extension_installed = true; |
| 1715 int version_compare_result = | 1707 int version_compare_result = |
| 1716 extension->version()->CompareTo(*(old->version())); | 1708 extension->version()->CompareTo(*(old->version())); |
| 1717 is_extension_upgrade = version_compare_result > 0; | 1709 is_extension_upgrade = version_compare_result > 0; |
| 1718 // Other than for unpacked extensions, CrxInstaller should have guaranteed | 1710 // Other than for unpacked extensions, CrxInstaller should have guaranteed |
| 1719 // that we aren't downgrading. | 1711 // that we aren't downgrading. |
| 1720 if (!Manifest::IsUnpackedLocation(extension->location())) | 1712 if (!Manifest::IsUnpackedLocation(extension->location())) |
| 1721 CHECK_GE(version_compare_result, 0); | 1713 CHECK_GE(version_compare_result, 0); |
| 1722 } | 1714 } |
| 1723 SetBeingUpgraded(extension, is_extension_upgrade); | 1715 system_->runtime_data()->SetBeingUpgraded(extension, is_extension_upgrade); |
| 1724 | 1716 |
| 1725 // The extension is now loaded, remove its data from unloaded extension map. | 1717 // The extension is now loaded, remove its data from unloaded extension map. |
| 1726 unloaded_extension_paths_.erase(extension->id()); | 1718 unloaded_extension_paths_.erase(extension->id()); |
| 1727 | 1719 |
| 1728 // If a terminated extension is loaded, remove it from the terminated list. | 1720 // If a terminated extension is loaded, remove it from the terminated list. |
| 1729 UntrackTerminatedExtension(extension->id()); | 1721 UntrackTerminatedExtension(extension->id()); |
| 1730 | 1722 |
| 1731 // If the extension was disabled for a reload, then enable it. | 1723 // If the extension was disabled for a reload, then enable it. |
| 1732 bool reloading = reloading_extensions_.erase(extension->id()) > 0; | 1724 bool reloading = reloading_extensions_.erase(extension->id()) > 0; |
| 1733 | 1725 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1776 } | 1768 } |
| 1777 extension_prefs_->app_sorting()->EnsureValidOrdinals( | 1769 extension_prefs_->app_sorting()->EnsureValidOrdinals( |
| 1778 extension->id(), syncer::StringOrdinal()); | 1770 extension->id(), syncer::StringOrdinal()); |
| 1779 } | 1771 } |
| 1780 | 1772 |
| 1781 registry_->AddEnabled(extension); | 1773 registry_->AddEnabled(extension); |
| 1782 if (extension_sync_service_) | 1774 if (extension_sync_service_) |
| 1783 extension_sync_service_->SyncExtensionChangeIfNeeded(*extension); | 1775 extension_sync_service_->SyncExtensionChangeIfNeeded(*extension); |
| 1784 NotifyExtensionLoaded(extension); | 1776 NotifyExtensionLoaded(extension); |
| 1785 } | 1777 } |
| 1786 SetBeingUpgraded(extension, false); | 1778 system_->runtime_data()->SetBeingUpgraded(extension, false); |
| 1787 } | 1779 } |
| 1788 | 1780 |
| 1789 void ExtensionService::AddComponentExtension(const Extension* extension) { | 1781 void ExtensionService::AddComponentExtension(const Extension* extension) { |
| 1790 const std::string old_version_string( | 1782 const std::string old_version_string( |
| 1791 extension_prefs_->GetVersionString(extension->id())); | 1783 extension_prefs_->GetVersionString(extension->id())); |
| 1792 const Version old_version(old_version_string); | 1784 const Version old_version(old_version_string); |
| 1793 | 1785 |
| 1794 VLOG(1) << "AddComponentExtension " << extension->name(); | 1786 VLOG(1) << "AddComponentExtension " << extension->name(); |
| 1795 if (!old_version.IsValid() || !old_version.Equals(*extension->version())) { | 1787 if (!old_version.IsValid() || !old_version.Equals(*extension->version())) { |
| 1796 VLOG(1) << "Component extension " << extension->name() << " (" | 1788 VLOG(1) << "Component extension " << extension->name() << " (" |
| (...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2609 const ExtensionSet& extensions = registry_->enabled_extensions(); | 2601 const ExtensionSet& extensions = registry_->enabled_extensions(); |
| 2610 for (ExtensionSet::const_iterator it = extensions.begin(); | 2602 for (ExtensionSet::const_iterator it = extensions.begin(); |
| 2611 it != extensions.end(); ++it) { | 2603 it != extensions.end(); ++it) { |
| 2612 if ((*it)->is_app() && (*it)->location() != Manifest::COMPONENT) | 2604 if ((*it)->is_app() && (*it)->location() != Manifest::COMPONENT) |
| 2613 result.insert((*it)->id()); | 2605 result.insert((*it)->id()); |
| 2614 } | 2606 } |
| 2615 | 2607 |
| 2616 return result; | 2608 return result; |
| 2617 } | 2609 } |
| 2618 | 2610 |
| 2619 bool ExtensionService::IsBackgroundPageReady(const Extension* extension) const { | |
| 2620 if (!extensions::BackgroundInfo::HasPersistentBackgroundPage(extension)) | |
| 2621 return true; | |
| 2622 ExtensionRuntimeDataMap::const_iterator it = | |
| 2623 extension_runtime_data_.find(extension->id()); | |
| 2624 return it == extension_runtime_data_.end() ? false : | |
| 2625 it->second.background_page_ready; | |
| 2626 } | |
| 2627 | |
| 2628 void ExtensionService::SetBackgroundPageReady(const Extension* extension) { | |
| 2629 DCHECK(extensions::BackgroundInfo::HasBackgroundPage(extension)); | |
| 2630 extension_runtime_data_[extension->id()].background_page_ready = true; | |
| 2631 } | |
| 2632 | |
| 2633 bool ExtensionService::IsBeingUpgraded(const Extension* extension) const { | |
| 2634 ExtensionRuntimeDataMap::const_iterator it = | |
| 2635 extension_runtime_data_.find(extension->id()); | |
| 2636 return it == extension_runtime_data_.end() ? false : | |
| 2637 it->second.being_upgraded; | |
| 2638 } | |
| 2639 | |
| 2640 void ExtensionService::SetBeingUpgraded(const Extension* extension, | |
| 2641 bool value) { | |
| 2642 extension_runtime_data_[extension->id()].being_upgraded = value; | |
| 2643 } | |
| 2644 | |
| 2645 bool ExtensionService::IsBeingReloaded( | 2611 bool ExtensionService::IsBeingReloaded( |
| 2646 const std::string& extension_id) const { | 2612 const std::string& extension_id) const { |
| 2647 return ContainsKey(extensions_being_reloaded_, extension_id); | 2613 return ContainsKey(extensions_being_reloaded_, extension_id); |
| 2648 } | 2614 } |
| 2649 | 2615 |
| 2650 void ExtensionService::SetBeingReloaded(const std::string& extension_id, | 2616 void ExtensionService::SetBeingReloaded(const std::string& extension_id, |
| 2651 bool isBeingReloaded) { | 2617 bool isBeingReloaded) { |
| 2652 if (isBeingReloaded) | 2618 if (isBeingReloaded) |
| 2653 extensions_being_reloaded_.insert(extension_id); | 2619 extensions_being_reloaded_.insert(extension_id); |
| 2654 else | 2620 else |
| 2655 extensions_being_reloaded_.erase(extension_id); | 2621 extensions_being_reloaded_.erase(extension_id); |
| 2656 } | 2622 } |
| 2657 | 2623 |
| 2658 bool ExtensionService::HasUsedWebRequest(const Extension* extension) const { | |
| 2659 ExtensionRuntimeDataMap::const_iterator it = | |
| 2660 extension_runtime_data_.find(extension->id()); | |
| 2661 return it == extension_runtime_data_.end() ? false : | |
| 2662 it->second.has_used_webrequest; | |
| 2663 } | |
| 2664 | |
| 2665 void ExtensionService::SetHasUsedWebRequest(const Extension* extension, | |
| 2666 bool value) { | |
| 2667 extension_runtime_data_[extension->id()].has_used_webrequest = value; | |
| 2668 } | |
| 2669 | |
| 2670 bool ExtensionService::ShouldEnableOnInstall(const Extension* extension) { | 2624 bool ExtensionService::ShouldEnableOnInstall(const Extension* extension) { |
| 2671 // Extensions installed by policy can't be disabled. So even if a previous | 2625 // Extensions installed by policy can't be disabled. So even if a previous |
| 2672 // installation disabled the extension, make sure it is now enabled. | 2626 // installation disabled the extension, make sure it is now enabled. |
| 2673 if (system_->management_policy()->MustRemainEnabled(extension, NULL)) | 2627 if (system_->management_policy()->MustRemainEnabled(extension, NULL)) |
| 2674 return true; | 2628 return true; |
| 2675 | 2629 |
| 2676 if (extension_prefs_->IsExtensionDisabled(extension->id())) | 2630 if (extension_prefs_->IsExtensionDisabled(extension->id())) |
| 2677 return false; | 2631 return false; |
| 2678 | 2632 |
| 2679 if (FeatureSwitch::prompt_for_external_extensions()->IsEnabled()) { | 2633 if (FeatureSwitch::prompt_for_external_extensions()->IsEnabled()) { |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2812 void ExtensionService::RemoveUpdateObserver( | 2766 void ExtensionService::RemoveUpdateObserver( |
| 2813 extensions::UpdateObserver* observer) { | 2767 extensions::UpdateObserver* observer) { |
| 2814 update_observers_.RemoveObserver(observer); | 2768 update_observers_.RemoveObserver(observer); |
| 2815 } | 2769 } |
| 2816 | 2770 |
| 2817 // Used only by test code. | 2771 // Used only by test code. |
| 2818 void ExtensionService::UnloadAllExtensionsInternal() { | 2772 void ExtensionService::UnloadAllExtensionsInternal() { |
| 2819 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions(); | 2773 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions(); |
| 2820 | 2774 |
| 2821 registry_->ClearAll(); | 2775 registry_->ClearAll(); |
| 2822 extension_runtime_data_.clear(); | 2776 system_->runtime_data()->ClearAll(); |
| 2823 | 2777 |
| 2824 // TODO(erikkay) should there be a notification for this? We can't use | 2778 // TODO(erikkay) should there be a notification for this? We can't use |
| 2825 // EXTENSION_UNLOADED since that implies that the extension has been disabled | 2779 // EXTENSION_UNLOADED since that implies that the extension has been disabled |
| 2826 // or uninstalled. | 2780 // or uninstalled. |
| 2827 } | 2781 } |
| OLD | NEW |