-
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
14 changed files
with
660 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
35 changes: 35 additions & 0 deletions
35
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,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 |
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_ |
60 changes: 60 additions & 0 deletions
60
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,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[] = { | ||
// [cr88] "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, 3> kBraveDisabledTrialFeatures = { | ||
// [cr88] 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 |
20 changes: 20 additions & 0 deletions
20
chromium_src/third_party/blink/renderer/core/origin_trials/origin_trials.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,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_ |
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,88 @@ | ||
/* 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_; | ||
}; | ||
|
||
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.