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