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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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/process_map.h" | 85 #include "extensions/browser/process_map.h" |
| 86 #include "extensions/browser/runtime_data.h" |
86 #include "extensions/browser/update_observer.h" | 87 #include "extensions/browser/update_observer.h" |
87 #include "extensions/common/constants.h" | 88 #include "extensions/common/constants.h" |
88 #include "extensions/common/error_utils.h" | 89 #include "extensions/common/error_utils.h" |
89 #include "extensions/common/extension.h" | 90 #include "extensions/common/extension.h" |
90 #include "extensions/common/extensions_client.h" | 91 #include "extensions/common/extensions_client.h" |
91 #include "extensions/common/feature_switch.h" | 92 #include "extensions/common/feature_switch.h" |
92 #include "extensions/common/manifest.h" | 93 #include "extensions/common/manifest.h" |
93 #include "extensions/common/manifest_constants.h" | 94 #include "extensions/common/manifest_constants.h" |
94 #include "extensions/common/manifest_handlers/background_info.h" | 95 #include "extensions/common/manifest_handlers/background_info.h" |
95 #include "extensions/common/manifest_handlers/incognito_info.h" | 96 #include "extensions/common/manifest_handlers/incognito_info.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 return IsCWSSharedModule(extension); | 183 return IsCWSSharedModule(extension); |
183 } | 184 } |
184 | 185 |
185 private: | 186 private: |
186 DISALLOW_COPY_AND_ASSIGN(SharedModuleProvider); | 187 DISALLOW_COPY_AND_ASSIGN(SharedModuleProvider); |
187 }; | 188 }; |
188 | 189 |
189 | 190 |
190 } // namespace | 191 } // namespace |
191 | 192 |
192 ExtensionService::ExtensionRuntimeData::ExtensionRuntimeData() | |
193 : background_page_ready(false), | |
194 being_upgraded(false), | |
195 has_used_webrequest(false) { | |
196 } | |
197 | |
198 ExtensionService::ExtensionRuntimeData::~ExtensionRuntimeData() { | |
199 } | |
200 | |
201 // ExtensionService. | 193 // ExtensionService. |
202 | 194 |
203 void ExtensionService::CheckExternalUninstall(const std::string& id) { | 195 void ExtensionService::CheckExternalUninstall(const std::string& id) { |
204 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 196 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
205 | 197 |
206 // Check if the providers know about this extension. | 198 // Check if the providers know about this extension. |
207 extensions::ProviderCollection::const_iterator i; | 199 extensions::ProviderCollection::const_iterator i; |
208 for (i = external_extension_providers_.begin(); | 200 for (i = external_extension_providers_.begin(); |
209 i != external_extension_providers_.end(); ++i) { | 201 i != external_extension_providers_.end(); ++i) { |
210 DCHECK(i->get()->IsReady()); | 202 DCHECK(i->get()->IsReady()); |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 if (host && DevToolsAgentHost::HasFor(host->render_view_host())) { | 725 if (host && DevToolsAgentHost::HasFor(host->render_view_host())) { |
734 // Look for an open inspector for the background page. | 726 // Look for an open inspector for the background page. |
735 scoped_refptr<DevToolsAgentHost> agent_host = | 727 scoped_refptr<DevToolsAgentHost> agent_host = |
736 DevToolsAgentHost::GetOrCreateFor(host->render_view_host()); | 728 DevToolsAgentHost::GetOrCreateFor(host->render_view_host()); |
737 agent_host->DisconnectRenderViewHost(); | 729 agent_host->DisconnectRenderViewHost(); |
738 orphaned_dev_tools_[extension_id] = agent_host; | 730 orphaned_dev_tools_[extension_id] = agent_host; |
739 } | 731 } |
740 | 732 |
741 path = current_extension->path(); | 733 path = current_extension->path(); |
742 // BeingUpgraded is set back to false when the extension is added. | 734 // BeingUpgraded is set back to false when the extension is added. |
743 SetBeingUpgraded(current_extension, true); | 735 system_->runtime_data()->SetBeingUpgraded(current_extension, true); |
744 DisableExtension(extension_id, Extension::DISABLE_RELOAD); | 736 DisableExtension(extension_id, Extension::DISABLE_RELOAD); |
745 reloading_extensions_.insert(extension_id); | 737 reloading_extensions_.insert(extension_id); |
746 } else { | 738 } else { |
747 path = unloaded_extension_paths_[extension_id]; | 739 path = unloaded_extension_paths_[extension_id]; |
748 } | 740 } |
749 | 741 |
750 if (delayed_installs_.Contains(extension_id)) { | 742 if (delayed_installs_.Contains(extension_id)) { |
751 FinishDelayedInstallation(extension_id); | 743 FinishDelayedInstallation(extension_id); |
752 return; | 744 return; |
753 } | 745 } |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
972 | 964 |
973 extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED); | 965 extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED); |
974 extension_prefs_->AddDisableReason(extension_id, disable_reason); | 966 extension_prefs_->AddDisableReason(extension_id, disable_reason); |
975 | 967 |
976 int include_mask = | 968 int include_mask = |
977 ExtensionRegistry::EVERYTHING & ~ExtensionRegistry::DISABLED; | 969 ExtensionRegistry::EVERYTHING & ~ExtensionRegistry::DISABLED; |
978 extension = registry_->GetExtensionById(extension_id, include_mask); | 970 extension = registry_->GetExtensionById(extension_id, include_mask); |
979 if (!extension) | 971 if (!extension) |
980 return; | 972 return; |
981 | 973 |
982 // Reset the background_page_ready flag | 974 // The extension is either enabled or terminated. |
983 if (extensions::BackgroundInfo::HasBackgroundPage(extension)) | 975 DCHECK(registry_->enabled_extensions().Contains(extension->id()) || |
984 extension_runtime_data_[extension->id()].background_page_ready = false; | 976 registry_->terminated_extensions().Contains(extension->id())); |
985 | 977 |
986 // Move it over to the disabled list. Don't send a second unload notification | 978 // Move it over to the disabled list. Don't send a second unload notification |
987 // for terminated extensions being disabled. | 979 // for terminated extensions being disabled. |
988 registry_->AddDisabled(make_scoped_refptr(extension)); | 980 registry_->AddDisabled(make_scoped_refptr(extension)); |
989 if (registry_->enabled_extensions().Contains(extension->id())) { | 981 if (registry_->enabled_extensions().Contains(extension->id())) { |
990 registry_->RemoveEnabled(extension->id()); | 982 registry_->RemoveEnabled(extension->id()); |
991 NotifyExtensionUnloaded(extension, UnloadedExtensionInfo::REASON_DISABLE); | 983 NotifyExtensionUnloaded(extension, UnloadedExtensionInfo::REASON_DISABLE); |
992 } else { | 984 } else { |
993 registry_->RemoveTerminated(extension->id()); | 985 registry_->RemoveTerminated(extension->id()); |
994 } | 986 } |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1137 if (extensions::PermissionsData::HasHostPermission( | 1129 if (extensions::PermissionsData::HasHostPermission( |
1138 extension, GURL(chrome::kChromeUIThumbnailURL))) { | 1130 extension, GURL(chrome::kChromeUIThumbnailURL))) { |
1139 ThumbnailSource* thumbnail_source = new ThumbnailSource(profile_, false); | 1131 ThumbnailSource* thumbnail_source = new ThumbnailSource(profile_, false); |
1140 content::URLDataSource::Add(profile_, thumbnail_source); | 1132 content::URLDataSource::Add(profile_, thumbnail_source); |
1141 } | 1133 } |
1142 } | 1134 } |
1143 | 1135 |
1144 void ExtensionService::NotifyExtensionUnloaded( | 1136 void ExtensionService::NotifyExtensionUnloaded( |
1145 const Extension* extension, | 1137 const Extension* extension, |
1146 UnloadedExtensionInfo::Reason reason) { | 1138 UnloadedExtensionInfo::Reason reason) { |
| 1139 registry_->TriggerOnUnloaded(extension); |
| 1140 |
1147 UnloadedExtensionInfo details(extension, reason); | 1141 UnloadedExtensionInfo details(extension, reason); |
1148 content::NotificationService::current()->Notify( | 1142 content::NotificationService::current()->Notify( |
1149 chrome::NOTIFICATION_EXTENSION_UNLOADED, | 1143 chrome::NOTIFICATION_EXTENSION_UNLOADED, |
1150 content::Source<Profile>(profile_), | 1144 content::Source<Profile>(profile_), |
1151 content::Details<UnloadedExtensionInfo>(&details)); | 1145 content::Details<UnloadedExtensionInfo>(&details)); |
1152 | 1146 |
1153 for (content::RenderProcessHost::iterator i( | 1147 for (content::RenderProcessHost::iterator i( |
1154 content::RenderProcessHost::AllHostsIterator()); | 1148 content::RenderProcessHost::AllHostsIterator()); |
1155 !i.IsAtEnd(); i.Advance()) { | 1149 !i.IsAtEnd(); i.Advance()) { |
1156 content::RenderProcessHost* host = i.GetCurrentValue(); | 1150 content::RenderProcessHost* host = i.GetCurrentValue(); |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1583 return; | 1577 return; |
1584 } | 1578 } |
1585 | 1579 |
1586 // Keep information about the extension so that we can reload it later | 1580 // Keep information about the extension so that we can reload it later |
1587 // even if it's not permanently installed. | 1581 // even if it's not permanently installed. |
1588 unloaded_extension_paths_[extension->id()] = extension->path(); | 1582 unloaded_extension_paths_[extension->id()] = extension->path(); |
1589 | 1583 |
1590 // Clean up if the extension is meant to be enabled after a reload. | 1584 // Clean up if the extension is meant to be enabled after a reload. |
1591 reloading_extensions_.erase(extension->id()); | 1585 reloading_extensions_.erase(extension->id()); |
1592 | 1586 |
1593 // Clean up runtime data. | |
1594 extension_runtime_data_.erase(extension_id); | |
1595 | |
1596 if (registry_->disabled_extensions().Contains(extension->id())) { | 1587 if (registry_->disabled_extensions().Contains(extension->id())) { |
1597 registry_->RemoveDisabled(extension->id()); | 1588 registry_->RemoveDisabled(extension->id()); |
1598 // Make sure the profile cleans up its RequestContexts when an already | 1589 // Make sure the profile cleans up its RequestContexts when an already |
1599 // disabled extension is unloaded (since they are also tracking the disabled | 1590 // disabled extension is unloaded (since they are also tracking the disabled |
1600 // extensions). | 1591 // extensions). |
1601 system_->UnregisterExtensionWithRequestContexts(extension_id, reason); | 1592 system_->UnregisterExtensionWithRequestContexts(extension_id, reason); |
| 1593 // Don't send the unloaded notification. It was sent when the extension |
| 1594 // was disabled. |
1602 } else { | 1595 } else { |
1603 // Remove the extension from the enabled list. | 1596 // Remove the extension from the enabled list. |
1604 registry_->RemoveEnabled(extension->id()); | 1597 registry_->RemoveEnabled(extension->id()); |
1605 NotifyExtensionUnloaded(extension.get(), reason); | 1598 NotifyExtensionUnloaded(extension.get(), reason); |
1606 } | 1599 } |
1607 | 1600 |
1608 content::NotificationService::current()->Notify( | 1601 content::NotificationService::current()->Notify( |
1609 chrome::NOTIFICATION_EXTENSION_REMOVED, | 1602 chrome::NOTIFICATION_EXTENSION_REMOVED, |
1610 content::Source<Profile>(profile_), | 1603 content::Source<Profile>(profile_), |
1611 content::Details<const Extension>(extension.get())); | 1604 content::Details<const Extension>(extension.get())); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1714 if (old) { | 1707 if (old) { |
1715 is_extension_installed = true; | 1708 is_extension_installed = true; |
1716 int version_compare_result = | 1709 int version_compare_result = |
1717 extension->version()->CompareTo(*(old->version())); | 1710 extension->version()->CompareTo(*(old->version())); |
1718 is_extension_upgrade = version_compare_result > 0; | 1711 is_extension_upgrade = version_compare_result > 0; |
1719 // Other than for unpacked extensions, CrxInstaller should have guaranteed | 1712 // Other than for unpacked extensions, CrxInstaller should have guaranteed |
1720 // that we aren't downgrading. | 1713 // that we aren't downgrading. |
1721 if (!Manifest::IsUnpackedLocation(extension->location())) | 1714 if (!Manifest::IsUnpackedLocation(extension->location())) |
1722 CHECK_GE(version_compare_result, 0); | 1715 CHECK_GE(version_compare_result, 0); |
1723 } | 1716 } |
1724 SetBeingUpgraded(extension, is_extension_upgrade); | 1717 system_->runtime_data()->SetBeingUpgraded(extension, is_extension_upgrade); |
1725 | 1718 |
1726 // The extension is now loaded, remove its data from unloaded extension map. | 1719 // The extension is now loaded, remove its data from unloaded extension map. |
1727 unloaded_extension_paths_.erase(extension->id()); | 1720 unloaded_extension_paths_.erase(extension->id()); |
1728 | 1721 |
1729 // If a terminated extension is loaded, remove it from the terminated list. | 1722 // If a terminated extension is loaded, remove it from the terminated list. |
1730 UntrackTerminatedExtension(extension->id()); | 1723 UntrackTerminatedExtension(extension->id()); |
1731 | 1724 |
1732 // If the extension was disabled for a reload, then enable it. | 1725 // If the extension was disabled for a reload, then enable it. |
1733 bool reloading = reloading_extensions_.erase(extension->id()) > 0; | 1726 bool reloading = reloading_extensions_.erase(extension->id()) > 0; |
1734 | 1727 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1777 } | 1770 } |
1778 extension_prefs_->app_sorting()->EnsureValidOrdinals( | 1771 extension_prefs_->app_sorting()->EnsureValidOrdinals( |
1779 extension->id(), syncer::StringOrdinal()); | 1772 extension->id(), syncer::StringOrdinal()); |
1780 } | 1773 } |
1781 | 1774 |
1782 registry_->AddEnabled(extension); | 1775 registry_->AddEnabled(extension); |
1783 if (extension_sync_service_) | 1776 if (extension_sync_service_) |
1784 extension_sync_service_->SyncExtensionChangeIfNeeded(*extension); | 1777 extension_sync_service_->SyncExtensionChangeIfNeeded(*extension); |
1785 NotifyExtensionLoaded(extension); | 1778 NotifyExtensionLoaded(extension); |
1786 } | 1779 } |
1787 SetBeingUpgraded(extension, false); | 1780 system_->runtime_data()->SetBeingUpgraded(extension, false); |
1788 } | 1781 } |
1789 | 1782 |
1790 void ExtensionService::AddComponentExtension(const Extension* extension) { | 1783 void ExtensionService::AddComponentExtension(const Extension* extension) { |
1791 const std::string old_version_string( | 1784 const std::string old_version_string( |
1792 extension_prefs_->GetVersionString(extension->id())); | 1785 extension_prefs_->GetVersionString(extension->id())); |
1793 const Version old_version(old_version_string); | 1786 const Version old_version(old_version_string); |
1794 | 1787 |
1795 VLOG(1) << "AddComponentExtension " << extension->name(); | 1788 VLOG(1) << "AddComponentExtension " << extension->name(); |
1796 if (!old_version.IsValid() || !old_version.Equals(*extension->version())) { | 1789 if (!old_version.IsValid() || !old_version.Equals(*extension->version())) { |
1797 VLOG(1) << "Component extension " << extension->name() << " (" | 1790 VLOG(1) << "Component extension " << extension->name() << " (" |
(...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2612 const ExtensionSet& extensions = registry_->enabled_extensions(); | 2605 const ExtensionSet& extensions = registry_->enabled_extensions(); |
2613 for (ExtensionSet::const_iterator it = extensions.begin(); | 2606 for (ExtensionSet::const_iterator it = extensions.begin(); |
2614 it != extensions.end(); ++it) { | 2607 it != extensions.end(); ++it) { |
2615 if ((*it)->is_app() && (*it)->location() != Manifest::COMPONENT) | 2608 if ((*it)->is_app() && (*it)->location() != Manifest::COMPONENT) |
2616 result.insert((*it)->id()); | 2609 result.insert((*it)->id()); |
2617 } | 2610 } |
2618 | 2611 |
2619 return result; | 2612 return result; |
2620 } | 2613 } |
2621 | 2614 |
2622 bool ExtensionService::IsBackgroundPageReady(const Extension* extension) const { | |
2623 if (!extensions::BackgroundInfo::HasPersistentBackgroundPage(extension)) | |
2624 return true; | |
2625 ExtensionRuntimeDataMap::const_iterator it = | |
2626 extension_runtime_data_.find(extension->id()); | |
2627 return it == extension_runtime_data_.end() ? false : | |
2628 it->second.background_page_ready; | |
2629 } | |
2630 | |
2631 void ExtensionService::SetBackgroundPageReady(const Extension* extension) { | |
2632 DCHECK(extensions::BackgroundInfo::HasBackgroundPage(extension)); | |
2633 extension_runtime_data_[extension->id()].background_page_ready = true; | |
2634 } | |
2635 | |
2636 bool ExtensionService::IsBeingUpgraded(const Extension* extension) const { | |
2637 ExtensionRuntimeDataMap::const_iterator it = | |
2638 extension_runtime_data_.find(extension->id()); | |
2639 return it == extension_runtime_data_.end() ? false : | |
2640 it->second.being_upgraded; | |
2641 } | |
2642 | |
2643 void ExtensionService::SetBeingUpgraded(const Extension* extension, | |
2644 bool value) { | |
2645 extension_runtime_data_[extension->id()].being_upgraded = value; | |
2646 } | |
2647 | |
2648 bool ExtensionService::IsBeingReloaded( | 2615 bool ExtensionService::IsBeingReloaded( |
2649 const std::string& extension_id) const { | 2616 const std::string& extension_id) const { |
2650 return ContainsKey(extensions_being_reloaded_, extension_id); | 2617 return ContainsKey(extensions_being_reloaded_, extension_id); |
2651 } | 2618 } |
2652 | 2619 |
2653 void ExtensionService::SetBeingReloaded(const std::string& extension_id, | 2620 void ExtensionService::SetBeingReloaded(const std::string& extension_id, |
2654 bool isBeingReloaded) { | 2621 bool isBeingReloaded) { |
2655 if (isBeingReloaded) | 2622 if (isBeingReloaded) |
2656 extensions_being_reloaded_.insert(extension_id); | 2623 extensions_being_reloaded_.insert(extension_id); |
2657 else | 2624 else |
2658 extensions_being_reloaded_.erase(extension_id); | 2625 extensions_being_reloaded_.erase(extension_id); |
2659 } | 2626 } |
2660 | 2627 |
2661 bool ExtensionService::HasUsedWebRequest(const Extension* extension) const { | |
2662 ExtensionRuntimeDataMap::const_iterator it = | |
2663 extension_runtime_data_.find(extension->id()); | |
2664 return it == extension_runtime_data_.end() ? false : | |
2665 it->second.has_used_webrequest; | |
2666 } | |
2667 | |
2668 void ExtensionService::SetHasUsedWebRequest(const Extension* extension, | |
2669 bool value) { | |
2670 extension_runtime_data_[extension->id()].has_used_webrequest = value; | |
2671 } | |
2672 | |
2673 bool ExtensionService::ShouldEnableOnInstall(const Extension* extension) { | 2628 bool ExtensionService::ShouldEnableOnInstall(const Extension* extension) { |
2674 // Extensions installed by policy can't be disabled. So even if a previous | 2629 // Extensions installed by policy can't be disabled. So even if a previous |
2675 // installation disabled the extension, make sure it is now enabled. | 2630 // installation disabled the extension, make sure it is now enabled. |
2676 if (system_->management_policy()->MustRemainEnabled(extension, NULL)) | 2631 if (system_->management_policy()->MustRemainEnabled(extension, NULL)) |
2677 return true; | 2632 return true; |
2678 | 2633 |
2679 if (extension_prefs_->IsExtensionDisabled(extension->id())) | 2634 if (extension_prefs_->IsExtensionDisabled(extension->id())) |
2680 return false; | 2635 return false; |
2681 | 2636 |
2682 if (FeatureSwitch::prompt_for_external_extensions()->IsEnabled()) { | 2637 if (FeatureSwitch::prompt_for_external_extensions()->IsEnabled()) { |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2815 void ExtensionService::RemoveUpdateObserver( | 2770 void ExtensionService::RemoveUpdateObserver( |
2816 extensions::UpdateObserver* observer) { | 2771 extensions::UpdateObserver* observer) { |
2817 update_observers_.RemoveObserver(observer); | 2772 update_observers_.RemoveObserver(observer); |
2818 } | 2773 } |
2819 | 2774 |
2820 // Used only by test code. | 2775 // Used only by test code. |
2821 void ExtensionService::UnloadAllExtensionsInternal() { | 2776 void ExtensionService::UnloadAllExtensionsInternal() { |
2822 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions(); | 2777 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions(); |
2823 | 2778 |
2824 registry_->ClearAll(); | 2779 registry_->ClearAll(); |
2825 extension_runtime_data_.clear(); | 2780 system_->runtime_data()->ClearAll(); |
2826 | 2781 |
2827 // TODO(erikkay) should there be a notification for this? We can't use | 2782 // TODO(erikkay) should there be a notification for this? We can't use |
2828 // EXTENSION_UNLOADED since that implies that the extension has been disabled | 2783 // EXTENSION_UNLOADED since that implies that the extension has been disabled |
2829 // or uninstalled. | 2784 // or uninstalled. |
2830 } | 2785 } |
OLD | NEW |