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); | |
37 LOG(ERROR) << "Thread ID: " << tid; | |
Bernhard Bauer
2013/08/01 08:21:27
Remove this log statement before committing.
Takashi Toyoshima
2013/08/01 09:29:45
Oops. Sorry, I added this to confirm the thread id
| |
38 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { | |
39 content::BrowserThread::PostTask( | |
40 content::BrowserThread::UI, FROM_HERE, | |
41 base::Bind(&ChromeMIDIPermissionContext::RequestMIDISysExPermission, | |
42 this, | |
43 render_process_id, | |
44 render_view_id, | |
45 requesting_frame, | |
46 callback)); | |
47 return; | |
48 } | |
49 | |
50 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
51 if (shutting_down_) | |
52 return; | |
53 | |
54 // TODO(toyoshim): Support Extension's manifest declared permission. | |
55 // http://crbug.com/266338 . | |
56 | |
57 content::WebContents* web_contents = | |
58 tab_util::GetWebContentsByID(render_process_id, render_view_id); | |
59 | |
60 // The page doesn't exist any more. | |
61 if (!web_contents) | |
62 return; | |
63 | |
64 const PermissionRequestID id(render_process_id, render_view_id, 0); | |
65 | |
66 GURL embedder = web_contents->GetURL(); | |
67 if (!requesting_frame.is_valid() || !embedder.is_valid()) { | |
68 LOG(WARNING) << "Attempt to use MIDI sysex from an invalid URL: " | |
69 << requesting_frame << "," << embedder | |
70 << " (Web MIDI is not supported in popups)"; | |
71 PermissionDecided(id, requesting_frame, embedder, callback, false); | |
72 return; | |
73 } | |
74 | |
75 DecidePermission(id, requesting_frame, embedder, callback); | |
76 } | |
77 | |
78 void ChromeMIDIPermissionContext::DecidePermission( | |
79 const PermissionRequestID& id, | |
80 const GURL& requesting_frame, | |
81 const GURL& embedder, | |
82 const content::BrowserContext::MIDISysExPermissionCallback& callback) { | |
83 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
84 | |
85 ContentSetting content_setting = | |
86 profile_->GetHostContentSettingsMap()->GetContentSetting( | |
87 requesting_frame, | |
88 embedder, | |
89 CONTENT_SETTINGS_TYPE_MIDI_SYSEX, | |
90 std::string()); | |
91 switch (content_setting) { | |
92 case CONTENT_SETTING_BLOCK: | |
93 PermissionDecided(id, requesting_frame, embedder, callback, false); | |
94 break; | |
95 case CONTENT_SETTING_ALLOW: | |
96 PermissionDecided(id, requesting_frame, embedder, callback, true); | |
97 break; | |
98 default: | |
99 GetQueueController()->CreateInfoBarRequest( | |
100 id, requesting_frame, embedder, base::Bind( | |
101 &ChromeMIDIPermissionContext::NotifyPermissionSet, | |
102 base::Unretained(this), id, requesting_frame, callback)); | |
103 } | |
104 } | |
105 | |
106 void ChromeMIDIPermissionContext::ShutdownOnUIThread() { | |
107 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
108 permission_queue_controller_.reset(); | |
109 shutting_down_ = true; | |
110 } | |
111 | |
112 void ChromeMIDIPermissionContext::PermissionDecided( | |
113 const PermissionRequestID& id, | |
114 const GURL& requesting_frame, | |
115 const GURL& embedder, | |
116 const content::BrowserContext::MIDISysExPermissionCallback& callback, | |
117 bool allowed) { | |
118 NotifyPermissionSet(id, requesting_frame, callback, allowed); | |
119 } | |
120 | |
121 void ChromeMIDIPermissionContext::NotifyPermissionSet( | |
122 const PermissionRequestID& id, | |
123 const GURL& requesting_frame, | |
124 const content::BrowserContext::MIDISysExPermissionCallback& callback, | |
125 bool allowed) { | |
126 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
127 | |
128 TabSpecificContentSettings* content_settings = | |
129 TabSpecificContentSettings::Get(id.render_process_id(), | |
130 id.render_view_id()); | |
131 if (content_settings) { | |
132 if (allowed) | |
133 content_settings->OnMIDISysExAccessed(requesting_frame); | |
134 else | |
135 content_settings->OnMIDISysExAccessBlocked(requesting_frame); | |
136 } | |
137 | |
138 callback.Run(allowed); | |
139 } | |
140 | |
141 PermissionQueueController* | |
142 ChromeMIDIPermissionContext::GetQueueController() { | |
143 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
144 DCHECK(!shutting_down_); | |
145 if (!permission_queue_controller_) | |
146 permission_queue_controller_.reset(CreateQueueController()); | |
147 return permission_queue_controller_.get(); | |
148 } | |
149 | |
150 PermissionQueueController* | |
151 ChromeMIDIPermissionContext::CreateQueueController() { | |
152 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
153 return new PermissionQueueController(profile_, | |
154 CONTENT_SETTINGS_TYPE_MIDI_SYSEX); | |
155 } | |
OLD | NEW |