REGRESSION(r135082): Restore the ability to insert author level style sheets from...
authortony@chromium.org <tony@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 Dec 2012 21:19:12 +0000 (21:19 +0000)
committertony@chromium.org <tony@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 Dec 2012 21:19:12 +0000 (21:19 +0000)
https://bugs.webkit.org/show_bug.cgi?id=104042

Reviewed by Antti Koivisto.

.:

Update exports for Internals.cpp.

* Source/autotools/symbols.filter:

Source/WebCore:

Add DocumentStyleSheetCollection::addAuthorSheet so embedders can allow scripts
to insert author level styles. Expose the method to window.interals for testing.

Test: userscripts/insert-stylesheets.html

* WebCore.exp.in: Update exports for Internals.cpp.
* WebCore.order: Update exports for Internals.cpp.
* dom/DocumentStyleSheetCollection.cpp:
(WebCore::DocumentStyleSheetCollection::~DocumentStyleSheetCollection):
(WebCore::DocumentStyleSheetCollection::addAuthorSheet): Add the stylesheet and force a style recalc.
(WebCore::DocumentStyleSheetCollection::updateActiveStyleSheets): Include author level styles.
(WebCore::DocumentStyleSheetCollection::reportMemoryUsage): Include author styles.
* dom/DocumentStyleSheetCollection.h:
(WebCore::DocumentStyleSheetCollection::documentAuthorStyleSheets): Accessor.
(DocumentStyleSheetCollection): Keep track of author styles added by script.
* testing/Internals.cpp:
(WebCore::Internals::insertAuthorCSS): Testing addAuthorSheet.
(WebCore::Internals::insertUserCSS): Testing addUserSheet.
* testing/Internals.h:
* testing/Internals.idl: Add addAuthorSheet and addUserSheet.

Source/WebKit/chromium:

* src/WebDocument.cpp:
(WebKit::WebDocument::insertUserStyleSheet): Use addAuthorSheet if an author level script is requested.

Source/WebKit2:

Update exports for Internals.cpp.

* win/WebKit2.def.in:

LayoutTests:

Add a test that makes sure that an author level style is set.

* userscripts/insert-stylesheets-expected.txt: Added.
* userscripts/insert-stylesheets.html: Added.

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

17 files changed:
ChangeLog
LayoutTests/ChangeLog
LayoutTests/userscripts/insert-stylesheets-expected.txt [new file with mode: 0644]
LayoutTests/userscripts/insert-stylesheets.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/WebCore.order
Source/WebCore/dom/DocumentStyleSheetCollection.cpp
Source/WebCore/dom/DocumentStyleSheetCollection.h
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/src/WebDocument.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/win/WebKit2.def.in
Source/autotools/symbols.filter

index 599c096..76e7a67 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2012-12-06  Tony Chang  <tony@chromium.org>
+
+        REGRESSION(r135082): Restore the ability to insert author level style sheets from script
+        https://bugs.webkit.org/show_bug.cgi?id=104042
+
+        Reviewed by Antti Koivisto.
+
+        Update exports for Internals.cpp.
+
+        * Source/autotools/symbols.filter:
+
 2012-12-06  Laszlo Gombos  <l.gombos@samsung.com>
 
         [EFL] Optimize binary size by removing dead sections on unix/gcc
index 3fc55c4..0db6615 100644 (file)
@@ -1,3 +1,15 @@
+2012-12-06  Tony Chang  <tony@chromium.org>
+
+        REGRESSION(r135082): Restore the ability to insert author level style sheets from script
+        https://bugs.webkit.org/show_bug.cgi?id=104042
+
+        Reviewed by Antti Koivisto.
+
+        Add a test that makes sure that an author level style is set.
+
+        * userscripts/insert-stylesheets-expected.txt: Added.
+        * userscripts/insert-stylesheets.html: Added.
+
 2012-12-06  Stephen White  <senorblanco@chromium.org>
 
         [Chromium] Unreviewed gardening.
