Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Side by Side Diff: chrome/common/extensions/permissions/permission_set.h

Issue 10837060: Don't show host permission warnings for platform apps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 CHROME_COMMON_EXTENSIONS_PERMISSIONS_PERMISSION_SET_H_ 5 #ifndef CHROME_COMMON_EXTENSIONS_PERMISSIONS_PERMISSION_SET_H_
6 #define CHROME_COMMON_EXTENSIONS_PERMISSIONS_PERMISSION_SET_H_ 6 #define CHROME_COMMON_EXTENSIONS_PERMISSIONS_PERMISSION_SET_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/gtest_prod_util.h" 13 #include "base/gtest_prod_util.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/memory/singleton.h" 15 #include "base/memory/singleton.h"
16 #include "base/string16.h" 16 #include "base/string16.h"
17 #include "chrome/common/extensions/extension.h"
17 #include "chrome/common/extensions/permissions/api_permission.h" 18 #include "chrome/common/extensions/permissions/api_permission.h"
18 #include "chrome/common/extensions/permissions/permission_message.h" 19 #include "chrome/common/extensions/permissions/permission_message.h"
19 #include "chrome/common/extensions/url_pattern_set.h" 20 #include "chrome/common/extensions/url_pattern_set.h"
20 21
21 namespace extensions { 22 namespace extensions {
22 23
23 class Extension;
24
25 // The PermissionSet is an immutable class that encapsulates an 24 // The PermissionSet is an immutable class that encapsulates an
26 // extension's permissions. The class exposes set operations for combining and 25 // extension's permissions. The class exposes set operations for combining and
27 // manipulating the permissions. 26 // manipulating the permissions.
28 class PermissionSet 27 class PermissionSet
29 : public base::RefCountedThreadSafe<PermissionSet> { 28 : public base::RefCountedThreadSafe<PermissionSet> {
30 public: 29 public:
31 // Creates an empty permission set (e.g. default permissions). 30 // Creates an empty permission set (e.g. default permissions).
32 PermissionSet(); 31 PermissionSet();
33 32
34 // Creates a new permission set based on the |extension| manifest data, and 33 // Creates a new permission set based on the |extension| manifest data, and
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 // (such as APIs that require no permissions, or APIs with functions that 70 // (such as APIs that require no permissions, or APIs with functions that
72 // require no permissions). 71 // require no permissions).
73 std::set<std::string> GetAPIsWithAnyAccessAsStrings() const; 72 std::set<std::string> GetAPIsWithAnyAccessAsStrings() const;
74 73
75 // Returns whether this namespace has any functions which the extension has 74 // Returns whether this namespace has any functions which the extension has
76 // permission to use. For example, even though the extension may not have 75 // permission to use. For example, even though the extension may not have
77 // the "tabs" permission, "tabs.create" requires no permissions so 76 // the "tabs" permission, "tabs.create" requires no permissions so
78 // HasAnyAPIPermission("tabs") will return true. 77 // HasAnyAPIPermission("tabs") will return true.
79 bool HasAnyAccessToAPI(const std::string& api_name) const; 78 bool HasAnyAccessToAPI(const std::string& api_name) const;
80 79
81 // Gets a list of the distinct hosts for displaying to the user.
82 // NOTE: do not use this for comparing permissions, since this disgards some
83 // information.
84 std::set<std::string> GetDistinctHostsForDisplay() const;
85
86 // Gets the localized permission messages that represent this set. 80 // Gets the localized permission messages that represent this set.
87 PermissionMessages GetPermissionMessages() const; 81 // The set of permission messages shown varies by extension type.
82 PermissionMessages GetPermissionMessages(Extension::Type extension_type)
83 const;
88 84
89 // Gets the localized permission messages that represent this set (represented 85 // Gets the localized permission messages that represent this set (represented
90 // as strings). 86 // as strings). The set of permission messages shown varies by extension type.
91 std::vector<string16> GetWarningMessages() const; 87 std::vector<string16> GetWarningMessages(Extension::Type extension_type)
88 const;
92 89
93 // Returns true if this is an empty set (e.g., the default permission set). 90 // Returns true if this is an empty set (e.g., the default permission set).
94 bool IsEmpty() const; 91 bool IsEmpty() const;
95 92
96 // Returns true if the set has the specified API permission. 93 // Returns true if the set has the specified API permission.
97 bool HasAPIPermission(APIPermission::ID permission) const; 94 bool HasAPIPermission(APIPermission::ID permission) const;
98 95
99 // Returns true if the permissions in this set grant access to the specified 96 // Returns true if the permissions in this set grant access to the specified
100 // |function_name|. 97 // |function_name|.
101 bool HasAccessToFunction(const std::string& function_name) const; 98 bool HasAccessToFunction(const std::string& function_name) const;
(...skipping 23 matching lines...) Expand all
125 122
126 const URLPatternSet& effective_hosts() const { return effective_hosts_; } 123 const URLPatternSet& effective_hosts() const { return effective_hosts_; }
127 124
128 const URLPatternSet& explicit_hosts() const { return explicit_hosts_; } 125 const URLPatternSet& explicit_hosts() const { return explicit_hosts_; }
129 126
130 const URLPatternSet& scriptable_hosts() const { return scriptable_hosts_; } 127 const URLPatternSet& scriptable_hosts() const { return scriptable_hosts_; }
131 128
132 private: 129 private:
133 FRIEND_TEST_ALL_PREFIXES(PermissionsTest, HasLessHostPrivilegesThan); 130 FRIEND_TEST_ALL_PREFIXES(PermissionsTest, HasLessHostPrivilegesThan);
134 FRIEND_TEST_ALL_PREFIXES(PermissionsTest, GetWarningMessages_AudioVideo); 131 FRIEND_TEST_ALL_PREFIXES(PermissionsTest, GetWarningMessages_AudioVideo);
132 FRIEND_TEST_ALL_PREFIXES(PermissionsTest, GetDistinctHostsForDisplay);
133 FRIEND_TEST_ALL_PREFIXES(PermissionsTest,
134 GetDistinctHostsForDisplay_ComIsBestRcd);
135 FRIEND_TEST_ALL_PREFIXES(PermissionsTest,
136 GetDistinctHostsForDisplay_NetIs2ndBestRcd);
137 FRIEND_TEST_ALL_PREFIXES(PermissionsTest,
138 GetDistinctHostsForDisplay_OrgIs3rdBestRcd);
139 FRIEND_TEST_ALL_PREFIXES(PermissionsTest,
140 GetDistinctHostsForDisplay_FirstInListIs4thBestRcd);
135 friend class base::RefCountedThreadSafe<PermissionSet>; 141 friend class base::RefCountedThreadSafe<PermissionSet>;
136 142
137 ~PermissionSet(); 143 ~PermissionSet();
138 144
139 static std::set<std::string> GetDistinctHosts( 145 static std::set<std::string> GetDistinctHosts(
140 const URLPatternSet& host_patterns, 146 const URLPatternSet& host_patterns,
141 bool include_rcd, 147 bool include_rcd,
142 bool exclude_file_scheme); 148 bool exclude_file_scheme);
143 149
144 // Initializes the set based on |extension|'s manifest data. 150 // Initializes the set based on |extension|'s manifest data.
(...skipping 11 matching lines...) Expand all
156 // Returns true if |permissions| has an elevated API privilege level than 162 // Returns true if |permissions| has an elevated API privilege level than
157 // this set. 163 // this set.
158 bool HasLessAPIPrivilegesThan( 164 bool HasLessAPIPrivilegesThan(
159 const PermissionSet* permissions) const; 165 const PermissionSet* permissions) const;
160 166
161 // Returns true if |permissions| has more host permissions compared to this 167 // Returns true if |permissions| has more host permissions compared to this
162 // set. 168 // set.
163 bool HasLessHostPrivilegesThan( 169 bool HasLessHostPrivilegesThan(
164 const PermissionSet* permissions) const; 170 const PermissionSet* permissions) const;
165 171
172 // Gets a list of the distinct hosts for displaying to the user.
173 // NOTE: do not use this for comparing permissions, since this disgards some
174 // information.
175 std::set<std::string> GetDistinctHostsForDisplay() const;
176
166 // The api list is used when deciding if an extension can access certain 177 // The api list is used when deciding if an extension can access certain
167 // extension APIs and features. 178 // extension APIs and features.
168 APIPermissionSet apis_; 179 APIPermissionSet apis_;
169 180
170 // The list of hosts that can be accessed directly from the extension. 181 // The list of hosts that can be accessed directly from the extension.
171 // TODO(jstritar): Rename to "hosts_"? 182 // TODO(jstritar): Rename to "hosts_"?
172 URLPatternSet explicit_hosts_; 183 URLPatternSet explicit_hosts_;
173 184
174 // The list of hosts that can be scripted by content scripts. 185 // The list of hosts that can be scripted by content scripts.
175 // TODO(jstritar): Rename to "user_script_hosts_"? 186 // TODO(jstritar): Rename to "user_script_hosts_"?
176 URLPatternSet scriptable_hosts_; 187 URLPatternSet scriptable_hosts_;
177 188
178 // The list of hosts this effectively grants access to. 189 // The list of hosts this effectively grants access to.
179 URLPatternSet effective_hosts_; 190 URLPatternSet effective_hosts_;
180 }; 191 };
181 192
182 } // namespace extensions 193 } // namespace extensions
183 194
184 #endif // CHROME_COMMON_EXTENSIONS_PERMISSIONS_PERMISSION_SET_H_ 195 #endif // CHROME_COMMON_EXTENSIONS_PERMISSIONS_PERMISSION_SET_H_
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension_unittest.cc ('k') | chrome/common/extensions/permissions/permission_set.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698