Merge from Chromium at DEPS revision r213780

This commit was generated by merge_to_master.py.

Change-Id: I702915ad75bd2cc5201b0239db771978b0a8137d
diff --git a/Source/core/dom/ActiveDOMObject.cpp b/Source/core/dom/ActiveDOMObject.cpp
index 15c43f3..de838fe 100644
--- a/Source/core/dom/ActiveDOMObject.cpp
+++ b/Source/core/dom/ActiveDOMObject.cpp
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  */
 
diff --git a/Source/core/dom/ActiveDOMObject.h b/Source/core/dom/ActiveDOMObject.h
index 23244ef..0e123c7 100644
--- a/Source/core/dom/ActiveDOMObject.h
+++ b/Source/core/dom/ActiveDOMObject.h
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  */
 
diff --git a/Source/core/dom/AutocompleteErrorEvent.h b/Source/core/dom/AutocompleteErrorEvent.h
index 1f35fe3..2f36cc7 100644
--- a/Source/core/dom/AutocompleteErrorEvent.h
+++ b/Source/core/dom/AutocompleteErrorEvent.h
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2013 Google Inc. All rights reserved.
- * 
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -9,7 +9,7 @@
  * 2.  Redistributions in binary form must reproduce the above copyright
  *     notice, this list of conditions and the following disclaimer in the
  *     documentation and/or other materials provided with the distribution.
- * 
+ *
  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
diff --git a/Source/core/dom/AutocompleteErrorEvent.idl b/Source/core/dom/AutocompleteErrorEvent.idl
index 807ef04..5f9b700 100644
--- a/Source/core/dom/AutocompleteErrorEvent.idl
+++ b/Source/core/dom/AutocompleteErrorEvent.idl
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2013 Google Inc. All rights reserved.
- * 
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -9,7 +9,7 @@
  * 2.  Redistributions in binary form must reproduce the above copyright
  *     notice, this list of conditions and the following disclaimer in the
  *     documentation and/or other materials provided with the distribution.
- * 
+ *
  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
diff --git a/Source/core/dom/BeforeLoadEvent.h b/Source/core/dom/BeforeLoadEvent.h
index 946693b..1e6d5fc 100644
--- a/Source/core/dom/BeforeLoadEvent.h
+++ b/Source/core/dom/BeforeLoadEvent.h
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  */
 
diff --git a/Source/core/dom/BeforeLoadEvent.idl b/Source/core/dom/BeforeLoadEvent.idl
index 54b8501..428a513 100644
--- a/Source/core/dom/BeforeLoadEvent.idl
+++ b/Source/core/dom/BeforeLoadEvent.idl
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  */
 
diff --git a/Source/core/dom/BeforeTextInsertedEvent.cpp b/Source/core/dom/BeforeTextInsertedEvent.cpp
index 213737c..72e4780 100644
--- a/Source/core/dom/BeforeTextInsertedEvent.cpp
+++ b/Source/core/dom/BeforeTextInsertedEvent.cpp
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #include "config.h"
diff --git a/Source/core/dom/BeforeTextInsertedEvent.h b/Source/core/dom/BeforeTextInsertedEvent.h
index 207daf6..a08e2de 100644
--- a/Source/core/dom/BeforeTextInsertedEvent.h
+++ b/Source/core/dom/BeforeTextInsertedEvent.h
@@ -20,9 +20,9 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
- 
+
 #ifndef BeforeTextInsertedEvent_h
 #define BeforeTextInsertedEvent_h
 
diff --git a/Source/core/dom/CharacterData.idl b/Source/core/dom/CharacterData.idl
index 2e3262c..eb6bfe7 100644
--- a/Source/core/dom/CharacterData.idl
+++ b/Source/core/dom/CharacterData.idl
@@ -22,18 +22,18 @@
     [TreatNullAs=NullString] attribute DOMString data;
 
     readonly attribute unsigned long length;
-    
+
     [TreatReturnedNullStringAs=Null, RaisesException] DOMString substringData([IsIndex,Default=Undefined] optional unsigned long offset, [IsIndex,Default=Undefined] optional unsigned long length);
 
     void appendData([Default=Undefined] optional DOMString data);
 
-     [RaisesException] void insertData([IsIndex,Default=Undefined] optional unsigned long offset, 
+     [RaisesException] void insertData([IsIndex,Default=Undefined] optional unsigned long offset,
                                    [Default=Undefined] optional DOMString data);
 
-     [RaisesException] void deleteData([IsIndex,Default=Undefined] optional unsigned long offset, 
+     [RaisesException] void deleteData([IsIndex,Default=Undefined] optional unsigned long offset,
                                    [IsIndex,Default=Undefined] optional unsigned long length);
 
-     [RaisesException] void replaceData([IsIndex,Default=Undefined] optional unsigned long offset, 
+     [RaisesException] void replaceData([IsIndex,Default=Undefined] optional unsigned long offset,
                                     [IsIndex,Default=Undefined] optional unsigned long length,
                                     [Default=Undefined] optional DOMString data);
 };
diff --git a/Source/core/dom/ChildNode.idl b/Source/core/dom/ChildNode.idl
index 80ba9f1..d320e11 100644
--- a/Source/core/dom/ChildNode.idl
+++ b/Source/core/dom/ChildNode.idl
@@ -2,7 +2,7 @@
  * Copyright (C) 2006, 2007, 2009 Apple Inc. All rights reserved.
  * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
  * Copyright (C) 2013 Samsung Electronics. 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
diff --git a/Source/core/dom/ClassNodeList.cpp b/Source/core/dom/ClassNodeList.cpp
index 7ab3202..f70f671 100644
--- a/Source/core/dom/ClassNodeList.cpp
+++ b/Source/core/dom/ClassNodeList.cpp
@@ -45,7 +45,7 @@
 ClassNodeList::~ClassNodeList()
 {
     ownerNode()->nodeLists()->removeCacheWithName(this, ClassNodeListType, m_originalClassNames);
-} 
+}
 
 bool ClassNodeList::nodeMatches(Element* testNode) const
 {
diff --git a/Source/core/dom/ClientRect.cpp b/Source/core/dom/ClientRect.cpp
index bff5d80..bc5f971 100644
--- a/Source/core/dom/ClientRect.cpp
+++ b/Source/core/dom/ClientRect.cpp
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  */
 
diff --git a/Source/core/dom/ClientRect.h b/Source/core/dom/ClientRect.h
index 9177a3f..6476e0f 100644
--- a/Source/core/dom/ClientRect.h
+++ b/Source/core/dom/ClientRect.h
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  */
 
@@ -34,7 +34,7 @@
 
 namespace WebCore {
 
-    class IntRect; 
+    class IntRect;
 
     class ClientRect : public ScriptWrappable, public RefCounted<ClientRect> {
     public:
@@ -55,7 +55,7 @@
         explicit ClientRect(const FloatRect&);
 
         FloatRect m_rect;
-    }; 
+    };
 
 } // namespace WebCore
 
diff --git a/Source/core/dom/ClientRect.idl b/Source/core/dom/ClientRect.idl
index 2d96ed0..ffdcfdd 100644
--- a/Source/core/dom/ClientRect.idl
+++ b/Source/core/dom/ClientRect.idl
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  */
 
diff --git a/Source/core/dom/ClientRectList.cpp b/Source/core/dom/ClientRectList.cpp
index d87b696..c7d054c 100644
--- a/Source/core/dom/ClientRectList.cpp
+++ b/Source/core/dom/ClientRectList.cpp
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  */
 
diff --git a/Source/core/dom/ClientRectList.h b/Source/core/dom/ClientRectList.h
index 33f54c7..bf36ef9 100644
--- a/Source/core/dom/ClientRectList.h
+++ b/Source/core/dom/ClientRectList.h
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  */
 
diff --git a/Source/core/dom/ClientRectList.idl b/Source/core/dom/ClientRectList.idl
index 2d35d67..7635d1e 100644
--- a/Source/core/dom/ClientRectList.idl
+++ b/Source/core/dom/ClientRectList.idl
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  */
 
diff --git a/Source/core/dom/ClipboardAccessPolicy.h b/Source/core/dom/ClipboardAccessPolicy.h
index 7a54009..969b3f6 100644
--- a/Source/core/dom/ClipboardAccessPolicy.h
+++ b/Source/core/dom/ClipboardAccessPolicy.h
@@ -20,9 +20,9 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
- 
+
 #ifndef ClipboardAccessPolicy_h
 #define ClipboardAccessPolicy_h
 
diff --git a/Source/core/dom/CompositionEvent.cpp b/Source/core/dom/CompositionEvent.cpp
index caad777..45c61c0 100644
--- a/Source/core/dom/CompositionEvent.cpp
+++ b/Source/core/dom/CompositionEvent.cpp
@@ -9,7 +9,7 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 
+ *
  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  */
 
diff --git a/Source/core/dom/CompositionEvent.h b/Source/core/dom/CompositionEvent.h
index 167b6d1..cf39f9b 100644
--- a/Source/core/dom/CompositionEvent.h
+++ b/Source/core/dom/CompositionEvent.h
@@ -9,7 +9,7 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 
+ *
  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  */
 
diff --git a/Source/core/dom/CompositionEvent.idl b/Source/core/dom/CompositionEvent.idl
index 4f1a5b0..c54d50f 100644
--- a/Source/core/dom/CompositionEvent.idl
+++ b/Source/core/dom/CompositionEvent.idl
@@ -9,7 +9,7 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 
+ *
  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 [
@@ -29,10 +29,10 @@
 
     [InitializedByEventConstructor] readonly attribute DOMString data;
 
-    void initCompositionEvent([Default=Undefined] optional DOMString typeArg, 
-                              [Default=Undefined] optional boolean canBubbleArg, 
-                              [Default=Undefined] optional boolean cancelableArg, 
-                              [Default=Undefined] optional Window viewArg, 
+    void initCompositionEvent([Default=Undefined] optional DOMString typeArg,
+                              [Default=Undefined] optional boolean canBubbleArg,
+                              [Default=Undefined] optional boolean cancelableArg,
+                              [Default=Undefined] optional Window viewArg,
                               [Default=Undefined] optional DOMString dataArg);
 
 };
diff --git a/Source/core/dom/CrossThreadTask.h b/Source/core/dom/CrossThreadTask.h
index 3418b31..7a8761c 100644
--- a/Source/core/dom/CrossThreadTask.h
+++ b/Source/core/dom/CrossThreadTask.h
@@ -336,12 +336,12 @@
     typedef typename CrossThreadTaskTraits<P6>::ParamType Param6;
     typedef typename CrossThreadTaskTraits<P7>::ParamType Param7;
     typedef typename CrossThreadTaskTraits<P8>::ParamType Param8;
-    
+
     static PassOwnPtr<CrossThreadTask> create(Method method, Param1 parameter1, Param2 parameter2, Param3 parameter3, Param4 parameter4, Param5 parameter5, Param6 parameter6, Param7 parameter7, Param8 parameter8)
     {
         return adoptPtr(new CrossThreadTask(method, parameter1, parameter2, parameter3, parameter4, parameter5, parameter6, parameter7, parameter8));
     }
-    
+
 private:
     CrossThreadTask8(Method method, Param1 parameter1, Param2 parameter2, Param3 parameter3, Param4 parameter4, Param5 parameter5, Param6 parameter6, Param7 parameter7, Param8 parameter8)
     : m_method(method)
@@ -355,12 +355,12 @@
     , m_parameter8(parameter8)
     {
     }
-    
+
     virtual void performTask(ScriptExecutionContext* context)
     {
         (*m_method)(context, m_parameter1, m_parameter2, m_parameter3, m_parameter4, m_parameter5, m_parameter6, m_parameter7, m_parameter8);
     }
-    
+
 private:
     Method m_method;
     P1 m_parameter1;
diff --git a/Source/core/dom/CustomElement.cpp b/Source/core/dom/CustomElement.cpp
index de0b688..c5007ff 100644
--- a/Source/core/dom/CustomElement.cpp
+++ b/Source/core/dom/CustomElement.cpp
@@ -32,7 +32,7 @@
 #include "core/dom/CustomElement.h"
 
 #include "core/dom/CustomElementCallbackScheduler.h"
-#include "core/dom/CustomElementRegistrationContext.h"
+#include "core/dom/CustomElementUpgradeCandidateMap.h"
 #include "core/dom/Element.h"
 
 namespace WebCore {
@@ -45,6 +45,11 @@
     CustomElementCallbackScheduler::scheduleCreatedCallback(definition->callbacks(), element);
 }
 
+CustomElementDefinition* CustomElement::definitionFor(Element* element)
+{
+    return definitions().get(element);
+}
+
 void CustomElement::attributeDidChange(Element* element, const AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue)
 {
     ASSERT(element->customElementState() == Element::Upgraded);
@@ -65,13 +70,20 @@
 
 void CustomElement::wasDestroyed(Element* element)
 {
-    definitions().remove(element);
+    switch (element->customElementState()) {
+    case Element::NotCustomElement:
+        ASSERT_NOT_REACHED();
+        break;
 
-    // FIXME: Elements should only depend on their document's
-    // registration context at creation; maintain a mapping to
-    // registration context for upgrade candidates.
-    if (element->document() && element->document()->registrationContext())
-        element->document()->registrationContext()->customElementWasDestroyed(element);
+    case Element::UpgradeCandidate:
+        CustomElementUpgradeCandidateMap::elementWasDestroyed(element);
+        break;
+
+    case Element::Defined:
+    case Element::Upgraded:
+        definitions().remove(element);
+        break;
+    }
 }
 
 void CustomElement::DefinitionMap::add(Element* element, PassRefPtr<CustomElementDefinition> definition)
@@ -95,8 +107,8 @@
 
 CustomElement::DefinitionMap& CustomElement::definitions()
 {
-    DEFINE_STATIC_LOCAL(DefinitionMap, definitionMap, ());
-    return definitionMap;
+    DEFINE_STATIC_LOCAL(DefinitionMap, map, ());
+    return map;
 }
 
 } // namespace WebCore
diff --git a/Source/core/dom/CustomElement.h b/Source/core/dom/CustomElement.h
index 21bc28c..6cd2661 100644
--- a/Source/core/dom/CustomElement.h
+++ b/Source/core/dom/CustomElement.h
@@ -44,7 +44,14 @@
 
 class CustomElement {
 public:
+    // API for registration contexts
     static void define(Element*, PassRefPtr<CustomElementDefinition>);
+
+    // API for wrapper creation, which uses a definition as a key
+    static CustomElementDefinition* definitionFor(Element*);
+
+    // API for Element to kick off changes
+
     static void attributeDidChange(Element*, const AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue);
     static void didEnterDocument(Element*);
     static void didLeaveDocument(Element*);
@@ -53,6 +60,8 @@
 private:
     CustomElement();
 
+    // Maps resolved elements to their definitions
+
     class DefinitionMap {
         WTF_MAKE_NONCOPYABLE(DefinitionMap);
     public:
@@ -67,7 +76,6 @@
         typedef HashMap<Element*, RefPtr<CustomElementDefinition> > ElementDefinitionHashMap;
         ElementDefinitionHashMap m_definitions;
     };
-
     static DefinitionMap& definitions();
 };
 
diff --git a/Source/core/dom/CustomElementRegistrationContext.cpp b/Source/core/dom/CustomElementRegistrationContext.cpp
index c3a0cad..4e8129d 100644
--- a/Source/core/dom/CustomElementRegistrationContext.cpp
+++ b/Source/core/dom/CustomElementRegistrationContext.cpp
@@ -36,76 +36,15 @@
 #include "SVGNames.h"
 #include "core/dom/CustomElement.h"
 #include "core/dom/CustomElementDefinition.h"
-#include "core/dom/CustomElementRegistry.h"
-#include "core/dom/CustomElementUpgradeCandidateMap.h"
 #include "core/dom/Element.h"
 #include "core/html/HTMLElement.h"
 #include "core/html/HTMLUnknownElement.h"
 #include "core/svg/SVGElement.h"
+#include "wtf/RefPtr.h"
 
 namespace WebCore {
 
-// The null registration context is used by documents that do not
-// process custom elements. All of its operations are no-ops.
-class NullRegistrationContext : public CustomElementRegistrationContext {
-public:
-    NullRegistrationContext() { }
-    virtual ~NullRegistrationContext() { }
-
-    virtual void registerElement(Document*, CustomElementConstructorBuilder*, const AtomicString&, ExceptionCode& ec) OVERRIDE { ec = NotSupportedError; }
-
-    virtual PassRefPtr<Element> createCustomTagElement(Document*, const QualifiedName&) OVERRIDE;
-    virtual void didGiveTypeExtension(Element*) OVERRIDE { }
-};
-
-PassRefPtr<Element> NullRegistrationContext::createCustomTagElement(Document* document, const QualifiedName& tagName)
-{
-    ASSERT(isCustomTagName(tagName.localName()));
-
-    if (!document)
-        return 0;
-
-    if (HTMLNames::xhtmlNamespaceURI == tagName.namespaceURI())
-        return HTMLUnknownElement::create(tagName, document);
-    if (SVGNames::svgNamespaceURI == tagName.namespaceURI())
-        return SVGElement::create(tagName, document);
-    return Element::create(tagName, document);
-}
-
-PassRefPtr<CustomElementRegistrationContext> CustomElementRegistrationContext::nullRegistrationContext()
-{
-    DEFINE_STATIC_LOCAL(RefPtr<NullRegistrationContext>, instance, ());
-    if (!instance)
-        instance = adoptRef(new NullRegistrationContext());
-    return instance.get();
-}
-
-// An active registration context is used by documents that are
-// processing custom elements.
-class ActiveRegistrationContext : public CustomElementRegistrationContext {
-public:
-    ActiveRegistrationContext() { }
-    virtual ~ActiveRegistrationContext() { }
-
-    virtual void registerElement(Document*, CustomElementConstructorBuilder*, const AtomicString& type, ExceptionCode&) OVERRIDE;
-
-    virtual PassRefPtr<Element> createCustomTagElement(Document*, const QualifiedName&) OVERRIDE;
-    virtual void didGiveTypeExtension(Element*) OVERRIDE;
-
-    virtual void customElementWasDestroyed(Element*) OVERRIDE;
-
-private:
-    void resolve(Element*);
-    void didResolveElement(CustomElementDefinition*, Element*);
-    void didCreateUnresolvedElement(const CustomElementDescriptor&, Element*);
-
-    CustomElementRegistry m_registry;
-
-    // Element creation
-    CustomElementUpgradeCandidateMap m_candidates;
-};
-
-void ActiveRegistrationContext::registerElement(Document* document, CustomElementConstructorBuilder* constructorBuilder, const AtomicString& type, ExceptionCode& ec)
+void CustomElementRegistrationContext::registerElement(Document* document, CustomElementConstructorBuilder* constructorBuilder, const AtomicString& type, ExceptionCode& ec)
 {
     CustomElementDefinition* definition = m_registry.registerElement(document, constructorBuilder, type, ec);
 
@@ -118,7 +57,7 @@
         didResolveElement(definition, *it);
 }
 
-PassRefPtr<Element> ActiveRegistrationContext::createCustomTagElement(Document* document, const QualifiedName& tagName)
+PassRefPtr<Element> CustomElementRegistrationContext::createCustomTagElement(Document* document, const QualifiedName& tagName)
 {
     ASSERT(isCustomTagName(tagName.localName()));
 
@@ -136,18 +75,25 @@
         return Element::create(tagName, document);
     }
 
-    resolve(element.get());
+    resolve(element.get(), nullAtom);
     return element.release();
 }
 
-void ActiveRegistrationContext::didGiveTypeExtension(Element* element)
+void CustomElementRegistrationContext::didGiveTypeExtension(Element* element, const AtomicString& type)
 {
-    resolve(element);
+    resolve(element, type);
 }
 
-void ActiveRegistrationContext::resolve(Element* element)
+void CustomElementRegistrationContext::resolve(Element* element, const AtomicString& typeExtension)
 {
-    const CustomElementDescriptor& descriptor = describe(element);
+    // If an element has a custom tag name it takes precedence over
+    // the "is" attribute (if any).
+    const AtomicString& type = isCustomTagName(element->localName())
+        ? element->localName()
+        : typeExtension;
+    ASSERT(!type.isNull());
+
+    CustomElementDescriptor descriptor(type, element->namespaceURI(), element->localName());
     CustomElementDefinition* definition = m_registry.find(descriptor);
     if (definition)
         didResolveElement(definition, element);
@@ -155,26 +101,24 @@
         didCreateUnresolvedElement(descriptor, element);
 }
 
-void ActiveRegistrationContext::didResolveElement(CustomElementDefinition* definition, Element* element)
+void CustomElementRegistrationContext::didResolveElement(CustomElementDefinition* definition, Element* element)
 {
     CustomElement::define(element, definition);
 }
 
-void ActiveRegistrationContext::didCreateUnresolvedElement(const CustomElementDescriptor& descriptor, Element* element)
+void CustomElementRegistrationContext::didCreateUnresolvedElement(const CustomElementDescriptor& descriptor, Element* element)
 {
-    element->setCustomElementState(Element::UpgradeCandidate);
     m_candidates.add(descriptor, element);
 }
 
-void ActiveRegistrationContext::customElementWasDestroyed(Element* element)
+void CustomElementRegistrationContext::customElementWasDestroyed(Element* element)
 {
     m_candidates.remove(element);
-    CustomElementRegistrationContext::customElementWasDestroyed(element);
 }
 
 PassRefPtr<CustomElementRegistrationContext> CustomElementRegistrationContext::create()
 {
-    return adoptRef(new ActiveRegistrationContext());
+    return adoptRef(new CustomElementRegistrationContext());
 }
 
 bool CustomElementRegistrationContext::isValidTypeName(const AtomicString& name)
@@ -205,17 +149,6 @@
     return isValidTypeName(localName);
 }
 
-CustomElementDescriptor CustomElementRegistrationContext::describe(Element* element)
-{
-    // If an element has a custom tag name it takes precedence over
-    // the "is" attribute (if any).
-    const AtomicString& type = isCustomTagName(element->localName())
-        ? element->localName()
-        : typeExtension(element);
-
-    return CustomElementDescriptor(type, element->namespaceURI(), element->localName());
-}
-
 void CustomElementRegistrationContext::setIsAttributeAndTypeExtension(Element* element, const AtomicString& type)
 {
     ASSERT(element);
@@ -232,28 +165,8 @@
     if (isCustomTagName(element->localName()))
         return; // custom tags take precedence over type extensions
 
-    TypeExtensionMap::AddResult result = typeExtensionMap()->add(element, type);
-    ASSERT(result.isNewEntry); // Type extensions should only be set once
-    element->document()->registrationContext()->didGiveTypeExtension(element);
-}
-
-void CustomElementRegistrationContext::customElementWasDestroyed(Element* element)
-{
-    ASSERT(element->isCustomElement());
-    typeExtensionMap()->remove(element);
-}
-
-const AtomicString& CustomElementRegistrationContext::typeExtension(Element* element)
-{
-    TypeExtensionMap::const_iterator it = typeExtensionMap()->find(element);
-    ASSERT(it != typeExtensionMap()->end());
-    return it->value;
-}
-
-CustomElementRegistrationContext::TypeExtensionMap* CustomElementRegistrationContext::typeExtensionMap()
-{
-    DEFINE_STATIC_LOCAL(TypeExtensionMap, typeExtensionMap, ());
-    return &typeExtensionMap;
+    if (CustomElementRegistrationContext* context = element->document()->registrationContext())
+        context->didGiveTypeExtension(element, type);
 }
 
 } // namespace WebCore
