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 PermissionDecidedCallback
& 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
;
54 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
55 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER
:
56 icon_id
= IDR_INFOBAR_PROTECTED_MEDIA_IDENTIFIER
;
61 return IDR_INFOBAR_WARNING
;
66 base::string16
PermissionBubbleRequestImpl::GetMessageText() const {
69 case CONTENT_SETTINGS_TYPE_GEOLOCATION
:
70 message_id
= IDS_GEOLOCATION_INFOBAR_QUESTION
;
72 #if defined(ENABLE_NOTIFICATIONS)
73 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS
:
74 message_id
= IDS_NOTIFICATION_PERMISSIONS
;
77 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX
:
78 message_id
= IDS_MIDI_SYSEX_INFOBAR_QUESTION
;
80 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING
:
81 message_id
= IDS_PUSH_MESSAGES_PERMISSION_QUESTION
;
83 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
84 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER
:
85 message_id
= IDS_PROTECTED_MEDIA_IDENTIFIER_INFOBAR_QUESTION
;
90 return base::string16();
92 return l10n_util::GetStringFUTF16(
94 net::FormatUrl(request_origin_
, display_languages_
,
95 net::kFormatUrlOmitUsernamePassword
|
96 net::kFormatUrlOmitTrailingSlashOnBareHostname
,
97 net::UnescapeRule::SPACES
, NULL
, NULL
, NULL
));
100 base::string16
PermissionBubbleRequestImpl::GetMessageTextFragment() const {
103 case CONTENT_SETTINGS_TYPE_GEOLOCATION
:
104 message_id
= IDS_GEOLOCATION_INFOBAR_PERMISSION_FRAGMENT
;
106 #if defined(ENABLE_NOTIFICATIONS)
107 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS
:
108 message_id
= IDS_NOTIFICATION_PERMISSIONS_FRAGMENT
;
111 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX
:
112 message_id
= IDS_MIDI_SYSEX_PERMISSION_FRAGMENT
;
114 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING
:
115 message_id
= IDS_PUSH_MESSAGES_BUBBLE_FRAGMENT
;
117 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
118 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER
:
119 message_id
= IDS_PROTECTED_MEDIA_IDENTIFIER_PERMISSION_FRAGMENT
;
124 return base::string16();
126 return l10n_util::GetStringUTF16(message_id
);
129 bool PermissionBubbleRequestImpl::HasUserGesture() const {
130 return user_gesture_
;
133 GURL
PermissionBubbleRequestImpl::GetRequestingHostname() const {
134 return request_origin_
;
137 void PermissionBubbleRequestImpl::PermissionGranted() {
138 RegisterActionTaken();
139 permission_decided_callback_
.Run(true, CONTENT_SETTING_ALLOW
);
142 void PermissionBubbleRequestImpl::PermissionDenied() {
143 RegisterActionTaken();
144 permission_decided_callback_
.Run(true, CONTENT_SETTING_BLOCK
);
147 void PermissionBubbleRequestImpl::Cancelled() {
148 RegisterActionTaken();
149 permission_decided_callback_
.Run(false, CONTENT_SETTING_DEFAULT
);
152 void PermissionBubbleRequestImpl::RequestFinished() {
154 delete_callback_
.Run();