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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_COMMON_EXTENSIONS_PERMISSIONS_PERMISSION_MESSAGE_H_ 6 #define CHROME_COMMON_EXTENSIONS_PERMISSIONS_PERMISSION_MESSAGE_H_ 7 8 #include <set> 9 #include <string> 10 #include <vector> 11 12 #include "base/strings/string16.h" 13 14 namespace extensions { 15 16 // When prompting the user to install or approve permissions, we display 17 // messages describing the effects of the permissions rather than listing the 18 // permissions themselves. Each PermissionMessage represents one of the 19 // messages shown to the user. 20 class PermissionMessage { 21 public: 22 // Do not reorder this enumeration. If you need to add a new enum, add it just 23 // prior to kEnumBoundary. 24 enum ID { 25 kUnknown, 26 kNone, 27 kBookmarks, 28 kGeolocation, 29 kBrowsingHistory, 30 kTabs, 31 kManagement, 32 kDebugger, 33 kHosts1, 34 kHosts2, 35 kHosts3, 36 kHosts4OrMore, 37 kHostsAll, 38 kFullAccess, 39 kClipboard, 40 kTtsEngine, 41 kContentSettings, 42 kPrivacy, 43 kManagedMode, 44 kInput, 45 kAudioCapture, 46 kVideoCapture, 47 kDownloads, 48 kFileSystemWrite, 49 kMediaGalleriesAllGalleriesRead, 50 kSerial, 51 kSocketAnyHost, 52 kSocketDomainHosts, 53 kSocketSpecificHosts, 54 kBluetooth, 55 kUsb, 56 kSystemIndicator, 57 kUsbDevice, 58 kMediaGalleriesAllGalleriesCopyTo, 59 kSystemInfoDisplay, 60 kNativeMessaging, 61 kSyncFileSystem, 62 kAudio, 63 kFavicon, 64 kMusicManagerPrivate, 65 kWebConnectable, 66 kActivityLogPrivate, 67 kBluetoothDevices, 68 kDownloadsOpen, 69 kNetworkingPrivate, 70 kEnumBoundary, 71 }; 72 73 // Creates the corresponding permission message for a list of hosts. This is 74 // simply a convenience method around the constructor, since the messages 75 // change depending on what hosts are present. 76 static PermissionMessage CreateFromHostList( 77 const std::set<std::string>& hosts); 78 79 // Creates the corresponding permission message. 80 PermissionMessage(ID id, const string16& message); 81 PermissionMessage(ID id, const string16& message, const string16& details); 82 ~PermissionMessage(); 83 84 // Gets the id of the permission message, which can be used in UMA 85 // histograms. 86 ID id() const { return id_; } 87 88 // Gets a localized message describing this permission. Please note that 89 // the message will be empty for message types TYPE_NONE and TYPE_UNKNOWN. 90 const string16& message() const { return message_; } 91 92 // Gets a localized message describing the details for this permission. Please 93 // note that the message will be empty for message types TYPE_NONE and 94 // TYPE_UNKNOWN. 95 const string16& details() const { return details_; } 96 97 // Comparator to work with std::set. 98 bool operator<(const PermissionMessage& that) const { 99 return id_ < that.id_; 100 } 101 // Comparator to work with base::STLSetDifference. 102 bool operator>(const PermissionMessage& that) const { 103 return id_ > that.id_; 104 } 105 106 private: 107 ID id_; 108 string16 message_; 109 string16 details_; 110 }; 111 112 typedef std::vector<PermissionMessage> PermissionMessages; 113 114 } // namespace extensions 115 116 #endif // CHROME_COMMON_EXTENSIONS_PERMISSIONS_PERMISSION_MESSAGE_H_ 117