Source/WebCore: [Qt] Permit qrc resources to load in QWebSettings::setUserStyleSheetUrl()
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Sep 2011 16:41:59 +0000 (16:41 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Sep 2011 16:41:59 +0000 (16:41 +0000)
https://bugs.webkit.org/show_bug.cgi?id=51159

Permit any URL with a local scheme to set a user style sheet. Allow qrc
resource URLs as arguments to QWebSettings::setUserStyleSheetUrl().

Patch by Jarred Nicholls <jarred@sencha.com> on 2011-09-20
Reviewed by Kenneth Rohde Christiansen.

* page/Page.cpp:
(WebCore::Page::userStyleSheetLocationChanged):
* platform/qt/KURLQt.cpp:
(WebCore::KURL::fileSystemPath):

Source/WebKit/qt: [Qt] Permit qrc resources to load in QWebSettings::setUserStyleSheetUrl()
https://bugs.webkit.org/show_bug.cgi?id=51159

Permit any URL with a local scheme to set a user style sheet. Allow qrc
resource URLs as arguments to QWebSettings::setUserStyleSheetUrl().

New test case makes sure a qrc URL will properly load a user stylesheet.

Patch by Jarred Nicholls <jarred@sencha.com> on 2011-09-20
Reviewed by Kenneth Rohde Christiansen.

(tst_QWebPage::userStyleSheetFromQrcUrl):
* tests/qwebpage/tst_qwebpage.qrc:

Tools: [Qt] Permit qrc resources to load in QWebSettings::setUserStyleSheetUrl()
https://bugs.webkit.org/show_bug.cgi?id=51159

Permit any URL with a local scheme to set a user style sheet. Allow qrc
resource URLs as arguments to QWebSettings::setUserStyleSheetUrl().

Add DRT/WKTR qrc resource to test loading user style sheets from a qrc URL.

Patch by Jarred Nicholls <jarred@sencha.com> on 2011-09-20
Reviewed by Kenneth Rohde Christiansen.

* DumpRenderTree/qt/DumpRenderTree.pro:
* DumpRenderTree/qt/DumpRenderTree.qrc: Added.
* DumpRenderTree/qt/resources/user.css: Added.
(body):
* WebKitTestRunner/qt/WebKitTestRunner.pro:
* WebKitTestRunner/qt/WebKitTestRunner.qrc: Added.
* WebKitTestRunner/qt/resources/user.css: Added.
(body):

LayoutTests: [Qt] Permit qrc resources to load in QWebSettings::setUserStyleSheetUrl()
https://bugs.webkit.org/show_bug.cgi?id=51159

Permit any URL with a local scheme to set a user style sheet. Allow qrc
resource URLs as arguments to QWebSettings::setUserStyleSheetUrl().

New platform layout test since user style sheet is testable from DRT.

Patch by Jarred Nicholls <jarred@sencha.com> on 2011-09-20
Reviewed by Kenneth Rohde Christiansen.

* platform/qt/fast/loader/user-stylesheet-qrc-path-expected.txt: Added.
* platform/qt/fast/loader/user-stylesheet-qrc-path.html: Added.

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

16 files changed:
LayoutTests/ChangeLog
LayoutTests/platform/qt/fast/loader/user-stylesheet-qrc-path-expected.txt [new file with mode: 0644]
LayoutTests/platform/qt/fast/loader/user-stylesheet-qrc-path.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/page/Page.cpp
Source/WebCore/platform/qt/KURLQt.cpp
Source/WebKit/qt/ChangeLog
Source/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp
Source/WebKit/qt/tests/qwebpage/tst_qwebpage.qrc
Tools/ChangeLog
Tools/DumpRenderTree/qt/DumpRenderTree.pro
Tools/DumpRenderTree/qt/DumpRenderTree.qrc [new file with mode: 0644]
Tools/DumpRenderTree/qt/resources/user.css [new file with mode: 0644]
Tools/WebKitTestRunner/qt/WebKitTestRunner.pro
Tools/WebKitTestRunner/qt/WebKitTestRunner.qrc [new file with mode: 0644]
Tools/WebKitTestRunner/qt/resources/user.css [new file with mode: 0644]

index 1630140..18cab82 100644 (file)
@@ -1,3 +1,18 @@
+2011-09-20  Jarred Nicholls  <jarred@sencha.com>
+
+        [Qt] Permit qrc resources to load in QWebSettings::setUserStyleSheetUrl()
+        https://bugs.webkit.org/show_bug.cgi?id=51159
+
+        Permit any URL with a local scheme to set a user style sheet. Allow qrc
+        resource URLs as arguments to QWebSettings::setUserStyleSheetUrl().
+
+        New platform layout test since user style sheet is testable from DRT.
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        * platform/qt/fast/loader/user-stylesheet-qrc-path-expected.txt: Added.
+        * platform/qt/fast/loader/user-stylesheet-qrc-path.html: Added.
+
 2011-09-20  Dmitry Lomov  <dslomov@google.com>
 
         [Chromium] Rebaseline expectationd and file WK68445.
diff --git a/LayoutTests/platform/qt/fast/loader/user-stylesheet-qrc-path-expected.txt b/LayoutTests/platform/qt/fast/loader/user-stylesheet-qrc-path-expected.txt
new file mode 100644 (file)
index 0000000..68a28f1
--- /dev/null
@@ -0,0 +1,3 @@
+This tests that a qrc URL is properly loaded as a user style sheet.
+
+PASS 50px rgb(255, 255, 0)
diff --git a/LayoutTests/platform/qt/fast/loader/user-stylesheet-qrc-path.html b/LayoutTests/platform/qt/fast/loader/user-stylesheet-qrc-path.html
new file mode 100644 (file)
index 0000000..368d2a3
--- /dev/null
@@ -0,0 +1,18 @@
+<p>
+    This tests that a qrc URL is properly loaded as a user style sheet.
+</p>
+<script>
+    if (window.layoutTestController) {
+        layoutTestController.dumpAsText();
+        layoutTestController.setUserStyleSheetEnabled(true);
+        layoutTestController.setUserStyleSheetLocation('qrc:///resources/user.css');
+        
+        var computedStyle = getComputedStyle(document.body),
+            result = computedStyle.fontSize == '50px' && computedStyle.backgroundColor == 'rgb(255, 255, 0)',
+            message = (result ? 'PASS' : 'FAIL') + ' ' + computedStyle.fontSize + ' ' + computedStyle.backgroundColor;
+
+        document.write(message);
+    } else {
+        document.write("This test can only be run in DumpRenderTree.");
+    }
+</script>
index 979c030..fc9fce9 100644 (file)
@@ -1,3 +1,18 @@
+2011-09-20  Jarred Nicholls  <jarred@sencha.com>
+
+        [Qt] Permit qrc resources to load in QWebSettings::setUserStyleSheetUrl()
+        https://bugs.webkit.org/show_bug.cgi?id=51159
+        
+        Permit any URL with a local scheme to set a user style sheet. Allow qrc
+        resource URLs as arguments to QWebSettings::setUserStyleSheetUrl().
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        * page/Page.cpp:
+        (WebCore::Page::userStyleSheetLocationChanged):
+        * platform/qt/KURLQt.cpp:
+        (WebCore::KURL::fileSystemPath):
+
 2011-09-20  Csaba Osztrogonác  <ossy@webkit.org>
 
         [Qt][Mac] Buildfix after r95513.
index e563d10..be52797 100644 (file)
@@ -63,6 +63,7 @@
 #include "RenderTheme.h"
 #include "RenderWidget.h"
 #include "RuntimeEnabledFeatures.h"
+#include "SchemeRegistry.h"
 #include "Settings.h"
 #include "SharedBuffer.h"
 #include "SpeechInput.h"
@@ -686,7 +687,9 @@ void Page::userStyleSheetLocationChanged()
     // FIXME: Eventually we will move to a model of just being handed the sheet
     // text instead of loading the URL ourselves.
     KURL url = m_settings->userStyleSheetLocation();
-    if (url.isLocalFile())
+    
+    // Allow any local file URL scheme to be loaded.
+    if (SchemeRegistry::shouldTreatURLSchemeAsLocal(url.protocol()))
         m_userStyleSheetPath = url.fileSystemPath();
     else
         m_userStyleSheetPath = String();
index 49df59a..c8f9ed7 100644 (file)
@@ -43,10 +43,17 @@ KURL::operator QUrl() const
 
 String KURL::fileSystemPath() const
 {
-    if (!isValid() || !protocolIs("file"))
+    if (!isValid())
         return String();
 
-    return static_cast<QUrl>(*this).toLocalFile();
+    if (isLocalFile())
+        return static_cast<QUrl>(*this).toLocalFile();
+
+    // A valid qrc resource path begins with a colon.
+    if (protocolIs("qrc"))
+        return ":" + path();
+
+    return String();
 }
 
 }
