1 // Copyright 2013 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/media/protected_media_identifier_infobar_delegate.h"
7 #include "chrome/browser/infobars/infobar_service.h"
8 #include "chrome/browser/permissions/permission_queue_controller.h"
9 #include "chrome/browser/permissions/permission_request_id.h"
10 #include "chrome/common/url_constants.h"
11 #include "chrome/grit/generated_resources.h"
12 #include "components/infobars/core/infobar.h"
13 #include "components/url_formatter/url_formatter.h"
14 #include "grit/components_strings.h"
15 #include "grit/theme_resources.h"
16 #include "ui/base/l10n/l10n_util.h"
19 infobars::InfoBar
* ProtectedMediaIdentifierInfoBarDelegate::Create(
20 InfoBarService
* infobar_service
,
21 PermissionQueueController
* controller
,
22 const PermissionRequestID
& id
,
23 const GURL
& requesting_frame
,
24 const std::string
& display_languages
) {
25 return infobar_service
->AddInfoBar(
26 infobar_service
->CreateConfirmInfoBar(scoped_ptr
<ConfirmInfoBarDelegate
>(
27 new ProtectedMediaIdentifierInfoBarDelegate(
28 controller
, id
, requesting_frame
, display_languages
))));
32 ProtectedMediaIdentifierInfoBarDelegate::
33 ProtectedMediaIdentifierInfoBarDelegate(
34 PermissionQueueController
* controller
,
35 const PermissionRequestID
& id
,
36 const GURL
& requesting_frame
,
37 const std::string
& display_languages
)
38 : ConfirmInfoBarDelegate(),
39 controller_(controller
),
41 requesting_frame_(requesting_frame
),
42 display_languages_(display_languages
) {
45 ProtectedMediaIdentifierInfoBarDelegate::
46 ~ProtectedMediaIdentifierInfoBarDelegate() {
49 bool ProtectedMediaIdentifierInfoBarDelegate::Accept() {
50 SetPermission(true, true);
54 void ProtectedMediaIdentifierInfoBarDelegate::SetPermission(
55 bool update_content_setting
,
57 content::WebContents
* web_contents
=
58 InfoBarService::WebContentsFromInfoBar(infobar());
59 controller_
->OnPermissionSet(id_
, requesting_frame_
,
60 web_contents
->GetLastCommittedURL().GetOrigin(),
61 update_content_setting
, allowed
);
64 infobars::InfoBarDelegate::Type
65 ProtectedMediaIdentifierInfoBarDelegate::GetInfoBarType() const {
66 return PAGE_ACTION_TYPE
;
69 int ProtectedMediaIdentifierInfoBarDelegate::GetIconID() const {
70 return IDR_INFOBAR_PROTECTED_MEDIA_IDENTIFIER
;
73 void ProtectedMediaIdentifierInfoBarDelegate::InfoBarDismissed() {
74 SetPermission(false, false);
77 base::string16
ProtectedMediaIdentifierInfoBarDelegate::GetMessageText() const {
78 return l10n_util::GetStringFUTF16(
79 IDS_PROTECTED_MEDIA_IDENTIFIER_INFOBAR_QUESTION
,
80 url_formatter::FormatUrl(requesting_frame_
.GetOrigin(),
84 base::string16
ProtectedMediaIdentifierInfoBarDelegate::GetButtonLabel(
85 InfoBarButton button
) const {
86 return l10n_util::GetStringUTF16((button
== BUTTON_OK
) ?
87 IDS_PROTECTED_MEDIA_IDENTIFIER_ALLOW_BUTTON
:
88 IDS_PROTECTED_MEDIA_IDENTIFIER_DENY_BUTTON
);
91 bool ProtectedMediaIdentifierInfoBarDelegate::Cancel() {
92 SetPermission(true, false);
96 base::string16
ProtectedMediaIdentifierInfoBarDelegate::GetLinkText() const {
97 return l10n_util::GetStringUTF16(IDS_LEARN_MORE
);
100 bool ProtectedMediaIdentifierInfoBarDelegate::LinkClicked(
101 WindowOpenDisposition disposition
) {
102 InfoBarService::WebContentsFromInfoBar(infobar())
103 ->OpenURL(content::OpenURLParams(
104 GURL(chrome::kEnhancedPlaybackNotificationLearnMoreURL
),
106 (disposition
== CURRENT_TAB
) ? NEW_FOREGROUND_TAB
: disposition
,
107 ui::PAGE_TRANSITION_LINK
, false));
108 return false; // Do not dismiss the info bar.