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