Skip to content

Commit

Permalink
Deprecate CSSStyleSheet.replace() with @import rules
Browse files Browse the repository at this point in the history
See the CSS Resolution [1], the I2R [2], and the chromestatus
entry [3].

[1] WICG/construct-stylesheets#119 (comment)
[2] https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/RKG8oxp22RY
[3] https://chromestatus.com/feature/4735925877735424

Bug: 1055943
Change-Id: I0f71af0d3dae5001a9ba93d1b5e41a859be6481f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2073204
Commit-Queue: Rune Lillesveen <[email protected]>
Auto-Submit: Mason Freed <[email protected]>
Reviewed-by: Rune Lillesveen <[email protected]>
Cr-Commit-Position: refs/heads/master@{#744588}
  • Loading branch information
mfreed7 authored and Commit Bot committed Feb 26, 2020
1 parent 48e7589 commit 13a53ff
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2512,6 +2512,7 @@ enum WebFeature {
kXRSessionRequestHitTestSource = 3166,
kXRSessionRequestHitTestSourceForTransientInput = 3167,
kXRDOMOverlay = 3168,
kCssStyleSheetReplaceWithImport = 3169,

// Add new features immediately above this line. Don't change assigned
// numbers of any item, and don't reuse removed slots.
Expand Down
3 changes: 3 additions & 0 deletions third_party/blink/renderer/core/css/css_style_sheet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,9 @@ ScriptPromise CSSStyleSheet::replace(ScriptState* script_state,
SetText(text, true /* allow_import_rules */, exception_state);
if (!IsLoading())
return ScriptPromise::Cast(script_state, ToV8(this, script_state));
// We're loading a stylesheet that contains @import rules. This is deprecated.
Deprecation::CountDeprecation(OwnerDocument(),
WebFeature::kCssStyleSheetReplaceWithImport);
resolver_ = MakeGarbageCollected<ScriptPromiseResolver>(script_state);
return resolver_->Promise();
}
Expand Down
14 changes: 14 additions & 0 deletions third_party/blink/renderer/core/frame/deprecation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ enum Milestone {
kM80 = 80,
kM81 = 81,
kM82 = 82,
kM83 = 83,
};

// Returns estimated milestone dates as milliseconds since January 1, 1970.
Expand Down Expand Up @@ -101,6 +102,8 @@ base::Time::Exploded MilestoneDate(Milestone milestone) {
return {2020, 3, 0, 17, 4};
case kM82:
return {2020, 4, 0, 28, 4};
case kM83:
return {2020, 6, 0, 9, 4};
}

NOTREACHED();
Expand Down Expand Up @@ -506,6 +509,17 @@ DeprecationInfo GetDeprecationInfo(WebFeature feature) {
"Please check with your partner to have this fixed.",
MilestoneString(kM81).Ascii().c_str())};

case WebFeature::kCssStyleSheetReplaceWithImport:
return {
"CssStyleSheetReplaceWithImport", kM83,
String::Format(
"Support for calls to CSSStyleSheet.replace() with stylesheet "
"text that includes @import has been deprecated, and will be "
"removed in %s. See "
"https://chromestatus.com/feature/4735925877735424 for more "
"details.",
MilestoneString(kM83).Ascii().c_str())};

// Features that aren't deprecated don't have a deprecation message.
default:
return {"NotDeprecated", kUnknown, ""};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CONSOLE MESSAGE: line 6: Start script - there should be a deprecation message below about replace() and @import.
CONSOLE WARNING: line 9: Support for calls to CSSStyleSheet.replace() with stylesheet text that includes @import has been deprecated, and will be removed in M83, around June 2020. See https://chromestatus.com/feature/4735925877735424 for more details.
CONSOLE MESSAGE: line 15: Finish script
CONSOLE MESSAGE: line 10: Replace resolved

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>

<script>
if (window.testRunner)
testRunner.dumpAsText();
console.log("Start script - there should be a deprecation message below about replace() and @import.");
const sheet = new CSSStyleSheet();
try {
sheet.replace('@import "resources/import.css";')
.then(() => {console.log("Replace resolved");});
} catch (e) {
console.log("Replace threw exception");
}

console.log("Finish script");
</script>
1 change: 1 addition & 0 deletions tools/metrics/histograms/enums.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26576,6 +26576,7 @@ to ensure that the crash string is shown properly on the user-facing crash UI.
<int value="3166" label="XRSessionRequestHitTestSource"/>
<int value="3167" label="XRSessionRequestHitTestSourceForTransientInput"/>
<int value="3168" label="XRDOMOverlay"/>
<int value="3169" label="CssStyleSheetReplaceWithImport"/>
</enum>

<enum name="FeaturePolicyAllowlistType">
Expand Down

0 comments on commit 13a53ff

Please sign in to comment.