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