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/content_settings/permission_queue_controller.h"
8 #include "chrome/browser/infobars/infobar_service.h"
9 #include "chrome/common/url_constants.h"
10 #include "chrome/grit/generated_resources.h"
11 #include "components/infobars/core/infobar.h"
12 #include "grit/components_strings.h"
13 #include "grit/theme_resources.h"
14 #include "net/base/net_util.h"
15 #include "ui/base/l10n/l10n_util.h"
18 infobars::InfoBar
* ProtectedMediaIdentifierInfoBarDelegate::Create(
19 InfoBarService
* infobar_service
,
20 PermissionQueueController
* controller
,
21 const PermissionRequestID
& id
,
22 const GURL
& requesting_frame
,
23 const std::string
& display_languages
) {
24 return infobar_service
->AddInfoBar(
25 infobar_service
->CreateConfirmInfoBar(scoped_ptr
<ConfirmInfoBarDelegate
>(
26 new ProtectedMediaIdentifierInfoBarDelegate(
27 controller
, id
, requesting_frame
, display_languages
))));
31 ProtectedMediaIdentifierInfoBarDelegate::
32 ProtectedMediaIdentifierInfoBarDelegate(
33 PermissionQueueController
* controller
,
34 const PermissionRequestID
& id
,
35 const GURL
& requesting_frame
,
36 const std::string
& display_languages
)
37 : ConfirmInfoBarDelegate(),
38 controller_(controller
),
40 requesting_frame_(requesting_frame
),
41 display_languages_(display_languages
) {
44 ProtectedMediaIdentifierInfoBarDelegate::
45 ~ProtectedMediaIdentifierInfoBarDelegate() {
48 bool ProtectedMediaIdentifierInfoBarDelegate::Accept() {
49 SetPermission(true, true);
53 void ProtectedMediaIdentifierInfoBarDelegate::SetPermission(
54 bool update_content_setting
,
56 content::WebContents
* web_contents
=
57 InfoBarService::WebContentsFromInfoBar(infobar());
58 controller_
->OnPermissionSet(id_
, requesting_frame_
,
59 web_contents
->GetLastCommittedURL().GetOrigin(),
60 update_content_setting
, allowed
);
63 infobars::InfoBarDelegate::Type
64 ProtectedMediaIdentifierInfoBarDelegate::GetInfoBarType() const {
65 return PAGE_ACTION_TYPE
;
68 int ProtectedMediaIdentifierInfoBarDelegate::GetIconID() const {
69 return IDR_INFOBAR_PROTECTED_MEDIA_IDENTIFIER
;
72 void ProtectedMediaIdentifierInfoBarDelegate::InfoBarDismissed() {
73 SetPermission(false, false);
76 base::string16
ProtectedMediaIdentifierInfoBarDelegate::GetMessageText() const {
77 return l10n_util::GetStringFUTF16(
78 IDS_PROTECTED_MEDIA_IDENTIFIER_INFOBAR_QUESTION
,
79 net::FormatUrl(requesting_frame_
.GetOrigin(), display_languages_
));
82 base::string16
ProtectedMediaIdentifierInfoBarDelegate::GetButtonLabel(
83 InfoBarButton button
) const {
84 return l10n_util::GetStringUTF16((button
== BUTTON_OK
) ?
85 IDS_PROTECTED_MEDIA_IDENTIFIER_ALLOW_BUTTON
:
86 IDS_PROTECTED_MEDIA_IDENTIFIER_DENY_BUTTON
);
89 bool ProtectedMediaIdentifierInfoBarDelegate::Cancel() {
90 SetPermission(true, false);
94 base::string16
ProtectedMediaIdentifierInfoBarDelegate::GetLinkText() const {
95 return l10n_util::GetStringUTF16(IDS_LEARN_MORE
);
98 bool ProtectedMediaIdentifierInfoBarDelegate::LinkClicked(
99 WindowOpenDisposition disposition
) {
100 InfoBarService::WebContentsFromInfoBar(infobar())
101 ->OpenURL(content::OpenURLParams(
102 GURL(chrome::kEnhancedPlaybackNotificationLearnMoreURL
),
104 (disposition
== CURRENT_TAB
) ? NEW_FOREGROUND_TAB
: disposition
,
105 ui::PAGE_TRANSITION_LINK
, false));
106 return false; // Do not dismiss the info bar.