diff --git a/LayoutTests/userscripts/insert-stylesheets-expected.txt b/LayoutTests/userscripts/insert-stylesheets-expected.txt
new file mode 100644 (file)
index 0000000..8cbf085
--- /dev/null
@@ -0,0 +1,9 @@
+PASS getComputedStyle(testElement).backgroundColor is 'rgb(255, 0, 0)'
+PASS testElement.offsetWidth is 0
+PASS getComputedStyle(testElement).backgroundColor is 'rgb(255, 0, 0)'
+PASS testElement.offsetWidth is 0
+PASS getComputedStyle(testElement).backgroundColor is 'rgb(0, 128, 0)'
+PASS testElement.offsetWidth is 100
+This test requires testRunner and window.internals.
+
+
diff --git a/LayoutTests/userscripts/insert-stylesheets.html b/LayoutTests/userscripts/insert-stylesheets.html
new file mode 100644 (file)
index 0000000..0f7abce
--- /dev/null
@@ -0,0 +1,43 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<style>
+  .styled {
+      background-color: red;
+      width: 0;
+      height: 100px;
+  }
+</style>
+<script src="../fast/js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p>This test requires testRunner and window.internals.</p>
+<div id="test" class="styled"></div>
+<script>
+function test()
+{
+    if (!window.testRunner)
+        return;
+    testRunner.dumpAsText();
+    window.testElement = document.getElementById("test");
+    shouldBe("getComputedStyle(testElement).backgroundColor", "'rgb(255, 0, 0)'");
+    shouldBe("testElement.offsetWidth", "0");
+
+    if (!window.internals)
+        return;
+
+    // The author style above should override this user style.
+    internals.insertUserCSS(document, "body .styled { background-color: green; width: 100px; }");
+    shouldBe("getComputedStyle(testElement).backgroundColor", "'rgb(255, 0, 0)'");
+    shouldBe("testElement.offsetWidth", "0");
+
+    // Since this style is more specific, it should override the original author style above.
+    internals.insertAuthorCSS(document, "body .styled { background-color: green; width: 100px; }");
+    shouldBe("getComputedStyle(testElement).backgroundColor", "'rgb(0, 128, 0)'");
+    shouldBe("testElement.offsetWidth", "100");
+}
+
+test();
+</script>
+</body>
+</html>
index 57fe80a..4ea1a6f 100644 (file)
@@ -1,3 +1,31 @@
+2012-12-06  Tony Chang  <tony@chromium.org>
+
+        REGRESSION(r135082): Restore the ability to insert author level style sheets from script
+        https://bugs.webkit.org/show_bug.cgi?id=104042
+
+        Reviewed by Antti Koivisto.
+
+        Add DocumentStyleSheetCollection::addAuthorSheet so embedders can allow scripts
+        to insert author level styles. Expose the method to window.interals for testing.
+
+        Test: userscripts/insert-stylesheets.html
+
+        * WebCore.exp.in: Update exports for Internals.cpp.
+        * WebCore.order: Update exports for Internals.cpp.
+        * dom/DocumentStyleSheetCollection.cpp:
+        (WebCore::DocumentStyleSheetCollection::~DocumentStyleSheetCollection):
+        (WebCore::DocumentStyleSheetCollection::addAuthorSheet): Add the stylesheet and force a style recalc.
+        (WebCore::DocumentStyleSheetCollection::updateActiveStyleSheets): Include author level styles.
+        (WebCore::DocumentStyleSheetCollection::reportMemoryUsage): Include author styles.
+        * dom/DocumentStyleSheetCollection.h:
+        (WebCore::DocumentStyleSheetCollection::documentAuthorStyleSheets): Accessor.
+        (DocumentStyleSheetCollection): Keep track of author styles added by script.
+        * testing/Internals.cpp:
+        (WebCore::Internals::insertAuthorCSS): Testing addAuthorSheet.
+        (WebCore::Internals::insertUserCSS): Testing addUserSheet.
+        * testing/Internals.h:
+        * testing/Internals.idl: Add addAuthorSheet and addUserSheet.
+
 2012-12-06  Elliott Sprehn  <esprehn@gmail.com>
 
         Create only NodeRareDataBase when setting TreeScope
index bb7ccb7..5a45d5d 100644 (file)
@@ -1484,6 +1484,12 @@ __ZTVN7WebCore16IconDatabaseBaseE
 __ZTVN7WebCore17FrameLoaderClientE
 __ZTVN7WebCore25HistoryPropertyListWriterE
 __ZTVN7WebCore28InspectorFrontendClientLocal8SettingsE
+__ZN7WebCore16CSSParserContextC1EPNS_8DocumentERKNS_4KURLERKN3WTF6StringE
+__ZN7WebCore18StyleSheetContents11parseStringERKN3WTF6StringE
+__ZN7WebCore18StyleSheetContentsC1EPNS_15StyleRuleImportERKN3WTF6StringERKNS_16CSSParserContextE
+__ZN7WebCore18StyleSheetContentsD1Ev
+__ZN7WebCore28DocumentStyleSheetCollection12addUserSheetEN3WTF10PassRefPtrINS_18StyleSheetContentsEEE
+__ZN7WebCore28DocumentStyleSheetCollection14addAuthorSheetEN3WTF10PassRefPtrINS_18StyleSheetContentsEEE
 _filenameByFixingIllegalCharacters
 _hasCaseInsensitivePrefix
 _hasCaseInsensitiveSubstring
index c1f90a4..00f6f14 100644 (file)
@@ -31878,3 +31878,9 @@ __ZN7WebCore5TimerINS_12RenderButtonEED0Ev
 __ZN7WebCore21jsDocumentOnmousemoveEPN3JSC9ExecStateENS0_7JSValueERKNS0_10IdentifierE
 __ZN7WebCore14StorageTracker8isActiveEv
 __ZN7WebCore14StorageTracker12deleteOriginERKN3WTF6StringE
+__ZN7WebCore16CSSParserContextC1EPNS_8DocumentERKNS_4KURLERKN3WTF6StringE
+__ZN7WebCore18StyleSheetContents11parseStringERKN3WTF6StringE
+__ZN7WebCore18StyleSheetContentsC1EPNS_15StyleRuleImportERKN3WTF6StringERKNS_16CSSParserContextE
+__ZN7WebCore18StyleSheetContentsD1Ev
+__ZN7WebCore28DocumentStyleSheetCollection12addUserSheetEN3WTF10PassRefPtrINS_18StyleSheetContentsEEE
+__ZN7WebCore28DocumentStyleSheetCollection14addAuthorSheetEN3WTF10PassRefPtrINS_18StyleSheetContentsEEE
index a531212..5e8e7ce 100644 (file)
@@ -81,6 +81,8 @@ DocumentStyleSheetCollection::~DocumentStyleSheetCollection()
         m_injectedAuthorStyleSheets[i]->clearOwnerNode();
     for (unsigned i = 0; i < m_userStyleSheets.size(); ++i)
         m_userStyleSheets[i]->clearOwnerNode();
+    for (unsigned i = 0; i < m_authorStyleSheets.size(); ++i)
+        m_authorStyleSheets[i]->clearOwnerNode();
 }
 
 void DocumentStyleSheetCollection::combineCSSFeatureFlags()
@@ -191,6 +193,13 @@ void DocumentStyleSheetCollection::invalidateInjectedStyleSheetCache()
     m_document->styleResolverChanged(DeferRecalcStyle);
 }
 
