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/content_settings/permission_bubble_request_impl.h"
7 #include "chrome/browser/content_settings/permission_context_base.h"
8 #include "chrome/browser/content_settings/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"
14 PermissionBubbleRequestImpl::PermissionBubbleRequestImpl(
15 const GURL
& request_origin
,
17 ContentSettingsType type
,
18 const std::string
& display_languages
,
19 const base::Callback
<void(bool, bool)> permission_decided_callback
,
20 const base::Closure delete_callback
)
21 : request_origin_(request_origin
),
22 user_gesture_(user_gesture
),
24 display_languages_(display_languages
),
25 permission_decided_callback_(permission_decided_callback
),
26 delete_callback_(delete_callback
),
28 action_taken_(false) {
31 PermissionBubbleRequestImpl::~PermissionBubbleRequestImpl() {
34 PermissionContextUmaUtil::PermissionIgnored(type_
, request_origin_
);
37 int PermissionBubbleRequestImpl::GetIconID() const {
40 case CONTENT_SETTINGS_TYPE_GEOLOCATION
:
41 icon_id
= IDR_INFOBAR_GEOLOCATION
;
43 #if defined(ENABLE_NOTIFICATIONS)
44 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS
:
45 icon_id
= IDR_INFOBAR_DESKTOP_NOTIFICATIONS
;
48 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX
:
49 icon_id
= IDR_ALLOWED_MIDI_SYSEX
;
51 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING
:
52 icon_id
= IDR_INFOBAR_WARNING
;
56 return IDR_INFOBAR_WARNING
;
61 base::string16
PermissionBubbleRequestImpl::GetMessageText() const {
64 case CONTENT_SETTINGS_TYPE_GEOLOCATION
:
65 message_id
= IDS_GEOLOCATION_INFOBAR_QUESTION
;
67 #if defined(ENABLE_NOTIFICATIONS)
68 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS
:
69 message_id
= IDS_NOTIFICATION_PERMISSIONS
;
72 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX
:
73 message_id
= IDS_MIDI_SYSEX_INFOBAR_QUESTION
;
75 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING
:
76 message_id
= IDS_PUSH_MESSAGES_PERMISSION_QUESTION
;
80 return base::string16();
82 return l10n_util::GetStringFUTF16(
84 net::FormatUrl(request_origin_
, display_languages_
,
85 net::kFormatUrlOmitUsernamePassword
|
86 net::kFormatUrlOmitTrailingSlashOnBareHostname
,
87 net::UnescapeRule::SPACES
, NULL
, NULL
, NULL
));
90 base::string16
PermissionBubbleRequestImpl::GetMessageTextFragment() const {
93 case CONTENT_SETTINGS_TYPE_GEOLOCATION
:
94 message_id
= IDS_GEOLOCATION_INFOBAR_PERMISSION_FRAGMENT
;
96 #if defined(ENABLE_NOTIFICATIONS)
97 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS
:
98 message_id
= IDS_NOTIFICATION_PERMISSIONS_FRAGMENT
;
101 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX
:
102 message_id
= IDS_MIDI_SYSEX_PERMISSION_FRAGMENT
;
104 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING
:
105 message_id
= IDS_PUSH_MESSAGES_BUBBLE_FRAGMENT
;
109 return base::string16();
111 return l10n_util::GetStringUTF16(message_id
);
114 bool PermissionBubbleRequestImpl::HasUserGesture() const {
115 return user_gesture_
;
118 GURL
PermissionBubbleRequestImpl::GetRequestingHostname() const {
119 return request_origin_
;
122 void PermissionBubbleRequestImpl::PermissionGranted() {
123 RegisterActionTaken();
124 permission_decided_callback_
.Run(true, true);
127 void PermissionBubbleRequestImpl::PermissionDenied() {
128 RegisterActionTaken();
129 permission_decided_callback_
.Run(true, false);
132 void PermissionBubbleRequestImpl::Cancelled() {
133 RegisterActionTaken();
134 permission_decided_callback_
.Run(false, false);
137 void PermissionBubbleRequestImpl::RequestFinished() {
139 delete_callback_
.Run();