Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / permissions / permission_bubble_request_impl.cc
blobf175962df61dfd2add1ca4c51101bbb17275d8c6
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,
17 bool user_gesture,
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),
24 type_(type),
25 display_languages_(display_languages),
26 permission_decided_callback_(permission_decided_callback),
27 delete_callback_(delete_callback),
28 is_finished_(false),
29 action_taken_(false) {
32 PermissionBubbleRequestImpl::~PermissionBubbleRequestImpl() {
33 DCHECK(is_finished_);
34 if (!action_taken_)
35 PermissionContextUmaUtil::PermissionIgnored(type_, request_origin_);
38 gfx::VectorIconId PermissionBubbleRequestImpl::GetVectorIconId() const {
39 switch (type_) {
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;
46 break;
47 #endif
48 #endif
50 default:
51 return gfx::VectorIconId::VECTOR_ICON_NONE;
55 int PermissionBubbleRequestImpl::GetIconID() const {
56 int icon_id;
57 switch (type_) {
58 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
59 icon_id = IDR_INFOBAR_GEOLOCATION;
60 break;
61 #if defined(ENABLE_NOTIFICATIONS)
62 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
63 icon_id = IDR_INFOBAR_DESKTOP_NOTIFICATIONS;
64 break;
65 #endif
66 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX:
67 icon_id = IDR_ALLOWED_MIDI_SYSEX;
68 break;
69 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING:
70 icon_id = IDR_INFOBAR_WARNING;
71 break;
72 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
73 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER:
74 icon_id = IDR_INFOBAR_PROTECTED_MEDIA_IDENTIFIER;
75 break;
76 #endif
77 default:
78 NOTREACHED();
79 return IDR_INFOBAR_WARNING;
81 return icon_id;
84 base::string16 PermissionBubbleRequestImpl::GetMessageText() const {
85 int message_id;
86 switch (type_) {
87 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
88 message_id = IDS_GEOLOCATION_INFOBAR_QUESTION;
89 break;
90 #if defined(ENABLE_NOTIFICATIONS)
91 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
92 message_id = IDS_NOTIFICATION_PERMISSIONS;
93 break;
94 #endif
95 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX:
96 message_id = IDS_MIDI_SYSEX_INFOBAR_QUESTION;
97 break;
98 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING:
99 message_id = IDS_PUSH_MESSAGES_PERMISSION_QUESTION;
100 break;
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;
104 break;
105 #endif
106 default:
107 NOTREACHED();
108 return base::string16();
110 return l10n_util::GetStringFUTF16(
111 message_id,
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 {
119 int message_id;
120 switch (type_) {
121 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
122 message_id = IDS_GEOLOCATION_INFOBAR_PERMISSION_FRAGMENT;
123 break;
124 #if defined(ENABLE_NOTIFICATIONS)
125 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
126 message_id = IDS_NOTIFICATION_PERMISSIONS_FRAGMENT;
127 break;
128 #endif
129 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX:
130 message_id = IDS_MIDI_SYSEX_PERMISSION_FRAGMENT;
131 break;
132 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING:
133 message_id = IDS_PUSH_MESSAGES_BUBBLE_FRAGMENT;
134 break;
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;
138 break;
139 #endif
140 default:
141 NOTREACHED();
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() {
171 is_finished_ = true;
172 delete_callback_.Run();