Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #ifndef EXTENSIONS_COMMON_PERMISSIONS_PERMISSION_MESSAGE_PROVIDER_H_ | 5 #ifndef EXTENSIONS_COMMON_PERMISSIONS_PERMISSION_MESSAGE_PROVIDER_H_ |
| 6 #define EXTENSIONS_COMMON_PERMISSIONS_PERMISSION_MESSAGE_PROVIDER_H_ | 6 #define EXTENSIONS_COMMON_PERMISSIONS_PERMISSION_MESSAGE_PROVIDER_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "extensions/common/manifest.h" | 10 #include "extensions/common/manifest.h" |
| 11 #include "extensions/common/permissions/coalesced_permission_message.h" | 11 #include "extensions/common/permissions/coalesced_permission_message.h" |
| 12 #include "extensions/common/permissions/permission_message.h" | 12 #include "extensions/common/permissions/permission_message.h" |
| 13 | 13 |
| 14 namespace extensions { | 14 namespace extensions { |
| 15 | 15 |
| 16 class PermissionIDSet; | 16 class PermissionIDSet; |
| 17 class PermissionSet; | 17 class PermissionSet; |
| 18 | 18 |
| 19 // Temporary type to help the transition between old and new system. | |
| 20 // Essentially a CoalescedPermissionMessage minus the IDs. | |
| 21 // TODO(treib): Remove this once we've switched to the new system. | |
|
sashab
2015/03/13 18:26:20
This was an ingenious idea. Great job.
| |
| 22 struct PermissionMessageString { | |
| 23 PermissionMessageString(const CoalescedPermissionMessage& message); | |
| 24 PermissionMessageString(const base::string16& message, | |
| 25 const base::string16& details); | |
| 26 ~PermissionMessageString(); | |
| 27 | |
| 28 base::string16 message; | |
| 29 std::vector<base::string16> submessages; | |
| 30 }; | |
| 31 typedef std::vector<PermissionMessageString> PermissionMessageStrings; | |
| 32 | |
| 19 // The PermissionMessageProvider interprets permissions, translating them | 33 // The PermissionMessageProvider interprets permissions, translating them |
| 20 // into warning messages to show to the user. It also determines whether | 34 // into warning messages to show to the user. It also determines whether |
| 21 // a new set of permissions entails showing new warning messages. | 35 // a new set of permissions entails showing new warning messages. |
| 22 class PermissionMessageProvider { | 36 class PermissionMessageProvider { |
| 23 public: | 37 public: |
| 24 PermissionMessageProvider() {} | 38 PermissionMessageProvider() {} |
| 25 virtual ~PermissionMessageProvider() {} | 39 virtual ~PermissionMessageProvider() {} |
| 26 | 40 |
| 27 // Return the global permission message provider. | 41 // Return the global permission message provider. |
| 28 static const PermissionMessageProvider* Get(); | 42 static const PermissionMessageProvider* Get(); |
| 29 | 43 |
| 30 // Gets the localized permission messages that represent this set. | 44 // Calculates and returns the full list of permission messages for the given |
| 31 // The set of permission messages shown varies by extension type. | 45 // |permissions|. This forwards to the new GetCoalescedPermissionMessages or |
| 32 // TODO(sashab): Deprecate this method in favor of | 46 // to the old GetWarningMessages/GetWarningMessagesDetails, depending on a |
| 33 // GetCoalescedPermissionMessages() instead. | 47 // cmdline flag. |
| 34 virtual PermissionMessages GetPermissionMessages( | 48 // TODO(treib): Remove this once we've switched to the new system, and update |
| 49 // all callers to use GetCoalescedPermissionMessages directly. | |
| 50 virtual PermissionMessageStrings GetPermissionMessageStrings( | |
| 35 const PermissionSet* permissions, | 51 const PermissionSet* permissions, |
| 36 Manifest::Type extension_type) const = 0; | 52 Manifest::Type extension_type) const = 0; |
| 37 | 53 |
| 54 // Gets the legacy permission message IDs that represent this set. | |
| 55 // Deprecated. You DO NOT want to call this! | |
| 56 // TODO(treib): Remove this once we've switched to the new system. | |
| 57 virtual PermissionMessageIDs GetLegacyPermissionMessageIDs( | |
| 58 const PermissionSet* permissions, | |
| 59 Manifest::Type extension_type) const = 0; | |
| 60 | |
| 38 // Calculates and returns the full list of permission messages for the given | 61 // Calculates and returns the full list of permission messages for the given |
| 39 // |permissions|. This involves converting the given PermissionIDs into | 62 // |permissions|. This involves converting the given PermissionIDs into |
| 40 // localized messages, as well as coalescing and parameterizing any messages | 63 // localized messages, as well as coalescing and parameterizing any messages |
| 41 // that require the permission ID's argument in their message. | 64 // that require the permission ID's argument in their message. |
| 42 // TODO(sashab): Rename this to GetPermissionMessages() once the current one | 65 // TODO(sashab): Rename this to GetPermissionMessages() once the current one |
| 43 // is deprecated. | 66 // is deprecated. |
| 44 virtual CoalescedPermissionMessages GetCoalescedPermissionMessages( | 67 virtual CoalescedPermissionMessages GetCoalescedPermissionMessages( |
| 45 const PermissionIDSet& permissions) const = 0; | 68 const PermissionIDSet& permissions) const = 0; |
| 46 | 69 |
| 47 // Gets the localized permission messages that represent this set (represented | 70 // Gets the localized permission messages that represent this set (represented |
| 48 // as strings). The set of permission messages shown varies by extension type. | 71 // as strings). The set of permission messages shown varies by extension type. |
| 49 // Any permissions added by API, host or manifest permissions need to be added | 72 // Any permissions added by API, host or manifest permissions need to be added |
| 50 // to |permissions| before this function is called. | 73 // to |permissions| before this function is called. |
| 51 // TODO(sashab): Deprecate this method in favor of | 74 // Deprecated; use GetPermissionMessageStrings instead. |
| 52 // GetCoalescedPermissionMessages(). | 75 // TODO(treib): Remove this once we've switched to the new system. |
| 53 virtual std::vector<base::string16> GetWarningMessages( | 76 virtual std::vector<base::string16> GetLegacyWarningMessages( |
| 54 const PermissionSet* permissions, | 77 const PermissionSet* permissions, |
| 55 Manifest::Type extension_type) const = 0; | 78 Manifest::Type extension_type) const = 0; |
| 56 | 79 |
| 57 // Gets the localized permission details for messages that represent this set | 80 // Gets the localized permission details for messages that represent this set |
| 58 // (represented as strings). The set of permission messages shown varies by | 81 // (represented as strings). The set of permission messages shown varies by |
| 59 // extension type. | 82 // extension type. |
| 60 // TODO(sashab): Deprecate this method in favor of | 83 // Deprecated; use GetPermissionMessageStrings instead. |
| 61 // GetCoalescedPermissionMessages(). | 84 // TODO(treib): Remove this once we've switched to the new system. |
| 62 virtual std::vector<base::string16> GetWarningMessagesDetails( | 85 virtual std::vector<base::string16> GetLegacyWarningMessagesDetails( |
| 63 const PermissionSet* permissions, | 86 const PermissionSet* permissions, |
| 64 Manifest::Type extension_type) const = 0; | 87 Manifest::Type extension_type) const = 0; |
| 65 | 88 |
| 66 // Returns true if |new_permissions| has a greater privilege level than | 89 // Returns true if |new_permissions| has a greater privilege level than |
| 67 // |old_permissions|. | 90 // |old_permissions|. |
| 68 // Whether certain permissions are considered varies by extension type. | 91 // Whether certain permissions are considered varies by extension type. |
| 69 // TODO(sashab): Add an implementation of this method that uses | 92 // TODO(sashab): Add an implementation of this method that uses |
| 70 // PermissionIDSet instead, then deprecate this one. | 93 // PermissionIDSet instead, then deprecate this one. |
| 71 virtual bool IsPrivilegeIncrease( | 94 virtual bool IsPrivilegeIncrease( |
| 72 const PermissionSet* old_permissions, | 95 const PermissionSet* old_permissions, |
| 73 const PermissionSet* new_permissions, | 96 const PermissionSet* new_permissions, |
| 74 Manifest::Type extension_type) const = 0; | 97 Manifest::Type extension_type) const = 0; |
| 75 | 98 |
| 76 // Given the permissions for an extension, finds the IDs of all the | 99 // Given the permissions for an extension, finds the IDs of all the |
| 77 // permissions for that extension (including API, manifest and host | 100 // permissions for that extension (including API, manifest and host |
| 78 // permissions). | 101 // permissions). |
| 79 // TODO(sashab): This uses the legacy PermissionSet type. Deprecate or rename | 102 // TODO(sashab): This uses the legacy PermissionSet type. Deprecate or rename |
| 80 // this type, and make this take as little as is needed to work out the | 103 // this type, and make this take as little as is needed to work out the |
| 81 // PermissionIDSet. | 104 // PermissionIDSet. |
| 82 virtual PermissionIDSet GetAllPermissionIDs( | 105 virtual PermissionIDSet GetAllPermissionIDs( |
| 83 const PermissionSet* permissions, | 106 const PermissionSet* permissions, |
| 84 Manifest::Type extension_type) const = 0; | 107 Manifest::Type extension_type) const = 0; |
| 85 }; | 108 }; |
| 86 | 109 |
| 87 } // namespace extensions | 110 } // namespace extensions |
| 88 | 111 |
| 89 #endif // EXTENSIONS_COMMON_PERMISSIONS_PERMISSION_MESSAGE_PROVIDER_H_ | 112 #endif // EXTENSIONS_COMMON_PERMISSIONS_PERMISSION_MESSAGE_PROVIDER_H_ |
| OLD | NEW |