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

Side by Side Diff: chrome/browser/permissions/permission_util.cc

Issue 2675483002: Replace PermissionType in chrome/ with ContentSettingsType (Closed)
Patch Set: rebase + include content_settings_types.h more Created 3 years, 10 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/browser/permissions/permission_util.h" 5 #include "chrome/browser/permissions/permission_util.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 #include "base/feature_list.h" 8 #include "base/feature_list.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 10 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
11 #include "chrome/browser/permissions/permission_uma_util.h" 11 #include "chrome/browser/permissions/permission_uma_util.h"
12 #include "chrome/common/chrome_features.h" 12 #include "chrome/common/chrome_features.h"
13 #include "components/content_settings/core/browser/host_content_settings_map.h" 13 #include "components/content_settings/core/browser/host_content_settings_map.h"
14 #include "content/public/browser/permission_type.h" 14 #include "content/public/browser/permission_type.h"
15 15
16 using content::PermissionType; 16 using content::PermissionType;
17 17
18 std::size_t PermissionTypeHash::operator()( 18 std::string PermissionUtil::GetPermissionString(
19 const content::PermissionType& type) const { 19 ContentSettingsType content_type) {
20 return static_cast<size_t>(type); 20 PermissionType permission_type;
21 bool success = PermissionUtil::GetPermissionType(
22 content_type, &permission_type);
23 DCHECK(success);
24 return GetPermissionString(permission_type);
21 } 25 }
22 26
23 // The returned strings must match the RAPPOR metrics in rappor.xml, 27 // The returned strings must match the RAPPOR metrics in rappor.xml,
24 // and any Field Trial configs for the Permissions kill switch e.g. 28 // and any Field Trial configs for the Permissions kill switch e.g.
25 // Permissions.Action.Geolocation etc.. 29 // Permissions.Action.Geolocation etc..
26 std::string PermissionUtil::GetPermissionString( 30 std::string PermissionUtil::GetPermissionString(PermissionType permission) {
27 content::PermissionType permission) {
28 switch (permission) { 31 switch (permission) {
29 case content::PermissionType::GEOLOCATION: 32 case PermissionType::GEOLOCATION:
30 return "Geolocation"; 33 return "Geolocation";
31 case content::PermissionType::NOTIFICATIONS: 34 case PermissionType::NOTIFICATIONS:
32 return "Notifications"; 35 return "Notifications";
33 case content::PermissionType::MIDI_SYSEX: 36 case PermissionType::MIDI_SYSEX:
34 return "MidiSysEx"; 37 return "MidiSysEx";
35 case content::PermissionType::PUSH_MESSAGING: 38 case PermissionType::PUSH_MESSAGING:
36 return "PushMessaging"; 39 return "PushMessaging";
37 case content::PermissionType::DURABLE_STORAGE: 40 case PermissionType::DURABLE_STORAGE:
38 return "DurableStorage"; 41 return "DurableStorage";
39 case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER: 42 case PermissionType::PROTECTED_MEDIA_IDENTIFIER:
40 return "ProtectedMediaIdentifier"; 43 return "ProtectedMediaIdentifier";
41 case content::PermissionType::AUDIO_CAPTURE: 44 case PermissionType::AUDIO_CAPTURE:
42 return "AudioCapture"; 45 return "AudioCapture";
43 case content::PermissionType::VIDEO_CAPTURE: 46 case PermissionType::VIDEO_CAPTURE:
44 return "VideoCapture"; 47 return "VideoCapture";
45 case content::PermissionType::MIDI: 48 case PermissionType::MIDI:
46 return "Midi"; 49 return "Midi";
47 case content::PermissionType::BACKGROUND_SYNC: 50 case PermissionType::BACKGROUND_SYNC:
48 return "BackgroundSync"; 51 return "BackgroundSync";
49 case content::PermissionType::FLASH: 52 case PermissionType::FLASH:
50 return "Flash"; 53 return "Flash";
51 case content::PermissionType::NUM: 54 default:
52 break; 55 break;
53 } 56 }
54 NOTREACHED(); 57 NOTREACHED();
55 return std::string(); 58 return std::string();
56 } 59 }
57 60
58 std::string PermissionUtil::ConvertPermissionTypeToSafeBrowsingName( 61 std::string PermissionUtil::ConvertContentSettingsTypeToSafeBrowsingName(
59 const content::PermissionType& permission_type) { 62 ContentSettingsType permission_type) {
60 switch (permission_type) { 63 switch (permission_type) {
61 case content::PermissionType::GEOLOCATION: 64 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
62 return "GEOLOCATION"; 65 return "GEOLOCATION";
63 case content::PermissionType::NOTIFICATIONS: 66 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
64 return "NOTIFICATIONS"; 67 return "NOTIFICATIONS";
65 case content::PermissionType::MIDI_SYSEX: 68 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX:
66 return "MIDI_SYSEX"; 69 return "MIDI_SYSEX";
67 case content::PermissionType::PUSH_MESSAGING: 70 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING:
68 return "PUSH_MESSAGING"; 71 return "PUSH_MESSAGING";
69 case content::PermissionType::DURABLE_STORAGE: 72 case CONTENT_SETTINGS_TYPE_DURABLE_STORAGE:
70 return "DURABLE_STORAGE"; 73 return "DURABLE_STORAGE";
71 case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER: 74 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER:
72 return "PROTECTED_MEDIA_IDENTIFIER"; 75 return "PROTECTED_MEDIA_IDENTIFIER";
73 case content::PermissionType::AUDIO_CAPTURE: 76 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC:
74 return "AUDIO_CAPTURE"; 77 return "AUDIO_CAPTURE";
75 case content::PermissionType::VIDEO_CAPTURE: 78 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA:
76 return "VIDEO_CAPTURE"; 79 return "VIDEO_CAPTURE";
77 case content::PermissionType::MIDI: 80 case CONTENT_SETTINGS_TYPE_BACKGROUND_SYNC:
78 return "MIDI";
79 case content::PermissionType::BACKGROUND_SYNC:
80 return "BACKGROUND_SYNC"; 81 return "BACKGROUND_SYNC";
81 case content::PermissionType::FLASH: 82 case CONTENT_SETTINGS_TYPE_PLUGINS:
82 return "FLASH"; 83 return "FLASH";
83 case content::PermissionType::NUM: 84 default:
84 break; 85 break;
85 } 86 }
86 NOTREACHED(); 87 NOTREACHED();
87 return std::string(); 88 return std::string();
88 } 89 }
89 90
90 PermissionRequestType PermissionUtil::GetRequestType( 91 PermissionRequestType PermissionUtil::GetRequestType(ContentSettingsType type) {
91 content::PermissionType type) {
92 switch (type) { 92 switch (type) {
93 case content::PermissionType::GEOLOCATION: 93 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
94 return PermissionRequestType::PERMISSION_GEOLOCATION; 94 return PermissionRequestType::PERMISSION_GEOLOCATION;
95 case content::PermissionType::NOTIFICATIONS: 95 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
96 return PermissionRequestType::PERMISSION_NOTIFICATIONS; 96 return PermissionRequestType::PERMISSION_NOTIFICATIONS;
97 case content::PermissionType::MIDI_SYSEX: 97 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX:
98 return PermissionRequestType::PERMISSION_MIDI_SYSEX; 98 return PermissionRequestType::PERMISSION_MIDI_SYSEX;
99 case content::PermissionType::PUSH_MESSAGING: 99 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING:
100 return PermissionRequestType::PERMISSION_PUSH_MESSAGING; 100 return PermissionRequestType::PERMISSION_PUSH_MESSAGING;
101 case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER: 101 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER:
102 return PermissionRequestType::PERMISSION_PROTECTED_MEDIA_IDENTIFIER; 102 return PermissionRequestType::PERMISSION_PROTECTED_MEDIA_IDENTIFIER;
103 case content::PermissionType::FLASH: 103 case CONTENT_SETTINGS_TYPE_PLUGINS:
104 return PermissionRequestType::PERMISSION_FLASH; 104 return PermissionRequestType::PERMISSION_FLASH;
105 default: 105 default:
106 NOTREACHED(); 106 NOTREACHED();
107 return PermissionRequestType::UNKNOWN; 107 return PermissionRequestType::UNKNOWN;
108 } 108 }
109 } 109 }
110 110
111 PermissionRequestGestureType PermissionUtil::GetGestureType(bool user_gesture) { 111 PermissionRequestGestureType PermissionUtil::GetGestureType(bool user_gesture) {
112 return user_gesture ? PermissionRequestGestureType::GESTURE 112 return user_gesture ? PermissionRequestGestureType::GESTURE
113 : PermissionRequestGestureType::NO_GESTURE; 113 : PermissionRequestGestureType::NO_GESTURE;
114 } 114 }
115 115
116 bool PermissionUtil::GetPermissionType(ContentSettingsType type, 116 bool PermissionUtil::GetPermissionType(ContentSettingsType type,
117 PermissionType* out) { 117 PermissionType* out) {
118 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { 118 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION) {
119 *out = PermissionType::GEOLOCATION; 119 *out = PermissionType::GEOLOCATION;
120 } else if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { 120 } else if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {
121 *out = PermissionType::NOTIFICATIONS; 121 *out = PermissionType::NOTIFICATIONS;
122 } else if (type == CONTENT_SETTINGS_TYPE_PUSH_MESSAGING) {
123 *out = PermissionType::PUSH_MESSAGING;
122 } else if (type == CONTENT_SETTINGS_TYPE_MIDI_SYSEX) { 124 } else if (type == CONTENT_SETTINGS_TYPE_MIDI_SYSEX) {
123 *out = PermissionType::MIDI_SYSEX; 125 *out = PermissionType::MIDI_SYSEX;
124 } else if (type == CONTENT_SETTINGS_TYPE_DURABLE_STORAGE) { 126 } else if (type == CONTENT_SETTINGS_TYPE_DURABLE_STORAGE) {
125 *out = PermissionType::DURABLE_STORAGE; 127 *out = PermissionType::DURABLE_STORAGE;
126 } else if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { 128 } else if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) {
127 *out = PermissionType::VIDEO_CAPTURE; 129 *out = PermissionType::VIDEO_CAPTURE;
128 } else if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { 130 } else if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) {
129 *out = PermissionType::AUDIO_CAPTURE; 131 *out = PermissionType::AUDIO_CAPTURE;
130 } else if (type == CONTENT_SETTINGS_TYPE_BACKGROUND_SYNC) { 132 } else if (type == CONTENT_SETTINGS_TYPE_BACKGROUND_SYNC) {
131 *out = PermissionType::BACKGROUND_SYNC; 133 *out = PermissionType::BACKGROUND_SYNC;
134 } else if (type == CONTENT_SETTINGS_TYPE_PLUGINS) {
135 *out = PermissionType::FLASH;
132 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) 136 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
133 } else if (type == CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER) { 137 } else if (type == CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER) {
134 *out = PermissionType::PROTECTED_MEDIA_IDENTIFIER; 138 *out = PermissionType::PROTECTED_MEDIA_IDENTIFIER;
135 #endif 139 #endif
136 } else { 140 } else {
137 return false; 141 return false;
138 } 142 }
139 return true; 143 return true;
140 } 144 }
141 145
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 PermissionUtil::ScopedRevocationReporter::~ScopedRevocationReporter() { 189 PermissionUtil::ScopedRevocationReporter::~ScopedRevocationReporter() {
186 if (!is_initially_allowed_) 190 if (!is_initially_allowed_)
187 return; 191 return;
188 HostContentSettingsMap* settings_map = 192 HostContentSettingsMap* settings_map =
189 HostContentSettingsMapFactory::GetForProfile(profile_); 193 HostContentSettingsMapFactory::GetForProfile(profile_);
190 ContentSetting final_content_setting = settings_map->GetContentSetting( 194 ContentSetting final_content_setting = settings_map->GetContentSetting(
191 primary_url_, secondary_url_, content_type_, std::string()); 195 primary_url_, secondary_url_, content_type_, std::string());
192 if (final_content_setting != CONTENT_SETTING_ALLOW) { 196 if (final_content_setting != CONTENT_SETTING_ALLOW) {
193 PermissionType permission_type; 197 PermissionType permission_type;
194 if (PermissionUtil::GetPermissionType(content_type_, &permission_type)) { 198 if (PermissionUtil::GetPermissionType(content_type_, &permission_type)) {
195 PermissionUmaUtil::PermissionRevoked(permission_type, source_ui_, 199 PermissionUmaUtil::PermissionRevoked(content_type_, source_ui_,
196 primary_url_, profile_); 200 primary_url_, profile_);
197 } 201 }
198 } 202 }
199 } 203 }
OLDNEW
« no previous file with comments | « chrome/browser/permissions/permission_util.h ('k') | chrome/browser/plugins/flash_download_interception.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698