| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 #include "extensions/browser/extension_registry.h" | 62 #include "extensions/browser/extension_registry.h" |
| 63 #include "extensions/browser/extension_system.h" | 63 #include "extensions/browser/extension_system.h" |
| 64 #include "extensions/browser/pref_names.h" | 64 #include "extensions/browser/pref_names.h" |
| 65 #include "extensions/browser/runtime_data.h" | 65 #include "extensions/browser/runtime_data.h" |
| 66 #include "extensions/browser/update_observer.h" | 66 #include "extensions/browser/update_observer.h" |
| 67 #include "extensions/common/extension_messages.h" | 67 #include "extensions/common/extension_messages.h" |
| 68 #include "extensions/common/feature_switch.h" | 68 #include "extensions/common/feature_switch.h" |
| 69 #include "extensions/common/file_util.h" | 69 #include "extensions/common/file_util.h" |
| 70 #include "extensions/common/manifest_constants.h" | 70 #include "extensions/common/manifest_constants.h" |
| 71 #include "extensions/common/manifest_handlers/background_info.h" | 71 #include "extensions/common/manifest_handlers/background_info.h" |
| 72 #include "extensions/common/manifest_handlers/permissions_parser.h" |
| 72 #include "extensions/common/one_shot_event.h" | 73 #include "extensions/common/one_shot_event.h" |
| 73 #include "extensions/common/permissions/permission_message_provider.h" | 74 #include "extensions/common/permissions/permission_message_provider.h" |
| 74 #include "extensions/common/permissions/permissions_data.h" | 75 #include "extensions/common/permissions/permissions_data.h" |
| 75 | 76 |
| 76 #if defined(OS_CHROMEOS) | 77 #if defined(OS_CHROMEOS) |
| 77 #include "chrome/browser/chromeos/extensions/install_limiter.h" | 78 #include "chrome/browser/chromeos/extensions/install_limiter.h" |
| 78 #include "webkit/browser/fileapi/file_system_backend.h" | 79 #include "webkit/browser/fileapi/file_system_backend.h" |
| 79 #include "webkit/browser/fileapi/file_system_context.h" | 80 #include "webkit/browser/fileapi/file_system_context.h" |
| 80 #endif | 81 #endif |
| 81 | 82 |
| (...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 973 const Extension* extension, const char* histogram) { | 974 const Extension* extension, const char* histogram) { |
| 974 // Since this is called from multiple sources, and since the histogram macros | 975 // Since this is called from multiple sources, and since the histogram macros |
| 975 // use statics, we need to manually lookup the histogram ourselves. | 976 // use statics, we need to manually lookup the histogram ourselves. |
| 976 base::HistogramBase* counter = base::LinearHistogram::FactoryGet( | 977 base::HistogramBase* counter = base::LinearHistogram::FactoryGet( |
| 977 histogram, | 978 histogram, |
| 978 1, | 979 1, |
| 979 PermissionMessage::kEnumBoundary, | 980 PermissionMessage::kEnumBoundary, |
| 980 PermissionMessage::kEnumBoundary + 1, | 981 PermissionMessage::kEnumBoundary + 1, |
| 981 base::HistogramBase::kUmaTargetedHistogramFlag); | 982 base::HistogramBase::kUmaTargetedHistogramFlag); |
| 982 | 983 |
| 983 PermissionMessages permissions = | 984 PermissionMessages permissions = extensions::PermissionsData::ForExtension( |
| 984 extensions::PermissionsData::GetPermissionMessages(extension); | 985 extension)->GetPermissionMessages(); |
| 985 if (permissions.empty()) { | 986 if (permissions.empty()) { |
| 986 counter->Add(PermissionMessage::kNone); | 987 counter->Add(PermissionMessage::kNone); |
| 987 } else { | 988 } else { |
| 988 for (PermissionMessages::iterator it = permissions.begin(); | 989 for (PermissionMessages::iterator it = permissions.begin(); |
| 989 it != permissions.end(); ++it) | 990 it != permissions.end(); ++it) |
| 990 counter->Add(it->id()); | 991 counter->Add(it->id()); |
| 991 } | 992 } |
| 992 } | 993 } |
| 993 | 994 |
| 994 void ExtensionService::NotifyExtensionLoaded(const Extension* extension) { | 995 void ExtensionService::NotifyExtensionLoaded(const Extension* extension) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1037 // TODO(kalman): Convert ExtensionSpecialStoragePolicy to a | 1038 // TODO(kalman): Convert ExtensionSpecialStoragePolicy to a |
| 1038 // BrowserContextKeyedService and use ExtensionRegistryObserver. | 1039 // BrowserContextKeyedService and use ExtensionRegistryObserver. |
| 1039 profile_->GetExtensionSpecialStoragePolicy()-> | 1040 profile_->GetExtensionSpecialStoragePolicy()-> |
| 1040 GrantRightsForExtension(extension); | 1041 GrantRightsForExtension(extension); |
| 1041 | 1042 |
| 1042 // TODO(kalman): This is broken. The crash reporter is process-wide so doesn't | 1043 // TODO(kalman): This is broken. The crash reporter is process-wide so doesn't |
| 1043 // work properly multi-profile. Besides which, it should be using | 1044 // work properly multi-profile. Besides which, it should be using |
| 1044 // ExtensionRegistryObserver. See http://crbug.com/355029. | 1045 // ExtensionRegistryObserver. See http://crbug.com/355029. |
| 1045 UpdateActiveExtensionsInCrashReporter(); | 1046 UpdateActiveExtensionsInCrashReporter(); |
| 1046 | 1047 |
| 1048 const extensions::PermissionsData* permissions_data = |
| 1049 extensions::PermissionsData::ForExtension(extension); |
| 1050 |
| 1047 // If the extension has permission to load chrome://favicon/ resources we need | 1051 // If the extension has permission to load chrome://favicon/ resources we need |
| 1048 // to make sure that the FaviconSource is registered with the | 1052 // to make sure that the FaviconSource is registered with the |
| 1049 // ChromeURLDataManager. | 1053 // ChromeURLDataManager. |
| 1050 if (extensions::PermissionsData::HasHostPermission( | 1054 if (permissions_data->HasHostPermission(GURL(chrome::kChromeUIFaviconURL))) { |
| 1051 extension, GURL(chrome::kChromeUIFaviconURL))) { | |
| 1052 FaviconSource* favicon_source = new FaviconSource(profile_, | 1055 FaviconSource* favicon_source = new FaviconSource(profile_, |
| 1053 FaviconSource::FAVICON); | 1056 FaviconSource::FAVICON); |
| 1054 content::URLDataSource::Add(profile_, favicon_source); | 1057 content::URLDataSource::Add(profile_, favicon_source); |
| 1055 } | 1058 } |
| 1056 | 1059 |
| 1057 #if !defined(OS_ANDROID) | 1060 #if !defined(OS_ANDROID) |
| 1058 // Same for chrome://theme/ resources. | 1061 // Same for chrome://theme/ resources. |
| 1059 if (extensions::PermissionsData::HasHostPermission( | 1062 if (permissions_data->HasHostPermission(GURL(chrome::kChromeUIThemeURL))) { |
| 1060 extension, GURL(chrome::kChromeUIThemeURL))) { | |
| 1061 ThemeSource* theme_source = new ThemeSource(profile_); | 1063 ThemeSource* theme_source = new ThemeSource(profile_); |
| 1062 content::URLDataSource::Add(profile_, theme_source); | 1064 content::URLDataSource::Add(profile_, theme_source); |
| 1063 } | 1065 } |
| 1064 | 1066 |
| 1065 // Same for chrome://thumb/ resources. | 1067 // Same for chrome://thumb/ resources. |
| 1066 if (extensions::PermissionsData::HasHostPermission( | 1068 if (permissions_data->HasHostPermission( |
| 1067 extension, GURL(chrome::kChromeUIThumbnailURL))) { | 1069 GURL(chrome::kChromeUIThumbnailURL))) { |
| 1068 ThumbnailSource* thumbnail_source = new ThumbnailSource(profile_, false); | 1070 ThumbnailSource* thumbnail_source = new ThumbnailSource(profile_, false); |
| 1069 content::URLDataSource::Add(profile_, thumbnail_source); | 1071 content::URLDataSource::Add(profile_, thumbnail_source); |
| 1070 } | 1072 } |
| 1071 #endif | 1073 #endif |
| 1072 } | 1074 } |
| 1073 | 1075 |
| 1074 void ExtensionService::NotifyExtensionUnloaded( | 1076 void ExtensionService::NotifyExtensionUnloaded( |
| 1075 const Extension* extension, | 1077 const Extension* extension, |
| 1076 UnloadedExtensionInfo::Reason reason) { | 1078 UnloadedExtensionInfo::Reason reason) { |
| 1077 UnloadedExtensionInfo details(extension, reason); | 1079 UnloadedExtensionInfo details(extension, reason); |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1590 // custom set of active permissions defined in the extension prefs. Here, | 1592 // custom set of active permissions defined in the extension prefs. Here, |
| 1591 // we update the extension's active permissions based on the prefs. | 1593 // we update the extension's active permissions based on the prefs. |
| 1592 scoped_refptr<PermissionSet> active_permissions = | 1594 scoped_refptr<PermissionSet> active_permissions = |
| 1593 extension_prefs_->GetActivePermissions(extension->id()); | 1595 extension_prefs_->GetActivePermissions(extension->id()); |
| 1594 | 1596 |
| 1595 if (active_permissions.get()) { | 1597 if (active_permissions.get()) { |
| 1596 // We restrict the active permissions to be within the bounds defined in the | 1598 // We restrict the active permissions to be within the bounds defined in the |
| 1597 // extension's manifest. | 1599 // extension's manifest. |
| 1598 // a) active permissions must be a subset of optional + default permissions | 1600 // a) active permissions must be a subset of optional + default permissions |
| 1599 // b) active permissions must contains all default permissions | 1601 // b) active permissions must contains all default permissions |
| 1600 scoped_refptr<PermissionSet> total_permissions = | 1602 scoped_refptr<PermissionSet> total_permissions = PermissionSet::CreateUnion( |
| 1601 PermissionSet::CreateUnion( | 1603 extensions::PermissionsParser::GetRequiredPermissions(extension), |
| 1602 extensions::PermissionsData::GetRequiredPermissions(extension), | 1604 extensions::PermissionsParser::GetOptionalPermissions(extension)); |
| 1603 extensions::PermissionsData::GetOptionalPermissions(extension)); | |
| 1604 | 1605 |
| 1605 // Make sure the active permissions contain no more than optional + default. | 1606 // Make sure the active permissions contain no more than optional + default. |
| 1606 scoped_refptr<PermissionSet> adjusted_active = | 1607 scoped_refptr<PermissionSet> adjusted_active = |
| 1607 PermissionSet::CreateIntersection( | 1608 PermissionSet::CreateIntersection( |
| 1608 total_permissions.get(), active_permissions.get()); | 1609 total_permissions.get(), active_permissions.get()); |
| 1609 | 1610 |
| 1610 // Make sure the active permissions contain the default permissions. | 1611 // Make sure the active permissions contain the default permissions. |
| 1611 adjusted_active = PermissionSet::CreateUnion( | 1612 adjusted_active = PermissionSet::CreateUnion( |
| 1612 extensions::PermissionsData::GetRequiredPermissions(extension), | 1613 extensions::PermissionsParser::GetRequiredPermissions(extension), |
| 1613 adjusted_active.get()); | 1614 adjusted_active.get()); |
| 1614 | 1615 |
| 1615 extensions::PermissionsUpdater perms_updater(profile()); | 1616 extensions::PermissionsUpdater perms_updater(profile()); |
| 1616 perms_updater.UpdateActivePermissions(extension, adjusted_active.get()); | 1617 perms_updater.UpdateActivePermissions(extension, adjusted_active.get()); |
| 1617 } | 1618 } |
| 1618 } | 1619 } |
| 1619 | 1620 |
| 1620 void ExtensionService::CheckPermissionsIncrease(const Extension* extension, | 1621 void ExtensionService::CheckPermissionsIncrease(const Extension* extension, |
| 1621 bool is_extension_installed) { | 1622 bool is_extension_installed) { |
| 1622 UpdateActivePermissions(extension); | 1623 UpdateActivePermissions(extension); |
| (...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2548 } | 2549 } |
| 2549 | 2550 |
| 2550 void ExtensionService::OnProfileDestructionStarted() { | 2551 void ExtensionService::OnProfileDestructionStarted() { |
| 2551 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); | 2552 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); |
| 2552 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); | 2553 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); |
| 2553 it != ids_to_unload.end(); | 2554 it != ids_to_unload.end(); |
| 2554 ++it) { | 2555 ++it) { |
| 2555 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); | 2556 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); |
| 2556 } | 2557 } |
| 2557 } | 2558 } |
| OLD | NEW |