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
|
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/permissions/contexts/midi_permission_context.h"
#include "components/content_settings/browser/page_specific_content_settings.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "components/permissions/features.h"
#include "components/permissions/permission_request_id.h"
#include "components/permissions/permissions_client.h"
#include "content/public/browser/child_process_security_policy.h"
#include "third_party/blink/public/mojom/permissions_policy/permissions_policy_feature.mojom.h"
#include "url/gurl.h"
namespace permissions {
MidiPermissionContext::MidiPermissionContext(
content::BrowserContext* browser_context)
: PermissionContextBase(
browser_context,
ContentSettingsType::MIDI,
blink::mojom::PermissionsPolicyFeature::kMidiFeature),
host_content_settings_map_(
permissions::PermissionsClient::Get()->GetSettingsMap(
browser_context)) {
if (base::FeatureList::IsEnabled(
permissions::features::kBlockMidiByDefault)) {
content_setting_observer_registered_by_subclass_ = true;
host_content_settings_map_->AddObserver(this);
}
}
MidiPermissionContext::~MidiPermissionContext() {
if (base::FeatureList::IsEnabled(
permissions::features::kBlockMidiByDefault)) {
host_content_settings_map_->RemoveObserver(this);
}
}
ContentSetting MidiPermissionContext::GetPermissionStatusInternal(
content::RenderFrameHost* render_frame_host,
const GURL& requesting_origin,
const GURL& embedding_origin) const {
if (base::FeatureList::IsEnabled(features::kBlockMidiByDefault)) {
return PermissionContextBase::GetPermissionStatusInternal(
render_frame_host, requesting_origin, embedding_origin);
}
return CONTENT_SETTING_ALLOW;
}
void MidiPermissionContext::OnContentSettingChanged(
const ContentSettingsPattern& primary_pattern,
const ContentSettingsPattern& secondary_pattern,
ContentSettingsTypeSet content_type_set) {
PermissionContextBase::OnContentSettingChanged(
primary_pattern, secondary_pattern, content_type_set);
// Synchronize the MIDI SysEx permission
if (base::FeatureList::IsEnabled(
permissions::features::kBlockMidiByDefault)) {
if (content_type_set.Contains(ContentSettingsType::MIDI)) {
// TODO(crbug.com/1078272): We should not need to deduce the url from
// the primary pattern here. Modify the infrastructure to facilitate
// this particular use case better.
const GURL url(primary_pattern.ToString());
if (!url::Origin::Create(url).opaque()) {
const ContentSetting midi_setting =
host_content_settings_map_->GetContentSetting(
url, url, ContentSettingsType::MIDI);
const ContentSetting midi_sysex_setting =
host_content_settings_map_->GetContentSetting(
url, url, ContentSettingsType::MIDI_SYSEX);
switch (midi_setting) {
case CONTENT_SETTING_BLOCK:
if (midi_sysex_setting != CONTENT_SETTING_BLOCK) {
host_content_settings_map_->SetContentSettingCustomScope(
primary_pattern, secondary_pattern,
ContentSettingsType::MIDI_SYSEX, CONTENT_SETTING_BLOCK);
}
break;
case CONTENT_SETTING_ASK:
if (midi_sysex_setting != CONTENT_SETTING_ASK) {
host_content_settings_map_->SetContentSettingCustomScope(
primary_pattern, secondary_pattern,
ContentSettingsType::MIDI_SYSEX, CONTENT_SETTING_ASK);
}
break;
case CONTENT_SETTING_ALLOW:
if (midi_sysex_setting != CONTENT_SETTING_ASK &&
midi_sysex_setting != CONTENT_SETTING_ALLOW) {
host_content_settings_map_->SetContentSettingCustomScope(
primary_pattern, secondary_pattern,
ContentSettingsType::MIDI_SYSEX, CONTENT_SETTING_ASK);
}
break;
default:
break;
}
}
}
}
}
void MidiPermissionContext::UpdateTabContext(const PermissionRequestID& id,
const GURL& requesting_frame,
bool allowed) {
if (base::FeatureList::IsEnabled(
permissions::features::kBlockMidiByDefault)) {
content_settings::PageSpecificContentSettings* content_settings =
content_settings::PageSpecificContentSettings::GetForFrame(
id.global_render_frame_host_id());
if (!content_settings) {
return;
}
if (allowed) {
content_settings->OnContentAllowed(ContentSettingsType::MIDI);
content::ChildProcessSecurityPolicy::GetInstance()->GrantSendMidiMessage(
id.global_render_frame_host_id().child_id);
} else {
content_settings->OnContentBlocked(ContentSettingsType::MIDI);
}
}
}
} // namespace permissions
|