protected_media_identifier_infobar_delegate.cc revision 68043e1e95eeb07d5cae7aca370b26518b0867d6
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. 4 5#include "chrome/browser/media/protected_media_identifier_infobar_delegate.h" 6 7#include "chrome/browser/content_settings/permission_queue_controller.h" 8#include "content/public/browser/navigation_details.h" 9#include "content/public/browser/navigation_entry.h" 10#include "grit/generated_resources.h" 11#include "grit/theme_resources.h" 12#include "net/base/net_util.h" 13#include "ui/base/l10n/l10n_util.h" 14 15// static 16InfoBarDelegate* ProtectedMediaIdentifierInfoBarDelegate::Create( 17 InfoBarService* infobar_service, 18 PermissionQueueController* controller, 19 const PermissionRequestID& id, 20 const GURL& requesting_frame, 21 const std::string& display_languages) { 22 const content::NavigationEntry* committed_entry = 23 infobar_service->web_contents()->GetController().GetLastCommittedEntry(); 24 return infobar_service->AddInfoBar( 25 scoped_ptr<InfoBarDelegate>(new ProtectedMediaIdentifierInfoBarDelegate( 26 infobar_service, 27 controller, 28 id, 29 requesting_frame, 30 committed_entry ? committed_entry->GetUniqueID() : 0, 31 display_languages))); 32} 33 34 35ProtectedMediaIdentifierInfoBarDelegate:: 36 ProtectedMediaIdentifierInfoBarDelegate( 37 InfoBarService* infobar_service, 38 PermissionQueueController* controller, 39 const PermissionRequestID& id, 40 const GURL& requesting_frame, 41 int contents_unique_id, 42 const std::string& display_languages) 43 : ConfirmInfoBarDelegate(infobar_service), 44 controller_(controller), 45 id_(id), 46 requesting_frame_(requesting_frame), 47 contents_unique_id_(contents_unique_id), 48 display_languages_(display_languages) {} 49 50ProtectedMediaIdentifierInfoBarDelegate:: 51 ~ProtectedMediaIdentifierInfoBarDelegate() {} 52 53bool ProtectedMediaIdentifierInfoBarDelegate::Accept() { 54 SetPermission(true, true); 55 return true; 56} 57 58void ProtectedMediaIdentifierInfoBarDelegate::SetPermission( 59 bool update_content_setting, 60 bool allowed) { 61 controller_->OnPermissionSet(id_, 62 requesting_frame_, 63 web_contents()->GetLastCommittedURL(), 64 update_content_setting, 65 allowed); 66} 67 68void ProtectedMediaIdentifierInfoBarDelegate::InfoBarDismissed() { 69 SetPermission(false, false); 70} 71 72int ProtectedMediaIdentifierInfoBarDelegate::GetIconID() const { 73 return IDR_PROTECTED_MEDIA_IDENTIFIER_INFOBAR_ICON; 74} 75 76InfoBarDelegate::Type ProtectedMediaIdentifierInfoBarDelegate::GetInfoBarType() 77 const { 78 return PAGE_ACTION_TYPE; 79} 80 81bool ProtectedMediaIdentifierInfoBarDelegate::ShouldExpireInternal( 82 const content::LoadCommittedDetails& details) const { 83 // This implementation matches InfoBarDelegate::ShouldExpireInternal(), but 84 // uses the unique ID we set in the constructor instead of that stored in the 85 // base class. 86 return (contents_unique_id_ != details.entry->GetUniqueID()) || 87 (content::PageTransitionStripQualifier( 88 details.entry->GetTransitionType()) == 89 content::PAGE_TRANSITION_RELOAD); 90} 91 92string16 ProtectedMediaIdentifierInfoBarDelegate::GetMessageText() const { 93 return l10n_util::GetStringFUTF16( 94 IDS_PROTECTED_MEDIA_IDENTIFIER_INFOBAR_QUESTION, 95 net::FormatUrl(requesting_frame_.GetOrigin(), display_languages_)); 96} 97 98string16 ProtectedMediaIdentifierInfoBarDelegate::GetButtonLabel( 99 InfoBarButton button) const { 100 return l10n_util::GetStringUTF16( 101 (button == BUTTON_OK) ? IDS_PROTECTED_MEDIA_IDENTIFIER_ALLOW_BUTTON 102 : IDS_PROTECTED_MEDIA_IDENTIFIER_DENY_BUTTON); 103} 104 105bool ProtectedMediaIdentifierInfoBarDelegate::Cancel() { 106 SetPermission(true, false); 107 return true; 108} 109