| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/permissions/permission_bubble_request_impl.h" | |
| 6 | |
| 7 #include "build/build_config.h" | |
| 8 #include "chrome/browser/permissions/permission_context_base.h" | |
| 9 #include "chrome/browser/permissions/permission_uma_util.h" | |
| 10 #include "chrome/grit/generated_resources.h" | |
| 11 #include "components/url_formatter/elide_url.h" | |
| 12 #include "grit/theme_resources.h" | |
| 13 #include "net/base/escape.h" | |
| 14 #include "ui/base/l10n/l10n_util.h" | |
| 15 #include "ui/gfx/vector_icons_public.h" | |
| 16 | |
| 17 PermissionBubbleRequestImpl::PermissionBubbleRequestImpl( | |
| 18 const GURL& request_origin, | |
| 19 content::PermissionType permission_type, | |
| 20 const PermissionDecidedCallback& permission_decided_callback, | |
| 21 const base::Closure delete_callback) | |
| 22 : request_origin_(request_origin), | |
| 23 permission_type_(permission_type), | |
| 24 permission_decided_callback_(permission_decided_callback), | |
| 25 delete_callback_(delete_callback), | |
| 26 is_finished_(false), | |
| 27 action_taken_(false) {} | |
| 28 | |
| 29 PermissionBubbleRequestImpl::~PermissionBubbleRequestImpl() { | |
| 30 DCHECK(is_finished_); | |
| 31 if (!action_taken_) | |
| 32 PermissionUmaUtil::PermissionIgnored(permission_type_, request_origin_); | |
| 33 } | |
| 34 | |
| 35 gfx::VectorIconId PermissionBubbleRequestImpl::GetVectorIconId() const { | |
| 36 #if !defined(OS_MACOSX) | |
| 37 switch (permission_type_) { | |
| 38 case content::PermissionType::GEOLOCATION: | |
| 39 return gfx::VectorIconId::LOCATION_ON; | |
| 40 #if defined(ENABLE_NOTIFICATIONS) | |
| 41 case content::PermissionType::NOTIFICATIONS: | |
| 42 return gfx::VectorIconId::NOTIFICATIONS; | |
| 43 #endif | |
| 44 #if defined(OS_CHROMEOS) | |
| 45 // TODO(xhwang): fix this icon, see crrev.com/863263007 | |
| 46 case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER: | |
| 47 return gfx::VectorIconId::CHROME_PRODUCT; | |
| 48 #endif | |
| 49 case content::PermissionType::MIDI_SYSEX: | |
| 50 return gfx::VectorIconId::MIDI; | |
| 51 default: | |
| 52 NOTREACHED(); | |
| 53 return gfx::VectorIconId::VECTOR_ICON_NONE; | |
| 54 } | |
| 55 #else // !defined(OS_MACOSX) | |
| 56 return gfx::VectorIconId::VECTOR_ICON_NONE; | |
| 57 #endif | |
| 58 } | |
| 59 | |
| 60 int PermissionBubbleRequestImpl::GetIconId() const { | |
| 61 int icon_id = IDR_INFOBAR_WARNING; | |
| 62 #if defined(OS_MACOSX) | |
| 63 switch (permission_type_) { | |
| 64 case content::PermissionType::GEOLOCATION: | |
| 65 icon_id = IDR_INFOBAR_GEOLOCATION; | |
| 66 break; | |
| 67 #if defined(ENABLE_NOTIFICATIONS) | |
| 68 case content::PermissionType::NOTIFICATIONS: | |
| 69 icon_id = IDR_INFOBAR_DESKTOP_NOTIFICATIONS; | |
| 70 break; | |
| 71 #endif | |
| 72 case content::PermissionType::MIDI_SYSEX: | |
| 73 icon_id = IDR_ALLOWED_MIDI_SYSEX; | |
| 74 break; | |
| 75 default: | |
| 76 NOTREACHED(); | |
| 77 } | |
| 78 #endif | |
| 79 return icon_id; | |
| 80 } | |
| 81 | |
| 82 base::string16 PermissionBubbleRequestImpl::GetMessageText() const { | |
| 83 int message_id; | |
| 84 switch (permission_type_) { | |
| 85 case content::PermissionType::GEOLOCATION: | |
| 86 message_id = IDS_GEOLOCATION_INFOBAR_QUESTION; | |
| 87 break; | |
| 88 #if defined(ENABLE_NOTIFICATIONS) | |
| 89 case content::PermissionType::NOTIFICATIONS: | |
| 90 message_id = IDS_NOTIFICATION_PERMISSIONS; | |
| 91 break; | |
| 92 #endif | |
| 93 case content::PermissionType::MIDI_SYSEX: | |
| 94 message_id = IDS_MIDI_SYSEX_INFOBAR_QUESTION; | |
| 95 break; | |
| 96 case content::PermissionType::PUSH_MESSAGING: | |
| 97 message_id = IDS_PUSH_MESSAGES_PERMISSION_QUESTION; | |
| 98 break; | |
| 99 #if defined(OS_CHROMEOS) | |
| 100 case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER: | |
| 101 message_id = IDS_PROTECTED_MEDIA_IDENTIFIER_INFOBAR_QUESTION; | |
| 102 break; | |
| 103 #endif | |
| 104 default: | |
| 105 NOTREACHED(); | |
| 106 return base::string16(); | |
| 107 } | |
| 108 return l10n_util::GetStringFUTF16( | |
| 109 message_id, | |
| 110 url_formatter::FormatUrlForSecurityDisplay( | |
| 111 request_origin_, url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC)); | |
| 112 } | |
| 113 | |
| 114 base::string16 PermissionBubbleRequestImpl::GetMessageTextFragment() const { | |
| 115 int message_id; | |
| 116 switch (permission_type_) { | |
| 117 case content::PermissionType::GEOLOCATION: | |
| 118 message_id = IDS_GEOLOCATION_INFOBAR_PERMISSION_FRAGMENT; | |
| 119 break; | |
| 120 #if defined(ENABLE_NOTIFICATIONS) | |
| 121 case content::PermissionType::NOTIFICATIONS: | |
| 122 message_id = IDS_NOTIFICATION_PERMISSIONS_FRAGMENT; | |
| 123 break; | |
| 124 #endif | |
| 125 case content::PermissionType::MIDI_SYSEX: | |
| 126 message_id = IDS_MIDI_SYSEX_PERMISSION_FRAGMENT; | |
| 127 break; | |
| 128 case content::PermissionType::PUSH_MESSAGING: | |
| 129 message_id = IDS_PUSH_MESSAGES_BUBBLE_FRAGMENT; | |
| 130 break; | |
| 131 #if defined(OS_CHROMEOS) | |
| 132 case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER: | |
| 133 message_id = IDS_PROTECTED_MEDIA_IDENTIFIER_PERMISSION_FRAGMENT; | |
| 134 break; | |
| 135 #endif | |
| 136 default: | |
| 137 NOTREACHED(); | |
| 138 return base::string16(); | |
| 139 } | |
| 140 return l10n_util::GetStringUTF16(message_id); | |
| 141 } | |
| 142 | |
| 143 GURL PermissionBubbleRequestImpl::GetOrigin() const { | |
| 144 return request_origin_; | |
| 145 } | |
| 146 | |
| 147 void PermissionBubbleRequestImpl::PermissionGranted() { | |
| 148 RegisterActionTaken(); | |
| 149 permission_decided_callback_.Run(true, CONTENT_SETTING_ALLOW); | |
| 150 } | |
| 151 | |
| 152 void PermissionBubbleRequestImpl::PermissionDenied() { | |
| 153 RegisterActionTaken(); | |
| 154 permission_decided_callback_.Run(true, CONTENT_SETTING_BLOCK); | |
| 155 } | |
| 156 | |
| 157 void PermissionBubbleRequestImpl::Cancelled() { | |
| 158 RegisterActionTaken(); | |
| 159 permission_decided_callback_.Run(false, CONTENT_SETTING_DEFAULT); | |
| 160 } | |
| 161 | |
| 162 void PermissionBubbleRequestImpl::RequestFinished() { | |
| 163 is_finished_ = true; | |
| 164 delete_callback_.Run(); | |
| 165 } | |
| 166 | |
| 167 PermissionBubbleType PermissionBubbleRequestImpl::GetPermissionBubbleType() | |
| 168 const { | |
| 169 return PermissionBubbleType::PERMISSION; | |
| 170 } | |
| OLD | NEW |