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