WebCore:
authortimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 27 Nov 2007 17:15:19 +0000 (17:15 +0000)
committertimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 27 Nov 2007 17:15:19 +0000 (17:15 +0000)
        Reviewed by Dave Hyatt.

        <rdar://problem/5569233> Add the ability to disable author and user CSS styles

        * WebCore.base.exp: Add the Settings::setAuthorAndUserStylesEnabled symbol.
        * css/CSSStyleSelector.cpp:
        (WebCore::CSSStyleSelector::CSSStyleSelector): Add a new matchAuthorAndUserStyles parameter.
        (WebCore::CSSStyleSelector::styleForElement): Check m_matchAuthorAndUserStyles before
        matching user and author rules.
        (WebCore::CSSStyleSelector::pseudoStyleForElement): Ditto.
        (WebCore::CSSStyleSelector::styleRulesForElement): Ditto.
        * css/CSSStyleSelector.h: Add m_matchAuthorAndUserStyles and new constructor parameter.
        * dom/Document.cpp:
        (WebCore::Document::Document): Pass Settings::authorAndUserStylesEnabled to the CSSStyleSelector.
        (WebCore::Document::recalcStyleSelector): Skip collecting the author stylesheets if
        Settings::authorAndUserStylesEnabled is false, and pass that to the CSSStyleSelector.
        * page/Settings.cpp:
        (WebCore::Settings::Settings): Initialize m_authorAndUserStylesEnabled to true.
        (WebCore::Settings::setAuthorAndUserStylesEnabled): Recalc style in all the frames
        when the setting changes.
        * page/Settings.h: Add m_authorAndUserStylesEnabled.
        (WebCore::Settings::authorAndUserStylesEnabled): Return m_authorAndUserStylesEnabled.

WebKit/mac:

        Reviewed by Dave Hyatt.

        <rdar://problem/5569233> Add the ability to disable author and user CSS styles

        * WebView/WebPreferenceKeysPrivate.h: Define WebKitRespectStandardStyleKeyEquivalentsPreferenceKey.
        * WebView/WebPreferences.m:
        (+[WebPreferences initialize]): Default WebKitRespectStandardStyleKeyEquivalentsPreferenceKey to YES.
        (-[WebPreferences authorAndUserStylesEnabled]): Return the setting's BOOL value.
        (-[WebPreferences setAuthorAndUserStylesEnabled:]): Set the setting's BOOL value.
        * WebView/WebPreferencesPrivate.h: Add authorAndUserStylesEnabled and setAuthorAndUserStylesEnabled:.
        * WebView/WebView.mm:
        (-[WebView _preferencesChangedNotification:]): Update WebCore::Settings::authorAndUserStylesEnabled.

WebKitTools:

        Reviewed by Dave Hyatt.

        <rdar://problem/5569233> Add the ability to disable author and user CSS styles

        Add support for disabling author and user styles for testing.

        * DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj:
        * DumpRenderTree/LayoutTestController.cpp:
        (setAuthorAndUserStylesEnabledCallback):
        (LayoutTestController::staticFunctions):
        * DumpRenderTree/LayoutTestController.h:
        * DumpRenderTree/mac/LayoutTestControllerMac.mm:
        (LayoutTestController::setAuthorAndUserStylesEnabled):
        * DumpRenderTree/win/LayoutTestControllerWin.cpp:
        (LayoutTestController::setAuthorAndUserStylesEnabled):

LayoutTests:

        Reviewed by Dave Hyatt.

        Test for: <rdar://problem/5569233> Add the ability to disable author and user CSS styles

        * fast/css/disabled-author-styles.html: Added.
        * platform/mac/fast/css/disabled-author-styles-expected.txt: Added.

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

24 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/css/disabled-author-styles.html [new file with mode: 0644]
LayoutTests/platform/mac/fast/css/disabled-author-styles-expected.txt [new file with mode: 0644]
LayoutTests/platform/win/Skipped
WebCore/ChangeLog
WebCore/WebCore.base.exp
WebCore/WebCore.xcodeproj/project.pbxproj
WebCore/css/CSSStyleSelector.cpp
WebCore/css/CSSStyleSelector.h
WebCore/dom/Document.cpp
WebCore/page/Settings.cpp
WebCore/page/Settings.h
WebKit/mac/ChangeLog
WebKit/mac/WebCoreSupport/WebInspectorClient.mm
WebKit/mac/WebView/WebPreferenceKeysPrivate.h
WebKit/mac/WebView/WebPreferences.m
WebKit/mac/WebView/WebPreferencesPrivate.h
WebKit/mac/WebView/WebView.mm
WebKitTools/ChangeLog
WebKitTools/DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj
WebKitTools/DumpRenderTree/LayoutTestController.cpp
WebKitTools/DumpRenderTree/LayoutTestController.h
WebKitTools/DumpRenderTree/mac/LayoutTestControllerMac.mm
WebKitTools/DumpRenderTree/win/LayoutTestControllerWin.cpp

