Modernize CSS code
https://bugs.webkit.org/show_bug.cgi?id=157875

Reviewed by Chris Dumez.

* bindings/scripts/CodeGeneratorJS.pm:
(GenerateImplementation):
(GenerateParametersCheck):
* bindings/scripts/test/JS/JSTestMediaQueryListListener.cpp:
(WebCore::jsTestMediaQueryListListenerPrototypeFunctionMethod):
* bindings/scripts/test/JS/JSTestObj.cpp:
(WebCore::JSTestObjConstructor::construct):
(WebCore::setJSTestObjPutForwardsNullableAttribute):
(WebCore::jsTestObjPrototypeFunctionMethodWithCallbackArg):
(WebCore::jsTestObjPrototypeFunctionMethodWithNonCallbackArgAndCallbackArg):
(WebCore::jsTestObjPrototypeFunctionMethodWithCallbackFunctionArg):
(WebCore::jsTestObjPrototypeFunctionMethodWithNonCallbackArgAndCallbackFunctionArg):
(WebCore::jsTestObjConstructorFunctionStaticMethodWithCallbackArg):
(WebCore::jsTestObjPrototypeFunctionOverloadedMethod5):
* bindings/scripts/test/JS/JSTestTypedefs.cpp:
(WebCore::JSTestTypedefsConstructor::construct):
* css/CSSBasicShapes.cpp:
(WebCore::serializePositionOffset):
(WebCore::buildSerializablePositionOffset):
(WebCore::CSSBasicShapeCircle::cssText):
(WebCore::CSSBasicShapeEllipse::cssText):
* css/CSSCalculationValue.cpp:
(WebCore::determineCategory):
(WebCore::CSSCalcExpressionNodeParser::parseValue):
* css/CSSMediaRule.cpp:
(WebCore::CSSMediaRule::media):
* css/CSSMediaRule.h:
* css/CSSOMUtils.h:
* css/CSSParser.cpp:
(WebCore::CSSParser::createImportRule):
(WebCore::CSSParser::createMediaRule):
* css/CSSReflectValue.h:
* css/CSSStyleSheet.cpp:
(WebCore::CSSStyleSheet::setDisabled):
(WebCore::CSSStyleSheet::setMediaQueries):
(WebCore::CSSStyleSheet::insertRule):
(WebCore::CSSStyleSheet::deleteRule):
(WebCore::CSSStyleSheet::isLoading):
(WebCore::CSSStyleSheet::media):
(WebCore::CSSStyleSheet::parentStyleSheet):
(WebCore::CSSStyleSheet::ownerDocument):
(WebCore::CSSStyleSheet::clearChildRuleCSSOMWrappers):
(WebCore::CSSStyleSheet::RuleMutationScope::RuleMutationScope):
* css/CSSStyleSheet.h:
* css/PropertySetCSSStyleDeclaration.cpp:
* css/StyleRule.cpp:
(WebCore::StyleRuleBase::createCSSOMWrapper):
(WebCore::StyleRuleBase::destroy):
(WebCore::StyleRuleGroup::wrapperRemoveRule):
(WebCore::StyleRuleMedia::StyleRuleMedia):
* css/StyleRule.h:
(WebCore::StyleRuleBase::deref):
(WebCore::StyleRuleBase::StyleRuleBase):
(WebCore::StyleRuleMedia::create):
(WebCore::StyleRuleMedia::mediaQueries):
(WebCore::StyleRuleMedia::copy):
(isType):
* css/StyleRuleImport.cpp:
(WebCore::StyleRuleImport::create):
(WebCore::StyleRuleImport::StyleRuleImport):
* css/StyleRuleImport.h:
* css/StyleSheetContents.cpp:
(WebCore::StyleSheetContents::isCacheable):
(WebCore::StyleSheetContents::parserAppendRule):
(WebCore::StyleSheetContents::ruleAt):
(WebCore::StyleSheetContents::parserSetEncodingFromCharsetRule):
(WebCore::StyleSheetContents::wrapperInsertRule):
* css/StyleSheetContents.h:
(WebCore::StyleSheetContents::hasSyntacticallyValidCSSHeader):
(WebCore::StyleSheetContents::parserSetUsesRemUnits):
(WebCore::StyleSheetContents::parserSetUsesStyleBasedEditability):
(WebCore::StyleSheetContents::copy):
* dom/InlineStyleSheetOwner.cpp:
(WebCore::InlineStyleSheetOwner::createSheet):
* inspector/InspectorStyleSheet.cpp:



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@201318 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/css/CSSBasicShapes.cpp b/Source/WebCore/css/CSSBasicShapes.cpp
index a212a63..7e9ce72 100644
--- a/Source/WebCore/css/CSSBasicShapes.cpp
+++ b/Source/WebCore/css/CSSBasicShapes.cpp
@@ -51,7 +51,7 @@
     return offset.cssText();
 }
 
