Fire an error if a pref used in the UI is missing once all prefs are fetched.
[chromium-blink-merge.git] / chrome / browser / media / protected_media_identifier_infobar_delegate.cc
blob33af2ddacc4c8dffcda42d8e0d5d40cea8c0d5ba
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/grit/generated_resources.h"
10 #include "components/infobars/core/infobar.h"
11 #include "content/public/browser/navigation_entry.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"
17 #if defined(OS_ANDROID)
18 #include "chrome/browser/android/chromium_application.h"
19 #endif
21 #if defined(OS_CHROMEOS)
22 #include "chrome/common/url_constants.h"
23 #endif
25 // static
26 infobars::InfoBar* ProtectedMediaIdentifierInfoBarDelegate::Create(
27 InfoBarService* infobar_service,
28 PermissionQueueController* controller,
29 const PermissionRequestID& id,
30 const GURL& requesting_frame,
31 const std::string& display_languages) {
32 const content::NavigationEntry* committed_entry =
33 infobar_service->web_contents()->GetController().GetLastCommittedEntry();
34 return infobar_service->AddInfoBar(
35 infobar_service->CreateConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate>(
36 new ProtectedMediaIdentifierInfoBarDelegate(
37 controller, id, requesting_frame,
38 committed_entry ? committed_entry->GetUniqueID() : 0,
39 display_languages))));
43 ProtectedMediaIdentifierInfoBarDelegate::
44 ProtectedMediaIdentifierInfoBarDelegate(
45 PermissionQueueController* controller,
46 const PermissionRequestID& id,
47 const GURL& requesting_frame,
48 int contents_unique_id,
49 const std::string& display_languages)
50 : ConfirmInfoBarDelegate(),
51 controller_(controller),
52 id_(id),
53 requesting_frame_(requesting_frame),
54 contents_unique_id_(contents_unique_id),
55 display_languages_(display_languages) {
58 ProtectedMediaIdentifierInfoBarDelegate::
59 ~ProtectedMediaIdentifierInfoBarDelegate() {
62 bool ProtectedMediaIdentifierInfoBarDelegate::Accept() {
63 SetPermission(true, true);
64 return true;
67 void ProtectedMediaIdentifierInfoBarDelegate::SetPermission(
68 bool update_content_setting,
69 bool allowed) {
70 content::WebContents* web_contents =
71 InfoBarService::WebContentsFromInfoBar(infobar());
72 controller_->OnPermissionSet(id_, requesting_frame_,
73 web_contents->GetLastCommittedURL().GetOrigin(),
74 update_content_setting, allowed);
77 infobars::InfoBarDelegate::Type
78 ProtectedMediaIdentifierInfoBarDelegate::GetInfoBarType() const {
79 return PAGE_ACTION_TYPE;
82 int ProtectedMediaIdentifierInfoBarDelegate::GetIconID() const {
83 return IDR_INFOBAR_PROTECTED_MEDIA_IDENTIFIER;
86 void ProtectedMediaIdentifierInfoBarDelegate::InfoBarDismissed() {
87 SetPermission(false, false);
90 bool ProtectedMediaIdentifierInfoBarDelegate::ShouldExpireInternal(
91 const NavigationDetails& details) const {
92 // This implementation matches InfoBarDelegate::ShouldExpireInternal(), but
93 // uses the unique ID we set in the constructor instead of that stored in the
94 // base class.
95 return (contents_unique_id_ != details.entry_id) || details.is_reload;
98 base::string16 ProtectedMediaIdentifierInfoBarDelegate::GetMessageText() const {
99 return l10n_util::GetStringFUTF16(
100 IDS_PROTECTED_MEDIA_IDENTIFIER_INFOBAR_QUESTION,
101 net::FormatUrl(requesting_frame_.GetOrigin(), display_languages_));
104 base::string16 ProtectedMediaIdentifierInfoBarDelegate::GetButtonLabel(
105 InfoBarButton button) const {
106 return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
107 IDS_PROTECTED_MEDIA_IDENTIFIER_ALLOW_BUTTON :
108 IDS_PROTECTED_MEDIA_IDENTIFIER_DENY_BUTTON);
111 bool ProtectedMediaIdentifierInfoBarDelegate::Cancel() {
112 SetPermission(true, false);
113 return true;
116 base::string16 ProtectedMediaIdentifierInfoBarDelegate::GetLinkText() const {
117 #if defined(OS_ANDROID)
118 return l10n_util::GetStringUTF16(
119 IDS_PROTECTED_MEDIA_IDENTIFIER_SETTINGS_LINK);
120 #else
121 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
122 #endif
125 bool ProtectedMediaIdentifierInfoBarDelegate::LinkClicked(
126 WindowOpenDisposition disposition) {
127 #if defined(OS_ANDROID)
128 chrome::android::ChromiumApplication::OpenProtectedContentSettings();
129 #elif defined(OS_CHROMEOS)
130 const GURL learn_more_url(chrome::kEnhancedPlaybackNotificationLearnMoreURL);
131 InfoBarService::WebContentsFromInfoBar(infobar())
132 ->OpenURL(content::OpenURLParams(
133 learn_more_url, content::Referrer(),
134 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition,
135 ui::PAGE_TRANSITION_LINK, false));
136 #else
137 NOTIMPLEMENTED();
138 #endif
139 return false; // Do not dismiss the info bar.