Chromium Code Reviews| 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 "base/memory/scoped_vector.h" | 7 #include "base/memory/scoped_vector.h" |
| 8 #include "base/metrics/field_trial.h" | |
| 8 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 9 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 10 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 11 #include "chrome/common/extensions/permissions/chrome_permission_message_rules.h " | 12 #include "chrome/common/extensions/permissions/chrome_permission_message_rules.h " |
| 12 #include "chrome/grit/generated_resources.h" | 13 #include "chrome/grit/generated_resources.h" |
| 13 #include "extensions/common/extensions_client.h" | 14 #include "extensions/common/extensions_client.h" |
| 14 #include "extensions/common/permissions/permission_message.h" | 15 #include "extensions/common/permissions/permission_message.h" |
| 15 #include "extensions/common/permissions/permission_message_util.h" | 16 #include "extensions/common/permissions/permission_message_util.h" |
| 16 #include "extensions/common/permissions/permission_set.h" | 17 #include "extensions/common/permissions/permission_set.h" |
| 17 #include "extensions/common/url_pattern.h" | 18 #include "extensions/common/url_pattern.h" |
| 18 #include "extensions/common/url_pattern_set.h" | 19 #include "extensions/common/url_pattern_set.h" |
| 19 #include "grit/extensions_strings.h" | 20 #include "grit/extensions_strings.h" |
| 20 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 21 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 22 | 23 |
| 23 namespace extensions { | 24 namespace extensions { |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 28 bool IsNewPermissionMessageSystemEnabled() { | |
| 29 const std::string group_name = | |
| 30 base::FieldTrialList::FindFullName("PermissionMessageSystem"); | |
|
Yoyo Zhou
2015/03/12 20:55:57
You haven't defined this field trial yet (see fiel
Marc Treib
2015/03/13 10:43:09
My intention was to enable this through Finch. In
Yoyo Zhou
2015/03/13 18:08:13
Ok.
| |
| 31 return group_name == "NewSystem"; | |
| 32 } | |
| 33 | |
| 27 typedef std::set<PermissionMessage> PermissionMsgSet; | 34 typedef std::set<PermissionMessage> PermissionMsgSet; |
| 28 | 35 |
| 29 template<typename T> | 36 template<typename T> |
| 30 typename T::iterator FindMessageByID(T& messages, int id) { | 37 typename T::iterator FindMessageByID(T& messages, int id) { |
| 31 for (typename T::iterator it = messages.begin(); | 38 for (typename T::iterator it = messages.begin(); |
| 32 it != messages.end(); ++it) { | 39 it != messages.end(); ++it) { |
| 33 if (it->id() == id) | 40 if (it->id() == id) |
| 34 return it; | 41 return it; |
| 35 } | 42 } |
| 36 return messages.end(); | 43 return messages.end(); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 PermissionMessage::ID>::const_iterator it = | 155 PermissionMessage::ID>::const_iterator it = |
| 149 kSuppressList.begin(); | 156 kSuppressList.begin(); |
| 150 it != kSuppressList.end(); | 157 it != kSuppressList.end(); |
| 151 ++it) { | 158 ++it) { |
| 152 SuppressMessage(messages, it->first, it->second); | 159 SuppressMessage(messages, it->first, it->second); |
| 153 } | 160 } |
| 154 | 161 |
| 155 return messages; | 162 return messages; |
| 156 } | 163 } |
| 157 | 164 |
| 165 PermissionMessageStrings | |
| 166 ChromePermissionMessageProvider::GetPermissionMessageStrings( | |
| 167 const PermissionSet* permissions, | |
| 168 Manifest::Type extension_type) const { | |
| 169 PermissionMessageStrings strings; | |
| 170 if (IsNewPermissionMessageSystemEnabled()) { | |
| 171 CoalescedPermissionMessages messages = GetCoalescedPermissionMessages( | |
| 172 GetAllPermissionIDs(permissions, extension_type)); | |
| 173 for (const CoalescedPermissionMessage& msg : messages) | |
| 174 strings.push_back(PermissionMessageString(msg)); | |
| 175 } else { | |
| 176 std::vector<base::string16> messages = | |
| 177 GetLegacyWarningMessages(permissions, extension_type); | |
| 178 std::vector<base::string16> details = | |
| 179 GetLegacyWarningMessagesDetails(permissions, extension_type); | |
| 180 DCHECK_EQ(messages.size(), details.size()); | |
| 181 for (size_t i = 0; i < messages.size(); i++) | |
| 182 strings.push_back(PermissionMessageString(messages[i], details[i])); | |
| 183 } | |
| 184 return strings; | |
| 185 } | |
| 186 | |
| 187 PermissionMessageIDs | |
| 188 ChromePermissionMessageProvider::GetLegacyPermissionMessageIDs( | |
| 189 const PermissionSet* permissions, | |
| 190 Manifest::Type extension_type) const { | |
| 191 PermissionMessageIDs ids; | |
| 192 for (const PermissionMessage& msg : | |
| 193 GetPermissionMessages(permissions, extension_type)) { | |
| 194 ids.push_back(msg.id()); | |
| 195 } | |
| 196 return ids; | |
| 197 } | |
| 198 | |
| 158 CoalescedPermissionMessages | 199 CoalescedPermissionMessages |
| 159 ChromePermissionMessageProvider::GetCoalescedPermissionMessages( | 200 ChromePermissionMessageProvider::GetCoalescedPermissionMessages( |
| 160 const PermissionIDSet& permissions) const { | 201 const PermissionIDSet& permissions) const { |
| 161 std::vector<ChromePermissionMessageRule> rules = | 202 std::vector<ChromePermissionMessageRule> rules = |
| 162 ChromePermissionMessageRule::GetAllRules(); | 203 ChromePermissionMessageRule::GetAllRules(); |
| 163 | 204 |
| 164 // Apply each of the rules, in order, to generate the messages for the given | 205 // Apply each of the rules, in order, to generate the messages for the given |
| 165 // permissions. Once a permission is used in a rule, remove it from the set | 206 // permissions. Once a permission is used in a rule, remove it from the set |
| 166 // of available permissions so it cannot be applied to subsequent rules. | 207 // of available permissions so it cannot be applied to subsequent rules. |
| 167 PermissionIDSet remaining_permissions = permissions; | 208 PermissionIDSet remaining_permissions = permissions; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 178 rule.formatter()->GetPermissionMessage(used_permissions)); | 219 rule.formatter()->GetPermissionMessage(used_permissions)); |
| 179 | 220 |
| 180 remaining_permissions = | 221 remaining_permissions = |
| 181 PermissionIDSet::Difference(remaining_permissions, used_permissions); | 222 PermissionIDSet::Difference(remaining_permissions, used_permissions); |
| 182 } | 223 } |
| 183 } | 224 } |
| 184 | 225 |
| 185 return messages; | 226 return messages; |
| 186 } | 227 } |
| 187 | 228 |
| 188 std::vector<base::string16> ChromePermissionMessageProvider::GetWarningMessages( | 229 std::vector<base::string16> |
| 230 ChromePermissionMessageProvider::GetLegacyWarningMessages( | |
| 189 const PermissionSet* permissions, | 231 const PermissionSet* permissions, |
| 190 Manifest::Type extension_type) const { | 232 Manifest::Type extension_type) const { |
| 191 std::vector<base::string16> message_strings; | 233 std::vector<base::string16> message_strings; |
| 192 std::vector<base::string16> message_details_strings; | 234 std::vector<base::string16> message_details_strings; |
| 193 CoalesceWarningMessages(permissions, | 235 CoalesceWarningMessages(permissions, |
| 194 extension_type, | 236 extension_type, |
| 195 &message_strings, | 237 &message_strings, |
| 196 &message_details_strings); | 238 &message_details_strings); |
| 197 return message_strings; | 239 return message_strings; |
| 198 } | 240 } |
| 199 | 241 |
| 200 std::vector<base::string16> | 242 std::vector<base::string16> |
| 201 ChromePermissionMessageProvider::GetWarningMessagesDetails( | 243 ChromePermissionMessageProvider::GetLegacyWarningMessagesDetails( |
| 202 const PermissionSet* permissions, | 244 const PermissionSet* permissions, |
| 203 Manifest::Type extension_type) const { | 245 Manifest::Type extension_type) const { |
| 204 std::vector<base::string16> message_strings; | 246 std::vector<base::string16> message_strings; |
| 205 std::vector<base::string16> message_details_strings; | 247 std::vector<base::string16> message_details_strings; |
| 206 CoalesceWarningMessages(permissions, | 248 CoalesceWarningMessages(permissions, |
| 207 extension_type, | 249 extension_type, |
| 208 &message_strings, | 250 &message_strings, |
| 209 &message_details_strings); | 251 &message_details_strings); |
| 210 return message_details_strings; | 252 return message_details_strings; |
| 211 } | 253 } |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 523 std::set<std::string> old_hosts_set( | 565 std::set<std::string> old_hosts_set( |
| 524 permission_message_util::GetDistinctHosts(old_list, false, false)); | 566 permission_message_util::GetDistinctHosts(old_list, false, false)); |
| 525 std::set<std::string> new_hosts_only = | 567 std::set<std::string> new_hosts_only = |
| 526 base::STLSetDifference<std::set<std::string> >(new_hosts_set, | 568 base::STLSetDifference<std::set<std::string> >(new_hosts_set, |
| 527 old_hosts_set); | 569 old_hosts_set); |
| 528 | 570 |
| 529 return !new_hosts_only.empty(); | 571 return !new_hosts_only.empty(); |
| 530 } | 572 } |
| 531 | 573 |
| 532 } // namespace extensions | 574 } // namespace extensions |
| OLD | NEW |