-static Ref<CSSPrimitiveValue> buildSerializablePositionOffset(PassRefPtr<CSSPrimitiveValue> offset, CSSValueID defaultSide)
+static Ref<CSSPrimitiveValue> buildSerializablePositionOffset(CSSPrimitiveValue* offset, CSSValueID defaultSide)
 {
     CSSValueID side = defaultSide;
     RefPtr<CSSPrimitiveValue> amount;
@@ -110,8 +110,8 @@
 
 String CSSBasicShapeCircle::cssText() const
 {
-    Ref<CSSPrimitiveValue> normalizedCX = buildSerializablePositionOffset(m_centerX, CSSValueLeft);
-    Ref<CSSPrimitiveValue> normalizedCY = buildSerializablePositionOffset(m_centerY, CSSValueTop);
+    Ref<CSSPrimitiveValue> normalizedCX = buildSerializablePositionOffset(m_centerX.get(), CSSValueLeft);
+    Ref<CSSPrimitiveValue> normalizedCY = buildSerializablePositionOffset(m_centerY.get(), CSSValueTop);
 
     String radius;
     if (m_radius && m_radius->getValueID() != CSSValueClosestSide)
@@ -167,8 +167,8 @@
 
 String CSSBasicShapeEllipse::cssText() const
 {
-    Ref<CSSPrimitiveValue> normalizedCX = buildSerializablePositionOffset(m_centerX, CSSValueLeft);
-    Ref<CSSPrimitiveValue> normalizedCY = buildSerializablePositionOffset(m_centerY, CSSValueTop);
+    Ref<CSSPrimitiveValue> normalizedCX = buildSerializablePositionOffset(m_centerX.get(), CSSValueLeft);
+    Ref<CSSPrimitiveValue> normalizedCY = buildSerializablePositionOffset(m_centerY.get(), CSSValueTop);
 
     String radiusX;
     String radiusY;
diff --git a/Source/WebCore/css/CSSCalculationValue.cpp b/Source/WebCore/css/CSSCalculationValue.cpp
index aaa54e6..54850c9 100644
--- a/Source/WebCore/css/CSSCalculationValue.cpp
+++ b/Source/WebCore/css/CSSCalculationValue.cpp
@@ -200,9 +200,9 @@
 class CSSCalcPrimitiveValue final : public CSSCalcExpressionNode {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    static Ref<CSSCalcPrimitiveValue> create(PassRefPtr<CSSPrimitiveValue> value, bool isInteger)
+    static Ref<CSSCalcPrimitiveValue> create(Ref<CSSPrimitiveValue>&& value, bool isInteger)
     {
-        return adoptRef(*new CSSCalcPrimitiveValue(value, isInteger));
+        return adoptRef(*new CSSCalcPrimitiveValue(WTFMove(value), isInteger));
     }
 
     static RefPtr<CSSCalcPrimitiveValue> create(double value, CSSPrimitiveValue::UnitTypes type, bool isInteger)
@@ -232,9 +232,7 @@
             return std::make_unique<CalcExpressionLength>(Length(m_value->computeLength<float>(conversionData), WebCore::Fixed));
         case CalcPercent:
         case CalcPercentLength: {
-            CSSPrimitiveValue* primitiveValue = m_value.get();
-            return std::make_unique<CalcExpressionLength>(primitiveValue
-                ? primitiveValue->convertToLength<FixedFloatConversion | PercentConversion>(conversionData) : Length(Undefined));
+            return std::make_unique<CalcExpressionLength>(m_value->convertToLength<FixedFloatConversion | PercentConversion>(conversionData));
         }
         // Only types that could be part of a Length expression can be converted
         // to a CalcExpressionNode. CalcPercentNumber makes no sense as a Length.
@@ -283,7 +281,7 @@
         if (type() != other.type())
             return false;
 
-        return compareCSSValuePtr(m_value, static_cast<const CSSCalcPrimitiveValue&>(other).m_value);
+        return compareCSSValue(m_value, static_cast<const CSSCalcPrimitiveValue&>(other).m_value);
     }
 
     Type type() const override { return CssCalcPrimitiveValue; }
@@ -293,13 +291,13 @@
     }
 
 private:
-    explicit CSSCalcPrimitiveValue(PassRefPtr<CSSPrimitiveValue> value, bool isInteger)
+    explicit CSSCalcPrimitiveValue(Ref<CSSPrimitiveValue>&& value, bool isInteger)
         : CSSCalcExpressionNode(unitCategory((CSSPrimitiveValue::UnitTypes)value->primitiveType()), isInteger)
-        , m_value(value)
+        , m_value(WTFMove(value))
     {
     }
 
-    RefPtr<CSSPrimitiveValue> m_value;
+    Ref<CSSPrimitiveValue> m_value;
 };
 
 static const CalculationCategory addSubtractResult[CalcAngle][CalcAngle] = {
@@ -610,8 +608,7 @@
         if (!is<CSSPrimitiveValue>(value.get()))
             return false;
 
-        CSSPrimitiveValue& primitiveValue = downcast<CSSPrimitiveValue>(*value);
-        result->value = CSSCalcPrimitiveValue::create(&primitiveValue, parserValue->isInt);
+        result->value = CSSCalcPrimitiveValue::create(Ref<CSSPrimitiveValue>(downcast<CSSPrimitiveValue>(*value)), parserValue->isInt);
 
         ++*index;
         return true;
diff --git a/Source/WebCore/css/CSSMediaRule.cpp b/Source/WebCore/css/CSSMediaRule.cpp
index 68dfa67..fcda496 100644
--- a/Source/WebCore/css/CSSMediaRule.cpp
+++ b/Source/WebCore/css/CSSMediaRule.cpp
@@ -27,6 +27,7 @@
 #include "CSSRuleList.h"
 #include "CSSStyleSheet.h"
 #include "ExceptionCode.h"
+#include "MediaList.h"
 #include "StyleRule.h"
 #include <wtf/text/StringBuilder.h>
 
@@ -65,7 +66,7 @@
 MediaList* CSSMediaRule::media() const
 {
     if (!mediaQueries())
-        return 0;
+        return nullptr;
     if (!m_mediaCSSOMWrapper)
         m_mediaCSSOMWrapper = MediaList::create(mediaQueries(), const_cast<CSSMediaRule*>(this));
     return m_mediaCSSOMWrapper.get();
diff --git a/Source/WebCore/css/CSSMediaRule.h b/Source/WebCore/css/CSSMediaRule.h
index 690858e..7ef948a 100644
--- a/Source/WebCore/css/CSSMediaRule.h
+++ b/Source/WebCore/css/CSSMediaRule.h
@@ -20,14 +20,13 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef CSSMediaRule_h
-#define CSSMediaRule_h
+#pragma once
 
 #include "CSSGroupingRule.h"
-#include "MediaList.h"
 
 namespace WebCore {
 
+class MediaList;
 class StyleRuleMedia;
 
 class CSSMediaRule final : public CSSGroupingRule {
@@ -54,5 +53,3 @@
 } // namespace WebCore
 
 SPECIALIZE_TYPE_TRAITS_CSS_RULE(CSSMediaRule, CSSRule::MEDIA_RULE)
-
-#endif // CSSMediaRule_h
diff --git a/Source/WebCore/css/CSSOMUtils.h b/Source/WebCore/css/CSSOMUtils.h
index 6071537..4bd07cc 100644
--- a/Source/WebCore/css/CSSOMUtils.h
+++ b/Source/WebCore/css/CSSOMUtils.h
@@ -28,12 +28,10 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef CSSOMUtils_h
-#define CSSOMUtils_h
+#pragma once
 
-#include <unicode/utypes.h>
+#include <unicode/umachine.h>
 #include <wtf/Forward.h>
-#include <wtf/Vector.h>
 
 // Utilities for CSSOM http://dev.w3.org/csswg/cssom/
 
@@ -46,5 +44,3 @@
 void serializeString(const String&, StringBuilder&);
 
 } // namespace WebCore
-
-#endif // CSSOMUtils_h
diff --git a/Source/WebCore/css/CSSParser.cpp b/Source/WebCore/css/CSSParser.cpp
index 93190f3..d62ea6f 100644
--- a/Source/WebCore/css/CSSParser.cpp
+++ b/Source/WebCore/css/CSSParser.cpp
@@ -12805,7 +12805,7 @@
         popRuleData();
         return nullptr;
     }
-    auto rule = StyleRuleImport::create(url, media);
+    auto rule = StyleRuleImport::create(url, media.releaseNonNull());
     processAndAddNewRuleToSourceTreeIfNeeded();
     return WTFMove(rule);
 }
@@ -12820,7 +12820,7 @@
         // even when it is syntactically incorrect.
         rule = StyleRuleMedia::create(MediaQuerySet::create(), emptyRules);
     } else
-        rule = StyleRuleMedia::create(media, rules ? *rules : emptyRules);
+        rule = StyleRuleMedia::create(media.releaseNonNull(), rules ? *rules : emptyRules);
     processAndAddNewRuleToSourceTreeIfNeeded();
     return rule.releaseNonNull();
 }
diff --git a/Source/WebCore/css/CSSReflectValue.h b/Source/WebCore/css/CSSReflectValue.h
index 2566eff..feb04c93 100644
--- a/Source/WebCore/css/CSSReflectValue.h
+++ b/Source/WebCore/css/CSSReflectValue.h
@@ -23,12 +23,10 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef CSSReflectValue_h
-#define CSSReflectValue_h
+#pragma once
 
 #include "CSSReflectionDirection.h"
 #include "CSSValue.h"
-#include <wtf/PassRefPtr.h>
 #include <wtf/RefPtr.h>
 
 namespace WebCore {
@@ -71,5 +69,3 @@
 } // namespace WebCore
 
 SPECIALIZE_TYPE_TRAITS_CSS_VALUE(CSSReflectValue, isReflectValue())
-
-#endif // CSSReflectValue_h
diff --git a/Source/WebCore/css/CSSStyleSheet.cpp b/Source/WebCore/css/CSSStyleSheet.cpp
index e8e979f..09c8745 100644
--- a/Source/WebCore/css/CSSStyleSheet.cpp
+++ b/Source/WebCore/css/CSSStyleSheet.cpp
@@ -222,9 +222,9 @@
     didMutate();
 }
 
-void CSSStyleSheet::setMediaQueries(PassRefPtr<MediaQuerySet> mediaQueries)
+void CSSStyleSheet::setMediaQueries(Ref<MediaQuerySet>&& mediaQueries)
 {
-    m_mediaQueries = mediaQueries;
+    m_mediaQueries = WTFMove(mediaQueries);
     if (m_mediaCSSOMWrapper && m_mediaQueries)
         m_mediaCSSOMWrapper->reattach(m_mediaQueries.get());
 
@@ -310,7 +310,7 @@
 
     RuleMutationScope mutationScope(this, RuleInsertion, is<StyleRuleKeyframes>(*rule) ? downcast<StyleRuleKeyframes>(rule.get()) : nullptr);
 
-    bool success = m_contents.get().wrapperInsertRule(rule, index);
+    bool success = m_contents.get().wrapperInsertRule(rule.releaseNonNull(), index);
     if (!success) {
         ec = HIERARCHY_REQUEST_ERR;
         return 0;
@@ -336,7 +336,7 @@
 
     if (!m_childRuleCSSOMWrappers.isEmpty()) {
         if (m_childRuleCSSOMWrappers[index])
-            m_childRuleCSSOMWrappers[index]->setParentStyleSheet(0);
+            m_childRuleCSSOMWrappers[index]->setParentStyleSheet(nullptr);
         m_childRuleCSSOMWrappers.remove(index);
     }
 }
@@ -381,9 +381,9 @@
 }
 
 MediaList* CSSStyleSheet::media() const 
-{ 
+{
     if (!m_mediaQueries)
-        return 0;
+        return nullptr;
 
     if (!m_mediaCSSOMWrapper)
         m_mediaCSSOMWrapper = MediaList::create(m_mediaQueries.get(), const_cast<CSSStyleSheet*>(this));
@@ -392,7 +392,7 @@
 
 CSSStyleSheet* CSSStyleSheet::parentStyleSheet() const 
 { 
-    return m_ownerRule ? m_ownerRule->parentStyleSheet() : 0; 
+    return m_ownerRule ? m_ownerRule->parentStyleSheet() : nullptr;
 }
 
 Document* CSSStyleSheet::ownerDocument() const
@@ -400,7 +400,7 @@
     const CSSStyleSheet* root = this;
     while (root->parentStyleSheet())
         root = root->parentStyleSheet();
-    return root->ownerNode() ? &root->ownerNode()->document() : 0;
+    return root->ownerNode() ? &root->ownerNode()->document() : nullptr;
 }
 
 void CSSStyleSheet::clearChildRuleCSSOMWrappers()
@@ -418,7 +418,7 @@
 }
 
 CSSStyleSheet::RuleMutationScope::RuleMutationScope(CSSRule* rule)
-    : m_styleSheet(rule ? rule->parentStyleSheet() : 0)
+    : m_styleSheet(rule ? rule->parentStyleSheet() : nullptr)
     , m_mutationType(OtherMutation)
     , m_contentsWereClonedForMutation(ContentsWereNotClonedForMutation)
     , m_insertedKeyframesRule(nullptr)
diff --git a/Source/WebCore/css/CSSStyleSheet.h b/Source/WebCore/css/CSSStyleSheet.h
index 3c4cdc3..c0e67e1 100644
--- a/Source/WebCore/css/CSSStyleSheet.h
+++ b/Source/WebCore/css/CSSStyleSheet.h
@@ -22,7 +22,6 @@
 #define CSSStyleSheet_h
 
 #include "CSSParserMode.h"
-#include "CSSRule.h"
 #include "StyleSheet.h"
 #include <memory>
 #include <wtf/HashMap.h>
@@ -85,7 +84,7 @@
     void clearOwnerRule() { m_ownerRule = 0; }
     Document* ownerDocument() const;
     MediaQuerySet* mediaQueries() const { return m_mediaQueries.get(); }
-    void setMediaQueries(PassRefPtr<MediaQuerySet>);
+    void setMediaQueries(Ref<MediaQuerySet>&&);
     void setTitle(const String& title) { m_title = title; }
 
     bool hadRulesMutation() const { return m_mutatedRules; }
diff --git a/Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp b/Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp
index b21db42..5666530 100644
--- a/Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp
+++ b/Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp
@@ -24,6 +24,7 @@
 
 #include "CSSCustomPropertyValue.h"
 #include "CSSParser.h"
+#include "CSSRule.h"
 #include "CSSStyleSheet.h"
 #include "HTMLNames.h"
 #include "InspectorInstrumentation.h"
diff --git a/Source/WebCore/css/StyleRule.cpp b/Source/WebCore/css/StyleRule.cpp
index b30f725..9c5d441 100644
--- a/Source/WebCore/css/StyleRule.cpp
+++ b/Source/WebCore/css/StyleRule.cpp
@@ -32,6 +32,7 @@
 #include "CSSStyleRule.h"
 #include "CSSSupportsRule.h"
 #include "CSSUnknownRule.h"
+#include "MediaList.h"
 #include "StyleProperties.h"
 #include "StyleRuleImport.h"
 #include "WebKitCSSRegionRule.h"
@@ -45,14 +46,14 @@
 
 COMPILE_ASSERT(sizeof(StyleRuleBase) == sizeof(SameSizeAsStyleRuleBase), StyleRuleBase_should_stay_small);
 
-PassRefPtr<CSSRule> StyleRuleBase::createCSSOMWrapper(CSSStyleSheet* parentSheet) const
+RefPtr<CSSRule> StyleRuleBase::createCSSOMWrapper(CSSStyleSheet* parentSheet) const
 {
-    return createCSSOMWrapper(parentSheet, 0);
+    return createCSSOMWrapper(parentSheet, nullptr);
 }
 
-PassRefPtr<CSSRule> StyleRuleBase::createCSSOMWrapper(CSSRule* parentRule) const
+RefPtr<CSSRule> StyleRuleBase::createCSSOMWrapper(CSSRule* parentRule) const
 { 
-    return createCSSOMWrapper(0, parentRule);
+    return createCSSOMWrapper(nullptr, parentRule);
 }
 
 void StyleRuleBase::destroy()
@@ -329,9 +330,9 @@
 }
 
 
-StyleRuleMedia::StyleRuleMedia(PassRefPtr<MediaQuerySet> media, Vector<RefPtr<StyleRuleBase>>& adoptRules)
+StyleRuleMedia::StyleRuleMedia(Ref<MediaQuerySet>&& media, Vector<RefPtr<StyleRuleBase>>& adoptRules)
     : StyleRuleGroup(Media, adoptRules)
-    , m_mediaQueries(media)
+    , m_mediaQueries(WTFMove(media))
 {
 }
 
diff --git a/Source/WebCore/css/StyleRule.h b/Source/WebCore/css/StyleRule.h
index f565136..0145218 100644
--- a/Source/WebCore/css/StyleRule.h
+++ b/Source/WebCore/css/StyleRule.h
@@ -19,11 +19,9 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#ifndef StyleRule_h
-#define StyleRule_h
+#pragma once
 
 #include "CSSSelectorList.h"
-#include "MediaList.h"
 #include "StyleProperties.h"
 #include <wtf/RefPtr.h>
 #include <wtf/TypeCasts.h>
@@ -33,6 +31,7 @@
 class CSSRule;
 class CSSStyleRule;
 class CSSStyleSheet;
+class MediaQuerySet;
 class MutableStyleProperties;
 class StyleProperties;
 
@@ -82,8 +81,8 @@
     }
 
     // FIXME: There shouldn't be any need for the null parent version.
-    PassRefPtr<CSSRule> createCSSOMWrapper(CSSStyleSheet* parentSheet = 0) const;
-    PassRefPtr<CSSRule> createCSSOMWrapper(CSSRule* parentRule) const;
+    RefPtr<CSSRule> createCSSOMWrapper(CSSStyleSheet* parentSheet = nullptr) const;
+    RefPtr<CSSRule> createCSSOMWrapper(CSSRule* parentRule) const;
 
 protected:
     StyleRuleBase(Type type, signed sourceLine = 0) : m_type(type), m_sourceLine(sourceLine) { }
@@ -193,9 +192,9 @@
 
 class StyleRuleMedia : public StyleRuleGroup {
 public:
-    static Ref<StyleRuleMedia> create(PassRefPtr<MediaQuerySet> media, Vector<RefPtr<StyleRuleBase>>& adoptRules)
+    static Ref<StyleRuleMedia> create(Ref<MediaQuerySet>&& media, Vector<RefPtr<StyleRuleBase>>& adoptRules)
     {
-        return adoptRef(*new StyleRuleMedia(media, adoptRules));
+        return adoptRef(*new StyleRuleMedia(WTFMove(media), adoptRules));
     }
 
     MediaQuerySet* mediaQueries() const { return m_mediaQueries.get(); }
@@ -203,7 +202,7 @@
     Ref<StyleRuleMedia> copy() const { return adoptRef(*new StyleRuleMedia(*this)); }
 
 private:
-    StyleRuleMedia(PassRefPtr<MediaQuerySet>, Vector<RefPtr<StyleRuleBase>>& adoptRules);
+    StyleRuleMedia(Ref<MediaQuerySet>&&, Vector<RefPtr<StyleRuleBase>>& adoptRules);
     StyleRuleMedia(const StyleRuleMedia&);
 
     RefPtr<MediaQuerySet> m_mediaQueries;
@@ -297,5 +296,3 @@
     static bool isType(const WebCore::StyleRuleBase& rule) { return rule.isViewportRule(); }
 SPECIALIZE_TYPE_TRAITS_END()
 #endif // ENABLE(CSS_DEVICE_ADAPTATION)
-
-#endif // StyleRule_h
diff --git a/Source/WebCore/css/StyleRuleImport.cpp b/Source/WebCore/css/StyleRuleImport.cpp
index f567956..2ce23f2 100644
--- a/Source/WebCore/css/StyleRuleImport.cpp
+++ b/Source/WebCore/css/StyleRuleImport.cpp
@@ -28,23 +28,24 @@
 #include "CachedResourceRequest.h"
 #include "CachedResourceRequestInitiators.h"
 #include "Document.h"
+#include "MediaList.h"
 #include "SecurityOrigin.h"
 #include "StyleSheetContents.h"
 #include <wtf/StdLibExtras.h>
 
 namespace WebCore {
 
-Ref<StyleRuleImport> StyleRuleImport::create(const String& href, PassRefPtr<MediaQuerySet> media)
+Ref<StyleRuleImport> StyleRuleImport::create(const String& href, Ref<MediaQuerySet>&& media)
 {
-    return adoptRef(*new StyleRuleImport(href, media));
+    return adoptRef(*new StyleRuleImport(href, WTFMove(media)));
 }
 
-StyleRuleImport::StyleRuleImport(const String& href, PassRefPtr<MediaQuerySet> media)
+StyleRuleImport::StyleRuleImport(const String& href, Ref<MediaQuerySet>&& media)
     : StyleRuleBase(Import, 0)
     , m_parentStyleSheet(0)
     , m_styleSheetClient(this)
     , m_strHref(href)
-    , m_mediaQueries(media)
+    , m_mediaQueries(WTFMove(media))
     , m_cachedSheet(0)
     , m_loading(false)
 {
diff --git a/Source/WebCore/css/StyleRuleImport.h b/Source/WebCore/css/StyleRuleImport.h
index ba0b2a7..3babb98 100644
--- a/Source/WebCore/css/StyleRuleImport.h
+++ b/Source/WebCore/css/StyleRuleImport.h
@@ -36,7 +36,7 @@
 class StyleRuleImport : public StyleRuleBase {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    static Ref<StyleRuleImport> create(const String& href, PassRefPtr<MediaQuerySet>);
+    static Ref<StyleRuleImport> create(const String& href, Ref<MediaQuerySet>&&);
 
     ~StyleRuleImport();
     
@@ -70,7 +70,7 @@
     void setCSSStyleSheet(const String& href, const URL& baseURL, const String& charset, const CachedCSSStyleSheet*);
     friend class ImportedStyleSheetClient;
 
-    StyleRuleImport(const String& href, PassRefPtr<MediaQuerySet>);
+    StyleRuleImport(const String& href, Ref<MediaQuerySet>&&);
 
     StyleSheetContents* m_parentStyleSheet;
 
diff --git a/Source/WebCore/css/StyleSheetContents.cpp b/Source/WebCore/css/StyleSheetContents.cpp
index ff63736..fd88b62 100644
--- a/Source/WebCore/css/StyleSheetContents.cpp
+++ b/Source/WebCore/css/StyleSheetContents.cpp
@@ -129,13 +129,13 @@
     return true;
 }
 
-void StyleSheetContents::parserAppendRule(PassRefPtr<StyleRuleBase> rule)
+void StyleSheetContents::parserAppendRule(Ref<StyleRuleBase>&& rule)
 {
     ASSERT(!rule->isCharsetRule());
-    if (is<StyleRuleImport>(*rule)) {
+    if (is<StyleRuleImport>(rule)) {
         // Parser enforces that @import rules come before anything else except @charset.
         ASSERT(m_childRules.isEmpty());
-        m_importRules.append(downcast<StyleRuleImport>(rule.get()));
+        m_importRules.append(downcast<StyleRuleImport>(rule.ptr()));
         m_importRules.last()->setParentStyleSheet(this);
         m_importRules.last()->requestStyleSheet();
         return;
@@ -143,19 +143,19 @@
 
 #if ENABLE(RESOLUTION_MEDIA_QUERY)
     // Add warning message to inspector if dpi/dpcm values are used for screen media.
-    if (is<StyleRuleMedia>(*rule))
-        reportMediaQueryWarningIfNeeded(singleOwnerDocument(), downcast<StyleRuleMedia>(*rule).mediaQueries());
+    if (is<StyleRuleMedia>(rule))
+        reportMediaQueryWarningIfNeeded(singleOwnerDocument(), downcast<StyleRuleMedia>(rule.get()).mediaQueries());
 #endif
 
     // NOTE: The selector list has to fit into RuleData. <http://webkit.org/b/118369>
     // If we're adding a rule with a huge number of selectors, split it up into multiple rules
-    if (is<StyleRule>(*rule) && downcast<StyleRule>(*rule).selectorList().componentCount() > RuleData::maximumSelectorComponentCount) {
-        Vector<RefPtr<StyleRule>> rules = downcast<StyleRule>(*rule).splitIntoMultipleRulesWithMaximumSelectorComponentCount(RuleData::maximumSelectorComponentCount);
+    if (is<StyleRule>(rule) && downcast<StyleRule>(rule.get()).selectorList().componentCount() > RuleData::maximumSelectorComponentCount) {
+        Vector<RefPtr<StyleRule>> rules = downcast<StyleRule>(rule.get()).splitIntoMultipleRulesWithMaximumSelectorComponentCount(RuleData::maximumSelectorComponentCount);
         m_childRules.appendVector(rules);
         return;
     }
 
-    m_childRules.append(rule);
+    m_childRules.append(WTFMove(rule));
 }
 
 StyleRuleBase* StyleSheetContents::ruleAt(unsigned index) const
@@ -207,7 +207,7 @@
     m_encodingFromCharsetRule = encoding; 
 }
 
-bool StyleSheetContents::wrapperInsertRule(PassRefPtr<StyleRuleBase> rule, unsigned index)
+bool StyleSheetContents::wrapperInsertRule(Ref<StyleRuleBase>&& rule, unsigned index)
 {
     ASSERT(m_isMutable);
     ASSERT_WITH_SECURITY_IMPLICATION(index <= ruleCount());
@@ -226,24 +226,24 @@
     
     if (childVectorIndex < m_importRules.size() || (childVectorIndex == m_importRules.size() && rule->isImportRule())) {
         // Inserting non-import rule before @import is not allowed.
-        if (!is<StyleRuleImport>(*rule))
+        if (!is<StyleRuleImport>(rule))
             return false;
-        m_importRules.insert(childVectorIndex, downcast<StyleRuleImport>(rule.get()));
+        m_importRules.insert(childVectorIndex, downcast<StyleRuleImport>(rule.ptr()));
         m_importRules[childVectorIndex]->setParentStyleSheet(this);
         m_importRules[childVectorIndex]->requestStyleSheet();
         // FIXME: Stylesheet doesn't actually change meaningfully before the imported sheets are loaded.
         return true;
     }
     // Inserting @import rule after a non-import rule is not allowed.
-    if (is<StyleRuleImport>(*rule))
+    if (is<StyleRuleImport>(rule))
         return false;
     childVectorIndex -= m_importRules.size();
 
     // If the number of selectors would overflow RuleData, we drop the operation.
-    if (is<StyleRule>(*rule) && downcast<StyleRule>(*rule).selectorList().componentCount() > RuleData::maximumSelectorComponentCount)
+    if (is<StyleRule>(rule) && downcast<StyleRule>(rule.get()).selectorList().componentCount() > RuleData::maximumSelectorComponentCount)
         return false;
 
-    m_childRules.insert(childVectorIndex, rule);
+    m_childRules.insert(childVectorIndex, WTFMove(rule));
     return true;
 }
 
diff --git a/Source/WebCore/css/StyleSheetContents.h b/Source/WebCore/css/StyleSheetContents.h
index f256621..da3f915 100644
--- a/Source/WebCore/css/StyleSheetContents.h
+++ b/Source/WebCore/css/StyleSheetContents.h
@@ -94,7 +94,7 @@
     bool hasSyntacticallyValidCSSHeader() const { return m_hasSyntacticallyValidCSSHeader; }
 
     void parserAddNamespace(const AtomicString& prefix, const AtomicString& uri);
-    void parserAppendRule(PassRefPtr<StyleRuleBase>);
+    void parserAppendRule(Ref<StyleRuleBase>&&);
     void parserSetEncodingFromCharsetRule(const String& encoding); 
     void parserSetUsesRemUnits() { m_usesRemUnits = true; }
     void parserSetUsesStyleBasedEditability() { m_usesStyleBasedEditability = true; }
@@ -127,7 +127,7 @@
 
     unsigned estimatedSizeInBytes() const;
     
-    bool wrapperInsertRule(PassRefPtr<StyleRuleBase>, unsigned index);
+    bool wrapperInsertRule(Ref<StyleRuleBase>&&, unsigned index);
     void wrapperDeleteRule(unsigned index);
 
     Ref<StyleSheetContents> copy() const { return adoptRef(*new StyleSheetContents(*this)); }