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

Disables several blink runtime features. (uplift to 1.19.x) #7733

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/brave_main_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,14 @@ bool BraveMainDelegate::BasicStartupComplete(int* exit_code) {
autofill::features::kAutofillEnableAccountWalletStorage.name,
autofill::features::kAutofillServerCommunication.name,
blink::features::kTextFragmentAnchor.name,
features::kDirectSockets.name,
features::kIdleDetection.name,
features::kLangClientHintHeader.name,
features::kNotificationTriggers.name,
features::kPrivacySettingsRedesign.name,
features::kSignedExchangePrefetchCacheForNavigations.name,
features::kSignedExchangeSubresourcePrefetch.name,
features::kSubresourceWebBundles.name,
features::kTabHoverCards.name,
features::kWebOTP.name,
network_time::kNetworkTimeServiceQuerying.name,
Expand Down
4 changes: 4 additions & 0 deletions app/brave_main_delegate_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,14 @@ IN_PROC_BROWSER_TEST_F(BraveMainDelegateBrowserTest, DisabledFeatures) {
&autofill::features::kAutofillEnableAccountWalletStorage,
&autofill::features::kAutofillServerCommunication,
&blink::features::kTextFragmentAnchor,
&features::kDirectSockets,
&features::kIdleDetection,
&features::kLangClientHintHeader,
&features::kNotificationTriggers,
&features::kPrivacySettingsRedesign,
&features::kSignedExchangePrefetchCacheForNavigations,
&features::kSignedExchangeSubresourcePrefetch,
&features::kSubresourceWebBundles,
&features::kTabHoverCards,
&features::kWebOTP,
&network_time::kNetworkTimeServiceQuerying,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "base/bind.h"
#include "base/feature_list.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/stl_util.h"
#include "base/test/scoped_feature_list.h"
#include "brave/common/brave_paths.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/common/content_features.h"
#include "content/public/test/browser_test.h"
#include "net/dns/mock_host_resolver.h"
#include "net/http/http_request_headers.h"
Expand All @@ -19,7 +22,8 @@

const char kClientHints[] = "/ch.html";

class ClientHintsBrowserTest : public InProcessBrowserTest {
class ClientHintsBrowserTest : public InProcessBrowserTest,
public ::testing::WithParamInterface<bool> {
public:
ClientHintsBrowserTest()
: https_server_(net::EmbeddedTestServer::TYPE_HTTPS),
Expand All @@ -40,7 +44,19 @@ class ClientHintsBrowserTest : public InProcessBrowserTest {

~ClientHintsBrowserTest() override {}

void SetUp() override { InProcessBrowserTest::SetUp(); }
bool IsLangClientHintHeaderEnabled() { return GetParam(); }

void SetUp() override {
if (IsLangClientHintHeaderEnabled()) {
// Test that even with Lang CH feature enabled, there is no header.
scoped_feature_list_.InitAndEnableFeature(
features::kLangClientHintHeader);
} else {
scoped_feature_list_.InitAndDisableFeature(
features::kLangClientHintHeader);
}
InProcessBrowserTest::SetUp();
}

void SetUpOnMainThread() override {
host_resolver()->AddRule("*", "127.0.0.1");
Expand Down Expand Up @@ -68,11 +84,18 @@ class ClientHintsBrowserTest : public InProcessBrowserTest {
net::EmbeddedTestServer https_server_;
GURL client_hints_url_;
size_t count_client_hints_headers_seen_;
base::test::ScopedFeatureList scoped_feature_list_;

DISALLOW_COPY_AND_ASSIGN(ClientHintsBrowserTest);
};

IN_PROC_BROWSER_TEST_F(ClientHintsBrowserTest, ClientHintsDisabled) {
IN_PROC_BROWSER_TEST_P(ClientHintsBrowserTest, ClientHintsDisabled) {
EXPECT_EQ(IsLangClientHintHeaderEnabled(),
base::FeatureList::IsEnabled(features::kLangClientHintHeader));
ui_test_utils::NavigateToURL(browser(), client_hints_url());
EXPECT_EQ(0u, count_client_hints_headers_seen());
}

INSTANTIATE_TEST_SUITE_P(ClientHintsBrowserTest,
ClientHintsBrowserTest,
::testing::Bool());
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "third_party/blink/renderer/core/origin_trials/origin_trial_context.h"

#define AddFeature AddFeature_ChromiumImpl
#define AddForceEnabledTrials AddForceEnabledTrials_ChromiumImpl
#include "../../../../../../../third_party/blink/renderer/core/origin_trials/origin_trial_context.cc"
#undef AddForceEnabledTrials
#undef AddFeature

namespace blink {

// AddFeature doesn't check if origin_trials::IsTrialValid.
void OriginTrialContext::AddFeature(OriginTrialFeature feature) {
if (origin_trials::IsTrialDisabledInBrave(feature))
return;

AddFeature_ChromiumImpl(feature);
}

// AddForceEnabledTrials only has a DCHECK with origin_trials::IsTrialValid.
void OriginTrialContext::AddForceEnabledTrials(
const Vector<String>& trial_names) {
for (const String& trial_name : trial_names) {
if (origin_trials::IsTrialDisabledInBrave(trial_name))
return;
}

AddForceEnabledTrials_ChromiumImpl(trial_names);
}

} // namespace blink
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_CHROMIUM_SRC_THIRD_PARTY_BLINK_RENDERER_CORE_ORIGIN_TRIALS_ORIGIN_TRIAL_CONTEXT_H_
#define BRAVE_CHROMIUM_SRC_THIRD_PARTY_BLINK_RENDERER_CORE_ORIGIN_TRIALS_ORIGIN_TRIAL_CONTEXT_H_

#define AddFeature \
AddFeature_ChromiumImpl(OriginTrialFeature feature); \
void AddFeature

#define AddForceEnabledTrials \
AddForceEnabledTrials_ChromiumImpl(const Vector<String>& trial_names); \
void AddForceEnabledTrials

#include "../../../../../../../third_party/blink/renderer/core/origin_trials/origin_trial_context.h"
#undef AddForceEnabledTrials
#undef AddFeature

#endif // BRAVE_CHROMIUM_SRC_THIRD_PARTY_BLINK_RENDERER_CORE_ORIGIN_TRIALS_ORIGIN_TRIAL_CONTEXT_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "third_party/blink/renderer/core/origin_trials/origin_trials.h"

namespace blink {
namespace origin_trials {
bool IsTrialValid_ChromiumImpl(const StringView& trial_name);
} // namespace origin_trials
} // namespace blink

#define IsTrialValid IsTrialValid_ChromiumImpl
#include "../gen/third_party/blink/renderer/core/origin_trials/origin_trials.cc"
#undef IsTrialValid

namespace blink {
namespace origin_trials {

bool IsTrialDisabledInBrave(const StringView& trial_name) {
// When updating also update the array in the overload below.
static const char* const kBraveDisabledTrialNames[] = {
"DigitalGoods",
"NativeFileSystem2",
"SignedExchangeSubresourcePrefetch",
"SubresourceWebBundles",
};

if (base::Contains(kBraveDisabledTrialNames, trial_name)) {
// Check if this is still a valid trial name in Chromium. If not, it needs
// to be changed as in Chromium or removed.
DCHECK(IsTrialValid_ChromiumImpl(trial_name));
return true;
}

return false;
}

bool IsTrialDisabledInBrave(OriginTrialFeature feature) {
// When updating also update the array in the overload above.
static const std::array<OriginTrialFeature, 4> kBraveDisabledTrialFeatures = {
OriginTrialFeature::kDigitalGoods,
OriginTrialFeature::kNativeFileSystem,
OriginTrialFeature::kSignedExchangeSubresourcePrefetch,
OriginTrialFeature::kSubresourceWebBundles,
};

return base::Contains(kBraveDisabledTrialFeatures, feature);
}

bool IsTrialValid(const StringView& trial_name) {
if (IsTrialDisabledInBrave(trial_name))
return false;

return IsTrialValid_ChromiumImpl(trial_name);
}

} // namespace origin_trials
} // namespace blink
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_CHROMIUM_SRC_THIRD_PARTY_BLINK_RENDERER_CORE_ORIGIN_TRIALS_ORIGIN_TRIALS_H_
#define BRAVE_CHROMIUM_SRC_THIRD_PARTY_BLINK_RENDERER_CORE_ORIGIN_TRIALS_ORIGIN_TRIALS_H_

#include "../../../../../../../third_party/blink/renderer/core/origin_trials/origin_trials.h"

namespace blink {
namespace origin_trials {

bool IsTrialDisabledInBrave(const StringView& trial_name);
bool IsTrialDisabledInBrave(OriginTrialFeature feature);

} // namespace origin_trials
} // namespace blink

#endif // BRAVE_CHROMIUM_SRC_THIRD_PARTY_BLINK_RENDERER_CORE_ORIGIN_TRIALS_ORIGIN_TRIALS_H_
5 changes: 5 additions & 0 deletions renderer/brave_content_renderer_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,10 @@ SetRuntimeFeaturesDefaultsBeforeBlinkInitialization() {
SetRuntimeFeaturesDefaultsBeforeBlinkInitialization();

blink::WebRuntimeFeatures::EnableSharedArrayBuffer(false);

// These features don't have dedicated WebRuntimeFeatures wrappers.
blink::WebRuntimeFeatures::EnableFeatureFromString("DigitalGoods", false);
blink::WebRuntimeFeatures::EnableFeatureFromString("NativeFileSystem", false);
}

BraveContentRendererClient::~BraveContentRendererClient() = default;
29 changes: 29 additions & 0 deletions renderer/test/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) 2020 The Brave Authors. All rights reserved.
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.

import("//testing/test.gni")

source_set("browser_tests") {
testonly = true

sources = [
"digital_goods_api_browsertest.cc",
"native_file_system_api_browsertest.cc",
"subresource_web_bundles_browsertest.cc",
]

defines = [ "HAS_OUT_OF_PROC_TEST_RUNNER" ]

deps = [
"//base/test:test_support",
"//brave/common",
"//chrome/browser/ui",
"//chrome/test:test_support_ui",
"//components/embedder_support",
"//components/web_package:test_support",
"//content/test:test_support",
"//net:test_support",
]
}
92 changes: 92 additions & 0 deletions renderer/test/digital_goods_api_browsertest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "base/path_service.h"
#include "brave/common/brave_paths.h"
#include "build/build_config.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "url/gurl.h"

class DigitalGoodsAPIBrowserTest : public InProcessBrowserTest,
public ::testing::WithParamInterface<bool> {
public:
DigitalGoodsAPIBrowserTest()
: https_server_(net::EmbeddedTestServer::TYPE_HTTPS) {
brave::RegisterPathProvider();
base::FilePath test_data_dir;
base::PathService::Get(brave::DIR_TEST_DATA, &test_data_dir);
https_server_.SetSSLConfig(net::EmbeddedTestServer::CERT_OK);
https_server_.ServeFilesFromDirectory(test_data_dir);
}

~DigitalGoodsAPIBrowserTest() override = default;

bool IsDigitalGoodsAPIEnabled() { return GetParam(); }

void SetUpCommandLine(base::CommandLine* command_line) override {
InProcessBrowserTest::SetUpCommandLine(command_line);
if (IsDigitalGoodsAPIEnabled()) {
#if defined(OS_ANDROID)
command_line->AppendSwitch(
switches::kEnableExperimentalWebPlatformFeatures);
#else
command_line->AppendSwitch(switches::kEnableBlinkTestFeatures);
#endif
}
}

void SetUpOnMainThread() override {
InProcessBrowserTest::SetUpOnMainThread();

EXPECT_TRUE(https_server_.Start());
// Map all hosts to localhost.
host_resolver()->AddRule("*", "127.0.0.1");
}

content::WebContents* web_contents() {
return browser()->tab_strip_model()->GetActiveWebContents();
}

content::RenderFrameHost* main_frame() {
return web_contents()->GetMainFrame();
}

protected:
net::EmbeddedTestServer https_server_;
};

IN_PROC_BROWSER_TEST_P(DigitalGoodsAPIBrowserTest, DigitalGoods) {
const GURL url = https_server_.GetURL("/simple.html");
ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), url));

auto result =
content::EvalJs(main_frame(), "window.getDigitalGoodsService()");
if (IsDigitalGoodsAPIEnabled()) {
EXPECT_TRUE(result.error.find(
"Failed to execute 'getDigitalGoodsService' on "
"'Window': 1 argument required, but only 0 present.") !=
std::string::npos)
<< result.error;
} else {
EXPECT_TRUE(
result.error.find("window.getDigitalGoodsService is not a function") !=
std::string::npos)
<< result.error;
}
}

INSTANTIATE_TEST_SUITE_P(DigitalGoodsAPIBrowserTest,
DigitalGoodsAPIBrowserTest,
::testing::Bool());
Loading