diff --git a/Source/core/dom/CustomElementRegistrationContext.h b/Source/core/dom/CustomElementRegistrationContext.h
index c0c89da..c8c2e15 100644
--- a/Source/core/dom/CustomElementRegistrationContext.h
+++ b/Source/core/dom/CustomElementRegistrationContext.h
@@ -32,58 +32,60 @@
 #define CustomElementRegistrationContext_h
 
 #include "core/dom/CustomElementDescriptor.h"
+#include "core/dom/CustomElementRegistry.h"
+#include "core/dom/CustomElementUpgradeCandidateMap.h"
 #include "core/dom/ExceptionCode.h"
 #include "core/dom/QualifiedName.h"
 #include "wtf/HashMap.h"
 #include "wtf/PassRefPtr.h"
-#include "wtf/RefPtr.h"
 #include "wtf/text/AtomicString.h"
 #include "wtf/text/AtomicStringHash.h"
 
 namespace WebCore {
 
 class CustomElementConstructorBuilder;
+class CustomElementDefinition;
 class Document;
 class Element;
 
 class CustomElementRegistrationContext : public RefCounted<CustomElementRegistrationContext> {
 public:
-    static PassRefPtr<CustomElementRegistrationContext> nullRegistrationContext();
     static PassRefPtr<CustomElementRegistrationContext> create();
 
-    virtual ~CustomElementRegistrationContext() { }
+    ~CustomElementRegistrationContext() { }
 
     // Model
     // FIXME: Move this to CustomElementRegistry
     static bool isValidTypeName(const AtomicString& type);
     // FIXME: Move this to CustomElement
     static bool isCustomTagName(const AtomicString& localName);
-    // FIXME: Privatize this when CustomElementWrapper uses the definition map.
-    static CustomElementDescriptor describe(Element*);
 
     // Definitions
-    virtual void registerElement(Document*, CustomElementConstructorBuilder*, const AtomicString& type, ExceptionCode&) = 0;
+    void registerElement(Document*, CustomElementConstructorBuilder*, const AtomicString& type, ExceptionCode&);
 
     // Instance creation
-    virtual PassRefPtr<Element> createCustomTagElement(Document*, const QualifiedName&) = 0;
+    PassRefPtr<Element> createCustomTagElement(Document*, const QualifiedName&);
     static void setIsAttributeAndTypeExtension(Element*, const AtomicString& type);
     static void setTypeExtension(Element*, const AtomicString& type);
 
     // Instance lifecycle
-    virtual void customElementWasDestroyed(Element*);
+    void customElementWasDestroyed(Element*);
 
 protected:
     CustomElementRegistrationContext() { }
 
-    // Model
-    static const AtomicString& typeExtension(Element*);
-
     // Instance creation
-    virtual void didGiveTypeExtension(Element*) = 0;
+    void didGiveTypeExtension(Element*, const AtomicString& type);
 
 private:
-    typedef HashMap<Element*, AtomicString> TypeExtensionMap;
-    static TypeExtensionMap* typeExtensionMap();
+    void resolve(Element*, const AtomicString& typeExtension);
+    void didResolveElement(CustomElementDefinition*, Element*);
+    void didCreateUnresolvedElement(const CustomElementDescriptor&, Element*);
+
+    CustomElementRegistry m_registry;
+
+    // Element creation
+    CustomElementUpgradeCandidateMap m_candidates;
 };
 
 }
diff --git a/Source/core/dom/CustomElementRegistry.cpp b/Source/core/dom/CustomElementRegistry.cpp
index 3bbd23f..65a675d 100644
--- a/Source/core/dom/CustomElementRegistry.cpp
+++ b/Source/core/dom/CustomElementRegistry.cpp
@@ -92,7 +92,7 @@
 
     ASSERT(!observer.registrationContextWentAway());
 
-    RefPtr<CustomElementLifecycleCallbacks> lifecycleCallbacks = constructorBuilder->createCallbacks(document);
+    RefPtr<CustomElementLifecycleCallbacks> lifecycleCallbacks = constructorBuilder->createCallbacks();
 
     // Consulting the constructor builder could execute script and
     // kill the document.
