forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpermission_infobar_delegate.cc
71 lines (59 loc) · 2.2 KB
/
permission_infobar_delegate.cc
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
// 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/permissions/permission_infobar_delegate.h"
#include "chrome/browser/permissions/permission_uma_util.h"
#include "chrome/grit/generated_resources.h"
#include "components/infobars/core/infobar.h"
#include "components/url_formatter/elide_url.h"
#include "ui/base/l10n/l10n_util.h"
PermissionInfobarDelegate::~PermissionInfobarDelegate() {
if (!action_taken_)
PermissionUmaUtil::PermissionIgnored(permission_type_, requesting_origin_);
}
PermissionInfobarDelegate::PermissionInfobarDelegate(
const GURL& requesting_origin,
content::PermissionType permission_type,
ContentSettingsType content_settings_type,
const base::Callback<void(bool, bool)>& callback)
: requesting_origin_(requesting_origin),
action_taken_(false),
permission_type_(permission_type),
content_settings_type_(content_settings_type),
callback_(callback) {}
base::string16 PermissionInfobarDelegate::GetMessageText() const {
return l10n_util::GetStringFUTF16(
GetMessageResourceId(),
url_formatter::FormatUrlForSecurityDisplay(
requesting_origin_,
url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC));
}
infobars::InfoBarDelegate::Type PermissionInfobarDelegate::GetInfoBarType()
const {
return PAGE_ACTION_TYPE;
}
void PermissionInfobarDelegate::InfoBarDismissed() {
SetPermission(false, false);
}
PermissionInfobarDelegate*
PermissionInfobarDelegate::AsPermissionInfobarDelegate() {
return this;
}
base::string16 PermissionInfobarDelegate::GetButtonLabel(
InfoBarButton button) const {
return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
IDS_PERMISSION_ALLOW : IDS_PERMISSION_DENY);
}
bool PermissionInfobarDelegate::Accept() {
SetPermission(true, true);
return true;
}
bool PermissionInfobarDelegate::Cancel() {
SetPermission(true, false);
return true;
}
void PermissionInfobarDelegate::SetPermission(bool update_content_setting,
bool allowed) {
action_taken_ = true;
callback_.Run(update_content_setting, allowed);
}