Handle meta viewport in HTMLPreloadScanner
authoryoav@yoav.ws <yoav@yoav.ws@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 7 May 2015 22:16:27 +0000 (22:16 +0000)
committeryoav@yoav.ws <yoav@yoav.ws@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 7 May 2015 22:16:27 +0000 (22:16 +0000)
https://bugs.webkit.org/show_bug.cgi?id=144640

Reviewed by Dean Jackson.

Source/WebCore:

Add support for the <meta> tag to the HTMLPreloadScanner
and when the meta tag's name is viewport, get the document
to process the tag's attribute value, and set its ViewportArgument.

Tests: fast/dom/HTMLMetaElement/meta-preloader.html

* html/parser/HTMLPreloadScanner.cpp:
(WebCore::TokenPreloadScanner::tagIdFor): Added meta.
(WebCore::TokenPreloadScanner::initiatorFor): Added meta.
(WebCore::TokenPreloadScanner::StartTagScanner::StartTagScanner): Call document.processViewport is meta viewport encountered.
(WebCore::TokenPreloadScanner::StartTagScanner::processAttributes):
(WebCore::TokenPreloadScanner::StartTagScanner::processAttribute): Keep track of meta viewport tags.
(WebCore::testPreloadScannerViewportSupport): Testing function that makes sure this functionality is working.
* html/parser/HTMLPreloadScanner.h:
* testing/Internals.cpp:
(WebCore::Internals::testPreloaderSettingViewport): Calls the testing function.
* testing/Internals.h:
* testing/Internals.idl:

LayoutTests:

Added a layout test that is simply calling an internals method
that tests the HTMLPreloadScanner.

* fast/dom/HTMLMetaElement/meta-preloader-expected.txt: Added.
* fast/dom/HTMLMetaElement/meta-preloader.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@183951 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/dom/HTMLMetaElement/meta-preloader-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/HTMLMetaElement/meta-preloader.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/html/parser/HTMLPreloadScanner.cpp
Source/WebCore/html/parser/HTMLPreloadScanner.h
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl

index 92f0119..8b0c20a 100644 (file)
@@ -1,3 +1,16 @@
+2015-05-07  Yoav Weiss  <yoav@yoav.ws>
+
+        Handle meta viewport in HTMLPreloadScanner
+        https://bugs.webkit.org/show_bug.cgi?id=144640
+
+        Reviewed by Dean Jackson.
+
+        Added a layout test that is simply calling an internals method
+        that tests the HTMLPreloadScanner.
+
+        * fast/dom/HTMLMetaElement/meta-preloader-expected.txt: Added.
+        * fast/dom/HTMLMetaElement/meta-preloader.html: Added.
+
 2015-05-07  Zalan Bujtas  <zalan@apple.com>
 
         REGRESSION (r164449): Subpixel rendering: http://www.apple.com/iphone-6/ "Faster wireless." image displays vertical black line on 1x displays at specific window width.
diff --git a/LayoutTests/fast/dom/HTMLMetaElement/meta-preloader-expected.txt b/LayoutTests/fast/dom/HTMLMetaElement/meta-preloader-expected.txt
new file mode 100644 (file)
index 0000000..5098a61
--- /dev/null
@@ -0,0 +1,2 @@
+You should see 1 line with "SUCCESS" below:
+SUCCESS (value: "true")
diff --git a/LayoutTests/fast/dom/HTMLMetaElement/meta-preloader.html b/LayoutTests/fast/dom/HTMLMetaElement/meta-preloader.html
new file mode 100644 (file)
index 0000000..b3ff1bd
--- /dev/null
@@ -0,0 +1,24 @@
+<html>
+<head>
+</head>
+<body>
+You should see 1 line with "SUCCESS" below:
+<div id=result></div>
+<script>
+if (window.testRunner)
+    testRunner.dumpAsText();
+
+function checkExpected(actual, expected)
+{
+    var result = document.getElementById("result");
+    if (actual != expected)
+        result.innerHTML = "<p>FAILURE: expected \"" + expected + "\", actual \"" + actual + "\"</p>";
+    else
+        result.innerHTML = "<p>SUCCESS (value: \"" + actual + "\")</p>";
+}
+
+if (window.internals)
+    checkExpected(internals.testPreloaderSettingViewport(), true);
+</script>
+</body>
+</html>
index 6184e7f..c0b7dd2 100644 (file)
@@ -1,3 +1,29 @@
+2015-05-07  Yoav Weiss  <yoav@yoav.ws>
+
+        Handle meta viewport in HTMLPreloadScanner
+        https://bugs.webkit.org/show_bug.cgi?id=144640
+
+        Reviewed by Dean Jackson.
+
+        Add support for the <meta> tag to the HTMLPreloadScanner
+        and when the meta tag's name is viewport, get the document
+        to process the tag's attribute value, and set its ViewportArgument.
+
+        Tests: fast/dom/HTMLMetaElement/meta-preloader.html
+
+        * html/parser/HTMLPreloadScanner.cpp:
+        (WebCore::TokenPreloadScanner::tagIdFor): Added meta.
+        (WebCore::TokenPreloadScanner::initiatorFor): Added meta.
+        (WebCore::TokenPreloadScanner::StartTagScanner::StartTagScanner): Call document.processViewport is meta viewport encountered.
+        (WebCore::TokenPreloadScanner::StartTagScanner::processAttributes):
+        (WebCore::TokenPreloadScanner::StartTagScanner::processAttribute): Keep track of meta viewport tags.
+        (WebCore::testPreloadScannerViewportSupport): Testing function that makes sure this functionality is working.
+        * html/parser/HTMLPreloadScanner.h:
+        * testing/Internals.cpp:
+        (WebCore::Internals::testPreloaderSettingViewport): Calls the testing function.
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
 2015-05-07  Zalan Bujtas  <zalan@apple.com>
 
         REGRESSION (r164449): Subpixel rendering: http://www.apple.com/iphone-6/ "Faster wireless." image displays vertical black line on 1x displays at specific window width.
