Skip to content

Commit

Permalink
Add enterprise policy for :--foo deprecation
Browse files Browse the repository at this point in the history
I am changing the syntax of the custom state pseudo class from :--foo to
:state(foo). In order to do that, I am deprecating and eventually
removing support for :--foo. We have already been emitting a console
error when :--foo is used for several releases, but in order to actually
disable it by default we need an enterprise policy in case anyone is
relying on it.

After having this enterprise policy available, I will disable the
CSSCustomStateDeprecatedSyntax flag by default, and then after enough
milestones, I will remove the code for it and retire/deprecate this
enterprise policy.

This deprecation for the old syntax:
https://chromestatus.com/feature/5140610730426368
https://groups.google.com/a/chromium.org/g/blink-dev/c/JvpHoUfhJYE/m/uRtWiqoHAQAJ

The new syntax which has already been enabled by default:
https://chromestatus.com/feature/5586433790443520
https://groups.google.com/a/chromium.org/g/blink-dev/c/GDmNaxAuCY4/m/pwH7c4p6AAAJ

Bug: 1514397
Change-Id: I41785603403087a0a7e2e0d4e38ad2be6b012dc1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5538599
Reviewed-by: Chris Harrelson <chrishtr@chromium.org>
Reviewed-by: Victor Gabriel Savu <vsavu@google.com>
Reviewed-by: Igor <igorcov@chromium.org>
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/heads/main@{#1303748}
  • Loading branch information
josepharhar authored and Chromium LUCI CQ committed May 21, 2024
1 parent 03904bd commit 1aad67a
Show file tree
Hide file tree
Showing 15 changed files with 254 additions and 0 deletions.
9 changes: 9 additions & 0 deletions chrome/browser/chrome_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1608,6 +1608,10 @@ void ChromeContentBrowserClient::RegisterProfilePrefs(
registry->RegisterBooleanPref(policy::policy_prefs::kMutationEventsEnabled,
false);

registry->RegisterBooleanPref(
policy::policy_prefs::kCSSCustomStateDeprecatedSyntaxEnabled,
/*default_value=*/false);

registry->RegisterBooleanPref(
policy::policy_prefs::kBeforeunloadEventCancelByPreventDefaultEnabled,
true);
Expand Down Expand Up @@ -2684,6 +2688,11 @@ void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
command_line->AppendSwitch(
blink::switches::kKeyboardFocusableScrollersOptOut);
}
if (prefs->GetBoolean(
policy::policy_prefs::kCSSCustomStateDeprecatedSyntaxEnabled)) {
command_line->AppendSwitch(
blink::switches::kCSSCustomStateDeprecatedSyntaxEnabled);
}

if (prefs->GetBoolean(policy::policy_prefs::
kForcePermissionPolicyUnloadDefaultEnabled)) {
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/policy/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ source_set("policy_specific_browser_tests") {
"test/automatic_fullscreen_policy_browsertest.cc",
"test/back_forward_cache_policy_browsertest.cc",
"test/certificate_transparency_policy_browsertest.cc",
"test/css_custom_state_deprecated_syntax_policy_browsertest.cc",
"test/force_permission_policy_unload_default_enabled_policy_browsertest.cc",
"test/hsts_policy_browsertest.cc",
"test/keyboard_focusable_scollers_policy_browsertest.cc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2099,6 +2099,9 @@ const PolicyToPreferenceMapEntry kSimplePolicyMap[] = {
{ key::kMutationEventsEnabled,
policy_prefs::kMutationEventsEnabled,
base::Value::Type::BOOLEAN},
{ key::kCSSCustomStateDeprecatedSyntaxEnabled,
policy_prefs::kCSSCustomStateDeprecatedSyntaxEnabled,
base::Value::Type::BOOLEAN},
{ key::kBeforeunloadEventCancelByPreventDefaultEnabled,
policy_prefs::kBeforeunloadEventCancelByPreventDefaultEnabled,
base::Value::Type::BOOLEAN},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/test/scoped_feature_list.h"
#include "chrome/browser/policy/policy_test_utils.h"
#include "components/policy/policy_constants.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "third_party/blink/public/common/features.h"

namespace policy {

enum class Policy {
kDefault,
kTrue,
kFalse,
};

class CSSCustomStateDeprecatedSyntaxEnabledPolicyBrowserTest
: public PolicyTest,
public ::testing::WithParamInterface<Policy> {
public:
static std::string DescribeParams(
const ::testing::TestParamInfo<ParamType>& info) {
switch (info.param) {
case Policy::kDefault:
return "Default";
case Policy::kTrue:
return "True";
case Policy::kFalse:
return "False";
}
}

protected:
void SetUpCommandLine(base::CommandLine* command_line) override {
feature_list_.InitAndDisableFeature(
blink::features::kCSSCustomStateDeprecatedSyntax);
}

void SetUpInProcessBrowserTestFixture() override {
PolicyTest::SetUpInProcessBrowserTestFixture();

if (GetParam() == Policy::kDefault) {
return;
}
PolicyMap policies;
SetPolicy(&policies, key::kCSSCustomStateDeprecatedSyntaxEnabled,
base::Value(GetParam() == Policy::kTrue));
UpdateProviderPolicy(policies);
}

private:
base::test::ScopedFeatureList feature_list_;
};

IN_PROC_BROWSER_TEST_P(CSSCustomStateDeprecatedSyntaxEnabledPolicyBrowserTest,
PolicyIsFollowed) {
// Both false and the default (no parameter) should be disabled.
const bool expected_enabled = GetParam() == Policy::kTrue;

ASSERT_TRUE(embedded_test_server()->Start());
const GURL url(embedded_test_server()->GetURL(
"/css_custom_state_deprecated_syntax.html"));
ASSERT_TRUE(NavigateToUrl(url, this));

content::DOMMessageQueue message_queue(
chrome_test_utils::GetActiveWebContents(this));
std::string enabled_color = "\"rgb(255, 0, 0)\"";
std::string disabled_color = "\"rgb(0, 0, 255)\"";

content::ExecuteScriptAsync(
chrome_test_utils::GetActiveWebContents(this),
"window.domAutomationController.send(window.deprecatedSyntaxColor)");
std::string deprecated_syntax_color;
ASSERT_TRUE(message_queue.WaitForMessage(&deprecated_syntax_color));
std::string expected_color =
expected_enabled ? enabled_color : disabled_color;
EXPECT_EQ(deprecated_syntax_color, expected_color);

// The new syntax should always be enabled and should not be affected by this
// enterprise policy.
content::ExecuteScriptAsync(
chrome_test_utils::GetActiveWebContents(this),
"window.domAutomationController.send(window.newSyntaxColor)");
std::string new_syntax_color;
ASSERT_TRUE(message_queue.WaitForMessage(&new_syntax_color));
EXPECT_EQ(new_syntax_color, enabled_color);
}

INSTANTIATE_TEST_SUITE_P(
/* no prefix */,
CSSCustomStateDeprecatedSyntaxEnabledPolicyBrowserTest,
::testing::Values(Policy::kDefault, Policy::kTrue, Policy::kFalse),
&CSSCustomStateDeprecatedSyntaxEnabledPolicyBrowserTest::DescribeParams);

} // namespace policy
45 changes: 45 additions & 0 deletions chrome/test/data/css_custom_state_deprecated_syntax.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!DOCTYPE html>

<style>
deprecated-syntax-element, new-syntax-element {
color: blue;
}
deprecated-syntax-element:--foo {
color: red;
}
new-syntax-element:state(foo) {
color: red;
}
</style>

<deprecated-syntax-element>
<div>hello world</div>
</deprecated-syntax-element>
<new-syntax-element>
<div>hello world</div>
</new-syntax-element>

<script>
class DeprecatedSyntaxElement extends HTMLElement {
constructor() {
super();
this.internals = this.attachInternals();
this.internals.states.add('--foo');
}
};
customElements.define('deprecated-syntax-element', DeprecatedSyntaxElement);

class NewSyntaxElement extends HTMLElement {
constructor() {
super();
this.internals = this.attachInternals();
this.internals.states.add('foo');
}
};
customElements.define('new-syntax-element', NewSyntaxElement);

const deprecatedSyntaxElement = document.querySelector('deprecated-syntax-element');
const newSyntaxElement = document.querySelector('new-syntax-element');
window.deprecatedSyntaxColor = getComputedStyle(deprecatedSyntaxElement).color;
window.newSyntaxColor = getComputedStyle(newSyntaxElement).color;
</script>
5 changes: 5 additions & 0 deletions components/policy/core/common/policy_pref_names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ const char kLocalTestPoliciesForNextStartup[] =
const char kMutationEventsEnabled[] =
"policy.deprecated_mutation_events_enabled";

// Enables the deprecated :--foo syntax of CSS custom state. The :--foo syntax
// was deprecated and replaced by :state(foo).
const char kCSSCustomStateDeprecatedSyntaxEnabled[] =
"policy.css_custom_state_deprecated_syntax_enabled";

// A boolean pref indicating whether to allow deprecation of the "unload"
// event.
// If false, the deprecation rollout will be ignored.
Expand Down
1 change: 1 addition & 0 deletions components/policy/core/common/policy_pref_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ extern const char kPolicyTestPageEnabled[];
extern const char kAllowBackForwardCacheForCacheControlNoStorePageEnabled[];
extern const char kLocalTestPoliciesForNextStartup[];
extern const char kMutationEventsEnabled[];
extern const char kCSSCustomStateDeprecatedSyntaxEnabled[];
extern const char kForcePermissionPolicyUnloadDefaultEnabled[];
#if BUILDFLAG(IS_CHROMEOS)
extern const char kAlwaysOnVpnPreConnectUrlAllowlist[];
Expand Down
1 change: 1 addition & 0 deletions components/policy/resources/templates/policies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1258,6 +1258,7 @@ policies:
1257: LockScreenAutoStartOnlineReauth
1258: KeyboardFocusableScrollersEnabled
1259: ExtensibleEnterpriseSSOEnabled
1260: CSSCustomStateDeprecatedSyntaxEnabled
atomic_groups:
1: Homepage
2: RemoteAccess
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
caption: Controls whether the deprecated <ph name="CUSTOM_STATE_DEPRECATED_SYNTAX">:--foo</ph> syntax for CSS custom state is enabled
desc: |2-
The <ph name="CUSTOM_STATE_DEPRECATED_SYNTAX">:--foo</ph> syntax for the CSS custom state feature is being changed to <ph name="CUSTOM_STATE_NEW_SYNTAX">:state(foo)</ph> in <ph name="PRODUCT_NAME">$1<ex>Google Chrome</ex></ph> in order to comply with changes that have been made in <ph name="FIREFOX_PRODUCT_NAME">Firefox</ph> and <ph name="SAFARI_PRODUCT_NAME">Safari</ph>. This policy allows the old deprecated syntax to be enabled until M133.
The deprecation may break some <ph name="PRODUCT_NAME">$1<ex>Google Chrome</ex></ph>-only websites which use the deprecated <ph name="CUSTOM_STATE_DEPRECATED_SYNTAX">:--foo</ph> syntax.
If this policy is enabled, then the old deprecated syntax will be enabled.
If this policy is disabled, then the old deprecated syntax will be disabled.
If this policy is not set, then the old deprecated syntax will be disabled.
default: false
example_value: true
features:
dynamic_refresh: false
per_profile: true
items:
- caption: Old deprecated syntax will be enabled.
value: true
- caption: Old deprecated syntax will be disabled.
value: false
owners:
- jarhar@chromium.org
- masonf@chromium.org
- dom-dev@google.com
schema:
type: boolean
supported_on:
- chrome.*:127-
- chrome_os:127-
- android:127-
- webview_android:127-
tags: []
type: main
deprecated: false
device_only: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[
{
"os": [
"win",
"linux",
"mac",
"chromeos_ash",
"chromeos_lacros",
"android",
"fuchsia"
],
"policy_pref_mapping_tests": [
{
"policies": {
"CSSCustomStateDeprecatedSyntaxEnabled": true
},
"prefs": {
"policy.css_custom_state_deprecated_syntax_enabled": {
"value": true
}
}
},
{
"policies": {
"CSSCustomStateDeprecatedSyntaxEnabled": false
},
"prefs": {
"policy.css_custom_state_deprecated_syntax_enabled": {
"value": false
}
}
},
{
"policies": {},
"prefs": {
"policy.css_custom_state_deprecated_syntax_enabled": {
"default_value": false
}
}
}
]
}
]
2 changes: 2 additions & 0 deletions content/child/runtime_features.cc
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,8 @@ void SetRuntimeFeaturesFromCommandLine(const base::CommandLine& command_line) {
blink::switches::kKeyboardFocusableScrollersEnabled, true},
{wrf::EnableKeyboardFocusableScrollers,
blink::switches::kKeyboardFocusableScrollersOptOut, false},
{wrf::EnableCSSCustomStateDeprecatedSyntax,
blink::switches::kCSSCustomStateDeprecatedSyntaxEnabled, true},
{wrf::EnableTextFragmentIdentifiers,
switches::kDisableScrollToTextFragment, false},
{wrf::EnableWebAuthenticationRemoteDesktopSupport,
Expand Down
6 changes: 6 additions & 0 deletions third_party/blink/common/switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ const char kMinHeightForGpuRasterTile[] = "min-height-for-gpu-raster-tile";
extern const char kMutationEventsEnabled[] =
"deprecated-mutation-events-enabled";

// Used to communicate managed policy for CSSCustomStateDeprecatedSynatx. This
// feature is typically controlled by a RuntimeEnabledFeature, but requires an
// enterprise policy override.
extern const char kCSSCustomStateDeprecatedSyntaxEnabled[] =
"css-custom-state-deprecated-syntax-enabled";

// Sets the timeout seconds of the network-quiet timers in IdlenessDetector.
// Used by embedders who want to change the timeout time in order to run web
// contents on various embedded devices and changeable network bandwidths in
Expand Down
1 change: 1 addition & 0 deletions third_party/blink/public/common/switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ BLINK_COMMON_EXPORT extern const char kJavaScriptFlags[];
BLINK_COMMON_EXPORT extern const char kMaxUntiledLayerHeight[];
BLINK_COMMON_EXPORT extern const char kMaxUntiledLayerWidth[];
BLINK_COMMON_EXPORT extern const char kMutationEventsEnabled[];
BLINK_COMMON_EXPORT extern const char kCSSCustomStateDeprecatedSyntaxEnabled[];
BLINK_COMMON_EXPORT extern const char kMinHeightForGpuRasterTile[];
BLINK_COMMON_EXPORT extern const char kNetworkQuietTimeout[];
BLINK_COMMON_EXPORT extern const char kSharedArrayBufferAllowedOrigins[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,7 @@
// TODO(crbug.com/1514397): Remove this when the feature is fully launched.
name: "CSSCustomStateDeprecatedSyntax",
status: "stable",
public: true,
},
{
// This flag controls whether the :state(foo) pseudo-class for custom
Expand Down
1 change: 1 addition & 0 deletions tools/metrics/histograms/metadata/enterprise/enums.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2136,6 +2136,7 @@ chromium-metrics-reviews@google.com.
<int value="1257" label="LockScreenAutoStartOnlineReauth"/>
<int value="1258" label="KeyboardFocusableScrollersEnabled"/>
<int value="1259" label="ExtensibleEnterpriseSSOEnabled"/>
<int value="1260" label="CSSCustomStateDeprecatedSyntaxEnabled"/>
</enum>

<enum name="EnterprisePoliciesSources">
Expand Down

0 comments on commit 1aad67a

Please sign in to comment.