index 2bfb809..c28af21 100644 (file)
@@ -1,3 +1,18 @@
+2011-09-20  Jarred Nicholls  <jarred@sencha.com>
+
+        [Qt] Permit qrc resources to load in QWebSettings::setUserStyleSheetUrl()
+        https://bugs.webkit.org/show_bug.cgi?id=51159
+        
+        Permit any URL with a local scheme to set a user style sheet. Allow qrc
+        resource URLs as arguments to QWebSettings::setUserStyleSheetUrl().
+        
+        New test case makes sure a qrc URL will properly load a user stylesheet.
+
+        Reviewed by Kenneth Rohde Christiansen.
+        
+        (tst_QWebPage::userStyleSheetFromQrcUrl):
+        * tests/qwebpage/tst_qwebpage.qrc:
+
 2011-09-20  Adenilson Cavalcanti  <adenilson.silva@openbossa.org>
 
         [Qt] resizeToContent seems to trigger infinite resize on some pages
index d7b56fe..5558c30 100644 (file)
@@ -103,6 +103,7 @@ private slots:
     void acceptNavigationRequestWithNewWindow();
     void userStyleSheet();
     void userStyleSheetFromLocalFileUrl();
+    void userStyleSheetFromQrcUrl();
     void loadHtml5Video();
     void modified();
     void contextMenuCrash();