index 3590436..d9f64f5 100644 (file)
@@ -58,6 +58,8 @@ TokenPreloadScanner::TagId TokenPreloadScanner::tagIdFor(const HTMLToken::DataVe
         return TagId::Base;
     if (tagName == templateTag)
         return TagId::Template;
+    if (tagName == metaTag)
+        return TagId::Meta;
     return TagId::Unknown;
 }
 
@@ -76,6 +78,7 @@ String TokenPreloadScanner::initiatorFor(TagId tagId)
     case TagId::Style:
     case TagId::Base:
     case TagId::Template:
+    case TagId::Meta:
         ASSERT_NOT_REACHED();
         return "unknown";
     }
@@ -88,6 +91,7 @@ public:
     explicit StartTagScanner(TagId tagId, float deviceScaleFactor = 1.0)
         : m_tagId(tagId)
         , m_linkIsStyleSheet(false)
+        , m_metaIsViewport(false)
         , m_inputIsImage(false)
         , m_deviceScaleFactor(deviceScaleFactor)
     {
@@ -116,6 +120,9 @@ public:
             ImageCandidate imageCandidate = bestFitSourceForImageAttributes(m_deviceScaleFactor, m_urlToLoad, m_srcSetAttribute, sourceSize);
             setUrlToLoad(imageCandidate.string.toString(), true);
         }
+
+        if (m_metaIsViewport && !m_metaContent.isNull())
+            document.processViewport(m_metaContent, ViewportArguments::ViewportMeta);
     }
 
     std::unique_ptr<PreloadRequest> createPreloadRequest(const URL& predictedBaseURL)
@@ -166,6 +173,11 @@ private:
                 setUrlToLoad(attributeValue);
             else if (match(attributeName, typeAttr))
                 m_inputIsImage = equalIgnoringCase(attributeValue, InputTypeNames::image());
+        } else if (m_tagId == TagId::Meta) {
+            if (match(attributeName, contentAttr))
+                m_metaContent = attributeValue;
+            else if (match(attributeName, nameAttr))
+                m_metaIsViewport = equalIgnoringCase(attributeValue, "viewport");
         }
     }
 
@@ -236,6 +248,8 @@ private:
     String m_crossOriginMode;
     bool m_linkIsStyleSheet;
     String m_mediaAttribute;
+    String m_metaContent;
+    bool m_metaIsViewport;
     bool m_inputIsImage;
     float m_deviceScaleFactor;
 };
@@ -347,4 +361,15 @@ void HTMLPreloadScanner::scan(HTMLResourcePreloader& preloader, Document& docume
     preloader.preload(WTF::move(requests));
 }
 
+bool testPreloadScannerViewportSupport(Document* document)
+{
+    ASSERT(document);
+    HTMLParserOptions options(*document);
+    HTMLPreloadScanner scanner(options, document->url());
+    HTMLResourcePreloader preloader(*document);
+    scanner.appendToEnd(String("<meta name=viewport content='width=400'>"));
+    scanner.scan(preloader, *document);
+    return (document->viewportArguments().width == 400);
+}
+
 }
index 1a9c283..b51a2d3 100644 (file)
@@ -49,6 +49,7 @@ private:
         Input,
         Link,
         Script,
+        Meta,
 
         // These tags are not scanned by the StartTagScanner.
         Unknown,
@@ -90,6 +91,8 @@ private:
     HTMLTokenizer m_tokenizer;
 };
 
+WEBCORE_EXPORT bool testPreloadScannerViewportSupport(Document*);
+
 }
 
 #endif
index 4ca3402..8829ee0 100644 (file)
@@ -58,6 +58,7 @@
 #include "HTMLInputElement.h"
 #include "HTMLNames.h"
 #include "HTMLPlugInElement.h"
+#include "HTMLPreloadScanner.h"
 #include "HTMLSelectElement.h"
 #include "HTMLTextAreaElement.h"
 #include "HTMLVideoElement.h"
@@ -2834,4 +2835,9 @@ String Internals::scrollSnapOffsets(Element* element, ExceptionCode& ec)
 }
 #endif
 
+bool Internals::testPreloaderSettingViewport()
+{
+    return testPreloadScannerViewportSupport(contextDocument());
+}
+
 }
index 1bab978..0941229 100644 (file)
@@ -395,6 +395,7 @@ public:
 
     RefPtr<File> createFile(const String&);
     void queueMicroTask(int);
+    bool testPreloaderSettingViewport();
 
 #if ENABLE(CONTENT_FILTERING)
     MockContentFilterSettings& mockContentFilterSettings();
index 02cd084..1b00980 100644 (file)
@@ -357,6 +357,7 @@ enum ResourceLoadPriority {
     
     File createFile(DOMString url);
     void queueMicroTask(long testNumber);
+    boolean testPreloaderSettingViewport();
 
     [Conditional=CONTENT_FILTERING] readonly attribute MockContentFilterSettings mockContentFilterSettings;