diff --git a/Source/core/dom/CustomElementRegistry.h b/Source/core/dom/CustomElementRegistry.h
index f4195a7..36477fe 100644
--- a/Source/core/dom/CustomElementRegistry.h
+++ b/Source/core/dom/CustomElementRegistry.h
@@ -49,7 +49,7 @@
 class CustomElementRegistry {
     WTF_MAKE_NONCOPYABLE(CustomElementRegistry);
 protected:
-    friend class ActiveRegistrationContext;
+    friend class CustomElementRegistrationContext;
 
     CustomElementRegistry() { }
     virtual ~CustomElementRegistry() { }
diff --git a/Source/core/dom/CustomElementUpgradeCandidateMap.cpp b/Source/core/dom/CustomElementUpgradeCandidateMap.cpp
index e3bcd0d..c84bcb7 100644
--- a/Source/core/dom/CustomElementUpgradeCandidateMap.cpp
+++ b/Source/core/dom/CustomElementUpgradeCandidateMap.cpp
@@ -31,11 +31,25 @@
 #include "config.h"
 #include "core/dom/CustomElementUpgradeCandidateMap.h"
 
+#include "core/dom/Element.h"
+
 namespace WebCore {
 
+CustomElementUpgradeCandidateMap::~CustomElementUpgradeCandidateMap()
+{
+    UpgradeCandidateMap::const_iterator::Keys end = m_upgradeCandidates.end().keys();
+    for (UpgradeCandidateMap::const_iterator::Keys it = m_upgradeCandidates.begin().keys(); it != end; ++it)
+        unregisterForElementDestructionNotification(*it, this);
+}
+
 void CustomElementUpgradeCandidateMap::add(const CustomElementDescriptor& descriptor, Element* element)
 {
-    m_upgradeCandidates.add(element, descriptor);
+    element->setCustomElementState(Element::UpgradeCandidate);
+
+    registerForElementDestructionNotification(element, this);
+
+    UpgradeCandidateMap::AddResult result = m_upgradeCandidates.add(element, descriptor);
+    ASSERT(result.isNewEntry);
 
     UnresolvedDefinitionMap::iterator it = m_unresolvedDefinitions.find(descriptor);
     if (it == m_unresolvedDefinitions.end())
@@ -45,9 +59,10 @@
 
 void CustomElementUpgradeCandidateMap::remove(Element* element)
 {
+    unregisterForElementDestructionNotification(element, this);
+
     UpgradeCandidateMap::iterator candidate = m_upgradeCandidates.find(element);
-    if (candidate == m_upgradeCandidates.end())
-        return;
+    ASSERT(candidate != m_upgradeCandidates.end());
 
     UnresolvedDefinitionMap::iterator elements = m_unresolvedDefinitions.find(candidate->value);
     ASSERT(elements != m_unresolvedDefinitions.end());
@@ -59,10 +74,38 @@
 {
     const ListHashSet<Element*>& candidates = m_unresolvedDefinitions.take(descriptor);
 
-    for (ElementSet::const_iterator candidate = candidates.begin(); candidate != candidates.end(); ++candidate)
+    for (ElementSet::const_iterator candidate = candidates.begin(); candidate != candidates.end(); ++candidate) {
+        unregisterForElementDestructionNotification(*candidate, this);
         m_upgradeCandidates.remove(*candidate);
+    }
 
     return candidates;
 }
 
+void CustomElementUpgradeCandidateMap::elementWasDestroyed(Element* element)
+{
+    DestructionObserverMap::iterator it = destructionObservers().find(element);
+    if (it == destructionObservers().end())
+        return;
+    it->value->remove(element); // will also remove the destruction observer
+}
+
+CustomElementUpgradeCandidateMap::DestructionObserverMap& CustomElementUpgradeCandidateMap::destructionObservers()
+{
+    DEFINE_STATIC_LOCAL(DestructionObserverMap, map, ());
+    return map;
+}
+
+void CustomElementUpgradeCandidateMap::registerForElementDestructionNotification(Element* element, CustomElementUpgradeCandidateMap* observer)
+{
+    DestructionObserverMap::AddResult result = destructionObservers().add(element, observer);
+    ASSERT(result.isNewEntry);
+}
+
+void CustomElementUpgradeCandidateMap::unregisterForElementDestructionNotification(Element* element, CustomElementUpgradeCandidateMap* observer)
+{
+    CustomElementUpgradeCandidateMap* map = destructionObservers().take(element);
+    ASSERT(map == observer);
+}
+
 }
diff --git a/Source/core/dom/CustomElementUpgradeCandidateMap.h b/Source/core/dom/CustomElementUpgradeCandidateMap.h
index bf22e7d..2814c0a 100644
--- a/Source/core/dom/CustomElementUpgradeCandidateMap.h
+++ b/Source/core/dom/CustomElementUpgradeCandidateMap.h
@@ -45,6 +45,9 @@
     WTF_MAKE_NONCOPYABLE(CustomElementUpgradeCandidateMap);
 public:
     CustomElementUpgradeCandidateMap() { }
+    ~CustomElementUpgradeCandidateMap();
+
+    static void elementWasDestroyed(Element*);
 
     void add(const CustomElementDescriptor&, Element*);
     void remove(Element*);
@@ -53,6 +56,12 @@
     ElementSet takeUpgradeCandidatesFor(const CustomElementDescriptor&);
 
 private:
+    // Maps elements to upgrade candidate maps observing their destruction
+    typedef HashMap<Element*, CustomElementUpgradeCandidateMap*> DestructionObserverMap;
+    static DestructionObserverMap& destructionObservers();
+    static void registerForElementDestructionNotification(Element*, CustomElementUpgradeCandidateMap*);
+    static void unregisterForElementDestructionNotification(Element*, CustomElementUpgradeCandidateMap*);
+
     typedef HashMap<Element*, CustomElementDescriptor> UpgradeCandidateMap;
     UpgradeCandidateMap m_upgradeCandidates;
 
diff --git a/Source/core/dom/CustomEvent.idl b/Source/core/dom/CustomEvent.idl
index ed86fda..12edaa5 100644
--- a/Source/core/dom/CustomEvent.idl
+++ b/Source/core/dom/CustomEvent.idl
@@ -9,7 +9,7 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 
+ *
  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 [
diff --git a/Source/core/dom/DOMImplementation.cpp b/Source/core/dom/DOMImplementation.cpp
index 9edaf7a..cee7eb3 100644
--- a/Source/core/dom/DOMImplementation.cpp
+++ b/Source/core/dom/DOMImplementation.cpp
@@ -31,6 +31,7 @@
 #include "core/css/MediaList.h"
 #include "core/css/StyleSheetContents.h"
 #include "core/dom/ContextFeatures.h"
+#include "core/dom/DocumentInit.h"
 #include "core/dom/DocumentType.h"
 #include "core/dom/Element.h"
 #include "core/dom/ExceptionCode.h"
@@ -146,7 +147,7 @@
         addString(svgFeatures, "ExternalResourcesRequired");
         addString(svgFeatures, "View");
         addString(svgFeatures, "Script");
-        addString(svgFeatures, "Animation"); 
+        addString(svgFeatures, "Animation");
 #if ENABLE(SVG_FONTS)
         addString(svgFeatures, "Font");
         addString(svgFeatures, "BasicFont");
@@ -257,7 +258,7 @@
     if (namespaceURI == SVGNames::svgNamespaceURI)
         doc = SVGDocument::create();
     else if (namespaceURI == HTMLNames::xhtmlNamespaceURI)
-        doc = Document::createXHTML();
+        doc = Document::createXHTML(DocumentInit().withRegistrationContext(m_document->registrationContext()));
     else
         doc = Document::create();
 
@@ -372,7 +373,7 @@
 
 PassRefPtr<HTMLDocument> DOMImplementation::createHTMLDocument(const String& title)
 {
-    RefPtr<HTMLDocument> d = HTMLDocument::create();
+    RefPtr<HTMLDocument> d = HTMLDocument::create(DocumentInit().withRegistrationContext(m_document->registrationContext()));
     d->open();
     d->write("<!doctype html><html><body></body></html>");
     if (!title.isNull())
@@ -411,7 +412,7 @@
     // Everything else except text/plain can be overridden by plugins. In particular, Adobe SVG Viewer should be used for SVG, if installed.
     // Disallowing plug-ins to use text/plain prevents plug-ins from hijacking a fundamental type that the browser is expected to handle,
     // and also serves as an optimization to prevent loading the plug-in database in the common case.
-    if (type != "text/plain" && pluginData && pluginData->supportsMimeType(type)) 
+    if (type != "text/plain" && pluginData && pluginData->supportsMimeType(type))
         return PluginDocument::create(DocumentInit(url, frame));
     if (isTextMIMEType(type))
         return TextDocument::create(DocumentInit(url, frame));
diff --git a/Source/core/dom/DOMImplementation.h b/Source/core/dom/DOMImplementation.h
index 14dcdf7..e09ff6e 100644
--- a/Source/core/dom/DOMImplementation.h
+++ b/Source/core/dom/DOMImplementation.h
@@ -43,7 +43,7 @@
     WTF_MAKE_FAST_ALLOCATED;
 public:
     static PassOwnPtr<DOMImplementation> create(Document* document) { return adoptPtr(new DOMImplementation(document)); }
-    
+
     void ref() { m_document->ref(); }
     void deref() { m_document->deref(); }
     Document* document() { return m_document; }
diff --git a/Source/core/dom/DOMImplementation.idl b/Source/core/dom/DOMImplementation.idl
index 0040c11..0d627f5 100644
--- a/Source/core/dom/DOMImplementation.idl
+++ b/Source/core/dom/DOMImplementation.idl
@@ -24,7 +24,7 @@
 
     // DOM Level 1
 
-     boolean hasFeature([Default=Undefined] optional DOMString feature, 
+     boolean hasFeature([Default=Undefined] optional DOMString feature,
                                       [TreatNullAs=NullString,Default=Undefined] optional DOMString version);
 
     // DOM Level 2
@@ -32,8 +32,8 @@
      [RaisesException] DocumentType createDocumentType([TreatNullAs=NullString, TreatUndefinedAs=NullString,Default=Undefined] optional DOMString qualifiedName,
                                                    [TreatNullAs=NullString, TreatUndefinedAs=NullString,Default=Undefined] optional DOMString publicId,
                                                    [TreatNullAs=NullString, TreatUndefinedAs=NullString,Default=Undefined] optional DOMString systemId);
-     [RaisesException] Document createDocument([TreatNullAs=NullString,Default=Undefined] optional DOMString namespaceURI, 
-                                           [TreatNullAs=NullString,Default=Undefined] optional DOMString qualifiedName, 
+     [RaisesException] Document createDocument([TreatNullAs=NullString,Default=Undefined] optional DOMString namespaceURI,
+                                           [TreatNullAs=NullString,Default=Undefined] optional DOMString qualifiedName,
                                            [TreatNullAs=NullString,Default=Undefined] optional DocumentType doctype);
 
     // DOMImplementationCSS interface from DOM Level 2 CSS
diff --git a/Source/core/dom/DataTransferItemList.idl b/Source/core/dom/DataTransferItemList.idl
index 07e9e2a..eec5c0c 100644
--- a/Source/core/dom/DataTransferItemList.idl
+++ b/Source/core/dom/DataTransferItemList.idl
@@ -36,7 +36,7 @@
 
     void clear();
     void add(File? file);
-    [RaisesException] void add([Default=Undefined] optional DOMString data, 
+    [RaisesException] void add([Default=Undefined] optional DOMString data,
              [Default=Undefined] optional DOMString type);
 };
 
diff --git a/Source/core/dom/DatasetDOMStringMap.cpp b/Source/core/dom/DatasetDOMStringMap.cpp
index b959ec0..10e9b40 100644
--- a/Source/core/dom/DatasetDOMStringMap.cpp
+++ b/Source/core/dom/DatasetDOMStringMap.cpp
@@ -76,7 +76,7 @@
 
     unsigned propertyLength = propertyName.length();
     unsigned attributeLength = attributeName.length();
-   
+
     unsigned a = 5;
     unsigned p = 0;
     bool wordBoundary = false;
diff --git a/Source/core/dom/DecodedDataDocumentParser.h b/Source/core/dom/DecodedDataDocumentParser.h
index ea13ff6..c931c0c 100644
--- a/Source/core/dom/DecodedDataDocumentParser.h
+++ b/Source/core/dom/DecodedDataDocumentParser.h
@@ -22,7 +22,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
- 
+
 #ifndef DecodedDataDocumentParser_h
 #define DecodedDataDocumentParser_h
 
diff --git a/Source/core/dom/Document.cpp b/Source/core/dom/Document.cpp
index 8f69070..8327fcf 100644
--- a/Source/core/dom/Document.cpp
+++ b/Source/core/dom/Document.cpp
@@ -437,6 +437,7 @@
     , m_lastHandledUserGestureTimestamp(0)
     , m_prerenderer(Prerenderer::create(this))
     , m_textAutosizer(TextAutosizer::create(this))
+    , m_registrationContext(initializer.registrationContext(this))
     , m_pendingTasksTimer(this, &Document::pendingTasksTimerFired)
     , m_scheduledTasksAreSuspended(false)
     , m_sharedObjectPoolClearTimer(this, &Document::sharedObjectPoolClearTimerFired)
@@ -475,13 +476,6 @@
         m_nodeListCounts[i] = 0;
 
     InspectorCounters::incrementCounter(InspectorCounters::DocumentCounter);
-
-    bool shouldProcessCustomElements =
-        (isHTMLDocument() || isXHTMLDocument())
-        && RuntimeEnabledFeatures::customDOMElementsEnabled();
-    m_registrationContext = shouldProcessCustomElements
-        ? CustomElementRegistrationContext::create()
-        : CustomElementRegistrationContext::nullRegistrationContext();
 }
 
 static void histogramMutationEventUsage(const unsigned short& listenerTypes)
@@ -720,7 +714,7 @@
 
     RefPtr<Element> element;
 
-    if (CustomElementRegistrationContext::isCustomTagName(localName))
+    if (CustomElementRegistrationContext::isCustomTagName(localName) && registrationContext())
         element = registrationContext()->createCustomTagElement(this, QualifiedName(nullAtom, localName, xhtmlNamespaceURI));
     else
         element = createElement(localName, ec);
@@ -744,7 +738,7 @@
     }
 
     RefPtr<Element> element;
-    if (CustomElementRegistrationContext::isCustomTagName(qName.localName()))
+    if (CustomElementRegistrationContext::isCustomTagName(qName.localName()) && registrationContext())
         element = registrationContext()->createCustomTagElement(this, qName);
     else
         element = createElementNS(namespaceURI, qualifiedName, ec);
@@ -762,6 +756,11 @@
 
 ScriptValue Document::registerElement(WebCore::ScriptState* state, const AtomicString& name, const Dictionary& options, ExceptionCode& ec)
 {
+    if (!registrationContext()) {
+        ec = NotSupportedError;
+        return ScriptValue();
+    }
+
     CustomElementConstructorBuilder constructorBuilder(state, &options);
     registrationContext()->registerElement(this, &constructorBuilder, name, ec);
     return constructorBuilder.bindingsReturnValue();
@@ -2315,7 +2314,7 @@
         || (documentElement() && !isHTMLHtmlElement(documentElement()));
 }
 
-bool Document::isLayoutTimerActive()
+bool Document::shouldParserYieldAgressivelyBeforeScriptExecution()
 {
     return view() && view()->layoutPending() && !minimumLayoutDelay();
 }
@@ -3154,7 +3153,7 @@
             oldFocusedElement->dispatchFormControlChangeEvent();
 
         // Dispatch the blur event and let the node do any other blur related activities (important for text fields)
-        oldFocusedElement->dispatchBlurEvent(newFocusedElement);
+        oldFocusedElement->dispatchBlurEvent(newFocusedElement.get());
 
         if (m_focusedElement) {
             // handler shifted focus
@@ -3162,10 +3161,10 @@
             newFocusedElement = 0;
         }
 
-        oldFocusedElement->dispatchFocusOutEvent(eventNames().focusoutEvent, newFocusedElement); // DOM level 3 name for the bubbling blur event.
+        oldFocusedElement->dispatchFocusOutEvent(eventNames().focusoutEvent, newFocusedElement.get()); // DOM level 3 name for the bubbling blur event.
         // FIXME: We should remove firing DOMFocusOutEvent event when we are sure no content depends
         // on it, probably when <rdar://problem/8503958> is resolved.
-        oldFocusedElement->dispatchFocusOutEvent(eventNames().DOMFocusOutEvent, newFocusedElement); // DOM level 2 name for compatibility.
+        oldFocusedElement->dispatchFocusOutEvent(eventNames().DOMFocusOutEvent, newFocusedElement.get()); // DOM level 2 name for compatibility.
 
         if (m_focusedElement) {
             // handler shifted focus
@@ -3195,7 +3194,7 @@
         m_focusedElement = newFocusedElement;
 
         // Dispatch the focus event and let the node do any other focus related activities (important for text fields)
-        m_focusedElement->dispatchFocusEvent(oldFocusedElement, direction);
+        m_focusedElement->dispatchFocusEvent(oldFocusedElement.get(), direction);
 
         if (m_focusedElement != newFocusedElement) {
             // handler shifted focus
@@ -3203,7 +3202,7 @@
             goto SetFocusedElementDone;
         }
 
-        m_focusedElement->dispatchFocusInEvent(eventNames().focusinEvent, oldFocusedElement); // DOM level 3 bubbling focus event.
+        m_focusedElement->dispatchFocusInEvent(eventNames().focusinEvent, oldFocusedElement.get()); // DOM level 3 bubbling focus event.
 
         if (m_focusedElement != newFocusedElement) {
             // handler shifted focus
@@ -3213,7 +3212,7 @@
 
         // FIXME: We should remove firing DOMFocusInEvent event when we are sure no content depends
         // on it, probably when <rdar://problem/8503958> is m.
-        m_focusedElement->dispatchFocusInEvent(eventNames().DOMFocusInEvent, oldFocusedElement); // DOM level 2 for compatibility.
+        m_focusedElement->dispatchFocusInEvent(eventNames().DOMFocusInEvent, oldFocusedElement.get()); // DOM level 2 for compatibility.
 
         if (m_focusedElement != newFocusedElement) {
             // handler shifted focus
@@ -4110,6 +4109,9 @@
 
     // Parser should have picked up all preloads by now
     m_fetcher->clearPreloads();
+
+    if (m_import)
+        m_import->didFinishParsing();
 }
 
 void Document::sharedObjectPoolClearTimerFired(Timer<Document>*)
@@ -4209,7 +4211,7 @@
         return;
     }
 
-    if (!initializer.frame()) {
+    if (!initializer.hasSecurityContext()) {
         // No source for a security context.
         // This can occur via document.implementation.createDocument().
         m_cookieURL = KURL(ParsedURLString, emptyString());
@@ -4281,12 +4283,11 @@
     setSecurityOrigin(ownerFrame->document()->securityOrigin());
 }
 
-void Document::initContentSecurityPolicy()
+void Document::initContentSecurityPolicy(const ContentSecurityPolicyResponseHeaders& headers)
 {
-    if (!m_frame->tree()->parent() || (!shouldInheritSecurityOriginFromOwner(m_url) && !isPluginDocument()))
-        return;
-
-    contentSecurityPolicy()->copyStateFrom(m_frame->tree()->parent()->document()->contentSecurityPolicy());
+    if (m_frame && m_frame->tree()->parent() && (shouldInheritSecurityOriginFromOwner(m_url) || isPluginDocument()))
+        contentSecurityPolicy()->copyStateFrom(m_frame->tree()->parent()->document()->contentSecurityPolicy());
+    contentSecurityPolicy()->didReceiveHeaders(headers);
 }
 
 void Document::didUpdateSecurityOrigin()
@@ -5043,7 +5044,7 @@
         return const_cast<Document*>(document);
 
     if (isHTMLDocument())
-        m_templateDocument = HTMLDocument::create(DocumentInit(blankURL()));
+        m_templateDocument = HTMLDocument::create(DocumentInit(blankURL()).withRegistrationContext(registrationContext()));
     else
         m_templateDocument = Document::create(DocumentInit(blankURL()));
 
diff --git a/Source/core/dom/Document.h b/Source/core/dom/Document.h
index 08627c3..6b2653e 100644
--- a/Source/core/dom/Document.h
+++ b/Source/core/dom/Document.h
@@ -69,6 +69,7 @@
 class CanvasRenderingContext;
 class CharacterData;
 class Comment;
+class ContentSecurityPolicyResponseHeaders;
 class ContextFeatures;
 class CustomElementRegistrationContext;
 class DOMImplementation;
@@ -299,7 +300,7 @@
     DocumentType* doctype() const { return m_docType.get(); }
 
     DOMImplementation* implementation();
-    
+
     Element* documentElement() const
     {
         return m_documentElement.get();
@@ -423,7 +424,7 @@
     bool sawElementsInKnownNamespaces() const { return m_sawElementsInKnownNamespaces; }
 
     StyleResolver* styleResolver()
-    { 
+    {
         if (!m_styleResolver)
             createStyleResolver();
         return m_styleResolver.get();
@@ -529,7 +530,7 @@
     // to get visually ordered hebrew and arabic pages right
     void setVisuallyOrdered();
     bool visuallyOrdered() const { return m_visuallyOrdered; }
-    
+
     DocumentLoader* loader() const;
 
     void open(Document* ownerDocument = 0);
@@ -575,17 +576,17 @@
     Frame* findUnsafeParentScrollPropagationBoundary();
 
     CSSStyleSheet* elementSheet();
-    
+
     virtual PassRefPtr<DocumentParser> createParser();
     DocumentParser* parser() const { return m_parser.get(); }
     ScriptableDocumentParser* scriptableDocumentParser() const;
-    
+
     bool printing() const { return m_printing; }
     void setPrinting(bool p) { m_printing = p; }
 
     bool paginatedForScreen() const { return m_paginatedForScreen; }
     void setPaginatedForScreen(bool p) { m_paginatedForScreen = p; }
-    
+
     bool paginated() const { return printing() || paginatedForScreen(); }
 
     enum CompatibilityMode { QuirksMode, LimitedQuirksMode, NoQuirksMode };
@@ -611,7 +612,7 @@
     int minimumLayoutDelay();
 
     bool shouldScheduleLayout();
-    bool isLayoutTimerActive();
+    bool shouldParserYieldAgressivelyBeforeScriptExecution();
     int elapsedTime() const;
 
     TextLinkColors& textLinkColors() { return m_textLinkColors; }
@@ -633,7 +634,7 @@
     const UserActionElementSet& userActionElements() const { return m_userActionElements; }
     void didRunCheckFocusedElementTask() { m_didPostCheckFocusedElementTask = false; }
 
-    // The m_ignoreAutofocus flag specifies whether or not the document has been changed by the user enough 
+    // The m_ignoreAutofocus flag specifies whether or not the document has been changed by the user enough
     // for WebCore to ignore the autofocus attribute on any form controls
     bool ignoreAutofocus() const { return m_ignoreAutofocus; };
     void setIgnoreAutofocus(bool shouldIgnore = true) { m_ignoreAutofocus = shouldIgnore; };
@@ -687,7 +688,7 @@
     void setDOMWindow(DOMWindow* domWindow) { m_domWindow = domWindow; }
     DOMWindow* domWindow() const { return m_domWindow; }
     // In DOM Level 2, the Document's DOMWindow is called the defaultView.
-    DOMWindow* defaultView() const { return domWindow(); } 
+    DOMWindow* defaultView() const { return domWindow(); }
 
     // Helper functions for forwarding DOMWindow event related tasks to the DOMWindow if it exists.
     void setWindowAttributeEventListener(const AtomicString& eventType, PassRefPtr<EventListener>, DOMWrapperWorld* isolatedWorld = 0);
@@ -780,7 +781,7 @@
     void setCookieURL(const KURL& url) { m_cookieURL = url; }
 
     const KURL& firstPartyForCookies() const;
-    
+
     // The following implements the rule from HTML 4 for what valid names are.
     // To get this right for all the XML cases, we probably have to improve this or move it
     // and make it sensitive to the type of document.
@@ -817,7 +818,7 @@
     KURL openSearchDescriptionURL();
 
     // designMode support
-    enum InheritedBool { off = false, on = true, inherit };    
+    enum InheritedBool { off = false, on = true, inherit };
     void setDesignMode(InheritedBool value);
     InheritedBool getDesignMode() const;
     bool inDesignMode() const;
@@ -858,7 +859,7 @@
 
     void updateFocusAppearanceSoon(bool restorePreviousSelection);
     void cancelFocusAppearanceUpdate();
-        
+
     // Extension for manipulating canvas drawing contexts for use in CSS
     CanvasRenderingContext* getCSSCanvasContext(const String& type, const String& name, int width, int height);
     HTMLCanvasElement* getCSSCanvasElement(const String& name);
@@ -903,7 +904,7 @@
 
     void initSecurityContext();
     void initSecurityContext(const DocumentInit&);
-    void initContentSecurityPolicy();
+    void initContentSecurityPolicy(const ContentSecurityPolicyResponseHeaders&);
 
     void updateURLForPushOrReplaceState(const KURL&);
     void statePopped(PassRefPtr<SerializedScriptValue>);
@@ -1176,7 +1177,7 @@
 
     uint64_t m_domTreeVersion;
     static uint64_t s_globalTreeVersion;
-    
+
     HashSet<NodeIterator*> m_nodeIterators;
     HashSet<Range*> m_ranges;
 
@@ -1219,7 +1220,7 @@
 
     OwnPtr<AXObjectCache> m_axObjectCache;
     OwnPtr<DocumentMarkerController> m_markers;
-    
+
     Timer<Document> m_updateFocusAppearanceTimer;
 
     Element* m_cssTarget;
@@ -1234,7 +1235,7 @@
     RefPtr<SerializedScriptValue> m_pendingStateObject;
     double m_startTime;
     bool m_overMinimumLayoutThreshold;
-    
+
     OwnPtr<ScriptRunner> m_scriptRunner;
 
     Vector<RefPtr<HTMLScriptElement> > m_currentScriptStack;
@@ -1301,7 +1302,7 @@
     RefPtr<MediaQueryMatcher> m_mediaQueryMatcher;
     bool m_writeRecursionIsTooDeep;
     unsigned m_writeRecursionDepth;
-    
+
     unsigned m_wheelEventHandlerCount;
     OwnPtr<TouchEventTargetSet> m_touchEventTargets;
 
@@ -1319,7 +1320,7 @@
     RefPtr<CustomElementRegistrationContext> m_registrationContext;
 
     bool m_scheduledTasksAreSuspended;
-    
+
     RefPtr<NamedFlowCollection> m_namedFlows;
 
     RefPtr<DOMSecurityPolicy> m_domSecurityPolicy;
diff --git a/Source/core/dom/DocumentEventQueue.cpp b/Source/core/dom/DocumentEventQueue.cpp
index 61c5bb5..8768c1e 100644
--- a/Source/core/dom/DocumentEventQueue.cpp
+++ b/Source/core/dom/DocumentEventQueue.cpp
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  */
 
@@ -34,7 +34,7 @@
 #include "core/page/SuspendableTimer.h"
 
 namespace WebCore {
-    
+
 class DocumentEventQueueTimer : public SuspendableTimer {
     WTF_MAKE_NONCOPYABLE(DocumentEventQueueTimer);
 public:
@@ -71,7 +71,7 @@
     ASSERT(event->target());
     bool wasAdded = m_queuedEvents.add(event).isNewEntry;
     ASSERT_UNUSED(wasAdded, wasAdded); // It should not have already been in the list.
-    
+
     if (!m_pendingEventTimer->isActive())
         m_pendingEventTimer->startOneShot(0);
 
@@ -86,7 +86,7 @@
     // Per the W3C CSSOM View Module, scroll events fired at the document should bubble, others should not.
     bool canBubble = targetType == ScrollEventDocumentTarget;
     RefPtr<Event> scrollEvent = Event::create(eventNames().scrollEvent, canBubble, false /* non cancelleable */);
-     
+
     if (!m_nodesWithQueuedScrollEvents.add(target.get()).isNewEntry)
         return;
 
diff --git a/Source/core/dom/DocumentEventQueue.h b/Source/core/dom/DocumentEventQueue.h
index 84d663e..bd8fb76 100644
--- a/Source/core/dom/DocumentEventQueue.h
+++ b/Source/core/dom/DocumentEventQueue.h
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  */
 
@@ -69,7 +69,7 @@
     HashSet<Node*> m_nodesWithQueuedScrollEvents;
     bool m_isClosed;
 
-    friend class DocumentEventQueueTimer;    
+    friend class DocumentEventQueueTimer;
 };
 
 }
diff --git a/Source/core/dom/DocumentFragment.h b/Source/core/dom/DocumentFragment.h
index 1b763a1..0489d39 100644
--- a/Source/core/dom/DocumentFragment.h
+++ b/Source/core/dom/DocumentFragment.h
@@ -38,7 +38,7 @@
 
     void parseHTML(const String&, Element* contextElement, ParserContentPolicy = AllowScriptingContent);
     bool parseXML(const String&, Element* contextElement, ParserContentPolicy = AllowScriptingContent);
-    
+
     virtual bool canContainRangeEndPoint() const { return true; }
     virtual bool isTemplateContent() const { return false; }
 
diff --git a/Source/core/dom/DocumentInit.cpp b/Source/core/dom/DocumentInit.cpp
index adf48c2..f6d74b2 100644
--- a/Source/core/dom/DocumentInit.cpp
+++ b/Source/core/dom/DocumentInit.cpp
@@ -28,6 +28,8 @@
 #include "config.h"
 #include "core/dom/DocumentInit.h"
 
+#include "RuntimeEnabledFeatures.h"
+#include "core/dom/Document.h"
 #include "core/html/HTMLImportsController.h"
 #include "core/page/Frame.h"
 
@@ -40,26 +42,62 @@
 
 bool DocumentInit::shouldTreatURLAsSrcdocDocument() const
 {
+    ASSERT(m_frame);
     return m_frame->loader()->shouldTreatURLAsSrcdocDocument(m_url);
 }
 
+Frame* DocumentInit::frameForSecurityContext() const
+{
+    if (m_frame)
+        return m_frame;
+    if (m_import)
+        return m_import->frame();
+    return 0;
+}
+
 SandboxFlags DocumentInit::sandboxFlags() const
 {
-    return m_frame->loader()->effectiveSandboxFlags();
+    ASSERT(frameForSecurityContext());
+    return frameForSecurityContext()->loader()->effectiveSandboxFlags();
 }
 
 Settings* DocumentInit::settings() const
 {
-    return m_frame->settings();
+    ASSERT(frameForSecurityContext());
+    return frameForSecurityContext()->settings();
 }
 
 Frame* DocumentInit::ownerFrame() const
 {
+    if (!m_frame)
+        return 0;
+
     Frame* ownerFrame = m_frame->tree()->parent();
     if (!ownerFrame)
         ownerFrame = m_frame->loader()->opener();
     return ownerFrame;
 }
 
+DocumentInit& DocumentInit::withRegistrationContext(CustomElementRegistrationContext* registrationContext)
+{
+    ASSERT(!m_registrationContext);
+    m_registrationContext = registrationContext;
+    return *this;
+}
+
+PassRefPtr<CustomElementRegistrationContext> DocumentInit::registrationContext(Document* document) const
+{
+    if (!RuntimeEnabledFeatures::customDOMElementsEnabled())
+        return 0;
+
+    if (!document->isHTMLDocument() && !document->isXHTMLDocument())
+        return 0;
+
+    if (m_registrationContext)
+        return m_registrationContext.get();
+
+    return CustomElementRegistrationContext::create();
+}
+
 } // namespace WebCore
 
diff --git a/Source/core/dom/DocumentInit.h b/Source/core/dom/DocumentInit.h
index 893662f..73ce2be 100644
--- a/Source/core/dom/DocumentInit.h
+++ b/Source/core/dom/DocumentInit.h
@@ -28,11 +28,15 @@
 #ifndef DocumentInit_h
 #define DocumentInit_h
 
+#include "core/dom/CustomElementRegistrationContext.h"
 #include "core/dom/SecurityContext.h"
 #include "weborigin/KURL.h"
+#include "wtf/PassRefPtr.h"
+#include "wtf/RefPtr.h"
 
 namespace WebCore {
 
+class Document;
 class Frame;
 class HTMLImport;
 class Settings;
@@ -49,6 +53,7 @@
     Frame* frame() const { return m_frame; }
     HTMLImport* import() const { return m_import; }
 
+    bool hasSecurityContext() const { return frameForSecurityContext(); }
     bool shouldTreatURLAsSrcdocDocument() const;
     bool shouldSetURL() const;
     SandboxFlags sandboxFlags() const;
@@ -56,10 +61,16 @@
     Frame* ownerFrame() const;
     Settings* settings() const;
 
+    DocumentInit& withRegistrationContext(CustomElementRegistrationContext*);
+    PassRefPtr<CustomElementRegistrationContext> registrationContext(Document*) const;
+
 private:
+    Frame* frameForSecurityContext() const;
+
     KURL m_url;
     Frame* m_frame;
     HTMLImport* m_import;
+    RefPtr<CustomElementRegistrationContext> m_registrationContext;
 };
 
 } // namespace WebCore
diff --git a/Source/core/dom/DocumentMarker.cpp b/Source/core/dom/DocumentMarker.cpp
index aa7d4b0..5f3db28 100644
--- a/Source/core/dom/DocumentMarker.cpp
+++ b/Source/core/dom/DocumentMarker.cpp
@@ -97,7 +97,7 @@
 }
 
 
-DocumentMarker::DocumentMarker() 
+DocumentMarker::DocumentMarker()
     : m_type(Spelling)
     , m_startOffset(0)
     , m_endOffset(0)
diff --git a/Source/core/dom/DocumentMarkerController.cpp b/Source/core/dom/DocumentMarkerController.cpp
index 0928c3d..c47e8b8 100644
--- a/Source/core/dom/DocumentMarkerController.cpp
+++ b/Source/core/dom/DocumentMarkerController.cpp
@@ -136,7 +136,7 @@
 // Markers are stored in order sorted by their start offset.
 // Markers of the same type do not overlap each other.
 
-void DocumentMarkerController::addMarker(Node* node, const DocumentMarker& newMarker) 
+void DocumentMarkerController::addMarker(Node* node, const DocumentMarker& newMarker)
 {
     ASSERT(newMarker.endOffset() >= newMarker.startOffset());
     if (newMarker.endOffset() == newMarker.startOffset())
@@ -436,7 +436,7 @@
     if (!possiblyHasMarkers(markerTypes))
         return;
     ASSERT(!m_markers.isEmpty());
-    
+
     MarkerMap::iterator iterator = m_markers.find(node);
     if (iterator != m_markers.end())
         removeMarkersFromList(iterator, markerTypes);
diff --git a/Source/core/dom/DocumentParser.h b/Source/core/dom/DocumentParser.h
index 587fa2f..3b3969b 100644
--- a/Source/core/dom/DocumentParser.h
+++ b/Source/core/dom/DocumentParser.h
@@ -51,6 +51,7 @@
     virtual size_t flush() = 0;
     virtual bool needsDecoder() const { return false; }
 
+    // pinToMainThread also makes append() not yield before completion of that chunk.
     virtual void pinToMainThread() { }
 
     // FIXME: append() should be private, but DocumentWriter::replaceDocument uses it for now.
diff --git a/Source/core/dom/DocumentStyleSheetCollection.cpp b/Source/core/dom/DocumentStyleSheetCollection.cpp
index d45931c..74ef2b1 100644
--- a/Source/core/dom/DocumentStyleSheetCollection.cpp
+++ b/Source/core/dom/DocumentStyleSheetCollection.cpp
@@ -233,9 +233,9 @@
     m_collectionForDocument.addStyleSheetCandidateNode(node, createdByParser);
 }
 
-void DocumentStyleSheetCollection::removeStyleSheetCandidateNode(Node* node)
+void DocumentStyleSheetCollection::removeStyleSheetCandidateNode(Node* node, ContainerNode* scopingNode)
 {
-    m_collectionForDocument.removeStyleSheetCandidateNode(node);
+    m_collectionForDocument.removeStyleSheetCandidateNode(node, scopingNode);
 }
 
 static bool styleSheetsUseRemUnits(const Vector<RefPtr<CSSStyleSheet> >& sheets)
diff --git a/Source/core/dom/DocumentStyleSheetCollection.h b/Source/core/dom/DocumentStyleSheetCollection.h
index 0e220e2..bbafeb8 100644
--- a/Source/core/dom/DocumentStyleSheetCollection.h
+++ b/Source/core/dom/DocumentStyleSheetCollection.h
@@ -63,7 +63,7 @@
     const Vector<RefPtr<CSSStyleSheet> >& injectedAuthorStyleSheets() const;
 
     void addStyleSheetCandidateNode(Node*, bool createdByParser);
-    void removeStyleSheetCandidateNode(Node*);
+    void removeStyleSheetCandidateNode(Node*, ContainerNode* scopingNode = 0);
 
     void clearPageUserSheet();
     void updatePageUserSheet();
@@ -100,6 +100,7 @@
     void setUsesBeforeAfterRulesOverride(bool b) { m_usesBeforeAfterRulesOverride = b; }
     bool usesRemUnits() const { return m_usesRemUnits; }
     void setUsesRemUnit(bool b) { m_usesRemUnits = b; }
+    bool hasScopedStyleSheet() { return m_collectionForDocument.scopingNodesForStyleScoped(); }
 
     void combineCSSFeatureFlags(const RuleFeatureSet&);
     void resetCSSFeatureFlags(const RuleFeatureSet&);
diff --git a/Source/core/dom/DocumentTiming.h b/Source/core/dom/DocumentTiming.h
index 89e2fb9..ba6e08c 100644
--- a/Source/core/dom/DocumentTiming.h
+++ b/Source/core/dom/DocumentTiming.h
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #ifndef DocumentTiming_h
diff --git a/Source/core/dom/Element.cpp b/Source/core/dom/Element.cpp
index dc64b8d..3d1ad9c 100644
--- a/Source/core/dom/Element.cpp
+++ b/Source/core/dom/Element.cpp
@@ -50,7 +50,9 @@
 #include "core/dom/Document.h"
 #include "core/dom/DocumentSharedObjectPool.h"
 #include "core/dom/ElementRareData.h"
+#include "core/dom/EventDispatcher.h"
 #include "core/dom/ExceptionCode.h"
+#include "core/dom/FocusEvent.h"
 #include "core/dom/FullscreenController.h"
 #include "core/dom/MutationObserverInterestGroup.h"
 #include "core/dom/MutationRecord.h"
@@ -2059,6 +2061,32 @@
     }
 }
 
+void Element::dispatchFocusEvent(Element* oldFocusedElement, FocusDirection)
+{
+    RefPtr<FocusEvent> event = FocusEvent::create(eventNames().focusEvent, false, false, document()->defaultView(), 0, oldFocusedElement);
+    EventDispatcher::dispatchEvent(this, FocusEventDispatchMediator::create(event.release()));
+}
+
+void Element::dispatchBlurEvent(Element* newFocusedElement)
+{
+    RefPtr<FocusEvent> event = FocusEvent::create(eventNames().blurEvent, false, false, document()->defaultView(), 0, newFocusedElement);
+    EventDispatcher::dispatchEvent(this, BlurEventDispatchMediator::create(event.release()));
+}
+
+void Element::dispatchFocusInEvent(const AtomicString& eventType, Element* oldFocusedElement)
+{
+    ASSERT(!NoEventDispatchAssertion::isEventDispatchForbidden());
+    ASSERT(eventType == eventNames().focusinEvent || eventType == eventNames().DOMFocusInEvent);
+    dispatchScopedEventDispatchMediator(FocusInEventDispatchMediator::create(FocusEvent::create(eventType, true, false, document()->defaultView(), 0, oldFocusedElement)));
+}
+
+void Element::dispatchFocusOutEvent(const AtomicString& eventType, Element* newFocusedElement)
+{
+    ASSERT(!NoEventDispatchAssertion::isEventDispatchForbidden());
+    ASSERT(eventType == eventNames().focusoutEvent || eventType == eventNames().DOMFocusOutEvent);
+    dispatchScopedEventDispatchMediator(FocusOutEventDispatchMediator::create(FocusEvent::create(eventType, true, false, document()->defaultView(), 0, newFocusedElement)));
+}
+
 String Element::innerText()
 {
     // We need to update layout, since plainText uses line boxes in the render tree.
diff --git a/Source/core/dom/Element.h b/Source/core/dom/Element.h
index 989019c..57a45a0 100644
--- a/Source/core/dom/Element.h
+++ b/Source/core/dom/Element.h
@@ -32,6 +32,7 @@
 #include "core/dom/Document.h"
 #include "core/dom/SpaceSplitString.h"
 #include "core/html/CollectionType.h"
+#include "core/page/FocusDirection.h"
 #include "core/platform/ScrollTypes.h"
 #include "core/rendering/RegionOversetState.h"
 
@@ -330,7 +331,7 @@
 
     PassRefPtr<ClientRectList> getClientRects();
     PassRefPtr<ClientRect> getBoundingClientRect();
-    
+
     // Returns the absolute bounding box translated into screen coordinates:
     IntRect screenRect() const;
 
@@ -357,7 +358,7 @@
     const QualifiedName& tagQName() const { return m_tagName; }
     String tagName() const { return nodeName(); }
     bool hasTagName(const QualifiedName& tagName) const { return m_tagName.matches(tagName); }
-    
+
     // A fast function for checking the local name against another atomic string.
     bool hasLocalName(const AtomicString& other) const { return m_tagName.localName() == other; }
     bool hasLocalName(const QualifiedName& other) const { return m_tagName.localName() == other.localName(); }
@@ -507,10 +508,14 @@
     virtual void focus(bool restorePreviousSelection = true, FocusDirection = FocusDirectionNone);
     virtual void updateFocusAppearance(bool restorePreviousSelection);
     virtual void blur();
+    virtual void dispatchFocusEvent(Element* oldFocusedElement, FocusDirection);
+    virtual void dispatchBlurEvent(Element* newFocusedElement);
+    void dispatchFocusInEvent(const AtomicString& eventType, Element* oldFocusedElement);
+    void dispatchFocusOutEvent(const AtomicString& eventType, Element* newFocusedElement);
 
     String innerText();
     String outerText();
- 
+
     String textFromChildren();
 
     virtual String title() const { return String(); }
@@ -592,7 +597,7 @@
         ALLOW_KEYBOARD_INPUT = 1 << 0,
         LEGACY_MOZILLA_REQUEST = 1 << 1,
     };
-    
+
     void webkitRequestFullScreen(unsigned short flags);
     bool containsFullScreenElement() const;
     void setContainsFullScreenElement(bool);
@@ -657,7 +662,7 @@
     virtual bool shouldRegisterAsNamedItem() const { return false; }
     virtual bool shouldRegisterAsExtraNamedItem() const { return false; }
 
-    void clearTabIndexExplicitlyIfNeeded();    
+    void clearTabIndexExplicitlyIfNeeded();
     void setTabIndexExplicitly(short);
     virtual bool supportsFocus() const OVERRIDE;
     virtual short tabIndex() const OVERRIDE;
@@ -727,7 +732,7 @@
     void cancelFocusAppearanceUpdate();
 
     virtual RenderStyle* virtualComputedStyle(PseudoId pseudoElementSpecifier = NOPSEUDO) { return computedStyle(pseudoElementSpecifier); }
-    
+
     // cloneNode is private so that non-virtual cloneElementWithChildren and cloneElementWithoutChildren
     // are used instead.
     virtual PassRefPtr<Node> cloneNode(bool deep) OVERRIDE;
@@ -769,7 +774,7 @@
 
     RefPtr<ElementData> m_elementData;
 };
-    
+
 inline Element* toElement(Node* node)
 {
     ASSERT_WITH_SECURITY_IMPLICATION(!node || node->isElementNode());
@@ -794,7 +799,7 @@
 {
     return isElementNode() && toElement(this)->hasTagName(name);
 }
-    
+
 inline bool Node::hasLocalName(const AtomicString& name) const
 {
     return isElementNode() && toElement(this)->hasLocalName(name);
diff --git a/Source/core/dom/Element.idl b/Source/core/dom/Element.idl
index db0aef0..29954ca 100644
--- a/Source/core/dom/Element.idl
+++ b/Source/core/dom/Element.idl
@@ -100,10 +100,15 @@
     // WebKit extension, pending specification.
     [RaisesException] boolean webkitMatchesSelector([Default=Undefined] optional DOMString selectors);
 
-    // ShadowAware API
-    [Reflect=pseudo, ImplementedAs=pseudo, PerWorldBindings] attribute DOMString webkitPseudo;
-    [ImplementedAs=createShadowRoot, RaisesException] ShadowRoot webkitCreateShadowRoot();
-    [ImplementedAs=shadowRoot, PerWorldBindings] readonly attribute ShadowRoot webkitShadowRoot;
+    // Shadow DOM API
+    [EnabledAtRuntime=ShadowDOM, Reflect, PerWorldBindings] attribute DOMString pseudo;
+    [EnabledAtRuntime=ShadowDOM, RaisesException] ShadowRoot createShadowRoot();
+    [EnabledAtRuntime=ShadowDOM, PerWorldBindings] readonly attribute ShadowRoot shadowRoot;
+
+    // To-be-deprecated prefixed Shadow DOM API
+    [Reflect=pseudo, ImplementedAs=pseudo, PerWorldBindings, MeasureAs=ShadowDOMPrefixedPseudo] attribute DOMString webkitPseudo;
+    [ImplementedAs=createShadowRoot, RaisesException, MeasureAs=ShadowDOMPrefixedCreateShadowRoot] ShadowRoot webkitCreateShadowRoot();
+    [ImplementedAs=shadowRoot, PerWorldBindings, MeasureAs=ShadowDOMPrefixedShadowRoot] readonly attribute ShadowRoot webkitShadowRoot;
 
     // CSSOM View Module API
     ClientRectList getClientRects();
diff --git a/Source/core/dom/ElementRareData.h b/Source/core/dom/ElementRareData.h
index 117e93a..e14dacb 100644
--- a/Source/core/dom/ElementRareData.h
+++ b/Source/core/dom/ElementRareData.h
@@ -48,7 +48,7 @@
 
     void resetComputedStyle();
     void resetDynamicRestyleObservations();
-    
+
     short tabIndex() const { return m_tabIndex; }
     void setTabIndexExplicitly(short index) { m_tabIndex = index; m_tabIndexWasSetExplicitly = true; }
     bool tabIndexSetExplicitly() const { return m_tabIndexWasSetExplicitly; }
diff --git a/Source/core/dom/Event.h b/Source/core/dom/Event.h
index 82e402d..7875b1e 100644
--- a/Source/core/dom/Event.h
+++ b/Source/core/dom/Event.h
@@ -39,18 +39,18 @@
 
 struct EventInit {
     EventInit();
-     
+
     bool bubbles;
     bool cancelable;
 };
 
 class Event : public ScriptWrappable, public RefCounted<Event> {
 public:
-    enum PhaseType { 
+    enum PhaseType {
         NONE                = 0,
-        CAPTURING_PHASE     = 1, 
+        CAPTURING_PHASE     = 1,
         AT_TARGET           = 2,
-        BUBBLING_PHASE      = 3 
+        BUBBLING_PHASE      = 3
     };
 
     enum EventType {
@@ -92,7 +92,7 @@
 
     const AtomicString& type() const { return m_type; }
     void setType(const AtomicString& type) { m_type = type; }
-    
+
     EventTarget* target() const { return m_target.get(); }
     void setTarget(PassRefPtr<EventTarget>);
 
@@ -108,7 +108,7 @@
 
     void stopPropagation() { m_propagationStopped = true; }
     void stopImmediatePropagation() { m_immediatePropagationStopped = true; }
-    
+
     // IE Extensions
     EventTarget* srcElement() const { return target(); } // MSIE extension - "the object that fired the event"
 
diff --git a/Source/core/dom/Event.idl b/Source/core/dom/Event.idl
index 680b038..74af6e1 100644
--- a/Source/core/dom/Event.idl
+++ b/Source/core/dom/Event.idl
@@ -22,7 +22,7 @@
 [
     CustomToV8,
     ConstructorTemplate=Event
-    
+
 ] interface Event {
 
     // DOM PhaseType
@@ -59,8 +59,8 @@
 
     void               stopPropagation();
     void               preventDefault();
-     void initEvent([Default=Undefined] optional DOMString eventTypeArg, 
-                                  [Default=Undefined] optional boolean canBubbleArg, 
+     void initEvent([Default=Undefined] optional DOMString eventTypeArg,
+                                  [Default=Undefined] optional boolean canBubbleArg,
                                   [Default=Undefined] optional boolean cancelableArg);
 
     // DOM Level 3 Additions.
@@ -72,7 +72,7 @@
              attribute boolean          returnValue;
              attribute boolean          cancelBubble;
 
-    [EnabledAtRuntime=experimentalShadowDOM] readonly attribute NodeList path;
+    [EnabledAtRuntime=ShadowDOM] readonly attribute NodeList path;
 
     [Custom] readonly attribute Clipboard        clipboardData;
 };
diff --git a/Source/core/dom/EventContext.cpp b/Source/core/dom/EventContext.cpp
index dee63c1..13bf7a8 100644
--- a/Source/core/dom/EventContext.cpp
+++ b/Source/core/dom/EventContext.cpp
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  */
 
diff --git a/Source/core/dom/EventContext.h b/Source/core/dom/EventContext.h
index ea8961b..4d15ece 100644
--- a/Source/core/dom/EventContext.h
+++ b/Source/core/dom/EventContext.h
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  */
 
diff --git a/Source/core/dom/EventListener.h b/Source/core/dom/EventListener.h
index 768a0c3..33c4a34 100644
--- a/Source/core/dom/EventListener.h
+++ b/Source/core/dom/EventListener.h
@@ -32,8 +32,8 @@
     class EventListener : public RefCounted<EventListener> {
     public:
         enum Type {
-            JSEventListenerType, 
-            ImageEventListenerType, 
+            JSEventListenerType,
+            ImageEventListenerType,
             ObjCEventListenerType,
             CPPEventListenerType,
             ConditionEventListenerType,
@@ -59,7 +59,7 @@
 
     private:
         virtual bool virtualisAttribute() const { return false; }
-        
+
         Type m_type;
     };
 
diff --git a/Source/core/dom/EventQueue.h b/Source/core/dom/EventQueue.h
index 513bf36..770ae79 100644
--- a/Source/core/dom/EventQueue.h
+++ b/Source/core/dom/EventQueue.h
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  */
 
diff --git a/Source/core/dom/EventRetargeter.cpp b/Source/core/dom/EventRetargeter.cpp
index 153ada7..6a9dac1 100644
--- a/Source/core/dom/EventRetargeter.cpp
+++ b/Source/core/dom/EventRetargeter.cpp
@@ -115,7 +115,7 @@
 
 void EventRetargeter::calculateAdjustedEventPathForEachNode(EventPath& eventPath)
 {
-    if (!RuntimeEnabledFeatures::experimentalShadowDOMEnabled())
+    if (!RuntimeEnabledFeatures::shadowDOMEnabled())
         return;
     TreeScope* lastScope = 0;
     size_t eventPathSize = eventPath.size();
diff --git a/Source/core/dom/EventTarget.cpp b/Source/core/dom/EventTarget.cpp
index f2aa211..d318f66 100644
--- a/Source/core/dom/EventTarget.cpp
+++ b/Source/core/dom/EventTarget.cpp
@@ -25,7 +25,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  */
 
@@ -218,7 +218,7 @@
 
     return !event->defaultPrevented();
 }
-        
+
 void EventTarget::fireEventListeners(Event* event, EventTargetData* d, EventListenerVector& entry)
 {
     RefPtr<EventTarget> protect = this;
diff --git a/Source/core/dom/EventTarget.h b/Source/core/dom/EventTarget.h
index 5b736ed..a0c3a0e 100644
--- a/Source/core/dom/EventTarget.h
+++ b/Source/core/dom/EventTarget.h
@@ -25,7 +25,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  */
 
@@ -129,14 +129,14 @@
 
     protected:
         virtual ~EventTarget();
-        
+
         virtual EventTargetData* eventTargetData() = 0;
         virtual EventTargetData* ensureEventTargetData() = 0;
 
     private:
         virtual void refEventTarget() = 0;
         virtual void derefEventTarget() = 0;
-        
+
         void fireEventListeners(Event*, EventTargetData*, EventListenerVector&);
 
         bool clearAttributeEventListener(const AtomicString& eventType, DOMWrapperWorld* isolatedWorld);
diff --git a/Source/core/dom/EventTarget.idl b/Source/core/dom/EventTarget.idl
index d711cd7..7c87036 100644
--- a/Source/core/dom/EventTarget.idl
+++ b/Source/core/dom/EventTarget.idl
@@ -22,10 +22,10 @@
     CustomToV8,
     DoNotGenerateWrap
 ] interface EventTarget {
-    void addEventListener(DOMString type, 
+    void addEventListener(DOMString type,
                           EventListener listener,
                           optional boolean useCapture);
-    void removeEventListener(DOMString type, 
+    void removeEventListener(DOMString type,
                              EventListener listener,
                              optional boolean useCapture);
     [RaisesException] boolean dispatchEvent(Event event);
diff --git a/Source/core/dom/FocusEvent.cpp b/Source/core/dom/FocusEvent.cpp
index e839fe7..6d9569d 100644
--- a/Source/core/dom/FocusEvent.cpp
+++ b/Source/core/dom/FocusEvent.cpp
@@ -53,7 +53,7 @@
     ScriptWrappable::init(this);
 }
 
-FocusEvent::FocusEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<AbstractView> view, int detail, PassRefPtr<EventTarget> relatedTarget)
+FocusEvent::FocusEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<AbstractView> view, int detail, EventTarget* relatedTarget)
     : UIEvent(type, canBubble, cancelable, view, detail)
     , m_relatedTarget(relatedTarget)
 {
diff --git a/Source/core/dom/FocusEvent.h b/Source/core/dom/FocusEvent.h
index 65dbfd5..f96c076 100644
--- a/Source/core/dom/FocusEvent.h
+++ b/Source/core/dom/FocusEvent.h
@@ -46,7 +46,7 @@
         return adoptRef(new FocusEvent);
     }
 
-    static PassRefPtr<FocusEvent> create(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<AbstractView> view, int detail, PassRefPtr<EventTarget> relatedTarget)
+    static PassRefPtr<FocusEvent> create(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<AbstractView> view, int detail, EventTarget* relatedTarget)
     {
         return adoptRef(new FocusEvent(type, canBubble, cancelable, view, detail, relatedTarget));
     }
@@ -57,14 +57,14 @@
     }
 
     EventTarget* relatedTarget() const { return m_relatedTarget.get(); }
-    void setRelatedTarget(PassRefPtr<EventTarget> relatedTarget) { m_relatedTarget = relatedTarget; }
+    void setRelatedTarget(EventTarget* relatedTarget) { m_relatedTarget = relatedTarget; }
 
     virtual const AtomicString& interfaceName() const;
     virtual bool isFocusEvent() const;
 
 private:
     FocusEvent();
-    FocusEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<AbstractView>, int, PassRefPtr<EventTarget>);
+    FocusEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<AbstractView>, int, EventTarget*);
     FocusEvent(const AtomicString& type, const FocusEventInit&);
 
     RefPtr<EventTarget> m_relatedTarget;
diff --git a/Source/core/dom/GenericEventQueue.cpp b/Source/core/dom/GenericEventQueue.cpp
index ba6932a..b002fd6 100644
--- a/Source/core/dom/GenericEventQueue.cpp
+++ b/Source/core/dom/GenericEventQueue.cpp
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #include "config.h"
diff --git a/Source/core/dom/GenericEventQueue.h b/Source/core/dom/GenericEventQueue.h
index 5f4e426..a4d1c20 100644
--- a/Source/core/dom/GenericEventQueue.h
+++ b/Source/core/dom/GenericEventQueue.h
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #ifndef GenericEventQueue_h
diff --git a/Source/core/dom/HashChangeEvent.idl b/Source/core/dom/HashChangeEvent.idl
index 2408afe..470a208 100644
--- a/Source/core/dom/HashChangeEvent.idl
+++ b/Source/core/dom/HashChangeEvent.idl
@@ -21,11 +21,11 @@
 [
     ConstructorTemplate=Event
 ] interface HashChangeEvent : Event {
-    void initHashChangeEvent([Default=Undefined] optional DOMString type, 
-                             [Default=Undefined] optional boolean canBubble, 
-                             [Default=Undefined] optional boolean cancelable, 
-                             [Default=Undefined] optional DOMString oldURL, 
-                             [Default=Undefined] optional DOMString newURL); 
+    void initHashChangeEvent([Default=Undefined] optional DOMString type,
+                             [Default=Undefined] optional boolean canBubble,
+                             [Default=Undefined] optional boolean cancelable,
+                             [Default=Undefined] optional DOMString oldURL,
+                             [Default=Undefined] optional DOMString newURL);
     [InitializedByEventConstructor] readonly attribute DOMString oldURL;
     [InitializedByEventConstructor] readonly attribute DOMString newURL;
 };
diff --git a/Source/core/dom/IconURL.h b/Source/core/dom/IconURL.h
index 7b689bb..e352b7f 100644
--- a/Source/core/dom/IconURL.h
+++ b/Source/core/dom/IconURL.h
@@ -69,7 +69,7 @@
         , m_isDefaultIcon(false)
     {
     }
-    
+
     static IconURL defaultIconURL(const KURL&, IconType);
 };
 
diff --git a/Source/core/dom/IdTargetObserverRegistry.cpp b/Source/core/dom/IdTargetObserverRegistry.cpp
index 2efc7fd..19d297a 100644
--- a/Source/core/dom/IdTargetObserverRegistry.cpp
+++ b/Source/core/dom/IdTargetObserverRegistry.cpp
@@ -39,7 +39,7 @@
 {
     if (id.isEmpty())
         return;
-    
+
     IdToObserverSetMap::AddResult result = m_registry.add(id.impl(), nullptr);
     if (result.isNewEntry)
         result.iterator->value = adoptPtr(new ObserverSet());
diff --git a/Source/core/dom/KeyboardEvent.h b/Source/core/dom/KeyboardEvent.h
index acb0d32..02c7e34 100644
--- a/Source/core/dom/KeyboardEvent.h
+++ b/Source/core/dom/KeyboardEvent.h
@@ -52,7 +52,7 @@
         DOMKeyLocationRight         = 0x02,
         DOMKeyLocationNumpad        = 0x03
     };
-        
+
     static PassRefPtr<KeyboardEvent> create()
     {
         return adoptRef(new KeyboardEvent);
@@ -77,18 +77,18 @@
     }
 
     virtual ~KeyboardEvent();
-    
+
     void initKeyboardEvent(const AtomicString& type, bool canBubble, bool cancelable, AbstractView*,
         const String& keyIdentifier, unsigned keyLocation,
         bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, bool altGraphKey = false);
-    
+
     const String& keyIdentifier() const { return m_keyIdentifier; }
     unsigned keyLocation() const { return m_keyLocation; }
 
     bool getModifierState(const String& keyIdentifier) const;
 
     bool altGraphKey() const { return m_altGraphKey; }
-    
+
     const PlatformKeyboardEvent* keyEvent() const { return m_keyEvent.get(); }
 
     int keyCode() const; // key code for keydown and keyup, character for keypress
diff --git a/Source/core/dom/KeyboardEvent.idl b/Source/core/dom/KeyboardEvent.idl
index 134cb59..cda219f 100644
--- a/Source/core/dom/KeyboardEvent.idl
+++ b/Source/core/dom/KeyboardEvent.idl
@@ -31,10 +31,10 @@
     readonly attribute boolean          altGraphKey;
 
     // FIXME: this does not match the version in the DOM spec.
-    void initKeyboardEvent([Default=Undefined] optional DOMString type, 
-                           [Default=Undefined] optional boolean canBubble, 
-                           [Default=Undefined] optional boolean cancelable, 
-                           [Default=Undefined] optional Window view, 
+    void initKeyboardEvent([Default=Undefined] optional DOMString type,
+                           [Default=Undefined] optional boolean canBubble,
+                           [Default=Undefined] optional boolean cancelable,
+                           [Default=Undefined] optional Window view,
                            [Default=Undefined] optional DOMString keyIdentifier,
                            [Default=Undefined] optional unsigned long keyLocation,
                            [Default=Undefined] optional boolean ctrlKey,
diff --git a/Source/core/dom/MessageChannel.cpp b/Source/core/dom/MessageChannel.cpp
index 4f2b284..4c65fac 100644
--- a/Source/core/dom/MessageChannel.cpp
+++ b/Source/core/dom/MessageChannel.cpp
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  */
 
diff --git a/Source/core/dom/MessageChannel.h b/Source/core/dom/MessageChannel.h
index 64b213c..507825b 100644
--- a/Source/core/dom/MessageChannel.h
+++ b/Source/core/dom/MessageChannel.h
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  */
 
diff --git a/Source/core/dom/MessageChannel.idl b/Source/core/dom/MessageChannel.idl
index c380c44..3d62729 100644
--- a/Source/core/dom/MessageChannel.idl
+++ b/Source/core/dom/MessageChannel.idl
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  */
 
diff --git a/Source/core/dom/MessageEvent.cpp b/Source/core/dom/MessageEvent.cpp
index bec2624..ce6e8fa 100644
--- a/Source/core/dom/MessageEvent.cpp
+++ b/Source/core/dom/MessageEvent.cpp
@@ -21,7 +21,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  */
 
diff --git a/Source/core/dom/MessageEvent.h b/Source/core/dom/MessageEvent.h
index d68bac8..7f54232 100644
--- a/Source/core/dom/MessageEvent.h
+++ b/Source/core/dom/MessageEvent.h
@@ -21,7 +21,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  */
 
diff --git a/Source/core/dom/MessageEvent.idl b/Source/core/dom/MessageEvent.idl
index 7b5fec3..3bc8866 100644
--- a/Source/core/dom/MessageEvent.idl
+++ b/Source/core/dom/MessageEvent.idl
@@ -21,7 +21,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  */
 
@@ -35,13 +35,13 @@
     [InitializedByEventConstructor, CustomGetter] readonly attribute any data;
     [InitializedByEventConstructor] readonly attribute MessagePort[] ports;
 
-    [Custom] void initMessageEvent([Default=Undefined] optional DOMString typeArg, 
-                                   [Default=Undefined] optional boolean canBubbleArg, 
-                                   [Default=Undefined] optional boolean cancelableArg, 
-                                   [Default=Undefined] optional any dataArg, 
-                                   [Default=Undefined] optional DOMString originArg, 
-                                   [Default=Undefined] optional DOMString lastEventIdArg, 
-                                   [Default=Undefined] optional Window sourceArg, 
+    [Custom] void initMessageEvent([Default=Undefined] optional DOMString typeArg,
+                                   [Default=Undefined] optional boolean canBubbleArg,
+                                   [Default=Undefined] optional boolean cancelableArg,
+                                   [Default=Undefined] optional any dataArg,
+                                   [Default=Undefined] optional DOMString originArg,
+                                   [Default=Undefined] optional DOMString lastEventIdArg,
+                                   [Default=Undefined] optional Window sourceArg,
                                    [Default=Undefined] optional Array messagePorts);
 
     [Custom] void webkitInitMessageEvent([Default=Undefined] optional DOMString typeArg,
diff --git a/Source/core/dom/MessagePort.h b/Source/core/dom/MessagePort.h
index f5f63c4..337e225 100644
--- a/Source/core/dom/MessagePort.h
+++ b/Source/core/dom/MessagePort.h
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  */
 
diff --git a/Source/core/dom/MessagePort.idl b/Source/core/dom/MessagePort.idl
index 18e7284..aa6ddb3 100644
--- a/Source/core/dom/MessagePort.idl
+++ b/Source/core/dom/MessagePort.idl
@@ -21,7 +21,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  */
 
diff --git a/Source/core/dom/MouseEvent.cpp b/Source/core/dom/MouseEvent.cpp
index e11d1d8..2d5f328 100644
--- a/Source/core/dom/MouseEvent.cpp
+++ b/Source/core/dom/MouseEvent.cpp
@@ -181,7 +181,7 @@
 int MouseEvent::which() const
 {
     // For the DOM, the return values for left, middle and right mouse buttons are 0, 1, 2, respectively.
-    // For the Netscape "which" property, the return values for left, middle and right mouse buttons are 1, 2, 3, respectively. 
+    // For the Netscape "which" property, the return values for left, middle and right mouse buttons are 1, 2, 3, respectively.
     // So we must add 1.
     if (!m_buttonDown)
         return 0;
diff --git a/Source/core/dom/MouseEvent.idl b/Source/core/dom/MouseEvent.idl
index 516cb1e..92c3bfb 100644
--- a/Source/core/dom/MouseEvent.idl
+++ b/Source/core/dom/MouseEvent.idl
@@ -32,21 +32,21 @@
     [InitializedByEventConstructor] readonly attribute EventTarget      relatedTarget;
                                     readonly attribute long             webkitMovementX;
                                     readonly attribute long             webkitMovementY;
-    
-     void initMouseEvent([Default=Undefined] optional DOMString type, 
-                                       [Default=Undefined] optional boolean canBubble, 
-                                       [Default=Undefined] optional boolean cancelable, 
-                                       [Default=Undefined] optional Window view, 
-                                       [Default=Undefined] optional long detail, 
-                                       [Default=Undefined] optional long screenX, 
-                                       [Default=Undefined] optional long screenY, 
-                                       [Default=Undefined] optional long clientX, 
-                                       [Default=Undefined] optional long clientY, 
-                                       [Default=Undefined] optional boolean ctrlKey, 
-                                       [Default=Undefined] optional boolean altKey, 
-                                       [Default=Undefined] optional boolean shiftKey, 
-                                       [Default=Undefined] optional boolean metaKey, 
-                                       [Default=Undefined] optional unsigned short button, 
+
+     void initMouseEvent([Default=Undefined] optional DOMString type,
+                                       [Default=Undefined] optional boolean canBubble,
+                                       [Default=Undefined] optional boolean cancelable,
+                                       [Default=Undefined] optional Window view,
+                                       [Default=Undefined] optional long detail,
+                                       [Default=Undefined] optional long screenX,
+                                       [Default=Undefined] optional long screenY,
+                                       [Default=Undefined] optional long clientX,
+                                       [Default=Undefined] optional long clientY,
+                                       [Default=Undefined] optional boolean ctrlKey,
+                                       [Default=Undefined] optional boolean altKey,
+                                       [Default=Undefined] optional boolean shiftKey,
+                                       [Default=Undefined] optional boolean metaKey,
+                                       [Default=Undefined] optional unsigned short button,
                                        [Default=Undefined] optional EventTarget relatedTarget);
 
     // extensions
diff --git a/Source/core/dom/MutationEvent.idl b/Source/core/dom/MutationEvent.idl
index 16c183e..0aae4e3 100644
--- a/Source/core/dom/MutationEvent.idl
+++ b/Source/core/dom/MutationEvent.idl
@@ -31,13 +31,13 @@
     readonly attribute DOMString      attrName;
     readonly attribute unsigned short attrChange;
 
-     void initMutationEvent([Default=Undefined] optional DOMString type, 
-                                          [Default=Undefined] optional boolean canBubble, 
-                                          [Default=Undefined] optional boolean cancelable, 
-                                          [Default=Undefined] optional Node relatedNode, 
-                                          [Default=Undefined] optional DOMString prevValue, 
-                                          [Default=Undefined] optional DOMString newValue, 
-                                          [Default=Undefined] optional DOMString attrName, 
+     void initMutationEvent([Default=Undefined] optional DOMString type,
+                                          [Default=Undefined] optional boolean canBubble,
+                                          [Default=Undefined] optional boolean cancelable,
+                                          [Default=Undefined] optional Node relatedNode,
+                                          [Default=Undefined] optional DOMString prevValue,
+                                          [Default=Undefined] optional DOMString newValue,
+                                          [Default=Undefined] optional DOMString attrName,
                                           [Default=Undefined] optional unsigned short attrChange);
 
 };
diff --git a/Source/core/dom/NameNodeList.cpp b/Source/core/dom/NameNodeList.cpp
index c4648c0..69634c9 100644
--- a/Source/core/dom/NameNodeList.cpp
+++ b/Source/core/dom/NameNodeList.cpp
@@ -40,7 +40,7 @@
 NameNodeList::~NameNodeList()
 {
     ownerNode()->nodeLists()->removeCacheWithAtomicName(this, NameNodeListType, m_name);
-} 
+}
 
 bool NameNodeList::nodeMatches(Element* testNode) const
 {
diff --git a/Source/core/dom/NamedNodeMap.idl b/Source/core/dom/NamedNodeMap.idl
index d0bd9bd..698a035 100644
--- a/Source/core/dom/NamedNodeMap.idl
+++ b/Source/core/dom/NamedNodeMap.idl
@@ -30,14 +30,14 @@
     [RaisesException, DeliverCustomElementCallbacks] Node removeNamedItem([Default=Undefined] optional DOMString name);
 
     getter Node item([Default=Undefined] optional unsigned long index);
-    
+
     readonly attribute unsigned long length;
 
 
     // Introduced in DOM Level 2:
 
     // FIXME: the implementation does take an exceptioncode parameter.
-    /*[RaisesException]*/ Node getNamedItemNS([TreatNullAs=NullString,Default=Undefined] optional DOMString namespaceURI, 
+    /*[RaisesException]*/ Node getNamedItemNS([TreatNullAs=NullString,Default=Undefined] optional DOMString namespaceURI,
                                               [Default=Undefined] optional DOMString localName);
 
     [RaisesException, DeliverCustomElementCallbacks] Node setNamedItemNS([Default=Undefined] optional Node node);
diff --git a/Source/core/dom/NamedNodesCollection.cpp b/Source/core/dom/NamedNodesCollection.cpp
index 9112f03..fb6b772 100644
--- a/Source/core/dom/NamedNodesCollection.cpp
+++ b/Source/core/dom/NamedNodesCollection.cpp
@@ -1,10 +1,10 @@
 // Copyright (c) 2008, Google Inc.
 // All rights reserved.
-// 
+//
 // Redistribution and use in source and binary forms, with or without
 // modification, are permitted provided that the following conditions are
 // met:
-// 
+//
 //     * Redistributions of source code must retain the above copyright
 // notice, this list of conditions and the following disclaimer.
 //     * Redistributions in binary form must reproduce the above
@@ -14,7 +14,7 @@
 //     * Neither the name of Google Inc. nor the names of its
 // contributors may be used to endorse or promote products derived from
 // this software without specific prior written permission.
-// 
+//
 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
diff --git a/Source/core/dom/NamedNodesCollection.h b/Source/core/dom/NamedNodesCollection.h
index 54839b5..0b4199b 100644
--- a/Source/core/dom/NamedNodesCollection.h
+++ b/Source/core/dom/NamedNodesCollection.h
@@ -1,10 +1,10 @@
 /*
 * Copyright (C) 2009 Google Inc. All rights reserved.
-* 
+*
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
-* 
+*
 *     * Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above
@@ -14,7 +14,7 @@
 *     * Neither the name of Google Inc. nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
-* 
+*
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
diff --git a/Source/core/dom/Node.cpp b/Source/core/dom/Node.cpp
index a8e04bd..56d0a7f 100644
--- a/Source/core/dom/Node.cpp
+++ b/Source/core/dom/Node.cpp
@@ -47,7 +47,6 @@
 #include "core/dom/EventNames.h"
 #include "core/dom/ExceptionCode.h"
 #include "core/dom/ExceptionCodePlaceholder.h"
-#include "core/dom/FocusEvent.h"
 #include "core/dom/GestureEvent.h"
 #include "core/dom/KeyboardEvent.h"
 #include "core/dom/LiveNodeList.h"
@@ -265,16 +264,16 @@
     bool fl1 = s1 && s1->hasPseudoStyle(FIRST_LETTER);
     EDisplay display2 = s2 ? s2->display() : NONE;
     bool fl2 = s2 && s2->hasPseudoStyle(FIRST_LETTER);
-    
+
     // We just detach if a renderer acquires or loses a column-span, since spanning elements
     // typically won't contain much content.
     bool colSpan1 = s1 && s1->columnSpan();
     bool colSpan2 = s2 && s2->columnSpan();
-    
+
     bool specifiesColumns1 = s1 && (!s1->hasAutoColumnCount() || !s1->hasAutoColumnWidth());
     bool specifiesColumns2 = s2 && (!s2->hasAutoColumnCount() || !s2->hasAutoColumnWidth());
 
-    if (display1 != display2 || fl1 != fl2 || colSpan1 != colSpan2 
+    if (display1 != display2 || fl1 != fl2 || colSpan1 != colSpan2
         || (specifiesColumns1 != specifiesColumns2 && doc->settings()->regionBasedColumnsEnabled())
         || (s1 && s2 && !s1->contentDataEquivalent(s2)))
         ch = Detach;
@@ -717,9 +716,9 @@
         return renderer()->absoluteBoundingBoxRect();
     return LayoutRect();
 }
-    
+
 LayoutRect Node::renderRect(bool* isReplaced)
-{    
+{
     RenderObject* hitRenderer = this->renderer();
     ASSERT(hitRenderer);
     RenderObject* renderer = hitRenderer;
@@ -730,7 +729,7 @@
         }
         renderer = renderer->parent();
     }
-    return LayoutRect();    
+    return LayoutRect();
 }
 
 bool Node::hasNonEmptyBoundingBox() const
@@ -1266,7 +1265,7 @@
         if (AXObjectCache* cache = document()->existingAXObjectCache())
             return const_cast<Element*>(cache->rootAXEditableElement(this));
     }
-    
+
     return rootEditableElement();
 }
 
@@ -1367,47 +1366,47 @@
 {
     if (!other)
         return false;
-    
+
     NodeType nodeType = this->nodeType();
     if (nodeType != other->nodeType())
         return false;
-    
+
     if (nodeName() != other->nodeName())
         return false;
-    
+
     if (localName() != other->localName())
         return false;
-    
+
     if (namespaceURI() != other->namespaceURI())
         return false;
-    
+
     if (prefix() != other->prefix())
         return false;
-    
+
     if (nodeValue() != other->nodeValue())
         return false;
-    
+
     if (isElementNode() && !toElement(this)->hasEquivalentAttributes(toElement(other)))
         return false;
-    
+
     Node* child = firstChild();
     Node* otherChild = other->firstChild();
-    
+
     while (child) {
         if (!child->isEqualNode(otherChild))
             return false;
-        
+
         child = child->nextSibling();
         otherChild = otherChild->nextSibling();
     }
-    
+
     if (otherChild)
         return false;
-    
+
     if (nodeType == DOCUMENT_TYPE_NODE) {
         const DocumentType* documentTypeThis = static_cast<const DocumentType*>(this);
         const DocumentType* documentTypeOther = static_cast<const DocumentType*>(other);
-        
+
         if (documentTypeThis->publicId() != documentTypeOther->publicId())
             return false;
 
@@ -1419,7 +1418,7 @@
 
         // FIXME: We don't compare entities or notations because currently both are always empty.
     }
-    
+
     return true;
 }
 
@@ -1430,14 +1429,14 @@
     switch (nodeType()) {
         case ELEMENT_NODE: {
             const Element* elem = toElement(this);
-            
+
             if (elem->prefix().isNull())
                 return elem->namespaceURI() == namespaceURI;
 
             if (elem->hasAttributes()) {
                 for (unsigned i = 0; i < elem->attributeCount(); i++) {
                     const Attribute* attr = elem->attributeItem(i);
-                    
+
                     if (attr->localName() == xmlnsAtom)
                         return attr->value() == namespaceURI;
                 }
@@ -1474,10 +1473,10 @@
 {
     // Implemented according to
     // http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/namespaces-algorithms.html#lookupNamespacePrefixAlgo
-    
+
     if (namespaceURI.isEmpty())
         return String();
-    
+
     switch (nodeType()) {
         case ELEMENT_NODE:
             return lookupNamespacePrefix(namespaceURI, toElement(this));
@@ -1507,30 +1506,30 @@
 {
     // Implemented according to
     // http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/namespaces-algorithms.html#lookupNamespaceURIAlgo
-    
+
     if (!prefix.isNull() && prefix.isEmpty())
         return String();
-    
+
     switch (nodeType()) {
         case ELEMENT_NODE: {
             const Element *elem = toElement(this);
-            
+
             if (!elem->namespaceURI().isNull() && elem->prefix() == prefix)
                 return elem->namespaceURI();
-            
+
             if (elem->hasAttributes()) {
                 for (unsigned i = 0; i < elem->attributeCount(); i++) {
                     const Attribute* attr = elem->attributeItem(i);
-                    
+
                     if (attr->prefix() == xmlnsAtom && attr->localName() == prefix) {
                         if (!attr->value().isEmpty())
                             return attr->value();
-                        
+
                         return String();
                     } else if (attr->localName() == xmlnsAtom && prefix.isNull()) {
                         if (!attr->value().isEmpty())
                             return attr->value();
-                        
+
                         return String();
                     }
                 }
@@ -1550,7 +1549,7 @@
             return String();
         case ATTRIBUTE_NODE: {
             const Attr *attr = static_cast<const Attr *>(this);
-            
+
             if (attr->ownerElement())
                 return attr->ownerElement()->lookupNamespaceURI(prefix);
             else
@@ -1567,22 +1566,22 @@
 {
     if (_namespaceURI.isNull())
         return String();
-            
+
     if (originalElement->lookupNamespaceURI(prefix()) == _namespaceURI)
         return prefix();
-    
+
     ASSERT(isElementNode());
     const Element* thisElement = toElement(this);
     if (thisElement->hasAttributes()) {
         for (unsigned i = 0; i < thisElement->attributeCount(); i++) {
             const Attribute* attr = thisElement->attributeItem(i);
-            
+
             if (attr->prefix() == xmlnsAtom && attr->value() == _namespaceURI
                     && originalElement->lookupNamespaceURI(attr->localName()) == _namespaceURI)
                 return attr->localName();
         }
     }
-    
+
     if (Element* ancestor = ancestorElement())
         return ancestor->lookupNamespacePrefix(_namespaceURI, originalElement);
     return String();
@@ -1602,7 +1601,7 @@
         isNullString = false;
         content.append(static_cast<const ProcessingInstruction*>(node)->data());
         break;
-    
+
     case Node::ELEMENT_NODE:
         if (node->hasTagName(brTag) && convertBRsToNewlines) {
             isNullString = false;
@@ -1638,7 +1637,7 @@
 }
 
 void Node::setTextContent(const String& text, ExceptionCode& ec)
-{           
+{
     switch (nodeType()) {
         case TEXT_NODE:
         case CDATA_SECTION_NODE:
@@ -1695,13 +1694,13 @@
 
     if (otherNode == this)
         return DOCUMENT_POSITION_EQUIVALENT;
-    
+
     const Attr* attr1 = nodeType() == ATTRIBUTE_NODE ? toAttr(this) : 0;
     const Attr* attr2 = otherNode->nodeType() == ATTRIBUTE_NODE ? toAttr(otherNode) : 0;
-    
+
     const Node* start1 = attr1 ? attr1->ownerElement() : this;
     const Node* start2 = attr2 ? attr2->ownerElement() : otherNode;
-    
+
     // If either of start1 or start2 is null, then we are disconnected, since one of the nodes is
     // an orphaned attribute node.
     if (!start1 || !start2) {
@@ -1715,17 +1714,17 @@
         chain1.append(attr1);
     if (attr2)
         chain2.append(attr2);
-    
+
     if (attr1 && attr2 && start1 == start2 && start1) {
         // We are comparing two attributes on the same node. Crawl our attribute map and see which one we hit first.
         const Element* owner1 = attr1->ownerElement();
         owner1->synchronizeAllAttributes();
         unsigned length = owner1->attributeCount();
         for (unsigned i = 0; i < length; ++i) {
-            // If neither of the two determining nodes is a child node and nodeType is the same for both determining nodes, then an 
+            // If neither of the two determining nodes is a child node and nodeType is the same for both determining nodes, then an
             // implementation-dependent order between the determining nodes is returned. This order is stable as long as no nodes of
-            // the same nodeType are inserted into or removed from the direct container. This would be the case, for example, 
-            // when comparing two attributes of the same element, and inserting or removing additional attributes might change 
+            // the same nodeType are inserted into or removed from the direct container. This would be the case, for example,
+            // when comparing two attributes of the same element, and inserting or removing additional attributes might change
             // the order between existing attributes.
             const Attribute* attribute = owner1->attributeItem(i);
             if (attr1->qualifiedName() == attribute->name())
@@ -1733,7 +1732,7 @@
             if (attr2->qualifiedName() == attribute->name())
                 return DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | DOCUMENT_POSITION_PRECEDING;
         }
-        
+
         ASSERT_NOT_REACHED();
         return DOCUMENT_POSITION_DISCONNECTED;
     }
@@ -1802,10 +1801,10 @@
             return DOCUMENT_POSITION_PRECEDING | connection;
         }
     }
-    
+
     // There was no difference between the two parent chains, i.e., one was a subset of the other.  The shorter
     // chain is the ancestor.
-    return index1 < index2 ? 
+    return index1 < index2 ?
                DOCUMENT_POSITION_FOLLOWING | DOCUMENT_POSITION_CONTAINED_BY | connection :
                DOCUMENT_POSITION_PRECEDING | DOCUMENT_POSITION_CONTAINS | connection;
 }
@@ -1815,7 +1814,7 @@
     // If there is a renderer, just ask it to do the conversion
     if (renderer())
         return renderer()->localToAbsolute(p, UseTransforms);
-    
+
     // Otherwise go up the tree looking for a renderer
     Element *parent = ancestorElement();
     if (parent)
@@ -2358,20 +2357,6 @@
     dispatchScopedEvent(MutationEvent::create(eventNames().DOMSubtreeModifiedEvent, true));
 }
 
-void Node::dispatchFocusInEvent(const AtomicString& eventType, PassRefPtr<Node> oldFocusedNode)
-{
-    ASSERT(!NoEventDispatchAssertion::isEventDispatchForbidden());
-    ASSERT(eventType == eventNames().focusinEvent || eventType == eventNames().DOMFocusInEvent);
-    dispatchScopedEventDispatchMediator(FocusInEventDispatchMediator::create(FocusEvent::create(eventType, true, false, document()->defaultView(), 0, oldFocusedNode)));
-}
-
-void Node::dispatchFocusOutEvent(const AtomicString& eventType, PassRefPtr<Node> newFocusedNode)
-{
-    ASSERT(!NoEventDispatchAssertion::isEventDispatchForbidden());
-    ASSERT(eventType == eventNames().focusoutEvent || eventType == eventNames().DOMFocusOutEvent);
-    dispatchScopedEventDispatchMediator(FocusOutEventDispatchMediator::create(FocusEvent::create(eventType, true, false, document()->defaultView(), 0, newFocusedNode)));
-}
-
 bool Node::dispatchDOMActivateEvent(int detail, PassRefPtr<Event> underlyingEvent)
 {
     ASSERT(!NoEventDispatchAssertion::isEventDispatchForbidden());
@@ -2426,18 +2411,6 @@
     return EventDispatcher::dispatchEvent(this, WheelEventDispatchMediator::create(event, document()->defaultView()));
 }
 
-void Node::dispatchFocusEvent(PassRefPtr<Node> oldFocusedNode, FocusDirection)
-{
-    RefPtr<FocusEvent> event = FocusEvent::create(eventNames().focusEvent, false, false, document()->defaultView(), 0, oldFocusedNode);
-    EventDispatcher::dispatchEvent(this, FocusEventDispatchMediator::create(event.release()));
-}
-
-void Node::dispatchBlurEvent(PassRefPtr<Node> newFocusedNode)
-{
-    RefPtr<FocusEvent> event = FocusEvent::create(eventNames().blurEvent, false, false, document()->defaultView(), 0, newFocusedNode);
-    EventDispatcher::dispatchEvent(this, BlurEventDispatchMediator::create(event.release()));
-}
-
 void Node::dispatchChangeEvent()
 {
     dispatchScopedEvent(Event::create(eventNames().changeEvent, true, false));
@@ -2495,7 +2468,7 @@
         Node* startNode = this;
         while (startNode && !startNode->renderer())
             startNode = startNode->parentOrShadowHostNode();
-        
+
         if (startNode && startNode->renderer())
             if (Frame* frame = document()->frame())
                 frame->eventHandler()->defaultWheelEventHandler(startNode, wheelEvent);
diff --git a/Source/core/dom/Node.h b/Source/core/dom/Node.h
index 45db9bc..24338a1 100644
--- a/Source/core/dom/Node.h
+++ b/Source/core/dom/Node.h
@@ -32,7 +32,6 @@
 #include "core/dom/TreeScope.h"
 #include "core/editing/EditingBoundary.h"
 #include "core/inspector/InspectorCounters.h"
-#include "core/page/FocusDirection.h"
 #include "core/platform/TreeShared.h"
 #include "core/platform/graphics/LayoutRect.h"
 #include "core/rendering/style/RenderStyleConstants.h"
@@ -166,7 +165,7 @@
     static bool isSupported(const String& feature, const String& version);
     static void dumpStatistics();
 
-    enum StyleChange { NoChange, NoInherit, Inherit, Detach, Force };    
+    enum StyleChange { NoChange, NoInherit, Inherit, Detach, Force };
     static StyleChange diff(const RenderStyle*, const RenderStyle*, Document*);
 
     virtual ~Node();
@@ -224,10 +223,10 @@
     String lookupPrefix(const AtomicString& namespaceURI) const;
     String lookupNamespaceURI(const String& prefix) const;
     String lookupNamespacePrefix(const AtomicString& namespaceURI, const Element* originalElement) const;
-    
+
     String textContent(bool convertBRsToNewlines = false) const;
     void setTextContent(const String&, ExceptionCode&);
-    
+
     Node* lastDescendant() const;
     Node* firstDescendant() const;
 
@@ -325,7 +324,7 @@
     // FIXME: These two functions belong in editing -- "atomic node" is an editing concept.
     Node* previousNodeConsideringAtomicNodes() const;
     Node* nextNodeConsideringAtomicNodes() const;
-    
+
     // Returns the next leaf node or 0 if there are no more.
     // Delivers leaf nodes as if the whole DOM tree were a linear chain of its leaf nodes.
     // Uses an editing-specific concept of what a leaf node is, and should probably be moved
@@ -480,11 +479,11 @@
 
     unsigned nodeIndex() const;
 
-    // Returns the DOM ownerDocument attribute. This method never returns NULL, except in the case 
-    // of (1) a Document node or (2) a DocumentType node that is not used with any Document yet. 
+    // Returns the DOM ownerDocument attribute. This method never returns NULL, except in the case
+    // of (1) a Document node or (2) a DocumentType node that is not used with any Document yet.
     Document* ownerDocument() const;
 
-    // Returns the document associated with this node. This method never returns NULL, except in the case 
+    // Returns the document associated with this node. This method never returns NULL, except in the case
     // of a DocumentType node that is not used with any Document yet. A Document node returns itself.
     Document* document() const
     {
@@ -499,8 +498,8 @@
 
     // Returns true if this node is associated with a document and is in its associated document's
     // node tree, false otherwise.
-    bool inDocument() const 
-    { 
+    bool inDocument() const
+    {
         ASSERT(documentInternal() || !getFlag(InDocumentFlag));
         return getFlag(InDocumentFlag);
     }
@@ -669,8 +668,6 @@
 
     void dispatchSubtreeModifiedEvent();
     bool dispatchDOMActivateEvent(int detail, PassRefPtr<Event> underlyingEvent);
-    void dispatchFocusInEvent(const AtomicString& eventType, PassRefPtr<Node> oldFocusedNode);
-    void dispatchFocusOutEvent(const AtomicString& eventType, PassRefPtr<Node> newFocusedNode);
 
     bool dispatchKeyEvent(const PlatformKeyboardEvent&);
     bool dispatchWheelEvent(const PlatformWheelEvent&);
@@ -681,8 +678,6 @@
     void dispatchSimulatedClick(Event* underlyingEvent, SimulatedClickMouseEventOptions = SendNoEvents, SimulatedClickVisualOptions = ShowPressedLook);
 
     virtual bool dispatchBeforeLoadEvent(const String& sourceURL);
-    virtual void dispatchFocusEvent(PassRefPtr<Node> oldFocusedNode, FocusDirection);
-    virtual void dispatchBlurEvent(PassRefPtr<Node> newFocusedNode);
     virtual void dispatchChangeEvent();
     virtual void dispatchInputEvent();
 
@@ -761,16 +756,16 @@
     // 3 bits remaining
 
     bool getFlag(NodeFlags mask) const { return m_nodeFlags & mask; }
-    void setFlag(bool f, NodeFlags mask) const { m_nodeFlags = (m_nodeFlags & ~mask) | (-(int32_t)f & mask); } 
-    void setFlag(NodeFlags mask) const { m_nodeFlags |= mask; } 
-    void clearFlag(NodeFlags mask) const { m_nodeFlags &= ~mask; } 
+    void setFlag(bool f, NodeFlags mask) const { m_nodeFlags = (m_nodeFlags & ~mask) | (-(int32_t)f & mask); }
+    void setFlag(NodeFlags mask) const { m_nodeFlags |= mask; }
+    void clearFlag(NodeFlags mask) const { m_nodeFlags &= ~mask; }
 
 protected:
-    enum ConstructionType { 
+    enum ConstructionType {
         CreateOther = DefaultNodeFlags,
         CreateText = DefaultNodeFlags | IsTextFlag,
-        CreateContainer = DefaultNodeFlags | IsContainerFlag, 
-        CreateElement = CreateContainer | IsElementFlag, 
+        CreateContainer = DefaultNodeFlags | IsContainerFlag,
+        CreateElement = CreateContainer | IsElementFlag,
         CreatePseudoElement =  CreateElement | InDocumentFlag,
         CreateShadowRoot = CreateContainer | IsDocumentFragmentFlag | IsInShadowTreeFlag,
         CreateDocumentFragment = CreateContainer | IsDocumentFragmentFlag,
@@ -800,7 +795,7 @@
     }
 
     virtual void didMoveToNewDocument(Document* oldDocument);
-    
+
     virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const { }
 
     bool hasRareData() const { return getFlag(HasRareDataFlag); }
diff --git a/Source/core/dom/Node.idl b/Source/core/dom/Node.idl
index 4ecd1d6..b14d4f7 100644
--- a/Source/core/dom/Node.idl
+++ b/Source/core/dom/Node.idl
@@ -61,7 +61,7 @@
     void               normalize();
 
     // Introduced in DOM Level 2:
-     boolean isSupported([Default=Undefined] optional DOMString feature, 
+     boolean isSupported([Default=Undefined] optional DOMString feature,
                                        [TreatNullAs=NullString,Default=Undefined] optional DOMString version);
 
     [TreatReturnedNullStringAs=Null, PerWorldBindings] readonly attribute DOMString        namespaceURI;
diff --git a/Source/core/dom/NodeIterator.cpp b/Source/core/dom/NodeIterator.cpp
index c23346f..bcd2bfe 100644
--- a/Source/core/dom/NodeIterator.cpp
+++ b/Source/core/dom/NodeIterator.cpp
@@ -198,7 +198,7 @@
                 }
                 if (node) {
                     // Removing last node.
-                    // Need to move the pointer after the node preceding the 
+                    // Need to move the pointer after the node preceding the
                     // new reference node.
                     referenceNode.node = node;
                     referenceNode.isPointerBeforeNode = false;
diff --git a/Source/core/dom/NodeTraversal.h b/Source/core/dom/NodeTraversal.h
index a0211c2..c9d5208 100644
--- a/Source/core/dom/NodeTraversal.h
+++ b/Source/core/dom/NodeTraversal.h
@@ -201,7 +201,7 @@
 }
 inline Node* next(const Node* current) { return traverseNextTemplate(current); }
 inline Node* next(const ContainerNode* current) { return traverseNextTemplate(current); }
-    
+
 template <class NodeType>
 inline Node* traverseNextTemplate(NodeType* current, const Node* stayWithin)
 {
diff --git a/Source/core/dom/NodeWithIndex.h b/Source/core/dom/NodeWithIndex.h
index 9c93755..8c75ccc 100644
--- a/Source/core/dom/NodeWithIndex.h
+++ b/Source/core/dom/NodeWithIndex.h
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #ifndef NodeWithIndex_h
diff --git a/Source/core/dom/OverflowEvent.cpp b/Source/core/dom/OverflowEvent.cpp
index a90ff6f..63ee454 100644
--- a/Source/core/dom/OverflowEvent.cpp
+++ b/Source/core/dom/OverflowEvent.cpp
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #include "config.h"
diff --git a/Source/core/dom/OverflowEvent.h b/Source/core/dom/OverflowEvent.h
index 38b940e..7509469 100644
--- a/Source/core/dom/OverflowEvent.h
+++ b/Source/core/dom/OverflowEvent.h
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #ifndef OverflowEvent_h
diff --git a/Source/core/dom/OverflowEvent.idl b/Source/core/dom/OverflowEvent.idl
index 04a86c8..69adee9 100644
--- a/Source/core/dom/OverflowEvent.idl
+++ b/Source/core/dom/OverflowEvent.idl
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 [
@@ -29,7 +29,7 @@
     const unsigned short HORIZONTAL = 0;
     const unsigned short VERTICAL   = 1;
     const unsigned short BOTH       = 2;
-    
+
     [InitializedByEventConstructor] readonly attribute unsigned short orient;
     [InitializedByEventConstructor] readonly attribute boolean horizontalOverflow;
     [InitializedByEventConstructor] readonly attribute boolean verticalOverflow;
diff --git a/Source/core/dom/PageTransitionEvent.cpp b/Source/core/dom/PageTransitionEvent.cpp
index 2c210d0..b351ef4 100644
--- a/Source/core/dom/PageTransitionEvent.cpp
+++ b/Source/core/dom/PageTransitionEvent.cpp
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #include "config.h"
diff --git a/Source/core/dom/PageTransitionEvent.h b/Source/core/dom/PageTransitionEvent.h
index 16d0115..723dfff 100644
--- a/Source/core/dom/PageTransitionEvent.h
+++ b/Source/core/dom/PageTransitionEvent.h
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #ifndef PageTransitionEvent_h
diff --git a/Source/core/dom/PageTransitionEvent.idl b/Source/core/dom/PageTransitionEvent.idl
index c8cea7f..47749be 100644
--- a/Source/core/dom/PageTransitionEvent.idl
+++ b/Source/core/dom/PageTransitionEvent.idl
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 [
diff --git a/Source/core/dom/PendingScript.cpp b/Source/core/dom/PendingScript.cpp
index e344593..94650ff 100644
--- a/Source/core/dom/PendingScript.cpp
+++ b/Source/core/dom/PendingScript.cpp
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #include "config.h"
diff --git a/Source/core/dom/PendingScript.h b/Source/core/dom/PendingScript.h
index 6794959..3d95eac 100644
--- a/Source/core/dom/PendingScript.h
+++ b/Source/core/dom/PendingScript.h
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #ifndef PendingScript_h
@@ -100,7 +100,7 @@
     bool m_watchingForLoad;
     RefPtr<Element> m_element;
     TextPosition m_startingPosition; // Only used for inline script tags.
-    CachedResourceHandle<CachedScript> m_cachedScript; 
+    CachedResourceHandle<CachedScript> m_cachedScript;
 };
 
 }
diff --git a/Source/core/dom/PopStateEvent.cpp b/Source/core/dom/PopStateEvent.cpp
index 6bd19f3..652d9a2 100644
--- a/Source/core/dom/PopStateEvent.cpp
+++ b/Source/core/dom/PopStateEvent.cpp
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  */
 
diff --git a/Source/core/dom/PopStateEvent.h b/Source/core/dom/PopStateEvent.h
index 46f6dd8..19abdd1 100644
--- a/Source/core/dom/PopStateEvent.h
+++ b/Source/core/dom/PopStateEvent.h
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  */
 
diff --git a/Source/core/dom/PopStateEvent.idl b/Source/core/dom/PopStateEvent.idl
index 709777f..20ddbaa 100644
--- a/Source/core/dom/PopStateEvent.idl
+++ b/Source/core/dom/PopStateEvent.idl
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  */
 
diff --git a/Source/core/dom/Position.h b/Source/core/dom/Position.h
index c3ad406..10cd594 100644
--- a/Source/core/dom/Position.h
+++ b/Source/core/dom/Position.h
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #ifndef Position_h
@@ -164,7 +164,7 @@
     // Returns true if the visually equivalent positions around have different editability
     bool atEditingBoundary() const;
     Node* parentEditingBoundary() const;
-    
+
     bool atStartOfTree() const;
     bool atEndOfTree() const;
 
@@ -172,11 +172,11 @@
     // These aren't really basic "position" operations. More high level editing helper functions.
     Position leadingWhitespacePosition(EAffinity, bool considerNonCollapsibleWhitespace = false) const;
     Position trailingWhitespacePosition(EAffinity, bool considerNonCollapsibleWhitespace = false) const;
-    
+
     // These return useful visually equivalent positions.
     Position upstream(EditingBoundaryCrossingRule = CannotCrossEditingBoundary) const;
     Position downstream(EditingBoundaryCrossingRule = CannotCrossEditingBoundary) const;
-    
+
     bool isCandidate() const;
     bool inRenderedText() const;
     bool isRenderedCharacter() const;
@@ -194,7 +194,7 @@
     static Node* rootUserSelectAllForNode(Node*);
 #endif
     static ContainerNode* findParent(const Node*);
-    
+
     void debugPosition(const char* msg = "") const;
 
 #ifndef NDEBUG
@@ -202,13 +202,13 @@
     void showAnchorTypeAndOffset() const;
     void showTreeForThis() const;
 #endif
-    
+
 private:
     int offsetForPositionAfterAnchor() const;
 
     int renderedOffset() const;
 
-    
+
     Position previousCharacterPosition(EAffinity) const;
     Position nextCharacterPosition(EAffinity) const;
 
@@ -300,7 +300,7 @@
     int newOffset = 0;
     for (Node* node = anchorNode->firstChild(); node && newOffset < offset; node = node->nextSibling())
         newOffset++;
-    
+
     return newOffset;
 }
 
@@ -312,8 +312,8 @@
     int currentOffset = 0;
     for (Node* node = anchorNode->firstChild(); node && currentOffset < offset; node = node->nextSibling())
         currentOffset++;
-    
-    
+
+
     return offset < currentOffset;
 }
 
diff --git a/Source/core/dom/PositionIterator.cpp b/Source/core/dom/PositionIterator.cpp
index 2156894..34328d6 100644
--- a/Source/core/dom/PositionIterator.cpp
+++ b/Source/core/dom/PositionIterator.cpp
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #include "config.h"
@@ -89,7 +89,7 @@
         }
         return;
     }
-    
+
     if (m_anchorNode->hasChildNodes()) {
         m_anchorNode = m_anchorNode->lastChild();
         m_offsetInAnchor = m_anchorNode->hasChildNodes()? 0: lastOffsetForEditing(m_anchorNode);
@@ -147,7 +147,7 @@
     RenderObject* renderer = m_anchorNode->renderer();
     if (!renderer)
         return false;
-    
+
     if (renderer->style()->visibility() != VISIBLE)
         return false;
 
diff --git a/Source/core/dom/PositionIterator.h b/Source/core/dom/PositionIterator.h
index 2457aba..6587f7e 100644
--- a/Source/core/dom/PositionIterator.h
+++ b/Source/core/dom/PositionIterator.h
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #ifndef PositionIterator_h
diff --git a/Source/core/dom/ProcessingInstruction.cpp b/Source/core/dom/ProcessingInstruction.cpp
index 89b0fc1..4706fe0 100644
--- a/Source/core/dom/ProcessingInstruction.cpp
+++ b/Source/core/dom/ProcessingInstruction.cpp
@@ -146,14 +146,14 @@
                 m_cachedSheet->removeClient(this);
                 m_cachedSheet = 0;
             }
-            
+
             String url = document()->completeURL(href).string();
             if (!dispatchBeforeLoadEvent(url))
                 return;
-            
+
             m_loading = true;
             document()->styleSheetCollection()->addPendingSheet();
-            
+
             FetchRequest request(ResourceRequest(document()->completeURL(href)), CachedResourceInitiatorTypeNames::processinginstruction);
             if (m_isXSL)
                 m_cachedSheet = document()->fetcher()->requestXSLStyleSheet(request);
@@ -260,7 +260,7 @@
     return true;
 }
 
-int ProcessingInstruction::maxCharacterOffset() const 
+int ProcessingInstruction::maxCharacterOffset() const
 {
     return static_cast<int>(m_data.length());
 }
@@ -269,7 +269,7 @@
 {
     if (!sheet())
         return;
-    
+
     addSubresourceURL(urls, sheet()->baseURL());
 }
 
@@ -288,7 +288,7 @@
     Node::removedFrom(insertionPoint);
     if (!insertionPoint->inDocument())
         return;
-    
+
     document()->styleSheetCollection()->removeStyleSheetCandidateNode(this);
 
     RefPtr<StyleSheet> removedSheet = m_sheet;
diff --git a/Source/core/dom/ProgressEvent.cpp b/Source/core/dom/ProgressEvent.cpp
index 18d6980..da8a3c1 100644
--- a/Source/core/dom/ProgressEvent.cpp
+++ b/Source/core/dom/ProgressEvent.cpp
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #include "config.h"
@@ -62,7 +62,7 @@
 {
     ScriptWrappable::init(this);
 }
-    
+
 const AtomicString& ProgressEvent::interfaceName() const
 {
     return eventNames().interfaceForProgressEvent;
diff --git a/Source/core/dom/ProgressEvent.h b/Source/core/dom/ProgressEvent.h
index eb1ecd3..035e23e 100644
--- a/Source/core/dom/ProgressEvent.h
+++ b/Source/core/dom/ProgressEvent.h
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #ifndef ProgressEvent_h
diff --git a/Source/core/dom/ProgressEvent.idl b/Source/core/dom/ProgressEvent.idl
index fd82129..d775b88 100644
--- a/Source/core/dom/ProgressEvent.idl
+++ b/Source/core/dom/ProgressEvent.idl
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 [
diff --git a/Source/core/dom/QualifiedName.cpp b/Source/core/dom/QualifiedName.cpp
index 14035fb..f57185d 100644
--- a/Source/core/dom/QualifiedName.cpp
+++ b/Source/core/dom/QualifiedName.cpp
@@ -52,7 +52,7 @@
 struct QNameComponentsTranslator {
     static unsigned hash(const QualifiedNameComponents& components)
     {
-        return hashComponents(components); 
+        return hashComponents(components);
     }
     static bool equal(QualifiedName::QualifiedNameImpl* name, const QualifiedNameComponents& c)
     {
diff --git a/Source/core/dom/QualifiedName.h b/Source/core/dom/QualifiedName.h
index 3aaae96..355ceeb 100644
--- a/Source/core/dom/QualifiedName.h
+++ b/Source/core/dom/QualifiedName.h
@@ -63,7 +63,7 @@
             , m_namespace(namespaceURI)
         {
             ASSERT(!namespaceURI.isEmpty() || namespaceURI.isNull());
-        }        
+        }
     };
 
     QualifiedName(const AtomicString& prefix, const AtomicString& localName, const AtomicString& namespaceURI);
@@ -95,16 +95,16 @@
     String toString() const;
 
     QualifiedNameImpl* impl() const { return m_impl; }
-    
+
     // Init routine for globals
     static void init();
-    
+
 private:
     void ref() const { m_impl->ref(); }
     void deref();
 
     static QualifiedNameImpl* hashTableDeletedValue() { return RefPtr<QualifiedNameImpl>::hashTableDeletedValue(); }
-    
+
     QualifiedNameImpl* m_impl;
 };
 
@@ -128,7 +128,7 @@
 struct QualifiedNameHash {
     static unsigned hash(const QualifiedName& name) { return hash(name.impl()); }
 
-    static unsigned hash(const QualifiedName::QualifiedNameImpl* name) 
+    static unsigned hash(const QualifiedName::QualifiedNameImpl* name)
     {
         if (!name->m_existingHash)
             name->m_existingHash = name->computeHash();
@@ -147,13 +147,13 @@
 }
 
 namespace WTF {
-    
+
     template<typename T> struct DefaultHash;
 
     template<> struct DefaultHash<WebCore::QualifiedName> {
         typedef WebCore::QualifiedNameHash Hash;
     };
-    
+
     template<> struct HashTraits<WebCore::QualifiedName> : SimpleClassHashTraits<WebCore::QualifiedName> {
         static const bool emptyValueIsZero = false;
         static WebCore::QualifiedName emptyValue() { return WebCore::nullQName(); }
diff --git a/Source/core/dom/Range.cpp b/Source/core/dom/Range.cpp
index f0c4659..33d2ea6 100644
--- a/Source/core/dom/Range.cpp
+++ b/Source/core/dom/Range.cpp
@@ -322,7 +322,7 @@
 short Range::comparePoint(Node* refNode, int offset, ExceptionCode& ec) const
 {
     // http://developer.mozilla.org/en/docs/DOM:range.comparePoint
-    // This method returns -1, 0 or 1 depending on if the point described by the 
+    // This method returns -1, 0 or 1 depending on if the point described by the
     // refNode node and an offset within the node is before, same as, or after the range respectively.
 
     if (!m_start.container()) {
@@ -370,7 +370,7 @@
         ec = NotFoundError;
         return NODE_BEFORE;
     }
-    
+
     if (!m_start.container() && refNode->attached()) {
         ec = InvalidStateError;
         return NODE_BEFORE;
@@ -388,7 +388,7 @@
 
     ContainerNode* parentNode = refNode->parentNode();
     int nodeIndex = refNode->nodeIndex();
-    
+
     if (!parentNode) {
         // if the node is the top document we should return NODE_BEFORE_AND_AFTER
         // but we throw to match firefox behavior
@@ -593,7 +593,7 @@
 
     ContainerNode* parentNode = refNode->parentNode();
     int nodeIndex = refNode->nodeIndex();
-    
+
     if (!parentNode) {
         // if the node is the top document we should return NODE_BEFORE_AND_AFTER
         // but we throw to match firefox behavior
@@ -608,7 +608,7 @@
                comparePoint(parentNode, nodeIndex + 1, ec) > 0) { // ends after end
         return false;
     }
-    
+
     return true; // all other cases
 }
 
@@ -629,7 +629,7 @@
 {
     ASSERT(container);
     ASSERT(commonRoot);
-    
+
     if (!commonRoot->contains(container))
         return 0;
 
@@ -787,7 +787,7 @@
     ASSERT(startOffset <= endOffset);
 
     // This switch statement must be consistent with that of lengthOfContentsInNode.
-    RefPtr<Node> result;   
+    RefPtr<Node> result;
     switch (container->nodeType()) {
     case Node::TEXT_NODE:
     case Node::CDATA_SECTION_NODE:
@@ -893,7 +893,7 @@
         // FIXME: This assertion may fail if DOM is modified during mutation event
         // FIXME: Share code with Range::processNodes
         ASSERT(!firstChildInAncestorToProcess || firstChildInAncestorToProcess->parentNode() == ancestor);
-        
+
         NodeVector nodes;
         for (Node* child = firstChildInAncestorToProcess.get(); child;
             child = (direction == ProcessContentsForward) ? child->nextSibling() : child->previousSibling())
@@ -1029,7 +1029,7 @@
         RefPtr<Text> newText = toText(container.get())->splitText(m_start.offset(), ec);
         if (ec)
             return;
-        
+
         container = m_start.container();
         container->parentNode()->insertBefore(newNode.release(), newText.get(), ec);
         if (ec)
@@ -1421,7 +1421,7 @@
     // Raise a HierarchyRequestError if m_start.container() doesn't accept children like newParent.
     Node* parentOfNewParent = m_start.container();
 
-    // If m_start.container() is a character data node, it will be split and it will be its parent that will 
+    // If m_start.container() is a character data node, it will be split and it will be its parent that will
     // need to accept newParent (or in the case of a comment, it logically "would" be inserted into the parent,
     // although this will fail below for another reason).
     if (parentOfNewParent->isCharacterDataNode())
@@ -1430,7 +1430,7 @@
         ec = HierarchyRequestError;
         return;
     }
-    
+
     if (newParent->contains(m_start.container())) {
         ec = HierarchyRequestError;
         return;
@@ -1499,7 +1499,7 @@
     ec = 0;
     if (!commonAncestorContainer(ec) || ec)
         return;
-        
+
     Node* pastLast = pastLastNode();
     for (Node* n = firstNode(); n != pastLast; n = NodeTraversal::next(n)) {
         if (n->nodeType() == Node::DOCUMENT_TYPE_NODE) {
@@ -1576,7 +1576,7 @@
         allFixed &= isFixed;
         someFixed |= isFixed;
     }
-    
+
     if (inFixed)
         *inFixed = allFixed ? EntirelyFixedPosition : (someFixed ? PartiallyFixedPosition : NotFixedPosition);
 }
@@ -1892,7 +1892,7 @@
                 RenderText* renderText = toRenderText(renderer);
                 int startOffset = (node == startContainer) ? m_start.offset() : 0;
                 int endOffset = (node == endContainer) ? m_end.offset() : INT_MAX;
-                
+
                 Vector<FloatQuad> textQuads;
                 renderText->absoluteQuadsForRange(textQuads, startOffset, endOffset);
                 m_ownerDocument->adjustFloatQuadsForScrollAndAbsoluteZoom(textQuads, renderText);
diff --git a/Source/core/dom/Range.h b/Source/core/dom/Range.h
index dea17c6..34716dc 100644
--- a/Source/core/dom/Range.h
+++ b/Source/core/dom/Range.h
@@ -138,7 +138,7 @@
     void textNodeSplit(Text* oldNode);
 
     // Expand range to a unit (word or sentence or block or document) boundary.
-    // Please refer to https://bugs.webkit.org/show_bug.cgi?id=27632 comment #5 
+    // Please refer to https://bugs.webkit.org/show_bug.cgi?id=27632 comment #5
     // for details.
     void expand(const String&, ExceptionCode&);
 
diff --git a/Source/core/dom/Range.idl b/Source/core/dom/Range.idl
index 8418229..b34558f 100644
--- a/Source/core/dom/Range.idl
+++ b/Source/core/dom/Range.idl
@@ -31,9 +31,9 @@
     [GetterRaisesException] readonly attribute boolean collapsed;
     [GetterRaisesException] readonly attribute Node commonAncestorContainer;
 
-     [RaisesException] void setStart([Default=Undefined] optional Node refNode, 
+     [RaisesException] void setStart([Default=Undefined] optional Node refNode,
                                  [Default=Undefined] optional long offset);
-     [RaisesException] void setEnd([Default=Undefined] optional Node refNode, 
+     [RaisesException] void setEnd([Default=Undefined] optional Node refNode,
                                [Default=Undefined] optional long offset);
     [RaisesException] void setStartBefore([Default=Undefined] optional Node refNode);
     [RaisesException] void setStartAfter([Default=Undefined] optional Node refNode);
@@ -83,10 +83,10 @@
     const unsigned short NODE_BEFORE_AND_AFTER = 2;
     const unsigned short NODE_INSIDE           = 3;
 
-    [RaisesException] short comparePoint([Default=Undefined] optional Node refNode, 
+    [RaisesException] short comparePoint([Default=Undefined] optional Node refNode,
                        [Default=Undefined] optional long offset);
 
-    [RaisesException] boolean isPointInRange([Default=Undefined] optional Node refNode, 
+    [RaisesException] boolean isPointInRange([Default=Undefined] optional Node refNode,
                            [Default=Undefined] optional long offset);
 
     [RaisesException] void expand([Default=Undefined] optional DOMString unit);
diff --git a/Source/core/dom/RangeBoundaryPoint.h b/Source/core/dom/RangeBoundaryPoint.h
index 77c025d..c1a4625 100644
--- a/Source/core/dom/RangeBoundaryPoint.h
+++ b/Source/core/dom/RangeBoundaryPoint.h
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #ifndef RangeBoundaryPoint_h
diff --git a/Source/core/dom/RegisteredEventListener.h b/Source/core/dom/RegisteredEventListener.h
index 23a718a..7dde557 100644
--- a/Source/core/dom/RegisteredEventListener.h
+++ b/Source/core/dom/RegisteredEventListener.h
@@ -40,7 +40,7 @@
         RefPtr<EventListener> listener;
         bool useCapture;
     };
-    
+
     inline bool operator==(const RegisteredEventListener& a, const RegisteredEventListener& b)
     {
         return *a.listener == *b.listener && a.useCapture == b.useCapture;
diff --git a/Source/core/dom/ResourceProgressEvent.idl b/Source/core/dom/ResourceProgressEvent.idl
index c08192a..660b8b1 100644
--- a/Source/core/dom/ResourceProgressEvent.idl
+++ b/Source/core/dom/ResourceProgressEvent.idl
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 // ResourceProgressEvent is a non-standard class that is simply a ProgressEvent
diff --git a/Source/core/dom/ScriptRunner.cpp b/Source/core/dom/ScriptRunner.cpp
index db5f7a5..6625728 100644
--- a/Source/core/dom/ScriptRunner.cpp
+++ b/Source/core/dom/ScriptRunner.cpp
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #include "config.h"
diff --git a/Source/core/dom/ScriptRunner.h b/Source/core/dom/ScriptRunner.h
index 6cbb2b9..166d61a 100644
--- a/Source/core/dom/ScriptRunner.h
+++ b/Source/core/dom/ScriptRunner.h
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #ifndef ScriptRunner_h
diff --git a/Source/core/dom/ScriptableDocumentParser.h b/Source/core/dom/ScriptableDocumentParser.h
index e40e8dd..18a2f93 100644
--- a/Source/core/dom/ScriptableDocumentParser.h
+++ b/Source/core/dom/ScriptableDocumentParser.h
@@ -22,7 +22,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
- 
+
 #ifndef ScriptableDocumentParser_h
 #define ScriptableDocumentParser_h
 
diff --git a/Source/core/dom/SelectorQuery.cpp b/Source/core/dom/SelectorQuery.cpp
index dd04402..d51245a 100644
--- a/Source/core/dom/SelectorQuery.cpp
+++ b/Source/core/dom/SelectorQuery.cpp
@@ -233,7 +233,7 @@
     const int maximumSelectorQueryCacheSize = 256;
     if (m_entries.size() == maximumSelectorQueryCacheSize)
         m_entries.remove(m_entries.begin());
-    
+
     OwnPtr<SelectorQuery> selectorQuery = adoptPtr(new SelectorQuery(selectorList));
     SelectorQuery* rawSelectorQuery = selectorQuery.get();
     m_entries.add(selectors, selectorQuery.release());
diff --git a/Source/core/dom/SelectorQuery.h b/Source/core/dom/SelectorQuery.h
index c3bd41a..2206303 100644
--- a/Source/core/dom/SelectorQuery.h
+++ b/Source/core/dom/SelectorQuery.h
@@ -34,7 +34,7 @@
 namespace WebCore {
 
 typedef int ExceptionCode;
-    
+
 class CSSSelector;
 class Document;
 class Element;
diff --git a/Source/core/dom/SpaceSplitString.h b/Source/core/dom/SpaceSplitString.h
index 7f9816c..6035f7c 100644
--- a/Source/core/dom/SpaceSplitString.h
+++ b/Source/core/dom/SpaceSplitString.h
@@ -49,7 +49,7 @@
         void add(const AtomicString&);
         void remove(unsigned index);
 
-        bool isUnique() const { return m_keyString.isNull(); } 
+        bool isUnique() const { return m_keyString.isNull(); }
         size_t size() const { return m_vector.size(); }
         const AtomicString& operator[](size_t i) { ASSERT_WITH_SECURITY_IMPLICATION(i < size()); return m_vector[i]; }
 
diff --git a/Source/core/dom/StyleElement.cpp b/Source/core/dom/StyleElement.cpp
index 4ac26c2..0320d16 100644
--- a/Source/core/dom/StyleElement.cpp
+++ b/Source/core/dom/StyleElement.cpp
@@ -28,6 +28,7 @@
 #include "core/dom/DocumentStyleSheetCollection.h"
 #include "core/dom/Element.h"
 #include "core/dom/ScriptableDocumentParser.h"
+#include "core/html/HTMLStyleElement.h"
 #include "core/page/ContentSecurityPolicy.h"
 #include "wtf/text/StringBuilder.h"
 #include "wtf/text/TextPosition.h"
@@ -65,11 +66,11 @@
     process(element);
 }
 
-void StyleElement::removedFromDocument(Document* document, Element* element)
+void StyleElement::removedFromDocument(Document* document, Element* element, ContainerNode* scopingNode)
 {
     ASSERT(document);
     ASSERT(element);
-    document->styleSheetCollection()->removeStyleSheetCandidateNode(element);
+    document->styleSheetCollection()->removeStyleSheetCandidateNode(element, scopingNode);
 
     RefPtr<StyleSheet> removedSheet = m_sheet;
 
@@ -87,7 +88,7 @@
         m_sheet->clearOwnerNode();
 
     if (element->inDocument())
-        document->styleSheetCollection()->removeStyleSheetCandidateNode(element);
+        document->styleSheetCollection()->removeStyleSheetCandidateNode(element, isHTMLStyleElement(element) ? toHTMLStyleElement(element)->scopingNode() :  0);
 }
 
 void StyleElement::childrenChanged(Element* element)
diff --git a/Source/core/dom/StyleElement.h b/Source/core/dom/StyleElement.h
index 0b1e410..38ffd15 100644
--- a/Source/core/dom/StyleElement.h
+++ b/Source/core/dom/StyleElement.h
@@ -26,6 +26,7 @@
 
 namespace WebCore {
 
+class ContainerNode;
 class Document;
 class Element;
 
@@ -45,7 +46,7 @@
     void startLoadingDynamicSheet(Document*);
 
     void processStyleSheet(Document*, Element*);
-    void removedFromDocument(Document*, Element*);
+    void removedFromDocument(Document*, Element*, ContainerNode* scopingNode = 0);
     void clearDocumentData(Document*, Element*);
     void childrenChanged(Element*);
     void finishParsingChildren(Element*);
diff --git a/Source/core/dom/StyleSheetCollection.cpp b/Source/core/dom/StyleSheetCollection.cpp
index 5164c84..52fbaed 100644
--- a/Source/core/dom/StyleSheetCollection.cpp
+++ b/Source/core/dom/StyleSheetCollection.cpp
@@ -3,11 +3,10 @@
  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
  *           (C) 2001 Dirk Mueller (mueller@kde.org)
  *           (C) 2006 Alexey Proskuryakov (ap@webkit.org)
- * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All rights reserved.
  * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
- * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved.
  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
- * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved.
+ * Copyright (C) 2013 Google 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
@@ -66,17 +65,25 @@
     // since styles outside of the body and head continue to be shunted into the head
     // (and thus can shift to end up before dynamically added DOM content that is also
     // outside the body).
-    if (createdByParser && document()->body()) {
+    if (createdByParser && document()->body())
         m_styleSheetCandidateNodes.parserAdd(node);
-        return;
-    }
+    else
+        m_styleSheetCandidateNodes.add(node);
 
-    m_styleSheetCandidateNodes.add(node);
+    if (!isHTMLStyleElement(node))
+        return;
+
+    ContainerNode* scopingNode = toHTMLStyleElement(node)->scopingNode();
+    if (!isTreeScopeRoot(scopingNode))
+        m_scopingNodesForStyleScoped.add(scopingNode);
 }
 
-void StyleSheetCollection::removeStyleSheetCandidateNode(Node* node)
+void StyleSheetCollection::removeStyleSheetCandidateNode(Node* node, ContainerNode* scopingNode)
 {
     m_styleSheetCandidateNodes.remove(node);
+
+    if (!isTreeScopeRoot(scopingNode))
+        m_scopingNodesForStyleScoped.remove(scopingNode);
 }
 
 void StyleSheetCollection::collectStyleSheets(DocumentStyleSheetCollection* collections, Vector<RefPtr<StyleSheet> >& styleSheets, Vector<RefPtr<CSSStyleSheet> >& activeSheets)
@@ -264,14 +271,25 @@
         document()->clearStyleResolver();
     } else {
         StyleResolver* styleResolver = document()->styleResolver();
+        styleResolver->setBuildScopedStyleTreeInDocumentOrder(!scopingNodesForStyleScoped());
         if (styleResolverUpdateType == Reset) {
-            styleResolver->resetAuthorStyle();
+            if (DocumentOrderedList* styleScopedScopingNodes = scopingNodesForStyleScoped()) {
+                for (DocumentOrderedList::iterator it = styleScopedScopingNodes->begin(); it != styleScopedScopingNodes->end(); ++it)
+                    styleResolver->resetAuthorStyle(toContainerNode(*it));
+            }
+            if (ListHashSet<Node*, 4>* removedNodes = scopingNodesRemoved()) {
+                for (ListHashSet<Node*, 4>::iterator it = removedNodes->begin(); it != removedNodes->end(); ++it)
+                    styleResolver->resetAuthorStyle(toContainerNode(*it));
+            }
+            ASSERT(m_treeScope->rootNode() == document());
+            styleResolver->resetAuthorStyle(toContainerNode(m_treeScope->rootNode()));
             styleResolver->appendAuthorStyleSheets(0, activeCSSStyleSheets);
         } else {
             ASSERT(styleResolverUpdateType == Additive);
             styleResolver->appendAuthorStyleSheets(m_activeAuthorStyleSheets.size(), activeCSSStyleSheets);
         }
     }
+    m_scopingNodesForStyleScoped.didRemoveScopingNodes();
     m_activeAuthorStyleSheets.swap(activeCSSStyleSheets);
     m_styleSheetsForStyleSheetList.swap(styleSheets);
 
diff --git a/Source/core/dom/StyleSheetCollection.h b/Source/core/dom/StyleSheetCollection.h
index e14a7ac..91da785 100644
--- a/Source/core/dom/StyleSheetCollection.h
+++ b/Source/core/dom/StyleSheetCollection.h
@@ -30,8 +30,10 @@
 
 #include "core/dom/Document.h"
 #include "core/dom/DocumentOrderedList.h"
+#include "core/dom/StyleSheetScopingNodeList.h"
 #include "core/dom/TreeScope.h"
 #include "wtf/FastAllocBase.h"
+#include "wtf/HashMap.h"
 #include "wtf/ListHashSet.h"
 #include "wtf/RefPtr.h"
 #include "wtf/Vector.h"
@@ -39,6 +41,7 @@
 
 namespace WebCore {
 
+class ContainerNode;
 class CSSStyleSheet;
 class DocumentStyleSheetCollection;
 class Node;
@@ -52,7 +55,7 @@
     explicit StyleSheetCollection(TreeScope*);
 
     void addStyleSheetCandidateNode(Node*, bool createdByParser);
-    void removeStyleSheetCandidateNode(Node*);
+    void removeStyleSheetCandidateNode(Node*, ContainerNode* scopingNode);
 
     Vector<RefPtr<CSSStyleSheet> >& activeAuthorStyleSheets() { return m_activeAuthorStyleSheets; }
     Vector<RefPtr<StyleSheet> >& styleSheetsForStyleSheetList() { return m_styleSheetsForStyleSheetList; }
@@ -60,6 +63,8 @@
     const Vector<RefPtr<StyleSheet> >& styleSheetsForStyleSheetList() const { return m_styleSheetsForStyleSheetList; }
 
     DocumentOrderedList& styleSheetCandidateNodes() { return m_styleSheetCandidateNodes; }
+    DocumentOrderedList* scopingNodesForStyleScoped() { return m_scopingNodesForStyleScoped.scopingNodes(); }
+    ListHashSet<Node*, 4>* scopingNodesRemoved() { return m_scopingNodesForStyleScoped.scopingNodesRemoved(); }
 
     enum StyleResolverUpdateType {
         Reconstruct,
@@ -85,6 +90,7 @@
     bool m_hadActiveLoadingStylesheet;
 
     DocumentOrderedList m_styleSheetCandidateNodes;
+    StyleSheetScopingNodeList m_scopingNodesForStyleScoped;
 };
 
 }
diff --git a/Source/core/dom/StyleSheetScopingNodeList.cpp b/Source/core/dom/StyleSheetScopingNodeList.cpp
new file mode 100644
index 0000000..7510eb0
--- /dev/null
+++ b/Source/core/dom/StyleSheetScopingNodeList.cpp
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
+ *           (C) 1999 Antti Koivisto (koivisto@kde.org)
+ *           (C) 2001 Dirk Mueller (mueller@kde.org)
+ *           (C) 2006 Alexey Proskuryakov (ap@webkit.org)
+ * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
+ * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved.
+ * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
+ * Copyright (C) Research In Motion Limited 2010-2011. 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
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "core/dom/StyleSheetScopingNodeList.h"
+
+#include "core/dom/Document.h"
+
+namespace WebCore {
+
+void StyleSheetScopingNodeList::add(ContainerNode* node)
+{
+    ASSERT(node && node->inDocument());
+    if (isTreeScopeRoot(node))
+        return;
+
+    if (!m_scopingNodes)
+        m_scopingNodes = adoptPtr(new DocumentOrderedList());
+    m_scopingNodes->add(node);
+
+    if (m_scopingNodesRemoved)
+        m_scopingNodesRemoved->remove(node);
+}
+
+void StyleSheetScopingNodeList::remove(ContainerNode* node)
+{
+    if (isTreeScopeRoot(node) || !m_scopingNodes)
+        return;
+
+    m_scopingNodes->remove(node);
+    if (node->inDocument() && node->numberOfScopedHTMLStyleChildren())
+        return;
+
+    if (!m_scopingNodesRemoved)
+        m_scopingNodesRemoved = adoptPtr(new ListHashSet<Node*, 4>());
+    m_scopingNodesRemoved->add(node);
+}
+
+}
+
+
diff --git a/Source/core/dom/StyleSheetScopingNodeList.h b/Source/core/dom/StyleSheetScopingNodeList.h
new file mode 100644
index 0000000..42ebda3
--- /dev/null
+++ b/Source/core/dom/StyleSheetScopingNodeList.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
+ *           (C) 1999 Antti Koivisto (koivisto@kde.org)
+ *           (C) 2001 Dirk Mueller (mueller@kde.org)
+ *           (C) 2006 Alexey Proskuryakov (ap@webkit.org)
+ * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
+ * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
+ * Copyright (C) 2013 Google 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
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef StyleSheetScopingNodeList_h
+#define StyleSheetScopingNodeList_h
+
+#include "core/dom/ContainerNode.h"
+#include "core/dom/DocumentOrderedList.h"
+#include "wtf/FastAllocBase.h"
+#include "wtf/ListHashSet.h"
+
+namespace WebCore {
+
+inline bool isTreeScopeRoot(const Node* node)
+{
+    return !node || node->isDocumentNode() || node->isShadowRoot();
+}
+
+class StyleSheetScopingNodeList {
+    WTF_MAKE_NONCOPYABLE(StyleSheetScopingNodeList); WTF_MAKE_FAST_ALLOCATED;
+public:
+    StyleSheetScopingNodeList() { }
+
+    void add(ContainerNode*);
+    void remove(ContainerNode*);
+    void clear()
+    {
+        m_scopingNodes.clear();
+        m_scopingNodesRemoved.clear();
+    }
+
+    void didRemoveScopingNodes()
+    {
+        if (!m_scopingNodesRemoved)
+            return;
+        m_scopingNodesRemoved->clear();
+    }
+
+    DocumentOrderedList* scopingNodes() { return m_scopingNodes.get(); }
+    ListHashSet<Node*, 4>* scopingNodesRemoved() { return m_scopingNodesRemoved.get(); }
+
+private:
+    OwnPtr<DocumentOrderedList> m_scopingNodes;
+    OwnPtr<ListHashSet<Node*, 4> > m_scopingNodesRemoved;
+};
+
+}
+
+#endif
diff --git a/Source/core/dom/Text.cpp b/Source/core/dom/Text.cpp
index 826f282..d16d727 100644
--- a/Source/core/dom/Text.cpp
+++ b/Source/core/dom/Text.cpp
@@ -213,14 +213,14 @@
     RenderObject* parent = context.parentRenderer();
     if (!parent->canHaveWhitespaceChildren())
         return false;
-    
+
     if (context.style()->preserveNewline()) // pre/pre-wrap/pre-line always make renderers.
         return true;
 
     RenderObject* prev = context.previousRenderer();
     if (prev && prev->isBR()) // <span><br/> <br/></span>
         return false;
-        
+
     if (parent->isRenderInline()) {
         // <span><div/> <div/></span>
         if (prev && !prev->isInline())
diff --git a/Source/core/dom/Text.h b/Source/core/dom/Text.h
index 65f7738..95c502b 100644
--- a/Source/core/dom/Text.h
+++ b/Source/core/dom/Text.h
@@ -45,7 +45,7 @@
 
     String wholeText() const;
     PassRefPtr<Text> replaceWholeText(const String&);
-    
+
     bool recalcTextStyle(StyleChange);
     void createTextRendererIfNeeded();
     bool textRendererIsNeeded(const NodeRenderingContext&);
@@ -53,7 +53,7 @@
     void updateTextRenderer(unsigned offsetOfReplacedData, unsigned lengthOfReplacedData);
 
     virtual void attach(const AttachContext& = AttachContext()) OVERRIDE FINAL;
-    
+
     virtual bool canContainRangeEndPoint() const OVERRIDE FINAL { return true; }
     virtual NodeType nodeType() const OVERRIDE;
 
diff --git a/Source/core/dom/TextEvent.cpp b/Source/core/dom/TextEvent.cpp
index 516cf88..e3ee3c8 100644
--- a/Source/core/dom/TextEvent.cpp
+++ b/Source/core/dom/TextEvent.cpp
@@ -9,7 +9,7 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 
+ *
  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  */
 
diff --git a/Source/core/dom/TextEvent.h b/Source/core/dom/TextEvent.h
index 90f06df..c0dcb69 100644
--- a/Source/core/dom/TextEvent.h
+++ b/Source/core/dom/TextEvent.h
@@ -9,7 +9,7 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 
+ *
  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  */
 
@@ -44,9 +44,9 @@
         static PassRefPtr<TextEvent> createForDrop(PassRefPtr<AbstractView> view, const String& data);
 
         virtual ~TextEvent();
-    
+
         void initTextEvent(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<AbstractView>, const String& data);
-    
+
         String data() const { return m_data; }
 
         virtual const AtomicString& interfaceName() const;
diff --git a/Source/core/dom/TextEvent.idl b/Source/core/dom/TextEvent.idl
index 10ec19a..3d03594e 100644
--- a/Source/core/dom/TextEvent.idl
+++ b/Source/core/dom/TextEvent.idl
@@ -9,7 +9,7 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 
+ *
  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 // Introduced in DOM Level 3:
@@ -28,10 +28,10 @@
 
     readonly attribute DOMString data;
 
-    void initTextEvent([Default=Undefined] optional DOMString typeArg, 
-                       [Default=Undefined] optional boolean canBubbleArg, 
-                       [Default=Undefined] optional boolean cancelableArg, 
-                       [Default=Undefined] optional Window viewArg, 
+    void initTextEvent([Default=Undefined] optional DOMString typeArg,
+                       [Default=Undefined] optional boolean canBubbleArg,
+                       [Default=Undefined] optional boolean cancelableArg,
+                       [Default=Undefined] optional Window viewArg,
                        [Default=Undefined] optional DOMString dataArg);
 
 };
diff --git a/Source/core/dom/TextEventInputType.h b/Source/core/dom/TextEventInputType.h
index 8be233c..fc98a6c 100644
--- a/Source/core/dom/TextEventInputType.h
+++ b/Source/core/dom/TextEventInputType.h
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #ifndef TextEventInputType_h
diff --git a/Source/core/dom/TouchEvent.cpp b/Source/core/dom/TouchEvent.cpp
index aec39ef..019a5b5 100644
--- a/Source/core/dom/TouchEvent.cpp
+++ b/Source/core/dom/TouchEvent.cpp
@@ -41,7 +41,7 @@
 }
 
 TouchEvent::TouchEvent(TouchList* touches, TouchList* targetTouches,
-        TouchList* changedTouches, const AtomicString& type, 
+        TouchList* changedTouches, const AtomicString& type,
         PassRefPtr<AbstractView> view, int screenX, int screenY, int pageX, int pageY,
         bool ctrlKey, bool altKey, bool shiftKey, bool metaKey)
     : MouseRelatedEvent(type, true, true, view, 0, IntPoint(screenX, screenY),
@@ -60,7 +60,7 @@
 }
 
 void TouchEvent::initTouchEvent(TouchList* touches, TouchList* targetTouches,
-        TouchList* changedTouches, const AtomicString& type, 
+        TouchList* changedTouches, const AtomicString& type,
         PassRefPtr<AbstractView> view, int screenX, int screenY, int clientX, int clientY,
         bool ctrlKey, bool altKey, bool shiftKey, bool metaKey)
 {
diff --git a/Source/core/dom/TouchEvent.h b/Source/core/dom/TouchEvent.h
index abbd7b8..45a38dd 100644
--- a/Source/core/dom/TouchEvent.h
+++ b/Source/core/dom/TouchEvent.h
@@ -41,8 +41,8 @@
     {
         return adoptRef(new TouchEvent);
     }
-    static PassRefPtr<TouchEvent> create(TouchList* touches, 
-            TouchList* targetTouches, TouchList* changedTouches, 
+    static PassRefPtr<TouchEvent> create(TouchList* touches,
+            TouchList* targetTouches, TouchList* changedTouches,
             const AtomicString& type, PassRefPtr<AbstractView> view,
             int screenX, int screenY, int pageX, int pageY,
             bool ctrlKey, bool altKey, bool shiftKey, bool metaKey)
@@ -53,8 +53,8 @@
     }
 
     void initTouchEvent(TouchList* touches, TouchList* targetTouches,
-            TouchList* changedTouches, const AtomicString& type, 
-            PassRefPtr<AbstractView> view, int screenX, int screenY, 
+            TouchList* changedTouches, const AtomicString& type,
+            PassRefPtr<AbstractView> view, int screenX, int screenY,
             int clientX, int clientY,
             bool ctrlKey, bool altKey, bool shiftKey, bool metaKey);
 
diff --git a/Source/core/dom/TouchEvent.idl b/Source/core/dom/TouchEvent.idl
index c3b7a81..f4b396e 100644
--- a/Source/core/dom/TouchEvent.idl
+++ b/Source/core/dom/TouchEvent.idl
@@ -36,9 +36,9 @@
                         [Default=Undefined] optional TouchList changedTouches,
                         [Default=Undefined] optional DOMString type,
                         [Default=Undefined] optional Window view,
-                        [Default=Undefined] optional long screenX, 
-                        [Default=Undefined] optional long screenY, 
-                        [Default=Undefined] optional long clientX, 
+                        [Default=Undefined] optional long screenX,
+                        [Default=Undefined] optional long screenY,
+                        [Default=Undefined] optional long clientX,
                         [Default=Undefined] optional long clientY,
                         [Default=Undefined] optional boolean ctrlKey,
                         [Default=Undefined] optional boolean altKey,
diff --git a/Source/core/dom/TransitionEvent.cpp b/Source/core/dom/TransitionEvent.cpp
index 7ddacd9..346a66f 100644
--- a/Source/core/dom/TransitionEvent.cpp
+++ b/Source/core/dom/TransitionEvent.cpp
@@ -21,7 +21,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #include "config.h"
diff --git a/Source/core/dom/TransitionEvent.h b/Source/core/dom/TransitionEvent.h
index c27ce92..9fe4ffb 100644
--- a/Source/core/dom/TransitionEvent.h
+++ b/Source/core/dom/TransitionEvent.h
@@ -21,7 +21,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #ifndef TransitionEvent_h
diff --git a/Source/core/dom/TransitionEvent.idl b/Source/core/dom/TransitionEvent.idl
index afce660..b2bd8ed 100644
--- a/Source/core/dom/TransitionEvent.idl
+++ b/Source/core/dom/TransitionEvent.idl
@@ -21,7 +21,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 [
diff --git a/Source/core/dom/TreeWalker.idl b/Source/core/dom/TreeWalker.idl
index 3a844b7..bfb435b 100644
--- a/Source/core/dom/TreeWalker.idl
+++ b/Source/core/dom/TreeWalker.idl
@@ -23,7 +23,7 @@
     readonly attribute Node root;
     readonly attribute unsigned long whatToShow;
     readonly attribute NodeFilter filter;
-    readonly attribute boolean expandEntityReferences;        
+    readonly attribute boolean expandEntityReferences;
              [SetterRaisesException] attribute Node currentNode;
 
     [CallWith=ScriptState] Node parentNode();
diff --git a/Source/core/dom/UIEvent.idl b/Source/core/dom/UIEvent.idl
index 09960d7..bfa6da9 100644
--- a/Source/core/dom/UIEvent.idl
+++ b/Source/core/dom/UIEvent.idl
@@ -22,11 +22,11 @@
 ] interface UIEvent : Event {
     [InitializedByEventConstructor] readonly attribute Window view;
     [InitializedByEventConstructor] readonly attribute long detail;
-    
-     void initUIEvent([Default=Undefined] optional DOMString type, 
-                                    [Default=Undefined] optional boolean canBubble, 
-                                    [Default=Undefined] optional boolean cancelable, 
-                                    [Default=Undefined] optional Window view, 
+
+     void initUIEvent([Default=Undefined] optional DOMString type,
+                                    [Default=Undefined] optional boolean canBubble,
+                                    [Default=Undefined] optional boolean cancelable,
+                                    [Default=Undefined] optional Window view,
                                     [Default=Undefined] optional long detail);
 
     // extensions
diff --git a/Source/core/dom/UIEventWithKeyState.cpp b/Source/core/dom/UIEventWithKeyState.cpp
index 176eaa7..da510d9 100644
--- a/Source/core/dom/UIEventWithKeyState.cpp
+++ b/Source/core/dom/UIEventWithKeyState.cpp
@@ -22,7 +22,7 @@
 #include "core/dom/UIEventWithKeyState.h"
 
 namespace WebCore {
-    
+
 UIEventWithKeyState* findEventWithKeyState(Event* event)
 {
     for (Event* e = event; e; e = e->underlyingEvent())
diff --git a/Source/core/dom/UIEventWithKeyState.h b/Source/core/dom/UIEventWithKeyState.h
index 64fca1f..bcf9a80 100644
--- a/Source/core/dom/UIEventWithKeyState.h
+++ b/Source/core/dom/UIEventWithKeyState.h
@@ -27,7 +27,7 @@
 #include "core/dom/UIEvent.h"
 
 namespace WebCore {
-    
+
     class UIEventWithKeyState : public UIEvent {
     public:
         bool ctrlKey() const { return m_ctrlKey; }
@@ -43,7 +43,7 @@
             , m_metaKey(false)
         {
         }
-        
+
         UIEventWithKeyState(const AtomicString& type, bool canBubble, bool cancelable, PassRefPtr<AbstractView> view,
                             int detail, bool ctrlKey, bool altKey, bool shiftKey, bool metaKey)
             : UIEvent(type, canBubble, cancelable, view, detail)
diff --git a/Source/core/dom/UserTypingGestureIndicator.h b/Source/core/dom/UserTypingGestureIndicator.h
index 02a9794..6625b36 100644
--- a/Source/core/dom/UserTypingGestureIndicator.h
+++ b/Source/core/dom/UserTypingGestureIndicator.h
@@ -46,7 +46,7 @@
 private:
     bool m_previousProcessingUserTypingGesture;
     RefPtr<Element> m_previousFocusedElement;
-};    
+};
 
 } // namespace WebCore
 
diff --git a/Source/core/dom/WebKitNamedFlow.idl b/Source/core/dom/WebKitNamedFlow.idl
index 68f2858..a8f68dd 100644
--- a/Source/core/dom/WebKitNamedFlow.idl
+++ b/Source/core/dom/WebKitNamedFlow.idl
@@ -12,7 +12,7 @@
  *    copyright notice, this list of conditions and the following
  *    disclaimer in the documentation and/or other materials
  *    provided with the distribution.
- * 
+ *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
diff --git a/Source/core/dom/WheelEvent.cpp b/Source/core/dom/WheelEvent.cpp
index 2f430c3..c7bdf0d 100644
--- a/Source/core/dom/WheelEvent.cpp
+++ b/Source/core/dom/WheelEvent.cpp
@@ -73,18 +73,18 @@
 {
     if (dispatched())
         return;
-    
+
     initUIEvent(eventNames().mousewheelEvent, true, true, view, 0);
-    
+
     m_screenLocation = IntPoint(screenX, screenY);
     m_ctrlKey = ctrlKey;
     m_altKey = altKey;
     m_shiftKey = shiftKey;
     m_metaKey = metaKey;
-    
+
     // Normalize to the Windows 120 multiple
     m_wheelDelta = IntPoint(rawDeltaX * TickMultiplier, rawDeltaY * TickMultiplier);
-    
+
     m_rawDelta = IntPoint(rawDeltaX, rawDeltaY);
     m_deltaMode = DOM_DELTA_PIXEL;
     m_directionInvertedFromDevice = false;
diff --git a/Source/core/dom/WheelEvent.idl b/Source/core/dom/WheelEvent.idl
index 6c8dad4..9dc0e4a 100644
--- a/Source/core/dom/WheelEvent.idl
+++ b/Source/core/dom/WheelEvent.idl
@@ -35,8 +35,8 @@
     readonly attribute boolean webkitDirectionInvertedFromDevice;
 
     void initWebKitWheelEvent([Default=Undefined] optional long wheelDeltaX,
-                              [Default=Undefined] optional long wheelDeltaY, 
-                              [Default=Undefined] optional Window view, 
+                              [Default=Undefined] optional long wheelDeltaY,
+                              [Default=Undefined] optional Window view,
                               [Default=Undefined] optional long screenX,
                               [Default=Undefined] optional long screenY,
                               [Default=Undefined] optional long clientX,
diff --git a/Source/core/dom/WindowEventContext.cpp b/Source/core/dom/WindowEventContext.cpp
index af5facf..b9cbaa9 100644
--- a/Source/core/dom/WindowEventContext.cpp
+++ b/Source/core/dom/WindowEventContext.cpp
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  */
 
diff --git a/Source/core/dom/WindowEventContext.h b/Source/core/dom/WindowEventContext.h
index 5d0aa7c..25c5079 100644
--- a/Source/core/dom/WindowEventContext.h
+++ b/Source/core/dom/WindowEventContext.h
@@ -20,7 +20,7 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  */
 
diff --git a/Source/core/dom/shadow/ContentDistributor.cpp b/Source/core/dom/shadow/ContentDistributor.cpp
index e7ae775..5d002a2 100644
--- a/Source/core/dom/shadow/ContentDistributor.cpp
+++ b/Source/core/dom/shadow/ContentDistributor.cpp
@@ -112,30 +112,27 @@
 
 void ScopeContentDistribution::registerInsertionPoint(InsertionPoint* point)
 {
-    switch (point->insertionPointType()) {
-    case InsertionPoint::ShadowInsertionPoint:
+    if (isHTMLShadowElement(point))
         ++m_numberOfShadowElementChildren;
-        break;
-    case InsertionPoint::ContentInsertionPoint:
+    else if (isHTMLContentElement(point))
         ++m_numberOfContentElementChildren;
-        break;
-    }
+    else
+        ASSERT_NOT_REACHED();
 
     invalidateInsertionPointList();
 }
 
 void ScopeContentDistribution::unregisterInsertionPoint(InsertionPoint* point)
 {
-    switch (point->insertionPointType()) {
-    case InsertionPoint::ShadowInsertionPoint:
-        ASSERT(m_numberOfShadowElementChildren > 0);
+    if (isHTMLShadowElement(point))
         --m_numberOfShadowElementChildren;
-        break;
-    case InsertionPoint::ContentInsertionPoint:
-        ASSERT(m_numberOfContentElementChildren > 0);
+    else if (isHTMLContentElement(point))
         --m_numberOfContentElementChildren;
-        break;
-    }
+    else
+        ASSERT_NOT_REACHED();
+
+    ASSERT(m_numberOfContentElementChildren >= 0);
+    ASSERT(m_numberOfShadowElementChildren >= 0);
 
     invalidateInsertionPointList();
 }
@@ -358,22 +355,18 @@
 
 void ContentDistributor::collectSelectFeatureSetFrom(ShadowRoot* root)
 {
-    if (root->containsShadowRoots()) {
-        for (Element* element = ElementTraversal::firstWithin(root); element; element = ElementTraversal::next(element)) {
-            if (ElementShadow* elementShadow = element->shadow())
-                m_selectFeatures.add(elementShadow->distributor().ensureSelectFeatureSet(elementShadow));
-        }
-    }
+    if (!root->containsShadowRoots() && !root->containsContentElements())
+        return;
 
-    if (root->containsContentElements()) {
-        for (Element* element = ElementTraversal::firstWithin(root); element; element = ElementTraversal::next(element)) {
-            if (!isHTMLContentElement(element))
-                continue;
-            const CSSSelectorList& list = toHTMLContentElement(element)->selectorList();
-            for (const CSSSelector* selector = list.first(); selector; selector = CSSSelectorList::next(selector)) {
-                for (const CSSSelector* component = selector; component; component = component->tagHistory())
-                    m_selectFeatures.collectFeaturesFromSelector(component);
-            }
+    for (Element* element = ElementTraversal::firstWithin(root); element; element = ElementTraversal::next(element, root)) {
+        if (ElementShadow* shadow = element->shadow())
+            m_selectFeatures.add(shadow->ensureSelectFeatureSet());
+        if (!isHTMLContentElement(element))
+            continue;
+        const CSSSelectorList& list = toHTMLContentElement(element)->selectorList();
+        for (const CSSSelector* selector = list.first(); selector; selector = CSSSelectorList::next(selector)) {
+            for (const CSSSelector* component = selector; component; component = component->tagHistory())
+                m_selectFeatures.collectFeaturesFromSelector(component);
         }
     }
 }
diff --git a/Source/core/dom/shadow/ElementShadow.h b/Source/core/dom/shadow/ElementShadow.h
index 084d7c1..bc73e91 100644
--- a/Source/core/dom/shadow/ElementShadow.h
+++ b/Source/core/dom/shadow/ElementShadow.h
@@ -64,6 +64,7 @@
     void invalidateDistribution() { m_distributor.invalidateDistribution(host()); }
     void didAffectSelector(AffectedSelectorMask mask) { m_distributor.didAffectSelector(host(), mask); }
     void willAffectSelector() { m_distributor.willAffectSelector(host()); }
+    const SelectRuleFeatureSet& ensureSelectFeatureSet() { return m_distributor.ensureSelectFeatureSet(this); }
 
     ContentDistributor& distributor() { return m_distributor; }
     const ContentDistributor& distributor() const { return m_distributor; }
diff --git a/Source/core/dom/shadow/InsertionPoint.cpp b/Source/core/dom/shadow/InsertionPoint.cpp
index 0fe52d9..878d661 100644
--- a/Source/core/dom/shadow/InsertionPoint.cpp
+++ b/Source/core/dom/shadow/InsertionPoint.cpp
@@ -194,11 +194,6 @@
     setBooleanAttribute(reset_style_inheritanceAttr, value);
 }
 
-bool InsertionPoint::contains(const Node* node) const
-{
-    return m_distribution.contains(const_cast<Node*>(node)) || (node->isShadowRoot() && toShadowRoot(node)->insertionPoint() == this);
-}
-
 const CSSSelectorList& InsertionPoint::emptySelectorList()
 {
     DEFINE_STATIC_LOCAL(CSSSelectorList, selectorList, (CSSSelectorList()));
diff --git a/Source/core/dom/shadow/InsertionPoint.h b/Source/core/dom/shadow/InsertionPoint.h
index 0f1d486..7100234 100644
--- a/Source/core/dom/shadow/InsertionPoint.h
+++ b/Source/core/dom/shadow/InsertionPoint.h
@@ -41,11 +41,6 @@
 
 class InsertionPoint : public HTMLElement {
 public:
-    enum Type {
-        ShadowInsertionPoint,
-        ContentInsertionPoint
-    };
-
     enum MatchType {
         AlwaysMatches,
         NeverMatches,
@@ -63,7 +58,6 @@
 
     virtual MatchType matchTypeFor(Node*) { return AlwaysMatches; }
     virtual const CSSSelectorList& selectorList() { return emptySelectorList(); }
-    virtual Type insertionPointType() const = 0;
     virtual bool canAffectSelector() const { return false; }
 
     bool resetStyleInheritance() const;
@@ -74,8 +68,6 @@
 
     bool shouldUseFallbackElements() const;
 
-    size_t indexOf(Node* node) const { return m_distribution.find(node); }
-    bool contains(const Node*) const;
     size_t size() const { return m_distribution.size(); }
     Node* at(size_t index)  const { return m_distribution.at(index).get(); }
     Node* first() const { return m_distribution.isEmpty() ? 0 : m_distribution.first().get(); }
diff --git a/Source/core/dom/shadow/ShadowRoot.idl b/Source/core/dom/shadow/ShadowRoot.idl
index 6a6e07e..b659c7c 100644
--- a/Source/core/dom/shadow/ShadowRoot.idl
+++ b/Source/core/dom/shadow/ShadowRoot.idl
@@ -30,7 +30,7 @@
     readonly attribute Element activeElement;
     attribute boolean applyAuthorStyles;
     attribute boolean resetStyleInheritance;
-    [EnabledAtRuntime=experimentalShadowDOM, ImplementedAs=bindingsOlderShadowRoot] readonly attribute ShadowRoot olderShadowRoot;
+    [EnabledAtRuntime=ShadowDOM, ImplementedAs=bindingsOlderShadowRoot] readonly attribute ShadowRoot olderShadowRoot;
 
     [TreatNullAs=NullString, DeliverCustomElementCallbacks, PerWorldBindings, ActivityLog=SetterForIsolatedWorlds, SetterRaisesException] attribute DOMString innerHTML;
 
@@ -42,6 +42,6 @@
     NodeList getElementsByTagNameNS([TreatNullAs=NullString,Default=Undefined] optional DOMString namespaceURI,
                                     [Default=Undefined] optional DOMString localName);
 
-    Element elementFromPoint([Default=Undefined] optional long x, 
+    Element elementFromPoint([Default=Undefined] optional long x,
                              [Default=Undefined] optional long y);
 };