@@ -504,6 +505,19 @@ void tst_QWebPage::userStyleSheetFromLocalFileUrl()
     QCOMPARE(networkManager->requestedUrls.at(0), QUrl("http://does.not/exist.png"));
 }
 
+void tst_QWebPage::userStyleSheetFromQrcUrl()
+{
+    TestNetworkManager* networkManager = new TestNetworkManager(m_page);
+    m_page->setNetworkAccessManager(networkManager);
+
+    m_page->settings()->setUserStyleSheetUrl(QUrl("qrc:///resources/user.css"));
+    m_view->setHtml("<p>hello world</p>");
+    QVERIFY(::waitForSignal(m_view, SIGNAL(loadFinished(bool))));
+
+    QVERIFY(networkManager->requestedUrls.count() >= 1);
+    QCOMPARE(networkManager->requestedUrls.at(0), QUrl("http://does.not/exist.png"));
+}
+
 void tst_QWebPage::loadHtml5Video()
 {
 #if defined(WTF_USE_QT_MULTIMEDIA) && WTF_USE_QT_MULTIMEDIA
index 7ddc462..ab78dfa 100644 (file)
@@ -9,6 +9,7 @@
     <file>resources/framedindex.html</file>
     <file>resources/content.html</file>
     <file>resources/script.html</file>
+    <file>resources/user.css</file>
 </qresource>
 </RCC>
 
index 0fc1d9e..27c4db9 100644 (file)
@@ -1,3 +1,24 @@
+2011-09-20  Jarred Nicholls  <jarred@sencha.com>
+
+        [Qt] Permit qrc resources to load in QWebSettings::setUserStyleSheetUrl()
+        https://bugs.webkit.org/show_bug.cgi?id=51159
+
+        Permit any URL with a local scheme to set a user style sheet. Allow qrc
+        resource URLs as arguments to QWebSettings::setUserStyleSheetUrl().
+        
+        Add DRT/WKTR qrc resource to test loading user style sheets from a qrc URL.
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        * DumpRenderTree/qt/DumpRenderTree.pro:
+        * DumpRenderTree/qt/DumpRenderTree.qrc: Added.
+        * DumpRenderTree/qt/resources/user.css: Added.
+        (body):
+        * WebKitTestRunner/qt/WebKitTestRunner.pro:
+        * WebKitTestRunner/qt/WebKitTestRunner.qrc: Added.
+        * WebKitTestRunner/qt/resources/user.css: Added.
+        (body):
+
 2011-09-20  Leandro Pereira  <leandro@profusion.mobi>
 
         ChangeLogEntry class should contain a list of touched files
index 242651d..e81086a 100644 (file)
@@ -53,3 +53,5 @@ wince*: {
 
 DEFINES += USE_SYSTEM_MALLOC=1
 DEFINES -= QT_ASCII_CAST_WARNINGS
+
+RESOURCES = DumpRenderTree.qrc
\ No newline at end of file
diff --git a/Tools/DumpRenderTree/qt/DumpRenderTree.qrc b/Tools/DumpRenderTree/qt/DumpRenderTree.qrc
new file mode 100644 (file)
index 0000000..71d163a
--- /dev/null
@@ -0,0 +1,5 @@
+<RCC>
+    <qresource prefix="/">
+        <file>resources/user.css</file>
+    </qresource>
+</RCC>
diff --git a/Tools/DumpRenderTree/qt/resources/user.css b/Tools/DumpRenderTree/qt/resources/user.css
new file mode 100644 (file)
index 0000000..af39819
--- /dev/null
@@ -0,0 +1,4 @@
+body {
+    font-size: 50px;
+    background-color: rgb(255, 255, 0);
+}
\ No newline at end of file
index 8e10720..e6c7094 100644 (file)
@@ -65,3 +65,5 @@ linux-* {
 
 include(../../../Source/JavaScriptCore/JavaScriptCore.pri)
 prependJavaScriptCoreLib(../../JavaScriptCore)
+
+RESOURCES = WebKitTestRunner.qrc
\ No newline at end of file
diff --git a/Tools/WebKitTestRunner/qt/WebKitTestRunner.qrc b/Tools/WebKitTestRunner/qt/WebKitTestRunner.qrc
new file mode 100644 (file)
index 0000000..71d163a
--- /dev/null
@@ -0,0 +1,5 @@
+<RCC>
+    <qresource prefix="/">
+        <file>resources/user.css</file>
+    </qresource>
+</RCC>
diff --git a/Tools/WebKitTestRunner/qt/resources/user.css b/Tools/WebKitTestRunner/qt/resources/user.css
new file mode 100644 (file)
index 0000000..af39819
--- /dev/null
@@ -0,0 +1,4 @@
+body {
+    font-size: 50px;
+    background-color: rgb(255, 255, 0);
+}
\ No newline at end of file