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 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 889 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 971 const Extension* extension, const char* histogram) { | 972 const Extension* extension, const char* histogram) { |
| 972 // Since this is called from multiple sources, and since the histogram macros | 973 // Since this is called from multiple sources, and since the histogram macros |
| 973 // use statics, we need to manually lookup the histogram ourselves. | 974 // use statics, we need to manually lookup the histogram ourselves. |
| 974 base::HistogramBase* counter = base::LinearHistogram::FactoryGet( | 975 base::HistogramBase* counter = base::LinearHistogram::FactoryGet( |
| 975 histogram, | 976 histogram, |
| 976 1, | 977 1, |
| 977 PermissionMessage::kEnumBoundary, | 978 PermissionMessage::kEnumBoundary, |
| 978 PermissionMessage::kEnumBoundary + 1, | 979 PermissionMessage::kEnumBoundary + 1, |
| 979 base::HistogramBase::kUmaTargetedHistogramFlag); | 980 base::HistogramBase::kUmaTargetedHistogramFlag); |
| 980 | 981 |
| 981 PermissionMessages permissions = | 982 PermissionMessages permissions = extensions::PermissionsData::ForExtension( |
| 982 extensions::PermissionsData::GetPermissionMessages(extension); | 983 extension)->GetPermissionMessages(); |
| 983 if (permissions.empty()) { | 984 if (permissions.empty()) { |
| 984 counter->Add(PermissionMessage::kNone); | 985 counter->Add(PermissionMessage::kNone); |
| 985 } else { | 986 } else { |
| 986 for (PermissionMessages::iterator it = permissions.begin(); | 987 for (PermissionMessages::iterator it = permissions.begin(); |
| 987 it != permissions.end(); ++it) | 988 it != permissions.end(); ++it) |
| 988 counter->Add(it->id()); | 989 counter->Add(it->id()); |
| 989 } | 990 } |
| 990 } | 991 } |
| 991 | 992 |
| 992 void ExtensionService::NotifyExtensionLoaded(const Extension* extension) { | 993 void ExtensionService::NotifyExtensionLoaded(const Extension* extension) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1038 GrantRightsForExtension(extension); | 1039 GrantRightsForExtension(extension); |
| 1039 | 1040 |
| 1040 // TODO(kalman): This is broken. The crash reporter is process-wide so doesn't | 1041 // TODO(kalman): This is broken. The crash reporter is process-wide so doesn't |
| 1041 // work properly multi-profile. Besides which, it should be using | 1042 // work properly multi-profile. Besides which, it should be using |
| 1042 // ExtensionRegistryObserver. See http://crbug.com/355029. | 1043 // ExtensionRegistryObserver. See http://crbug.com/355029. |
| 1043 UpdateActiveExtensionsInCrashReporter(); | 1044 UpdateActiveExtensionsInCrashReporter(); |
| 1044 | 1045 |
| 1045 // If the extension has permission to load chrome://favicon/ resources we need | 1046 // If the extension has permission to load chrome://favicon/ resources we need |
| 1046 // to make sure that the FaviconSource is registered with the | 1047 // to make sure that the FaviconSource is registered with the |
| 1047 // ChromeURLDataManager. | 1048 // ChromeURLDataManager. |
| 1048 if (extensions::PermissionsData::HasHostPermission( | 1049 if (extensions::PermissionsData::ForExtension(extension) |
|
not at google - send to devlin
2014/06/02 23:20:06
here
Devlin
2014/06/03 15:28:21
Done.
| |
| 1049 extension, GURL(chrome::kChromeUIFaviconURL))) { | 1050 ->HasHostPermission(GURL(chrome::kChromeUIFaviconURL))) { |
| 1050 FaviconSource* favicon_source = new FaviconSource(profile_, | 1051 FaviconSource* favicon_source = new FaviconSource(profile_, |
| 1051 FaviconSource::FAVICON); | 1052 FaviconSource::FAVICON); |
| 1052 content::URLDataSource::Add(profile_, favicon_source); | 1053 content::URLDataSource::Add(profile_, favicon_source); |
| 1053 } | 1054 } |
| 1054 | 1055 |
| 1055 #if !defined(OS_ANDROID) | 1056 #if !defined(OS_ANDROID) |
| 1056 // Same for chrome://theme/ resources. | 1057 // Same for chrome://theme/ resources. |
| 1057 if (extensions::PermissionsData::HasHostPermission( | 1058 if (extensions::PermissionsData::ForExtension(extension) |
| 1058 extension, GURL(chrome::kChromeUIThemeURL))) { | 1059 ->HasHostPermission(GURL(chrome::kChromeUIThemeURL))) { |
| 1059 ThemeSource* theme_source = new ThemeSource(profile_); | 1060 ThemeSource* theme_source = new ThemeSource(profile_); |
| 1060 content::URLDataSource::Add(profile_, theme_source); | 1061 content::URLDataSource::Add(profile_, theme_source); |
| 1061 } | 1062 } |
| 1062 | 1063 |
| 1063 // Same for chrome://thumb/ resources. | 1064 // Same for chrome://thumb/ resources. |
| 1064 if (extensions::PermissionsData::HasHostPermission( | 1065 if (extensions::PermissionsData::ForExtension(extension) |
| 1065 extension, GURL(chrome::kChromeUIThumbnailURL))) { | 1066 ->HasHostPermission(GURL(chrome::kChromeUIThumbnailURL))) { |
| 1066 ThumbnailSource* thumbnail_source = new ThumbnailSource(profile_, false); | 1067 ThumbnailSource* thumbnail_source = new ThumbnailSource(profile_, false); |
| 1067 content::URLDataSource::Add(profile_, thumbnail_source); | 1068 content::URLDataSource::Add(profile_, thumbnail_source); |
| 1068 } | 1069 } |
| 1069 #endif | 1070 #endif |
| 1070 } | 1071 } |
| 1071 | 1072 |
| 1072 void ExtensionService::NotifyExtensionUnloaded( | 1073 void ExtensionService::NotifyExtensionUnloaded( |
| 1073 const Extension* extension, | 1074 const Extension* extension, |
| 1074 UnloadedExtensionInfo::Reason reason) { | 1075 UnloadedExtensionInfo::Reason reason) { |
| 1075 UnloadedExtensionInfo details(extension, reason); | 1076 UnloadedExtensionInfo details(extension, reason); |
| (...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1592 scoped_refptr<PermissionSet> active_permissions = | 1593 scoped_refptr<PermissionSet> active_permissions = |
| 1593 extension_prefs_->GetActivePermissions(extension->id()); | 1594 extension_prefs_->GetActivePermissions(extension->id()); |
| 1594 | 1595 |
| 1595 if (active_permissions.get()) { | 1596 if (active_permissions.get()) { |
| 1596 // We restrict the active permissions to be within the bounds defined in the | 1597 // We restrict the active permissions to be within the bounds defined in the |
| 1597 // extension's manifest. | 1598 // extension's manifest. |
| 1598 // a) active permissions must be a subset of optional + default permissions | 1599 // a) active permissions must be a subset of optional + default permissions |
| 1599 // b) active permissions must contains all default permissions | 1600 // b) active permissions must contains all default permissions |
| 1600 scoped_refptr<PermissionSet> total_permissions = | 1601 scoped_refptr<PermissionSet> total_permissions = |
| 1601 PermissionSet::CreateUnion( | 1602 PermissionSet::CreateUnion( |
| 1602 extensions::PermissionsData::GetRequiredPermissions(extension), | 1603 extensions::PermissionsParser::GetRequiredPermissions(extension), |
| 1603 extensions::PermissionsData::GetOptionalPermissions(extension)); | 1604 extensions::PermissionsParser::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 |