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/chrome_midi_permission_context.h" |
| 6 |
| 7 #include "base/prefs/pref_service.h" |
| 8 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 9 #include "chrome/browser/content_settings/permission_queue_controller.h" |
| 10 #include "chrome/browser/content_settings/permission_request_id.h" |
| 11 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/tab_contents/tab_util.h" |
| 14 #include "content/public/browser/browser_thread.h" |
| 15 #include "content/public/browser/web_contents.h" |
| 16 |
| 17 ChromeMIDIPermissionContext::ChromeMIDIPermissionContext(Profile* profile) |
| 18 : profile_(profile), |
| 19 shutting_down_(false) { |
| 20 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 21 } |
| 22 |
| 23 ChromeMIDIPermissionContext::~ChromeMIDIPermissionContext() { |
| 24 DCHECK(!permission_queue_controller_); |
| 25 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 26 } |
| 27 |
| 28 void ChromeMIDIPermissionContext::Shutdown() { |
| 29 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 30 permission_queue_controller_.reset(); |
| 31 shutting_down_ = true; |
| 32 } |
| 33 |
| 34 void ChromeMIDIPermissionContext::RequestMIDISysExPermission( |
| 35 int render_process_id, |
| 36 int render_view_id, |
| 37 const GURL& requesting_frame, |
| 38 const content::BrowserContext::MIDISysExPermissionCallback& callback) { |
| 39 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 40 DCHECK(!shutting_down_); |
| 41 |
| 42 // TODO(toyoshim): Support Extension's manifest declared permission. |
| 43 // http://crbug.com/266338 . |
| 44 |
| 45 content::WebContents* web_contents = |
| 46 tab_util::GetWebContentsByID(render_process_id, render_view_id); |
| 47 |
| 48 // The page doesn't exist any more. |
| 49 if (!web_contents) |
| 50 return; |
| 51 |
| 52 const PermissionRequestID id(render_process_id, render_view_id, 0); |
| 53 |
| 54 GURL embedder = web_contents->GetURL(); |
| 55 if (!requesting_frame.is_valid() || !embedder.is_valid()) { |
| 56 LOG(WARNING) << "Attempt to use MIDI sysex from an invalid URL: " |
| 57 << requesting_frame << "," << embedder |
| 58 << " (Web MIDI is not supported in popups)"; |
| 59 PermissionDecided(id, requesting_frame, embedder, callback, false); |
| 60 return; |
| 61 } |
| 62 |
| 63 DecidePermission(id, requesting_frame, embedder, callback); |
| 64 } |
| 65 |
| 66 void ChromeMIDIPermissionContext::DecidePermission( |
| 67 const PermissionRequestID& id, |
| 68 const GURL& requesting_frame, |
| 69 const GURL& embedder, |
| 70 const content::BrowserContext::MIDISysExPermissionCallback& callback) { |
| 71 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 72 |
| 73 ContentSetting content_setting = |
| 74 profile_->GetHostContentSettingsMap()->GetContentSetting( |
| 75 requesting_frame, |
| 76 embedder, |
| 77 CONTENT_SETTINGS_TYPE_MIDI_SYSEX, |
| 78 std::string()); |
| 79 switch (content_setting) { |
| 80 case CONTENT_SETTING_BLOCK: |
| 81 PermissionDecided(id, requesting_frame, embedder, callback, false); |
| 82 break; |
| 83 case CONTENT_SETTING_ALLOW: |
| 84 PermissionDecided(id, requesting_frame, embedder, callback, true); |
| 85 break; |
| 86 default: |
| 87 GetQueueController()->CreateInfoBarRequest( |
| 88 id, requesting_frame, embedder, base::Bind( |
| 89 &ChromeMIDIPermissionContext::NotifyPermissionSet, |
| 90 base::Unretained(this), id, requesting_frame, callback)); |
| 91 } |
| 92 } |
| 93 |
| 94 void ChromeMIDIPermissionContext::PermissionDecided( |
| 95 const PermissionRequestID& id, |
| 96 const GURL& requesting_frame, |
| 97 const GURL& embedder, |
| 98 const content::BrowserContext::MIDISysExPermissionCallback& callback, |
| 99 bool allowed) { |
| 100 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 101 NotifyPermissionSet(id, requesting_frame, callback, allowed); |
| 102 } |
| 103 |
| 104 void ChromeMIDIPermissionContext::NotifyPermissionSet( |
| 105 const PermissionRequestID& id, |
| 106 const GURL& requesting_frame, |
| 107 const content::BrowserContext::MIDISysExPermissionCallback& callback, |
| 108 bool allowed) { |
| 109 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 110 |
| 111 TabSpecificContentSettings* content_settings = |
| 112 TabSpecificContentSettings::Get(id.render_process_id(), |
| 113 id.render_view_id()); |
| 114 if (content_settings) { |
| 115 if (allowed) |
| 116 content_settings->OnMIDISysExAccessed(requesting_frame); |
| 117 else |
| 118 content_settings->OnMIDISysExAccessBlocked(requesting_frame); |
| 119 } |
| 120 |
| 121 callback.Run(allowed); |
| 122 } |
| 123 |
| 124 PermissionQueueController* ChromeMIDIPermissionContext::GetQueueController() { |
| 125 if (!permission_queue_controller_) { |
| 126 permission_queue_controller_.reset( |
| 127 new PermissionQueueController(profile_, |
| 128 CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); |
| 129 } |
| 130 return permission_queue_controller_.get(); |
| 131 } |
OLD | NEW |