| 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 #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/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 const PermissionIDSet& permissions) const { | 60 const PermissionIDSet& permissions) const { |
| 61 std::vector<ChromePermissionMessageRule> rules = | 61 std::vector<ChromePermissionMessageRule> rules = |
| 62 ChromePermissionMessageRule::GetAllRules(); | 62 ChromePermissionMessageRule::GetAllRules(); |
| 63 | 63 |
| 64 // Apply each of the rules, in order, to generate the messages for the given | 64 // Apply each of the rules, in order, to generate the messages for the given |
| 65 // permissions. Once a permission is used in a rule, remove it from the set | 65 // permissions. Once a permission is used in a rule, remove it from the set |
| 66 // of available permissions so it cannot be applied to subsequent rules. | 66 // of available permissions so it cannot be applied to subsequent rules. |
| 67 PermissionIDSet remaining_permissions = permissions; | 67 PermissionIDSet remaining_permissions = permissions; |
| 68 CoalescedPermissionMessages messages; | 68 CoalescedPermissionMessages messages; |
| 69 for (const auto& rule : rules) { | 69 for (const auto& rule : rules) { |
| 70 // Only apply the rule if we have all the required permission IDs. | 70 // Only apply the rule if we have all the required permission IDs. If the |
| 71 if (remaining_permissions.ContainsAllIDs(rule.required_permissions())) { | 71 // rule has no required IDs, then apply it only if any of the optional ones |
| 72 // are there. |
| 73 bool has_required_permissions = !rule.required_permissions().empty(); |
| 74 bool use_rule = |
| 75 has_required_permissions |
| 76 ? remaining_permissions.ContainsAllIDs(rule.required_permissions()) |
| 77 : remaining_permissions.ContainsAnyID(rule.optional_permissions()); |
| 78 if (use_rule) { |
| 72 // We can apply the rule. Add all the required permissions, and as many | 79 // We can apply the rule. Add all the required permissions, and as many |
| 73 // optional permissions as we can, to the new message. | 80 // optional permissions as we can, to the new message. |
| 74 PermissionIDSet used_permissions = | 81 PermissionIDSet used_permissions = |
| 75 remaining_permissions.GetAllPermissionsWithIDs( | 82 remaining_permissions.GetAllPermissionsWithIDs( |
| 76 rule.all_permissions()); | 83 rule.all_permissions()); |
| 77 messages.push_back(rule.GetPermissionMessage(used_permissions)); | 84 messages.push_back(rule.GetPermissionMessage(used_permissions)); |
| 78 | 85 |
| 79 remaining_permissions = | 86 remaining_permissions = |
| 80 PermissionIDSet::Difference(remaining_permissions, used_permissions); | 87 PermissionIDSet::Difference(remaining_permissions, used_permissions); |
| 81 } | 88 } |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 std::set<std::string> old_hosts_set( | 255 std::set<std::string> old_hosts_set( |
| 249 permission_message_util::GetDistinctHosts(old_list, false, false)); | 256 permission_message_util::GetDistinctHosts(old_list, false, false)); |
| 250 std::set<std::string> new_hosts_only = | 257 std::set<std::string> new_hosts_only = |
| 251 base::STLSetDifference<std::set<std::string> >(new_hosts_set, | 258 base::STLSetDifference<std::set<std::string> >(new_hosts_set, |
| 252 old_hosts_set); | 259 old_hosts_set); |
| 253 | 260 |
| 254 return !new_hosts_only.empty(); | 261 return !new_hosts_only.empty(); |
| 255 } | 262 } |
| 256 | 263 |
| 257 } // namespace extensions | 264 } // namespace extensions |
| OLD | NEW |