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