Commit 9b6d756c authored by suzyh's avatar suzyh Committed by Commit bot

Remove fetching stylesheets with unsupported type

Having deprecated stylesheet links with unsupported MIME types in
https://codereview.chromium.org/1501393003, this patch removes the
capability, updates the affected tests, and removes the UseCounter and
deprecation warning.

This patch also updates the preload scanner to ensure that the resources
are not preloaded, and adds a test to check for this.

BUG=286682

Review URL: https://codereview.chromium.org/1623403002

Cr-Commit-Position: refs/heads/master@{#371708}
parent feb0860c
main frame - didStartProvisionalLoadForFrame
main frame - didCommitLoadForFrame
main frame - didFinishDocumentLoadForFrame
CONSOLE MESSAGE: line 18: http://127.0.0.1:8000/resources/testharness.js
CONSOLE MESSAGE: line 18: http://127.0.0.1:8000/resources/testharnessreport.js
CONSOLE MESSAGE: line 18: http://127.0.0.1:8000/resources/slow-script.pl?delay=500
CONSOLE MESSAGE: line 18: http://127.0.0.1:8000/resources/dummy.css?1
CONSOLE MESSAGE: line 18: http://127.0.0.1:8000/resources/dummy.css?3
main frame - didHandleOnloadEventsForFrame
main frame - didFinishLoadForFrame
This is a testharness.js-based test.
PASS Makes sure that unsupported stylesheet types are neither preloaded nor loaded
Harness: the test ran to completion.
<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script>
var t = async_test('Makes sure that unsupported stylesheet types are neither preloaded nor loaded');
var cssLoaded = false;
var jsLoaded = false;
var noTypeLoaded = false;
</script>
<script src="../resources/slow-script.pl?delay=500"></script>
<link rel=stylesheet href="../resources/dummy.css?1" type="text/css" onload="cssLoaded = true;">
<link rel=stylesheet href="../resources/dummy.css?2" type="application/javascript" onload="jsLoaded = true;">
<link rel=stylesheet href="../resources/dummy.css?3" onload="noTypeLoaded = true;">
<script>
window.addEventListener("load", t.step_func(function() {
var entries = performance.getEntriesByType("resource");
for (var i = 0; i < entries.length; ++i) {
console.log(entries[i].name);
}
assert_equals(entries.length, 5);
assert_true(cssLoaded, "text/css triggered load event");
assert_false(jsLoaded, "application/javascript triggered load event");
assert_true(noTypeLoaded, "no type triggered load event");
t.done();
}));
</script>
<!DOCTYPE html>
<html>
<body>
<div style="color: blue" id="blue">This text should be blue</div>
<div style="color: green" id="red">This text should be green</div>
<div style="color: yellow" id="yellow">This text should be yellow</div>
</body>
</html>
CONSOLE WARNING: Using stylesheet links with types other than 'text/css' is deprecated and will be removed in M50, around April 2016.
This text should be blue
This text should be red and trigger a deprecation warning
This text should be yellow
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<body> <body>
<script>
if (window.testRunner)
testRunner.dumpAsText();
</script>
<link rel="stylesheet" type="text/css" href="data:text/css,#blue { color: blue !important; }"> <link rel="stylesheet" type="text/css" href="data:text/css,#blue { color: blue !important; }">
<link rel="stylesheet" type="application/javascript" href="data:text/css,#red { color: red !important; }"> <link rel="stylesheet" type="application/javascript" href="data:text/css,#red { color: red !important; }">
<link rel="stylesheet" href="data:text/css,#yellow { color: yellow !important; }"> <link rel="stylesheet" href="data:text/css,#yellow { color: yellow !important; }">
<div style="color: green" id="blue">This text should be blue</div> <div style="color: green" id="blue">This text should be blue</div>
<div style="color: green" id="red">This text should be red and trigger a deprecation warning</div> <div style="color: green" id="red">This text should be green</div>
<div style="color: green" id="yellow">This text should be yellow</div> <div style="color: green" id="yellow">This text should be yellow</div>
</body> </body>
</html> </html>
<!DOCTYPE html>
<html>
<body>
<div style="color: blue" id="blue">This text should be blue</div>
<div style="color: green" id="red">This text should be green</div>
<div style="color: yellow" id="yellow">This text should be yellow</div>
</body>
</html>
CONSOLE WARNING: Using stylesheet links with types other than 'text/css' is deprecated and will be removed in M50, around April 2016.
This text should be blue
This text should be red and trigger a deprecation warning
This text should be yellow
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<body> <body>
<script>
if (window.testRunner)
testRunner.dumpAsText();
</script>
<link rel="stylesheet" type="text/css" href="resources/blue.css"> <link rel="stylesheet" type="text/css" href="resources/blue.css">
<link rel="stylesheet" type="application/javascript" href="resources/red.css"> <link rel="stylesheet" type="application/javascript" href="resources/red.css">
<link rel="stylesheet" href="resources/yellow.css"> <link rel="stylesheet" href="resources/yellow.css">
<div style="color: green" id="blue">This text should be blue</div> <div style="color: green" id="blue">This text should be blue</div>
<div style="color: green" id="red">This text should be red and trigger a deprecation warning</div> <div style="color: green" id="red">This text should be green</div>
<div style="color: green" id="yellow">This text should be yellow</div> <div style="color: green" id="yellow">This text should be yellow</div>
</body> </body>
</html> </html>
...@@ -972,9 +972,6 @@ String UseCounter::deprecationMessage(Feature feature) ...@@ -972,9 +972,6 @@ String UseCounter::deprecationMessage(Feature feature)
case ObjectObserve: case ObjectObserve:
return willBeRemoved("'Object.observe'", 50, "6147094632988672"); return willBeRemoved("'Object.observe'", 50, "6147094632988672");
case NonCSSStyleSheetType:
return String::format("Using stylesheet links with types other than 'text/css' is deprecated and will be removed in %s.", milestoneString(50));
// Features that aren't deprecated don't have a deprecation message. // Features that aren't deprecated don't have a deprecation message.
default: default:
return String(); return String();
......
...@@ -976,7 +976,6 @@ public: ...@@ -976,7 +976,6 @@ public:
MediaDevicesEnumerateDevices = 1119, MediaDevicesEnumerateDevices = 1119,
NonSecureSharedWorkerAccessedFromSecureContext = 1120, NonSecureSharedWorkerAccessedFromSecureContext = 1120,
SecureSharedWorkerAccessedFromNonSecureContext = 1121, SecureSharedWorkerAccessedFromNonSecureContext = 1121,
NonCSSStyleSheetType = 1122,
EventDeepPath = 1123, EventDeepPath = 1123,
LinkHeaderPreload = 1124, LinkHeaderPreload = 1124,
MouseWheelEvent = 1125, MouseWheelEvent = 1125,
......
...@@ -721,10 +721,7 @@ void LinkStyle::process() ...@@ -721,10 +721,7 @@ void LinkStyle::process()
if (!m_owner->loadLink(type, as, builder.url())) if (!m_owner->loadLink(type, as, builder.url()))
return; return;
if (m_disabledState != Disabled && m_owner->relAttribute().isStyleSheet() && shouldLoadResource() && builder.url().isValid()) { if (m_disabledState != Disabled && m_owner->relAttribute().isStyleSheet() && styleSheetTypeIsSupported(type) && shouldLoadResource() && builder.url().isValid()) {
if (!styleSheetTypeIsSupported(type))
UseCounter::countDeprecation(document(), UseCounter::NonCSSStyleSheetType);
if (resource()) { if (resource()) {
removePendingSheet(); removePendingSheet();
clearResource(); clearResource();
......
...@@ -45,6 +45,8 @@ ...@@ -45,6 +45,8 @@
#include "core/html/parser/HTMLSrcsetParser.h" #include "core/html/parser/HTMLSrcsetParser.h"
#include "core/html/parser/HTMLTokenizer.h" #include "core/html/parser/HTMLTokenizer.h"
#include "core/loader/LinkLoader.h" #include "core/loader/LinkLoader.h"
#include "platform/ContentType.h"
#include "platform/MIMETypeRegistry.h"
#include "platform/RuntimeEnabledFeatures.h" #include "platform/RuntimeEnabledFeatures.h"
#include "platform/TraceEvent.h" #include "platform/TraceEvent.h"
#include "wtf/MainThread.h" #include "wtf/MainThread.h"
...@@ -116,6 +118,7 @@ public: ...@@ -116,6 +118,7 @@ public:
StartTagScanner(const StringImpl* tagImpl, PassRefPtrWillBeRawPtr<MediaValues> mediaValues) StartTagScanner(const StringImpl* tagImpl, PassRefPtrWillBeRawPtr<MediaValues> mediaValues)
: m_tagImpl(tagImpl) : m_tagImpl(tagImpl)
, m_linkIsStyleSheet(false) , m_linkIsStyleSheet(false)
, m_linkTypeIsMissingOrSupportedStyleSheet(true)
, m_linkIsPreconnect(false) , m_linkIsPreconnect(false)
, m_linkIsPreload(false) , m_linkIsPreload(false)
, m_linkIsImport(false) , m_linkIsImport(false)
...@@ -280,6 +283,8 @@ private: ...@@ -280,6 +283,8 @@ private:
setCrossOrigin(attributeValue); setCrossOrigin(attributeValue);
} else if (match(attributeName, asAttr)) { } else if (match(attributeName, asAttr)) {
m_asAttributeValue = attributeValue; m_asAttributeValue = attributeValue;
} else if (match(attributeName, typeAttr)) {
m_linkTypeIsMissingOrSupportedStyleSheet = MIMETypeRegistry::isSupportedStyleSheetMIMEType(ContentType(attributeValue).type());
} }
} }
...@@ -392,10 +397,13 @@ private: ...@@ -392,10 +397,13 @@ private:
return false; return false;
if (match(m_tagImpl, linkTag) && !m_linkIsStyleSheet && !m_linkIsImport && !m_linkIsPreload) if (match(m_tagImpl, linkTag) && !m_linkIsStyleSheet && !m_linkIsImport && !m_linkIsPreload)
return false; return false;
if (match(m_tagImpl, linkTag) && m_linkIsStyleSheet && !m_linkTypeIsMissingOrSupportedStyleSheet)
return false;
if (match(m_tagImpl, inputTag) && !m_inputIsImage) if (match(m_tagImpl, inputTag) && !m_inputIsImage)
return false; return false;
return true; return true;
} }
void setCrossOrigin(const String& corsSetting) void setCrossOrigin(const String& corsSetting)
{ {
m_crossOrigin = crossOriginAttributeValue(corsSetting); m_crossOrigin = crossOriginAttributeValue(corsSetting);
...@@ -416,6 +424,7 @@ private: ...@@ -416,6 +424,7 @@ private:
ImageCandidate m_srcsetImageCandidate; ImageCandidate m_srcsetImageCandidate;
String m_charset; String m_charset;
bool m_linkIsStyleSheet; bool m_linkIsStyleSheet;
bool m_linkTypeIsMissingOrSupportedStyleSheet;
bool m_linkIsPreconnect; bool m_linkIsPreconnect;
bool m_linkIsPreload; bool m_linkIsPreload;
bool m_linkIsImport; bool m_linkIsImport;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment