-
Notifications
You must be signed in to change notification settings - Fork 920
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disable serveral blink runtime features.
Fixes brave/brave-browser#11133 Fixes brave/brave-browser#11407 Fixes brave/brave-browser#11546 Fixes brave/brave-browser#11547 - Disables features via Chromium features: * Direct Sockets * Lang Client Hint Header * Signed Exchange Prefetch Cache For Navigations * Subresource Web Bundles - Disabled the following blink features in BraveContentRendererClient::SetRuntimeFeaturesDefaultsBeforeBlinkInitialization since they don't have Chromium features: * Digital Goods * Native File System (File System Access) - Added browser tests for these features - Modified redirect-cc.py to allow overriding files under out/XXX/gen - Added an override for blink::origin_trials::IsTrialValid and overrides for blink::OriginTrialContext methods AddFeature and AddForceEnabledTrials for trials: * NativeFileSystem2 * SignedExchangeSubresourcePrefetch * SubresourceWebBundles - Added browser tests for trials disablement.
- Loading branch information
Showing
13 changed files
with
651 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
chromium_src/third_party/blink/renderer/core/origin_trials/origin_trial_context.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* 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) { | ||
// When updating this list also update the trials names below in | ||
// AddForceEnabledTrials override as well as the names in | ||
// * origin_trials.cc override and | ||
static const std::array<OriginTrialFeature, 3> kBraveDisabledTrialFeatures = { | ||
// [cr88] OriginTrialFeature::kDigitalGoods, | ||
OriginTrialFeature::kNativeFileSystem, | ||
OriginTrialFeature::kSignedExchangeSubresourcePrefetch, | ||
OriginTrialFeature::kSubresourceWebBundles, | ||
}; | ||
if (base::Contains(kBraveDisabledTrialFeatures, feature)) | ||
return; | ||
|
||
AddFeature_ChromiumImpl(feature); | ||
} | ||
|
||
// AddForceEnabledTrials only has a DCHECK with origin_trials::IsTrialValid. | ||
void OriginTrialContext::AddForceEnabledTrials( | ||
const Vector<String>& trial_names) { | ||
// When updating this list also update | ||
// * origin_trials.cc override and | ||
static const char* const kBraveDisabledTrialNames[] = { | ||
// [cr88] "DigitalGoods", | ||
"NativeFileSystem2", | ||
"SignedExchangeSubresourcePrefetch", | ||
"SubresourceWebBundles", | ||
}; | ||
|
||
for (const auto* disabled_name : kBraveDisabledTrialNames) { | ||
if (base::Contains(trial_names, disabled_name)) | ||
return; | ||
} | ||
|
||
AddForceEnabledTrials_ChromiumImpl(trial_names); | ||
} | ||
|
||
} // namespace blink |
21 changes: 21 additions & 0 deletions
21
chromium_src/third_party/blink/renderer/core/origin_trials/origin_trial_context.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
40 changes: 40 additions & 0 deletions
40
chromium_src/third_party/blink/renderer/core/origin_trials/origin_trials.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* 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 { | ||
|
||
bool origin_trials::IsTrialValid(const StringView& trial_name) { | ||
// When updating this list also update | ||
// * origin_trial_context.cc override and | ||
static const char* const kBraveDisabledTrialNames[] = { | ||
// [cr88] "DigitalGoods", | ||
"NativeFileSystem2", | ||
"SignedExchangeSubresourcePrefetch", | ||
"SubresourceWebBundles", | ||
}; | ||
|
||
if (base::Contains(kBraveDisabledTrialNames, trial_name)) { | ||
// Check if this is still a valid trial in Chromium. If not, we can remove | ||
// our override for this trial. | ||
DCHECK(origin_trials::IsTrialValid_ChromiumImpl(trial_name)); | ||
return false; | ||
} | ||
|
||
return origin_trials::IsTrialValid_ChromiumImpl(trial_name); | ||
} | ||
|
||
} // namespace blink |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* 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 "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/common/content_switches.h" | ||
#include "content/public/browser/render_frame_host.h" | ||
#include "content/public/browser/web_contents.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()) { | ||
command_line->AppendSwitch( | ||
switches::kEnableExperimentalWebPlatformFeatures); | ||
} | ||
} | ||
|
||
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_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(DigitalGoodsAPIBrowserTest); | ||
}; | ||
|
||
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()); |
Oops, something went wrong.