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
,
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
),
26 display_languages_(display_languages
),
27 permission_decided_callback_(permission_decided_callback
),
28 delete_callback_(delete_callback
),
30 action_taken_(false) {
33 PermissionBubbleRequestImpl::~PermissionBubbleRequestImpl() {
36 PermissionContextUmaUtil::PermissionIgnored(type_
, request_origin_
);
39 gfx::VectorIconId
PermissionBubbleRequestImpl::GetVectorIconId() const {
40 #if defined(TOOLKIT_VIEWS)
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
;
48 #if defined(OS_CHROMEOS)
49 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER
:
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
;
57 return gfx::VectorIconId::VECTOR_ICON_NONE
;
59 #else // !defined(TOOLKIT_VIEWS)
60 return gfx::VectorIconId::VECTOR_ICON_NONE
;
64 int PermissionBubbleRequestImpl::GetIconId() const {
67 case CONTENT_SETTINGS_TYPE_GEOLOCATION
:
68 icon_id
= IDR_INFOBAR_GEOLOCATION
;
70 #if defined(ENABLE_NOTIFICATIONS)
71 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS
:
72 icon_id
= IDR_INFOBAR_DESKTOP_NOTIFICATIONS
;
75 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX
:
76 icon_id
= IDR_ALLOWED_MIDI_SYSEX
;
78 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
79 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER
:
80 icon_id
= IDR_INFOBAR_PROTECTED_MEDIA_IDENTIFIER
;
83 // TODO(dgrogan): Get a real icon. https://crbug.com/516069
84 case CONTENT_SETTINGS_TYPE_DURABLE_STORAGE
:
85 icon_id
= IDR_INFOBAR_WARNING
;
89 return IDR_INFOBAR_WARNING
;
94 base::string16
PermissionBubbleRequestImpl::GetMessageText() const {
97 case CONTENT_SETTINGS_TYPE_GEOLOCATION
:
98 message_id
= IDS_GEOLOCATION_INFOBAR_QUESTION
;
100 #if defined(ENABLE_NOTIFICATIONS)
101 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS
:
102 message_id
= IDS_NOTIFICATION_PERMISSIONS
;
105 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX
:
106 message_id
= IDS_MIDI_SYSEX_INFOBAR_QUESTION
;
108 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING
:
109 message_id
= IDS_PUSH_MESSAGES_PERMISSION_QUESTION
;
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
;
118 return base::string16();
120 return l10n_util::GetStringFUTF16(
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 {
132 case CONTENT_SETTINGS_TYPE_GEOLOCATION
:
133 message_id
= IDS_GEOLOCATION_INFOBAR_PERMISSION_FRAGMENT
;
135 #if defined(ENABLE_NOTIFICATIONS)
136 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS
:
137 message_id
= IDS_NOTIFICATION_PERMISSIONS_FRAGMENT
;
140 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX
:
141 message_id
= IDS_MIDI_SYSEX_PERMISSION_FRAGMENT
;
143 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING
:
144 message_id
= IDS_PUSH_MESSAGES_BUBBLE_FRAGMENT
;
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
;
151 case CONTENT_SETTINGS_TYPE_DURABLE_STORAGE
:
152 message_id
= IDS_DURABLE_STORAGE_BUBBLE_FRAGMENT
;
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() {
186 delete_callback_
.Run();