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