Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow WebSerial API to be enabled via brave://flags. #19252

Merged
merged 3 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions browser/about_flags.cc
Expand Up @@ -760,6 +760,14 @@
kOsDesktop, \
FEATURE_VALUE_TYPE(blink::features::kFileSystemAccessAPI), \
}, \
{ \
"brave-web-serial-api", \
"Web Serial API", \
"Enables the Web Serial API, allowing websites to request access " \
"to serial ports ", \
kOsDesktop, \
FEATURE_VALUE_TYPE(blink::features::kBraveWebSerialAPI), \
}, \
{ \
"navigator-connection-attribute", \
"Enable navigator.connection attribute", \
Expand Down
Expand Up @@ -88,6 +88,14 @@ RegisterPolymerComponentReplacement(
lists_.permissionsAdvanced.splice(indexForIdleDetection, 1)
}
}
if (!loadTimeData.getBoolean('isBraveWebSerialApiEnabled')) {
let indexForSerialPorts = lists_.permissionsAdvanced.findIndex(item => item.id === ContentSettingsTypes.SERIAL_PORTS)
if (indexForSerialPorts === -1) {
console.error('Could not find SERIAL_PORTS site settings item')
} else {
lists_.permissionsAdvanced.splice(indexForSerialPorts, 1)
}
}
let indexForAutoplay = lists_.permissionsAdvanced.findIndex(item => item.id === ContentSettingsTypes.AUTOMATIC_DOWNLOADS)
if (indexForAutoplay === -1) {
console.error('Could not find automatic downloads site settings item')
Expand Down
4 changes: 4 additions & 0 deletions browser/ui/webui/brave_settings_ui.cc
Expand Up @@ -44,6 +44,7 @@
#include "content/public/common/content_features.h"
#include "extensions/buildflags/buildflags.h"
#include "net/base/features.h"
#include "third_party/blink/public/common/features.h"

#if BUILDFLAG(ENABLE_PIN_SHORTCUT)
#include "brave/browser/ui/webui/settings/pin_shortcut_handler.h"
Expand Down Expand Up @@ -129,6 +130,9 @@ void BraveSettingsUI::AddResources(content::WebUIDataSource* html_source,
html_source->AddBoolean(
"isIdleDetectionFeatureEnabled",
base::FeatureList::IsEnabled(features::kIdleDetection));
html_source->AddBoolean(
"isBraveWebSerialApiEnabled",
base::FeatureList::IsEnabled(blink::features::kBraveWebSerialAPI));
#if BUILDFLAG(ENABLE_BRAVE_VPN)
html_source->AddBoolean("isBraveVPNEnabled",
brave_vpn::IsBraveVPNEnabled(profile));
Expand Down
Expand Up @@ -5,7 +5,9 @@

#include "chrome/browser/ui/webui/settings/site_settings_helper.h"

#include "base/containers/cxx20_erase_vector.h"
#include "brave/components/brave_shields/common/brave_shield_constants.h"
#include "third_party/blink/public/common/features.h"

#define HasRegisteredGroupName HasRegisteredGroupName_ChromiumImpl
#define ContentSettingsTypeToGroupName \
Expand Down Expand Up @@ -100,6 +102,11 @@ const std::vector<ContentSettingsType>& GetVisiblePermissionCategories() {
if (!initialized) {
auto& base_types = GetVisiblePermissionCategories_ChromiumImpl();
types->insert(types->end(), base_types.begin(), base_types.end());

if (!base::FeatureList::IsEnabled(blink::features::kBraveWebSerialAPI)) {
base::Erase(*types, ContentSettingsType::SERIAL_GUARD);
}

initialized = true;
}

Expand Down
4 changes: 4 additions & 0 deletions chromium_src/third_party/blink/common/features.cc
Expand Up @@ -66,6 +66,10 @@ BASE_FEATURE(kFileSystemAccessAPI,
"FileSystemAccessAPI",
base::FEATURE_DISABLED_BY_DEFAULT);

BASE_FEATURE(kBraveWebSerialAPI,
"BraveWebSerialAPI",
base::FEATURE_DISABLED_BY_DEFAULT);

BASE_FEATURE(kNavigatorConnectionAttribute,
"NavigatorConnectionAttribute",
base::FEATURE_DISABLED_BY_DEFAULT);
Expand Down
1 change: 1 addition & 0 deletions chromium_src/third_party/blink/public/common/features.h
Expand Up @@ -16,6 +16,7 @@ namespace features {
BLINK_COMMON_EXPORT BASE_DECLARE_FEATURE(kAllowCertainClientHints);
BLINK_COMMON_EXPORT BASE_DECLARE_FEATURE(kClampPlatformVersionClientHint);
BLINK_COMMON_EXPORT BASE_DECLARE_FEATURE(kFileSystemAccessAPI);
BLINK_COMMON_EXPORT BASE_DECLARE_FEATURE(kBraveWebSerialAPI);
BLINK_COMMON_EXPORT BASE_DECLARE_FEATURE(kNavigatorConnectionAttribute);
BLINK_COMMON_EXPORT BASE_DECLARE_FEATURE(kPartitionBlinkMemoryCache);
BLINK_COMMON_EXPORT BASE_DECLARE_FEATURE(kRestrictWebSocketsPool);
Expand Down
4 changes: 3 additions & 1 deletion renderer/brave_content_renderer_client.cc
Expand Up @@ -62,7 +62,9 @@ void BraveContentRendererClient::
blink::WebRuntimeFeatures::EnableFeatureFromString(
"FileSystemAccessAPIExperimental", false);
}
blink::WebRuntimeFeatures::EnableFeatureFromString("Serial", false);
if (!base::FeatureList::IsEnabled(blink::features::kBraveWebSerialAPI)) {
blink::WebRuntimeFeatures::EnableFeatureFromString("Serial", false);
}
blink::WebRuntimeFeatures::EnableFeatureFromString(
"SpeculationRulesPrefetchProxy", false);
blink::WebRuntimeFeatures::EnableFeatureFromString("AdTagging", false);
Expand Down