| 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 774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 if (!GetFileTaskRunner()->PostTask( | 785 if (!GetFileTaskRunner()->PostTask( |
| 786 FROM_HERE, | 786 FROM_HERE, |
| 787 base::Bind( | 787 base::Bind( |
| 788 &extension_file_util::UninstallExtension, | 788 &extension_file_util::UninstallExtension, |
| 789 install_directory_, | 789 install_directory_, |
| 790 extension_id))) | 790 extension_id))) |
| 791 NOTREACHED(); | 791 NOTREACHED(); |
| 792 } | 792 } |
| 793 | 793 |
| 794 GURL launch_web_url_origin( | 794 GURL launch_web_url_origin( |
| 795 extensions::AppLaunchInfo::GetLaunchWebURL(extension).GetOrigin()); | 795 extensions::AppLaunchInfo::GetLaunchWebURL(extension.get()).GetOrigin()); |
| 796 bool is_storage_isolated = | 796 bool is_storage_isolated = |
| 797 extensions::AppIsolationInfo::HasIsolatedStorage(extension.get()); | 797 extensions::AppIsolationInfo::HasIsolatedStorage(extension.get()); |
| 798 | 798 |
| 799 if (is_storage_isolated) { | 799 if (is_storage_isolated) { |
| 800 BrowserContext::AsyncObliterateStoragePartition( | 800 BrowserContext::AsyncObliterateStoragePartition( |
| 801 profile_, | 801 profile_, |
| 802 GetSiteForExtensionId(extension_id), | 802 GetSiteForExtensionId(extension_id), |
| 803 base::Bind(&ExtensionService::OnNeedsToGarbageCollectIsolatedStorage, | 803 base::Bind(&ExtensionService::OnNeedsToGarbageCollectIsolatedStorage, |
| 804 AsWeakPtr())); | 804 AsWeakPtr())); |
| 805 } else { | 805 } else { |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1149 extensions::ExtensionUpdater* ExtensionService::updater() { | 1149 extensions::ExtensionUpdater* ExtensionService::updater() { |
| 1150 return updater_.get(); | 1150 return updater_.get(); |
| 1151 } | 1151 } |
| 1152 | 1152 |
| 1153 void ExtensionService::CheckManagementPolicy() { | 1153 void ExtensionService::CheckManagementPolicy() { |
| 1154 std::vector<std::string> to_be_removed; | 1154 std::vector<std::string> to_be_removed; |
| 1155 | 1155 |
| 1156 // Loop through extensions list, unload installed extensions. | 1156 // Loop through extensions list, unload installed extensions. |
| 1157 for (ExtensionSet::const_iterator iter = extensions_.begin(); | 1157 for (ExtensionSet::const_iterator iter = extensions_.begin(); |
| 1158 iter != extensions_.end(); ++iter) { | 1158 iter != extensions_.end(); ++iter) { |
| 1159 const Extension* extension = (*iter); | 1159 const Extension* extension = (iter->get()); |
| 1160 if (!system_->management_policy()->UserMayLoad(extension, NULL)) | 1160 if (!system_->management_policy()->UserMayLoad(extension, NULL)) |
| 1161 to_be_removed.push_back(extension->id()); | 1161 to_be_removed.push_back(extension->id()); |
| 1162 } | 1162 } |
| 1163 | 1163 |
| 1164 // UnloadExtension will change the extensions_ list. So, we should | 1164 // UnloadExtension will change the extensions_ list. So, we should |
| 1165 // call it outside the iterator loop. | 1165 // call it outside the iterator loop. |
| 1166 for (size_t i = 0; i < to_be_removed.size(); ++i) | 1166 for (size_t i = 0; i < to_be_removed.size(); ++i) |
| 1167 UnloadExtension(to_be_removed[i], extension_misc::UNLOAD_REASON_DISABLE); | 1167 UnloadExtension(to_be_removed[i], extension_misc::UNLOAD_REASON_DISABLE); |
| 1168 } | 1168 } |
| 1169 | 1169 |
| (...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1687 it != blacklisted_extensions_.end(); ++it) { | 1687 it != blacklisted_extensions_.end(); ++it) { |
| 1688 std::string id = (*it)->id(); | 1688 std::string id = (*it)->id(); |
| 1689 if (!extension_prefs_->IsBlacklistedExtensionAcknowledged(id)) { | 1689 if (!extension_prefs_->IsBlacklistedExtensionAcknowledged(id)) { |
| 1690 extension_error_ui->AddBlacklistedExtension(id); | 1690 extension_error_ui->AddBlacklistedExtension(id); |
| 1691 needs_alert = true; | 1691 needs_alert = true; |
| 1692 } | 1692 } |
| 1693 } | 1693 } |
| 1694 | 1694 |
| 1695 for (ExtensionSet::const_iterator iter = extensions_.begin(); | 1695 for (ExtensionSet::const_iterator iter = extensions_.begin(); |
| 1696 iter != extensions_.end(); ++iter) { | 1696 iter != extensions_.end(); ++iter) { |
| 1697 const Extension* e = *iter; | 1697 const Extension* e = iter->get(); |
| 1698 | 1698 |
| 1699 // Extensions disabled by policy. Note: this no longer includes blacklisted | 1699 // Extensions disabled by policy. Note: this no longer includes blacklisted |
| 1700 // extensions, though we still show the same UI. | 1700 // extensions, though we still show the same UI. |
| 1701 if (!system_->management_policy()->UserMayLoad(e, NULL)) { | 1701 if (!system_->management_policy()->UserMayLoad(e, NULL)) { |
| 1702 if (!extension_prefs_->IsBlacklistedExtensionAcknowledged(e->id())) { | 1702 if (!extension_prefs_->IsBlacklistedExtensionAcknowledged(e->id())) { |
| 1703 extension_error_ui->AddBlacklistedExtension(e->id()); | 1703 extension_error_ui->AddBlacklistedExtension(e->id()); |
| 1704 needs_alert = true; | 1704 needs_alert = true; |
| 1705 } | 1705 } |
| 1706 } | 1706 } |
| 1707 } | 1707 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1747 extension_error_ui_->Close(); | 1747 extension_error_ui_->Close(); |
| 1748 } | 1748 } |
| 1749 | 1749 |
| 1750 void ExtensionService::UpdateExternalExtensionAlert() { | 1750 void ExtensionService::UpdateExternalExtensionAlert() { |
| 1751 if (!FeatureSwitch::prompt_for_external_extensions()->IsEnabled()) | 1751 if (!FeatureSwitch::prompt_for_external_extensions()->IsEnabled()) |
| 1752 return; | 1752 return; |
| 1753 | 1753 |
| 1754 const Extension* extension = NULL; | 1754 const Extension* extension = NULL; |
| 1755 for (ExtensionSet::const_iterator iter = disabled_extensions_.begin(); | 1755 for (ExtensionSet::const_iterator iter = disabled_extensions_.begin(); |
| 1756 iter != disabled_extensions_.end(); ++iter) { | 1756 iter != disabled_extensions_.end(); ++iter) { |
| 1757 const Extension* e = *iter; | 1757 const Extension* e = iter->get(); |
| 1758 if (IsUnacknowledgedExternalExtension(e)) { | 1758 if (IsUnacknowledgedExternalExtension(e)) { |
| 1759 extension = e; | 1759 extension = e; |
| 1760 break; | 1760 break; |
| 1761 } | 1761 } |
| 1762 } | 1762 } |
| 1763 | 1763 |
| 1764 if (extension) { | 1764 if (extension) { |
| 1765 if (!extensions::HasExternalInstallError(this)) { | 1765 if (!extensions::HasExternalInstallError(this)) { |
| 1766 if (extension_prefs_->IncrementAcknowledgePromptCount(extension->id()) > | 1766 if (extension_prefs_->IncrementAcknowledgePromptCount(extension->id()) > |
| 1767 kMaxExtensionAcknowledgePromptCount) { | 1767 kMaxExtensionAcknowledgePromptCount) { |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2111 // Add all the recognized permissions if the granted permissions list | 2111 // Add all the recognized permissions if the granted permissions list |
| 2112 // hasn't been initialized yet. | 2112 // hasn't been initialized yet. |
| 2113 scoped_refptr<PermissionSet> granted_permissions = | 2113 scoped_refptr<PermissionSet> granted_permissions = |
| 2114 extension_prefs_->GetGrantedPermissions(extension->id()); | 2114 extension_prefs_->GetGrantedPermissions(extension->id()); |
| 2115 CHECK(granted_permissions.get()); | 2115 CHECK(granted_permissions.get()); |
| 2116 | 2116 |
| 2117 // Here, we check if an extension's privileges have increased in a manner | 2117 // Here, we check if an extension's privileges have increased in a manner |
| 2118 // that requires the user's approval. This could occur because the browser | 2118 // that requires the user's approval. This could occur because the browser |
| 2119 // upgraded and recognized additional privileges, or an extension upgrades | 2119 // upgraded and recognized additional privileges, or an extension upgrades |
| 2120 // to a version that requires additional privileges. | 2120 // to a version that requires additional privileges. |
| 2121 is_privilege_increase = | 2121 is_privilege_increase = granted_permissions->HasLessPrivilegesThan( |
| 2122 granted_permissions->HasLessPrivilegesThan( | 2122 extension->GetActivePermissions().get()); |
| 2123 extension->GetActivePermissions()); | |
| 2124 } | 2123 } |
| 2125 | 2124 |
| 2126 if (is_extension_upgrade) { | 2125 if (is_extension_upgrade) { |
| 2127 // If the extension was already disabled, suppress any alerts for becoming | 2126 // If the extension was already disabled, suppress any alerts for becoming |
| 2128 // disabled on permissions increase. | 2127 // disabled on permissions increase. |
| 2129 bool previously_disabled = | 2128 bool previously_disabled = |
| 2130 extension_prefs_->IsExtensionDisabled(extension->id()); | 2129 extension_prefs_->IsExtensionDisabled(extension->id()); |
| 2131 // Legacy disabled extensions do not have a disable reason. Infer that if | 2130 // Legacy disabled extensions do not have a disable reason. Infer that if |
| 2132 // there was no permission increase, it was likely disabled by the user. | 2131 // there was no permission increase, it was likely disabled by the user. |
| 2133 if (previously_disabled && disable_reasons == Extension::DISABLE_NONE && | 2132 if (previously_disabled && disable_reasons == Extension::DISABLE_NONE && |
| (...skipping 27 matching lines...) Expand all Loading... |
| 2161 extension_prefs_->AddDisableReason( | 2160 extension_prefs_->AddDisableReason( |
| 2162 extension->id(), | 2161 extension->id(), |
| 2163 static_cast<Extension::DisableReason>(disable_reasons)); | 2162 static_cast<Extension::DisableReason>(disable_reasons)); |
| 2164 } | 2163 } |
| 2165 } | 2164 } |
| 2166 | 2165 |
| 2167 void ExtensionService::UpdateActiveExtensionsInCrashReporter() { | 2166 void ExtensionService::UpdateActiveExtensionsInCrashReporter() { |
| 2168 std::set<std::string> extension_ids; | 2167 std::set<std::string> extension_ids; |
| 2169 for (ExtensionSet::const_iterator iter = extensions_.begin(); | 2168 for (ExtensionSet::const_iterator iter = extensions_.begin(); |
| 2170 iter != extensions_.end(); ++iter) { | 2169 iter != extensions_.end(); ++iter) { |
| 2171 const Extension* extension = *iter; | 2170 const Extension* extension = iter->get(); |
| 2172 if (!extension->is_theme() && extension->location() != Manifest::COMPONENT) | 2171 if (!extension->is_theme() && extension->location() != Manifest::COMPONENT) |
| 2173 extension_ids.insert(extension->id()); | 2172 extension_ids.insert(extension->id()); |
| 2174 } | 2173 } |
| 2175 | 2174 |
| 2176 child_process_logging::SetActiveExtensions(extension_ids); | 2175 child_process_logging::SetActiveExtensions(extension_ids); |
| 2177 } | 2176 } |
| 2178 | 2177 |
| 2179 void ExtensionService::OnExtensionInstalled( | 2178 void ExtensionService::OnExtensionInstalled( |
| 2180 const Extension* extension, | 2179 const Extension* extension, |
| 2181 const syncer::StringOrdinal& page_ordinal, | 2180 const syncer::StringOrdinal& page_ordinal, |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2576 // to renderers. | 2575 // to renderers. |
| 2577 process->Send(new ExtensionMsg_SetScriptingWhitelist( | 2576 process->Send(new ExtensionMsg_SetScriptingWhitelist( |
| 2578 *Extension::GetScriptingWhitelist())); | 2577 *Extension::GetScriptingWhitelist())); |
| 2579 | 2578 |
| 2580 // Loaded extensions. | 2579 // Loaded extensions. |
| 2581 std::vector<ExtensionMsg_Loaded_Params> loaded_extensions; | 2580 std::vector<ExtensionMsg_Loaded_Params> loaded_extensions; |
| 2582 for (ExtensionSet::const_iterator iter = extensions_.begin(); | 2581 for (ExtensionSet::const_iterator iter = extensions_.begin(); |
| 2583 iter != extensions_.end(); ++iter) { | 2582 iter != extensions_.end(); ++iter) { |
| 2584 // Renderers don't need to know about themes. | 2583 // Renderers don't need to know about themes. |
| 2585 if (!(*iter)->is_theme()) | 2584 if (!(*iter)->is_theme()) |
| 2586 loaded_extensions.push_back(ExtensionMsg_Loaded_Params(*iter)); | 2585 loaded_extensions.push_back(ExtensionMsg_Loaded_Params(iter->get())); |
| 2587 } | 2586 } |
| 2588 process->Send(new ExtensionMsg_Loaded(loaded_extensions)); | 2587 process->Send(new ExtensionMsg_Loaded(loaded_extensions)); |
| 2589 break; | 2588 break; |
| 2590 } | 2589 } |
| 2591 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: { | 2590 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: { |
| 2592 content::RenderProcessHost* process = | 2591 content::RenderProcessHost* process = |
| 2593 content::Source<content::RenderProcessHost>(source).ptr(); | 2592 content::Source<content::RenderProcessHost>(source).ptr(); |
| 2594 Profile* host_profile = | 2593 Profile* host_profile = |
| 2595 Profile::FromBrowserContext(process->GetBrowserContext()); | 2594 Profile::FromBrowserContext(process->GetBrowserContext()); |
| 2596 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile())) | 2595 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile())) |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2783 // Delay installation if the extension is not idle. | 2782 // Delay installation if the extension is not idle. |
| 2784 return !IsExtensionIdle(extension_id); | 2783 return !IsExtensionIdle(extension_id); |
| 2785 } | 2784 } |
| 2786 } | 2785 } |
| 2787 | 2786 |
| 2788 void ExtensionService::GarbageCollectIsolatedStorage() { | 2787 void ExtensionService::GarbageCollectIsolatedStorage() { |
| 2789 scoped_ptr<base::hash_set<base::FilePath> > active_paths( | 2788 scoped_ptr<base::hash_set<base::FilePath> > active_paths( |
| 2790 new base::hash_set<base::FilePath>()); | 2789 new base::hash_set<base::FilePath>()); |
| 2791 for (ExtensionSet::const_iterator it = extensions_.begin(); | 2790 for (ExtensionSet::const_iterator it = extensions_.begin(); |
| 2792 it != extensions_.end(); ++it) { | 2791 it != extensions_.end(); ++it) { |
| 2793 if (extensions::AppIsolationInfo::HasIsolatedStorage(*it)) { | 2792 if (extensions::AppIsolationInfo::HasIsolatedStorage(it->get())) { |
| 2794 active_paths->insert( | 2793 active_paths->insert(BrowserContext::GetStoragePartitionForSite( |
| 2795 BrowserContext::GetStoragePartitionForSite( | 2794 profile_, GetSiteForExtensionId((*it)->id()))->GetPath()); |
| 2796 profile_, | |
| 2797 GetSiteForExtensionId((*it)->id()))->GetPath()); | |
| 2798 } | 2795 } |
| 2799 } | 2796 } |
| 2800 | 2797 |
| 2801 DCHECK(!installs_delayed()); | 2798 DCHECK(!installs_delayed()); |
| 2802 set_installs_delayed(true); | 2799 set_installs_delayed(true); |
| 2803 BrowserContext::GarbageCollectStoragePartitions( | 2800 BrowserContext::GarbageCollectStoragePartitions( |
| 2804 profile_, active_paths.Pass(), | 2801 profile_, active_paths.Pass(), |
| 2805 base::Bind(&ExtensionService::OnGarbageCollectIsolatedStorageFinished, | 2802 base::Bind(&ExtensionService::OnGarbageCollectIsolatedStorageFinished, |
| 2806 AsWeakPtr())); | 2803 AsWeakPtr())); |
| 2807 } | 2804 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2879 } | 2876 } |
| 2880 | 2877 |
| 2881 void ExtensionService::AddUpdateObserver(extensions::UpdateObserver* observer) { | 2878 void ExtensionService::AddUpdateObserver(extensions::UpdateObserver* observer) { |
| 2882 update_observers_.AddObserver(observer); | 2879 update_observers_.AddObserver(observer); |
| 2883 } | 2880 } |
| 2884 | 2881 |
| 2885 void ExtensionService::RemoveUpdateObserver( | 2882 void ExtensionService::RemoveUpdateObserver( |
| 2886 extensions::UpdateObserver* observer) { | 2883 extensions::UpdateObserver* observer) { |
| 2887 update_observers_.RemoveObserver(observer); | 2884 update_observers_.RemoveObserver(observer); |
| 2888 } | 2885 } |
| OLD | NEW |