Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: chrome/browser/media/chrome_midi_permission_context.cc

Issue 20990005: Web MIDI: implement permission infobar (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: disable icon for now Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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_.get());
Bernhard Bauer 2013/07/31 15:35:39 You can leave out the .get(); scoped_ptr has an im
Takashi Toyoshima 2013/08/01 07:43:09 Done.
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 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) {
Bernhard Bauer 2013/07/31 15:35:39 I'm not a big fan of this construct. The calling c
Takashi Toyoshima 2013/08/01 07:43:09 No. This function is always called from *IO* threa
Bernhard Bauer 2013/08/01 08:21:27 Uhh... Isn't this called from (OffTheRecord)Profil
Takashi Toyoshima 2013/08/01 09:29:45 The caller code is introduced in this change. Plea
Bernhard Bauer 2013/08/01 11:14:02 Yes, but who calls BrowserContext::RequestMIDISysE
36 content::BrowserThread::PostTask(
37 content::BrowserThread::UI, FROM_HERE,
38 base::Bind(&ChromeMIDIPermissionContext::RequestMIDISysExPermission,
39 this,
40 render_process_id,
41 render_view_id,
42 requesting_frame,
43 callback));
44 return;
45 }
46
47 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
48 if (shutting_down_)
49 return;
50
51 // TODO(toyoshim): Support Extension's manifest declared permission.
52 // http://crbug.com/266338 .
53
54 content::WebContents* web_contents =
55 tab_util::GetWebContentsByID(render_process_id, render_view_id);
56
57 // The page doesn't exist any more.
58 if (!web_contents)
59 return;
60
61 const PermissionRequestID id(render_process_id, render_view_id, 0);
62
63 GURL embedder = web_contents->GetURL();
64 if (!requesting_frame.is_valid() || !embedder.is_valid()) {
65 LOG(WARNING) << "Attempt to use MIDI sysex from an invalid URL: "
66 << requesting_frame << "," << embedder
67 << " (Web MIDI is not supported in popups)";
68 PermissionDecided(id, requesting_frame, embedder, callback, false);
69 return;
70 }
71
72 DecidePermission(id, requesting_frame, embedder, callback);
73 }
74
75 void ChromeMIDIPermissionContext::DecidePermission(
76 const PermissionRequestID& id,
77 const GURL& requesting_frame,
78 const GURL& embedder,
79 const content::BrowserContext::MIDISysExPermissionCallback& callback) {
80 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
81
82 ContentSetting content_setting =
83 profile_->GetHostContentSettingsMap()->GetContentSetting(
84 requesting_frame,
85 embedder,
86 CONTENT_SETTINGS_TYPE_MIDI_SYSEX,
87 std::string());
88 switch (content_setting) {
89 case CONTENT_SETTING_BLOCK:
90 PermissionDecided(id, requesting_frame, embedder, callback, false);
91 break;
92 case CONTENT_SETTING_ALLOW:
93 PermissionDecided(id, requesting_frame, embedder, callback, true);
94 break;
95 default:
96 QueueController()->CreateInfoBarRequest(
97 id, requesting_frame, embedder, base::Bind(
98 &ChromeMIDIPermissionContext::NotifyPermissionSet,
99 base::Unretained(this), id, requesting_frame, callback));
100 }
101 }
102
103 void ChromeMIDIPermissionContext::ShutdownOnUIThread() {
104 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
105 permission_queue_controller_.reset();
106 shutting_down_ = true;
107 }
108
109 void ChromeMIDIPermissionContext::PermissionDecided(
110 const PermissionRequestID& id,
111 const GURL& requesting_frame,
112 const GURL& embedder,
113 const content::BrowserContext::MIDISysExPermissionCallback& callback,
114 bool allowed) {
115 NotifyPermissionSet(id, requesting_frame, callback, allowed);
116 }
117
118 void ChromeMIDIPermissionContext::NotifyPermissionSet(
119 const PermissionRequestID& id,
120 const GURL& requesting_frame,
121 const content::BrowserContext::MIDISysExPermissionCallback& callback,
122 bool allowed) {
123 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
124
125 TabSpecificContentSettings* content_settings =
126 TabSpecificContentSettings::Get(id.render_process_id(),
127 id.render_view_id());
128 if (content_settings) {
129 if (allowed)
130 content_settings->OnMIDISysExAccessed(requesting_frame);
131 else
132 content_settings->OnMIDISysExAccessBlocked(requesting_frame);
133 }
134
135 callback.Run(allowed);
136 }
137
138 PermissionQueueController*
139 ChromeMIDIPermissionContext::QueueController() {
140 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
141 DCHECK(!shutting_down_);
142 if (!permission_queue_controller_)
143 permission_queue_controller_.reset(CreateQueueController());
144 return permission_queue_controller_.get();
145 }
146
147 PermissionQueueController*
148 ChromeMIDIPermissionContext::CreateQueueController() {
149 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
150 return new PermissionQueueController(profile(),
151 CONTENT_SETTINGS_TYPE_MIDI_SYSEX);
152 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698