| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <iterator> | 10 #include <iterator> |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 } | 450 } |
| 451 for (const std::string& extension : extensions_to_enable) { | 451 for (const std::string& extension : extensions_to_enable) { |
| 452 EnableExtension(extension); | 452 EnableExtension(extension); |
| 453 } | 453 } |
| 454 } | 454 } |
| 455 | 455 |
| 456 void ExtensionService::MaybeFinishShutdownDelayed() { | 456 void ExtensionService::MaybeFinishShutdownDelayed() { |
| 457 TRACE_EVENT0("browser,startup", | 457 TRACE_EVENT0("browser,startup", |
| 458 "ExtensionService::MaybeFinishShutdownDelayed"); | 458 "ExtensionService::MaybeFinishShutdownDelayed"); |
| 459 | 459 |
| 460 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> delayed_info( | 460 std::unique_ptr<extensions::ExtensionPrefs::ExtensionsInfo> delayed_info( |
| 461 extension_prefs_->GetAllDelayedInstallInfo()); | 461 extension_prefs_->GetAllDelayedInstallInfo()); |
| 462 for (size_t i = 0; i < delayed_info->size(); ++i) { | 462 for (size_t i = 0; i < delayed_info->size(); ++i) { |
| 463 ExtensionInfo* info = delayed_info->at(i).get(); | 463 ExtensionInfo* info = delayed_info->at(i).get(); |
| 464 scoped_refptr<const Extension> extension(nullptr); | 464 scoped_refptr<const Extension> extension(nullptr); |
| 465 if (info->extension_manifest) { | 465 if (info->extension_manifest) { |
| 466 std::string error; | 466 std::string error; |
| 467 extension = Extension::Create( | 467 extension = Extension::Create( |
| 468 info->extension_path, info->extension_location, | 468 info->extension_path, info->extension_location, |
| 469 *info->extension_manifest, | 469 *info->extension_manifest, |
| 470 extension_prefs_->GetDelayedInstallCreationFlags(info->extension_id), | 470 extension_prefs_->GetDelayedInstallCreationFlags(info->extension_id), |
| 471 info->extension_id, &error); | 471 info->extension_id, &error); |
| 472 if (extension.get()) | 472 if (extension.get()) |
| 473 delayed_installs_.Insert(extension); | 473 delayed_installs_.Insert(extension); |
| 474 } | 474 } |
| 475 } | 475 } |
| 476 MaybeFinishDelayedInstallations(); | 476 MaybeFinishDelayedInstallations(); |
| 477 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> delayed_info2( | 477 std::unique_ptr<extensions::ExtensionPrefs::ExtensionsInfo> delayed_info2( |
| 478 extension_prefs_->GetAllDelayedInstallInfo()); | 478 extension_prefs_->GetAllDelayedInstallInfo()); |
| 479 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateOnLoad", | 479 UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateOnLoad", |
| 480 delayed_info2->size() - delayed_info->size()); | 480 delayed_info2->size() - delayed_info->size()); |
| 481 } | 481 } |
| 482 | 482 |
| 483 void ExtensionService::LoadGreylistFromPrefs() { | 483 void ExtensionService::LoadGreylistFromPrefs() { |
| 484 TRACE_EVENT0("browser,startup", "ExtensionService::LoadGreylistFromPrefs"); | 484 TRACE_EVENT0("browser,startup", "ExtensionService::LoadGreylistFromPrefs"); |
| 485 | 485 |
| 486 scoped_ptr<ExtensionSet> all_extensions = | 486 std::unique_ptr<ExtensionSet> all_extensions = |
| 487 registry_->GenerateInstalledExtensionsSet(); | 487 registry_->GenerateInstalledExtensionsSet(); |
| 488 | 488 |
| 489 for (const auto& extension : *all_extensions) { | 489 for (const auto& extension : *all_extensions) { |
| 490 const extensions::BlacklistState state = | 490 const extensions::BlacklistState state = |
| 491 extension_prefs_->GetExtensionBlacklistState(extension->id()); | 491 extension_prefs_->GetExtensionBlacklistState(extension->id()); |
| 492 if (state == extensions::BLACKLISTED_SECURITY_VULNERABILITY || | 492 if (state == extensions::BLACKLISTED_SECURITY_VULNERABILITY || |
| 493 state == extensions::BLACKLISTED_POTENTIALLY_UNWANTED || | 493 state == extensions::BLACKLISTED_POTENTIALLY_UNWANTED || |
| 494 state == extensions::BLACKLISTED_CWS_POLICY_VIOLATION) | 494 state == extensions::BLACKLISTED_CWS_POLICY_VIOLATION) |
| 495 greylist_.Insert(extension); | 495 greylist_.Insert(extension); |
| 496 } | 496 } |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 | 667 |
| 668 // If we're reloading a component extension, use the component extension | 668 // If we're reloading a component extension, use the component extension |
| 669 // loader's reloader. | 669 // loader's reloader. |
| 670 if (component_loader_->Exists(extension_id)) { | 670 if (component_loader_->Exists(extension_id)) { |
| 671 component_loader_->Reload(extension_id); | 671 component_loader_->Reload(extension_id); |
| 672 return; | 672 return; |
| 673 } | 673 } |
| 674 | 674 |
| 675 // Check the installed extensions to see if what we're reloading was already | 675 // Check the installed extensions to see if what we're reloading was already |
| 676 // installed. | 676 // installed. |
| 677 scoped_ptr<ExtensionInfo> installed_extension( | 677 std::unique_ptr<ExtensionInfo> installed_extension( |
| 678 extension_prefs_->GetInstalledExtensionInfo(extension_id)); | 678 extension_prefs_->GetInstalledExtensionInfo(extension_id)); |
| 679 if (installed_extension.get() && | 679 if (installed_extension.get() && |
| 680 installed_extension->extension_manifest.get()) { | 680 installed_extension->extension_manifest.get()) { |
| 681 extensions::InstalledLoader(this).Load(*installed_extension, false); | 681 extensions::InstalledLoader(this).Load(*installed_extension, false); |
| 682 } else { | 682 } else { |
| 683 // Otherwise, the extension is unpacked (location LOAD). | 683 // Otherwise, the extension is unpacked (location LOAD). |
| 684 // We should always be able to remember the extension's path. If it's not in | 684 // We should always be able to remember the extension's path. If it's not in |
| 685 // the map, someone failed to update |unloaded_extension_paths_|. | 685 // the map, someone failed to update |unloaded_extension_paths_|. |
| 686 CHECK(!path.empty()); | 686 CHECK(!path.empty()); |
| 687 scoped_refptr<extensions::UnpackedInstaller> unpacked_installer = | 687 scoped_refptr<extensions::UnpackedInstaller> unpacked_installer = |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 934 | 934 |
| 935 // Extensions that are not locked, components or forced by policy should be | 935 // Extensions that are not locked, components or forced by policy should be |
| 936 // locked. Extensions are no longer considered enabled or disabled. Blacklisted | 936 // locked. Extensions are no longer considered enabled or disabled. Blacklisted |
| 937 // extensions are now considered both blacklisted and locked. | 937 // extensions are now considered both blacklisted and locked. |
| 938 void ExtensionService::BlockAllExtensions() { | 938 void ExtensionService::BlockAllExtensions() { |
| 939 if (block_extensions_) | 939 if (block_extensions_) |
| 940 return; | 940 return; |
| 941 block_extensions_ = true; | 941 block_extensions_ = true; |
| 942 | 942 |
| 943 // Blacklisted extensions are already unloaded, need not be blocked. | 943 // Blacklisted extensions are already unloaded, need not be blocked. |
| 944 scoped_ptr<ExtensionSet> extensions = | 944 std::unique_ptr<ExtensionSet> extensions = |
| 945 registry_->GenerateInstalledExtensionsSet(ExtensionRegistry::ENABLED | | 945 registry_->GenerateInstalledExtensionsSet(ExtensionRegistry::ENABLED | |
| 946 ExtensionRegistry::DISABLED | | 946 ExtensionRegistry::DISABLED | |
| 947 ExtensionRegistry::TERMINATED); | 947 ExtensionRegistry::TERMINATED); |
| 948 | 948 |
| 949 for (const auto& extension : *extensions) { | 949 for (const auto& extension : *extensions) { |
| 950 const std::string& id = extension->id(); | 950 const std::string& id = extension->id(); |
| 951 | 951 |
| 952 if (!CanBlockExtension(extension.get())) | 952 if (!CanBlockExtension(extension.get())) |
| 953 continue; | 953 continue; |
| 954 | 954 |
| 955 registry_->RemoveEnabled(id); | 955 registry_->RemoveEnabled(id); |
| 956 registry_->RemoveDisabled(id); | 956 registry_->RemoveDisabled(id); |
| 957 registry_->RemoveTerminated(id); | 957 registry_->RemoveTerminated(id); |
| 958 | 958 |
| 959 registry_->AddBlocked(extension.get()); | 959 registry_->AddBlocked(extension.get()); |
| 960 UnloadExtension(id, extensions::UnloadedExtensionInfo::REASON_LOCK_ALL); | 960 UnloadExtension(id, extensions::UnloadedExtensionInfo::REASON_LOCK_ALL); |
| 961 } | 961 } |
| 962 } | 962 } |
| 963 | 963 |
| 964 // All locked extensions should revert to being either enabled or disabled | 964 // All locked extensions should revert to being either enabled or disabled |
| 965 // as appropriate. | 965 // as appropriate. |
| 966 void ExtensionService::UnblockAllExtensions() { | 966 void ExtensionService::UnblockAllExtensions() { |
| 967 block_extensions_ = false; | 967 block_extensions_ = false; |
| 968 scoped_ptr<ExtensionSet> to_unblock = | 968 std::unique_ptr<ExtensionSet> to_unblock = |
| 969 registry_->GenerateInstalledExtensionsSet(ExtensionRegistry::BLOCKED); | 969 registry_->GenerateInstalledExtensionsSet(ExtensionRegistry::BLOCKED); |
| 970 | 970 |
| 971 for (const auto& extension : *to_unblock) { | 971 for (const auto& extension : *to_unblock) { |
| 972 registry_->RemoveBlocked(extension->id()); | 972 registry_->RemoveBlocked(extension->id()); |
| 973 AddExtension(extension.get()); | 973 AddExtension(extension.get()); |
| 974 } | 974 } |
| 975 } | 975 } |
| 976 | 976 |
| 977 void ExtensionService::GrantPermissionsAndEnableExtension( | 977 void ExtensionService::GrantPermissionsAndEnableExtension( |
| 978 const Extension* extension) { | 978 const Extension* extension) { |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1313 | 1313 |
| 1314 // Install any pending extensions. | 1314 // Install any pending extensions. |
| 1315 if (update_once_all_providers_are_ready_ && updater()) { | 1315 if (update_once_all_providers_are_ready_ && updater()) { |
| 1316 update_once_all_providers_are_ready_ = false; | 1316 update_once_all_providers_are_ready_ = false; |
| 1317 extensions::ExtensionUpdater::CheckParams params; | 1317 extensions::ExtensionUpdater::CheckParams params; |
| 1318 params.callback = external_updates_finished_callback_; | 1318 params.callback = external_updates_finished_callback_; |
| 1319 updater()->CheckNow(params); | 1319 updater()->CheckNow(params); |
| 1320 } | 1320 } |
| 1321 | 1321 |
| 1322 // Uninstall all the unclaimed extensions. | 1322 // Uninstall all the unclaimed extensions. |
| 1323 scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> extensions_info( | 1323 std::unique_ptr<extensions::ExtensionPrefs::ExtensionsInfo> extensions_info( |
| 1324 extension_prefs_->GetInstalledExtensionsInfo()); | 1324 extension_prefs_->GetInstalledExtensionsInfo()); |
| 1325 for (size_t i = 0; i < extensions_info->size(); ++i) { | 1325 for (size_t i = 0; i < extensions_info->size(); ++i) { |
| 1326 ExtensionInfo* info = extensions_info->at(i).get(); | 1326 ExtensionInfo* info = extensions_info->at(i).get(); |
| 1327 if (Manifest::IsExternalLocation(info->extension_location)) | 1327 if (Manifest::IsExternalLocation(info->extension_location)) |
| 1328 CheckExternalUninstall(info->extension_id); | 1328 CheckExternalUninstall(info->extension_id); |
| 1329 } | 1329 } |
| 1330 | 1330 |
| 1331 error_controller_->ShowErrorIfNeeded(); | 1331 error_controller_->ShowErrorIfNeeded(); |
| 1332 | 1332 |
| 1333 external_install_manager_->UpdateExternalExtensionAlert(); | 1333 external_install_manager_->UpdateExternalExtensionAlert(); |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1580 if (auto_grant_permission) | 1580 if (auto_grant_permission) |
| 1581 GrantPermissions(extension); | 1581 GrantPermissions(extension); |
| 1582 | 1582 |
| 1583 bool is_privilege_increase = false; | 1583 bool is_privilege_increase = false; |
| 1584 // We only need to compare the granted permissions to the current permissions | 1584 // We only need to compare the granted permissions to the current permissions |
| 1585 // if the extension has not been auto-granted its permissions above and is | 1585 // if the extension has not been auto-granted its permissions above and is |
| 1586 // installed internally. | 1586 // installed internally. |
| 1587 if (extension->location() == Manifest::INTERNAL && !auto_grant_permission) { | 1587 if (extension->location() == Manifest::INTERNAL && !auto_grant_permission) { |
| 1588 // Add all the recognized permissions if the granted permissions list | 1588 // Add all the recognized permissions if the granted permissions list |
| 1589 // hasn't been initialized yet. | 1589 // hasn't been initialized yet. |
| 1590 scoped_ptr<const PermissionSet> granted_permissions = | 1590 std::unique_ptr<const PermissionSet> granted_permissions = |
| 1591 extension_prefs_->GetGrantedPermissions(extension->id()); | 1591 extension_prefs_->GetGrantedPermissions(extension->id()); |
| 1592 CHECK(granted_permissions.get()); | 1592 CHECK(granted_permissions.get()); |
| 1593 | 1593 |
| 1594 // Here, we check if an extension's privileges have increased in a manner | 1594 // Here, we check if an extension's privileges have increased in a manner |
| 1595 // that requires the user's approval. This could occur because the browser | 1595 // that requires the user's approval. This could occur because the browser |
| 1596 // upgraded and recognized additional privileges, or an extension upgrades | 1596 // upgraded and recognized additional privileges, or an extension upgrades |
| 1597 // to a version that requires additional privileges. | 1597 // to a version that requires additional privileges. |
| 1598 is_privilege_increase = | 1598 is_privilege_increase = |
| 1599 extensions::PermissionMessageProvider::Get()->IsPrivilegeIncrease( | 1599 extensions::PermissionMessageProvider::Get()->IsPrivilegeIncrease( |
| 1600 *granted_permissions, | 1600 *granted_permissions, |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1821 } | 1821 } |
| 1822 } | 1822 } |
| 1823 | 1823 |
| 1824 void ExtensionService::OnExtensionManagementSettingsChanged() { | 1824 void ExtensionService::OnExtensionManagementSettingsChanged() { |
| 1825 error_controller_->ShowErrorIfNeeded(); | 1825 error_controller_->ShowErrorIfNeeded(); |
| 1826 | 1826 |
| 1827 // Revokes blocked permissions from active_permissions for all extensions. | 1827 // Revokes blocked permissions from active_permissions for all extensions. |
| 1828 extensions::ExtensionManagement* settings = | 1828 extensions::ExtensionManagement* settings = |
| 1829 extensions::ExtensionManagementFactory::GetForBrowserContext(profile()); | 1829 extensions::ExtensionManagementFactory::GetForBrowserContext(profile()); |
| 1830 CHECK(settings); | 1830 CHECK(settings); |
| 1831 scoped_ptr<ExtensionSet> all_extensions( | 1831 std::unique_ptr<ExtensionSet> all_extensions( |
| 1832 registry_->GenerateInstalledExtensionsSet()); | 1832 registry_->GenerateInstalledExtensionsSet()); |
| 1833 for (const auto& extension : *all_extensions) { | 1833 for (const auto& extension : *all_extensions) { |
| 1834 if (!settings->IsPermissionSetAllowed( | 1834 if (!settings->IsPermissionSetAllowed( |
| 1835 extension.get(), | 1835 extension.get(), |
| 1836 extension->permissions_data()->active_permissions())) { | 1836 extension->permissions_data()->active_permissions())) { |
| 1837 extensions::PermissionsUpdater(profile()).RemovePermissionsUnsafe( | 1837 extensions::PermissionsUpdater(profile()).RemovePermissionsUnsafe( |
| 1838 extension.get(), *settings->GetBlockedPermissions(extension.get())); | 1838 extension.get(), *settings->GetBlockedPermissions(extension.get())); |
| 1839 } | 1839 } |
| 1840 } | 1840 } |
| 1841 | 1841 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1949 const std::string& id) const { | 1949 const std::string& id) const { |
| 1950 return delayed_installs_.GetByID(id); | 1950 return delayed_installs_.GetByID(id); |
| 1951 } | 1951 } |
| 1952 | 1952 |
| 1953 void ExtensionService::RegisterContentSettings( | 1953 void ExtensionService::RegisterContentSettings( |
| 1954 HostContentSettingsMap* host_content_settings_map) { | 1954 HostContentSettingsMap* host_content_settings_map) { |
| 1955 TRACE_EVENT0("browser,startup", "ExtensionService::RegisterContentSettings"); | 1955 TRACE_EVENT0("browser,startup", "ExtensionService::RegisterContentSettings"); |
| 1956 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1956 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1957 host_content_settings_map->RegisterProvider( | 1957 host_content_settings_map->RegisterProvider( |
| 1958 HostContentSettingsMap::INTERNAL_EXTENSION_PROVIDER, | 1958 HostContentSettingsMap::INTERNAL_EXTENSION_PROVIDER, |
| 1959 scoped_ptr<content_settings::ObservableProvider>( | 1959 std::unique_ptr<content_settings::ObservableProvider>( |
| 1960 new content_settings::InternalExtensionProvider(profile_))); | 1960 new content_settings::InternalExtensionProvider(profile_))); |
| 1961 | 1961 |
| 1962 host_content_settings_map->RegisterProvider( | 1962 host_content_settings_map->RegisterProvider( |
| 1963 HostContentSettingsMap::CUSTOM_EXTENSION_PROVIDER, | 1963 HostContentSettingsMap::CUSTOM_EXTENSION_PROVIDER, |
| 1964 scoped_ptr<content_settings::ObservableProvider>( | 1964 std::unique_ptr<content_settings::ObservableProvider>( |
| 1965 new content_settings::CustomExtensionProvider( | 1965 new content_settings::CustomExtensionProvider( |
| 1966 extensions::ContentSettingsService::Get( | 1966 extensions::ContentSettingsService::Get(profile_) |
| 1967 profile_)->content_settings_store(), | 1967 ->content_settings_store(), |
| 1968 profile_->GetOriginalProfile() != profile_))); | 1968 profile_->GetOriginalProfile() != profile_))); |
| 1969 } | 1969 } |
| 1970 | 1970 |
| 1971 void ExtensionService::TrackTerminatedExtension( | 1971 void ExtensionService::TrackTerminatedExtension( |
| 1972 const std::string& extension_id) { | 1972 const std::string& extension_id) { |
| 1973 extensions_being_terminated_.erase(extension_id); | 1973 extensions_being_terminated_.erase(extension_id); |
| 1974 | 1974 |
| 1975 const Extension* extension = GetInstalledExtension(extension_id); | 1975 const Extension* extension = GetInstalledExtension(extension_id); |
| 1976 if (!extension) { | 1976 if (!extension) { |
| 1977 return; | 1977 return; |
| (...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2451 } | 2451 } |
| 2452 | 2452 |
| 2453 void ExtensionService::OnProfileDestructionStarted() { | 2453 void ExtensionService::OnProfileDestructionStarted() { |
| 2454 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); | 2454 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); |
| 2455 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); | 2455 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); |
| 2456 it != ids_to_unload.end(); | 2456 it != ids_to_unload.end(); |
| 2457 ++it) { | 2457 ++it) { |
| 2458 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); | 2458 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); |
| 2459 } | 2459 } |
| 2460 } | 2460 } |
| OLD | NEW |