Chromium Code Reviews| 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/gfx/vector_icons_public.h" | 15 #include "ui/gfx/vector_icons_public.h" |
| 16 | 16 |
| 17 PermissionBubbleRequestImpl::PermissionBubbleRequestImpl( | 17 PermissionRequestImpl::PermissionRequestImpl( |
| 18 const GURL& request_origin, | 18 const GURL& request_origin, |
| 19 content::PermissionType permission_type, | 19 content::PermissionType permission_type, |
| 20 const PermissionDecidedCallback& permission_decided_callback, | 20 const PermissionDecidedCallback& permission_decided_callback, |
| 21 const base::Closure delete_callback) | 21 const base::Closure delete_callback) |
| 22 : request_origin_(request_origin), | 22 : request_origin_(request_origin), |
| 23 permission_type_(permission_type), | 23 permission_type_(permission_type), |
| 24 permission_decided_callback_(permission_decided_callback), | 24 permission_decided_callback_(permission_decided_callback), |
| 25 delete_callback_(delete_callback), | 25 delete_callback_(delete_callback), |
| 26 is_finished_(false), | 26 is_finished_(false), |
| 27 action_taken_(false) {} | 27 action_taken_(false) {} |
| 28 | 28 |
| 29 PermissionBubbleRequestImpl::~PermissionBubbleRequestImpl() { | 29 PermissionRequestImpl::~PermissionRequestImpl() { |
| 30 DCHECK(is_finished_); | 30 DCHECK(is_finished_); |
| 31 if (!action_taken_) | 31 if (!action_taken_) |
| 32 PermissionUmaUtil::PermissionIgnored(permission_type_, request_origin_); | 32 PermissionUmaUtil::PermissionIgnored(permission_type_, request_origin_); |
| 33 } | 33 } |
| 34 | 34 |
| 35 gfx::VectorIconId PermissionBubbleRequestImpl::GetVectorIconId() const { | 35 gfx::VectorIconId PermissionRequestImpl::GetVectorIconId() const { |
| 36 #if !defined(OS_MACOSX) | 36 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) |
| 37 switch (permission_type_) { | 37 switch (permission_type_) { |
| 38 case content::PermissionType::GEOLOCATION: | 38 case content::PermissionType::GEOLOCATION: |
| 39 return gfx::VectorIconId::LOCATION_ON; | 39 return gfx::VectorIconId::LOCATION_ON; |
| 40 #if defined(ENABLE_NOTIFICATIONS) | 40 #if defined(ENABLE_NOTIFICATIONS) |
| 41 case content::PermissionType::NOTIFICATIONS: | 41 case content::PermissionType::NOTIFICATIONS: |
| 42 return gfx::VectorIconId::NOTIFICATIONS; | 42 return gfx::VectorIconId::NOTIFICATIONS; |
| 43 #endif | 43 #endif |
| 44 #if defined(OS_CHROMEOS) | 44 #if defined(OS_CHROMEOS) |
| 45 // TODO(xhwang): fix this icon, see crrev.com/863263007 | 45 // TODO(xhwang): fix this icon, see crrev.com/863263007 |
| 46 case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER: | 46 case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER: |
| 47 return gfx::VectorIconId::CHROME_PRODUCT; | 47 return gfx::VectorIconId::CHROME_PRODUCT; |
| 48 #endif | 48 #endif |
| 49 case content::PermissionType::MIDI_SYSEX: | 49 case content::PermissionType::MIDI_SYSEX: |
| 50 return gfx::VectorIconId::MIDI; | 50 return gfx::VectorIconId::MIDI; |
| 51 default: | 51 default: |
| 52 NOTREACHED(); | 52 NOTREACHED(); |
| 53 return gfx::VectorIconId::VECTOR_ICON_NONE; | 53 return gfx::VectorIconId::VECTOR_ICON_NONE; |
| 54 } | 54 } |
| 55 #else // !defined(OS_MACOSX) | 55 #else // !defined(OS_MACOSX) && !defined(OS_ANDROID) |
| 56 return gfx::VectorIconId::VECTOR_ICON_NONE; | 56 return gfx::VectorIconId::VECTOR_ICON_NONE; |
| 57 #endif | 57 #endif |
| 58 } | 58 } |
| 59 | 59 |
| 60 int PermissionBubbleRequestImpl::GetIconId() const { | 60 int PermissionRequestImpl::GetIconId() const { |
| 61 int icon_id = IDR_INFOBAR_WARNING; | 61 int icon_id = IDR_INFOBAR_WARNING; |
| 62 #if defined(OS_MACOSX) | 62 #if defined(OS_MACOSX) |
|
felt
2016/07/19 00:21:28
does this one also need the !defined(OS_ANDROID) g
tsergeant
2016/07/19 01:40:37
Done. It's not necessary for the file to compile (
| |
| 63 switch (permission_type_) { | 63 switch (permission_type_) { |
| 64 case content::PermissionType::GEOLOCATION: | 64 case content::PermissionType::GEOLOCATION: |
| 65 icon_id = IDR_INFOBAR_GEOLOCATION; | 65 icon_id = IDR_INFOBAR_GEOLOCATION; |
| 66 break; | 66 break; |
| 67 #if defined(ENABLE_NOTIFICATIONS) | 67 #if defined(ENABLE_NOTIFICATIONS) |
| 68 case content::PermissionType::NOTIFICATIONS: | 68 case content::PermissionType::NOTIFICATIONS: |
| 69 icon_id = IDR_INFOBAR_DESKTOP_NOTIFICATIONS; | 69 icon_id = IDR_INFOBAR_DESKTOP_NOTIFICATIONS; |
| 70 break; | 70 break; |
| 71 #endif | 71 #endif |
| 72 case content::PermissionType::MIDI_SYSEX: | 72 case content::PermissionType::MIDI_SYSEX: |
| 73 icon_id = IDR_ALLOWED_MIDI_SYSEX; | 73 icon_id = IDR_ALLOWED_MIDI_SYSEX; |
| 74 break; | 74 break; |
| 75 default: | 75 default: |
| 76 NOTREACHED(); | 76 NOTREACHED(); |
| 77 } | 77 } |
| 78 #endif | 78 #endif |
| 79 return icon_id; | 79 return icon_id; |
| 80 } | 80 } |
| 81 | 81 |
| 82 base::string16 PermissionBubbleRequestImpl::GetMessageTextFragment() const { | 82 base::string16 PermissionRequestImpl::GetMessageTextFragment() const { |
| 83 int message_id; | 83 int message_id; |
| 84 switch (permission_type_) { | 84 switch (permission_type_) { |
| 85 case content::PermissionType::GEOLOCATION: | 85 case content::PermissionType::GEOLOCATION: |
| 86 message_id = IDS_GEOLOCATION_INFOBAR_PERMISSION_FRAGMENT; | 86 message_id = IDS_GEOLOCATION_INFOBAR_PERMISSION_FRAGMENT; |
| 87 break; | 87 break; |
| 88 #if defined(ENABLE_NOTIFICATIONS) | 88 #if defined(ENABLE_NOTIFICATIONS) |
| 89 case content::PermissionType::NOTIFICATIONS: | 89 case content::PermissionType::NOTIFICATIONS: |
| 90 message_id = IDS_NOTIFICATION_PERMISSIONS_FRAGMENT; | 90 message_id = IDS_NOTIFICATION_PERMISSIONS_FRAGMENT; |
| 91 break; | 91 break; |
| 92 #endif | 92 #endif |
| 93 case content::PermissionType::MIDI_SYSEX: | 93 case content::PermissionType::MIDI_SYSEX: |
| 94 message_id = IDS_MIDI_SYSEX_PERMISSION_FRAGMENT; | 94 message_id = IDS_MIDI_SYSEX_PERMISSION_FRAGMENT; |
| 95 break; | 95 break; |
| 96 case content::PermissionType::PUSH_MESSAGING: | 96 case content::PermissionType::PUSH_MESSAGING: |
| 97 message_id = IDS_PUSH_MESSAGES_BUBBLE_FRAGMENT; | 97 message_id = IDS_PUSH_MESSAGES_BUBBLE_FRAGMENT; |
| 98 break; | 98 break; |
| 99 #if defined(OS_CHROMEOS) | 99 #if defined(OS_CHROMEOS) |
| 100 case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER: | 100 case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER: |
| 101 message_id = IDS_PROTECTED_MEDIA_IDENTIFIER_PERMISSION_FRAGMENT; | 101 message_id = IDS_PROTECTED_MEDIA_IDENTIFIER_PERMISSION_FRAGMENT; |
| 102 break; | 102 break; |
| 103 #endif | 103 #endif |
| 104 default: | 104 default: |
| 105 NOTREACHED(); | 105 NOTREACHED(); |
| 106 return base::string16(); | 106 return base::string16(); |
| 107 } | 107 } |
| 108 return l10n_util::GetStringUTF16(message_id); | 108 return l10n_util::GetStringUTF16(message_id); |
| 109 } | 109 } |
| 110 | 110 |
| 111 GURL PermissionBubbleRequestImpl::GetOrigin() const { | 111 GURL PermissionRequestImpl::GetOrigin() const { |
| 112 return request_origin_; | 112 return request_origin_; |
| 113 } | 113 } |
| 114 | 114 |
| 115 void PermissionBubbleRequestImpl::PermissionGranted() { | 115 void PermissionRequestImpl::PermissionGranted() { |
| 116 RegisterActionTaken(); | 116 RegisterActionTaken(); |
| 117 permission_decided_callback_.Run(true, CONTENT_SETTING_ALLOW); | 117 permission_decided_callback_.Run(true, CONTENT_SETTING_ALLOW); |
| 118 } | 118 } |
| 119 | 119 |
| 120 void PermissionBubbleRequestImpl::PermissionDenied() { | 120 void PermissionRequestImpl::PermissionDenied() { |
| 121 RegisterActionTaken(); | 121 RegisterActionTaken(); |
| 122 permission_decided_callback_.Run(true, CONTENT_SETTING_BLOCK); | 122 permission_decided_callback_.Run(true, CONTENT_SETTING_BLOCK); |
| 123 } | 123 } |
| 124 | 124 |
| 125 void PermissionBubbleRequestImpl::Cancelled() { | 125 void PermissionRequestImpl::Cancelled() { |
| 126 RegisterActionTaken(); | 126 RegisterActionTaken(); |
| 127 permission_decided_callback_.Run(false, CONTENT_SETTING_DEFAULT); | 127 permission_decided_callback_.Run(false, CONTENT_SETTING_DEFAULT); |
| 128 } | 128 } |
| 129 | 129 |
| 130 void PermissionBubbleRequestImpl::RequestFinished() { | 130 void PermissionRequestImpl::RequestFinished() { |
| 131 is_finished_ = true; | 131 is_finished_ = true; |
| 132 delete_callback_.Run(); | 132 delete_callback_.Run(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 PermissionBubbleType PermissionBubbleRequestImpl::GetPermissionBubbleType() | 135 PermissionRequestType PermissionRequestImpl::GetPermissionRequestType() |
| 136 const { | 136 const { |
| 137 switch (permission_type_) { | 137 switch (permission_type_) { |
| 138 case content::PermissionType::GEOLOCATION: | 138 case content::PermissionType::GEOLOCATION: |
| 139 return PermissionBubbleType::PERMISSION_GEOLOCATION; | 139 return PermissionRequestType::PERMISSION_GEOLOCATION; |
| 140 #if defined(ENABLE_NOTIFICATIONS) | 140 #if defined(ENABLE_NOTIFICATIONS) |
| 141 case content::PermissionType::NOTIFICATIONS: | 141 case content::PermissionType::NOTIFICATIONS: |
| 142 return PermissionBubbleType::PERMISSION_NOTIFICATIONS; | 142 return PermissionRequestType::PERMISSION_NOTIFICATIONS; |
| 143 #endif | 143 #endif |
| 144 case content::PermissionType::MIDI_SYSEX: | 144 case content::PermissionType::MIDI_SYSEX: |
| 145 return PermissionBubbleType::PERMISSION_MIDI_SYSEX; | 145 return PermissionRequestType::PERMISSION_MIDI_SYSEX; |
| 146 case content::PermissionType::PUSH_MESSAGING: | 146 case content::PermissionType::PUSH_MESSAGING: |
| 147 return PermissionBubbleType::PERMISSION_PUSH_MESSAGING; | 147 return PermissionRequestType::PERMISSION_PUSH_MESSAGING; |
| 148 #if defined(OS_CHROMEOS) | 148 #if defined(OS_CHROMEOS) |
| 149 case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER: | 149 case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER: |
| 150 return PermissionBubbleType::PERMISSION_PROTECTED_MEDIA_IDENTIFIER; | 150 return PermissionRequestType::PERMISSION_PROTECTED_MEDIA_IDENTIFIER; |
| 151 #endif | 151 #endif |
| 152 default: | 152 default: |
| 153 NOTREACHED(); | 153 NOTREACHED(); |
| 154 return PermissionBubbleType::UNKNOWN; | 154 return PermissionRequestType::UNKNOWN; |
| 155 } | 155 } |
| 156 } | 156 } |
| OLD | NEW |