| 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_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_uma_util.h" | 8 #include "chrome/browser/permissions/permission_uma_util.h" |
| 9 #include "chrome/browser/permissions/permission_util.h" | 9 #include "chrome/browser/permissions/permission_util.h" |
| 10 #include "chrome/grit/generated_resources.h" | 10 #include "chrome/grit/generated_resources.h" |
| 11 #include "chrome/grit/theme_resources.h" | 11 #include "chrome/grit/theme_resources.h" |
| 12 #include "components/url_formatter/elide_url.h" | 12 #include "components/url_formatter/elide_url.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 #if defined(OS_ANDROID) |
| 18 #include "chrome/browser/android/android_theme_resources.h" |
| 19 #endif |
| 20 |
| 17 PermissionRequestImpl::PermissionRequestImpl( | 21 PermissionRequestImpl::PermissionRequestImpl( |
| 18 const GURL& request_origin, | 22 const GURL& request_origin, |
| 19 content::PermissionType permission_type, | 23 content::PermissionType permission_type, |
| 20 Profile* profile, | 24 Profile* profile, |
| 21 bool has_gesture, | 25 bool has_gesture, |
| 22 const PermissionDecidedCallback& permission_decided_callback, | 26 const PermissionDecidedCallback& permission_decided_callback, |
| 23 const base::Closure delete_callback) | 27 const base::Closure delete_callback) |
| 24 : request_origin_(request_origin), | 28 : request_origin_(request_origin), |
| 25 permission_type_(permission_type), | 29 permission_type_(permission_type), |
| 26 profile_(profile), | 30 profile_(profile), |
| 27 has_gesture_(has_gesture), | 31 has_gesture_(has_gesture), |
| 28 permission_decided_callback_(permission_decided_callback), | 32 permission_decided_callback_(permission_decided_callback), |
| 29 delete_callback_(delete_callback), | 33 delete_callback_(delete_callback), |
| 30 is_finished_(false), | 34 is_finished_(false), |
| 31 action_taken_(false) {} | 35 action_taken_(false) {} |
| 32 | 36 |
| 33 PermissionRequestImpl::~PermissionRequestImpl() { | 37 PermissionRequestImpl::~PermissionRequestImpl() { |
| 34 DCHECK(is_finished_); | 38 DCHECK(is_finished_); |
| 35 if (!action_taken_) { | 39 if (!action_taken_) { |
| 36 PermissionUmaUtil::PermissionIgnored(permission_type_, GetGestureType(), | 40 PermissionUmaUtil::PermissionIgnored(permission_type_, GetGestureType(), |
| 37 request_origin_, profile_); | 41 request_origin_, profile_); |
| 38 } | 42 } |
| 39 } | 43 } |
| 40 | 44 |
| 41 gfx::VectorIconId PermissionRequestImpl::GetVectorIconId() const { | 45 gfx::VectorIconId PermissionRequestImpl::GetVectorIconId() const { |
| 42 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) | 46 #if defined(OS_ANDROID) |
| 47 return gfx::VectorIconId::VECTOR_ICON_NONE; |
| 48 #else |
| 43 switch (permission_type_) { | 49 switch (permission_type_) { |
| 44 case content::PermissionType::GEOLOCATION: | 50 case content::PermissionType::GEOLOCATION: |
| 45 return gfx::VectorIconId::LOCATION_ON; | 51 return gfx::VectorIconId::LOCATION_ON; |
| 46 #if defined(ENABLE_NOTIFICATIONS) | 52 #if defined(ENABLE_NOTIFICATIONS) |
| 47 case content::PermissionType::NOTIFICATIONS: | 53 case content::PermissionType::NOTIFICATIONS: |
| 48 case content::PermissionType::PUSH_MESSAGING: | 54 case content::PermissionType::PUSH_MESSAGING: |
| 49 return gfx::VectorIconId::NOTIFICATIONS; | 55 return gfx::VectorIconId::NOTIFICATIONS; |
| 50 #endif | 56 #endif |
| 51 #if defined(OS_CHROMEOS) | 57 #if defined(OS_CHROMEOS) |
| 52 // TODO(xhwang): fix this icon, see crrev.com/863263007 | 58 // TODO(xhwang): fix this icon, see crrev.com/863263007 |
| 53 case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER: | 59 case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER: |
| 54 return gfx::VectorIconId::CHROME_PRODUCT; | 60 return gfx::VectorIconId::CHROME_PRODUCT; |
| 55 #endif | 61 #endif |
| 56 case content::PermissionType::MIDI_SYSEX: | 62 case content::PermissionType::MIDI_SYSEX: |
| 57 return gfx::VectorIconId::MIDI; | 63 return gfx::VectorIconId::MIDI; |
| 58 case content::PermissionType::FLASH: | 64 case content::PermissionType::FLASH: |
| 59 return gfx::VectorIconId::EXTENSION; | 65 return gfx::VectorIconId::EXTENSION; |
| 60 default: | 66 default: |
| 61 NOTREACHED(); | 67 NOTREACHED(); |
| 62 return gfx::VectorIconId::VECTOR_ICON_NONE; | 68 return gfx::VectorIconId::VECTOR_ICON_NONE; |
| 63 } | 69 } |
| 64 #else // !defined(OS_MACOSX) && !defined(OS_ANDROID) | |
| 65 return gfx::VectorIconId::VECTOR_ICON_NONE; | |
| 66 #endif | 70 #endif |
| 67 } | 71 } |
| 68 | 72 |
| 73 #if defined(OS_ANDROID) |
| 69 int PermissionRequestImpl::GetIconId() const { | 74 int PermissionRequestImpl::GetIconId() const { |
| 70 int icon_id = IDR_INFOBAR_WARNING; | |
| 71 #if defined(OS_MACOSX) || defined(OS_ANDROID) | |
| 72 switch (permission_type_) { | 75 switch (permission_type_) { |
| 73 case content::PermissionType::GEOLOCATION: | 76 case content::PermissionType::GEOLOCATION: |
| 74 icon_id = IDR_INFOBAR_GEOLOCATION; | 77 return IDR_ANDROID_INFOBAR_GEOLOCATION; |
| 75 break; | |
| 76 #if defined(ENABLE_NOTIFICATIONS) | |
| 77 case content::PermissionType::NOTIFICATIONS: | |
| 78 case content::PermissionType::PUSH_MESSAGING: | |
| 79 icon_id = IDR_INFOBAR_DESKTOP_NOTIFICATIONS; | |
| 80 break; | |
| 81 #endif | |
| 82 case content::PermissionType::MIDI_SYSEX: | 78 case content::PermissionType::MIDI_SYSEX: |
| 83 icon_id = IDR_ALLOWED_MIDI_SYSEX; | 79 return IDR_ALLOWED_MIDI_SYSEX; |
| 84 break; | |
| 85 case content::PermissionType::FLASH: | 80 case content::PermissionType::FLASH: |
| 86 icon_id = IDR_ALLOWED_PLUGINS; | 81 return IDR_ALLOWED_PLUGINS; |
| 87 break; | |
| 88 default: | 82 default: |
| 89 NOTREACHED(); | 83 NOTREACHED(); |
| 84 return 0; |
| 90 } | 85 } |
| 86 } |
| 91 #endif | 87 #endif |
| 92 return icon_id; | |
| 93 } | |
| 94 | 88 |
| 95 base::string16 PermissionRequestImpl::GetMessageTextFragment() const { | 89 base::string16 PermissionRequestImpl::GetMessageTextFragment() const { |
| 96 int message_id; | 90 int message_id; |
| 97 switch (permission_type_) { | 91 switch (permission_type_) { |
| 98 case content::PermissionType::GEOLOCATION: | 92 case content::PermissionType::GEOLOCATION: |
| 99 message_id = IDS_GEOLOCATION_INFOBAR_PERMISSION_FRAGMENT; | 93 message_id = IDS_GEOLOCATION_INFOBAR_PERMISSION_FRAGMENT; |
| 100 break; | 94 break; |
| 101 #if defined(ENABLE_NOTIFICATIONS) | 95 #if defined(ENABLE_NOTIFICATIONS) |
| 102 case content::PermissionType::NOTIFICATIONS: | 96 case content::PermissionType::NOTIFICATIONS: |
| 103 case content::PermissionType::PUSH_MESSAGING: | 97 case content::PermissionType::PUSH_MESSAGING: |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 NOTREACHED(); | 168 NOTREACHED(); |
| 175 return PermissionRequestType::UNKNOWN; | 169 return PermissionRequestType::UNKNOWN; |
| 176 } | 170 } |
| 177 } | 171 } |
| 178 | 172 |
| 179 PermissionRequestGestureType PermissionRequestImpl::GetGestureType() | 173 PermissionRequestGestureType PermissionRequestImpl::GetGestureType() |
| 180 const { | 174 const { |
| 181 return has_gesture_ ? PermissionRequestGestureType::GESTURE | 175 return has_gesture_ ? PermissionRequestGestureType::GESTURE |
| 182 : PermissionRequestGestureType::NO_GESTURE; | 176 : PermissionRequestGestureType::NO_GESTURE; |
| 183 } | 177 } |
| OLD | NEW |