Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / permissions / permission_infobar_delegate.cc
blobf91c995a0cd618ca64f8fbc31dd016d4f3e6c057
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_infobar_delegate.h"
7 #include "chrome/browser/permissions/permission_context_uma_util.h"
8 #include "chrome/grit/generated_resources.h"
9 #include "components/infobars/core/infobar.h"
10 #include "ui/base/l10n/l10n_util.h"
12 PermissionInfobarDelegate::~PermissionInfobarDelegate() {
13 if (!action_taken_)
14 PermissionContextUmaUtil::PermissionIgnored(type_, requesting_origin_);
17 PermissionInfobarDelegate::PermissionInfobarDelegate(
18 const GURL& requesting_origin,
19 ContentSettingsType type,
20 const base::Callback<void(bool, bool)>& callback)
21 : requesting_origin_(requesting_origin),
22 action_taken_(false),
23 type_(type),
24 callback_(callback) {
27 infobars::InfoBarDelegate::Type
28 PermissionInfobarDelegate::GetInfoBarType() const {
29 return PAGE_ACTION_TYPE;
32 void PermissionInfobarDelegate::InfoBarDismissed() {
33 SetPermission(false, false);
36 PermissionInfobarDelegate*
37 PermissionInfobarDelegate::AsPermissionInfobarDelegate() {
38 return this;
41 base::string16 PermissionInfobarDelegate::GetButtonLabel(
42 InfoBarButton button) const {
43 return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
44 IDS_PERMISSION_ALLOW : IDS_PERMISSION_DENY);
47 bool PermissionInfobarDelegate::Accept() {
48 SetPermission(true, true);
49 return true;
52 bool PermissionInfobarDelegate::Cancel() {
53 SetPermission(true, false);
54 return true;
57 void PermissionInfobarDelegate::SetPermission(bool update_content_setting,
58 bool allowed) {
59 action_taken_ = true;
60 callback_.Run(update_content_setting, allowed);