Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / media / midi_permission_infobar_delegate.cc
blob9226a050df741731cc4046d677d18a39960db3e8
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/midi_permission_infobar_delegate.h"
7 #include "chrome/browser/content_settings/permission_queue_controller.h"
8 #include "chrome/browser/content_settings/permission_request_id.h"
9 #include "chrome/browser/infobars/infobar.h"
10 #include "chrome/browser/infobars/infobar_service.h"
11 #include "content/public/browser/navigation_details.h"
12 #include "content/public/browser/navigation_entry.h"
13 #include "content/public/browser/web_contents.h"
14 #include "grit/generated_resources.h"
15 #include "grit/locale_settings.h"
16 #include "grit/theme_resources.h"
17 #include "net/base/net_util.h"
18 #include "ui/base/l10n/l10n_util.h"
20 // static
21 InfoBar* MIDIPermissionInfoBarDelegate::Create(
22 InfoBarService* infobar_service,
23 PermissionQueueController* controller,
24 const PermissionRequestID& id,
25 const GURL& requesting_frame,
26 const std::string& display_languages) {
27 const content::NavigationEntry* committed_entry =
28 infobar_service->web_contents()->GetController().GetLastCommittedEntry();
29 return infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar(
30 scoped_ptr<ConfirmInfoBarDelegate>(new MIDIPermissionInfoBarDelegate(
31 controller, id, requesting_frame,
32 committed_entry ? committed_entry->GetUniqueID() : 0,
33 display_languages))));
36 MIDIPermissionInfoBarDelegate::MIDIPermissionInfoBarDelegate(
37 PermissionQueueController* controller,
38 const PermissionRequestID& id,
39 const GURL& requesting_frame,
40 int contents_unique_id,
41 const std::string& display_languages)
42 : ConfirmInfoBarDelegate(),
43 controller_(controller),
44 id_(id),
45 requesting_frame_(requesting_frame),
46 contents_unique_id_(contents_unique_id),
47 display_languages_(display_languages) {
50 MIDIPermissionInfoBarDelegate::~MIDIPermissionInfoBarDelegate() {
53 void MIDIPermissionInfoBarDelegate::InfoBarDismissed() {
54 SetPermission(false, false);
57 int MIDIPermissionInfoBarDelegate::GetIconID() const {
58 return IDR_INFOBAR_MIDI_SYSEX;
61 InfoBarDelegate::Type MIDIPermissionInfoBarDelegate::GetInfoBarType() const {
62 return PAGE_ACTION_TYPE;
65 bool MIDIPermissionInfoBarDelegate::ShouldExpireInternal(
66 const content::LoadCommittedDetails& details) const {
67 // This implementation matches InfoBarDelegate::ShouldExpireInternal(), but
68 // uses the unique ID we set in the constructor instead of that stored in the
69 // base class.
70 return (contents_unique_id_ != details.entry->GetUniqueID()) ||
71 (content::PageTransitionStripQualifier(
72 details.entry->GetTransitionType()) ==
73 content::PAGE_TRANSITION_RELOAD);
76 base::string16 MIDIPermissionInfoBarDelegate::GetMessageText() const {
77 return l10n_util::GetStringFUTF16(
78 IDS_MIDI_SYSEX_INFOBAR_QUESTION,
79 net::FormatUrl(requesting_frame_.GetOrigin(), display_languages_));
82 base::string16 MIDIPermissionInfoBarDelegate::GetButtonLabel(
83 InfoBarButton button) const {
84 return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
85 IDS_MIDI_SYSEX_ALLOW_BUTTON : IDS_MIDI_SYSEX_DENY_BUTTON);
88 bool MIDIPermissionInfoBarDelegate::Accept() {
89 SetPermission(true, true);
90 return true;
93 bool MIDIPermissionInfoBarDelegate::Cancel() {
94 SetPermission(true, false);
95 return true;
98 void MIDIPermissionInfoBarDelegate::SetPermission(bool update_content_setting,
99 bool allowed) {
100 controller_->OnPermissionSet(id_, requesting_frame_, web_contents()->GetURL(),
101 update_content_setting, allowed);