| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_rules.h
" | 5 #include "chrome/common/extensions/permissions/chrome_permission_message_rules.h
" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 return PermissionMessage( | 248 return PermissionMessage( |
| 249 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE_LIST), | 249 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE_LIST), |
| 250 permissions, submessages); | 250 permissions, submessages); |
| 251 } | 251 } |
| 252 | 252 |
| 253 DISALLOW_COPY_AND_ASSIGN(USBDevicesFormatter); | 253 DISALLOW_COPY_AND_ASSIGN(USBDevicesFormatter); |
| 254 }; | 254 }; |
| 255 | 255 |
| 256 } // namespace | 256 } // namespace |
| 257 | 257 |
| 258 // Convenience constructors to allow inline initialization of the permission | |
| 259 // ID sets. | |
| 260 // TODO(treib): Once we're allowed to use uniform initialization (and | |
| 261 // std::initializer_list), get rid of this helper. | |
| 262 class ChromePermissionMessageRule::PermissionIDSetInitializer | |
| 263 : public std::set<APIPermission::ID> { | |
| 264 public: | |
| 265 template <typename... IDs> | |
| 266 PermissionIDSetInitializer(IDs... ids) { | |
| 267 // This effectively calls insert() with each of the ids. | |
| 268 ExpandHelper(insert(ids)...); | |
| 269 } | |
| 270 | |
| 271 virtual ~PermissionIDSetInitializer() {} | |
| 272 | |
| 273 private: | |
| 274 template <typename... Args> | |
| 275 void ExpandHelper(Args&&...) {} | |
| 276 }; | |
| 277 | |
| 278 ChromePermissionMessageRule::ChromePermissionMessageRule( | 258 ChromePermissionMessageRule::ChromePermissionMessageRule( |
| 279 int message_id, | 259 int message_id, |
| 280 const PermissionIDSetInitializer& required, | 260 const std::initializer_list<APIPermission::ID>& required, |
| 281 const PermissionIDSetInitializer& optional) | 261 const std::initializer_list<APIPermission::ID>& optional) |
| 282 : ChromePermissionMessageRule( | 262 : ChromePermissionMessageRule( |
| 283 new DefaultPermissionMessageFormatter(message_id), | 263 new DefaultPermissionMessageFormatter(message_id), |
| 284 required, | 264 required, |
| 285 optional) {} | 265 optional) {} |
| 286 | 266 |
| 287 ChromePermissionMessageRule::ChromePermissionMessageRule( | 267 ChromePermissionMessageRule::ChromePermissionMessageRule( |
| 288 ChromePermissionMessageFormatter* formatter, | 268 ChromePermissionMessageFormatter* formatter, |
| 289 const PermissionIDSetInitializer& required, | 269 const std::initializer_list<APIPermission::ID>& required, |
| 290 const PermissionIDSetInitializer& optional) | 270 const std::initializer_list<APIPermission::ID>& optional) |
| 291 : required_permissions_(required), | 271 : required_permissions_(required), |
| 292 optional_permissions_(optional), | 272 optional_permissions_(optional), |
| 293 formatter_(formatter) { | 273 formatter_(formatter) { |
| 294 DCHECK(!required_permissions_.empty()); | 274 DCHECK(!required_permissions_.empty()); |
| 295 } | 275 } |
| 296 | 276 |
| 297 ChromePermissionMessageRule::ChromePermissionMessageRule( | 277 ChromePermissionMessageRule::ChromePermissionMessageRule( |
| 298 const ChromePermissionMessageRule& other) = default; | 278 const ChromePermissionMessageRule& other) = default; |
| 299 | 279 |
| 300 ChromePermissionMessageRule::~ChromePermissionMessageRule() { | 280 ChromePermissionMessageRule::~ChromePermissionMessageRule() { |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 {IDS_EXTENSION_PROMPT_WARNING_DISPLAY_SOURCE, | 624 {IDS_EXTENSION_PROMPT_WARNING_DISPLAY_SOURCE, |
| 645 {APIPermission::kDisplaySource}, | 625 {APIPermission::kDisplaySource}, |
| 646 {}}, | 626 {}}, |
| 647 }; | 627 }; |
| 648 | 628 |
| 649 return std::vector<ChromePermissionMessageRule>( | 629 return std::vector<ChromePermissionMessageRule>( |
| 650 rules_arr, rules_arr + arraysize(rules_arr)); | 630 rules_arr, rules_arr + arraysize(rules_arr)); |
| 651 } | 631 } |
| 652 | 632 |
| 653 } // namespace extensions | 633 } // namespace extensions |
| OLD | NEW |