OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/media/protected_media_identifier_infobar_delegate.h" | 5 #include "chrome/browser/media/protected_media_identifier_infobar_delegate.h" |
6 | 6 |
7 #include "chrome/browser/infobars/infobar_service.h" | 7 #include "chrome/browser/infobars/infobar_service.h" |
8 #include "chrome/browser/permissions/permission_queue_controller.h" | 8 #include "chrome/browser/permissions/permission_queue_controller.h" |
9 #include "chrome/browser/permissions/permission_request_id.h" | 9 #include "chrome/browser/permissions/permission_request_id.h" |
10 #include "chrome/common/url_constants.h" | 10 #include "chrome/common/url_constants.h" |
11 #include "chrome/grit/generated_resources.h" | 11 #include "chrome/grit/generated_resources.h" |
12 #include "components/infobars/core/infobar.h" | 12 #include "components/infobars/core/infobar.h" |
13 #include "components/url_formatter/url_formatter.h" | 13 #include "components/url_formatter/url_formatter.h" |
14 #include "grit/components_strings.h" | 14 #include "grit/components_strings.h" |
15 #include "grit/theme_resources.h" | 15 #include "grit/theme_resources.h" |
16 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
17 | 17 |
18 // static | 18 // static |
19 infobars::InfoBar* ProtectedMediaIdentifierInfoBarDelegate::Create( | 19 infobars::InfoBar* ProtectedMediaIdentifierInfoBarDelegate::Create( |
20 InfoBarService* infobar_service, | 20 InfoBarService* infobar_service, |
21 PermissionQueueController* controller, | 21 PermissionQueueController* controller, |
22 const PermissionRequestID& id, | 22 const PermissionRequestID& id, |
23 const GURL& requesting_frame, | 23 const GURL& requesting_frame, |
24 const std::string& display_languages) { | 24 const std::string& display_languages) { |
25 return infobar_service->AddInfoBar( | 25 return infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar( |
26 infobar_service->CreateConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate>( | 26 scoped_ptr<ConfirmInfoBarDelegate>( |
27 new ProtectedMediaIdentifierInfoBarDelegate( | 27 new ProtectedMediaIdentifierInfoBarDelegate( |
28 controller, id, requesting_frame, display_languages)))); | 28 controller, id, requesting_frame, display_languages)))); |
29 } | 29 } |
30 | 30 |
31 | |
32 ProtectedMediaIdentifierInfoBarDelegate:: | 31 ProtectedMediaIdentifierInfoBarDelegate:: |
33 ProtectedMediaIdentifierInfoBarDelegate( | 32 ProtectedMediaIdentifierInfoBarDelegate( |
34 PermissionQueueController* controller, | 33 PermissionQueueController* controller, |
35 const PermissionRequestID& id, | 34 const PermissionRequestID& id, |
36 const GURL& requesting_frame, | 35 const GURL& requesting_frame, |
37 const std::string& display_languages) | 36 const std::string& display_languages) |
38 : ConfirmInfoBarDelegate(), | 37 : PermissionInfobarDelegate( |
39 controller_(controller), | 38 controller, id, requesting_frame, |
40 id_(id), | 39 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER), |
41 requesting_frame_(requesting_frame), | 40 requesting_frame_(requesting_frame), |
42 display_languages_(display_languages) { | 41 display_languages_(display_languages) { |
43 } | 42 } |
44 | 43 |
45 ProtectedMediaIdentifierInfoBarDelegate:: | 44 ProtectedMediaIdentifierInfoBarDelegate:: |
46 ~ProtectedMediaIdentifierInfoBarDelegate() { | 45 ~ProtectedMediaIdentifierInfoBarDelegate() { |
47 } | 46 } |
48 | 47 |
49 bool ProtectedMediaIdentifierInfoBarDelegate::Accept() { | |
50 SetPermission(true, true); | |
51 return true; | |
52 } | |
53 | |
54 void ProtectedMediaIdentifierInfoBarDelegate::SetPermission( | |
55 bool update_content_setting, | |
56 bool allowed) { | |
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); | |
62 } | |
63 | |
64 infobars::InfoBarDelegate::Type | |
65 ProtectedMediaIdentifierInfoBarDelegate::GetInfoBarType() const { | |
66 return PAGE_ACTION_TYPE; | |
67 } | |
68 | |
69 int ProtectedMediaIdentifierInfoBarDelegate::GetIconId() const { | 48 int ProtectedMediaIdentifierInfoBarDelegate::GetIconId() const { |
70 return IDR_INFOBAR_PROTECTED_MEDIA_IDENTIFIER; | 49 return IDR_INFOBAR_PROTECTED_MEDIA_IDENTIFIER; |
71 } | 50 } |
72 | 51 |
73 void ProtectedMediaIdentifierInfoBarDelegate::InfoBarDismissed() { | |
74 SetPermission(false, false); | |
75 } | |
76 | |
77 base::string16 ProtectedMediaIdentifierInfoBarDelegate::GetMessageText() const { | 52 base::string16 ProtectedMediaIdentifierInfoBarDelegate::GetMessageText() const { |
78 return l10n_util::GetStringFUTF16( | 53 return l10n_util::GetStringFUTF16( |
79 IDS_PROTECTED_MEDIA_IDENTIFIER_INFOBAR_QUESTION, | 54 IDS_PROTECTED_MEDIA_IDENTIFIER_INFOBAR_QUESTION, |
80 url_formatter::FormatUrl(requesting_frame_.GetOrigin(), | 55 url_formatter::FormatUrl(requesting_frame_.GetOrigin(), |
81 display_languages_)); | 56 display_languages_)); |
82 } | 57 } |
83 | 58 |
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); | |
89 } | |
90 | |
91 bool ProtectedMediaIdentifierInfoBarDelegate::Cancel() { | |
92 SetPermission(true, false); | |
93 return true; | |
94 } | |
95 | |
96 base::string16 ProtectedMediaIdentifierInfoBarDelegate::GetLinkText() const { | 59 base::string16 ProtectedMediaIdentifierInfoBarDelegate::GetLinkText() const { |
97 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); | 60 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); |
98 } | 61 } |
99 | 62 |
100 bool ProtectedMediaIdentifierInfoBarDelegate::LinkClicked( | 63 bool ProtectedMediaIdentifierInfoBarDelegate::LinkClicked( |
101 WindowOpenDisposition disposition) { | 64 WindowOpenDisposition disposition) { |
102 InfoBarService::WebContentsFromInfoBar(infobar()) | 65 InfoBarService::WebContentsFromInfoBar(infobar()) |
103 ->OpenURL(content::OpenURLParams( | 66 ->OpenURL(content::OpenURLParams( |
104 GURL(chrome::kEnhancedPlaybackNotificationLearnMoreURL), | 67 GURL(chrome::kEnhancedPlaybackNotificationLearnMoreURL), |
105 content::Referrer(), | 68 content::Referrer(), |
106 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, | 69 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, |
107 ui::PAGE_TRANSITION_LINK, false)); | 70 ui::PAGE_TRANSITION_LINK, false)); |
108 return false; // Do not dismiss the info bar. | 71 return false; // Do not dismiss the info bar. |
109 } | 72 } |
OLD | NEW |