| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 #include "extensions/browser/extension_system.h" | 63 #include "extensions/browser/extension_system.h" |
| 64 #include "extensions/browser/install_flag.h" | 64 #include "extensions/browser/install_flag.h" |
| 65 #include "extensions/browser/pref_names.h" | 65 #include "extensions/browser/pref_names.h" |
| 66 #include "extensions/browser/runtime_data.h" | 66 #include "extensions/browser/runtime_data.h" |
| 67 #include "extensions/browser/update_observer.h" | 67 #include "extensions/browser/update_observer.h" |
| 68 #include "extensions/common/extension_messages.h" | 68 #include "extensions/common/extension_messages.h" |
| 69 #include "extensions/common/feature_switch.h" | 69 #include "extensions/common/feature_switch.h" |
| 70 #include "extensions/common/file_util.h" | 70 #include "extensions/common/file_util.h" |
| 71 #include "extensions/common/manifest_constants.h" | 71 #include "extensions/common/manifest_constants.h" |
| 72 #include "extensions/common/manifest_handlers/background_info.h" | 72 #include "extensions/common/manifest_handlers/background_info.h" |
| 73 #include "extensions/common/manifest_handlers/permissions_parser.h" | |
| 74 #include "extensions/common/one_shot_event.h" | 73 #include "extensions/common/one_shot_event.h" |
| 75 #include "extensions/common/permissions/permission_message_provider.h" | 74 #include "extensions/common/permissions/permission_message_provider.h" |
| 76 #include "extensions/common/permissions/permissions_data.h" | 75 #include "extensions/common/permissions/permissions_data.h" |
| 77 | 76 |
| 78 #if defined(OS_CHROMEOS) | 77 #if defined(OS_CHROMEOS) |
| 79 #include "chrome/browser/chromeos/extensions/install_limiter.h" | 78 #include "chrome/browser/chromeos/extensions/install_limiter.h" |
| 80 #include "webkit/browser/fileapi/file_system_backend.h" | 79 #include "webkit/browser/fileapi/file_system_backend.h" |
| 81 #include "webkit/browser/fileapi/file_system_context.h" | 80 #include "webkit/browser/fileapi/file_system_context.h" |
| 82 #endif | 81 #endif |
| 83 | 82 |
| (...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 961 const Extension* extension) { | 960 const Extension* extension) { |
| 962 GrantPermissions(extension); | 961 GrantPermissions(extension); |
| 963 RecordPermissionMessagesHistogram(extension, | 962 RecordPermissionMessagesHistogram(extension, |
| 964 "Extensions.Permissions_ReEnable2"); | 963 "Extensions.Permissions_ReEnable2"); |
| 965 extension_prefs_->SetDidExtensionEscalatePermissions(extension, false); | 964 extension_prefs_->SetDidExtensionEscalatePermissions(extension, false); |
| 966 EnableExtension(extension->id()); | 965 EnableExtension(extension->id()); |
| 967 } | 966 } |
| 968 | 967 |
| 969 void ExtensionService::GrantPermissions(const Extension* extension) { | 968 void ExtensionService::GrantPermissions(const Extension* extension) { |
| 970 CHECK(extension); | 969 CHECK(extension); |
| 971 extensions::PermissionsUpdater perms_updater(profile()); | 970 extensions::PermissionsUpdater(profile()).GrantActivePermissions(extension); |
| 972 perms_updater.GrantActivePermissions(extension); | |
| 973 } | 971 } |
| 974 | 972 |
| 975 // static | 973 // static |
| 976 void ExtensionService::RecordPermissionMessagesHistogram( | 974 void ExtensionService::RecordPermissionMessagesHistogram( |
| 977 const Extension* extension, const char* histogram) { | 975 const Extension* extension, const char* histogram) { |
| 978 // Since this is called from multiple sources, and since the histogram macros | 976 // Since this is called from multiple sources, and since the histogram macros |
| 979 // use statics, we need to manually lookup the histogram ourselves. | 977 // use statics, we need to manually lookup the histogram ourselves. |
| 980 base::HistogramBase* counter = base::LinearHistogram::FactoryGet( | 978 base::HistogramBase* counter = base::LinearHistogram::FactoryGet( |
| 981 histogram, | 979 histogram, |
| 982 1, | 980 1, |
| (...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1584 Extension::ENABLED_COMPONENT, | 1582 Extension::ENABLED_COMPONENT, |
| 1585 extensions::kInstallFlagNone, | 1583 extensions::kInstallFlagNone, |
| 1586 syncer::StringOrdinal(), | 1584 syncer::StringOrdinal(), |
| 1587 std::string()); | 1585 std::string()); |
| 1588 return; | 1586 return; |
| 1589 } | 1587 } |
| 1590 | 1588 |
| 1591 AddExtension(extension); | 1589 AddExtension(extension); |
| 1592 } | 1590 } |
| 1593 | 1591 |
| 1594 void ExtensionService::UpdateActivePermissions(const Extension* extension) { | |
| 1595 // If the extension has used the optional permissions API, it will have a | |
| 1596 // custom set of active permissions defined in the extension prefs. Here, | |
| 1597 // we update the extension's active permissions based on the prefs. | |
| 1598 scoped_refptr<PermissionSet> active_permissions = | |
| 1599 extension_prefs_->GetActivePermissions(extension->id()); | |
| 1600 | |
| 1601 if (active_permissions.get()) { | |
| 1602 // We restrict the active permissions to be within the bounds defined in the | |
| 1603 // extension's manifest. | |
| 1604 // a) active permissions must be a subset of optional + default permissions | |
| 1605 // b) active permissions must contains all default permissions | |
| 1606 scoped_refptr<PermissionSet> total_permissions = PermissionSet::CreateUnion( | |
| 1607 extensions::PermissionsParser::GetRequiredPermissions(extension), | |
| 1608 extensions::PermissionsParser::GetOptionalPermissions(extension)); | |
| 1609 | |
| 1610 // Make sure the active permissions contain no more than optional + default. | |
| 1611 scoped_refptr<PermissionSet> adjusted_active = | |
| 1612 PermissionSet::CreateIntersection( | |
| 1613 total_permissions.get(), active_permissions.get()); | |
| 1614 | |
| 1615 // Make sure the active permissions contain the default permissions. | |
| 1616 adjusted_active = PermissionSet::CreateUnion( | |
| 1617 extensions::PermissionsParser::GetRequiredPermissions(extension), | |
| 1618 adjusted_active.get()); | |
| 1619 | |
| 1620 extensions::PermissionsUpdater perms_updater(profile()); | |
| 1621 perms_updater.UpdateActivePermissions(extension, adjusted_active.get()); | |
| 1622 } | |
| 1623 } | |
| 1624 | |
| 1625 void ExtensionService::CheckPermissionsIncrease(const Extension* extension, | 1592 void ExtensionService::CheckPermissionsIncrease(const Extension* extension, |
| 1626 bool is_extension_installed) { | 1593 bool is_extension_installed) { |
| 1627 UpdateActivePermissions(extension); | 1594 extensions::PermissionsUpdater(profile_).UpdateActivePermissions(extension); |
| 1628 | 1595 |
| 1629 // We keep track of all permissions the user has granted each extension. | 1596 // We keep track of all permissions the user has granted each extension. |
| 1630 // This allows extensions to gracefully support backwards compatibility | 1597 // This allows extensions to gracefully support backwards compatibility |
| 1631 // by including unknown permissions in their manifests. When the user | 1598 // by including unknown permissions in their manifests. When the user |
| 1632 // installs the extension, only the recognized permissions are recorded. | 1599 // installs the extension, only the recognized permissions are recorded. |
| 1633 // When the unknown permissions become recognized (e.g., through browser | 1600 // When the unknown permissions become recognized (e.g., through browser |
| 1634 // upgrade), we can prompt the user to accept these new permissions. | 1601 // upgrade), we can prompt the user to accept these new permissions. |
| 1635 // Extensions can also silently upgrade to less permissions, and then | 1602 // Extensions can also silently upgrade to less permissions, and then |
| 1636 // silently upgrade to a version that adds these permissions back. | 1603 // silently upgrade to a version that adds these permissions back. |
| 1637 // | 1604 // |
| (...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2534 } | 2501 } |
| 2535 | 2502 |
| 2536 void ExtensionService::OnProfileDestructionStarted() { | 2503 void ExtensionService::OnProfileDestructionStarted() { |
| 2537 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); | 2504 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); |
| 2538 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); | 2505 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); |
| 2539 it != ids_to_unload.end(); | 2506 it != ids_to_unload.end(); |
| 2540 ++it) { | 2507 ++it) { |
| 2541 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); | 2508 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); |
| 2542 } | 2509 } |
| 2543 } | 2510 } |
| OLD | NEW |