Skip to content

Commit

Permalink
Merge pull request #19252 from /issues/15637-about-flags
Browse files Browse the repository at this point in the history
Allow WebSerial API to be enabled via brave://flags.
  • Loading branch information
goodov committed Jul 17, 2023
2 parents 11e220d + 9f58cb1 commit f06d2e8
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 1 deletion.
8 changes: 8 additions & 0 deletions browser/about_flags.cc
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit f06d2e8

Please sign in to comment.