1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/content_settings/permission_bubble_request_impl.h"
#include "chrome/browser/content_settings/permission_context_base.h"
#include "chrome/browser/content_settings/permission_context_uma_util.h"
#include "chrome/grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "net/base/net_util.h"
#include "ui/base/l10n/l10n_util.h"
PermissionBubbleRequestImpl::PermissionBubbleRequestImpl(
const GURL& request_origin,
bool user_gesture,
ContentSettingsType type,
const std::string& display_languages,
const base::Callback<void(bool, bool)> permission_decided_callback,
const base::Closure delete_callback)
: request_origin_(request_origin),
user_gesture_(user_gesture),
type_(type),
display_languages_(display_languages),
permission_decided_callback_(permission_decided_callback),
delete_callback_(delete_callback),
is_finished_(false),
action_taken_(false) {
}
PermissionBubbleRequestImpl::~PermissionBubbleRequestImpl() {
DCHECK(is_finished_);
if (!action_taken_)
PermissionContextUmaUtil::PermissionIgnored(type_);
}
int PermissionBubbleRequestImpl::GetIconID() const {
int icon_id;
switch (type_) {
case CONTENT_SETTINGS_TYPE_GEOLOCATION:
icon_id = IDR_INFOBAR_GEOLOCATION;
break;
#if defined(ENABLE_NOTIFICATIONS)
case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
icon_id = IDR_INFOBAR_DESKTOP_NOTIFICATIONS;
break;
#endif
case CONTENT_SETTINGS_TYPE_MIDI_SYSEX:
icon_id = IDR_ALLOWED_MIDI_SYSEX;
break;
case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING:
icon_id = IDR_INFOBAR_WARNING;
break;
default:
NOTREACHED();
return IDR_INFOBAR_WARNING;
}
return icon_id;
}
base::string16 PermissionBubbleRequestImpl::GetMessageText() const {
int message_id;
switch (type_) {
case CONTENT_SETTINGS_TYPE_GEOLOCATION:
message_id = IDS_GEOLOCATION_INFOBAR_QUESTION;
break;
#if defined(ENABLE_NOTIFICATIONS)
case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
message_id = IDS_NOTIFICATION_PERMISSIONS;
break;
#endif
case CONTENT_SETTINGS_TYPE_MIDI_SYSEX:
message_id = IDS_MIDI_SYSEX_INFOBAR_QUESTION;
break;
case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING:
message_id = IDS_PUSH_MESSAGES_PERMISSION_QUESTION;
break;
default:
NOTREACHED();
return base::string16();
}
return l10n_util::GetStringFUTF16(
message_id,
net::FormatUrl(request_origin_, display_languages_,
net::kFormatUrlOmitUsernamePassword |
net::kFormatUrlOmitTrailingSlashOnBareHostname,
net::UnescapeRule::SPACES, NULL, NULL, NULL));
}
base::string16 PermissionBubbleRequestImpl::GetMessageTextFragment() const {
int message_id;
switch (type_) {
case CONTENT_SETTINGS_TYPE_GEOLOCATION:
message_id = IDS_GEOLOCATION_INFOBAR_PERMISSION_FRAGMENT;
break;
#if defined(ENABLE_NOTIFICATIONS)
case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
message_id = IDS_NOTIFICATION_PERMISSIONS_FRAGMENT;
break;
#endif
case CONTENT_SETTINGS_TYPE_MIDI_SYSEX:
message_id = IDS_MIDI_SYSEX_PERMISSION_FRAGMENT;
break;
case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING:
message_id = IDS_PUSH_MESSAGES_BUBBLE_FRAGMENT;
break;
default:
NOTREACHED();
return base::string16();
}
return l10n_util::GetStringUTF16(message_id);
}
bool PermissionBubbleRequestImpl::HasUserGesture() const {
return user_gesture_;
}
GURL PermissionBubbleRequestImpl::GetRequestingHostname() const {
return request_origin_;
}
void PermissionBubbleRequestImpl::PermissionGranted() {
RegisterActionTaken();
permission_decided_callback_.Run(true, true);
}
void PermissionBubbleRequestImpl::PermissionDenied() {
RegisterActionTaken();
permission_decided_callback_.Run(true, false);
}
void PermissionBubbleRequestImpl::Cancelled() {
RegisterActionTaken();
permission_decided_callback_.Run(false, false);
}
void PermissionBubbleRequestImpl::RequestFinished() {
is_finished_ = true;
delete_callback_.Run();
}
|