index abde75bdcd29382731e85e3d0f2ccca7d76e2fbe..753cbb6e4c4b80c41c6ae65f11cecc5e047f4364 100644 (file)
@@ -1,3 +1,12 @@
+2007-11-26  Timothy Hatcher  <timothy@apple.com>
+
+        Reviewed by Dave Hyatt.
+
+        Test for: <rdar://problem/5569233> Add the ability to disable author and user CSS styles
+
+        * fast/css/disabled-author-styles.html: Added.
+        * platform/mac/fast/css/disabled-author-styles-expected.txt: Added.
+
 2007-11-26  Feng Qian <ian.eng.webkit@gmail.com>
 
         Reviewed by Sam Weinig.
diff --git a/LayoutTests/fast/css/disabled-author-styles.html b/LayoutTests/fast/css/disabled-author-styles.html
new file mode 100644 (file)
index 0000000..5432a52
--- /dev/null
@@ -0,0 +1,39 @@
+<html>
+<head>
+    <script>
+        function loaded()
+        {
+            if (!window.layoutTestController) {
+               alert("This test must be run in the DumpRenderTree to work.");
+               return;
+            }
+
+            layoutTestController.setAuthorAndUserStylesEnabled(false);
+
+            // Check the matched rules after a timeout to give time for WebPreferences to update WebCore::Settings.
+            setTimeout(checkMatchedRules, 0);
+        }
+
+        function checkMatchedRules()
+        {
+            var matchedRules = getMatchedCSSRules(document.getElementById("test"), "", true);
+            if (matchedRules && matchedRules.length)
+                alert(matchedRules.length + " rule(s) were returned from getMatchedCSSRules, expected zero.");
+        }
+    </script>
+    <style>
+        #test {
+            color: red;
+        }
+
+        #test2::before {
+            color: red;
+            content: "This pseudo-element text should not show up.";
+        }
+    </style>
+</head>
+<body onload="loaded();">
+    <div id="test">This text should be black, not red.</div>
+    <div id="test2"></div>
+</body>
+</html>
diff --git a/LayoutTests/platform/mac/fast/css/disabled-author-styles-expected.txt b/LayoutTests/platform/mac/fast/css/disabled-author-styles-expected.txt
new file mode 100644 (file)
index 0000000..d483460
--- /dev/null
@@ -0,0 +1,9 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x584
+      RenderBlock {DIV} at (0,0) size 784x18
+        RenderText {#text} at (0,0) size 214x18
+          text run at (0,0) width 214: "This text should be black, not red."
+      RenderBlock {DIV} at (0,18) size 784x0
index c149ff4684e061adde1a1ec3b0fe05a8b4f6ff2f..4768684c0d0cee2a1dc526870e43e1ded88ed405 100644 (file)
@@ -316,6 +316,9 @@ fast/events/keydown-1.html
 # fireKeyboardEventsToElement is not implemented in DRT <rdar://problem/5137198>
 fast/events/objc-keyboard-event-creation.html
 
+# setAuthorAndUserStylesEnabled is not implemented in DRT <rdar://problem/5614497>
+fast/css/disabled-author-styles.html
+
 # The eqqivalent of option-tab doesn not exist in Boomer <rdar://problem/5137230>
 fast/events/frame-tab-focus.html
 fast/events/option-tab.html
index 69256c0ebb04e743915b2ceb606a19a8bb28c953..404c2b0e5a64ff1d77a537cb7fb83617d428bed2 100644 (file)
@@ -1,3 +1,28 @@
+2007-11-26  Timothy Hatcher  <timothy@apple.com>
+
+        Reviewed by Dave Hyatt.
+
+        <rdar://problem/5569233> Add the ability to disable author and user CSS styles
+
+        * WebCore.base.exp: Add the Settings::setAuthorAndUserStylesEnabled symbol.
+        * css/CSSStyleSelector.cpp:
+        (WebCore::CSSStyleSelector::CSSStyleSelector): Add a new matchAuthorAndUserStyles parameter.
+        (WebCore::CSSStyleSelector::styleForElement): Check m_matchAuthorAndUserStyles before
+        matching user and author rules.
+        (WebCore::CSSStyleSelector::pseudoStyleForElement): Ditto.
+        (WebCore::CSSStyleSelector::styleRulesForElement): Ditto.
+        * css/CSSStyleSelector.h: Add m_matchAuthorAndUserStyles and new constructor parameter.
+        * dom/Document.cpp:
+        (WebCore::Document::Document): Pass Settings::authorAndUserStylesEnabled to the CSSStyleSelector.
+        (WebCore::Document::recalcStyleSelector): Skip collecting the author stylesheets if
+        Settings::authorAndUserStylesEnabled is false, and pass that to the CSSStyleSelector.
+        * page/Settings.cpp:
+        (WebCore::Settings::Settings): Initialize m_authorAndUserStylesEnabled to true.
+        (WebCore::Settings::setAuthorAndUserStylesEnabled): Recalc style in all the frames
+        when the setting changes.
+        * page/Settings.h: Add m_authorAndUserStylesEnabled.
+        (WebCore::Settings::authorAndUserStylesEnabled): Return m_authorAndUserStylesEnabled.
+
 2007-11-27  Alp Toker  <alp@atoker.com>
 
         Reviewed by Mark Rowe.
index 636365d0925b5ea8355171abe7acb94c7cefe019..763487fa828f84bb1cd357424b8c69b96bd0aa56 100644 (file)
@@ -498,6 +498,7 @@ __ZN7WebCore8Settings26setDefaultTextEncodingNameERKNS_6StringE
 __ZN7WebCore8Settings27setFTPDirectoryTemplatePathERKNS_6StringE
 __ZN7WebCore8Settings27setLoadsImagesAutomaticallyEb
 __ZN7WebCore8Settings28setForceFTPDirectoryListingsEb
+__ZN7WebCore8Settings29setAuthorAndUserStylesEnabledEb
 __ZN7WebCore8Settings29setDefaultDatabaseOriginQuotaEy
 __ZN7WebCore8Settings31setShrinksStandaloneImagesToFitEb
 __ZN7WebCore8Settings32setNeedsAdobeFrameReloadingQuirkEb
index 2c9a306b36796c9bf94f2ae6f6f3fe8b70bd18ee..dcc3e494504b3d5e3b5c148ccf786af3f516af1a 100644 (file)
                0867D690FE84028FC02AAC07 /* Project object */ = {
                        isa = PBXProject;
                        buildConfigurationList = 149C284308902B11008A9EFC /* Build configuration list for PBXProject "WebCore" */;
+                       compatibilityVersion = "Xcode 2.4";
                        hasScannedForEncodings = 1;
                        knownRegions = (
                                English,
index 67239161346e6be942f0a6dcd1e1776706db930d..119284d070ec2aa6c4074da4ee623cd48c60a538 100644 (file)
@@ -235,12 +235,14 @@ CSSStyleSheet *CSSStyleSelector::svgSheet = 0;
 static CSSStyleSelector::Encodedurl *currentEncodedURL = 0;
 static PseudoState pseudoState;
 
-CSSStyleSelector::CSSStyleSelector(Document* doc, const String& userStyleSheet, StyleSheetList *styleSheets, CSSStyleSheet* mappedElementSheet, bool _strictParsing)
+CSSStyleSelector::CSSStyleSelector(Document* doc, const String& userStyleSheet, StyleSheetList *styleSheets, CSSStyleSheet* mappedElementSheet, bool _strictParsing, bool matchAuthorAndUserStyles)
 {
     init();
     
     m_document = doc;
 
+    m_matchAuthorAndUserStyles = matchAuthorAndUserStyles;
+
     strictParsing = _strictParsing;
     if (!defaultStyle)
         loadDefaultStyle();
@@ -831,7 +833,8 @@ RenderStyle* CSSStyleSelector::styleForElement(Element* e, RenderStyle* defaultP
 
     if (!resolveForRootDefault) {
         // 4. Now we check user sheet rules.
-        matchRules(m_userStyle, firstUserRule, lastUserRule);
+        if (m_matchAuthorAndUserStyles)
+            matchRules(m_userStyle, firstUserRule, lastUserRule);
 
         // 5. Now check author rules, beginning first with presentational attributes
         // mapped from HTML.
@@ -864,10 +867,11 @@ RenderStyle* CSSStyleSelector::styleForElement(Element* e, RenderStyle* defaultP
         }
     
         // 6. Check the rules in author sheets next.
-        matchRules(m_authorStyle, firstAuthorRule, lastAuthorRule);
-    
+        if (m_matchAuthorAndUserStyles)
+            matchRules(m_authorStyle, firstAuthorRule, lastAuthorRule);
+
         // 7. Now check our inline style attribute.
-        if (styledElement) {
+        if (m_matchAuthorAndUserStyles && styledElement) {
             CSSMutableStyleDeclaration* inlineDecl = styledElement->inlineStyleDecl();
             if (inlineDecl) {
                 lastAuthorRule = m_matchedDecls.size();
@@ -947,9 +951,12 @@ RenderStyle* CSSStyleSelector::pseudoStyleForElement(RenderStyle::PseudoId pseud
     // Check UA, user and author rules.
     int firstUARule = -1, lastUARule = -1, firstUserRule = -1, lastUserRule = -1, firstAuthorRule = -1, lastAuthorRule = -1;
     matchUARules(firstUARule, lastUARule);
-    matchRules(m_userStyle, firstUserRule, lastUserRule);
-    matchRules(m_authorStyle, firstAuthorRule, lastAuthorRule);
-    
+
+    if (m_matchAuthorAndUserStyles) {
+        matchRules(m_userStyle, firstUserRule, lastUserRule);
+        matchRules(m_authorStyle, firstAuthorRule, lastAuthorRule);
+    }
+
     if (m_matchedDecls.isEmpty())
         return 0;
     
@@ -1204,14 +1211,18 @@ RefPtr<CSSRuleList> CSSStyleSelector::styleRulesForElement(Element* e, bool auth
         matchUARules(firstUARule, lastUARule);
 
         // Now we check user sheet rules.
-        int firstUserRule = -1, lastUserRule = -1;
-        matchRules(m_userStyle, firstUserRule, lastUserRule);
+        if (m_matchAuthorAndUserStyles) {
+            int firstUserRule = -1, lastUserRule = -1;
+            matchRules(m_userStyle, firstUserRule, lastUserRule);
+        }
+    }
+
+    if (m_matchAuthorAndUserStyles) {
+        // Check the rules in author sheets.
+        int firstAuthorRule = -1, lastAuthorRule = -1;
+        matchRules(m_authorStyle, firstAuthorRule, lastAuthorRule);
     }
 
-    // Check the rules in author sheets.
-    int firstAuthorRule = -1, lastAuthorRule = -1;
-    matchRules(m_authorStyle, firstAuthorRule, lastAuthorRule);
-    
     m_collectRulesOnly = false;
     
     return m_ruleList;
index ce81a1494899f0b693e723ca2c51a6d5f8a15ea9..0ccf7d57ebff1d7b76b191cb47cdbd9b282b08aa 100644 (file)
@@ -82,7 +82,7 @@ class StyledElement;
     class CSSStyleSelector : public StyleSelector
     {
     public:
-        CSSStyleSelector(Document*, const String& userStyleSheet, StyleSheetList *styleSheets, CSSStyleSheet* mappedElementsSheet, bool strictParsing);
+        CSSStyleSelector(Document*, const String& userStyleSheet, StyleSheetList *styleSheets, CSSStyleSheet* mappedElementsSheet, bool strictParsing, bool matchAuthorAndUserStyles);
         ~CSSStyleSelector();
 
         static void loadDefaultStyle();
@@ -231,7 +231,8 @@ class StyledElement;
         CSSValue* m_lineHeightValue;
         bool fontDirty;
         bool isXMLDoc;
-        
+        bool m_matchAuthorAndUserStyles;
+
         RefPtr<CSSFontSelector> m_fontSelector;
 
         HashSet<AtomicStringImpl*> m_selectorAttrs;
index 6f31d89e9d659a776043fb0159e091878c7d7587..42005f878d76044b61e5ad6c8b831f3665cc059e 100644 (file)
@@ -317,7 +317,11 @@ Document::Document(DOMImplementation* impl, Frame* frame, bool isXHTML)
     m_usesFirstLetterRules = false;
     m_gotoAnchorNeededAfterStylesheetsLoad = false;
 
-    m_styleSelector = new CSSStyleSelector(this, m_usersheet, m_styleSheets.get(), m_mappedElementSheet.get(), !inCompatMode());
+    bool matchAuthorAndUserStyles = true;
+    if (Settings* settings = this->settings())
+        matchAuthorAndUserStyles = settings->authorAndUserStylesEnabled();
+    m_styleSelector = new CSSStyleSelector(this, m_usersheet, m_styleSheets.get(), m_mappedElementSheet.get(), !inCompatMode(), matchAuthorAndUserStyles);
+
     m_didCalculateStyleSelector = false;
     m_pendingStylesheets = 0;
     m_ignorePendingStylesheets = false;
@@ -2053,12 +2057,16 @@ void Document::recalcStyleSelector()
 
     DeprecatedPtrList<StyleSheet> oldStyleSheets = m_styleSheets->styleSheets;
     m_styleSheets->styleSheets.clear();
-    Node *n;
-    for (n = this; n; n = n->traverseNextNode()) {
-        StyleSheet *sheet = 0;
 
-        if (n->nodeType() == PROCESSING_INSTRUCTION_NODE)
-        {
+    bool matchAuthorAndUserStyles = true;
+    if (Settings* settings = this->settings())
+        matchAuthorAndUserStyles = settings->authorAndUserStylesEnabled();
+
+    Node* n = matchAuthorAndUserStyles ? this : 0;
+    for ( ; n; n = n->traverseNextNode()) {
+        StyleSheet* sheet = 0;
+
+        if (n->nodeType() == PROCESSING_INSTRUCTION_NODE) {
             // Processing instruction (XML documents only)
             ProcessingInstruction* pi = static_cast<ProcessingInstruction*>(n);
             sheet = pi->sheet();
@@ -2071,8 +2079,7 @@ void Document::recalcStyleSelector()
                 return;
             }
 #endif
-            if (!sheet && !pi->localHref().isEmpty())
-            {
+            if (!sheet && !pi->localHref().isEmpty()) {
                 // Processing instruction with reference to an element in this document - e.g.
                 // <?xml-stylesheet href="#mystyle">, with the element
                 // <foo id="mystyle">heading { color: red; }</foo> at some location in
@@ -2080,19 +2087,17 @@ void Document::recalcStyleSelector()
                 Element* elem = getElementById(pi->localHref().impl());
                 if (elem) {
                     String sheetText("");
-                    Node *c;
-                    for (c = elem->firstChild(); c; c = c->nextSibling()) {
+                    for (Node* c = elem->firstChild(); c; c = c->nextSibling()) {
                         if (c->nodeType() == TEXT_NODE || c->nodeType() == CDATA_SECTION_NODE)
                             sheetText += c->nodeValue();
                     }
 
-                    CSSStyleSheet *cssSheet = new CSSStyleSheet(this);
+                    CSSStyleSheetcssSheet = new CSSStyleSheet(this);
                     cssSheet->parseString(sheetText);
                     pi->setCSSStyleSheet(cssSheet);
                     sheet = cssSheet;
                 }
             }
-
         } else if (n->isHTMLElement() && (n->hasTagName(linkTag) || n->hasTagName(styleTag))
 #if ENABLE(SVG)
             ||  (n->isSVGElement() && n->hasTagName(SVGNames::styleTag))
@@ -2149,7 +2154,7 @@ void Document::recalcStyleSelector()
                     if (e->hasLocalName(styleTag) || !rel.contains("alternate"))
                         m_preferredStylesheetSet = m_selectedStylesheetSet = title;
                 }
-                
+
                 if (title != m_preferredStylesheetSet)
                     sheet = 0;
 
@@ -2164,7 +2169,7 @@ void Document::recalcStyleSelector()
             sheet->ref();
             m_styleSheets->styleSheets.append(sheet);
         }
-    
+
         // For HTML documents, stylesheets are not allowed within/after the <BODY> tag. So we
         // can stop searching here.
         if (isHTMLDocument() && n->hasTagName(bodyTag))
@@ -2181,7 +2186,7 @@ void Document::recalcStyleSelector()
     String usersheet = m_usersheet;
     if (view() && view()->mediaType() == "print")
         usersheet += m_printSheet;
-    m_styleSelector = new CSSStyleSelector(this, usersheet, m_styleSheets.get(), m_mappedElementSheet.get(), !inCompatMode());
+    m_styleSelector = new CSSStyleSelector(this, usersheet, m_styleSheets.get(), m_mappedElementSheet.get(), !inCompatMode(), matchAuthorAndUserStyles);
     m_styleSelector->setEncodedURL(m_url);
     m_didCalculateStyleSelector = true;
 }
index 0793539203f83ccecc7a8cc0eb94e7b865300bd1..369e98721ae0b7f10ca8e561c815d9cc0580f217 100644 (file)
@@ -64,6 +64,7 @@ Settings::Settings(Page* page)
     , m_showsURLsInToolTips(false)
     , m_forceFTPDirectoryListings(false)
     , m_developerExtrasEnabled(false)
+    , m_authorAndUserStylesEnabled(true)
 {
     // A Frame may not have been created yet, so we initialize the AtomicString 
     // hash before trying to use it.
@@ -279,6 +280,12 @@ void Settings::setDeveloperExtrasEnabled(bool developerExtrasEnabled)
     m_developerExtrasEnabled = developerExtrasEnabled;
 }
 
+void Settings::setAuthorAndUserStylesEnabled(bool authorAndUserStylesEnabled)
+{
+    m_authorAndUserStylesEnabled = authorAndUserStylesEnabled;
+    setNeedsReapplyStylesInAllFrames(m_page);
+}
+
 void Settings::setDefaultDatabaseOriginQuota(unsigned long long quota)
 {
     DatabaseTracker::tracker().setDefaultOriginQuota(quota);
@@ -289,5 +296,4 @@ unsigned long long Settings::defaultDatabaseOriginQuota() const
     return DatabaseTracker::tracker().defaultOriginQuota();
 }
 
-
 } // namespace WebCore
index ba2d564b25f199c2c2aee057c8288ae75989ae91..569deac61575f44cc2dadb87c349d279b91e9465 100644 (file)
@@ -137,6 +137,9 @@ namespace WebCore {
         void setDeveloperExtrasEnabled(bool);
         bool developerExtrasEnabled() const { return m_developerExtrasEnabled; }
         
+        void setAuthorAndUserStylesEnabled(bool);
+        bool authorAndUserStylesEnabled() const { return m_authorAndUserStylesEnabled; }
+        
         void setDefaultDatabaseOriginQuota(unsigned long long);
         unsigned long long defaultDatabaseOriginQuota() const;
         
@@ -173,6 +176,7 @@ namespace WebCore {
         bool m_showsURLsInToolTips : 1;
         bool m_forceFTPDirectoryListings : 1;
         bool m_developerExtrasEnabled : 1;
+        bool m_authorAndUserStylesEnabled : 1;
     };
 
 } // namespace WebCore
index 7321525f2188e47867f0bf35fd5742b46e1a80d0..c7c79948123389ff6bdea80d522bf196fab58804 100644 (file)
@@ -1,3 +1,18 @@
+2007-11-26  Timothy Hatcher  <timothy@apple.com>
+
+        Reviewed by Dave Hyatt.
+
+        <rdar://problem/5569233> Add the ability to disable author and user CSS styles
+
+        * WebView/WebPreferenceKeysPrivate.h: Define WebKitRespectStandardStyleKeyEquivalentsPreferenceKey.
+        * WebView/WebPreferences.m:
+        (+[WebPreferences initialize]): Default WebKitRespectStandardStyleKeyEquivalentsPreferenceKey to YES.
+        (-[WebPreferences authorAndUserStylesEnabled]): Return the setting's BOOL value.
+        (-[WebPreferences setAuthorAndUserStylesEnabled:]): Set the setting's BOOL value.
+        * WebView/WebPreferencesPrivate.h: Add authorAndUserStylesEnabled and setAuthorAndUserStylesEnabled:.
+        * WebView/WebView.mm:
+        (-[WebView _preferencesChangedNotification:]): Update WebCore::Settings::authorAndUserStylesEnabled.
+
 2007-11-26  Brady Eidson  <beidson@apple.com>
 
         Reviewed by Mark Rowe
index 1325defac61fbe86c5b7716c5e8f7b4b3534fff0..453cd1adf3a605f3fc4fd226a8619a518ee2b23c 100644 (file)
@@ -160,6 +160,7 @@ void WebInspectorClient::updateWindowTitle() const
     [preferences setAutosaves:NO];
     [preferences setPrivateBrowsingEnabled:YES];
     [preferences setLoadsImagesAutomatically:YES];
+    [preferences setAuthorAndUserStylesEnabled:YES];
     [preferences setJavaScriptEnabled:YES];
     [preferences setAllowsAnimatedImages:YES];
     [preferences setLoadsImagesAutomatically:YES];
index 74d6f91fda21196e95c9718648d6ec2d7a45aadc..5180cc6ccd5b626c77f1f43f271a79ab8051f392 100644 (file)
@@ -63,6 +63,7 @@
 #define WebKitFTPDirectoryTemplatePath @"WebKitFTPDirectoryTemplatePath"
 #define WebKitForceFTPDirectoryListings @"WebKitForceFTPDirectoryListings"
 #define WebKitDeveloperExtrasEnabledPreferenceKey @"WebKitDeveloperExtrasEnabledPreferenceKey"
+#define WebKitAuthorAndUserStylesEnabledPreferenceKey @"WebKitAuthorAndUserStylesEnabledPreferenceKey"
 
 // These are private both because callers should be using the cover methods and because the
 // cover methods themselves are private.
index 96d3d1f9a859f74990d38003e228151edaf71b96..26f336f773f80c12ab45dee9bb873a9aa6cbaef8 100644 (file)
@@ -331,6 +331,7 @@ static WebCacheModel cacheModelForMainBundle(void)
         [NSNumber numberWithBool:YES],  WebKitUsesPageCachePreferenceKey,
         [NSNumber numberWithInt:cacheModelForMainBundle()], WebKitCacheModelPreferenceKey,
         [NSNumber numberWithBool:NO],  WebKitDeveloperExtrasEnabledPreferenceKey,
+        [NSNumber numberWithBool:YES],  WebKitAuthorAndUserStylesEnabledPreferenceKey,
         nil];
 
     // This value shouldn't ever change, which is assumed in the initialization of WebKitPDFDisplayModePreferenceKey above
@@ -744,6 +745,16 @@ static WebCacheModel cacheModelForMainBundle(void)
     [self _setBoolValue:flag forKey:WebKitDeveloperExtrasEnabledPreferenceKey];
 }
 
+- (BOOL)authorAndUserStylesEnabled
+{
+    return [self _boolValueForKey:WebKitAuthorAndUserStylesEnabledPreferenceKey];
+}
+
+- (void)setAuthorAndUserStylesEnabled:(BOOL)flag
+{
+    [self _setBoolValue:flag forKey:WebKitAuthorAndUserStylesEnabledPreferenceKey];
+}
+
 - (BOOL)respectStandardStyleKeyEquivalents
 {
     return [self _boolValueForKey:WebKitRespectStandardStyleKeyEquivalentsPreferenceKey];
index 2b5d239d5f593294a91a080e174609fce912ad47..443c084d3999a2d4f4df019edb78ddff76a9c238 100644 (file)
@@ -48,6 +48,9 @@ extern NSString *WebPreferencesRemovedNotification;
 - (BOOL)developerExtrasEnabled;
 - (void)setDeveloperExtrasEnabled:(BOOL)flag;
 
+- (BOOL)authorAndUserStylesEnabled;
+- (void)setAuthorAndUserStylesEnabled:(BOOL)flag;
+
 - (BOOL)respectStandardStyleKeyEquivalents;
 - (void)setRespectStandardStyleKeyEquivalents:(BOOL)flag;
 
index 10e004c21283b1443169fbad5899b7a9adbe4484..bf59e320d58b49133466105e8e4550c1084808e2 100644 (file)
@@ -940,6 +940,7 @@ static bool debugWidget = true;
     settings->setUsesPageCache([self usesPageCache]);
     settings->setShowsURLsInToolTips([preferences showsURLsInToolTips]);
     settings->setDeveloperExtrasEnabled([preferences developerExtrasEnabled]);
+    settings->setAuthorAndUserStylesEnabled([preferences authorAndUserStylesEnabled]);
     if ([preferences userStyleSheetEnabled]) {
         NSString* location = [[preferences userStyleSheetLocation] _web_originalDataAsString];
         settings->setUserStyleSheetLocation([NSURL URLWithString:(location ? location : @"")]);
index a341fa822bc2109b2eb67d23d8be36d3d8c5fdc6..026545af0bf3d4c1028d5789c026fd454f0f302a 100644 (file)
@@ -1,3 +1,21 @@
+2007-11-27  Timothy Hatcher  <timothy@apple.com>
+
+        Reviewed by Dave Hyatt.
+
+        <rdar://problem/5569233> Add the ability to disable author and user CSS styles
+        
+        Add support for disabling author and user styles for testing.
+
+        * DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj:
+        * DumpRenderTree/LayoutTestController.cpp:
+        (setAuthorAndUserStylesEnabledCallback):
+        (LayoutTestController::staticFunctions):
+        * DumpRenderTree/LayoutTestController.h:
+        * DumpRenderTree/mac/LayoutTestControllerMac.mm:
+        (LayoutTestController::setAuthorAndUserStylesEnabled):
+        * DumpRenderTree/win/LayoutTestControllerWin.cpp:
+        (LayoutTestController::setAuthorAndUserStylesEnabled):
+
 2007-11-26  Dan Bernstein  <mitz@apple.com>
 
         - Tiger build fix.
index b8f7a6de7f190b71b15ea45c37fa2d5791faca24..e34d5e44aa8768a82ec3efa245f940ee44d1d532 100644 (file)
                A8B91BF70CF522B4008F91FF /* CheckedMalloc.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CheckedMalloc.cpp; path = mac/CheckedMalloc.cpp; sourceTree = "<group>"; };
                A8B91BF80CF522B4008F91FF /* JavaScriptThreading.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = JavaScriptThreading.cpp; path = mac/JavaScriptThreading.cpp; sourceTree = "<group>"; };
                A8B91BF90CF522B4008F91FF /* CheckedMalloc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CheckedMalloc.h; path = mac/CheckedMalloc.h; sourceTree = "<group>"; };
-               AA7F10C20CB3C1030003BDC9 /* AHEM____.TTF */ = {isa = PBXFileReference; lastKnownFileType = file; name = AHEM____.TTF; path = qt/fonts/AHEM____.TTF; sourceTree = "<group>"; };
+               AA7F10C20CB3C1030003BDC9 /* AHEM____.TTF */ = {isa = PBXFileReference; lastKnownFileType = file; name = "AHEM____.TTF"; path = "qt/fonts/AHEM____.TTF"; sourceTree = "<group>"; };
                AE8257EF08D22389000507AB /* Carbon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Carbon.framework; path = /System/Library/Frameworks/Carbon.framework; sourceTree = "<absolute>"; };
                B5A7526708AF4A4A00138E45 /* ImageDiff */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = ImageDiff; sourceTree = BUILT_PRODUCTS_DIR; };
                B5A752A108AF5D1F00138E45 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = /System/Library/Frameworks/QuartzCore.framework; sourceTree = "<absolute>"; };
                08FB7793FE84155DC02AAC07 /* Project object */ = {
                        isa = PBXProject;
                        buildConfigurationList = 149C29C308902C6D008A9EFC /* Build configuration list for PBXProject "DumpRenderTree" */;
+                       compatibilityVersion = "Xcode 2.4";
                        hasScannedForEncodings = 1;
                        mainGroup = 08FB7794FE84155DC02AAC07 /* DumpRenderTree */;
                        productRefGroup = 9340995508540CAF007F3BC8 /* Products */;
index e59b37a565e3c750826886604fbb81ad9bb824b2..9271cba912429b009188c299be0a36cb06884370 100644 (file)
@@ -358,6 +358,18 @@ static JSValueRef setAcceptsEditingCallback(JSContextRef context, JSObjectRef fu
     return JSValueMakeUndefined(context);
 }
 
+static JSValueRef setAuthorAndUserStylesEnabledCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    // Has mac & windows implementation
+    if (argumentCount < 1)
+        return JSValueMakeUndefined(context);
+
+    LayoutTestController* controller = reinterpret_cast<LayoutTestController*>(JSObjectGetPrivate(thisObject));
+    controller->setAuthorAndUserStylesEnabled(JSValueToBoolean(context, arguments[0]));
+
+    return JSValueMakeUndefined(context);
+}
+
 static JSValueRef setCustomPolicyDelegateCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
 {
     // Has mac implementation
@@ -555,6 +567,7 @@ JSStaticFunction* LayoutTestController::staticFunctions()
         { "queueScript", queueScriptCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "repaintSweepHorizontally", repaintSweepHorizontallyCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "setAcceptsEditing", setAcceptsEditingCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
+        { "setAuthorAndUserStylesEnabled", setAuthorAndUserStylesEnabledCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "setCallCloseOnWebViews", setCallCloseOnWebViewsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "setCanOpenWindows", setCanOpenWindowsCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
         { "setCloseRemainingWindowsWhenComplete", setCloseRemainingWindowsWhenCompleteCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
index 9b8cc5f1136695185b043d4e18bbddaf9e8f3c76..9ad07c9f3ca9b89599c3dafca5bc9a7a05029e6c 100644 (file)
@@ -52,6 +52,7 @@ public:
     void queueReload();
     void queueScript(JSStringRef url);
     void setAcceptsEditing(bool acceptsEditing);
+    void setAuthorAndUserStylesEnabled(bool);
     void setCustomPolicyDelegate(bool setDelegate);
     void setMainFrameIsFirstResponder(bool flag);
     void setPrivateBrowsingEnabled(bool flag);
index 0f352f49bc1f0734c6a238de094e739527fa9b81..a40458e807958b64fb52f7a36ed00659aead1990 100644 (file)
@@ -42,6 +42,7 @@
 #import <WebKit/WebHistory.h>
 #import <WebKit/WebNSURLExtras.h>
 #import <WebKit/WebPreferences.h>
+#import <WebKit/WebPreferencesPrivate.h>
 #import <WebKit/WebView.h>
 #import <WebKit/WebViewPrivate.h>
 #import <wtf/RetainPtr.h>
@@ -151,6 +152,11 @@ void LayoutTestController::setAcceptsEditing(bool newAcceptsEditing)
     [(EditingDelegate *)[[mainFrame webView] editingDelegate] setAcceptsEditing:newAcceptsEditing];
 }
 
+void LayoutTestController::setAuthorAndUserStylesEnabled(bool flag)
+{
+    [[[mainFrame webView] preferences] setAuthorAndUserStylesEnabled:flag];
+}
+
 void LayoutTestController::setCustomPolicyDelegate(bool setDelegate)
 {
     if (setDelegate)
index 8b1fc3d7a163600d82bc029a305af1ffbcd486e3..9e6e70faac9625633bf69e9eeae07988b81015b0 100644 (file)
@@ -219,6 +219,11 @@ void LayoutTestController::setAcceptsEditing(bool acceptsEditing)
     editingDelegate->setAcceptsEditing(acceptsEditing);
 }
 
+void LayoutTestController::setAuthorAndUserStylesEnabled(bool flag)
+{
+    // FIXME: Implement!
+}
+
 void LayoutTestController::setCustomPolicyDelegate(bool setDelegate)
 {
     COMPtr<IWebView> webView;