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

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

Issue 2675483002: Replace PermissionType in chrome/ with ContentSettingsType (Closed)
Patch Set: rebase 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 CHECK(PermissionUtil::GetPermissionType(content_type, &permission_type));
raymes 2017/02/09 00:39:57 nit: here and elsewhere. We tend not to use CHECK
Timothy Loh 2017/02/10 07:25:38 Done here and in permission_uma_util.cc
22 return GetPermissionString(permission_type);
21 } 23 }
22 24
23 // The returned strings must match the RAPPOR metrics in rappor.xml, 25 // The returned strings must match the RAPPOR metrics in rappor.xml,
24 // and any Field Trial configs for the Permissions kill switch e.g. 26 // and any Field Trial configs for the Permissions kill switch e.g.
25 // Permissions.Action.Geolocation etc.. 27 // Permissions.Action.Geolocation etc..
26 std::string PermissionUtil::GetPermissionString( 28 std::string PermissionUtil::GetPermissionString(PermissionType permission) {
27 content::PermissionType permission) {
28 switch (permission) { 29 switch (permission) {
29 case content::PermissionType::GEOLOCATION: 30 case PermissionType::GEOLOCATION:
30 return "Geolocation"; 31 return "Geolocation";
31 case content::PermissionType::NOTIFICATIONS: 32 case PermissionType::NOTIFICATIONS:
32 return "Notifications"; 33 return "Notifications";
33 case content::PermissionType::MIDI_SYSEX: 34 case PermissionType::MIDI_SYSEX:
34 return "MidiSysEx"; 35 return "MidiSysEx";
35 case content::PermissionType::PUSH_MESSAGING: 36 case PermissionType::PUSH_MESSAGING:
36 return "PushMessaging"; 37 return "PushMessaging";
37 case content::PermissionType::DURABLE_STORAGE: 38 case PermissionType::DURABLE_STORAGE:
38 return "DurableStorage"; 39 return "DurableStorage";
39 case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER: 40 case PermissionType::PROTECTED_MEDIA_IDENTIFIER:
40 return "ProtectedMediaIdentifier"; 41 return "ProtectedMediaIdentifier";
41 case content::PermissionType::AUDIO_CAPTURE: 42 case PermissionType::AUDIO_CAPTURE:
42 return "AudioCapture"; 43 return "AudioCapture";
43 case content::PermissionType::VIDEO_CAPTURE: 44 case PermissionType::VIDEO_CAPTURE:
44 return "VideoCapture"; 45 return "VideoCapture";
45 case content::PermissionType::MIDI: 46 case PermissionType::MIDI:
46 return "Midi"; 47 return "Midi";
47 case content::PermissionType::BACKGROUND_SYNC: 48 case PermissionType::BACKGROUND_SYNC:
48 return "BackgroundSync"; 49 return "BackgroundSync";
49 case content::PermissionType::FLASH: 50 case PermissionType::FLASH:
50 return "Flash"; 51 return "Flash";
51 case content::PermissionType::NUM: 52 default:
52 break; 53 break;
53 } 54 }
54 NOTREACHED(); 55 NOTREACHED();
55 return std::string(); 56 return std::string();
56 } 57 }
57 58
58 std::string PermissionUtil::ConvertPermissionTypeToSafeBrowsingName( 59 std::string PermissionUtil::ConvertContentSettingsTypeToSafeBrowsingName(
59 const content::PermissionType& permission_type) { 60 ContentSettingsType permission_type) {
60 switch (permission_type) { 61 switch (permission_type) {
61 case content::PermissionType::GEOLOCATION: 62 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
62 return "GEOLOCATION"; 63 return "GEOLOCATION";
63 case content::PermissionType::NOTIFICATIONS: 64 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
64 return "NOTIFICATIONS"; 65 return "NOTIFICATIONS";
65 case content::PermissionType::MIDI_SYSEX: 66 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX:
66 return "MIDI_SYSEX"; 67 return "MIDI_SYSEX";
67 case content::PermissionType::PUSH_MESSAGING: 68 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING:
68 return "PUSH_MESSAGING"; 69 return "PUSH_MESSAGING";
69 case content::PermissionType::DURABLE_STORAGE: 70 case CONTENT_SETTINGS_TYPE_DURABLE_STORAGE:
70 return "DURABLE_STORAGE"; 71 return "DURABLE_STORAGE";
71 case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER: 72 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER:
72 return "PROTECTED_MEDIA_IDENTIFIER"; 73 return "PROTECTED_MEDIA_IDENTIFIER";
73 case content::PermissionType::AUDIO_CAPTURE: 74 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC:
74 return "AUDIO_CAPTURE"; 75 return "AUDIO_CAPTURE";
75 case content::PermissionType::VIDEO_CAPTURE: 76 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA:
76 return "VIDEO_CAPTURE"; 77 return "VIDEO_CAPTURE";
77 case content::PermissionType::MIDI: 78 case CONTENT_SETTINGS_TYPE_BACKGROUND_SYNC:
78 return "MIDI";
79 case content::PermissionType::BACKGROUND_SYNC:
80 return "BACKGROUND_SYNC"; 79 return "BACKGROUND_SYNC";
81 case content::PermissionType::FLASH: 80 case CONTENT_SETTINGS_TYPE_PLUGINS:
82 return "FLASH"; 81 return "FLASH";
83 case content::PermissionType::NUM: 82 default:
84 break; 83 break;
85 } 84 }
86 NOTREACHED(); 85 NOTREACHED();
87 return std::string(); 86 return std::string();
88 } 87 }
89 88
90 PermissionRequestType PermissionUtil::GetRequestType( 89 PermissionRequestType PermissionUtil::GetRequestType(ContentSettingsType type) {
91 content::PermissionType type) {
92 switch (type) { 90 switch (type) {
93 case content::PermissionType::GEOLOCATION: 91 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
94 return PermissionRequestType::PERMISSION_GEOLOCATION; 92 return PermissionRequestType::PERMISSION_GEOLOCATION;
95 case content::PermissionType::NOTIFICATIONS: 93 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
96 return PermissionRequestType::PERMISSION_NOTIFICATIONS; 94 return PermissionRequestType::PERMISSION_NOTIFICATIONS;
97 case content::PermissionType::MIDI_SYSEX: 95 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX:
98 return PermissionRequestType::PERMISSION_MIDI_SYSEX; 96 return PermissionRequestType::PERMISSION_MIDI_SYSEX;
99 case content::PermissionType::PUSH_MESSAGING: 97 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING:
100 return PermissionRequestType::PERMISSION_PUSH_MESSAGING; 98 return PermissionRequestType::PERMISSION_PUSH_MESSAGING;
101 case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER: 99 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER:
102 return PermissionRequestType::PERMISSION_PROTECTED_MEDIA_IDENTIFIER; 100 return PermissionRequestType::PERMISSION_PROTECTED_MEDIA_IDENTIFIER;
103 case content::PermissionType::FLASH: 101 case CONTENT_SETTINGS_TYPE_PLUGINS:
104 return PermissionRequestType::PERMISSION_FLASH; 102 return PermissionRequestType::PERMISSION_FLASH;
105 default: 103 default:
106 NOTREACHED(); 104 NOTREACHED();
107 return PermissionRequestType::UNKNOWN; 105 return PermissionRequestType::UNKNOWN;
108 } 106 }
109 } 107 }
110 108
111 PermissionRequestGestureType PermissionUtil::GetGestureType(bool user_gesture) { 109 PermissionRequestGestureType PermissionUtil::GetGestureType(bool user_gesture) {
112 return user_gesture ? PermissionRequestGestureType::GESTURE 110 return user_gesture ? PermissionRequestGestureType::GESTURE
113 : PermissionRequestGestureType::NO_GESTURE; 111 : PermissionRequestGestureType::NO_GESTURE;
114 } 112 }
115 113
116 bool PermissionUtil::GetPermissionType(ContentSettingsType type, 114 bool PermissionUtil::GetPermissionType(ContentSettingsType type,
117 PermissionType* out) { 115 PermissionType* out) {
118 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { 116 if (type == CONTENT_SETTINGS_TYPE_GEOLOCATION) {
119 *out = PermissionType::GEOLOCATION; 117 *out = PermissionType::GEOLOCATION;
120 } else if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { 118 } else if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {
121 *out = PermissionType::NOTIFICATIONS; 119 *out = PermissionType::NOTIFICATIONS;
120 } else if (type == CONTENT_SETTINGS_TYPE_PUSH_MESSAGING) {
121 *out = PermissionType::PUSH_MESSAGING;
122 } else if (type == CONTENT_SETTINGS_TYPE_MIDI_SYSEX) { 122 } else if (type == CONTENT_SETTINGS_TYPE_MIDI_SYSEX) {
123 *out = PermissionType::MIDI_SYSEX; 123 *out = PermissionType::MIDI_SYSEX;
124 } else if (type == CONTENT_SETTINGS_TYPE_DURABLE_STORAGE) { 124 } else if (type == CONTENT_SETTINGS_TYPE_DURABLE_STORAGE) {
125 *out = PermissionType::DURABLE_STORAGE; 125 *out = PermissionType::DURABLE_STORAGE;
126 } else if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { 126 } else if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) {
127 *out = PermissionType::VIDEO_CAPTURE; 127 *out = PermissionType::VIDEO_CAPTURE;
128 } else if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { 128 } else if (type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) {
129 *out = PermissionType::AUDIO_CAPTURE; 129 *out = PermissionType::AUDIO_CAPTURE;
130 } else if (type == CONTENT_SETTINGS_TYPE_BACKGROUND_SYNC) { 130 } else if (type == CONTENT_SETTINGS_TYPE_BACKGROUND_SYNC) {
131 *out = PermissionType::BACKGROUND_SYNC; 131 *out = PermissionType::BACKGROUND_SYNC;
132 } else if (type == CONTENT_SETTINGS_TYPE_PLUGINS) {
133 *out = PermissionType::FLASH;
132 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) 134 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
133 } else if (type == CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER) { 135 } else if (type == CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER) {
134 *out = PermissionType::PROTECTED_MEDIA_IDENTIFIER; 136 *out = PermissionType::PROTECTED_MEDIA_IDENTIFIER;
135 #endif 137 #endif
136 } else { 138 } else {
137 return false; 139 return false;
138 } 140 }
139 return true; 141 return true;
140 } 142 }
141 143
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 PermissionUtil::ScopedRevocationReporter::~ScopedRevocationReporter() { 187 PermissionUtil::ScopedRevocationReporter::~ScopedRevocationReporter() {
186 if (!is_initially_allowed_) 188 if (!is_initially_allowed_)
187 return; 189 return;
188 HostContentSettingsMap* settings_map = 190 HostContentSettingsMap* settings_map =
189 HostContentSettingsMapFactory::GetForProfile(profile_); 191 HostContentSettingsMapFactory::GetForProfile(profile_);
190 ContentSetting final_content_setting = settings_map->GetContentSetting( 192 ContentSetting final_content_setting = settings_map->GetContentSetting(
191 primary_url_, secondary_url_, content_type_, std::string()); 193 primary_url_, secondary_url_, content_type_, std::string());
192 if (final_content_setting != CONTENT_SETTING_ALLOW) { 194 if (final_content_setting != CONTENT_SETTING_ALLOW) {
193 PermissionType permission_type; 195 PermissionType permission_type;
194 if (PermissionUtil::GetPermissionType(content_type_, &permission_type)) { 196 if (PermissionUtil::GetPermissionType(content_type_, &permission_type)) {
195 PermissionUmaUtil::PermissionRevoked(permission_type, source_ui_, 197 PermissionUmaUtil::PermissionRevoked(content_type_, source_ui_,
196 primary_url_, profile_); 198 primary_url_, profile_);
197 } 199 }
198 } 200 }
199 } 201 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698