Chromium Code Reviews| OLD | NEW |
|---|---|
| 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::size_t PermissionTypeHash::operator()( |
| 19 const content::PermissionType& type) const { | 19 const content::PermissionType& type) const { |
| 20 return static_cast<size_t>(type); | 20 return static_cast<size_t>(type); |
| 21 } | 21 } |
| 22 | 22 |
| 23 // The returned strings must match the RAPPOR metrics in rappor.xml, | 23 // The returned strings must match the RAPPOR metrics in rappor.xml, |
| 24 // and any Field Trial configs for the Permissions kill switch e.g. | 24 // and any Field Trial configs for the Permissions kill switch e.g. |
| 25 // Permissions.Action.Geolocation etc.. | 25 // Permissions.Action.Geolocation etc.. |
| 26 std::string PermissionUtil::GetPermissionString( | 26 std::string PermissionUtil::GetPermissionString( |
| 27 content::PermissionType permission) { | 27 content::PermissionType permission) { |
| 28 switch (permission) { | 28 switch (permission) { |
| 29 case content::PermissionType::GEOLOCATION: | 29 case content::PermissionType::GEOLOCATION: |
| 30 return "Geolocation"; | 30 return kGeolocationPermissionName; |
| 31 case content::PermissionType::NOTIFICATIONS: | 31 case content::PermissionType::NOTIFICATIONS: |
| 32 return "Notifications"; | 32 return kNotificationPermissionName; |
| 33 case content::PermissionType::MIDI_SYSEX: | 33 case content::PermissionType::MIDI_SYSEX: |
| 34 return "MidiSysEx"; | 34 return kMidiSysExnPermissionName; |
| 35 case content::PermissionType::PUSH_MESSAGING: | 35 case content::PermissionType::PUSH_MESSAGING: |
| 36 return "PushMessaging"; | 36 return kPushMessagingPermissionName; |
| 37 case content::PermissionType::DURABLE_STORAGE: | 37 case content::PermissionType::DURABLE_STORAGE: |
| 38 return "DurableStorage"; | 38 return kDurableStoragePermissionName; |
| 39 case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER: | 39 case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER: |
| 40 return "ProtectedMediaIdentifier"; | 40 return kProtectedMediaPermissionName; |
| 41 case content::PermissionType::AUDIO_CAPTURE: | 41 case content::PermissionType::AUDIO_CAPTURE: |
| 42 return "AudioCapture"; | 42 return kAudioCapturePermissionName; |
| 43 case content::PermissionType::VIDEO_CAPTURE: | 43 case content::PermissionType::VIDEO_CAPTURE: |
| 44 return "VideoCapture"; | 44 return kVideoCapturePermissionName; |
| 45 case content::PermissionType::MIDI: | 45 case content::PermissionType::MIDI: |
| 46 return "Midi"; | 46 return kMidiPermissionName; |
| 47 case content::PermissionType::BACKGROUND_SYNC: | 47 case content::PermissionType::BACKGROUND_SYNC: |
| 48 return "BackgroundSync"; | 48 return kBackgroundSyncPermissionName; |
| 49 case content::PermissionType::FLASH: | 49 case content::PermissionType::FLASH: |
| 50 return "Flash"; | 50 return kFlashPermissionName; |
| 51 case content::PermissionType::NUM: | 51 case content::PermissionType::NUM: |
| 52 break; | 52 break; |
| 53 } | 53 } |
| 54 NOTREACHED(); | 54 NOTREACHED(); |
| 55 return std::string(); | 55 return std::string(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 content::PermissionType PermissionUtil::ConvertSafeBrowsingNameToPermissionType( | |
| 59 const std::string& sb_name) { | |
| 60 if (sb_name == "GEOLOCATION") | |
|
raymes
2017/01/24 05:15:17
nit: please make a note that the name is a stringi
meredithl
2017/01/24 23:20:21
I've now changed this method around so there is no
| |
| 61 return content::PermissionType::GEOLOCATION; | |
| 62 if (sb_name == "NOTIFICATIONS") | |
| 63 return content::PermissionType::NOTIFICATIONS; | |
| 64 if (sb_name == "MIDI_SYSEX") | |
| 65 return content::PermissionType::MIDI_SYSEX; | |
| 66 if (sb_name == "PUSH_MESSAGING") | |
| 67 return content::PermissionType::PUSH_MESSAGING; | |
| 68 if (sb_name == "DURABLE_STORAGE") | |
| 69 return content::PermissionType::DURABLE_STORAGE; | |
| 70 if (sb_name == "PROTECTED_MEDIA_IDENTIFIER") | |
| 71 return content::PermissionType::PROTECTED_MEDIA_IDENTIFIER; | |
| 72 if (sb_name == "AUDIO_CAPTURE") | |
| 73 return content::PermissionType::AUDIO_CAPTURE; | |
| 74 if (sb_name == "VIDEO_CAPTURE") | |
| 75 return content::PermissionType::MIDI; | |
| 76 if (sb_name == "MIDI") | |
| 77 return content::PermissionType::MIDI; | |
| 78 if (sb_name == "BACKGROUND_SYNC") | |
| 79 return content::PermissionType::BACKGROUND_SYNC; | |
| 80 if (sb_name == "FLASH") | |
| 81 return content::PermissionType::FLASH; | |
| 82 NOTREACHED(); | |
| 83 return content::PermissionType::NUM; | |
| 84 } | |
| 85 | |
| 58 PermissionRequestType PermissionUtil::GetRequestType( | 86 PermissionRequestType PermissionUtil::GetRequestType( |
| 59 content::PermissionType type) { | 87 content::PermissionType type) { |
| 60 switch (type) { | 88 switch (type) { |
| 61 case content::PermissionType::GEOLOCATION: | 89 case content::PermissionType::GEOLOCATION: |
| 62 return PermissionRequestType::PERMISSION_GEOLOCATION; | 90 return PermissionRequestType::PERMISSION_GEOLOCATION; |
| 63 case content::PermissionType::NOTIFICATIONS: | 91 case content::PermissionType::NOTIFICATIONS: |
| 64 return PermissionRequestType::PERMISSION_NOTIFICATIONS; | 92 return PermissionRequestType::PERMISSION_NOTIFICATIONS; |
| 65 case content::PermissionType::MIDI_SYSEX: | 93 case content::PermissionType::MIDI_SYSEX: |
| 66 return PermissionRequestType::PERMISSION_MIDI_SYSEX; | 94 return PermissionRequestType::PERMISSION_MIDI_SYSEX; |
| 67 case content::PermissionType::PUSH_MESSAGING: | 95 case content::PermissionType::PUSH_MESSAGING: |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 ContentSetting final_content_setting = settings_map->GetContentSetting( | 186 ContentSetting final_content_setting = settings_map->GetContentSetting( |
| 159 primary_url_, secondary_url_, content_type_, std::string()); | 187 primary_url_, secondary_url_, content_type_, std::string()); |
| 160 if (final_content_setting != CONTENT_SETTING_ALLOW) { | 188 if (final_content_setting != CONTENT_SETTING_ALLOW) { |
| 161 PermissionType permission_type; | 189 PermissionType permission_type; |
| 162 if (PermissionUtil::GetPermissionType(content_type_, &permission_type)) { | 190 if (PermissionUtil::GetPermissionType(content_type_, &permission_type)) { |
| 163 PermissionUmaUtil::PermissionRevoked(permission_type, source_ui_, | 191 PermissionUmaUtil::PermissionRevoked(permission_type, source_ui_, |
| 164 primary_url_, profile_); | 192 primary_url_, profile_); |
| 165 } | 193 } |
| 166 } | 194 } |
| 167 } | 195 } |
| OLD | NEW |