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 "grit/theme_resources.h"
11 #include "net/base/net_util.h"
12 #include "ui/base/l10n/l10n_util.h"
13 #include "ui/gfx/vector_icons_public2.h"
15 PermissionBubbleRequestImpl::PermissionBubbleRequestImpl(
16 const GURL
& request_origin
,
18 ContentSettingsType type
,
19 const std::string
& display_languages
,
20 const PermissionDecidedCallback
& permission_decided_callback
,
21 const base::Closure delete_callback
)
22 : request_origin_(request_origin
),
23 user_gesture_(user_gesture
),
25 display_languages_(display_languages
),
26 permission_decided_callback_(permission_decided_callback
),
27 delete_callback_(delete_callback
),
29 action_taken_(false) {
32 PermissionBubbleRequestImpl::~PermissionBubbleRequestImpl() {
35 PermissionContextUmaUtil::PermissionIgnored(type_
, request_origin_
);
38 gfx::VectorIconId
PermissionBubbleRequestImpl::GetVectorIconId() const {
40 #if defined(TOOLKIT_VIEWS)
41 case CONTENT_SETTINGS_TYPE_GEOLOCATION
:
42 return gfx::VectorIconId::LOCATION_ON
;
43 #if defined(ENABLE_NOTIFICATIONS)
44 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS
:
45 return gfx::VectorIconId::NOTIFICATIONS
;
51 return gfx::VectorIconId::VECTOR_ICON_NONE
;
55 int PermissionBubbleRequestImpl::GetIconID() const {
58 case CONTENT_SETTINGS_TYPE_GEOLOCATION
:
59 icon_id
= IDR_INFOBAR_GEOLOCATION
;
61 #if defined(ENABLE_NOTIFICATIONS)
62 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS
:
63 icon_id
= IDR_INFOBAR_DESKTOP_NOTIFICATIONS
;
66 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX
:
67 icon_id
= IDR_ALLOWED_MIDI_SYSEX
;
69 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING
:
70 icon_id
= IDR_INFOBAR_WARNING
;
72 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
73 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER
:
74 icon_id
= IDR_INFOBAR_PROTECTED_MEDIA_IDENTIFIER
;
79 return IDR_INFOBAR_WARNING
;
84 base::string16
PermissionBubbleRequestImpl::GetMessageText() const {
87 case CONTENT_SETTINGS_TYPE_GEOLOCATION
:
88 message_id
= IDS_GEOLOCATION_INFOBAR_QUESTION
;
90 #if defined(ENABLE_NOTIFICATIONS)
91 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS
:
92 message_id
= IDS_NOTIFICATION_PERMISSIONS
;
95 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX
:
96 message_id
= IDS_MIDI_SYSEX_INFOBAR_QUESTION
;
98 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING
:
99 message_id
= IDS_PUSH_MESSAGES_PERMISSION_QUESTION
;
101 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
102 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER
:
103 message_id
= IDS_PROTECTED_MEDIA_IDENTIFIER_INFOBAR_QUESTION
;
108 return base::string16();
110 return l10n_util::GetStringFUTF16(
112 net::FormatUrl(request_origin_
, display_languages_
,
113 net::kFormatUrlOmitUsernamePassword
|
114 net::kFormatUrlOmitTrailingSlashOnBareHostname
,
115 net::UnescapeRule::SPACES
, NULL
, NULL
, NULL
));
118 base::string16
PermissionBubbleRequestImpl::GetMessageTextFragment() const {
121 case CONTENT_SETTINGS_TYPE_GEOLOCATION
:
122 message_id
= IDS_GEOLOCATION_INFOBAR_PERMISSION_FRAGMENT
;
124 #if defined(ENABLE_NOTIFICATIONS)
125 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS
:
126 message_id
= IDS_NOTIFICATION_PERMISSIONS_FRAGMENT
;
129 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX
:
130 message_id
= IDS_MIDI_SYSEX_PERMISSION_FRAGMENT
;
132 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING
:
133 message_id
= IDS_PUSH_MESSAGES_BUBBLE_FRAGMENT
;
135 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
136 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER
:
137 message_id
= IDS_PROTECTED_MEDIA_IDENTIFIER_PERMISSION_FRAGMENT
;
142 return base::string16();
144 return l10n_util::GetStringUTF16(message_id
);
147 bool PermissionBubbleRequestImpl::HasUserGesture() const {
148 return user_gesture_
;
151 GURL
PermissionBubbleRequestImpl::GetRequestingHostname() const {
152 return request_origin_
;
155 void PermissionBubbleRequestImpl::PermissionGranted() {
156 RegisterActionTaken();
157 permission_decided_callback_
.Run(true, CONTENT_SETTING_ALLOW
);
160 void PermissionBubbleRequestImpl::PermissionDenied() {
161 RegisterActionTaken();
162 permission_decided_callback_
.Run(true, CONTENT_SETTING_BLOCK
);
165 void PermissionBubbleRequestImpl::Cancelled() {
166 RegisterActionTaken();
167 permission_decided_callback_
.Run(false, CONTENT_SETTING_DEFAULT
);
170 void PermissionBubbleRequestImpl::RequestFinished() {
172 delete_callback_
.Run();