Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / extensions / common / permissions / permission_message_provider.h
blobca11ab37b20729026bc5b578b1f6e00f03c35e62
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
3 // found in the LICENSE file.
5 #ifndef EXTENSIONS_COMMON_PERMISSIONS_PERMISSION_MESSAGE_PROVIDER_H_
6 #define EXTENSIONS_COMMON_PERMISSIONS_PERMISSION_MESSAGE_PROVIDER_H_
8 #include <vector>
10 #include "extensions/common/manifest.h"
11 #include "extensions/common/permissions/coalesced_permission_message.h"
12 #include "extensions/common/permissions/permission_message.h"
14 namespace extensions {
16 class PermissionIDSet;
17 class PermissionSet;
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.
22 struct PermissionMessageString {
23 PermissionMessageString(const CoalescedPermissionMessage& message);
24 PermissionMessageString(const base::string16& message);
25 PermissionMessageString(const base::string16& message,
26 const std::vector<base::string16>& submessages);
27 PermissionMessageString(const base::string16& message,
28 const base::string16& details);
29 ~PermissionMessageString();
31 base::string16 message;
32 std::vector<base::string16> submessages;
34 typedef std::vector<PermissionMessageString> PermissionMessageStrings;
36 enum class ForceForTesting {
37 DONT_FORCE,
38 FORCE_OLD,
39 FORCE_NEW
42 void ForcePermissionMessageSystemForTesting(ForceForTesting force);
44 // The PermissionMessageProvider interprets permissions, translating them
45 // into warning messages to show to the user. It also determines whether
46 // a new set of permissions entails showing new warning messages.
47 class PermissionMessageProvider {
48 public:
49 PermissionMessageProvider() {}
50 virtual ~PermissionMessageProvider() {}
52 // Return the global permission message provider.
53 static const PermissionMessageProvider* Get();
55 // Calculates and returns the full list of permission messages for the given
56 // |permissions|. This forwards to the new GetCoalescedPermissionMessages or
57 // to the old GetWarningMessages/GetWarningMessagesDetails, depending on a
58 // cmdline flag.
59 // TODO(treib): Remove this once we've switched to the new system, and update
60 // all callers to use GetCoalescedPermissionMessages directly.
61 PermissionMessageStrings GetPermissionMessageStrings(
62 const PermissionSet* permissions,
63 Manifest::Type extension_type) const;
65 // Gets the legacy permission message IDs that represent this set.
66 // Deprecated. You DO NOT want to call this!
67 // TODO(treib): Remove this once we've switched to the new system.
68 virtual PermissionMessageIDs GetLegacyPermissionMessageIDs(
69 const PermissionSet* permissions,
70 Manifest::Type extension_type) const = 0;
72 // Calculates and returns the full list of permission messages for the given
73 // |permissions|. This involves converting the given PermissionIDs into
74 // localized messages, as well as coalescing and parameterizing any messages
75 // that require the permission ID's argument in their message.
76 // TODO(sashab): Rename this to GetPermissionMessages() once the current one
77 // is deprecated.
78 virtual CoalescedPermissionMessages GetCoalescedPermissionMessages(
79 const PermissionIDSet& permissions) const = 0;
81 // Returns true if |new_permissions| has a greater privilege level than
82 // |old_permissions|.
83 // Whether certain permissions are considered varies by extension type.
84 // TODO(sashab): Add an implementation of this method that uses
85 // PermissionIDSet instead, then deprecate this one.
86 virtual bool IsPrivilegeIncrease(
87 const PermissionSet* old_permissions,
88 const PermissionSet* new_permissions,
89 Manifest::Type extension_type) const = 0;
91 // Given the permissions for an extension, finds the IDs of all the
92 // permissions for that extension (including API, manifest and host
93 // permissions).
94 // TODO(sashab): This uses the legacy PermissionSet type. Deprecate or rename
95 // this type, and make this take as little as is needed to work out the
96 // PermissionIDSet.
97 virtual PermissionIDSet GetAllPermissionIDs(
98 const PermissionSet* permissions,
99 Manifest::Type extension_type) const = 0;
101 private:
102 // Gets the localized permission messages that represent this set (represented
103 // as strings). The set of permission messages shown varies by extension type.
104 // Any permissions added by API, host or manifest permissions need to be added
105 // to |permissions| before this function is called.
106 // Deprecated; use GetPermissionMessageStrings instead.
107 // TODO(treib): Remove this once we've switched to the new system.
108 virtual std::vector<base::string16> GetLegacyWarningMessages(
109 const PermissionSet* permissions,
110 Manifest::Type extension_type) const = 0;
112 // Gets the localized permission details for messages that represent this set
113 // (represented as strings). The set of permission messages shown varies by
114 // extension type.
115 // Deprecated; use GetPermissionMessageStrings instead.
116 // TODO(treib): Remove this once we've switched to the new system.
117 virtual std::vector<base::string16> GetLegacyWarningMessagesDetails(
118 const PermissionSet* permissions,
119 Manifest::Type extension_type) const = 0;
122 } // namespace extensions
124 #endif // EXTENSIONS_COMMON_PERMISSIONS_PERMISSION_MESSAGE_PROVIDER_H_