+void DocumentStyleSheetCollection::addAuthorSheet(PassRefPtr<StyleSheetContents> authorSheet)
+{
+    ASSERT(!authorSheet->isUserStyleSheet());
+    m_authorStyleSheets.append(CSSStyleSheet::create(authorSheet, m_document));
+    m_document->styleResolverChanged(RecalcStyleImmediately);
+}
+
 void DocumentStyleSheetCollection::addUserSheet(PassRefPtr<StyleSheetContents> userSheet)
 {
     ASSERT(userSheet->isUserStyleSheet());
@@ -456,6 +465,7 @@ bool DocumentStyleSheetCollection::updateActiveStyleSheets(UpdateFlag updateFlag
 
     Vector<RefPtr<CSSStyleSheet> > activeCSSStyleSheets;
     activeCSSStyleSheets.append(injectedAuthorStyleSheets());
+    activeCSSStyleSheets.append(documentAuthorStyleSheets());
     collectActiveCSSStyleSheetsFromSeamlessParents(activeCSSStyleSheets, m_document);
     filterEnabledCSSStyleSheets(activeCSSStyleSheets, activeStyleSheets);
 
@@ -494,6 +504,7 @@ void DocumentStyleSheetCollection::reportMemoryUsage(MemoryObjectInfo* memoryObj
     info.addMember(m_injectedUserStyleSheets);
     info.addMember(m_injectedAuthorStyleSheets);
     info.addMember(m_userStyleSheets);
+    info.addMember(m_authorStyleSheets);
     info.addMember(m_activeAuthorStyleSheets);
     info.addMember(m_styleSheetsForStyleSheetList);
     info.addMember(m_styleSheetCandidateNodes);
index b94bde9..51997fa 100644 (file)
@@ -56,6 +56,7 @@ public:
 
     CSSStyleSheet* pageUserSheet();
     const Vector<RefPtr<CSSStyleSheet> >& documentUserStyleSheets() const { return m_userStyleSheets; }
+    const Vector<RefPtr<CSSStyleSheet> >& documentAuthorStyleSheets() const { return m_authorStyleSheets; }
     const Vector<RefPtr<CSSStyleSheet> >& injectedUserStyleSheets() const;
     const Vector<RefPtr<CSSStyleSheet> >& injectedAuthorStyleSheets() const;
 
@@ -67,6 +68,7 @@ public:
     void invalidateInjectedStyleSheetCache();
     void updateInjectedStyleSheetCache() const;
 
+    void addAuthorSheet(PassRefPtr<StyleSheetContents> authorSheet);
     void addUserSheet(PassRefPtr<StyleSheetContents> userSheet);
 
     bool needsUpdateActiveStylesheetsOnStyleRecalc() const { return m_needsUpdateActiveStylesheetsOnStyleRecalc; }
@@ -132,6 +134,7 @@ private:
     mutable bool m_injectedStyleSheetCacheValid;
 
     Vector<RefPtr<CSSStyleSheet> > m_userStyleSheets;
+    Vector<RefPtr<CSSStyleSheet> > m_authorStyleSheets;
 
     bool m_hadActiveLoadingStylesheet;
     bool m_needsUpdateActiveStylesheetsOnStyleRecalc;
index 947c2ad..766a0e2 100644 (file)
@@ -78,6 +78,7 @@
 #include "Settings.h"
 #include "ShadowRoot.h"
 #include "SpellChecker.h"
+#include "StyleSheetContents.h"
 #include "TextIterator.h"
 #include "TreeScope.h"
 #include "ViewportArguments.h"
@@ -1474,6 +1475,22 @@ void Internals::allowRoundingHacks() const
     TextRun::setAllowsRoundingHacks(true);
 }
 
+void Internals::insertAuthorCSS(Document* document, const String& css) const
+{
+    RefPtr<StyleSheetContents> parsedSheet = StyleSheetContents::create(document);
+    parsedSheet->setIsUserStyleSheet(false);
+    parsedSheet->parseString(css);
+    document->styleSheetCollection()->addAuthorSheet(parsedSheet);
+}
+
+void Internals::insertUserCSS(Document* document, const String& css) const
+{
+    RefPtr<StyleSheetContents> parsedSheet = StyleSheetContents::create(document);
+    parsedSheet->setIsUserStyleSheet(true);
+    parsedSheet->parseString(css);
+    document->styleSheetCollection()->addUserSheet(parsedSheet);
+}
+
 String Internals::counterValue(Element* element)
 {
     if (!element)
index 4e37008..5bc2685 100644 (file)
@@ -212,6 +212,9 @@ public:
 
     void allowRoundingHacks() const;
 
+    void insertAuthorCSS(Document*, const String&) const;
+    void insertUserCSS(Document*, const String&) const;
+
 #if ENABLE(INSPECTOR)
     unsigned numberOfLiveNodes() const;
     unsigned numberOfLiveDocuments() const;
index 794058c..cdd3e38 100644 (file)
 
     void allowRoundingHacks();
 
+    void insertAuthorCSS(in Document document, in DOMString css);
+    void insertUserCSS(in Document document, in DOMString css);
+
 #if defined(ENABLE_BATTERY_STATUS) && ENABLE_BATTERY_STATUS
     void setBatteryStatus(in Document document, in DOMString eventType, in boolean charging, in double chargingTime, in double dischargingTime, in double level) raises (DOMException);
 #endif
index 7694e33..bae2f8e 100644 (file)
@@ -1,3 +1,13 @@
+2012-12-06  Tony Chang  <tony@chromium.org>
+
+        REGRESSION(r135082): Restore the ability to insert author level style sheets from script
+        https://bugs.webkit.org/show_bug.cgi?id=104042
+
+        Reviewed by Antti Koivisto.
+
+        * src/WebDocument.cpp:
+        (WebKit::WebDocument::insertUserStyleSheet): Use addAuthorSheet if an author level script is requested.
+
 2012-12-06  Sadrul Habib Chowdhury  <sadrul@chromium.org>
 
         [chromium] Add some null-checks for the touch-lists in TouchEvent
index ddd7666..09a62d2 100644 (file)
@@ -194,15 +194,17 @@ WebDocumentType WebDocument::doctype() const
     return WebDocumentType(constUnwrap<Document>()->doctype());
 }
 
-void WebDocument::insertUserStyleSheet(const WebString& sourceCode, UserStyleLevel)
+void WebDocument::insertUserStyleSheet(const WebString& sourceCode, UserStyleLevel styleLevel)
 {
     RefPtr<Document> document = unwrap<Document>();
 
-    // FIXME: We currently ignore the passed in UserStyleLevel. http://crbug.com/162096
     RefPtr<StyleSheetContents> parsedSheet = StyleSheetContents::create(document.get());
-    parsedSheet->setIsUserStyleSheet(true);
+    parsedSheet->setIsUserStyleSheet(styleLevel == UserStyleUserLevel);
     parsedSheet->parseString(sourceCode);
-    document->styleSheetCollection()->addUserSheet(parsedSheet.release());
+    if (parsedSheet->isUserStyleSheet())
+        document->styleSheetCollection()->addUserSheet(parsedSheet);
+    else
+        document->styleSheetCollection()->addAuthorSheet(parsedSheet);
 }
 
 void WebDocument::cancelFullScreen()
index fd718e2..2b4f83e 100644 (file)
@@ -1,3 +1,14 @@
+2012-12-06  Tony Chang  <tony@chromium.org>
+
+        REGRESSION(r135082): Restore the ability to insert author level style sheets from script
+        https://bugs.webkit.org/show_bug.cgi?id=104042
+
+        Reviewed by Antti Koivisto.
+
+        Update exports for Internals.cpp.
+
+        * win/WebKit2.def.in:
+
 2012-12-06  Andras Becsi  <andras.becsi@digia.com>
 
         [Qt][WK2] Fix QWebKitTest's notification of device pixel ratio change
index 8c0c608..4e67178 100644 (file)
@@ -379,3 +379,11 @@ EXPORTS
         ?solidColor@BitmapImage@WebCore@@MBE?AVColor@2@XZ
         ?draw@BitmapImage@WebCore@@MAEXPAVGraphicsContext@2@ABVFloatRect@2@1W4ColorSpace@2@W4CompositeOperator@2@W4RespectImageOrientationEnum@2@@Z
         ?frameCount@BitmapImage@WebCore@@MAEIXZ
+        ?addAuthorSheet@DocumentStyleSheetCollection@WebCore@@QAEXV?$PassRefPtr@VStyleSheetContents@WebCore@@@WTF@@@Z
+        ?parseString@StyleSheetContents@WebCore@@QAE_NABVString@WTF@@@Z
+        ??0CSSParserContext@WebCore@@QAE@PAVDocument@1@ABVKURL@1@ABVString@WTF@@@Z
+        ?emptyString@WTF@@YAABVString@1@XZ
+        ?invalidate@KURL@WebCore@@AAEXXZ
+        ??0StyleSheetContents@WebCore@@AAE@PAVStyleRuleImport@1@ABVString@WTF@@ABUCSSParserContext@1@@Z
+        ?addUserSheet@DocumentStyleSheetCollection@WebCore@@QAEXV?$PassRefPtr@VStyleSheetContents@WebCore@@@WTF@@@Z
+        ??1StyleSheetContents@WebCore@@QAE@XZ
index dba873d..5b77776 100644 (file)
@@ -225,6 +225,13 @@ _ZN7WebCore21SerializedScriptValue8toStringEv;
 _ZN7WebCore21SerializedScriptValue11deserializeEPN3JSC9ExecStateEPNS1_14JSGlobalObjectEPN3WTF6VectorINS6_6RefPtrINS_11MessagePortEEELm1EEENS_22SerializationErrorModeE;
 _ZN7WebCore21SerializedScriptValueD1Ev;
 _ZNK7WebCore21SerializedScriptValue12toWireStringEv;
+_ZN7WebCore16CSSParserContextC1EPNS_8DocumentERKNS_4KURLERKN3WTF6StringE;
+_ZN7WebCore18StyleSheetContents11parseStringERKN3WTF6StringE;
+_ZN7WebCore18StyleSheetContentsC1EPNS_15StyleRuleImportERKN3WTF6StringERKNS_16CSSParserContextE;
+_ZN7WebCore18StyleSheetContentsD1Ev;
+_ZN7WebCore28DocumentStyleSheetCollection12addUserSheetEN3WTF10PassRefPtrINS_18StyleSheetContentsEEE;
+_ZN7WebCore28DocumentStyleSheetCollection14addAuthorSheetEN3WTF10PassRefPtrINS_18StyleSheetContentsEEE;
+_ZN7WebCore4KURL10invalidateEv;
 
 local:
 _Z*;