Commit 7e0371b6 authored by Reilly Grant's avatar Reilly Grant Committed by Commit Bot

[serial] Show serial port permissions in site settings

This change displays serial port permissions the user has granted to
sites in chrome://settings/content/serialPorts.

Bug: 908836
Change-Id: I49570dc785d6de395160ffbb4541e7203cda9357
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1453363
Commit-Queue: Reilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarDan Beam <dbeam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#644436}
parent 66b27048
...@@ -2984,6 +2984,18 @@ ...@@ -2984,6 +2984,18 @@
<message name="IDS_SETTINGS_SITE_SETTINGS_USB_DEVICES_BLOCK" desc="The block label for USB devices in site settings."> <message name="IDS_SETTINGS_SITE_SETTINGS_USB_DEVICES_BLOCK" desc="The block label for USB devices in site settings.">
Do not allow any sites to access USB devices Do not allow any sites to access USB devices
</message> </message>
<message name="IDS_SETTINGS_SITE_SETTINGS_SERIAL_PORTS" desc="Label for serial ports in site settings.">
Serial ports
</message>
<message name="IDS_SETTINGS_SITE_SETTINGS_SERIAL_PORTS_ASK" desc="The ask label for serial ports in site settings.">
Ask when a site wants to access serial ports
</message>
<message name="IDS_SETTINGS_SITE_SETTINGS_SERIAL_PORTS_ASK_RECOMMENDED" desc="The ask label for serial ports in site settings (with the 'recommended' suffix).">
Ask when a site wants to access serial ports (recommended)
</message>
<message name="IDS_SETTINGS_SITE_SETTINGS_SERIAL_PORTS_BLOCK" desc="The block label for serial ports in site settings.">
Do not allow any sites to access serial ports
</message>
<message name="IDS_SETTINGS_SITE_SETTINGS_REMOVE_ZOOM_LEVEL" desc="Title tooltip and accessibility text for the button to remove zoom levels in site settings"> <message name="IDS_SETTINGS_SITE_SETTINGS_REMOVE_ZOOM_LEVEL" desc="Title tooltip and accessibility text for the button to remove zoom levels in site settings">
Remove zoom level Remove zoom level
</message> </message>
...@@ -3301,6 +3313,9 @@ ...@@ -3301,6 +3313,9 @@
<message name="IDS_SETTINGS_NO_USB_DEVICES_FOUND" desc="Explanation for not showing USB devices in site settings."> <message name="IDS_SETTINGS_NO_USB_DEVICES_FOUND" desc="Explanation for not showing USB devices in site settings.">
No USB devices found No USB devices found
</message> </message>
<message name="IDS_SETTINGS_NO_SERIAL_PORTS_FOUND" desc="Explanation for not showing serial ports in site settings.">
No serial ports found
</message>
<message name="IDS_SETTINGS_ADD_SITE_EXCEPTION_PLACEHOLDER" desc="Placeholder text shown before the user starts typing a new content settings exception for a site." > <message name="IDS_SETTINGS_ADD_SITE_EXCEPTION_PLACEHOLDER" desc="Placeholder text shown before the user starts typing a new content settings exception for a site." >
[*.]example.com [*.]example.com
</message> </message>
......
...@@ -120,6 +120,7 @@ List icons here rather than importing large sets of (e.g. Polymer) icons. ...@@ -120,6 +120,7 @@ List icons here rather than importing large sets of (e.g. Polymer) icons.
<g id="restore"><path d="M13 3c-4.97 0-9 4.03-9 9H1l3.89 3.89.07.14L9 12H6c0-3.87 3.13-7 7-7s7 3.13 7 7-3.13 7-7 7c-1.93 0-3.68-.79-4.94-2.06l-1.42 1.42C8.27 19.99 10.51 21 13 21c4.97 0 9-4.03 9-9s-4.03-9-9-9zm-1 5v5l4.28 2.54.72-1.21-3.5-2.08V8H12z"></path></g> <g id="restore"><path d="M13 3c-4.97 0-9 4.03-9 9H1l3.89 3.89.07.14L9 12H6c0-3.87 3.13-7 7-7s7 3.13 7 7-3.13 7-7 7c-1.93 0-3.68-.79-4.94-2.06l-1.42 1.42C8.27 19.99 10.51 21 13 21c4.97 0 9-4.03 9-9s-4.03-9-9-9zm-1 5v5l4.28 2.54.72-1.21-3.5-2.08V8H12z"></path></g>
<g id="rotate-right"><path d="M15.55 5.55L11 1v3.07C7.06 4.56 4 7.92 4 12s3.05 7.44 7 7.93v-2.02c-2.84-.48-5-2.94-5-5.91s2.16-5.43 5-5.91V10l4.55-4.45zM19.93 11c-.17-1.39-.72-2.73-1.62-3.89l-1.42 1.42c.54.75.88 1.6 1.02 2.47h2.02zM13 17.9v2.02c1.39-.17 2.74-.71 3.9-1.61l-1.44-1.44c-.75.54-1.59.89-2.46 1.03zm3.89-2.42l1.42 1.41c.9-1.16 1.45-2.5 1.62-3.89h-2.02c-.14.87-.48 1.72-1.02 2.48z"></path></g> <g id="rotate-right"><path d="M15.55 5.55L11 1v3.07C7.06 4.56 4 7.92 4 12s3.05 7.44 7 7.93v-2.02c-2.84-.48-5-2.94-5-5.91s2.16-5.43 5-5.91V10l4.55-4.45zM19.93 11c-.17-1.39-.72-2.73-1.62-3.89l-1.42 1.42c.54.75.88 1.6 1.02 2.47h2.02zM13 17.9v2.02c1.39-.17 2.74-.71 3.9-1.61l-1.44-1.44c-.75.54-1.59.89-2.46 1.03zm3.89-2.42l1.42 1.41c.9-1.16 1.45-2.5 1.62-3.89h-2.02c-.14.87-.48 1.72-1.02 2.48z"></path></g>
<g id="sensors"><path d="M10 8.5c-0.8 0-1.5 0.7-1.5 1.5s0.7 1.5 1.5 1.5s1.5-0.7 1.5-1.5S10.8 8.5 10 8.5z M7.6 5.8 C6.2 6.7 5.2 8.2 5.2 10c0 1.8 1 3.4 2.4 4.2l0.8-1.4c-1-0.6-1.6-1.6-1.6-2.8c0-1.2 0.6-2.2 1.6-2.8L7.6 5.8z M14.8 10 c0-1.8-1-3.4-2.4-4.2l-0.8 1.4c0.9 0.6 1.6 1.6 1.6 2.8c0 1.2-0.6 2.2-1.6 2.8l0.8 1.4C13.8 13.4 14.8 11.8 14.8 10z M6 3 c-2.4 1.4-4 4-4 7c0 3 1.6 5.6 4 7l0.8-1.4c-1.9-1.1-3.2-3.2-3.2-5.6c0-2.4 1.3-4.5 3.2-5.6L6 3z M13.2 4.4 c1.9 1.1 3.2 3.2 3.2 5.6c0 2.4-1.3 4.5-3.2 5.6L14 17c2.4-1.4 4-4 4-7c0-3-1.6-5.6-4-7L13.2 4.4z"></path></g> <g id="sensors"><path d="M10 8.5c-0.8 0-1.5 0.7-1.5 1.5s0.7 1.5 1.5 1.5s1.5-0.7 1.5-1.5S10.8 8.5 10 8.5z M7.6 5.8 C6.2 6.7 5.2 8.2 5.2 10c0 1.8 1 3.4 2.4 4.2l0.8-1.4c-1-0.6-1.6-1.6-1.6-2.8c0-1.2 0.6-2.2 1.6-2.8L7.6 5.8z M14.8 10 c0-1.8-1-3.4-2.4-4.2l-0.8 1.4c0.9 0.6 1.6 1.6 1.6 2.8c0 1.2-0.6 2.2-1.6 2.8l0.8 1.4C13.8 13.4 14.8 11.8 14.8 10z M6 3 c-2.4 1.4-4 4-4 7c0 3 1.6 5.6 4 7l0.8-1.4c-1.9-1.1-3.2-3.2-3.2-5.6c0-2.4 1.3-4.5 3.2-5.6L6 3z M13.2 4.4 c1.9 1.1 3.2 3.2 3.2 5.6c0 2.4-1.3 4.5-3.2 5.6L14 17c2.4-1.4 4-4 4-7c0-3-1.6-5.6-4-7L13.2 4.4z"></path></g>
<g id="serial-port"><path stroke="#000" fill="none" stroke-width=".529" d="M1.963 7.039h20.074c.632 0 1.176.836 1 1.443l-2.14 7.339c-.177.606-.51 1.14-1.141 1.14H4.244c-.631 0-.962-.534-1.14-1.14l-2.14-7.3c-.178-.605.367-1.482 1-1.482z"></path><circle r="1.154" cx="4.279" cy="9.882"></circle><circle r="1.154" cx="5.772" cy="14.134"></circle><circle r="1.154" cx="19.892" cy="9.882"></circle><circle r="1.154" cx="15.989" cy="9.882"></circle><circle r="1.154" cx="12.086" cy="9.882"></circle><circle r="1.154" cx="8.183" cy="9.882"></circle><circle r="1.154" cx="9.849" cy="14.134"></circle><circle r="1.154" cx="13.925" cy="14.134"></circle><circle r="1.154" cx="18.002" cy="14.134"></circle></g>
<if expr="chromeos"> <if expr="chromeos">
<g id="alert-device-out-of-range" fill="none" fill-rule="evenodd"><path d="M-1-1h20v20H-1z"></path><path fill="#C53929" fill-rule="nonzero" d="M8.167 11.5h1.666v1.667H8.167V11.5zm0-6.667h1.666v5H8.167v-5zM8.992.667C4.392.667.667 4.4.667 9s3.725 8.333 8.325 8.333c4.608 0 8.341-3.733 8.341-8.333S13.6.667 8.992.667zm.008 15A6.665 6.665 0 0 1 2.333 9 6.665 6.665 0 0 1 9 2.333 6.665 6.665 0 0 1 15.667 9 6.665 6.665 0 0 1 9 15.667z"></path></g> <g id="alert-device-out-of-range" fill="none" fill-rule="evenodd"><path d="M-1-1h20v20H-1z"></path><path fill="#C53929" fill-rule="nonzero" d="M8.167 11.5h1.666v1.667H8.167V11.5zm0-6.667h1.666v5H8.167v-5zM8.992.667C4.392.667.667 4.4.667 9s3.725 8.333 8.325 8.333c4.608 0 8.341-3.733 8.341-8.333S13.6.667 8.992.667zm.008 15A6.665 6.665 0 0 1 2.333 9 6.665 6.665 0 0 1 9 2.333 6.665 6.665 0 0 1 15.667 9 6.665 6.665 0 0 1 9 15.667z"></path></g>
<g id="signal-cellular-0-bar"><path fill-opacity=".3" d="M2 22h20V2z"></path></g> <g id="signal-cellular-0-bar"><path fill-opacity=".3" d="M2 22h20V2z"></path></g>
......
...@@ -547,6 +547,22 @@ ...@@ -547,6 +547,22 @@
</chooser-exception-list> </chooser-exception-list>
</settings-subpage> </settings-subpage>
</template> </template>
<template is="dom-if" if="[[enableExperimentalWebPlatformFeatures_]]">
<template is="dom-if" route-path="/content/serialPorts" no-search>
<settings-subpage page-title="$i18n{siteSettingsSerialPorts}">
<category-default-setting
toggle-off-label="$i18n{siteSettingsSerialPortsBlock}"
toggle-on-label=
"$i18n{siteSettingsSerialPortsAskRecommended}"
category="{{ContentSettingsTypes.SERIAL_PORTS}}">
</category-default-setting>
<chooser-exception-list
category="{{ContentSettingsTypes.SERIAL_PORTS}}"
chooser-type="{{ChooserType.SERIAL_PORTS}}">
</chooser-exception-list>
</settings-subpage>
</template>
</template>
<template is="dom-if" route-path="/content/siteDetails" no-search> <template is="dom-if" route-path="/content/siteDetails" no-search>
<settings-subpage page-title="[[pageTitle]]"> <settings-subpage page-title="[[pageTitle]]">
<site-details <site-details
......
...@@ -135,6 +135,14 @@ Polymer({ ...@@ -135,6 +135,14 @@ Polymer({
} }
}, },
/** @private */
enableExperimentalWebPlatformFeatures_: {
type: Boolean,
value: function() {
return loadTimeData.getBoolean('enableExperimentalWebPlatformFeatures');
},
},
/** @private */ /** @private */
enableSecurityKeysSubpage_: { enableSecurityKeysSubpage_: {
type: Boolean, type: Boolean,
......
...@@ -97,6 +97,7 @@ ...@@ -97,6 +97,7 @@
* SITE_SETTINGS_SITE_DETAILS: (undefined|!settings.Route), * SITE_SETTINGS_SITE_DETAILS: (undefined|!settings.Route),
* SITE_SETTINGS_UNSANDBOXED_PLUGINS: (undefined|!settings.Route), * SITE_SETTINGS_UNSANDBOXED_PLUGINS: (undefined|!settings.Route),
* SITE_SETTINGS_USB_DEVICES: (undefined|!settings.Route), * SITE_SETTINGS_USB_DEVICES: (undefined|!settings.Route),
* SITE_SETTINGS_SERIAL_PORTS: (undefined|!settings.Route),
* SITE_SETTINGS_ZOOM_LEVELS: (undefined|!settings.Route), * SITE_SETTINGS_ZOOM_LEVELS: (undefined|!settings.Route),
* SMART_LOCK: (undefined|!settings.Route), * SMART_LOCK: (undefined|!settings.Route),
* SMB_SHARES: (undefined|!settings.Route), * SMB_SHARES: (undefined|!settings.Route),
...@@ -371,6 +372,10 @@ cr.define('settings', function() { ...@@ -371,6 +372,10 @@ cr.define('settings', function() {
r.SITE_SETTINGS.createChild('unsandboxedPlugins'); r.SITE_SETTINGS.createChild('unsandboxedPlugins');
r.SITE_SETTINGS_MIDI_DEVICES = r.SITE_SETTINGS.createChild('midiDevices'); r.SITE_SETTINGS_MIDI_DEVICES = r.SITE_SETTINGS.createChild('midiDevices');
r.SITE_SETTINGS_USB_DEVICES = r.SITE_SETTINGS.createChild('usbDevices'); r.SITE_SETTINGS_USB_DEVICES = r.SITE_SETTINGS.createChild('usbDevices');
if (loadTimeData.getBoolean('enableExperimentalWebPlatformFeatures')) {
r.SITE_SETTINGS_SERIAL_PORTS =
r.SITE_SETTINGS.createChild('serialPorts');
}
r.SITE_SETTINGS_ZOOM_LEVELS = r.SITE_SETTINGS.createChild('zoomLevels'); r.SITE_SETTINGS_ZOOM_LEVELS = r.SITE_SETTINGS.createChild('zoomLevels');
r.SITE_SETTINGS_PDF_DOCUMENTS = r.SITE_SETTINGS_PDF_DOCUMENTS =
r.SITE_SETTINGS.createChild('pdfDocuments'); r.SITE_SETTINGS.createChild('pdfDocuments');
......
...@@ -124,6 +124,7 @@ Polymer({ ...@@ -124,6 +124,7 @@ Polymer({
case settings.ContentSettingsTypes.UNSANDBOXED_PLUGINS: case settings.ContentSettingsTypes.UNSANDBOXED_PLUGINS:
case settings.ContentSettingsTypes.MIDI_DEVICES: case settings.ContentSettingsTypes.MIDI_DEVICES:
case settings.ContentSettingsTypes.USB_DEVICES: case settings.ContentSettingsTypes.USB_DEVICES:
case settings.ContentSettingsTypes.SERIAL_PORTS:
// "Ask" vs "Blocked". // "Ask" vs "Blocked".
this.browserProxy.setDefaultValueForContentType( this.browserProxy.setDefaultValueForContentType(
this.category, this.category,
......
...@@ -109,6 +109,10 @@ Polymer({ ...@@ -109,6 +109,10 @@ Polymer({
switch (this.chooserType) { switch (this.chooserType) {
case settings.ChooserType.USB_DEVICES: case settings.ChooserType.USB_DEVICES:
this.emptyListMessage_ = this.i18n('noUsbDevicesFound'); this.emptyListMessage_ = this.i18n('noUsbDevicesFound');
break;
case settings.ChooserType.SERIAL_PORTS:
this.emptyListMessage_ = this.i18n('noSerialPortsFound');
break;
default: default:
this.emptyListMessage_ = ''; this.emptyListMessage_ = '';
} }
......
...@@ -29,6 +29,7 @@ settings.ContentSettingsTypes = { ...@@ -29,6 +29,7 @@ settings.ContentSettingsTypes = {
BACKGROUND_SYNC: 'background-sync', BACKGROUND_SYNC: 'background-sync',
MIDI_DEVICES: 'midi-sysex', MIDI_DEVICES: 'midi-sysex',
USB_DEVICES: 'usb-devices', USB_DEVICES: 'usb-devices',
SERIAL_PORTS: 'serial-ports',
ZOOM_LEVELS: 'zoom-levels', ZOOM_LEVELS: 'zoom-levels',
PROTECTED_CONTENT: 'protected-content', PROTECTED_CONTENT: 'protected-content',
ADS: 'ads', ADS: 'ads',
...@@ -61,6 +62,7 @@ settings.ContentSetting = { ...@@ -61,6 +62,7 @@ settings.ContentSetting = {
settings.ChooserType = { settings.ChooserType = {
NONE: '', NONE: '',
USB_DEVICES: 'usb-devices-data', USB_DEVICES: 'usb-devices-data',
SERIAL_PORTS: 'serial-ports-data',
}; };
/** /**
......
...@@ -179,6 +179,13 @@ ...@@ -179,6 +179,13 @@
category="{{ContentSettingsTypes.USB_DEVICES}}" icon="settings:usb" category="{{ContentSettingsTypes.USB_DEVICES}}" icon="settings:usb"
id="usbDevices" label="$i18n{siteSettingsUsbDevices}"> id="usbDevices" label="$i18n{siteSettingsUsbDevices}">
</site-details-permission> </site-details-permission>
<template is="dom-if" if="[[enableExperimentalWebPlatformFeatures_]]">
<site-details-permission
category="{{ContentSettingsTypes.SERIAL_PORTS}}"
icon="settings:serial-port" id="serialPorts"
label="$i18n{siteSettingsSerialPorts}">
</site-details-permission>
</template>
<site-details-permission <site-details-permission
category="{{ContentSettingsTypes.UNSANDBOXED_PLUGINS}}" category="{{ContentSettingsTypes.UNSANDBOXED_PLUGINS}}"
icon="cr:extension" id="unsandboxedPlugins" icon="cr:extension" id="unsandboxedPlugins"
......
...@@ -54,6 +54,14 @@ Polymer({ ...@@ -54,6 +54,14 @@ Polymer({
value: '', value: '',
}, },
/** @private */
enableExperimentalWebPlatformFeatures_: {
type: Boolean,
value: function() {
return loadTimeData.getBoolean('enableExperimentalWebPlatformFeatures');
},
},
/** @private */ /** @private */
enableSiteSettings_: { enableSiteSettings_: {
type: Boolean, type: Boolean,
......
...@@ -194,6 +194,9 @@ const SiteSettingsBehaviorImpl = { ...@@ -194,6 +194,9 @@ const SiteSettingsBehaviorImpl = {
// These categories are gated behind flags. // These categories are gated behind flags.
addOrRemoveSettingWithFlag( addOrRemoveSettingWithFlag(
settings.ContentSettingsTypes.SENSORS, 'enableSensorsContentSetting'); settings.ContentSettingsTypes.SENSORS, 'enableSensorsContentSetting');
addOrRemoveSettingWithFlag(
settings.ContentSettingsTypes.SERIAL_PORTS,
'enableExperimentalWebPlatformFeatures');
addOrRemoveSettingWithFlag( addOrRemoveSettingWithFlag(
settings.ContentSettingsTypes.ADS, settings.ContentSettingsTypes.ADS,
'enableSafeBrowsingSubresourceFilter'); 'enableSafeBrowsingSubresourceFilter');
......
...@@ -194,6 +194,22 @@ ...@@ -194,6 +194,22 @@
'$i18nPolymer{siteSettingsUsbDevicesAsk}', '$i18nPolymer{siteSettingsUsbDevicesAsk}',
'$i18nPolymer{siteSettingsUsbDevicesBlock}')]]"></cr-link-row> '$i18nPolymer{siteSettingsUsbDevicesBlock}')]]"></cr-link-row>
<template is="dom-if" if="[[enableExperimentalWebPlatformFeatures_]]">
<cr-link-row
class="hr two-line"
data-route="SITE_SETTINGS_SERIAL_PORTS"
icon-class="subpage-arrow"
id="serial-ports"
label="$i18n{siteSettingsSerialPorts}"
on-click="onTapNavigate_"
start-icon="settings:serial-port"
sub-label="[[defaultSettingLabel_(
default_.serialPorts,
'$i18nPolymer{siteSettingsSerialPortsAsk}',
'$i18nPolymer{siteSettingsSerialPortsBlock}')]]">
</cr-link-row>
</template>
<cr-link-row class="hr" data-route="SITE_SETTINGS_PDF_DOCUMENTS" <cr-link-row class="hr" data-route="SITE_SETTINGS_PDF_DOCUMENTS"
id="pdf-documents" label="$i18n{siteSettingsPdfDocuments}" id="pdf-documents" label="$i18n{siteSettingsPdfDocuments}"
on-click="onTapNavigate_" start-icon="settings:pdf"></cr-link-row> on-click="onTapNavigate_" start-icon="settings:pdf"></cr-link-row>
......
...@@ -68,6 +68,14 @@ Polymer({ ...@@ -68,6 +68,14 @@ Polymer({
} }
}, },
/** @private */
enableExperimentalWebPlatformFeatures_: {
type: Boolean,
value: function() {
return loadTimeData.getBoolean('enableExperimentalWebPlatformFeatures');
},
},
/** @private */ /** @private */
enablePaymentHandlerContentSetting_: { enablePaymentHandlerContentSetting_: {
type: Boolean, type: Boolean,
...@@ -126,6 +134,10 @@ Polymer({ ...@@ -126,6 +134,10 @@ Polymer({
pairs.push([R.SITE_SETTINGS_PAYMENT_HANDLER, 'paymentHandler']); pairs.push([R.SITE_SETTINGS_PAYMENT_HANDLER, 'paymentHandler']);
} }
if (this.enableExperimentalWebPlatformFeatures_) {
pairs.push([R.SITE_SETTINGS_SERIAL_PORTS, 'serial-ports']);
}
pairs.forEach(([route, id]) => { pairs.forEach(([route, id]) => {
this.focusConfig.set(route.path, () => this.async(() => { this.focusConfig.set(route.path, () => this.async(() => {
cr.ui.focusWithoutInk(assert(this.$$(`#${id}`))); cr.ui.focusWithoutInk(assert(this.$$(`#${id}`)));
......
...@@ -142,6 +142,7 @@ void SerialChooserContext::RevokeObjectPermission( ...@@ -142,6 +142,7 @@ void SerialChooserContext::RevokeObjectPermission(
DCHECK(IsValidObject(object)); DCHECK(IsValidObject(object));
ports.erase(DecodeToken(*object.FindStringKey(kTokenKey))); ports.erase(DecodeToken(*object.FindStringKey(kTokenKey)));
NotifyPermissionRevoked(requesting_origin, embedding_origin);
} }
void SerialChooserContext::GrantPortPermission( void SerialChooserContext::GrantPortPermission(
...@@ -153,6 +154,7 @@ void SerialChooserContext::GrantPortPermission( ...@@ -153,6 +154,7 @@ void SerialChooserContext::GrantPortPermission(
ephemeral_ports_[std::make_pair(requesting_origin, embedding_origin)].insert( ephemeral_ports_[std::make_pair(requesting_origin, embedding_origin)].insert(
port.token); port.token);
port_info_[port.token] = PortInfoToValue(port); port_info_[port.token] = PortInfoToValue(port);
NotifyPermissionChanged();
} }
bool SerialChooserContext::HasPortPermission( bool SerialChooserContext::HasPortPermission(
...@@ -211,5 +213,20 @@ void SerialChooserContext::SetUpPortManagerConnection( ...@@ -211,5 +213,20 @@ void SerialChooserContext::SetUpPortManagerConnection(
void SerialChooserContext::OnPortManagerConnectionError() { void SerialChooserContext::OnPortManagerConnectionError() {
port_info_.clear(); port_info_.clear();
std::vector<std::pair<url::Origin, url::Origin>> revoked_origins;
revoked_origins.reserve(ephemeral_ports_.size());
for (const auto& map_entry : ephemeral_ports_)
revoked_origins.push_back(map_entry.first);
ephemeral_ports_.clear(); ephemeral_ports_.clear();
// Notify permission observers that all ephemeral permissions have been
// revoked.
for (auto& observer : permission_observer_list_) {
observer.OnChooserObjectPermissionChanged(guard_content_settings_type_,
data_content_settings_type_);
for (const auto& origin : revoked_origins)
observer.OnPermissionRevoked(origin.first.GetURL(),
origin.second.GetURL());
}
} }
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "chrome/browser/serial/serial_chooser_context.h" #include "chrome/browser/serial/serial_chooser_context.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "chrome/browser/permissions/chooser_context_base_mock_permission_observer.h"
#include "chrome/browser/serial/serial_chooser_context_factory.h" #include "chrome/browser/serial/serial_chooser_context_factory.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_browser_thread_bundle.h"
...@@ -19,14 +20,18 @@ class SerialChooserContextTest : public testing::Test { ...@@ -19,14 +20,18 @@ class SerialChooserContextTest : public testing::Test {
~SerialChooserContextTest() override = default; ~SerialChooserContextTest() override = default;
Profile* profile() { return &profile_; } Profile* profile() { return &profile_; }
MockPermissionObserver& observer() { return mock_observer_; }
SerialChooserContext* GetContext(Profile* profile) { SerialChooserContext* GetContext(Profile* profile) {
return SerialChooserContextFactory::GetForProfile(profile); auto* context = SerialChooserContextFactory::GetForProfile(profile);
context->AddObserver(&mock_observer_);
return context;
} }
private: private:
content::TestBrowserThreadBundle thread_bundle_; content::TestBrowserThreadBundle thread_bundle_;
TestingProfile profile_; TestingProfile profile_;
MockPermissionObserver mock_observer_;
}; };
} // namespace } // namespace
...@@ -39,6 +44,11 @@ TEST_F(SerialChooserContextTest, GrantAndRevokeEphemeralPermission) { ...@@ -39,6 +44,11 @@ TEST_F(SerialChooserContextTest, GrantAndRevokeEphemeralPermission) {
SerialChooserContext* context = GetContext(profile()); SerialChooserContext* context = GetContext(profile());
EXPECT_FALSE(context->HasPortPermission(origin, origin, *port)); EXPECT_FALSE(context->HasPortPermission(origin, origin, *port));
EXPECT_CALL(observer(), OnChooserObjectPermissionChanged(
CONTENT_SETTINGS_TYPE_SERIAL_GUARD,
CONTENT_SETTINGS_TYPE_SERIAL_CHOOSER_DATA));
context->GrantPortPermission(origin, origin, *port); context->GrantPortPermission(origin, origin, *port);
EXPECT_TRUE(context->HasPortPermission(origin, origin, *port)); EXPECT_TRUE(context->HasPortPermission(origin, origin, *port));
...@@ -56,6 +66,12 @@ TEST_F(SerialChooserContextTest, GrantAndRevokeEphemeralPermission) { ...@@ -56,6 +66,12 @@ TEST_F(SerialChooserContextTest, GrantAndRevokeEphemeralPermission) {
objects[0]->source); objects[0]->source);
EXPECT_FALSE(objects[0]->incognito); EXPECT_FALSE(objects[0]->incognito);
EXPECT_CALL(observer(), OnChooserObjectPermissionChanged(
CONTENT_SETTINGS_TYPE_SERIAL_GUARD,
CONTENT_SETTINGS_TYPE_SERIAL_CHOOSER_DATA));
EXPECT_CALL(observer(),
OnPermissionRevoked(origin.GetURL(), origin.GetURL()));
context->RevokeObjectPermission(origin.GetURL(), origin.GetURL(), context->RevokeObjectPermission(origin.GetURL(), origin.GetURL(),
objects[0]->value); objects[0]->value);
EXPECT_FALSE(context->HasPortPermission(origin, origin, *port)); EXPECT_FALSE(context->HasPortPermission(origin, origin, *port));
......
...@@ -51,6 +51,7 @@ ...@@ -51,6 +51,7 @@
#include "components/unified_consent/feature.h" #include "components/unified_consent/feature.h"
#include "content/public/browser/web_ui_data_source.h" #include "content/public/browser/web_ui_data_source.h"
#include "content/public/common/content_features.h" #include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "device/fido/features.h" #include "device/fido/features.h"
#include "media/base/media_switches.h" #include "media/base/media_switches.h"
#include "services/device/public/cpp/device_features.h" #include "services/device/public/cpp/device_features.h"
...@@ -2369,6 +2370,7 @@ void AddSiteSettingsStrings(content::WebUIDataSource* html_source, ...@@ -2369,6 +2370,7 @@ void AddSiteSettingsStrings(content::WebUIDataSource* html_source,
{"mediaLicenseSize", IDS_SETTINGS_COOKIES_LOCAL_STORAGE_SIZE_ON_DISK_LABEL}, {"mediaLicenseSize", IDS_SETTINGS_COOKIES_LOCAL_STORAGE_SIZE_ON_DISK_LABEL},
{"mediaLicenseLastModified", {"mediaLicenseLastModified",
IDS_SETTINGS_COOKIES_LOCAL_STORAGE_LAST_MODIFIED_LABEL}, IDS_SETTINGS_COOKIES_LOCAL_STORAGE_LAST_MODIFIED_LABEL},
{"noSerialPortsFound", IDS_SETTINGS_NO_SERIAL_PORTS_FOUND},
{"noUsbDevicesFound", IDS_SETTINGS_NO_USB_DEVICES_FOUND}, {"noUsbDevicesFound", IDS_SETTINGS_NO_USB_DEVICES_FOUND},
{"serviceWorkerOrigin", IDS_SETTINGS_COOKIES_LOCAL_STORAGE_ORIGIN_LABEL}, {"serviceWorkerOrigin", IDS_SETTINGS_COOKIES_LOCAL_STORAGE_ORIGIN_LABEL},
{"serviceWorkerSize", {"serviceWorkerSize",
...@@ -2451,6 +2453,12 @@ void AddSiteSettingsStrings(content::WebUIDataSource* html_source, ...@@ -2451,6 +2453,12 @@ void AddSiteSettingsStrings(content::WebUIDataSource* html_source,
IDS_SETTINGS_SITE_SETTINGS_MIDI_DEVICES_ASK_RECOMMENDED}, IDS_SETTINGS_SITE_SETTINGS_MIDI_DEVICES_ASK_RECOMMENDED},
{"siteSettingsMidiDevicesBlock", {"siteSettingsMidiDevicesBlock",
IDS_SETTINGS_SITE_SETTINGS_MIDI_DEVICES_BLOCK}, IDS_SETTINGS_SITE_SETTINGS_MIDI_DEVICES_BLOCK},
{"siteSettingsSerialPorts", IDS_SETTINGS_SITE_SETTINGS_SERIAL_PORTS},
{"siteSettingsSerialPortsAsk", IDS_SETTINGS_SITE_SETTINGS_SERIAL_PORTS_ASK},
{"siteSettingsSerialPortsAskRecommended",
IDS_SETTINGS_SITE_SETTINGS_SERIAL_PORTS_ASK_RECOMMENDED},
{"siteSettingsSerialPortsBlock",
IDS_SETTINGS_SITE_SETTINGS_SERIAL_PORTS_BLOCK},
{"siteSettingsUsbDevices", IDS_SETTINGS_SITE_SETTINGS_USB_DEVICES}, {"siteSettingsUsbDevices", IDS_SETTINGS_SITE_SETTINGS_USB_DEVICES},
{"siteSettingsUsbDevicesAsk", IDS_SETTINGS_SITE_SETTINGS_USB_DEVICES_ASK}, {"siteSettingsUsbDevicesAsk", IDS_SETTINGS_SITE_SETTINGS_USB_DEVICES_ASK},
{"siteSettingsUsbDevicesAskRecommended", {"siteSettingsUsbDevicesAskRecommended",
...@@ -2657,6 +2665,11 @@ void AddSiteSettingsStrings(content::WebUIDataSource* html_source, ...@@ -2657,6 +2665,11 @@ void AddSiteSettingsStrings(content::WebUIDataSource* html_source,
"enablePaymentHandlerContentSetting", "enablePaymentHandlerContentSetting",
base::FeatureList::IsEnabled(features::kServiceWorkerPaymentApps)); base::FeatureList::IsEnabled(features::kServiceWorkerPaymentApps));
base::CommandLine& cmd = *base::CommandLine::ForCurrentProcess();
html_source->AddBoolean(
"enableExperimentalWebPlatformFeatures",
cmd.HasSwitch(::switches::kEnableExperimentalWebPlatformFeatures));
if (PluginUtils::ShouldPreferHtmlOverPlugins( if (PluginUtils::ShouldPreferHtmlOverPlugins(
HostContentSettingsMapFactory::GetForProfile(profile))) { HostContentSettingsMapFactory::GetForProfile(profile))) {
static constexpr LocalizedString kFlashStrings[] = { static constexpr LocalizedString kFlashStrings[] = {
......
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
#include "chrome/browser/permissions/permission_uma_util.h" #include "chrome/browser/permissions/permission_uma_util.h"
#include "chrome/browser/permissions/permission_util.h" #include "chrome/browser/permissions/permission_util.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/serial/serial_chooser_context.h"
#include "chrome/browser/serial/serial_chooser_context_factory.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/page_info/page_info_infobar_delegate.h" #include "chrome/browser/ui/page_info/page_info_infobar_delegate.h"
...@@ -1370,6 +1372,10 @@ void SiteSettingsHandler::ObserveSourcesForProfile(Profile* profile) { ...@@ -1370,6 +1372,10 @@ void SiteSettingsHandler::ObserveSourcesForProfile(Profile* profile) {
auto* usb_context = UsbChooserContextFactory::GetForProfile(profile); auto* usb_context = UsbChooserContextFactory::GetForProfile(profile);
if (!chooser_observer_.IsObserving(usb_context)) if (!chooser_observer_.IsObserving(usb_context))
chooser_observer_.Add(usb_context); chooser_observer_.Add(usb_context);
auto* serial_context = SerialChooserContextFactory::GetForProfile(profile);
if (!chooser_observer_.IsObserving(serial_context))
chooser_observer_.Add(serial_context);
} }
void SiteSettingsHandler::StopObservingSourcesForProfile(Profile* profile) { void SiteSettingsHandler::StopObservingSourcesForProfile(Profile* profile) {
...@@ -1380,6 +1386,10 @@ void SiteSettingsHandler::StopObservingSourcesForProfile(Profile* profile) { ...@@ -1380,6 +1386,10 @@ void SiteSettingsHandler::StopObservingSourcesForProfile(Profile* profile) {
auto* usb_context = UsbChooserContextFactory::GetForProfile(profile); auto* usb_context = UsbChooserContextFactory::GetForProfile(profile);
if (chooser_observer_.IsObserving(usb_context)) if (chooser_observer_.IsObserving(usb_context))
chooser_observer_.Remove(usb_context); chooser_observer_.Remove(usb_context);
auto* serial_context = SerialChooserContextFactory::GetForProfile(profile);
if (chooser_observer_.IsObserving(serial_context))
chooser_observer_.Remove(serial_context);
} }
void SiteSettingsHandler::TreeNodesAdded(ui::TreeModel* model, void SiteSettingsHandler::TreeNodesAdded(ui::TreeModel* model,
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
#include "chrome/browser/permissions/permission_manager.h" #include "chrome/browser/permissions/permission_manager.h"
#include "chrome/browser/permissions/permission_result.h" #include "chrome/browser/permissions/permission_result.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/serial/serial_chooser_context.h"
#include "chrome/browser/serial/serial_chooser_context_factory.h"
#include "chrome/browser/usb/usb_chooser_context.h" #include "chrome/browser/usb/usb_chooser_context.h"
#include "chrome/browser/usb/usb_chooser_context_factory.h" #include "chrome/browser/usb/usb_chooser_context_factory.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
...@@ -50,6 +52,7 @@ typedef std::map<std::pair<GURL, std::string>, OneOriginObjects> ...@@ -50,6 +52,7 @@ typedef std::map<std::pair<GURL, std::string>, OneOriginObjects>
// Chooser data group names. // Chooser data group names.
const char kUsbChooserDataGroupType[] = "usb-devices-data"; const char kUsbChooserDataGroupType[] = "usb-devices-data";
const char kSerialChooserDataGroupType[] = "serial-ports-data";
const ContentSettingsTypeNameEntry kContentSettingsTypeGroupNames[] = { const ContentSettingsTypeNameEntry kContentSettingsTypeGroupNames[] = {
// The following ContentSettingsTypes have UI in Content Settings // The following ContentSettingsTypes have UI in Content Settings
...@@ -79,6 +82,8 @@ const ContentSettingsTypeNameEntry kContentSettingsTypeGroupNames[] = { ...@@ -79,6 +82,8 @@ const ContentSettingsTypeNameEntry kContentSettingsTypeGroupNames[] = {
{CONTENT_SETTINGS_TYPE_USB_GUARD, "usb-devices"}, {CONTENT_SETTINGS_TYPE_USB_GUARD, "usb-devices"},
{CONTENT_SETTINGS_TYPE_USB_CHOOSER_DATA, kUsbChooserDataGroupType}, {CONTENT_SETTINGS_TYPE_USB_CHOOSER_DATA, kUsbChooserDataGroupType},
{CONTENT_SETTINGS_TYPE_IDLE_DETECTION, "idle-detection"}, {CONTENT_SETTINGS_TYPE_IDLE_DETECTION, "idle-detection"},
{CONTENT_SETTINGS_TYPE_SERIAL_GUARD, "serial-ports"},
{CONTENT_SETTINGS_TYPE_SERIAL_CHOOSER_DATA, kSerialChooserDataGroupType},
// Add new content settings here if a corresponding Javascript string // Add new content settings here if a corresponding Javascript string
// representation for it is not required. Note some exceptions do have UI in // representation for it is not required. Note some exceptions do have UI in
...@@ -104,9 +109,6 @@ const ContentSettingsTypeNameEntry kContentSettingsTypeGroupNames[] = { ...@@ -104,9 +109,6 @@ const ContentSettingsTypeNameEntry kContentSettingsTypeGroupNames[] = {
{CONTENT_SETTINGS_TYPE_PLUGINS_DATA, nullptr}, {CONTENT_SETTINGS_TYPE_PLUGINS_DATA, nullptr},
{CONTENT_SETTINGS_TYPE_BACKGROUND_FETCH, nullptr}, {CONTENT_SETTINGS_TYPE_BACKGROUND_FETCH, nullptr},
{CONTENT_SETTINGS_TYPE_INTENT_PICKER_DISPLAY, nullptr}, {CONTENT_SETTINGS_TYPE_INTENT_PICKER_DISPLAY, nullptr},
// TODO(crbug.com/908836): Add UI for setting this permission.
{CONTENT_SETTINGS_TYPE_SERIAL_GUARD, nullptr},
{CONTENT_SETTINGS_TYPE_SERIAL_CHOOSER_DATA, nullptr},
}; };
static_assert(base::size(kContentSettingsTypeGroupNames) == static_assert(base::size(kContentSettingsTypeGroupNames) ==
// ContentSettingsType starts at -1, so add 1 here. // ContentSettingsType starts at -1, so add 1 here.
...@@ -240,8 +242,13 @@ ChooserContextBase* GetUsbChooserContext(Profile* profile) { ...@@ -240,8 +242,13 @@ ChooserContextBase* GetUsbChooserContext(Profile* profile) {
return UsbChooserContextFactory::GetForProfile(profile); return UsbChooserContextFactory::GetForProfile(profile);
} }
ChooserContextBase* GetSerialChooserContext(Profile* profile) {
return SerialChooserContextFactory::GetForProfile(profile);
}
const ChooserTypeNameEntry kChooserTypeGroupNames[] = { const ChooserTypeNameEntry kChooserTypeGroupNames[] = {
{&GetUsbChooserContext, kUsbChooserDataGroupType}, {&GetUsbChooserContext, kUsbChooserDataGroupType},
{&GetSerialChooserContext, kSerialChooserDataGroupType},
}; };
} // namespace } // namespace
......
...@@ -346,7 +346,10 @@ suite('ChooserExceptionList', function() { ...@@ -346,7 +346,10 @@ suite('ChooserExceptionList', function() {
.then(function(chooserType) { .then(function(chooserType) {
assertEquals(settings.ChooserType.USB_DEVICES, chooserType); assertEquals(settings.ChooserType.USB_DEVICES, chooserType);
assertEquals(0, testElement.chooserExceptions.length); assertEquals(0, testElement.chooserExceptions.length);
assertFalse(testElement.$$('#empty-list-message').hidden); const emptyListMessage = testElement.$$('#empty-list-message');
assertFalse(emptyListMessage.hidden);
assertEquals(
'No USB devices found', emptyListMessage.textContent.trim());
}); });
}); });
......
...@@ -138,6 +138,9 @@ suite('SiteDetails', function() { ...@@ -138,6 +138,9 @@ suite('SiteDetails', function() {
optionalSiteDetailsContentSettingsTypes[settings.ContentSettingsTypes optionalSiteDetailsContentSettingsTypes[settings.ContentSettingsTypes
.PAYMENT_HANDLER] = .PAYMENT_HANDLER] =
'enablePaymentHandlerContentSetting'; 'enablePaymentHandlerContentSetting';
optionalSiteDetailsContentSettingsTypes[settings.ContentSettingsTypes
.SERIAL_PORTS] =
'enableExperimentalWebPlatformFeatures';
browserProxy.setPrefs(prefs); browserProxy.setPrefs(prefs);
// First, explicitly set all the optional settings to false. // First, explicitly set all the optional settings to false.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment