[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

darin at apple.com darin at apple.com
Wed Dec 22 12:46:11 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 3b8ced0ad9d0f359d61e801c3dee53f78f3c3bd9
Author: darin at apple.com <darin at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Sun Aug 29 19:56:50 2010 +0000

    2010-08-29  Darin Adler  <darin at apple.com>
    
            Reviewed by Sam Weinig.
    
            Deploy OwnPtr, PassOwnPtr, and adoptPtr in some CSS-related files
            https://bugs.webkit.org/show_bug.cgi?id=44834
    
            * css/CSSFunctionValue.cpp:
            (WebCore::CSSFunctionValue::CSSFunctionValue): Updated since
            CSSParserFunction::args is an OwnPtr.
            (WebCore::CSSFunctionValue::parserValue): Ditto.
    
            * css/CSSGrammar.y: Added leakPtr calls for putting MediaQueryExp*
            into the media query expression list, which is a vector of raw pointers
            that are deleted explicitly.
    
            * css/CSSImportRule.cpp:
            (WebCore::CSSImportRule::setCSSStyleSheet): Updated to use document instead of doc.
            (WebCore::CSSImportRule::insertedIntoParent): Ditto.
            * css/CSSMutableStyleDeclaration.cpp:
            (WebCore::CSSMutableStyleDeclaration::setNeedsStyleRecalc): Ditto.
    
            * css/CSSNamespace.h: Took the "m_" off the names of the data members of
            this structure. Used OwnPtr for the parent data member. Rewrote the
            namespaceForPrefix function so it's iterative instead of recursive.
    
            * css/CSSParser.cpp:
            (WebCore::CSSParser::CSSParser): Update since m_mediaQuery, m_floatingMediaQuery,
            m_floatingMediaQueryExp, and m_floatingMediaQueryExpList are now all OwnPtr and
            thus don't need to be initialized.
            (WebCore::CSSParser::~CSSParser): Update to not delete the above OwnPtr.
            (WebCore::CSSParser::parseMediaQuery): Replaced the code that sets m_mediaQuery
            to 0 with an assertion. Also use release when passing the media query to
            appendMediaQuery.
            (WebCore::CSSParser::document): Updated to use document instead of doc and to
            use early return instead of a nested if.
            (WebCore::CSSParser::parseContent): Added a get() call needed since
            CSSParserFunction::args is an OwnPtr.
            (WebCore::CSSParser::parseAnimationTimingFunction): Ditto.
            (WebCore::CSSParser::parseDashboardRegions): Ditto.
            (WebCore::CSSParser::parseShape): Ditto.
            (WebCore::isValidFormatFunction): Ditto.
            (WebCore::CSSParser::parseFontFaceSrc): Ditto.
            (WebCore::CSSParser::parseColorParameters): Ditto.
            (WebCore::CSSParser::parseHSLParameters): Ditto.
            (WebCore::parseGradientColorStop): Ditto.
            (WebCore::CSSParser::parseGradient): Ditto.
            (WebCore::CSSParser::parseCanvas): Ditto.
            (WebCore::CSSParser::parseTransform): Ditto.
            (WebCore::CSSParser::createFloatingMediaQueryExp): Updated to use adoptPtr and
            remove the explicit deletion.
            (WebCore::CSSParser::sinkFloatingMediaQueryExp): Updated to use release.
            (WebCore::CSSParser::createFloatingMediaQueryExpList): Ditto.
            (WebCore::CSSParser::sinkFloatingMediaQueryExpList): Ditto.
            (WebCore::CSSParser::createFloatingMediaQuery): Ditto.
            (WebCore::CSSParser::sinkFloatingMediaQuery): Ditto.
            (WebCore::CSSParser::checkForVariables): Use get for CSSParserFunction::args.
    
            * css/CSSParser.h: Made return values for sinkFloatingMediaQueryExp,
            sinkFloatingMediaQueryExpList, and sinkFloatingMediaQuery be PassOwnPtr.
            Made createFloatingMediaQuery take a PassOwnPtr. Made m_mediaQuery,
            m_floatingMediaQuery, m_floatingMediaQueryExp, and m_floatingMediaQueryExpList
            be OwnPtr.
    
            * css/CSSParserValues.h: Made args be an OwnPtr.
    
            * css/CSSStyleSelector.cpp: Made CSSRuleSet m_universalRules and m_pageRules
            be OwnPtr.
            (WebCore::CSSStyleSelector::CSSStyleSelector): Use document instead of doc.
            Got rid of the init function, only called here, because it did nothing that
            wasn't already done. Eliminated unneeded code to set m_userStyle to 0, since
            it's now an OwnPtr and will be 0 automatically. Use adoptPtr when initializing
            m_medium, m_authorStyle, and m_useStyle.
            (WebCore::CSSStyleSelector::~CSSStyleSelector): Got rid of unneeded delete of
            m_medium, m_authorStyle, and m_userStyle, and unneded clear of m_keyframesRuleMap.
            (WebCore::CSSStyleSelector::styleForElement): Use get with m_userStyle and
            m_authorStyle.
            (WebCore::CSSStyleSelector::pseudoStyleForElement): Ditto.
            (WebCore::CSSStyleSelector::styleForPage): Ditto.
            (WebCore::CSSStyleSelector::pseudoStyleRulesForElement): Ditto.
            (WebCore::CSSRuleSet::CSSRuleSet): Got rid of unneeded initialization of
            m_universalRules and m_pageRules.
            (WebCore::CSSRuleSet::~CSSRuleSet): Got rid of unneeed deletion of same.
            (WebCore::CSSRuleSet::addRule): Use adoptPtr to initialize m_universalRules.
            (WebCore::CSSRuleSet::addPageRule): Use adoptPtr to initialize m_pageRules.
            (WebCore::CSSStyleSelector::applyProperty): Use adopPtr to create counter
            context object.
    
            * css/CSSStyleSelector.h: Made m_authorStyle, m_userStyle, and m_medium use
            OwnPtr. Got rid of init function.
    
            * css/CSSStyleSheet.cpp:
            (WebCore::CSSStyleSheet::CSSStyleSheet): Updatd for name change from m_doc
            and doc to m_document and document. Eliminated unneeded initialization of
            m_namespaces now that it is an OwnPtr.
            (WebCore::CSSStyleSheet::~CSSStyleSheet): Got rid of unneeded deletion of same.
            (WebCore::CSSStyleSheet::cssRules): Updated doc to document.
            (WebCore::CSSStyleSheet::addNamespace): Added adopPtr when setting m_namespaces.
            (WebCore::CSSStyleSheet::determineNamespace): Updated for changes to the
            CSSNamespace class, using uri data member instead of function.
            (WebCore::CSSStyleSheet::styleSheetChanged): Use document instead of doc.
    
            * css/CSSStyleSheet.h: Renamed doc and m_doc to document and m_document.
            Made m_namespaces an OwnPtr.
    
            * css/CSSValueList.cpp:
            (WebCore::CSSValueList::CSSValueList): Clean up logic a bit.
            (WebCore::CSSValueList::createParserValueList): Clean up logic a bit and
            return a PassOwnPtr.
    
            * css/CSSValueList.h: Changed createParserValueList to return a PassOwnPtr.
    
            * css/CSSVariablesDeclaration.cpp:
            (WebCore::CSSVariablesDeclaration::setNeedsStyleRecalc): Updated to use
            document instead of doc.
    
            * css/MediaList.cpp:
            (WebCore::MediaList::deleteMedium): Use OwnPtr instead of a boolean to
            make sure the newly-created query here is deleted.
            (WebCore::MediaList::appendMediaQuery): Updated to take PassOwnPtr.
    
            * css/MediaList.h: Changed appendMediaQuery to take a PassOwnPtr.
    
            * inspector/InspectorDOMAgent.cpp:
            (WebCore::InspectorDOMAgent::getStyleSheet): Use document instead of doc.
            (WebCore::InspectorDOMAgent::getRuleRanges): Ditto.
            (WebCore::InspectorDOMAgent::buildObjectForStyleSheet): Ditto.
    
            * rendering/style/ContentData.cpp:
            (WebCore::ContentData::clear): Update since data members are OwnPtr.
            Also, fixed iterative deletion algorithm to be much simpler.
            (WebCore::ContentData::dataEquivalent): Added FIXMEs and tweaked formatting.
            (WebCore::ContentData::deleteContent): Tweaked formatting.
    
            * rendering/style/ContentData.h: Changed m_next to an OwnPtr.
            Added assertions to getters to check that we get the correct type.
            Use leakRef instead of releaseRef. Changed setCounter and setNext functions
            to take PassOwnPtr arguments.
    
            * rendering/style/RenderStyle.cpp:
            (WebCore::RenderStyle::prepareToSetContent): Refactored common part of the
            into a shared function so the three setContent functions don't have to repeat
            the logic. Used an OwnPtr to avoid confusing logic and leakPtr.
            (WebCore::RenderStyle::setContent): Changed argument to PassOwnPtr.
    
            * rendering/style/RenderStyle.h: Changed setContent argument to a PassOwnPtr.
            Added declaration of prepareToSetContent helper function.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@66334 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 5ebeed5..c37596a 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,151 @@
+2010-08-29  Darin Adler  <darin at apple.com>
+
+        Reviewed by Sam Weinig.
+
+        Deploy OwnPtr, PassOwnPtr, and adoptPtr in some CSS-related files
+        https://bugs.webkit.org/show_bug.cgi?id=44834
+
+        * css/CSSFunctionValue.cpp:
+        (WebCore::CSSFunctionValue::CSSFunctionValue): Updated since
+        CSSParserFunction::args is an OwnPtr.
+        (WebCore::CSSFunctionValue::parserValue): Ditto.
+
+        * css/CSSGrammar.y: Added leakPtr calls for putting MediaQueryExp*
+        into the media query expression list, which is a vector of raw pointers
+        that are deleted explicitly.
+
+        * css/CSSImportRule.cpp:
+        (WebCore::CSSImportRule::setCSSStyleSheet): Updated to use document instead of doc.
+        (WebCore::CSSImportRule::insertedIntoParent): Ditto.
+        * css/CSSMutableStyleDeclaration.cpp:
+        (WebCore::CSSMutableStyleDeclaration::setNeedsStyleRecalc): Ditto.
+
+        * css/CSSNamespace.h: Took the "m_" off the names of the data members of
+        this structure. Used OwnPtr for the parent data member. Rewrote the
+        namespaceForPrefix function so it's iterative instead of recursive.
+
+        * css/CSSParser.cpp:
+        (WebCore::CSSParser::CSSParser): Update since m_mediaQuery, m_floatingMediaQuery,
+        m_floatingMediaQueryExp, and m_floatingMediaQueryExpList are now all OwnPtr and
+        thus don't need to be initialized.
+        (WebCore::CSSParser::~CSSParser): Update to not delete the above OwnPtr.
+        (WebCore::CSSParser::parseMediaQuery): Replaced the code that sets m_mediaQuery
+        to 0 with an assertion. Also use release when passing the media query to
+        appendMediaQuery.
+        (WebCore::CSSParser::document): Updated to use document instead of doc and to
+        use early return instead of a nested if.
+        (WebCore::CSSParser::parseContent): Added a get() call needed since
+        CSSParserFunction::args is an OwnPtr.
+        (WebCore::CSSParser::parseAnimationTimingFunction): Ditto.
+        (WebCore::CSSParser::parseDashboardRegions): Ditto.
+        (WebCore::CSSParser::parseShape): Ditto.
+        (WebCore::isValidFormatFunction): Ditto.
+        (WebCore::CSSParser::parseFontFaceSrc): Ditto.
+        (WebCore::CSSParser::parseColorParameters): Ditto.
+        (WebCore::CSSParser::parseHSLParameters): Ditto.
+        (WebCore::parseGradientColorStop): Ditto.
+        (WebCore::CSSParser::parseGradient): Ditto.
+        (WebCore::CSSParser::parseCanvas): Ditto.
+        (WebCore::CSSParser::parseTransform): Ditto.
+        (WebCore::CSSParser::createFloatingMediaQueryExp): Updated to use adoptPtr and
+        remove the explicit deletion.
+        (WebCore::CSSParser::sinkFloatingMediaQueryExp): Updated to use release.
+        (WebCore::CSSParser::createFloatingMediaQueryExpList): Ditto.
+        (WebCore::CSSParser::sinkFloatingMediaQueryExpList): Ditto.
+        (WebCore::CSSParser::createFloatingMediaQuery): Ditto.
+        (WebCore::CSSParser::sinkFloatingMediaQuery): Ditto.
+        (WebCore::CSSParser::checkForVariables): Use get for CSSParserFunction::args.
+
+        * css/CSSParser.h: Made return values for sinkFloatingMediaQueryExp,
+        sinkFloatingMediaQueryExpList, and sinkFloatingMediaQuery be PassOwnPtr.
+        Made createFloatingMediaQuery take a PassOwnPtr. Made m_mediaQuery,
+        m_floatingMediaQuery, m_floatingMediaQueryExp, and m_floatingMediaQueryExpList
+        be OwnPtr.
+
+        * css/CSSParserValues.h: Made args be an OwnPtr.
+
+        * css/CSSStyleSelector.cpp: Made CSSRuleSet m_universalRules and m_pageRules
+        be OwnPtr.
+        (WebCore::CSSStyleSelector::CSSStyleSelector): Use document instead of doc.
+        Got rid of the init function, only called here, because it did nothing that
+        wasn't already done. Eliminated unneeded code to set m_userStyle to 0, since
+        it's now an OwnPtr and will be 0 automatically. Use adoptPtr when initializing
+        m_medium, m_authorStyle, and m_useStyle.
+        (WebCore::CSSStyleSelector::~CSSStyleSelector): Got rid of unneeded delete of
+        m_medium, m_authorStyle, and m_userStyle, and unneded clear of m_keyframesRuleMap.
+        (WebCore::CSSStyleSelector::styleForElement): Use get with m_userStyle and
+        m_authorStyle.
+        (WebCore::CSSStyleSelector::pseudoStyleForElement): Ditto.
+        (WebCore::CSSStyleSelector::styleForPage): Ditto.
+        (WebCore::CSSStyleSelector::pseudoStyleRulesForElement): Ditto.
+        (WebCore::CSSRuleSet::CSSRuleSet): Got rid of unneeded initialization of
+        m_universalRules and m_pageRules.
+        (WebCore::CSSRuleSet::~CSSRuleSet): Got rid of unneeed deletion of same.
+        (WebCore::CSSRuleSet::addRule): Use adoptPtr to initialize m_universalRules.
+        (WebCore::CSSRuleSet::addPageRule): Use adoptPtr to initialize m_pageRules.
+        (WebCore::CSSStyleSelector::applyProperty): Use adopPtr to create counter
+        context object.
+
+        * css/CSSStyleSelector.h: Made m_authorStyle, m_userStyle, and m_medium use
+        OwnPtr. Got rid of init function.
+
+        * css/CSSStyleSheet.cpp:
+        (WebCore::CSSStyleSheet::CSSStyleSheet): Updatd for name change from m_doc
+        and doc to m_document and document. Eliminated unneeded initialization of
+        m_namespaces now that it is an OwnPtr.
+        (WebCore::CSSStyleSheet::~CSSStyleSheet): Got rid of unneeded deletion of same.
+        (WebCore::CSSStyleSheet::cssRules): Updated doc to document.
+        (WebCore::CSSStyleSheet::addNamespace): Added adopPtr when setting m_namespaces.
+        (WebCore::CSSStyleSheet::determineNamespace): Updated for changes to the
+        CSSNamespace class, using uri data member instead of function.
+        (WebCore::CSSStyleSheet::styleSheetChanged): Use document instead of doc.
+
+        * css/CSSStyleSheet.h: Renamed doc and m_doc to document and m_document.
+        Made m_namespaces an OwnPtr.
+
+        * css/CSSValueList.cpp:
+        (WebCore::CSSValueList::CSSValueList): Clean up logic a bit.
+        (WebCore::CSSValueList::createParserValueList): Clean up logic a bit and
+        return a PassOwnPtr.
+
+        * css/CSSValueList.h: Changed createParserValueList to return a PassOwnPtr.
+
+        * css/CSSVariablesDeclaration.cpp:
+        (WebCore::CSSVariablesDeclaration::setNeedsStyleRecalc): Updated to use
+        document instead of doc.
+
+        * css/MediaList.cpp:
+        (WebCore::MediaList::deleteMedium): Use OwnPtr instead of a boolean to
+        make sure the newly-created query here is deleted.
+        (WebCore::MediaList::appendMediaQuery): Updated to take PassOwnPtr.
+
+        * css/MediaList.h: Changed appendMediaQuery to take a PassOwnPtr.
+
+        * inspector/InspectorDOMAgent.cpp:
+        (WebCore::InspectorDOMAgent::getStyleSheet): Use document instead of doc.
+        (WebCore::InspectorDOMAgent::getRuleRanges): Ditto.
+        (WebCore::InspectorDOMAgent::buildObjectForStyleSheet): Ditto.
+
+        * rendering/style/ContentData.cpp:
+        (WebCore::ContentData::clear): Update since data members are OwnPtr.
+        Also, fixed iterative deletion algorithm to be much simpler.
+        (WebCore::ContentData::dataEquivalent): Added FIXMEs and tweaked formatting.
+        (WebCore::ContentData::deleteContent): Tweaked formatting.
+
+        * rendering/style/ContentData.h: Changed m_next to an OwnPtr.
+        Added assertions to getters to check that we get the correct type.
+        Use leakRef instead of releaseRef. Changed setCounter and setNext functions
+        to take PassOwnPtr arguments.
+
+        * rendering/style/RenderStyle.cpp:
+        (WebCore::RenderStyle::prepareToSetContent): Refactored common part of the
+        into a shared function so the three setContent functions don't have to repeat
+        the logic. Used an OwnPtr to avoid confusing logic and leakPtr.
+        (WebCore::RenderStyle::setContent): Changed argument to PassOwnPtr.
+
+        * rendering/style/RenderStyle.h: Changed setContent argument to a PassOwnPtr.
+        Added declaration of prepareToSetContent helper function.
+
 2010-08-29  Patrick Gansterer  <paroga at paroga.com>
 
         Reviewed by Adam Roben.
diff --git a/WebCore/css/CSSFunctionValue.cpp b/WebCore/css/CSSFunctionValue.cpp
index 0fc260d..70e8174 100644
--- a/WebCore/css/CSSFunctionValue.cpp
+++ b/WebCore/css/CSSFunctionValue.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2008, 2010 Apple Inc. All Rights Reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -25,15 +25,17 @@
 
 #include "config.h"
 #include "CSSFunctionValue.h"
+
 #include "CSSValueList.h"
+#include <wtf/PassOwnPtr.h>
 
 namespace WebCore {
 
 CSSFunctionValue::CSSFunctionValue(CSSParserFunction* function)
+    : m_name(function->name)
 {
-    m_name = function->name;
     if (function->args)
-        m_args = CSSValueList::createFromParserValueList(function->args);
+        m_args = CSSValueList::createFromParserValueList(function->args.get());
 }
 
 CSSFunctionValue::~CSSFunctionValue()
@@ -58,7 +60,8 @@ CSSParserValue CSSFunctionValue::parserValue() const
     val.function = new CSSParserFunction;
     val.function->name.characters = const_cast<UChar*>(m_name.characters());
     val.function->name.length = m_name.length();
-    val.function->args = m_args ? m_args->createParserValueList() : 0;
+    if (m_args)
+        val.function->args = m_args->createParserValueList();
     return val;
 }
 
diff --git a/WebCore/css/CSSGrammar.y b/WebCore/css/CSSGrammar.y
index 26b2ba8..16b2cc8 100644
--- a/WebCore/css/CSSGrammar.y
+++ b/WebCore/css/CSSGrammar.y
@@ -2,7 +2,7 @@
 
 /*
  *  Copyright (C) 2002-2003 Lars Knoll (knoll at kde.org)
- *  Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
+ *  Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
  *  Copyright (C) 2006 Alexey Proskuryakov (ap at nypop.com)
  *  Copyright (C) 2008 Eric Seidel <eric at webkit.org>
  *
@@ -34,6 +34,7 @@
 #include "Document.h"
 #include "HTMLNames.h"
 #include "MediaList.h"
+#include "MediaQueryExp.h"
 #include "WebKitCSSKeyframeRule.h"
 #include "WebKitCSSKeyframesRule.h"
 #include <wtf/FastMalloc.h>
@@ -617,11 +618,11 @@ media_query_exp_list:
     media_query_exp {
         CSSParser* p = static_cast<CSSParser*>(parser);
         $$ = p->createFloatingMediaQueryExpList();
-        $$->append(p->sinkFloatingMediaQueryExp($1));
+        $$->append(p->sinkFloatingMediaQueryExp($1).leakPtr());
     }
     | media_query_exp_list maybe_space MEDIA_AND maybe_space media_query_exp {
         $$ = $1;
-        $$->append(static_cast<CSSParser*>(parser)->sinkFloatingMediaQueryExp($5));
+        $$->append(static_cast<CSSParser*>(parser)->sinkFloatingMediaQueryExp($5).leakPtr());
     }
     ;
 
diff --git a/WebCore/css/CSSImportRule.cpp b/WebCore/css/CSSImportRule.cpp
index 1e79a39..689d6e3 100644
--- a/WebCore/css/CSSImportRule.cpp
+++ b/WebCore/css/CSSImportRule.cpp
@@ -1,7 +1,7 @@
 /*
  * (C) 1999-2003 Lars Knoll (knoll at kde.org)
  * (C) 2002-2003 Dirk Mueller (mueller at kde.org)
- * Copyright (C) 2002, 2005, 2006, 2008, 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2002, 2005, 2006, 2008, 2009, 2010 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -65,7 +65,7 @@ void CSSImportRule::setCSSStyleSheet(const String& href, const KURL& baseURL, co
     CSSStyleSheet* parent = parentStyleSheet();
     bool strict = !parent || parent->useStrictParsing();
     bool enforceMIMEType = strict;
-    bool needsSiteSpecificQuirks = parent && parent->doc() && parent->doc()->settings() && parent->doc()->settings()->needsSiteSpecificQuirks();
+    bool needsSiteSpecificQuirks = parent && parent->document() && parent->document()->settings() && parent->document()->settings()->needsSiteSpecificQuirks();
 
 #if defined(BUILDING_ON_TIGER) || defined(BUILDING_ON_LEOPARD)
     if (enforceMIMEType && needsSiteSpecificQuirks) {
@@ -78,7 +78,7 @@ void CSSImportRule::setCSSStyleSheet(const String& href, const KURL& baseURL, co
     String sheetText = sheet->sheetText(enforceMIMEType, &validMIMEType);
     m_styleSheet->parseString(sheetText, strict);
 
-    if (!parent || !parent->doc() || !parent->doc()->securityOrigin()->canRequest(baseURL))
+    if (!parent || !parent->document() || !parent->document()->securityOrigin()->canRequest(baseURL))
         crossOriginCSS = true;
 
     if (crossOriginCSS && !validMIMEType && !m_styleSheet->hasSyntacticallyValidCSSHeader())
@@ -115,7 +115,7 @@ void CSSImportRule::insertedIntoParent()
     if (!parentSheet)
         return;
 
-    DocLoader* docLoader = parentSheet->doc()->docLoader();
+    DocLoader* docLoader = parentSheet->document()->docLoader();
     if (!docLoader)
         return;
 
@@ -143,7 +143,7 @@ void CSSImportRule::insertedIntoParent()
         // removed from the pending sheet count, so let the doc know
         // the sheet being imported is pending.
         if (parentSheet && parentSheet->loadCompleted() && root == parentSheet)
-            parentSheet->doc()->addPendingSheet();
+            parentSheet->document()->addPendingSheet();
         m_loading = true;
         m_cachedSheet->addClient(this);
     }
diff --git a/WebCore/css/CSSMutableStyleDeclaration.cpp b/WebCore/css/CSSMutableStyleDeclaration.cpp
index 6b85d8b..b1b7805 100644
--- a/WebCore/css/CSSMutableStyleDeclaration.cpp
+++ b/WebCore/css/CSSMutableStyleDeclaration.cpp
@@ -1,6 +1,6 @@
 /*
  * (C) 1999-2003 Lars Knoll (knoll at kde.org)
- * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -488,9 +488,10 @@ void CSSMutableStyleDeclaration::setNeedsStyleRecalc()
     StyleBase* root = this;
     while (StyleBase* parent = root->parent())
         root = parent;
-    if (root->isCSSStyleSheet())
-        if (Document* doc = static_cast<CSSStyleSheet*>(root)->doc())
-            doc->styleSelectorChanged(DeferRecalcStyle);
+    if (root->isCSSStyleSheet()) {
+        if (Document* document = static_cast<CSSStyleSheet*>(root)->document())
+            document->styleSelectorChanged(DeferRecalcStyle);
+    }
 }
 
 bool CSSMutableStyleDeclaration::getPropertyPriority(int propertyID) const
diff --git a/WebCore/css/CSSNamespace.h b/WebCore/css/CSSNamespace.h
index d7fab4c..6225c36 100644
--- a/WebCore/css/CSSNamespace.h
+++ b/WebCore/css/CSSNamespace.h
@@ -1,7 +1,7 @@
 /*
  * Copyright (C) 1999-2003 Lars Knoll (knoll at kde.org)
  *               1999 Waldo Bastian (bastian at kde.org)
- * Copyright (C) 2004, 2006 Apple Computer, Inc.
+ * Copyright (C) 2004, 2006, 2010 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -27,27 +27,23 @@
 namespace WebCore {
 
     struct CSSNamespace : Noncopyable {
-        AtomicString m_prefix;
-        AtomicString m_uri;
-        CSSNamespace* m_parent;
-
-        CSSNamespace(const AtomicString& prefix, const AtomicString& uri, CSSNamespace* parent)
-            : m_prefix(prefix)
-            , m_uri(uri)
-            , m_parent(parent)
+        AtomicString prefix;
+        AtomicString uri;
+        OwnPtr<CSSNamespace> parent;
+
+        CSSNamespace(const AtomicString& prefix, const AtomicString& uri, PassOwnPtr<CSSNamespace> parent)
+            : prefix(prefix)
+            , uri(uri)
+            , parent(parent)
         {
         }
-        ~CSSNamespace() { delete m_parent; }
-
-        const AtomicString& uri() { return m_uri; }
-        const AtomicString& prefix() { return m_prefix; }
 
         CSSNamespace* namespaceForPrefix(const AtomicString& prefix)
         {
-            if (prefix == m_prefix)
-                return this;
-            if (m_parent)
-                return m_parent->namespaceForPrefix(prefix);
+            for (CSSNamespace* candidate = this; candidate; candidate = candidate->parent.get()) {
+                if (candidate->prefix == prefix)
+                    return candidate;
+            }
             return 0;
         }
     };
diff --git a/WebCore/css/CSSParser.cpp b/WebCore/css/CSSParser.cpp
index c1f8177..e20537a 100644
--- a/WebCore/css/CSSParser.cpp
+++ b/WebCore/css/CSSParser.cpp
@@ -134,7 +134,6 @@ CSSParser::CSSParser(bool strictParsing)
     , m_important(false)
     , m_id(0)
     , m_styleSheet(0)
-    , m_mediaQuery(0)
     , m_valueList(0)
     , m_parsedProperties(static_cast<CSSProperty**>(fastMalloc(32 * sizeof(CSSProperty*))))
     , m_numParsedProperties(0)
@@ -156,9 +155,6 @@ CSSParser::CSSParser(bool strictParsing)
     , m_allowImportRules(true)
     , m_allowVariablesRules(true)
     , m_allowNamespaceDeclarations(true)
-    , m_floatingMediaQuery(0)
-    , m_floatingMediaQueryExp(0)
-    , m_floatingMediaQueryExpList(0)
 {
 #if YYDEBUG > 0
     cssyydebug = 1;
@@ -176,12 +172,8 @@ CSSParser::~CSSParser()
 
     fastFree(m_data);
 
-    if (m_floatingMediaQueryExpList) {
+    if (m_floatingMediaQueryExpList)
         deleteAllValues(*m_floatingMediaQueryExpList);
-        delete m_floatingMediaQueryExpList;
-    }
-    delete m_floatingMediaQueryExp;
-    delete m_floatingMediaQuery;
     fastDeleteAllValues(m_floatingSelectors);
     deleteAllValues(m_floatingValueLists);
     deleteAllValues(m_floatingFunctions);
@@ -363,7 +355,8 @@ bool CSSParser::parseMediaQuery(MediaList* queries, const String& string)
     if (string.isEmpty())
         return true;
 
-    m_mediaQuery = 0;
+    ASSERT(!m_mediaQuery);
+
     // can't use { because tokenizer state switches from mediaquery to initial state when it sees { token.
     // instead insert one " " (which is WHITESPACE in CSSGrammar.y)
     setupParser("@-webkit-mediaquery ", string, "} ");
@@ -372,8 +365,7 @@ bool CSSParser::parseMediaQuery(MediaList* queries, const String& string)
     bool ok = false;
     if (m_mediaQuery) {
         ok = true;
-        queries->appendMediaQuery(m_mediaQuery);
-        m_mediaQuery = 0;
+        queries->appendMediaQuery(m_mediaQuery.release());
     }
 
     return ok;
@@ -414,12 +406,13 @@ void CSSParser::clearProperties()
 Document* CSSParser::document() const
 {
     StyleBase* root = m_styleSheet;
-    Document* doc = 0;
     while (root && root->parent())
         root = root->parent();
-    if (root && root->isCSSStyleSheet())
-        doc = static_cast<CSSStyleSheet*>(root)->doc();
-    return doc;
+    if (!root)
+        return 0;
+    if (!root->isCSSStyleSheet())
+        return 0;
+    return static_cast<CSSStyleSheet*>(root)->document();
 }
 
 bool CSSParser::validUnit(CSSParserValue* value, Units unitflags, bool strict)
@@ -2272,7 +2265,7 @@ bool CSSParser::parseContent(int propId, bool important)
             parsedValue = CSSImageValue::create(m_styleSheet->completeURL(val->string));
         } else if (val->unit == CSSParserValue::Function) {
             // attr(X) | counter(X [,Y]) | counters(X, Y, [,Z]) | -webkit-gradient(...)
-            CSSParserValueList* args = val->function->args;
+            CSSParserValueList* args = val->function->args.get();
             if (!args)
                 return false;
             if (equalIgnoringCase(val->function->name, "attr(")) {
@@ -2822,7 +2815,7 @@ PassRefPtr<CSSValue> CSSParser::parseAnimationTimingFunction()
         return 0;
 
     // The only timing function we accept for now is a cubic bezier function.  4 points must be specified.
-    CSSParserValueList* args = value->function->args;
+    CSSParserValueList* args = value->function->args.get();
     if (!equalIgnoringCase(value->function->name, "cubic-bezier(") || !args || args->size() != 7)
         return 0;
 
@@ -2997,7 +2990,7 @@ bool CSSParser::parseDashboardRegions(int propId, bool important)
         // also allow
         // dashboard-region(label, type) or dashboard-region(label type)
         // dashboard-region(label, type) or dashboard-region(label type)
-        CSSParserValueList* args = value->function->args;
+        CSSParserValueList* args = value->function->args.get();
         if (!equalIgnoringCase(value->function->name, "dashboard-region(") || !args) {
             valid = false;
             break;
@@ -3143,7 +3136,7 @@ PassRefPtr<CSSValue> CSSParser::parseCounterContent(CSSParserValueList* args, bo
 bool CSSParser::parseShape(int propId, bool important)
 {
     CSSParserValue* value = m_valueList->current();
-    CSSParserValueList* args = value->function->args;
+    CSSParserValueList* args = value->function->args.get();
 
     if (!equalIgnoringCase(value->function->name, "rect(") || !args)
         return false;
@@ -3507,7 +3500,7 @@ bool CSSParser::parseFontWeight(bool important)
 
 static bool isValidFormatFunction(CSSParserValue* val)
 {
-    CSSParserValueList* args = val->function->args;
+    CSSParserValueList* args = val->function->args.get();
     return equalIgnoringCase(val->function->name, "format(") && (args->current()->unit == CSSPrimitiveValue::CSS_STRING || args->current()->unit == CSSPrimitiveValue::CSS_IDENT);
 }
 
@@ -3530,7 +3523,7 @@ bool CSSParser::parseFontFaceSrc()
             expectComma = true;
         } else if (val->unit == CSSParserValue::Function) {
             // There are two allowed functions: local() and format().
-            CSSParserValueList* args = val->function->args;
+            CSSParserValueList* args = val->function->args.get();
             if (args && args->size() == 1) {
                 if (equalIgnoringCase(val->function->name, "local(") && !expectComma) {
                     expectComma = true;
@@ -3868,7 +3861,7 @@ static inline int colorIntFromValue(CSSParserValue* v)
 
 bool CSSParser::parseColorParameters(CSSParserValue* value, int* colorArray, bool parseAlpha)
 {
-    CSSParserValueList* args = value->function->args;
+    CSSParserValueList* args = value->function->args.get();
     CSSParserValue* v = args->current();
     Units unitType = FUnknown;
     // Get the first value and its type
@@ -3909,7 +3902,7 @@ bool CSSParser::parseColorParameters(CSSParserValue* value, int* colorArray, boo
 // The first value, HUE, is in an angle with a value between 0 and 360
 bool CSSParser::parseHSLParameters(CSSParserValue* value, double* colorArray, bool parseAlpha)
 {
-    CSSParserValueList* args = value->function->args;
+    CSSParserValueList* args = value->function->args.get();
     CSSParserValue* v = args->current();
     // Get the first value
     if (!validUnit(v, FNumber, true))
@@ -4558,7 +4551,7 @@ static bool parseGradientColorStop(CSSParser* p, CSSParserValue* a, CSSGradientC
         !equalIgnoringCase(a->function->name, "color-stop("))
         return false;
 
-    CSSParserValueList* args = a->function->args;
+    CSSParserValueList* args = a->function->args.get();
     if (!args)
         return false;
 
@@ -4617,7 +4610,7 @@ bool CSSParser::parseGradient(RefPtr<CSSValue>& gradient)
     RefPtr<CSSGradientValue> result = CSSGradientValue::create();
 
     // Walk the arguments.
-    CSSParserValueList* args = m_valueList->current()->function->args;
+    CSSParserValueList* args = m_valueList->current()->function->args.get();
     if (!args || args->size() == 0)
         return false;
 
@@ -4738,7 +4731,7 @@ bool CSSParser::parseCanvas(RefPtr<CSSValue>& canvas)
     RefPtr<CSSCanvasValue> result = CSSCanvasValue::create();
 
     // Walk the arguments.
-    CSSParserValueList* args = m_valueList->current()->function->args;
+    CSSParserValueList* args = m_valueList->current()->function->args.get();
     if (!args || args->size() != 1)
         return false;
 
@@ -4858,7 +4851,7 @@ PassRefPtr<CSSValueList> CSSParser::parseTransform()
             return 0;
 
         // Every primitive requires at least one argument.
-        CSSParserValueList* args = value->function->args;
+        CSSParserValueList* args = value->function->args.get();
         if (!args)
             return 0;
 
@@ -5280,52 +5273,45 @@ CSSParserValue& CSSParser::sinkFloatingValue(CSSParserValue& value)
 
 MediaQueryExp* CSSParser::createFloatingMediaQueryExp(const AtomicString& mediaFeature, CSSParserValueList* values)
 {
-    delete m_floatingMediaQueryExp;
-    m_floatingMediaQueryExp = new MediaQueryExp(mediaFeature, values);
-    return m_floatingMediaQueryExp;
+    m_floatingMediaQueryExp = adoptPtr(new MediaQueryExp(mediaFeature, values));
+    return m_floatingMediaQueryExp.get();
 }
 
-MediaQueryExp* CSSParser::sinkFloatingMediaQueryExp(MediaQueryExp* e)
+PassOwnPtr<MediaQueryExp> CSSParser::sinkFloatingMediaQueryExp(MediaQueryExp* expression)
 {
-    ASSERT(e == m_floatingMediaQueryExp);
-    m_floatingMediaQueryExp = 0;
-    return e;
+    ASSERT_UNUSED(expression, expression == m_floatingMediaQueryExp);
+    return m_floatingMediaQueryExp.release();
 }
 
 Vector<MediaQueryExp*>* CSSParser::createFloatingMediaQueryExpList()
 {
-    if (m_floatingMediaQueryExpList) {
+    if (m_floatingMediaQueryExpList)
         deleteAllValues(*m_floatingMediaQueryExpList);
-        delete m_floatingMediaQueryExpList;
-    }
-    m_floatingMediaQueryExpList = new Vector<MediaQueryExp*>;
-    return m_floatingMediaQueryExpList;
+    m_floatingMediaQueryExpList = adoptPtr(new Vector<MediaQueryExp*>);
+    return m_floatingMediaQueryExpList.get();
 }
 
-Vector<MediaQueryExp*>* CSSParser::sinkFloatingMediaQueryExpList(Vector<MediaQueryExp*>* l)
+PassOwnPtr<Vector<MediaQueryExp*> > CSSParser::sinkFloatingMediaQueryExpList(Vector<MediaQueryExp*>* list)
 {
-    ASSERT(l == m_floatingMediaQueryExpList);
-    m_floatingMediaQueryExpList = 0;
-    return l;
+    ASSERT_UNUSED(list, list == m_floatingMediaQueryExpList);
+    return m_floatingMediaQueryExpList.release();
 }
 
-MediaQuery* CSSParser::createFloatingMediaQuery(MediaQuery::Restrictor r, const String& mediaType, Vector<MediaQueryExp*>* exprs)
+MediaQuery* CSSParser::createFloatingMediaQuery(MediaQuery::Restrictor restrictor, const String& mediaType, PassOwnPtr<Vector<MediaQueryExp*> > expressions)
 {
-    delete m_floatingMediaQuery;
-    m_floatingMediaQuery = new MediaQuery(r, mediaType, exprs);
-    return m_floatingMediaQuery;
+    m_floatingMediaQuery = adoptPtr(new MediaQuery(restrictor, mediaType, expressions));
+    return m_floatingMediaQuery.get();
 }
 
-MediaQuery* CSSParser::createFloatingMediaQuery(Vector<MediaQueryExp*>* exprs)
+MediaQuery* CSSParser::createFloatingMediaQuery(PassOwnPtr<Vector<MediaQueryExp*> > expressions)
 {
-    return createFloatingMediaQuery(MediaQuery::None, "all", exprs);
+    return createFloatingMediaQuery(MediaQuery::None, "all", expressions);
 }
 
-MediaQuery* CSSParser::sinkFloatingMediaQuery(MediaQuery* mq)
+PassOwnPtr<MediaQuery> CSSParser::sinkFloatingMediaQuery(MediaQuery* query)
 {
-    ASSERT(mq == m_floatingMediaQuery);
-    m_floatingMediaQuery = 0;
-    return mq;
+    ASSERT_UNUSED(query, query == m_floatingMediaQuery);
+    return m_floatingMediaQuery.release();
 }
 
 MediaList* CSSParser::createMediaList()
@@ -5581,7 +5567,7 @@ bool CSSParser::checkForVariables(CSSParserValueList* valueList)
             break;
         }
 
-        if (valueList->valueAt(i)->unit == CSSParserValue::Function && checkForVariables(valueList->valueAt(i)->function->args)) {
+        if (valueList->valueAt(i)->unit == CSSParserValue::Function && checkForVariables(valueList->valueAt(i)->function->args.get())) {
             hasVariables = true;
             break;
         }
diff --git a/WebCore/css/CSSParser.h b/WebCore/css/CSSParser.h
index 1e233c8..6211e62 100644
--- a/WebCore/css/CSSParser.h
+++ b/WebCore/css/CSSParser.h
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2003 Lars Knoll (knoll at kde.org)
- * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010 Apple Inc. All rights reserved.
  * Copyright (C) 2008 Eric Seidel <eric at webkit.org>
  * Copyright (C) 2009 - 2010  Torch Mobile (Beijing) Co. Ltd. All rights reserved.
  *
@@ -194,12 +194,12 @@ namespace WebCore {
         void endDeclarationsForMarginBox();
 
         MediaQueryExp* createFloatingMediaQueryExp(const AtomicString&, CSSParserValueList*);
-        MediaQueryExp* sinkFloatingMediaQueryExp(MediaQueryExp*);
+        PassOwnPtr<MediaQueryExp> sinkFloatingMediaQueryExp(MediaQueryExp*);
         Vector<MediaQueryExp*>* createFloatingMediaQueryExpList();
-        Vector<MediaQueryExp*>* sinkFloatingMediaQueryExpList(Vector<MediaQueryExp*>*);
-        MediaQuery* createFloatingMediaQuery(MediaQuery::Restrictor, const String&, Vector<MediaQueryExp*>*);
-        MediaQuery* createFloatingMediaQuery(Vector<MediaQueryExp*>*);
-        MediaQuery* sinkFloatingMediaQuery(MediaQuery*);
+        PassOwnPtr<Vector<MediaQueryExp*> > sinkFloatingMediaQueryExpList(Vector<MediaQueryExp*>*);
+        MediaQuery* createFloatingMediaQuery(MediaQuery::Restrictor, const String&, PassOwnPtr<Vector<MediaQueryExp*> >);
+        MediaQuery* createFloatingMediaQuery(PassOwnPtr<Vector<MediaQueryExp*> >);
+        PassOwnPtr<MediaQuery> sinkFloatingMediaQuery(MediaQuery*);
 
         void addNamespace(const AtomicString& prefix, const AtomicString& uri);
 
@@ -221,7 +221,7 @@ namespace WebCore {
         CSSStyleSheet* m_styleSheet;
         RefPtr<CSSRule> m_rule;
         RefPtr<CSSRule> m_keyframe;
-        MediaQuery* m_mediaQuery;
+        OwnPtr<MediaQuery> m_mediaQuery;
         CSSParserValueList* m_valueList;
         CSSProperty** m_parsedProperties;
         CSSSelectorList* m_selectorListForParseSelector;
@@ -301,9 +301,9 @@ namespace WebCore {
         HashSet<CSSParserValueList*> m_floatingValueLists;
         HashSet<CSSParserFunction*> m_floatingFunctions;
 
-        MediaQuery* m_floatingMediaQuery;
-        MediaQueryExp* m_floatingMediaQueryExp;
-        Vector<MediaQueryExp*>* m_floatingMediaQueryExpList;
+        OwnPtr<MediaQuery> m_floatingMediaQuery;
+        OwnPtr<MediaQueryExp> m_floatingMediaQueryExp;
+        OwnPtr<Vector<MediaQueryExp*> > m_floatingMediaQueryExpList;
 
         Vector<CSSSelector*> m_reusableSelectorVector;
 
diff --git a/WebCore/css/CSSParserValues.h b/WebCore/css/CSSParserValues.h
index 5c6f55e..8644d9b 100644
--- a/WebCore/css/CSSParserValues.h
+++ b/WebCore/css/CSSParserValues.h
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2003 Lars Knoll (knoll at kde.org)
- * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -90,9 +90,7 @@ private:
 
 struct CSSParserFunction : FastAllocBase {
     CSSParserString name;
-    CSSParserValueList* args;
-
-    ~CSSParserFunction() { delete args; }
+    OwnPtr<CSSParserValueList> args;
 };
 
 }
diff --git a/WebCore/css/CSSStyleSelector.cpp b/WebCore/css/CSSStyleSelector.cpp
index 203a414..96f50cc 100644
--- a/WebCore/css/CSSStyleSelector.cpp
+++ b/WebCore/css/CSSStyleSelector.cpp
@@ -371,15 +371,15 @@ public:
     CSSRuleDataList* getIDRules(AtomicStringImpl* key) { return m_idRules.get(key); }
     CSSRuleDataList* getClassRules(AtomicStringImpl* key) { return m_classRules.get(key); }
     CSSRuleDataList* getTagRules(AtomicStringImpl* key) { return m_tagRules.get(key); }
-    CSSRuleDataList* getUniversalRules() { return m_universalRules; }
-    CSSRuleDataList* getPageRules() { return m_pageRules; }
+    CSSRuleDataList* getUniversalRules() { return m_universalRules.get(); }
+    CSSRuleDataList* getPageRules() { return m_pageRules.get(); }
     
 public:
     AtomRuleMap m_idRules;
     AtomRuleMap m_classRules;
     AtomRuleMap m_tagRules;
-    CSSRuleDataList* m_universalRules;
-    CSSRuleDataList* m_pageRules;
+    OwnPtr<CSSRuleDataList> m_universalRules;
+    OwnPtr<CSSRuleDataList> m_pageRules;
     unsigned m_ruleCount;
     unsigned m_pageRuleCount;
 };
@@ -414,21 +414,19 @@ static const MediaQueryEvaluator& printEval()
     return staticPrintEval;
 }
 
-CSSStyleSelector::CSSStyleSelector(Document* doc, StyleSheetList* styleSheets, CSSStyleSheet* mappedElementSheet,
+CSSStyleSelector::CSSStyleSelector(Document* document, StyleSheetList* styleSheets, CSSStyleSheet* mappedElementSheet,
                                    CSSStyleSheet* pageUserSheet, const Vector<RefPtr<CSSStyleSheet> >* pageGroupUserSheets,
                                    bool strictParsing, bool matchAuthorAndUserStyles)
     : m_backgroundData(BackgroundFillLayer)
-    , m_checker(doc, strictParsing)
+    , m_checker(document, strictParsing)
     , m_element(0)
     , m_styledElement(0)
     , m_elementLinkState(NotInsideLink)
-    , m_fontSelector(CSSFontSelector::create(doc))
+    , m_fontSelector(CSSFontSelector::create(document))
 {
-    init();
-        
     m_matchAuthorAndUserStyles = matchAuthorAndUserStyles;
     
-    Element* root = doc->documentElement();
+    Element* root = document->documentElement();
 
     if (!defaultStyle) {
         if (!root || elementCanUseSimpleDefaultStyle(root))
@@ -437,32 +435,28 @@ CSSStyleSelector::CSSStyleSelector(Document* doc, StyleSheetList* styleSheets, C
             loadFullDefaultStyle();
     }
 
-    m_userStyle = 0;
-
     // construct document root element default style. this is needed
     // to evaluate media queries that contain relative constraints, like "screen and (max-width: 10em)"
     // This is here instead of constructor, because when constructor is run,
     // document doesn't have documentElement
     // NOTE: this assumes that element that gets passed to styleForElement -call
     // is always from the document that owns the style selector
-    FrameView* view = doc->view();
+    FrameView* view = document->view();
     if (view)
-        m_medium = new MediaQueryEvaluator(view->mediaType());
+        m_medium = adoptPtr(new MediaQueryEvaluator(view->mediaType()));
     else
-        m_medium = new MediaQueryEvaluator("all");
+        m_medium = adoptPtr(new MediaQueryEvaluator("all"));
 
     if (root)
         m_rootDefaultStyle = styleForElement(root, 0, false, true); // don't ref, because the RenderStyle is allocated from global heap
 
-    if (m_rootDefaultStyle && view) {
-        delete m_medium;
-        m_medium = new MediaQueryEvaluator(view->mediaType(), view->frame(), m_rootDefaultStyle.get());
-    }
+    if (m_rootDefaultStyle && view)
+        m_medium = adoptPtr(new MediaQueryEvaluator(view->mediaType(), view->frame(), m_rootDefaultStyle.get()));
 
-    m_authorStyle = new CSSRuleSet();
+    m_authorStyle = adoptPtr(new CSSRuleSet);
 
     // FIXME: This sucks! The user sheet is reparsed every time!
-    OwnPtr<CSSRuleSet> tempUserStyle(new CSSRuleSet);
+    OwnPtr<CSSRuleSet> tempUserStyle = adoptPtr(new CSSRuleSet);
     if (pageUserSheet)
         tempUserStyle->addRulesFromSheet(pageUserSheet, *m_medium, this);
     if (pageGroupUserSheets) {
@@ -476,7 +470,7 @@ CSSStyleSelector::CSSStyleSelector(Document* doc, StyleSheetList* styleSheets, C
     }
 
     if (tempUserStyle->m_ruleCount > 0 || tempUserStyle->m_pageRuleCount > 0)
-        m_userStyle = tempUserStyle.leakPtr();
+        m_userStyle = tempUserStyle.release();
 
     // Add rules from elements like SVG's <font-face>
     if (mappedElementSheet)
@@ -490,8 +484,8 @@ CSSStyleSelector::CSSStyleSelector(Document* doc, StyleSheetList* styleSheets, C
             m_authorStyle->addRulesFromSheet(static_cast<CSSStyleSheet*>(sheet), *m_medium, this);
     }
 
-    if (doc->renderer() && doc->renderer()->style())
-        doc->renderer()->style()->font().update(fontSelector());
+    if (document->renderer() && document->renderer()->style())
+        document->renderer()->style()->font().update(fontSelector());
 }
 
 // This is a simplified style setting function for keyframe styles
@@ -501,23 +495,10 @@ void CSSStyleSelector::addKeyframeStyle(PassRefPtr<WebKitCSSKeyframesRule> rule)
     m_keyframesRuleMap.add(s.impl(), rule);
 }
 
-void CSSStyleSelector::init()
-{
-    initElement(0);
-    m_matchedDecls.clear();
-    m_ruleList = 0;
-    m_rootDefaultStyle = 0;
-    m_medium = 0;
-}
-
 CSSStyleSelector::~CSSStyleSelector()
 {
     m_fontSelector->clearDocument();
-    delete m_medium;
-    delete m_authorStyle;
-    delete m_userStyle;
     deleteAllValues(m_viewportDependentMediaQueryResults);
-    m_keyframesRuleMap.clear();
 }
 
 static CSSStyleSheet* parseUASheet(const String& str)
@@ -1267,7 +1248,7 @@ PassRefPtr<RenderStyle> CSSStyleSelector::styleForElement(Element* e, RenderStyl
     if (!resolveForRootDefault) {
         // 4. Now we check user sheet rules.
         if (m_matchAuthorAndUserStyles)
-            matchRules(m_userStyle, firstUserRule, lastUserRule);
+            matchRules(m_userStyle.get(), firstUserRule, lastUserRule);
 
         // 5. Now check author rules, beginning first with presentational attributes
         // mapped from HTML.
@@ -1306,7 +1287,7 @@ PassRefPtr<RenderStyle> CSSStyleSelector::styleForElement(Element* e, RenderStyl
     
         // 6. Check the rules in author sheets next.
         if (m_matchAuthorAndUserStyles)
-            matchRules(m_authorStyle, firstAuthorRule, lastAuthorRule);
+            matchRules(m_authorStyle.get(), firstAuthorRule, lastAuthorRule);
 
         // 7. Now check our inline style attribute.
         if (m_matchAuthorAndUserStyles && m_styledElement) {
@@ -1534,8 +1515,8 @@ PassRefPtr<RenderStyle> CSSStyleSelector::pseudoStyleForElement(PseudoId pseudo,
     matchUARules(firstUARule, lastUARule);
 
     if (m_matchAuthorAndUserStyles) {
-        matchRules(m_userStyle, firstUserRule, lastUserRule);
-        matchRules(m_authorStyle, firstAuthorRule, lastAuthorRule);
+        matchRules(m_userStyle.get(), firstUserRule, lastUserRule);
+        matchRules(m_authorStyle.get(), firstAuthorRule, lastAuthorRule);
     }
 
     if (m_matchedDecls.isEmpty() && !visitedStyle)
@@ -1607,8 +1588,8 @@ PassRefPtr<RenderStyle> CSSStyleSelector::styleForPage(int pageIndex)
     const bool isFirst = isFirstPage(pageIndex);
     const String page = pageName(pageIndex);
     matchPageRules(defaultPrintStyle, isLeft, isFirst, page);
-    matchPageRules(m_userStyle, isLeft, isFirst, page);
-    matchPageRules(m_authorStyle, isLeft, isFirst, page);
+    matchPageRules(m_userStyle.get(), isLeft, isFirst, page);
+    matchPageRules(m_authorStyle.get(), isLeft, isFirst, page);
     m_lineHeightValue = 0;
     applyDeclarations<true>(false, 0, m_matchedDecls.size() - 1);
 
@@ -1887,14 +1868,14 @@ PassRefPtr<CSSRuleList> CSSStyleSelector::pseudoStyleRulesForElement(Element* e,
         // Now we check user sheet rules.
         if (m_matchAuthorAndUserStyles) {
             int firstUserRule = -1, lastUserRule = -1;
-            matchRules(m_userStyle, firstUserRule, lastUserRule);
+            matchRules(m_userStyle.get(), firstUserRule, lastUserRule);
         }
     }
 
     if (m_matchAuthorAndUserStyles) {
         // Check the rules in author sheets.
         int firstAuthorRule = -1, lastAuthorRule = -1;
-        matchRules(m_authorStyle, firstAuthorRule, lastAuthorRule);
+        matchRules(m_authorStyle.get(), firstAuthorRule, lastAuthorRule);
     }
 
     m_checker.m_collectRulesOnly = false;
@@ -2787,11 +2768,9 @@ CSSValue* CSSStyleSelector::resolveVariableDependentValue(CSSVariableDependentVa
 // -----------------------------------------------------------------
 
 CSSRuleSet::CSSRuleSet()
+    : m_ruleCount(0)
+    , m_pageRuleCount(0)
 {
-    m_universalRules = 0;
-    m_pageRules = 0;
-    m_ruleCount = 0;
-    m_pageRuleCount = 0;
 }
 
 CSSRuleSet::~CSSRuleSet()
@@ -2799,9 +2778,6 @@ CSSRuleSet::~CSSRuleSet()
     deleteAllValues(m_idRules);
     deleteAllValues(m_classRules);
     deleteAllValues(m_tagRules);
-
-    delete m_universalRules; 
-    delete m_pageRules;
 }
 
 
@@ -2836,7 +2812,7 @@ void CSSRuleSet::addRule(CSSStyleRule* rule, CSSSelector* sel)
     
     // Just put it in the universal rule set.
     if (!m_universalRules)
-        m_universalRules = new CSSRuleDataList(m_ruleCount++, rule, sel);
+        m_universalRules = adoptPtr(new CSSRuleDataList(m_ruleCount++, rule, sel));
     else
         m_universalRules->append(m_ruleCount++, rule, sel);
 }
@@ -2844,7 +2820,7 @@ void CSSRuleSet::addRule(CSSStyleRule* rule, CSSSelector* sel)
 void CSSRuleSet::addPageRule(CSSStyleRule* rule, CSSSelector* sel)
 {
     if (!m_pageRules)
-        m_pageRules = new CSSRuleDataList(m_pageRuleCount++, rule, sel);
+        m_pageRules = adoptPtr(new CSSRuleDataList(m_pageRuleCount++, rule, sel));
     else
         m_pageRules->append(m_pageRuleCount++, rule, sel);
 }
@@ -4322,9 +4298,9 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value)
                 }
                 case CSSPrimitiveValue::CSS_COUNTER: {
                     Counter* counterValue = val->getCounterValue();
-                    CounterContent* counter = new CounterContent(counterValue->identifier(),
-                        (EListStyleType)counterValue->listStyleNumber(), counterValue->separator());
-                    m_style->setContent(counter, didSet);
+                    OwnPtr<CounterContent> counter = adoptPtr(new CounterContent(counterValue->identifier(),
+                        (EListStyleType)counterValue->listStyleNumber(), counterValue->separator()));
+                    m_style->setContent(counter.release(), didSet);
                     didSet = true;
                 }
             }
diff --git a/WebCore/css/CSSStyleSelector.h b/WebCore/css/CSSStyleSelector.h
index c3e423a..7038b44 100644
--- a/WebCore/css/CSSStyleSelector.h
+++ b/WebCore/css/CSSStyleSelector.h
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 1999 Lars Knoll (knoll at kde.org)
- * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -195,8 +195,8 @@ public:
         bool isFirstPage(int pageIndex) const;
         String pageName(int pageIndex) const;
         
-        CSSRuleSet* m_authorStyle;
-        CSSRuleSet* m_userStyle;
+        OwnPtr<CSSRuleSet> m_authorStyle;
+        OwnPtr<CSSRuleSet> m_userStyle;
 
         bool m_hasUAAppearance;
         BorderData m_borderData;
@@ -235,8 +235,6 @@ public:
     private:
         static RenderStyle* s_styleNotYetAvailable;
 
-        void init();
-
         void matchUARules(int& firstUARule, int& lastUARule);
         void updateFont();
         void cacheBorderAndBackground();
@@ -292,7 +290,7 @@ public:
         
         HashSet<int> m_pendingImageProperties; // Hash of CSSPropertyIDs
 
-        MediaQueryEvaluator* m_medium;
+        OwnPtr<MediaQueryEvaluator> m_medium;
         RefPtr<RenderStyle> m_rootDefaultStyle;
 
         PseudoId m_dynamicPseudo;
diff --git a/WebCore/css/CSSStyleSheet.cpp b/WebCore/css/CSSStyleSheet.cpp
index 69c769a..9bbcb8b 100644
--- a/WebCore/css/CSSStyleSheet.cpp
+++ b/WebCore/css/CSSStyleSheet.cpp
@@ -36,8 +36,7 @@ namespace WebCore {
 
 CSSStyleSheet::CSSStyleSheet(CSSStyleSheet* parentSheet, const String& href, const KURL& baseURL, const String& charset)
     : StyleSheet(parentSheet, href, baseURL)
-    , m_doc(parentSheet ? parentSheet->doc() : 0)
-    , m_namespaces(0)
+    , m_document(parentSheet ? parentSheet->document() : 0)
     , m_charset(charset)
     , m_loadCompleted(false)
     , m_strictParsing(!parentSheet || parentSheet->useStrictParsing())
@@ -48,8 +47,7 @@ CSSStyleSheet::CSSStyleSheet(CSSStyleSheet* parentSheet, const String& href, con
 
 CSSStyleSheet::CSSStyleSheet(Node* parentNode, const String& href, const KURL& baseURL, const String& charset)
     : StyleSheet(parentNode, href, baseURL)
-    , m_doc(parentNode->document())
-    , m_namespaces(0)
+    , m_document(parentNode->document())
     , m_charset(charset)
     , m_loadCompleted(false)
     , m_strictParsing(false)
@@ -60,20 +58,18 @@ CSSStyleSheet::CSSStyleSheet(Node* parentNode, const String& href, const KURL& b
 
 CSSStyleSheet::CSSStyleSheet(CSSRule* ownerRule, const String& href, const KURL& baseURL, const String& charset)
     : StyleSheet(ownerRule, href, baseURL)
-    , m_namespaces(0)
     , m_charset(charset)
     , m_loadCompleted(false)
     , m_strictParsing(!ownerRule || ownerRule->useStrictParsing())
     , m_hasSyntacticallyValidCSSHeader(true)
 {
     CSSStyleSheet* parentSheet = ownerRule ? ownerRule->parentStyleSheet() : 0;
-    m_doc = parentSheet ? parentSheet->doc() : 0;
+    m_document = parentSheet ? parentSheet->document() : 0;
     m_isUserStyleSheet = parentSheet ? parentSheet->isUserStyleSheet() : false;
 }
 
 CSSStyleSheet::~CSSStyleSheet()
 {
-    delete m_namespaces;
 }
 
 CSSRule *CSSStyleSheet::ownerRule() const
@@ -137,7 +133,7 @@ int CSSStyleSheet::addRule(const String& selector, const String& style, Exceptio
 PassRefPtr<CSSRuleList> CSSStyleSheet::cssRules(bool omitCharsetRules)
 {
     KURL url = finalURL();
-    if (!url.isEmpty() && doc() && !doc()->securityOrigin()->canRequest(url))
+    if (!url.isEmpty() && document() && !document()->securityOrigin()->canRequest(url))
         return 0;
     return CSSRuleList::create(this, omitCharsetRules);
 }
@@ -159,7 +155,7 @@ void CSSStyleSheet::addNamespace(CSSParser* p, const AtomicString& prefix, const
     if (uri.isNull())
         return;
 
-    m_namespaces = new CSSNamespace(prefix, uri, m_namespaces);
+    m_namespaces = adoptPtr(new CSSNamespace(prefix, uri, m_namespaces.release()));
     
     if (prefix.isEmpty())
         // Set the default namespace on the parser so that selectors that omit namespace info will
@@ -174,11 +170,10 @@ const AtomicString& CSSStyleSheet::determineNamespace(const AtomicString& prefix
     if (prefix == starAtom)
         return starAtom; // We'll match any namespace.
     if (m_namespaces) {
-        CSSNamespace* ns = m_namespaces->namespaceForPrefix(prefix);
-        if (ns)
-            return ns->uri();
+        if (CSSNamespace* namespaceForPrefix = m_namespaces->namespaceForPrefix(prefix))
+            return namespaceForPrefix->uri;
     }
-    return nullAtom; // Assume we wont match any namespaces.
+    return nullAtom; // Assume we won't match any namespaces.
 }
 
 bool CSSStyleSheet::parseString(const String &string, bool strict)
@@ -224,7 +219,7 @@ void CSSStyleSheet::styleSheetChanged()
     StyleBase* root = this;
     while (StyleBase* parent = root->parent())
         root = parent;
-    Document* documentToUpdate = root->isCSSStyleSheet() ? static_cast<CSSStyleSheet*>(root)->doc() : 0;
+    Document* documentToUpdate = root->isCSSStyleSheet() ? static_cast<CSSStyleSheet*>(root)->document() : 0;
     
     /* FIXME: We don't need to do everything updateStyleSelector does,
      * basically we just need to recreate the document's selector with the
diff --git a/WebCore/css/CSSStyleSheet.h b/WebCore/css/CSSStyleSheet.h
index fe82794..3b18522 100644
--- a/WebCore/css/CSSStyleSheet.h
+++ b/WebCore/css/CSSStyleSheet.h
@@ -1,6 +1,6 @@
 /*
  * (C) 1999-2003 Lars Knoll (knoll at kde.org)
- * Copyright (C) 2004, 2006, 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2004, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -87,7 +87,7 @@ public:
 
     virtual void checkLoaded();
 
-    Document* doc() { return m_doc; }
+    Document* document() { return m_document; }
 
     const String& charset() const { return m_charset; }
 
@@ -112,8 +112,8 @@ private:
     virtual bool isCSSStyleSheet() const { return true; }
     virtual String type() const { return "text/css"; }
 
-    Document* m_doc;
-    CSSNamespace* m_namespaces;
+    Document* m_document;
+    OwnPtr<CSSNamespace> m_namespaces;
     String m_charset;
     bool m_loadCompleted : 1;
     bool m_strictParsing : 1;
diff --git a/WebCore/css/CSSValueList.cpp b/WebCore/css/CSSValueList.cpp
index 8f1f88d..f8d8457 100644
--- a/WebCore/css/CSSValueList.cpp
+++ b/WebCore/css/CSSValueList.cpp
@@ -1,6 +1,6 @@
-/**
+/*
  * (C) 1999-2003 Lars Knoll (knoll at kde.org)
- * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2004, 2005, 2006, 2007, 2010 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -17,11 +17,13 @@
  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  * Boston, MA 02110-1301, USA.
  */
+
 #include "config.h"
 #include "CSSValueList.h"
 
 #include "CSSParserValues.h"
 #include "PlatformString.h"
+#include <wtf/PassOwnPtr.h>
 
 namespace WebCore {
 
@@ -34,11 +36,9 @@ CSSValueList::CSSValueList(CSSParserValueList* list)
     : m_isSpaceSeparated(true)
 {
     if (list) {
-        unsigned s = list->size();
-        for (unsigned i = 0; i < s; ++i) {
-            CSSParserValue* v = list->valueAt(i);
-            append(v->createCSSValue());
-        }
+        size_t size = list->size();
+        for (unsigned i = 0; i < size; ++i)
+            append(list->valueAt(i)->createCSSValue());
     }
 }
 
@@ -120,15 +120,15 @@ String CSSValueList::cssText() const
     return result;
 }
 
-CSSParserValueList* CSSValueList::createParserValueList() const
+PassOwnPtr<CSSParserValueList> CSSValueList::createParserValueList() const
 {
-    unsigned s = m_values.size();
-    if (!s)
+    size_t size = m_values.size();
+    if (!size)
         return 0;
-    CSSParserValueList* result = new CSSParserValueList;
-    for (unsigned i = 0; i < s; ++i)
+    OwnPtr<CSSParserValueList> result = adoptPtr(new CSSParserValueList);
+    for (size_t i = 0; i < size; ++i)
         result->addValue(m_values[i]->parserValue());
-    return result;
+    return result.release();
 }
 
 void CSSValueList::addSubresourceStyleURLs(ListHashSet<KURL>& urls, const CSSStyleSheet* styleSheet)
diff --git a/WebCore/css/CSSValueList.h b/WebCore/css/CSSValueList.h
index b835345..0d5c882 100644
--- a/WebCore/css/CSSValueList.h
+++ b/WebCore/css/CSSValueList.h
@@ -1,6 +1,6 @@
 /*
  * (C) 1999-2003 Lars Knoll (knoll at kde.org)
- * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -58,7 +58,7 @@ public:
 
     virtual String cssText() const;
 
-    CSSParserValueList* createParserValueList() const;
+    PassOwnPtr<CSSParserValueList> createParserValueList() const;
 
     virtual void addSubresourceStyleURLs(ListHashSet<KURL>&, const CSSStyleSheet*);
 
diff --git a/WebCore/css/CSSVariablesDeclaration.cpp b/WebCore/css/CSSVariablesDeclaration.cpp
index 23d7f83..e40750a 100644
--- a/WebCore/css/CSSVariablesDeclaration.cpp
+++ b/WebCore/css/CSSVariablesDeclaration.cpp
@@ -169,7 +169,7 @@ void CSSVariablesDeclaration::setNeedsStyleRecalc()
     while (StyleBase* parent = root->parent())
         root = parent;
     if (root->isCSSStyleSheet())
-        static_cast<CSSStyleSheet*>(root)->doc()->styleSelectorChanged(DeferRecalcStyle);
+        static_cast<CSSStyleSheet*>(root)->document()->styleSelectorChanged(DeferRecalcStyle);
 }
 
 }
diff --git a/WebCore/css/MediaList.cpp b/WebCore/css/MediaList.cpp
index 85cf590..e67c9c7 100644
--- a/WebCore/css/MediaList.cpp
+++ b/WebCore/css/MediaList.cpp
@@ -1,6 +1,6 @@
 /*
  * (C) 1999-2003 Lars Knoll (knoll at kde.org)
- * Copyright (C) 2004, 2006 Apple Computer, Inc.
+ * Copyright (C) 2004, 2006, 2010 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -122,7 +122,7 @@ void MediaList::deleteMedium(const String& oldMedium, ExceptionCode& ec)
     CSSParser p(true);
 
     MediaQuery* oldQuery = 0;
-    bool deleteOldQuery = false;
+    OwnPtr<MediaQuery> createdQuery;
 
     if (p.parseMediaQuery(tempMediaList.get(), oldMedium)) {
         if (tempMediaList->m_queries.size() > 0)
@@ -130,8 +130,8 @@ void MediaList::deleteMedium(const String& oldMedium, ExceptionCode& ec)
     } else if (m_fallback) {
         String medium = parseMediaDescriptor(oldMedium);
         if (!medium.isNull()) {
-            oldQuery = new MediaQuery(MediaQuery::None, medium, 0);
-            deleteOldQuery = true;
+            createdQuery = adoptPtr(new MediaQuery(MediaQuery::None, medium, 0));
+            oldQuery = createdQuery.get();
         }
     }
 
@@ -148,8 +148,6 @@ void MediaList::deleteMedium(const String& oldMedium, ExceptionCode& ec)
                 break;
             }
         }
-        if (deleteOldQuery)
-            delete oldQuery;
     }
     
     if (!ec)
@@ -242,9 +240,9 @@ void MediaList::appendMedium(const String& newMedium, ExceptionCode& ec)
         notifyChanged();
 }
 
-void MediaList::appendMediaQuery(MediaQuery* mediaQuery)
+void MediaList::appendMediaQuery(PassOwnPtr<MediaQuery> mediaQuery)
 {
-    m_queries.append(mediaQuery);
+    m_queries.append(mediaQuery.leakPtr());
 }
 
 void MediaList::notifyChanged()
diff --git a/WebCore/css/MediaList.h b/WebCore/css/MediaList.h
index e91ca9d..f4b1fa7 100644
--- a/WebCore/css/MediaList.h
+++ b/WebCore/css/MediaList.h
@@ -1,6 +1,6 @@
 /*
  * (C) 1999-2003 Lars Knoll (knoll at kde.org)
- * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2004, 2006, 2008, 2009, 2010 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -73,7 +73,7 @@ public:
     String mediaText() const;
     void setMediaText(const String&, ExceptionCode&xo);
 
-    void appendMediaQuery(MediaQuery*);
+    void appendMediaQuery(PassOwnPtr<MediaQuery>);
     const Vector<MediaQuery*>& mediaQueries() const { return m_queries; }
 
 private:
diff --git a/WebCore/inspector/InspectorDOMAgent.cpp b/WebCore/inspector/InspectorDOMAgent.cpp
index 82827bd..d2760e4 100644
--- a/WebCore/inspector/InspectorDOMAgent.cpp
+++ b/WebCore/inspector/InspectorDOMAgent.cpp
@@ -1167,14 +1167,14 @@ void InspectorDOMAgent::getAllStyles(RefPtr<InspectorArray>* styles)
 void InspectorDOMAgent::getStyleSheet(long styleSheetId, RefPtr<InspectorObject>* styleSheetObject)
 {
     CSSStyleSheet* styleSheet = cssStore()->styleSheetForId(styleSheetId);
-    if (styleSheet && styleSheet->doc())
-        *styleSheetObject = buildObjectForStyleSheet(styleSheet->doc(), styleSheet);
+    if (styleSheet && styleSheet->document())
+        *styleSheetObject = buildObjectForStyleSheet(styleSheet->document(), styleSheet);
 }
 
 void InspectorDOMAgent::getRuleRanges(long styleSheetId, RefPtr<InspectorValue>* ruleRange)
 {
     CSSStyleSheet* styleSheet = cssStore()->styleSheetForId(styleSheetId);
-    if (styleSheet && styleSheet->doc()) {
+    if (styleSheet && styleSheet->document()) {
         HashMap<long, SourceRange> ruleRanges = cssStore()->getRuleRanges(styleSheet);
         if (!ruleRanges.size())
             return;
@@ -1509,7 +1509,7 @@ PassRefPtr<InspectorObject> InspectorDOMAgent::buildObjectForStyleSheet(Document
     result->setBoolean("disabled", styleSheet->disabled());
     result->setString("href", styleSheet->href());
     result->setString("title", styleSheet->title());
-    result->setNumber("documentElementId", m_documentNodeToIdMap.get(styleSheet->doc()));
+    result->setNumber("documentElementId", m_documentNodeToIdMap.get(styleSheet->document()));
     RefPtr<InspectorArray> cssRules = InspectorArray::create();
     PassRefPtr<CSSRuleList> cssRuleList = CSSRuleList::create(styleSheet, true);
     if (cssRuleList) {
diff --git a/WebCore/rendering/style/ContentData.cpp b/WebCore/rendering/style/ContentData.cpp
index b0f9e81..25b889b 100644
--- a/WebCore/rendering/style/ContentData.cpp
+++ b/WebCore/rendering/style/ContentData.cpp
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 1999 Antti Koivisto (koivisto at kde.org)
- * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -32,42 +32,26 @@ void ContentData::clear()
 {
     deleteContent();
 
-    ContentData* n = m_next;
-    m_next = 0;
-
-    // Reverse the list so we can delete without recursing.
-    ContentData* last = 0;
-    ContentData* c;
-    while ((c = n)) {
-        n = c->m_next;
-        c->m_next = last;
-        last = c;
-    }
-    for (c = last; c; c = n) {
-        n = c->m_next;
-        c->m_next = 0;
-        delete c;
-    }
+    // Delete the singly-linked list without recursing.
+    for (OwnPtr<ContentData> next = m_next.release(); next; next = next->m_next.release()) { }
 }
 
+// FIXME: Why isn't this just operator==?
+// FIXME: This is not a good name for a boolean-returning function.
 bool ContentData::dataEquivalent(const ContentData& other) const
 {
     if (type() != other.type())
         return false;
 
     switch (type()) {
-        case CONTENT_NONE:
-            return true;
-            break;
-        case CONTENT_TEXT:
-            return equal(text(), other.text());
-            break;
-        case CONTENT_OBJECT:
-            return StyleImage::imagesEquivalent(image(), other.image());
-            break;
-        case CONTENT_COUNTER:
-            return *counter() == *other.counter();
-            break;
+    case CONTENT_NONE:
+        return true;
+    case CONTENT_TEXT:
+        return equal(text(), other.text());
+    case CONTENT_OBJECT:
+        return StyleImage::imagesEquivalent(image(), other.image());
+    case CONTENT_COUNTER:
+        return *counter() == *other.counter();
     }
 
     ASSERT_NOT_REACHED();
@@ -77,17 +61,17 @@ bool ContentData::dataEquivalent(const ContentData& other) const
 void ContentData::deleteContent()
 {
     switch (m_type) {
-        case CONTENT_NONE:
-            break;
-        case CONTENT_OBJECT:
-            m_content.m_image->deref();
-            break;
-        case CONTENT_TEXT:
-            m_content.m_text->deref();
-            break;
-        case CONTENT_COUNTER:
-            delete m_content.m_counter;
-            break;
+    case CONTENT_NONE:
+        break;
+    case CONTENT_OBJECT:
+        m_content.m_image->deref();
+        break;
+    case CONTENT_TEXT:
+        m_content.m_text->deref();
+        break;
+    case CONTENT_COUNTER:
+        delete m_content.m_counter;
+        break;
     }
 
     m_type = CONTENT_NONE;
diff --git a/WebCore/rendering/style/ContentData.h b/WebCore/rendering/style/ContentData.h
index 5c3565e..14cef9f 100644
--- a/WebCore/rendering/style/ContentData.h
+++ b/WebCore/rendering/style/ContentData.h
@@ -2,7 +2,7 @@
  * Copyright (C) 2000 Lars Knoll (knoll at kde.org)
  *           (C) 2000 Antti Koivisto (koivisto at kde.org)
  *           (C) 2000 Dirk Mueller (mueller at kde.org)
- * Copyright (C) 2003, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2003, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights reserved.
  * Copyright (C) 2006 Graham Dennis (graham.dennis at gmail.com)
  *
  * This library is free software; you can redistribute it and/or
@@ -28,6 +28,8 @@
 #include "RenderStyleConstants.h"
 #include <wtf/Forward.h>
 #include <wtf/Noncopyable.h>
+#include <wtf/OwnPtr.h>
+#include <wtf/PassOwnPtr.h>
 #include <wtf/PassRefPtr.h>
 
 namespace WebCore {
@@ -39,7 +41,6 @@ struct ContentData : Noncopyable {
 public:
     ContentData()
         : m_type(CONTENT_NONE)
-        , m_next(0)
     {
     }
 
@@ -59,35 +60,44 @@ public:
 
     bool dataEquivalent(const ContentData&) const;
 
-    StyleImage* image() const { return m_content.m_image; }
+    StyleImage* image() const
+    {
+        ASSERT(isImage());
+        return m_content.m_image;
+    }
     void setImage(PassRefPtr<StyleImage> image)
     {
         deleteContent();
         m_type = CONTENT_OBJECT;
-        m_content.m_image = image.releaseRef();
+        m_content.m_image = image.leakRef();
     }
 
-    StringImpl* text() const { return m_content.m_text; }
+    StringImpl* text() const
+    {
+        ASSERT(isText());
+        return m_content.m_text;
+    }
     void setText(PassRefPtr<StringImpl> text)
     {
         deleteContent();
         m_type = CONTENT_TEXT;
-        m_content.m_text = text.releaseRef();
+        m_content.m_text = text.leakRef();
     }
 
-    CounterContent* counter() const { return m_content.m_counter; }
-    void setCounter(CounterContent* counter)
+    CounterContent* counter() const
+    {
+        ASSERT(isCounter());
+        return m_content.m_counter;
+    }
+    void setCounter(PassOwnPtr<CounterContent> counter)
     {
         deleteContent();
         m_type = CONTENT_COUNTER;
-        m_content.m_counter = counter;
+        m_content.m_counter = counter.leakPtr();
     }
 
-    ContentData* next() const { return m_next; }
-    void setNext(ContentData* next)
-    {
-        m_next = next;
-    }
+    ContentData* next() const { return m_next.get(); }
+    void setNext(PassOwnPtr<ContentData> next) { m_next = next; }
 
 private:
     void deleteContent();
@@ -98,7 +108,7 @@ private:
         StringImpl* m_text;
         CounterContent* m_counter;
     } m_content;
-    ContentData* m_next;
+    OwnPtr<ContentData> m_next;
 };
 
 } // namespace WebCore
diff --git a/WebCore/rendering/style/RenderStyle.cpp b/WebCore/rendering/style/RenderStyle.cpp
index 6c925b2..b75c4b7 100644
--- a/WebCore/rendering/style/RenderStyle.cpp
+++ b/WebCore/rendering/style/RenderStyle.cpp
@@ -575,92 +575,59 @@ void RenderStyle::clearContent()
         rareNonInheritedData->m_content->clear();
 }
 
-void RenderStyle::setContent(PassRefPtr<StyleImage> image, bool add)
+ContentData* RenderStyle::prepareToSetContent(StringImpl* string, bool add)
 {
-    if (!image)
-        return; // The object is null. Nothing to do. Just bail.
-
     OwnPtr<ContentData>& content = rareNonInheritedData.access()->m_content;
     ContentData* lastContent = content.get();
     while (lastContent && lastContent->next())
         lastContent = lastContent->next();
 
+    if (string && add && lastContent && lastContent->isText()) {
+        // Augment the existing string and share the existing ContentData node.
+        String newText = lastContent->text();
+        newText.append(string);
+        lastContent->setText(newText.impl());
+        return 0;
+    }
+
     bool reuseContent = !add;
-    ContentData* newContentData;
+    OwnPtr<ContentData> newContentData;
     if (reuseContent && content) {
         content->clear();
-        newContentData = content.leakPtr();
+        newContentData = content.release();
     } else
-        newContentData = new ContentData;
+        newContentData = adoptPtr(new ContentData);
+
+    ContentData* result = newContentData.get();
 
     if (lastContent && !reuseContent)
-        lastContent->setNext(newContentData);
+        lastContent->setNext(newContentData.release());
     else
-        content.set(newContentData);
+        content = newContentData.release();
 
-    newContentData->setImage(image);
+    return result;
 }
 
-void RenderStyle::setContent(PassRefPtr<StringImpl> s, bool add)
+void RenderStyle::setContent(PassRefPtr<StyleImage> image, bool add)
 {
-    if (!s)
-        return; // The string is null. Nothing to do. Just bail.
-
-    OwnPtr<ContentData>& content = rareNonInheritedData.access()->m_content;
-    ContentData* lastContent = content.get();
-    while (lastContent && lastContent->next())
-        lastContent = lastContent->next();
-
-    bool reuseContent = !add;
-    if (add && lastContent) {
-        if (lastContent->isText()) {
-            // We can augment the existing string and share this ContentData node.
-            String newStr = lastContent->text();
-            newStr.append(s.get());
-            lastContent->setText(newStr.impl());
-            return;
-        }
-    }
-
-    ContentData* newContentData = 0;
-    if (reuseContent && content) {
-        content->clear();
-        newContentData = content.leakPtr();
-    } else
-        newContentData = new ContentData;
-
-    if (lastContent && !reuseContent)
-        lastContent->setNext(newContentData);
-    else
-        content.set(newContentData);
-
-    newContentData->setText(s);
+    if (!image)
+        return;
+    prepareToSetContent(0, add)->setImage(image);
 }
 
-void RenderStyle::setContent(CounterContent* c, bool add)
+void RenderStyle::setContent(PassRefPtr<StringImpl> string, bool add)
 {
-    if (!c)
+    if (!string)
         return;
+    if (ContentData* data = prepareToSetContent(string.get(), add))
+        data->setText(string);
+}
 
-    OwnPtr<ContentData>& content = rareNonInheritedData.access()->m_content;
-    ContentData* lastContent = content.get();
-    while (lastContent && lastContent->next())
-        lastContent = lastContent->next();
-
-    bool reuseContent = !add;
-    ContentData* newContentData = 0;
-    if (reuseContent && content) {
-        content->clear();
-        newContentData = content.leakPtr();
-    } else
-        newContentData = new ContentData;
-
-    if (lastContent && !reuseContent)
-        lastContent->setNext(newContentData);
-    else
-        content.set(newContentData);
-
-    newContentData->setCounter(c);
+void RenderStyle::setContent(PassOwnPtr<CounterContent> counter, bool add)
+{
+    if (!counter)
+        return;
+    prepareToSetContent(0, add)->setCounter(counter);
 }
 
 void RenderStyle::applyTransform(TransformationMatrix& transform, const IntSize& borderBoxSize, ApplyTransformOrigin applyOrigin) const
diff --git a/WebCore/rendering/style/RenderStyle.h b/WebCore/rendering/style/RenderStyle.h
index 2363a9e..920e452 100644
--- a/WebCore/rendering/style/RenderStyle.h
+++ b/WebCore/rendering/style/RenderStyle.h
@@ -1049,7 +1049,7 @@ public:
     void clearContent();
     void setContent(PassRefPtr<StringImpl>, bool add = false);
     void setContent(PassRefPtr<StyleImage>, bool add = false);
-    void setContent(CounterContent*, bool add = false);
+    void setContent(PassOwnPtr<CounterContent>, bool add = false);
 
     const CounterDirectiveMap* counterDirectives() const;
     CounterDirectiveMap& accessCounterDirectives();
@@ -1224,6 +1224,8 @@ private:
     const Color& textStrokeColor() const { return rareInheritedData->textStrokeColor; }
     
     const Color colorIncludingFallback(int colorProperty, EBorderStyle borderStyle) const;
+
+    ContentData* prepareToSetContent(StringImpl*, bool add);
 };
 
 } // namespace WebCore

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list