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 CHROME_COMMON_EXTENSIONS_PERMISSIONS_CHROME_PERMISSION_MESSAGE_PROVIDER_H_
6 #define CHROME_COMMON_EXTENSIONS_PERMISSIONS_CHROME_PERMISSION_MESSAGE_PROVIDER_H_
10 #include "base/basictypes.h"
11 #include "base/gtest_prod_util.h"
12 #include "base/strings/string16.h"
13 #include "extensions/common/permissions/permission_message_provider.h"
15 namespace extensions
{
17 // Tested in two places:
18 // 1. chrome_permission_message_provider_unittest.cc, which is a regular unit
19 // test for this class
20 // 2. chrome/browser/extensions/permission_messages_unittest.cc, which is an
21 // integration test that ensures messages are correctly generated for
22 // extensions created through the extension system.
23 class ChromePermissionMessageProvider
: public PermissionMessageProvider
{
25 ChromePermissionMessageProvider();
26 ~ChromePermissionMessageProvider() override
;
28 // PermissionMessageProvider implementation.
29 // See comments in permission_message_provider.h. TL;DR: You want to use only
30 // GetPermissionMessageStrings to get messages, not the *Legacy* or
31 // *Coalesced* methods.
32 PermissionMessageIDs
GetLegacyPermissionMessageIDs(
33 const PermissionSet
* permissions
,
34 Manifest::Type extension_type
) const override
;
35 CoalescedPermissionMessages
GetCoalescedPermissionMessages(
36 const PermissionIDSet
& permissions
) const override
;
37 std::vector
<base::string16
> GetLegacyWarningMessages(
38 const PermissionSet
* permissions
,
39 Manifest::Type extension_type
) const override
;
40 std::vector
<base::string16
> GetLegacyWarningMessagesDetails(
41 const PermissionSet
* permissions
,
42 Manifest::Type extension_type
) const override
;
43 bool IsPrivilegeIncrease(const PermissionSet
* old_permissions
,
44 const PermissionSet
* new_permissions
,
45 Manifest::Type extension_type
) const override
;
46 PermissionIDSet
GetAllPermissionIDs(
47 const PermissionSet
* permissions
,
48 Manifest::Type extension_type
) const override
;
51 // TODO(treib): Remove this once we've switched to the new system.
52 PermissionMessages
GetLegacyPermissionMessages(
53 const PermissionSet
* permissions
,
54 Manifest::Type extension_type
) const;
56 // Gets the permission messages for the API permissions. Also adds any
57 // permission IDs from API Permissions to |permission_ids|.
58 // TODO(sashab): Deprecate the |permissions| argument, and rename this to
59 // AddAPIPermissions().
60 std::set
<PermissionMessage
> GetAPIPermissionMessages(
61 const PermissionSet
* permissions
,
62 PermissionIDSet
* permission_ids
,
63 Manifest::Type extension_type
) const;
65 // Gets the permission messages for the Manifest permissions. Also adds any
66 // permission IDs from manifest Permissions to |permission_ids|.
67 // TODO(sashab): Deprecate the |permissions| argument, and rename this to
68 // AddManifestPermissions().
69 std::set
<PermissionMessage
> GetManifestPermissionMessages(
70 const PermissionSet
* permissions
,
71 PermissionIDSet
* permission_ids
) const;
73 // Gets the permission messages for the host permissions. Also adds any
74 // permission IDs from host Permissions to |permission_ids|.
75 // TODO(sashab): Deprecate the |permissions| argument, and rename this to
76 // AddHostPermissions().
77 std::set
<PermissionMessage
> GetHostPermissionMessages(
78 const PermissionSet
* permissions
,
79 PermissionIDSet
* permission_ids
,
80 Manifest::Type extension_type
) const;
82 // Applies coalescing rules and writes the resulting messages and their
83 // details into |message_strings| and |message_details_strings|.
84 // TODO(treib): Remove this method as soon as we've fully switched to the
86 void CoalesceWarningMessages(
87 const PermissionSet
* permissions
,
88 Manifest::Type extension_type
,
89 std::vector
<base::string16
>* message_strings
,
90 std::vector
<base::string16
>* message_details_strings
) const;
92 // Returns true if |new_permissions| has an elevated API privilege level
93 // compared to |old_permissions|.
94 bool IsAPIPrivilegeIncrease(const PermissionSet
* old_permissions
,
95 const PermissionSet
* new_permissions
,
96 Manifest::Type extension_type
) const;
98 // Returns true if |new_permissions| has an elevated manifest permission
99 // privilege level compared to |old_permissions|.
100 bool IsManifestPermissionPrivilegeIncrease(
101 const PermissionSet
* old_permissions
,
102 const PermissionSet
* new_permissions
) const;
104 // Returns true if |new_permissions| has more host permissions compared to
105 // |old_permissions|.
106 bool IsHostPrivilegeIncrease(
107 const PermissionSet
* old_permissions
,
108 const PermissionSet
* new_permissions
,
109 Manifest::Type extension_type
) const;
111 DISALLOW_COPY_AND_ASSIGN(ChromePermissionMessageProvider
);
114 } // namespace extensions
116 #endif // CHROME_COMMON_EXTENSIONS_PERMISSIONS_CHROME_PERMISSION_MESSAGE_PROVIDER_H_