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

Side by Side Diff: chrome/common/extensions/permissions/chrome_permission_message_provider.cc

Issue 1774103002: Cleanup: remove evil hack to suppress permission warnings for searchProvider (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « no previous file | chrome/common/extensions/permissions/chrome_permission_message_provider_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "chrome/common/extensions/permissions/chrome_permission_message_provide r.h" 5 #include "chrome/common/extensions/permissions/chrome_permission_message_provide r.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 26 matching lines...) Expand all
37 if (msg_->message() > rhs.msg_->message()) 37 if (msg_->message() > rhs.msg_->message())
38 return false; 38 return false;
39 return msg_->submessages() < rhs.msg_->submessages(); 39 return msg_->submessages() < rhs.msg_->submessages();
40 } 40 }
41 41
42 private: 42 private:
43 const PermissionMessage* msg_; 43 const PermissionMessage* msg_;
44 }; 44 };
45 using ComparablePermissions = std::vector<ComparablePermission>; 45 using ComparablePermissions = std::vector<ComparablePermission>;
46 46
47 void DropPermissionParameter(APIPermission::ID id,
48 PermissionIDSet* permissions) {
49 if (permissions->ContainsID(id)) {
50 // Erase the permission, and insert it again without a parameter.
51 permissions->erase(id);
52 permissions->insert(id);
53 }
54 }
55
56 } // namespace 47 } // namespace
57 48
58 typedef std::set<PermissionMessage> PermissionMsgSet; 49 typedef std::set<PermissionMessage> PermissionMsgSet;
59 50
60 ChromePermissionMessageProvider::ChromePermissionMessageProvider() { 51 ChromePermissionMessageProvider::ChromePermissionMessageProvider() {
61 } 52 }
62 53
63 ChromePermissionMessageProvider::~ChromePermissionMessageProvider() { 54 ChromePermissionMessageProvider::~ChromePermissionMessageProvider() {
64 } 55 }
65 56
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 bool ChromePermissionMessageProvider::IsAPIOrManifestPrivilegeIncrease( 169 bool ChromePermissionMessageProvider::IsAPIOrManifestPrivilegeIncrease(
179 const PermissionSet& old_permissions, 170 const PermissionSet& old_permissions,
180 const PermissionSet& new_permissions) const { 171 const PermissionSet& new_permissions) const {
181 PermissionIDSet old_ids; 172 PermissionIDSet old_ids;
182 AddAPIPermissions(old_permissions, &old_ids); 173 AddAPIPermissions(old_permissions, &old_ids);
183 AddManifestPermissions(old_permissions, &old_ids); 174 AddManifestPermissions(old_permissions, &old_ids);
184 PermissionIDSet new_ids; 175 PermissionIDSet new_ids;
185 AddAPIPermissions(new_permissions, &new_ids); 176 AddAPIPermissions(new_permissions, &new_ids);
186 AddManifestPermissions(new_permissions, &new_ids); 177 AddManifestPermissions(new_permissions, &new_ids);
187 178
188 // Ugly hack: Before M46 beta, we didn't store the parameter for settings
189 // override permissions in prefs (which is where |old_permissions| is coming
190 // from). To avoid a spurious permission increase warning, drop the parameter.
191 // See crbug.com/533086.
192 // TODO(treib,devlin): Remove this for M48, when hopefully all users will have
193 // updated prefs.
194 const APIPermission::ID kSettingsOverrideIDs[] = {
195 APIPermission::kHomepage, APIPermission::kSearchProvider,
196 APIPermission::kStartupPages};
197 for (auto id : kSettingsOverrideIDs) {
198 DropPermissionParameter(id, &old_ids);
199 DropPermissionParameter(id, &new_ids);
200 }
201
202 // If all the IDs were already there, it's not a privilege increase. 179 // If all the IDs were already there, it's not a privilege increase.
203 if (old_ids.Includes(new_ids)) 180 if (old_ids.Includes(new_ids))
204 return false; 181 return false;
205 182
206 // Otherwise, check the actual messages - not all IDs result in a message, 183 // Otherwise, check the actual messages - not all IDs result in a message,
207 // and some messages can suppress others. 184 // and some messages can suppress others.
208 PermissionMessages old_messages = GetPermissionMessages(old_ids); 185 PermissionMessages old_messages = GetPermissionMessages(old_ids);
209 PermissionMessages new_messages = GetPermissionMessages(new_ids); 186 PermissionMessages new_messages = GetPermissionMessages(new_ids);
210 187
211 ComparablePermissions old_strings(old_messages.begin(), old_messages.end()); 188 ComparablePermissions old_strings(old_messages.begin(), old_messages.end());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 std::set<std::string> old_hosts_set( 223 std::set<std::string> old_hosts_set(
247 permission_message_util::GetDistinctHosts(old_list, false, false)); 224 permission_message_util::GetDistinctHosts(old_list, false, false));
248 std::set<std::string> new_hosts_only = 225 std::set<std::string> new_hosts_only =
249 base::STLSetDifference<std::set<std::string> >(new_hosts_set, 226 base::STLSetDifference<std::set<std::string> >(new_hosts_set,
250 old_hosts_set); 227 old_hosts_set);
251 228
252 return !new_hosts_only.empty(); 229 return !new_hosts_only.empty();
253 } 230 }
254 231
255 } // namespace extensions 232 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/common/extensions/permissions/chrome_permission_message_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698