Skip to content

Commit

Permalink
Disable SXG and WebBundles blink experimental features.
Browse files Browse the repository at this point in the history
Fixes brave/brave-browser#11133

- Modified redirect-cc.py to allow overriding files under out/XXX/gen
- Overrode getter methods for:
  * SignedExchangePrefetchCacheForNavigations
  * SignedExchangeSubresourcePrefetch
  * SubresourceWebBundles
  to always return `false`
  • Loading branch information
mkarolin committed Aug 17, 2020
1 parent 07dcae5 commit 4b72a92
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* 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/platform/runtime_enabled_features.h"

#define RuntimeEnabledFeatures RuntimeEnabledFeaturesBase
#include "../gen/third_party/blink/renderer/platform/runtime_enabled_features.cc"
#undef RuntimeEnabledFeatures

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* 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_PLATFORM_RUNTIME_ENABLED_FEATURES_H_
#define BRAVE_CHROMIUM_SRC_THIRD_PARTY_BLINK_RENDERER_PLATFORM_RUNTIME_ENABLED_FEATURES_H_

#define RuntimeEnabledFeatures RuntimeEnabledFeaturesBase
#include "../gen/third_party/blink/renderer/platform/runtime_enabled_features.h"
#undef RuntimeEnabledFeatures

namespace blink {

class PLATFORM_EXPORT RuntimeEnabledFeatures
: public RuntimeEnabledFeaturesBase {
STATIC_ONLY(RuntimeEnabledFeatures);

public:
// Hide these base class static methods:
static bool SignedExchangePrefetchCacheForNavigationsEnabled() {
return false;
}
static bool SignedExchangePrefetchCacheForNavigationsEnabled(
const FeatureContext*) {
return false;
}
static bool SignedExchangeSubresourcePrefetchEnabledByRuntimeFlag() {
return false;
}
static bool SignedExchangeSubresourcePrefetchEnabled(const FeatureContext*) {
return false;
}
static bool SubresourceWebBundlesEnabled() { return false; }
static bool SubresourceWebBundlesEnabled(const FeatureContext*) {
return false;
}
};

} // namespace blink

#endif // BRAVE_CHROMIUM_SRC_THIRD_PARTY_BLINK_RENDERER_PLATFORM_RUNTIME_ENABLED_FEATURES_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/renderer/platform/runtime_enabled_features.h"

#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/platform/testing/runtime_enabled_features_test_helpers.h"

namespace blink {
namespace {

class RuntimeEnabledFeaturesTest : public testing::Test {
public:
void CheckAllDisabled() {
EXPECT_FALSE(RuntimeEnabledFeatures::
SignedExchangePrefetchCacheForNavigationsEnabled());
EXPECT_FALSE(RuntimeEnabledFeatures::
SignedExchangePrefetchCacheForNavigationsEnabled(nullptr));
EXPECT_FALSE(RuntimeEnabledFeatures::
SignedExchangeSubresourcePrefetchEnabledByRuntimeFlag());
EXPECT_FALSE(
RuntimeEnabledFeatures::SignedExchangeSubresourcePrefetchEnabled(
nullptr));
EXPECT_FALSE(RuntimeEnabledFeatures::SubresourceWebBundlesEnabled());
EXPECT_FALSE(RuntimeEnabledFeatures::SubresourceWebBundlesEnabled(nullptr));
}

void CheckChromiumImplState(bool state) {
EXPECT_EQ(state, RuntimeEnabledFeaturesBase::
SignedExchangePrefetchCacheForNavigationsEnabled());
EXPECT_EQ(state, RuntimeEnabledFeaturesBase::
SignedExchangePrefetchCacheForNavigationsEnabled(nullptr));
EXPECT_EQ(state, RuntimeEnabledFeaturesBase::
SignedExchangeSubresourcePrefetchEnabledByRuntimeFlag());
EXPECT_EQ(
state,
RuntimeEnabledFeaturesBase::SignedExchangeSubresourcePrefetchEnabled(
nullptr));
EXPECT_EQ(state,
RuntimeEnabledFeaturesBase::SubresourceWebBundlesEnabled());
EXPECT_EQ(state, RuntimeEnabledFeaturesBase::SubresourceWebBundlesEnabled(
nullptr));
}

void CheckChromiumImplDisabled() { CheckChromiumImplState(false); }
void CheckChromiumImplEnabled() { CheckChromiumImplState(true); }

void SetFeaturesState(bool state) {
RuntimeEnabledFeatures::SetSignedExchangePrefetchCacheForNavigationsEnabled(
state);
RuntimeEnabledFeatures::SetSignedExchangeSubresourcePrefetchEnabled(state);
RuntimeEnabledFeatures::SetSubresourceWebBundlesEnabled(state);
}

void SetFeaturesDisabled() { SetFeaturesState(false); }
void SetFeaturesEnabled() { SetFeaturesState(true); }
};

TEST_F(RuntimeEnabledFeaturesTest, TestSXGandWebBundlesDisabled) {
// Initial state - all disabled.
CheckChromiumImplDisabled();
CheckAllDisabled();

// Enable SXG and WebBundles
SetFeaturesEnabled();
// Check that features are enabled via the chromium implementation
CheckChromiumImplEnabled();
// Should all come back as disabled.
CheckAllDisabled();

// Reset to disabled.
SetFeaturesDisabled();
CheckChromiumImplDisabled();
CheckAllDisabled();

// Enable using SetFeatureEnabledFromString API.
RuntimeEnabledFeatures::SetFeatureEnabledFromString(
"SignedExchangePrefetchCacheForNavigations", true);
RuntimeEnabledFeatures::SetFeatureEnabledFromString(
"SignedExchangeSubresourcePrefetch", true);
RuntimeEnabledFeatures::SetFeatureEnabledFromString("SubresourceWebBundles",
true);
// Check that features are enabled via the chromium implementation
CheckChromiumImplEnabled();
// Should all come back as disabled.
CheckAllDisabled();
}

} // namespace
} // namespace blink
11 changes: 7 additions & 4 deletions script/redirect-cc.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,13 @@ def replace_cc_arg(args):
# Filter away out and out_x86
# Maybe this dir can be queried from env variable instead of hardcoding
OUT_DIR_NAMES = ['out', 'out_x86']
start_dir = rel_path.split(os.sep)[0]
if start_dir in OUT_DIR_NAMES:
# Don't even try to substitute path for auto-generated cc
return
rel_path_parts = rel_path.split(os.sep, 3)
if rel_path_parts[0] in OUT_DIR_NAMES:
if rel_path_parts[2] == 'gen':
rel_path = rel_path_parts[3]
else:
# Don't even try to substitute path for other auto-generated cc
return

# Build possible brave/chromium_src_path
brave_path = os.path.join(chromium_original_dir, 'brave', 'chromium_src',
Expand Down
1 change: 1 addition & 0 deletions test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ test("brave_unit_tests") {
"//brave/chromium_src/components/version_info/brave_version_info_unittest.cc",
"//brave/chromium_src/net/cookies/brave_canonical_cookie_unittest.cc",
"//brave/chromium_src/services/network/public/cpp/cors/cors_unittest.cc",
"//brave/chromium_src/third_party/blink/renderer/platform/runtime_enabled_features_test.cc",
"//brave/common/brave_content_client_unittest.cc",
"//brave/components/assist_ranker/ranker_model_loader_impl_unittest.cc",
"//brave/components/brave_private_cdn/private_cdn_helper_unittest.cc",
Expand Down

0 comments on commit 4b72a92

Please sign in to comment.