Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / content_settings / permission_bubble_request_impl.cc
blob3fc8bedca41c410a8afc0408c152e50cad27a36b
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,
16 bool user_gesture,
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),
23 type_(type),
24 display_languages_(display_languages),
25 permission_decided_callback_(permission_decided_callback),
26 delete_callback_(delete_callback),
27 is_finished_(false),
28 action_taken_(false) {
31 PermissionBubbleRequestImpl::~PermissionBubbleRequestImpl() {
32 DCHECK(is_finished_);
33 if (!action_taken_)
34 PermissionContextUmaUtil::PermissionIgnored(type_, request_origin_);
37 int PermissionBubbleRequestImpl::GetIconID() const {
38 int icon_id;
39 switch (type_) {
40 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
41 icon_id = IDR_INFOBAR_GEOLOCATION;
42 break;
43 #if defined(ENABLE_NOTIFICATIONS)
44 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
45 icon_id = IDR_INFOBAR_DESKTOP_NOTIFICATIONS;
46 break;
47 #endif
48 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX:
49 icon_id = IDR_ALLOWED_MIDI_SYSEX;
50 break;
51 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING:
52 icon_id = IDR_INFOBAR_WARNING;
53 break;
54 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
55 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER:
56 icon_id = IDR_INFOBAR_PROTECTED_MEDIA_IDENTIFIER;
57 break;
58 #endif
59 default:
60 NOTREACHED();
61 return IDR_INFOBAR_WARNING;
63 return icon_id;
66 base::string16 PermissionBubbleRequestImpl::GetMessageText() const {
67 int message_id;
68 switch (type_) {
69 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
70 message_id = IDS_GEOLOCATION_INFOBAR_QUESTION;
71 break;
72 #if defined(ENABLE_NOTIFICATIONS)
73 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
74 message_id = IDS_NOTIFICATION_PERMISSIONS;
75 break;
76 #endif
77 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX:
78 message_id = IDS_MIDI_SYSEX_INFOBAR_QUESTION;
79 break;
80 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING:
81 message_id = IDS_PUSH_MESSAGES_PERMISSION_QUESTION;
82 break;
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;
86 break;
87 #endif
88 default:
89 NOTREACHED();
90 return base::string16();
92 return l10n_util::GetStringFUTF16(
93 message_id,
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 {
101 int message_id;
102 switch (type_) {
103 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
104 message_id = IDS_GEOLOCATION_INFOBAR_PERMISSION_FRAGMENT;
105 break;
106 #if defined(ENABLE_NOTIFICATIONS)
107 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
108 message_id = IDS_NOTIFICATION_PERMISSIONS_FRAGMENT;
109 break;
110 #endif
111 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX:
112 message_id = IDS_MIDI_SYSEX_PERMISSION_FRAGMENT;
113 break;
114 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING:
115 message_id = IDS_PUSH_MESSAGES_BUBBLE_FRAGMENT;
116 break;
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;
120 break;
121 #endif
122 default:
123 NOTREACHED();
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() {
153 is_finished_ = true;
154 delete_callback_.Run();