Roll src/third_party/WebKit 8b42d1d:744641d (svn 186770:186771)
[chromium-blink-merge.git] / chrome / browser / content_settings / permission_bubble_request_impl.cc
blob5359d6599f62fe2a6f13d91fcc760bd8ed3efcaa
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 base::Callback<void(bool, bool)> 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 default:
55 NOTREACHED();
56 return IDR_INFOBAR_WARNING;
58 return icon_id;
61 base::string16 PermissionBubbleRequestImpl::GetMessageText() const {
62 int message_id;
63 switch (type_) {
64 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
65 message_id = IDS_GEOLOCATION_INFOBAR_QUESTION;
66 break;
67 #if defined(ENABLE_NOTIFICATIONS)
68 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
69 message_id = IDS_NOTIFICATION_PERMISSIONS;
70 break;
71 #endif
72 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX:
73 message_id = IDS_MIDI_SYSEX_INFOBAR_QUESTION;
74 break;
75 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING:
76 message_id = IDS_PUSH_MESSAGES_PERMISSION_QUESTION;
77 break;
78 default:
79 NOTREACHED();
80 return base::string16();
82 return l10n_util::GetStringFUTF16(
83 message_id,
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 {
91 int message_id;
92 switch (type_) {
93 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
94 message_id = IDS_GEOLOCATION_INFOBAR_PERMISSION_FRAGMENT;
95 break;
96 #if defined(ENABLE_NOTIFICATIONS)
97 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
98 message_id = IDS_NOTIFICATION_PERMISSIONS_FRAGMENT;
99 break;
100 #endif
101 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX:
102 message_id = IDS_MIDI_SYSEX_PERMISSION_FRAGMENT;
103 break;
104 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING:
105 message_id = IDS_PUSH_MESSAGES_BUBBLE_FRAGMENT;
106 break;
107 default:
108 NOTREACHED();
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() {
138 is_finished_ = true;
139 delete_callback_.Run();