Rename GetIconID to GetIconId
[chromium-blink-merge.git] / chrome / browser / permissions / permission_bubble_request_impl.cc
blob9a8c34949d6a0cb56b1534b3d7febdf1951e90fa
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.
5 #include "chrome/browser/permissions/permission_bubble_request_impl.h"
7 #include "chrome/browser/permissions/permission_context_base.h"
8 #include "chrome/browser/permissions/permission_context_uma_util.h"
9 #include "chrome/grit/generated_resources.h"
10 #include "components/url_formatter/url_formatter.h"
11 #include "grit/theme_resources.h"
12 #include "net/base/escape.h"
13 #include "ui/base/l10n/l10n_util.h"
14 #include "ui/gfx/vector_icons_public.h"
16 PermissionBubbleRequestImpl::PermissionBubbleRequestImpl(
17 const GURL& request_origin,
18 bool user_gesture,
19 ContentSettingsType type,
20 const std::string& display_languages,
21 const PermissionDecidedCallback& permission_decided_callback,
22 const base::Closure delete_callback)
23 : request_origin_(request_origin),
24 user_gesture_(user_gesture),
25 type_(type),
26 display_languages_(display_languages),
27 permission_decided_callback_(permission_decided_callback),
28 delete_callback_(delete_callback),
29 is_finished_(false),
30 action_taken_(false) {
33 PermissionBubbleRequestImpl::~PermissionBubbleRequestImpl() {
34 DCHECK(is_finished_);
35 if (!action_taken_)
36 PermissionContextUmaUtil::PermissionIgnored(type_, request_origin_);
39 gfx::VectorIconId PermissionBubbleRequestImpl::GetVectorIconId() const {
40 #if defined(TOOLKIT_VIEWS)
41 switch (type_) {
42 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
43 return gfx::VectorIconId::LOCATION_ON;
44 #if defined(ENABLE_NOTIFICATIONS)
45 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
46 return gfx::VectorIconId::NOTIFICATIONS;
47 #endif
48 #if defined(OS_CHROMEOS)
49 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER:
50 #endif
51 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX:
52 case CONTENT_SETTINGS_TYPE_DURABLE_STORAGE:
53 // TODO(estade): add vector icons for these.
54 return gfx::VectorIconId::VECTOR_ICON_NONE;
55 default:
56 NOTREACHED();
57 return gfx::VectorIconId::VECTOR_ICON_NONE;
59 #else // !defined(TOOLKIT_VIEWS)
60 return gfx::VectorIconId::VECTOR_ICON_NONE;
61 #endif
64 int PermissionBubbleRequestImpl::GetIconId() const {
65 int icon_id;
66 switch (type_) {
67 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
68 icon_id = IDR_INFOBAR_GEOLOCATION;
69 break;
70 #if defined(ENABLE_NOTIFICATIONS)
71 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
72 icon_id = IDR_INFOBAR_DESKTOP_NOTIFICATIONS;
73 break;
74 #endif
75 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX:
76 icon_id = IDR_ALLOWED_MIDI_SYSEX;
77 break;
78 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
79 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER:
80 icon_id = IDR_INFOBAR_PROTECTED_MEDIA_IDENTIFIER;
81 break;
82 #endif
83 // TODO(dgrogan): Get a real icon. https://crbug.com/516069
84 case CONTENT_SETTINGS_TYPE_DURABLE_STORAGE:
85 icon_id = IDR_INFOBAR_WARNING;
86 break;
87 default:
88 NOTREACHED();
89 return IDR_INFOBAR_WARNING;
91 return icon_id;
94 base::string16 PermissionBubbleRequestImpl::GetMessageText() const {
95 int message_id;
96 switch (type_) {
97 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
98 message_id = IDS_GEOLOCATION_INFOBAR_QUESTION;
99 break;
100 #if defined(ENABLE_NOTIFICATIONS)
101 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
102 message_id = IDS_NOTIFICATION_PERMISSIONS;
103 break;
104 #endif
105 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX:
106 message_id = IDS_MIDI_SYSEX_INFOBAR_QUESTION;
107 break;
108 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING:
109 message_id = IDS_PUSH_MESSAGES_PERMISSION_QUESTION;
110 break;
111 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
112 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER:
113 message_id = IDS_PROTECTED_MEDIA_IDENTIFIER_INFOBAR_QUESTION;
114 break;
115 #endif
116 default:
117 NOTREACHED();
118 return base::string16();
120 return l10n_util::GetStringFUTF16(
121 message_id,
122 url_formatter::FormatUrl(
123 request_origin_, display_languages_,
124 url_formatter::kFormatUrlOmitUsernamePassword |
125 url_formatter::kFormatUrlOmitTrailingSlashOnBareHostname,
126 net::UnescapeRule::SPACES, nullptr, nullptr, nullptr));
129 base::string16 PermissionBubbleRequestImpl::GetMessageTextFragment() const {
130 int message_id;
131 switch (type_) {
132 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
133 message_id = IDS_GEOLOCATION_INFOBAR_PERMISSION_FRAGMENT;
134 break;
135 #if defined(ENABLE_NOTIFICATIONS)
136 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
137 message_id = IDS_NOTIFICATION_PERMISSIONS_FRAGMENT;
138 break;
139 #endif
140 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX:
141 message_id = IDS_MIDI_SYSEX_PERMISSION_FRAGMENT;
142 break;
143 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING:
144 message_id = IDS_PUSH_MESSAGES_BUBBLE_FRAGMENT;
145 break;
146 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
147 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER:
148 message_id = IDS_PROTECTED_MEDIA_IDENTIFIER_PERMISSION_FRAGMENT;
149 break;
150 #endif
151 case CONTENT_SETTINGS_TYPE_DURABLE_STORAGE:
152 message_id = IDS_DURABLE_STORAGE_BUBBLE_FRAGMENT;
153 break;
154 default:
155 NOTREACHED();
156 return base::string16();
158 return l10n_util::GetStringUTF16(message_id);
161 bool PermissionBubbleRequestImpl::HasUserGesture() const {
162 return user_gesture_;
165 GURL PermissionBubbleRequestImpl::GetRequestingHostname() const {
166 return request_origin_;
169 void PermissionBubbleRequestImpl::PermissionGranted() {
170 RegisterActionTaken();
171 permission_decided_callback_.Run(true, CONTENT_SETTING_ALLOW);
174 void PermissionBubbleRequestImpl::PermissionDenied() {
175 RegisterActionTaken();
176 permission_decided_callback_.Run(true, CONTENT_SETTING_BLOCK);
179 void PermissionBubbleRequestImpl::Cancelled() {
180 RegisterActionTaken();
181 permission_decided_callback_.Run(false, CONTENT_SETTING_DEFAULT);
184 void PermissionBubbleRequestImpl::RequestFinished() {
185 is_finished_ = true;
186 delete_callback_.Run();