Merge from Chromium at DEPS revision r199464

This commit was generated by merge_to_master.py.

Change-Id: I19655f81f4534807b2fa07bc72b5208501b02896
diff --git a/Source/core/dom/Attr.cpp b/Source/core/dom/Attr.cpp
index b71a1e2..4751272 100644
--- a/Source/core/dom/Attr.cpp
+++ b/Source/core/dom/Attr.cpp
@@ -151,13 +151,7 @@
 // DOM Section 1.1.1
 bool Attr::childTypeAllowed(NodeType type) const
 {
-    switch (type) {
-        case TEXT_NODE:
-        case ENTITY_REFERENCE_NODE:
-            return true;
-        default:
-            return false;
-    }
+    return TEXT_NODE == type;
 }
 
 void Attr::childrenChanged(bool, Node*, Node*, int)
@@ -167,8 +161,6 @@
 
     invalidateNodeListCachesInAncestors(&qualifiedName(), m_element);
 
-    // FIXME: We should include entity references in the value
-
     StringBuilder valueBuilder;
     for (Node *n = firstChild(); n; n = n->nextSibling()) {
         if (n->isTextNode())
diff --git a/Source/core/dom/Attr.h b/Source/core/dom/Attr.h
index c525725..5ac819a 100644
--- a/Source/core/dom/Attr.h
+++ b/Source/core/dom/Attr.h
@@ -33,7 +33,7 @@
 class CSSStyleDeclaration;
 class StylePropertySet;
 
-// Attr can have Text and EntityReference children
+// Attr can have Text children
 // therefore it has to be a fullblown Node. The plan
 // is to dynamically allocate a textchild and store the
 // resulting nodevalue in the attribute upon
diff --git a/Source/core/dom/Comment.cpp b/Source/core/dom/Comment.cpp
index 5b8374f..eb525bd 100644
--- a/Source/core/dom/Comment.cpp
+++ b/Source/core/dom/Comment.cpp
@@ -37,6 +37,11 @@
     return adoptRef(new Comment(document, text));
 }
 
+PassRefPtr<Comment> Comment::create(ScriptExecutionContext* context, const String& text)
+{
+    return adoptRef(new Comment(toDocument(context), text));
+}
+
 String Comment::nodeName() const
 {
     return commentAtom.string();
diff --git a/Source/core/dom/Comment.h b/Source/core/dom/Comment.h
index df79fbb..5ef2285 100644
--- a/Source/core/dom/Comment.h
+++ b/Source/core/dom/Comment.h
@@ -27,9 +27,12 @@
 
 namespace WebCore {
 
+class ScriptExecutionContext;
+
 class Comment FINAL : public CharacterData {
 public:
     static PassRefPtr<Comment> create(Document*, const String&);
+    static PassRefPtr<Comment> create(ScriptExecutionContext*, const String&);
 
 private:
     Comment(Document*, const String&);
diff --git a/Source/core/dom/Comment.idl b/Source/core/dom/Comment.idl
index 5c07e2f..3a46dd7 100644
--- a/Source/core/dom/Comment.idl
+++ b/Source/core/dom/Comment.idl
@@ -17,6 +17,9 @@
  * Boston, MA 02110-1301, USA.
  */
 
-interface Comment : CharacterData {
+[
+    Constructor([Default=NullString] optional DOMString data),
+    CallWith=ScriptExecutionContext
+] interface Comment : CharacterData {
 };
 
diff --git a/Source/core/dom/ContainerNode.cpp b/Source/core/dom/ContainerNode.cpp
index a25bfb9..4256a59 100644
--- a/Source/core/dom/ContainerNode.cpp
+++ b/Source/core/dom/ContainerNode.cpp
@@ -166,7 +166,6 @@
 
     // Use common case fast path if possible.
     if ((newChild->isElementNode() || newChild->isTextNode()) && newParent->isElementNode()) {
-        ASSERT(!newParent->isReadOnlyNode());
         ASSERT(!newParent->isDocumentTypeNode());
         ASSERT(isChildTypeAllowed(newParent, newChild));
         if (containsConsideringHostElements(newChild, newParent))
@@ -179,8 +178,6 @@
     if (newChild->isPseudoElement())
         return HIERARCHY_REQUEST_ERR;
 
-    if (newParent->isReadOnlyNode())
-        return NO_MODIFICATION_ALLOWED_ERR;
     if (newChild->inDocument() && newChild->isDocumentTypeNode())
         return HIERARCHY_REQUEST_ERR;
     if (containsConsideringHostElements(newChild, newParent))
@@ -197,7 +194,6 @@
 
 static inline bool checkAcceptChildGuaranteedNodeTypes(ContainerNode* newParent, Node* newChild, ExceptionCode& ec)
 {
-    ASSERT(!newParent->isReadOnlyNode());
     ASSERT(!newParent->isDocumentTypeNode());
     ASSERT(isChildTypeAllowed(newParent, newChild));
     if (newChild->contains(newParent)) {
@@ -474,12 +470,6 @@
 
     ec = 0;
 
-    // NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
-    if (isReadOnlyNode()) {
-        ec = NO_MODIFICATION_ALLOWED_ERR;
-        return false;
-    }
-
     // NOT_FOUND_ERR: Raised if oldChild is not a child of this node.
     if (!oldChild || oldChild->parentNode() != this) {
         ec = NOT_FOUND_ERR;
diff --git a/Source/core/dom/CustomElementConstructor.cpp b/Source/core/dom/CustomElementConstructor.cpp
index f664ecf..ff02ea7 100644
--- a/Source/core/dom/CustomElementConstructor.cpp
+++ b/Source/core/dom/CustomElementConstructor.cpp
@@ -32,6 +32,7 @@
 
 #include "core/dom/CustomElementConstructor.h"
 
+#include "core/dom/CustomElementRegistry.h"
 #include "core/dom/Document.h"
 #include "core/dom/Element.h"
 
@@ -55,7 +56,12 @@
 PassRefPtr<Element> CustomElementConstructor::createElement(ExceptionCode& ec) {
     if (!document())
         return 0;
-    return document()->createElementNS(m_tag.namespaceURI(), m_tag.localName(), m_typeExtension, ec);
+    RefPtr<Element> result;
+    {
+        CustomElementRegistry::CallbackDeliveryScope deliveryScope;
+        result = document()->createElementNS(m_tag.namespaceURI(), m_tag.localName(), m_typeExtension, ec);
+    }
+    return result.release();
 }
 
 }
diff --git a/Source/core/dom/CustomElementConstructor.idl b/Source/core/dom/CustomElementConstructor.idl
index 0460874..d5c0726 100644
--- a/Source/core/dom/CustomElementConstructor.idl
+++ b/Source/core/dom/CustomElementConstructor.idl
@@ -23,6 +23,7 @@
  */
 
 [
+    NoInterfaceObject,
     EnabledAtRuntime=customDOMElements,
     WrapAsFunction,
     CustomCall
diff --git a/Source/core/dom/DOMCoreException.cpp b/Source/core/dom/DOMCoreException.cpp
index 6e3e76e..10488d5 100644
--- a/Source/core/dom/DOMCoreException.cpp
+++ b/Source/core/dom/DOMCoreException.cpp
@@ -29,6 +29,8 @@
 #include "config.h"
 #include "core/dom/DOMCoreException.h"
 
+#include "DOMException.h"
+
 namespace WebCore {
 
 static struct CoreException {
diff --git a/Source/core/dom/DOMError.idl b/Source/core/dom/DOMError.idl
index 79a5881..81fa031 100644
--- a/Source/core/dom/DOMError.idl
+++ b/Source/core/dom/DOMError.idl
@@ -26,6 +26,7 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 [
+    NoInterfaceObject,
     ImplementationLacksVTable
 ] interface  DOMError {
     readonly attribute DOMString name;
diff --git a/Source/core/dom/DOMExceptions.in b/Source/core/dom/DOMExceptions.in
index b27312b..21ad60d 100644
--- a/Source/core/dom/DOMExceptions.in
+++ b/Source/core/dom/DOMExceptions.in
@@ -1,4 +1,4 @@
-namespace=Exception
+namespace=DOMException
 
 core/dom/DOMCoreException
 core/dom/EventException
diff --git a/Source/core/dom/DOMImplementation.cpp b/Source/core/dom/DOMImplementation.cpp
index 5481f20..7118c1c 100644
--- a/Source/core/dom/DOMImplementation.cpp
+++ b/Source/core/dom/DOMImplementation.cpp
@@ -25,6 +25,7 @@
 #include "config.h"
 #include "core/dom/DOMImplementation.h"
 
+#include <wtf/StdLibExtras.h>
 #include "HTMLNames.h"
 #include "XMLNames.h"
 #include "core/css/CSSStyleSheet.h"
@@ -44,14 +45,13 @@
 #include "core/loader/FrameLoaderClient.h"
 #include "core/page/Frame.h"
 #include "core/page/Page.h"
-#include "core/page/SecurityOrigin.h"
 #include "core/page/Settings.h"
 #include "core/platform/ContentType.h"
 #include "core/platform/MIMETypeRegistry.h"
 #include "core/platform/graphics/Image.h"
 #include "core/platform/graphics/MediaPlayer.h"
 #include "core/plugins/PluginData.h"
-#include <wtf/StdLibExtras.h>
+#include "origin/SecurityOrigin.h"
 
 #if ENABLE(SVG)
 #include "SVGNames.h"
@@ -67,22 +67,6 @@
     set.add(string);
 }
 
-class DOMImplementationSupportsTypeClient : public MediaPlayerSupportsTypeClient {
-public:
-    DOMImplementationSupportsTypeClient(bool needsHacks, const String& host)
-        : m_needsHacks(needsHacks)
-        , m_host(host)
-    {
-    }
-
-private:
-    virtual bool mediaPlayerNeedsSiteSpecificHacks() const OVERRIDE { return m_needsHacks; }
-    virtual String mediaPlayerDocumentHost() const OVERRIDE { return m_host; }
-
-    bool m_needsHacks;
-    String m_host;
-};
-
 #if ENABLE(SVG)
 
 static bool isSVG10Feature(const String &feature, const String &version)
@@ -433,11 +417,10 @@
     if (Image::supportsType(type))
         return ImageDocument::create(frame, url);
 
-     // Check to see if the type can be played by our MediaPlayer, if so create a MediaDocument
+    // Check to see if the type can be played by our MediaPlayer, if so create a MediaDocument
     // Key system is not applicable here.
-    DOMImplementationSupportsTypeClient client(frame && frame->settings() && frame->settings()->needsSiteSpecificQuirks(), url.host());
-    if (MediaPlayer::supportsType(ContentType(type), String(), url, &client))
-         return MediaDocument::create(frame, url);
+    if (MediaPlayer::supportsType(ContentType(type), String(), url))
+        return MediaDocument::create(frame, url);
 
     // 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,
diff --git a/Source/core/dom/DOMNamedFlowCollection.idl b/Source/core/dom/DOMNamedFlowCollection.idl
index 6225e98..b8bda55 100644
--- a/Source/core/dom/DOMNamedFlowCollection.idl
+++ b/Source/core/dom/DOMNamedFlowCollection.idl
@@ -28,6 +28,7 @@
  */
 
 [
+    NoInterfaceObject,
     EnabledAtRuntime=cssRegions,
     InterfaceName=WebKitNamedFlowCollection,
     ImplementationLacksVTable
diff --git a/Source/core/dom/DataTransferItem.idl b/Source/core/dom/DataTransferItem.idl
index 227e5a5..c10e6fe 100644
--- a/Source/core/dom/DataTransferItem.idl
+++ b/Source/core/dom/DataTransferItem.idl
@@ -29,6 +29,7 @@
  */
 
 [
+    NoInterfaceObject,
     ImplementationLacksVTable
 ] interface DataTransferItem {
     readonly attribute DOMString kind;
diff --git a/Source/core/dom/DataTransferItemList.idl b/Source/core/dom/DataTransferItemList.idl
index 0217784..184426b 100644
--- a/Source/core/dom/DataTransferItemList.idl
+++ b/Source/core/dom/DataTransferItemList.idl
@@ -29,6 +29,7 @@
  */
 
 [
+    NoInterfaceObject,
     ImplementationLacksVTable
 ] interface DataTransferItemList {
     readonly attribute long length;
diff --git a/Source/core/dom/Document.cpp b/Source/core/dom/Document.cpp
index d2102fb..6cf7bcc 100644
--- a/Source/core/dom/Document.cpp
+++ b/Source/core/dom/Document.cpp
@@ -28,6 +28,16 @@
 #include "config.h"
 #include "core/dom/Document.h"
 
+#include <wtf/CurrentTime.h>
+#include <wtf/HashFunctions.h>
+#include <wtf/MainThread.h>
+#include <wtf/MemoryInstrumentationHashCountedSet.h>
+#include <wtf/MemoryInstrumentationHashMap.h>
+#include <wtf/MemoryInstrumentationHashSet.h>
+#include <wtf/MemoryInstrumentationVector.h>
+#include <wtf/PassRefPtr.h>
+#include <wtf/StdLibExtras.h>
+#include <wtf/text/StringBuffer.h>
 #include "CSSValueKeywords.h"
 #include "HTMLElementFactory.h"
 #include "HTMLNames.h"
@@ -45,9 +55,9 @@
 #include "core/css/MediaQueryList.h"
 #include "core/css/MediaQueryMatcher.h"
 #include "core/css/StylePropertySet.h"
-#include "core/css/StyleResolver.h"
 #include "core/css/StyleSheetContents.h"
 #include "core/css/StyleSheetList.h"
+#include "core/css/resolver/StyleResolver.h"
 #include "core/dom/Attr.h"
 #include "core/dom/Attribute.h"
 #include "core/dom/CDATASection.h"
@@ -65,7 +75,6 @@
 #include "core/dom/DocumentType.h"
 #include "core/dom/Element.h"
 #include "core/dom/ElementShadow.h"
-#include "core/dom/EntityReference.h"
 #include "core/dom/Event.h"
 #include "core/dom/EventFactory.h"
 #include "core/dom/EventListener.h"
@@ -117,6 +126,7 @@
 #include "core/html/HTMLStyleElement.h"
 #include "core/html/HTMLTitleElement.h"
 #include "core/html/PluginDocument.h"
+#include "core/html/parser/HTMLDocumentParser.h"
 #include "core/html/parser/HTMLParserIdioms.h"
 #include "core/html/parser/NestingLevelIncrementer.h"
 #include "core/inspector/InspectorCounters.h"
@@ -149,8 +159,6 @@
 #include "core/page/PageConsole.h"
 #include "core/page/PageGroup.h"
 #include "core/page/PointerLockController.h"
-#include "core/page/SecurityOrigin.h"
-#include "core/page/SecurityPolicy.h"
 #include "core/page/Settings.h"
 #include "core/page/UserContentURLPattern.h"
 #include "core/page/animation/AnimationController.h"
@@ -160,7 +168,6 @@
 #include "core/platform/Language.h"
 #include "core/platform/Logging.h"
 #include "core/platform/PlatformKeyboardEvent.h"
-#include "core/platform/SchemeRegistry.h"
 #include "core/platform/Timer.h"
 #include "core/platform/chromium/TraceEvent.h"
 #include "core/platform/network/HTTPParsers.h"
@@ -186,16 +193,9 @@
 #include "core/xml/XSLTProcessor.h"
 #include "core/xml/parser/XMLDocumentParser.h"
 #include "modules/geolocation/GeolocationController.h"
-#include <wtf/CurrentTime.h>
-#include <wtf/HashFunctions.h>
-#include <wtf/MainThread.h>
-#include <wtf/MemoryInstrumentationHashCountedSet.h>
-#include <wtf/MemoryInstrumentationHashMap.h>
-#include <wtf/MemoryInstrumentationHashSet.h>
-#include <wtf/MemoryInstrumentationVector.h>
-#include <wtf/PassRefPtr.h>
-#include <wtf/StdLibExtras.h>
-#include <wtf/text/StringBuffer.h>
+#include "origin/SchemeRegistry.h"
+#include "origin/SecurityOrigin.h"
+#include "origin/SecurityPolicy.h"
 
 #if ENABLE(SVG)
 #include "SVGElementFactory.h"
@@ -373,7 +373,7 @@
 
 uint64_t Document::s_globalTreeVersion = 0;
 
-Document::Document(Frame* frame, const KURL& url, bool isXHTML, bool isHTML)
+Document::Document(Frame* frame, const KURL& url, DocumentClassFlags documentClasses)
     : ContainerNode(0, CreateDocument)
     , TreeScope(this)
     , m_styleResolverThrowawayTimer(this, &Document::styleResolverThrowawayTimerFired)
@@ -408,8 +408,7 @@
     , m_createRenderers(true)
     , m_accessKeyMapValid(false)
     , m_useSecureKeyboardEntryWhenActive(false)
-    , m_isXHTML(isXHTML)
-    , m_isHTML(isHTML)
+    , m_documentClasses(documentClasses)
     , m_isViewSource(false)
     , m_sawElementsInKnownNamespaces(false)
     , m_isSrcdocDocument(false)
@@ -436,6 +435,7 @@
 #ifndef NDEBUG
     , m_didDispatchViewportPropertiesChanged(false)
 #endif
+    , m_timeline(DocumentTimeline::create(this))
     , m_templateDocumentHost(0)
     , m_fontloader(0)
     , m_didAssociateFormControlsTimer(this, &Document::didAssociateFormControlsTimerFired)
@@ -760,8 +760,8 @@
         return 0;
     }
 
-    if (m_isXHTML)
-        return HTMLElementFactory::createHTMLElement(QualifiedName(nullAtom, name, xhtmlNamespaceURI), this, 0, false);
+    if (isXHTMLDocument() || isHTMLDocument())
+        return HTMLElementFactory::createHTMLElement(QualifiedName(nullAtom, isHTMLDocument() ? name.lower() : name, xhtmlNamespaceURI), this, 0, false);
 
     return createElement(QualifiedName(nullAtom, name, nullAtom), false);
 }
@@ -875,19 +875,6 @@
     return ProcessingInstruction::create(this, target, data);
 }
 
-PassRefPtr<EntityReference> Document::createEntityReference(const String& name, ExceptionCode& ec)
-{
-    if (!isValidName(name)) {
-        ec = INVALID_CHARACTER_ERR;
-        return 0;
-    }
-    if (isHTMLDocument()) {
-        ec = NOT_SUPPORTED_ERR;
-        return 0;
-    }
-    return EntityReference::create(this, name);
-}
-
 PassRefPtr<Text> Document::createEditingTextNode(const String& text)
 {
     return Text::createEditingText(this, text);
@@ -912,8 +899,6 @@
         return createTextNode(importedNode->nodeValue());
     case CDATA_SECTION_NODE:
         return createCDATASection(importedNode->nodeValue(), ec);
-    case ENTITY_REFERENCE_NODE:
-        return createEntityReference(importedNode->nodeName(), ec);
     case PROCESSING_INSTRUCTION_NODE:
         return createProcessingInstruction(importedNode->nodeName(), importedNode->nodeValue(), ec);
     case COMMENT_NODE:
@@ -987,11 +972,6 @@
         return 0;
     }
 
-    if (source->isReadOnlyNode()) {
-        ec = NO_MODIFICATION_ALLOWED_ERR;
-        return 0;
-    }
-
     EventQueueScope scope;
 
     switch (source->nodeType()) {
@@ -1664,7 +1644,7 @@
             if (!n->isElementNode())
                 continue;
             Element* element = toElement(n);
-            if (change >= Inherit || element->childNeedsStyleRecalc() || element->needsStyleRecalc())
+            if (shouldRecalcStyle(change, element))
                 element->recalcStyle(change);
         }
 
@@ -2018,10 +1998,22 @@
 
 PassRefPtr<DocumentParser> Document::createParser()
 {
+    if (isHTMLDocument()) {
+        bool reportErrors = InspectorInstrumentation::collectingHTMLParseErrors(this->page());
+        return HTMLDocumentParser::create(toHTMLDocument(this), reportErrors);
+    }
     // FIXME: this should probably pass the frame instead
     return XMLDocumentParser::create(this, view());
 }
 
+bool Document::isFrameSet() const
+{
+    if (!isHTMLDocument())
+        return false;
+    HTMLElement* bodyElement = body();
+    return bodyElement && bodyElement->hasTagName(framesetTag);
+}
+
 ScriptableDocumentParser* Document::scriptableDocumentParser() const
 {
     return parser() ? parser()->asScriptableDocumentParser() : 0;
@@ -2828,7 +2820,6 @@
     case DOCUMENT_FRAGMENT_NODE:
     case DOCUMENT_NODE:
     case ENTITY_NODE:
-    case ENTITY_REFERENCE_NODE:
     case NOTATION_NODE:
     case TEXT_NODE:
     case XPATH_NAMESPACE_NODE:
@@ -2887,7 +2878,6 @@
             case DOCUMENT_FRAGMENT_NODE:
             case DOCUMENT_NODE:
             case ENTITY_NODE:
-            case ENTITY_REFERENCE_NODE:
             case NOTATION_NODE:
             case TEXT_NODE:
             case XPATH_NAMESPACE_NODE:
@@ -2910,7 +2900,6 @@
         case DOCUMENT_FRAGMENT_NODE:
         case DOCUMENT_NODE:
         case ENTITY_NODE:
-        case ENTITY_REFERENCE_NODE:
         case NOTATION_NODE:
         case TEXT_NODE:
         case XPATH_NAMESPACE_NODE:
diff --git a/Source/core/dom/Document.h b/Source/core/dom/Document.h
index b5949b1..14d4b4b 100644
--- a/Source/core/dom/Document.h
+++ b/Source/core/dom/Document.h
@@ -28,6 +28,7 @@
 #ifndef Document_h
 #define Document_h
 
+#include "core/animation/DocumentTimeline.h"
 #include "core/dom/ContainerNode.h"
 #include "core/dom/DOMTimeStamp.h"
 #include "core/dom/DocumentEventQueue.h"
@@ -44,7 +45,7 @@
 #include "core/page/FocusDirection.h"
 #include "core/page/PageVisibilityState.h"
 #include "core/platform/PlatformScreen.h"
-#include "core/platform/ReferrerPolicy.h"
+#include "origin/ReferrerPolicy.h"
 #include "core/platform/Timer.h"
 #include "core/platform/graphics/Color.h"
 #include "core/platform/graphics/IntRect.h"
@@ -89,7 +90,6 @@
 class DocumentStyleSheetCollection;
 class DocumentType;
 class Element;
-class EntityReference;
 class Event;
 class EventListener;
 class FloatRect;
@@ -191,15 +191,27 @@
 
 typedef HashCountedSet<Node*> TouchEventTargetSet;
 
+enum DocumentClass {
+    DefaultDocumentClass = 0,
+    HTMLDocumentClass = 1,
+    XHTMLDocumentClass = 1 << 1,
+    ImageDocumentClass = 1 << 2,
+    PluginDocumentClass = 1 << 3,
+    MediaDocumentClass = 1 << 4,
+    SVGDocumentClass = 1 << 5,
+};
+
+typedef unsigned char DocumentClassFlags;
+
 class Document : public ContainerNode, public TreeScope, public ScriptExecutionContext {
 public:
     static PassRefPtr<Document> create(Frame* frame, const KURL& url)
     {
-        return adoptRef(new Document(frame, url, false, false));
+        return adoptRef(new Document(frame, url));
     }
     static PassRefPtr<Document> createXHTML(Frame* frame, const KURL& url)
     {
-        return adoptRef(new Document(frame, url, true, false));
+        return adoptRef(new Document(frame, url, XHTMLDocumentClass));
     }
     virtual ~Document();
 
@@ -293,8 +305,8 @@
     }
 
     bool hasManifest() const;
-    
-    virtual PassRefPtr<Element> createElement(const AtomicString& tagName, ExceptionCode&);
+
+    PassRefPtr<Element> createElement(const AtomicString& name, ExceptionCode&);
     PassRefPtr<DocumentFragment> createDocumentFragment();
     PassRefPtr<Text> createTextNode(const String& data);
     PassRefPtr<Comment> createComment(const String& data);
@@ -302,10 +314,9 @@
     PassRefPtr<ProcessingInstruction> createProcessingInstruction(const String& target, const String& data, ExceptionCode&);
     PassRefPtr<Attr> createAttribute(const String& name, ExceptionCode&);
     PassRefPtr<Attr> createAttributeNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode&, bool shouldIgnoreNamespaceChecks = false);
-    PassRefPtr<EntityReference> createEntityReference(const String& name, ExceptionCode&);
     PassRefPtr<Node> importNode(Node* importedNode, ExceptionCode& ec) { return importNode(importedNode, true, ec); }
     PassRefPtr<Node> importNode(Node* importedNode, bool deep, ExceptionCode&);
-    virtual PassRefPtr<Element> createElementNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode&);
+    PassRefPtr<Element> createElementNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode&);
     PassRefPtr<Element> createElement(const QualifiedName&, bool createdByParser);
 
     bool cssStickyPositionEnabled() const;
@@ -391,20 +402,20 @@
     PassRefPtr<HTMLCollection> windowNamedItems(const AtomicString& name);
     PassRefPtr<HTMLCollection> documentNamedItems(const AtomicString& name);
 
-    // Other methods (not part of DOM)
-    bool isHTMLDocument() const { return m_isHTML; }
-    bool isXHTMLDocument() const { return m_isXHTML; }
-    virtual bool isImageDocument() const { return false; }
+    bool isHTMLDocument() const { return m_documentClasses & HTMLDocumentClass; }
+    bool isXHTMLDocument() const { return m_documentClasses & XHTMLDocumentClass; }
+    bool isImageDocument() const { return m_documentClasses & ImageDocumentClass; }
+    bool isSVGDocument() const { return m_documentClasses & SVGDocumentClass; }
+    bool isPluginDocument() const { return m_documentClasses & PluginDocumentClass; }
+    bool isMediaDocument() const { return m_documentClasses & MediaDocumentClass; }
+
 #if ENABLE(SVG)
-    virtual bool isSVGDocument() const { return false; }
     bool hasSVGRootNode() const;
 #else
-    static bool isSVGDocument() { return false; }
     static bool hasSVGRootNode() { return false; }
 #endif
-    virtual bool isPluginDocument() const { return false; }
-    virtual bool isMediaDocument() const { return false; }
-    virtual bool isFrameSet() const { return false; }
+
+    bool isFrameSet() const;
 
     bool isSrcdocDocument() const { return m_isSrcdocDocument; }
 
@@ -899,10 +910,10 @@
 
     virtual void postTask(PassOwnPtr<Task>); // Executes the task on context's thread asynchronously.
 
-    virtual void suspendScriptedAnimationControllerCallbacks();
-    virtual void resumeScriptedAnimationControllerCallbacks();
-    
-    virtual void finishedParsing();
+    void suspendScriptedAnimationControllerCallbacks();
+    void resumeScriptedAnimationControllerCallbacks();
+
+    void finishedParsing();
 
     void documentWillBecomeInactive();
 
@@ -1089,6 +1100,8 @@
     // Return a Locale for the default locale if the argument is null or empty.
     Locale& getCachedLocale(const AtomicString& locale = nullAtom);
 
+    DocumentTimeline* timeline() { return m_timeline.get(); }
+
     void addToTopLayer(Element*);
     void removeFromTopLayer(Element*);
     const Vector<RefPtr<Element> >& topLayerElements() const { return m_topLayerElements; }
@@ -1108,7 +1121,7 @@
     PassRefPtr<FontLoader> fontloader();
 
 protected:
-    Document(Frame*, const KURL&, bool isXHTML, bool isHTML);
+    Document(Frame*, const KURL&, DocumentClassFlags = DefaultDocumentClass);
 
     virtual void didUpdateSecurityOrigin() OVERRIDE;
 
@@ -1355,8 +1368,7 @@
 
     bool m_useSecureKeyboardEntryWhenActive;
 
-    bool m_isXHTML;
-    bool m_isHTML;
+    DocumentClassFlags m_documentClasses;
 
     bool m_isViewSource;
     bool m_sawElementsInKnownNamespaces;
@@ -1431,6 +1443,8 @@
     typedef HashMap<AtomicString, OwnPtr<Locale> > LocaleIdentifierToLocaleMap;
     LocaleIdentifierToLocaleMap m_localeCache;
 
+    RefPtr<DocumentTimeline> m_timeline;
+
     RefPtr<Document> m_templateDocument;
     Document* m_templateDocumentHost; // Manually managed weakref (backpointer from m_templateDocument).
 
diff --git a/Source/core/dom/Document.idl b/Source/core/dom/Document.idl
index 985097c..7f756cf 100644
--- a/Source/core/dom/Document.idl
+++ b/Source/core/dom/Document.idl
@@ -35,7 +35,6 @@
     [RaisesException] ProcessingInstruction createProcessingInstruction([Default=Undefined] optional DOMString target,
                                                                                  [Default=Undefined] optional DOMString data);
     [RaisesException] Attr createAttribute([Default=Undefined] optional DOMString name);
-    [RaisesException] EntityReference createEntityReference([Default=Undefined] optional DOMString name);
     [PerWorldBindings] NodeList           getElementsByTagName([Default=Undefined] optional DOMString tagname);
 
     // Introduced in DOM Level 2:
@@ -137,7 +136,7 @@
 
     [PerWorldBindings] NodeList getElementsByName([Default=Undefined] optional DOMString elementName);
 
-    [Custom, PerWorldBindings, ActivityLog=AccessForIsolatedWorlds] attribute Location location;
+    [Custom, Replaceable, PerWorldBindings, ActivityLog=AccessForIsolatedWorlds] readonly attribute Location location;
 
     // IE extensions
 
diff --git a/Source/core/dom/DocumentFragment.cpp b/Source/core/dom/DocumentFragment.cpp
index 037b207..6c56322 100644
--- a/Source/core/dom/DocumentFragment.cpp
+++ b/Source/core/dom/DocumentFragment.cpp
@@ -43,6 +43,11 @@
     return adoptRef(new DocumentFragment(document, Node::CreateDocumentFragment));
 }
 
+PassRefPtr<DocumentFragment> DocumentFragment::create(ScriptExecutionContext* context)
+{
+    return adoptRef(new DocumentFragment(toDocument(context), Node::CreateDocumentFragment));
+}
+
 String DocumentFragment::nodeName() const
 {
     return "#document-fragment";
@@ -61,7 +66,6 @@
         case COMMENT_NODE:
         case TEXT_NODE:
         case CDATA_SECTION_NODE:
-        case ENTITY_REFERENCE_NODE:
             return true;
         default:
             return false;
diff --git a/Source/core/dom/DocumentFragment.h b/Source/core/dom/DocumentFragment.h
index bb2fbb3..5d713fe 100644
--- a/Source/core/dom/DocumentFragment.h
+++ b/Source/core/dom/DocumentFragment.h
@@ -29,9 +29,12 @@
 
 namespace WebCore {
 
+class ScriptExecutionContext;
+
 class DocumentFragment : public ContainerNode {
 public:
     static PassRefPtr<DocumentFragment> create(Document*);
+    static PassRefPtr<DocumentFragment> create(ScriptExecutionContext*);
 
     void parseHTML(const String&, Element* contextElement, ParserContentPolicy = AllowScriptingContent);
     bool parseXML(const String&, Element* contextElement, ParserContentPolicy = AllowScriptingContent);
diff --git a/Source/core/dom/DocumentFragment.idl b/Source/core/dom/DocumentFragment.idl
index e8cd287..0837e78 100644
--- a/Source/core/dom/DocumentFragment.idl
+++ b/Source/core/dom/DocumentFragment.idl
@@ -18,6 +18,8 @@
  */
 
 [
+    Constructor,
+    CallWith=ScriptExecutionContext,
     SkipVTableValidation
 ] interface DocumentFragment : Node {
     // NodeSelector - Selector API
diff --git a/Source/core/dom/DocumentStyleSheetCollection.cpp b/Source/core/dom/DocumentStyleSheetCollection.cpp
index 7f7bfd3..4735ab2 100644
--- a/Source/core/dom/DocumentStyleSheetCollection.cpp
+++ b/Source/core/dom/DocumentStyleSheetCollection.cpp
@@ -34,9 +34,9 @@
 #include "core/css/CSSStyleSheet.h"
 #include "core/css/SelectorChecker.h"
 #include "core/css/StyleInvalidationAnalysis.h"
-#include "core/css/StyleResolver.h"
 #include "core/css/StyleSheetContents.h"
 #include "core/css/StyleSheetList.h"
+#include "core/css/resolver/StyleResolver.h"
 #include "core/dom/Document.h"
 #include "core/dom/Element.h"
 #include "core/dom/ProcessingInstruction.h"
diff --git a/Source/core/dom/Element.cpp b/Source/core/dom/Element.cpp
index 1ea9515..cd5ec55 100644
--- a/Source/core/dom/Element.cpp
+++ b/Source/core/dom/Element.cpp
@@ -33,7 +33,7 @@
 #include "core/css/CSSParser.h"
 #include "core/css/CSSSelectorList.h"
 #include "core/css/StylePropertySet.h"
-#include "core/css/StyleResolver.h"
+#include "core/css/resolver/StyleResolver.h"
 #include "core/dom/Attr.h"
 #include "core/dom/ClientRect.h"
 #include "core/dom/ClientRectList.h"
@@ -183,13 +183,6 @@
     return 0;
 }
 
-// Need a template since ElementShadow is not a Node, but has the style recalc methods.
-template<class T>
-static inline bool shouldRecalcStyle(Node::StyleChange change, const T* node)
-{
-    return change >= Node::Inherit || node->childNeedsStyleRecalc() || node->needsStyleRecalc();
-}
-
 PassRefPtr<Element> Element::create(const QualifiedName& tagName, Document* document)
 {
     return adoptRef(new Element(tagName, document, CreateElement));
@@ -340,6 +333,36 @@
     return rareData->attributeMap();
 }
 
+void Element::addActiveAnimation(Animation* animation)
+{
+    ElementRareData* rareData = ensureElementRareData();
+    if (!rareData->activeAnimations())
+        rareData->setActiveAnimations(adoptPtr(new Vector<Animation*>));
+    rareData->activeAnimations()->append(animation);
+}
+
+void Element::removeActiveAnimation(Animation* animation)
+{
+    ElementRareData* rareData = elementRareData();
+    ASSERT(rareData);
+    size_t position = rareData->activeAnimations()->find(animation);
+    ASSERT(position != notFound);
+    rareData->activeAnimations()->remove(position);
+}
+
+bool Element::hasActiveAnimations() const
+{
+    return hasRareData() && elementRareData()->activeAnimations()
+        && elementRareData()->activeAnimations()->size();
+}
+
+Vector<Animation*>* Element::activeAnimations() const
+{
+    if (!elementRareData())
+        return 0;
+    return elementRareData()->activeAnimations();
+}
+
 Node::NodeType Element::nodeType() const
 {
     return ELEMENT_NODE;
@@ -1555,7 +1578,6 @@
     case COMMENT_NODE:
     case PROCESSING_INSTRUCTION_NODE:
     case CDATA_SECTION_NODE:
-    case ENTITY_REFERENCE_NODE:
         return true;
     default:
         break;
@@ -2889,6 +2911,11 @@
     info.addMember(m_elementData, "elementData");
 }
 
+InputMethodContext* Element::getInputContext()
+{
+    return ensureElementRareData()->ensureInputMethodContext(toHTMLElement(this));
+}
+
 #if ENABLE(SVG)
 bool Element::hasPendingResources() const
 {
diff --git a/Source/core/dom/Element.h b/Source/core/dom/Element.h
index 0edd20f..8b2580b 100644
--- a/Source/core/dom/Element.h
+++ b/Source/core/dom/Element.h
@@ -35,6 +35,8 @@
 
 namespace WebCore {
 
+class Animation;
+
 class Attr;
 class ClientRect;
 class ClientRectList;
@@ -43,14 +45,15 @@
 class Element;
 class ElementRareData;
 class ElementShadow;
-class ShareableElementData;
+class InputMethodContext;
 class IntSize;
 class Locale;
-class UniqueElementData;
 class PseudoElement;
 class RenderRegion;
 class ShadowRoot;
+class ShareableElementData;
 class StylePropertySet;
+class UniqueElementData;
 
 class ElementData : public RefCounted<ElementData> {
     WTF_MAKE_FAST_ALLOCATED;
@@ -596,6 +599,13 @@
 
     virtual void reportMemoryUsage(MemoryObjectInfo*) const OVERRIDE;
 
+    void addActiveAnimation(Animation*);
+    void removeActiveAnimation(Animation*);
+    bool hasActiveAnimations() const;
+    Vector<Animation*>* activeAnimations() const;
+
+    InputMethodContext* getInputContext();
+
 protected:
     Element(const QualifiedName& tagName, Document* document, ConstructionType type)
         : ContainerNode(document, type)
diff --git a/Source/core/dom/ElementRareData.cpp b/Source/core/dom/ElementRareData.cpp
index 72ce782..24e14a9 100644
--- a/Source/core/dom/ElementRareData.cpp
+++ b/Source/core/dom/ElementRareData.cpp
@@ -41,7 +41,7 @@
     unsigned bitfields;
     LayoutSize sizeForResizing;
     IntSize scrollOffset;
-    void* pointers[7];
+    void* pointers[9];
 };
 
 COMPILE_ASSERT(sizeof(ElementRareData) == sizeof(SameSizeAsElementRareData), ElementRareDataShouldStaySmall);
diff --git a/Source/core/dom/ElementRareData.h b/Source/core/dom/ElementRareData.h
index effc75d..fe35129 100644
--- a/Source/core/dom/ElementRareData.h
+++ b/Source/core/dom/ElementRareData.h
@@ -22,17 +22,22 @@
 #ifndef ElementRareData_h
 #define ElementRareData_h
 
+#include "core/animation/Animation.h"
 #include "core/dom/DatasetDOMStringMap.h"
 #include "core/dom/ElementShadow.h"
 #include "core/dom/NamedNodeMap.h"
 #include "core/dom/NodeRareData.h"
 #include "core/dom/PseudoElement.h"
 #include "core/html/ClassList.h"
+#include "core/html/ime/InputMethodContext.h"
 #include "core/rendering/style/StyleInheritedData.h"
 #include <wtf/OwnPtr.h>
 
 namespace WebCore {
 
+class Animation;
+class HTMLElement;
+
 class ElementRareData : public NodeRareData {
 public:
     static PassOwnPtr<ElementRareData> create(RenderObject* renderer) { return adoptPtr(new ElementRareData(renderer)); }
@@ -122,11 +127,24 @@
     IntSize savedLayerScrollOffset() const { return m_savedLayerScrollOffset; }
     void setSavedLayerScrollOffset(IntSize size) { m_savedLayerScrollOffset = size; }
 
+    Vector<Animation*>* activeAnimations() { return m_activeAnimations.get(); }
+    void setActiveAnimations(PassOwnPtr<Vector<Animation*> > animations)
+    {
+        m_activeAnimations = animations;
+    }
+
 #if ENABLE(SVG)
     bool hasPendingResources() const { return m_hasPendingResources; }
     void setHasPendingResources(bool has) { m_hasPendingResources = has; }
 #endif
 
+    InputMethodContext* ensureInputMethodContext(HTMLElement* element)
+    {
+        if (!m_inputMethodContext)
+            m_inputMethodContext = InputMethodContext::create(element);
+        return m_inputMethodContext.get();
+    }
+
 private:
     short m_tabIndex;
     unsigned short m_childIndex;
@@ -159,6 +177,9 @@
     OwnPtr<ClassList> m_classList;
     OwnPtr<ElementShadow> m_shadow;
     OwnPtr<NamedNodeMap> m_attributeMap;
+    OwnPtr<InputMethodContext> m_inputMethodContext;
+
+    OwnPtr<Vector<Animation*> > m_activeAnimations;
 
     RefPtr<PseudoElement> m_generatedBefore;
     RefPtr<PseudoElement> m_generatedAfter;
diff --git a/Source/core/dom/EntityReference.cpp b/Source/core/dom/EntityReference.cpp
deleted file mode 100644
index f461e28..0000000
--- a/Source/core/dom/EntityReference.cpp
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (C) 2000 Peter Kelly (pmk@post.com)
- * Copyright (C) 2006, 2008, 2009 Apple Inc. All rights reserved.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * 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/EntityReference.h"
-
-#include "core/dom/Document.h"
-
-namespace WebCore {
-
-inline EntityReference::EntityReference(Document* document, const String& entityName)
-    : ContainerNode(document)
-    , m_entityName(entityName)
-{
-    ScriptWrappable::init(this);
-}
-
-PassRefPtr<EntityReference> EntityReference::create(Document* document, const String& entityName)
-{
-    return adoptRef(new EntityReference(document, entityName));
-}
-
-String EntityReference::nodeName() const
-{
-    return m_entityName;
-}
-
-Node::NodeType EntityReference::nodeType() const
-{
-    return ENTITY_REFERENCE_NODE;
-}
-
-PassRefPtr<Node> EntityReference::cloneNode(bool)
-{
-    return create(document(), m_entityName);
-}
-
-} // namespace
diff --git a/Source/core/dom/EntityReference.h b/Source/core/dom/EntityReference.h
deleted file mode 100644
index 31320a7..0000000
--- a/Source/core/dom/EntityReference.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (C) 2000 Peter Kelly (pmk@post.com)
- * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * 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 EntityReference_h
-#define EntityReference_h
-
-#include "core/dom/ContainerNode.h"
-
-namespace WebCore {
-
-class EntityReference FINAL : public ContainerNode {
-public:
-    static PassRefPtr<EntityReference> create(Document*, const String& entityName);
-
-private:
-    EntityReference(Document*, const String& entityName);
-
-    virtual String nodeName() const;
-    virtual NodeType nodeType() const;
-    virtual PassRefPtr<Node> cloneNode(bool deep);
-
-    String m_entityName;
-};
-
-} //namespace
-
-#endif
diff --git a/Source/core/dom/EntityReference.idl b/Source/core/dom/EntityReference.idl
deleted file mode 100644
index 363554a..0000000
--- a/Source/core/dom/EntityReference.idl
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
- *
- * 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.
- */
-
-interface EntityReference : Node {
-};
-
diff --git a/Source/core/dom/Event.cpp b/Source/core/dom/Event.cpp
index 637ca94..de51a3f 100644
--- a/Source/core/dom/Event.cpp
+++ b/Source/core/dom/Event.cpp
@@ -26,6 +26,7 @@
 #include "core/dom/EventDispatcher.h"
 #include "core/dom/EventNames.h"
 #include "core/dom/EventTarget.h"
+#include "core/dom/StaticNodeList.h"
 #include "core/dom/UserGestureIndicator.h"
 #include "core/dom/WebCoreMemoryInstrumentation.h"
 #include <wtf/CurrentTime.h>
@@ -201,4 +202,20 @@
     m_underlyingEvent = ue;
 }
 
+PassRefPtr<NodeList> Event::path() const
+{
+    if (!m_currentTarget || !m_currentTarget->toNode())
+        return StaticNodeList::createEmpty();
+    TreeScope* currentScope = m_currentTarget->toNode()->treeScope();
+    Vector<RefPtr<Node> > nodes;
+    size_t eventPathSize = m_eventPath.size();
+    for (size_t i = 0; i < eventPathSize; ++i) {
+        Node* node = m_eventPath[i]->node();
+        ASSERT(node);
+        if (node->treeScope()->isInclusiveAncestorOf(currentScope))
+            nodes.append(node);
+    }
+    return StaticNodeList::adopt(nodes);
+}
+
 } // namespace WebCore
diff --git a/Source/core/dom/Event.h b/Source/core/dom/Event.h
index 1a2942e..0ec17f8 100644
--- a/Source/core/dom/Event.h
+++ b/Source/core/dom/Event.h
@@ -157,6 +157,7 @@
     void setUnderlyingEvent(PassRefPtr<Event>);
 
     EventPath& eventPath() { return m_eventPath; }
+    PassRefPtr<NodeList> path() const;
 
     virtual bool storesResultAsString() const;
     virtual void storeResult(const String&);
diff --git a/Source/core/dom/Event.idl b/Source/core/dom/Event.idl
index 82b8e28..aa4f375 100644
--- a/Source/core/dom/Event.idl
+++ b/Source/core/dom/Event.idl
@@ -73,6 +73,8 @@
              attribute boolean          returnValue;
              attribute boolean          cancelBubble;
 
+    [EnabledAtRuntime=experimentalShadowDOM] NodeList path();
+
     [Custom] readonly attribute Clipboard        clipboardData;
 };
 
diff --git a/Source/core/dom/EventContext.cpp b/Source/core/dom/EventContext.cpp
index 5161783..7b8dd56 100644
--- a/Source/core/dom/EventContext.cpp
+++ b/Source/core/dom/EventContext.cpp
@@ -129,7 +129,7 @@
 void TouchEventContext::checkReachability(TouchList* touchList) const
 {
     for (size_t i = 0; i < touchList->length(); ++i)
-        ASSERT(isReachable(touchList->item(i)->target()->toNode()));
+        ASSERT(touchList->item(i)->target()->toNode()->treeScope()->isInclusiveAncestorOf(m_node->treeScope()));
 }
 #endif
 
diff --git a/Source/core/dom/EventContext.h b/Source/core/dom/EventContext.h
index 0a21f59..5017e5c 100644
--- a/Source/core/dom/EventContext.h
+++ b/Source/core/dom/EventContext.h
@@ -53,7 +53,6 @@
 protected:
 #ifndef NDEBUG
     bool isUnreachableNode(EventTarget*);
-    bool isReachable(Node*) const;
 #endif
     RefPtr<Node> m_node;
     RefPtr<EventTarget> m_currentTarget;
@@ -107,18 +106,7 @@
 inline bool EventContext::isUnreachableNode(EventTarget* target)
 {
     // FIXME: Checks also for SVG elements.
-    return target && target->toNode() && !target->toNode()->isSVGElement() && !isReachable(target->toNode());
-}
-
-inline bool EventContext::isReachable(Node* target) const
-{
-    ASSERT(target);
-    TreeScope* targetScope = target->treeScope();
-    for (TreeScope* scope = m_node->treeScope(); scope; scope = scope->parentTreeScope()) {
-        if (scope == targetScope)
-            return true;
-    }
-    return false;
+    return target && target->toNode() && !target->toNode()->isSVGElement() && !target->toNode()->treeScope()->isInclusiveAncestorOf(m_node->treeScope());
 }
 #endif
 
diff --git a/Source/core/dom/EventNames.cpp b/Source/core/dom/EventNames.cpp
index 3d68964..9821d03 100644
--- a/Source/core/dom/EventNames.cpp
+++ b/Source/core/dom/EventNames.cpp
@@ -31,9 +31,9 @@
 
 EventNames::EventNames()
     : dummy(0)
-DOM_EVENT_NAMES_FOR_EACH(INITIALIZE_EVENT_NAME)
-DOM_EVENT_INTERFACES_FOR_EACH(INITIALIZE_EVENT_INTERFACE)
-DOM_EVENT_TARGET_INTERFACES_FOR_EACH(INITIALIZE_EVENT_INTERFACE)
+EVENT_NAMES_FOR_EACH(INITIALIZE_EVENT_NAME)
+EVENT_INTERFACES_FOR_EACH(INITIALIZE_EVENT_INTERFACE)
+EVENT_TARGET_INTERFACES_FOR_EACH(INITIALIZE_EVENT_INTERFACE)
 {
 }
 
diff --git a/Source/core/dom/EventNames.h b/Source/core/dom/EventNames.h
index 12db1a6..a436fee 100644
--- a/Source/core/dom/EventNames.h
+++ b/Source/core/dom/EventNames.h
@@ -29,7 +29,7 @@
 
 namespace WebCore {
 
-#define DOM_EVENT_NAMES_FOR_EACH(macro) \
+#define EVENT_NAMES_FOR_EACH(macro) \
     \
     macro(abort) \
     macro(beforecopy) \
@@ -73,6 +73,7 @@
     macro(focusin) \
     macro(focusout) \
     macro(gesturetap) \
+    macro(gesturetapunconfirmed) \
     macro(gesturetapdown) \
     macro(gesturescrollstart) \
     macro(gesturescrollend) \
@@ -260,7 +261,7 @@
     macro(securitypolicyviolation) \
     \
 
-// end of DOM_EVENT_NAMES_FOR_EACH
+// end of EVENT_NAMES_FOR_EACH
 
     class EventNames {
         WTF_MAKE_NONCOPYABLE(EventNames); WTF_MAKE_FAST_ALLOCATED;
@@ -270,14 +271,14 @@
         friend class ThreadGlobalData;
 
     public:
-        #define DOM_EVENT_NAMES_DECLARE(name) AtomicString name##Event;
-        DOM_EVENT_NAMES_FOR_EACH(DOM_EVENT_NAMES_DECLARE)
-        #undef DOM_EVENT_NAMES_DECLARE
+        #define EVENT_NAMES_DECLARE(name) AtomicString name##Event;
+        EVENT_NAMES_FOR_EACH(EVENT_NAMES_DECLARE)
+        #undef EVENT_NAMES_DECLARE
 
-        #define DOM_EVENT_INTERFACE_DECLARE(name) AtomicString interfaceFor##name;
-        DOM_EVENT_INTERFACES_FOR_EACH(DOM_EVENT_INTERFACE_DECLARE)
-        DOM_EVENT_TARGET_INTERFACES_FOR_EACH(DOM_EVENT_INTERFACE_DECLARE)
-        #undef DOM_EVENT_INTERFACE_DECLARE
+        #define EVENT_INTERFACE_DECLARE(name) AtomicString interfaceFor##name;
+        EVENT_INTERFACES_FOR_EACH(EVENT_INTERFACE_DECLARE)
+        EVENT_TARGET_INTERFACES_FOR_EACH(EVENT_INTERFACE_DECLARE)
+        #undef EVENT_INTERFACE_DECLARE
 
         inline bool isTouchEventType(const AtomicString& eventType) const
         {
@@ -290,6 +291,7 @@
         inline bool isGestureEventType(const AtomicString& eventType) const
         {
             return eventType == gesturetapEvent
+                || eventType == gesturetapunconfirmedEvent
                 || eventType == gesturetapdownEvent
                 || eventType == gesturescrollstartEvent
                 || eventType == gesturescrollendEvent
diff --git a/Source/core/dom/EventTarget.idl b/Source/core/dom/EventTarget.idl
index 8647c27..32af401 100644
--- a/Source/core/dom/EventTarget.idl
+++ b/Source/core/dom/EventTarget.idl
@@ -19,6 +19,7 @@
  */
 
 [
+    NoInterfaceObject,
     CustomToV8,
     DoNotGenerateWrap,
     EventTarget
diff --git a/Source/core/dom/EventTargetFactory.in b/Source/core/dom/EventTargetFactory.in
index d5e4f56..c62e1da 100644
--- a/Source/core/dom/EventTargetFactory.in
+++ b/Source/core/dom/EventTargetFactory.in
@@ -33,7 +33,7 @@
 modules/mediastream/RTCDataChannel
 modules/mediastream/RTCDTMFSender
 modules/mediastream/RTCPeerConnection
-modules/notifications/Notification conditional=NOTIFICATIONS|LEGACY_NOTIFICATIONS
+modules/notifications/Notification conditional=NOTIFICATIONS
 modules/speech/SpeechRecognition
 modules/speech/SpeechSynthesisUtterance
 modules/webaudio/AudioContext conditional=WEB_AUDIO
diff --git a/Source/core/dom/ExceptionCode.h b/Source/core/dom/ExceptionCode.h
index 88f5f10..84b520e 100644
--- a/Source/core/dom/ExceptionCode.h
+++ b/Source/core/dom/ExceptionCode.h
@@ -20,7 +20,7 @@
 #define ExceptionCode_h
 
 // FIXME: Move this header into the files that actually need it.
-#include "ExceptionCodeDescription.h"
+#include "DOMException.h"
 
 namespace WebCore {
 
diff --git a/Source/core/dom/GestureEvent.cpp b/Source/core/dom/GestureEvent.cpp
index 7a60317..5b1be80 100644
--- a/Source/core/dom/GestureEvent.cpp
+++ b/Source/core/dom/GestureEvent.cpp
@@ -48,6 +48,8 @@
         eventType = eventNames().gesturescrollupdateEvent; break;
     case PlatformEvent::GestureTap:
         eventType = eventNames().gesturetapEvent; break;
+    case PlatformEvent::GestureTapUnconfirmed:
+        eventType = eventNames().gesturetapunconfirmedEvent; break;
     case PlatformEvent::GestureTapDown:
         eventType = eventNames().gesturetapdownEvent; break;
     case PlatformEvent::GestureTwoFingerTap:
diff --git a/Source/core/dom/MessagePort.cpp b/Source/core/dom/MessagePort.cpp
index c18b0cc..0068061 100644
--- a/Source/core/dom/MessagePort.cpp
+++ b/Source/core/dom/MessagePort.cpp
@@ -27,16 +27,16 @@
 #include "config.h"
 #include "core/dom/MessagePort.h"
 
+#include <wtf/text/AtomicString.h>
 #include "core/dom/Document.h"
 #include "core/dom/EventException.h"
 #include "core/dom/EventNames.h"
 #include "core/dom/ExceptionCode.h"
 #include "core/dom/MessageEvent.h"
 #include "core/page/DOMWindow.h"
-#include "core/page/SecurityOrigin.h"
 #include "core/platform/Timer.h"
 #include "core/workers/WorkerContext.h"
-#include <wtf/text/AtomicString.h>
+#include "origin/SecurityOrigin.h"
 
 namespace WebCore {
 
diff --git a/Source/core/dom/NamedFlow.idl b/Source/core/dom/NamedFlow.idl
index b7e09e5..c95891f 100644
--- a/Source/core/dom/NamedFlow.idl
+++ b/Source/core/dom/NamedFlow.idl
@@ -28,6 +28,7 @@
  */
 
 [
+    NoInterfaceObject,
     EnabledAtRuntime=cssRegions,
     EventTarget,
     InterfaceName=WebKitNamedFlow,
diff --git a/Source/core/dom/NamedNodeMap.idl b/Source/core/dom/NamedNodeMap.idl
index 17e7736..070beb3 100644
--- a/Source/core/dom/NamedNodeMap.idl
+++ b/Source/core/dom/NamedNodeMap.idl
@@ -20,11 +20,10 @@
 
 [
     GenerateIsReachable=ImplElementRoot,
-    CustomNamedGetter,
     ImplementationLacksVTable
 ] interface NamedNodeMap {
 
-    Node getNamedItem([Default=Undefined] optional DOMString name);
+    getter Node getNamedItem([Default=Undefined] optional DOMString name);
 
     [RaisesException] Node setNamedItem([Default=Undefined] optional Node node);
 
diff --git a/Source/core/dom/Node.cpp b/Source/core/dom/Node.cpp
index 4b0e256..79136ad 100644
--- a/Source/core/dom/Node.cpp
+++ b/Source/core/dom/Node.cpp
@@ -34,7 +34,7 @@
 #include "core/css/CSSSelectorList.h"
 #include "core/css/CSSStyleRule.h"
 #include "core/css/CSSStyleSheet.h"
-#include "core/css/StyleResolver.h"
+#include "core/css/resolver/StyleResolver.h"
 #include "core/dom/Attr.h"
 #include "core/dom/Attribute.h"
 #include "core/dom/BeforeLoadEvent.h"
@@ -150,7 +150,6 @@
     size_t textNodes = 0;
     size_t cdataNodes = 0;
     size_t commentNodes = 0;
-    size_t entityReferenceNodes = 0;
     size_t entityNodes = 0;
     size_t piNodes = 0;
     size_t documentNodes = 0;
@@ -217,10 +216,6 @@
                 ++commentNodes;
                 break;
             }
-            case ENTITY_REFERENCE_NODE: {
-                ++entityReferenceNodes;
-                break;
-            }
             case ENTITY_NODE: {
                 ++entityNodes;
                 break;
@@ -264,7 +259,6 @@
     printf("  Number of Text nodes: %zu\n", textNodes);
     printf("  Number of CDATASection nodes: %zu\n", cdataNodes);
     printf("  Number of Comment nodes: %zu\n", commentNodes);
-    printf("  Number of EntityReference nodes: %zu\n", entityReferenceNodes);
     printf("  Number of Entity nodes: %zu\n", entityNodes);
     printf("  Number of ProcessingInstruction nodes: %zu\n", piNodes);
     printf("  Number of Document nodes: %zu\n", documentNodes);
@@ -496,12 +490,6 @@
 
 void Node::setNodeValue(const String& /*nodeValue*/, ExceptionCode& ec)
 {
-    // NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly
-    if (isReadOnlyNode()) {
-        ec = NO_MODIFICATION_ALLOWED_ERR;
-        return;
-    }
-
     // By default, setting nodeValue has no effect.
 }
 
@@ -1027,11 +1015,6 @@
         return;
     }
 
-    if (isReadOnlyNode()) {
-        ec = NO_MODIFICATION_ALLOWED_ERR;
-        return;
-    }
-
     // FIXME: Raise NAMESPACE_ERR if prefix is malformed per the Namespaces in XML specification.
 
     const AtomicString& nodeNamespaceURI = namespaceURI();
@@ -1688,7 +1671,6 @@
     // Fall through.
     case Node::ATTRIBUTE_NODE:
     case Node::ENTITY_NODE:
-    case Node::ENTITY_REFERENCE_NODE:
     case Node::DOCUMENT_FRAGMENT_NODE:
         isNullString = false;
         for (Node* child = node->firstChild(); child; child = child->nextSibling()) {
@@ -1726,7 +1708,6 @@
         case ELEMENT_NODE:
         case ATTRIBUTE_NODE:
         case ENTITY_NODE:
-        case ENTITY_REFERENCE_NODE:
         case DOCUMENT_FRAGMENT_NODE: {
             RefPtr<ContainerNode> container = toContainerNode(this);
             ChildListMutationScope mutation(this);
@@ -2508,18 +2489,12 @@
 
 void Node::dispatchFocusEvent(PassRefPtr<Node> oldFocusedNode, FocusDirection)
 {
-    if (document()->page())
-        document()->page()->chrome()->client()->elementDidFocus(this);
-
     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)
 {
-    if (document()->page())
-        document()->page()->chrome()->client()->elementDidBlur(this);
-
     RefPtr<FocusEvent> event = FocusEvent::create(eventNames().blurEvent, false, false, document()->defaultView(), 0, newFocusedNode);
     EventDispatcher::dispatchEvent(this, BlurEventDispatchMediator::create(event.release()));
 }
diff --git a/Source/core/dom/Node.h b/Source/core/dom/Node.h
index 0b74968..b919d19 100644
--- a/Source/core/dom/Node.h
+++ b/Source/core/dom/Node.h
@@ -127,7 +127,6 @@
         ATTRIBUTE_NODE = 2,
         TEXT_NODE = 3,
         CDATA_SECTION_NODE = 4,
-        ENTITY_REFERENCE_NODE = 5,
         ENTITY_NODE = 6,
         PROCESSING_INSTRUCTION_NODE = 7,
         COMMENT_NODE = 8,
@@ -137,6 +136,15 @@
         NOTATION_NODE = 12,
         XPATH_NAMESPACE_NODE = 13,
     };
+
+    // EntityReference nodes are deprecated and impossible to create in WebKit.
+    // We want Node.ENTITY_REFERNCE_NODE to exist in JS and this enum, makes the bindings
+    // generation not complain about ENTITY_REFERENCE_NODE being missing from the implementation
+    // while not requiring all switch(NodeType) blocks to include this deprecated constant.
+    enum DeprecatedNodeType {
+        ENTITY_REFERENCE_NODE = 5
+    };
+
     enum DocumentPosition {
         DOCUMENT_POSITION_EQUIVALENT = 0x00,
         DOCUMENT_POSITION_DISCONNECTED = 0x01,
@@ -474,7 +482,6 @@
     bool isInShadowTree() const { return getFlag(IsInShadowTreeFlag); }
     bool isInTreeScope() const { return getFlag(static_cast<NodeFlags>(InDocumentFlag | IsInShadowTreeFlag)); }
 
-    bool isReadOnlyNode() const { return nodeType() == ENTITY_REFERENCE_NODE; }
     bool isDocumentTypeNode() const { return nodeType() == DOCUMENT_TYPE_NODE; }
     virtual bool childTypeAllowed(NodeType) const { return false; }
     unsigned childNodeCount() const;
@@ -879,6 +886,13 @@
     lazyAttach(shouldSetAttached);
 }
 
+// Need a template since ElementShadow is not a Node, but has the style recalc methods.
+template<class T>
+inline bool shouldRecalcStyle(Node::StyleChange change, const T* node)
+{
+    return change >= Node::Inherit || node->childNeedsStyleRecalc() || node->needsStyleRecalc();
+}
+
 } //namespace
 
 #ifndef NDEBUG
diff --git a/Source/core/dom/Node.idl b/Source/core/dom/Node.idl
index 28d760e..ba0eb17 100644
--- a/Source/core/dom/Node.idl
+++ b/Source/core/dom/Node.idl
@@ -29,7 +29,7 @@
     const unsigned short      ATTRIBUTE_NODE                 = 2;
     const unsigned short      TEXT_NODE                      = 3;
     const unsigned short      CDATA_SECTION_NODE             = 4;
-    const unsigned short      ENTITY_REFERENCE_NODE          = 5;
+    const unsigned short      ENTITY_REFERENCE_NODE          = 5; // EntityReference nodes are impossible to create in WebKit.
     const unsigned short      ENTITY_NODE                    = 6;
     const unsigned short      PROCESSING_INSTRUCTION_NODE    = 7;
     const unsigned short      COMMENT_NODE                   = 8;
diff --git a/Source/core/dom/NodeIterator.idl b/Source/core/dom/NodeIterator.idl
index 3101322..e22c8fa 100644
--- a/Source/core/dom/NodeIterator.idl
+++ b/Source/core/dom/NodeIterator.idl
@@ -20,6 +20,7 @@
 
 // Introduced in DOM Level 2:
 [
+    NoInterfaceObject,
     ImplementationLacksVTable
 ] interface NodeIterator {
     readonly attribute Node root;
diff --git a/Source/core/dom/NodeRenderingContext.cpp b/Source/core/dom/NodeRenderingContext.cpp
index aca7e5f..acdfbbd 100644
--- a/Source/core/dom/NodeRenderingContext.cpp
+++ b/Source/core/dom/NodeRenderingContext.cpp
@@ -27,7 +27,7 @@
 #include "core/dom/NodeRenderingContext.h"
 
 #include "HTMLNames.h"
-#include "core/css/StyleResolver.h"
+#include "core/css/resolver/StyleResolver.h"
 #include "core/dom/ContainerNode.h"
 #include "core/dom/ElementShadow.h"
 #include "core/dom/Node.h"
diff --git a/Source/core/dom/Range.cpp b/Source/core/dom/Range.cpp
index 87ccff1..125cab1 100644
--- a/Source/core/dom/Range.cpp
+++ b/Source/core/dom/Range.cpp
@@ -104,6 +104,11 @@
     return adoptRef(new Range(ownerDocument, start.containerNode(), start.computeOffsetInContainerNode(), end.containerNode(), end.computeOffsetInContainerNode()));
 }
 
+PassRefPtr<Range> Range::create(ScriptExecutionContext* context)
+{
+    return adoptRef(new Range(toDocument(context)));
+}
+
 Range::~Range()
 {
     // Always detach (even if we've already detached) to fix https://bugs.webkit.org/show_bug.cgi?id=26044
@@ -654,7 +659,6 @@
         return static_cast<ProcessingInstruction*>(node)->data().length();
     case Node::ELEMENT_NODE:
     case Node::ATTRIBUTE_NODE:
-    case Node::ENTITY_REFERENCE_NODE:
     case Node::ENTITY_NODE:
     case Node::DOCUMENT_NODE:
     case Node::DOCUMENT_TYPE_NODE:
@@ -816,7 +820,6 @@
         break;
     case Node::ELEMENT_NODE:
     case Node::ATTRIBUTE_NODE:
-    case Node::ENTITY_REFERENCE_NODE:
     case Node::ENTITY_NODE:
     case Node::DOCUMENT_NODE:
     case Node::DOCUMENT_TYPE_NODE:
@@ -952,13 +955,6 @@
         return;
     }
 
-    // NO_MODIFICATION_ALLOWED_ERR: Raised if an ancestor container of either boundary-point of
-    // the Range is read-only.
-    if (containedByReadOnly()) {
-        ec = NO_MODIFICATION_ALLOWED_ERR;
-        return;
-    }
-
     // HIERARCHY_REQUEST_ERR: Raised if the container of the start of the Range is of a type that
     // does not allow children of the type of newNode or if newNode is an ancestor of the container.
 
@@ -1152,7 +1148,6 @@
         case Node::DOCUMENT_FRAGMENT_NODE:
         case Node::DOCUMENT_NODE:
         case Node::ELEMENT_NODE:
-        case Node::ENTITY_REFERENCE_NODE:
         case Node::XPATH_NAMESPACE_NODE: {
             if (!offset)
                 return 0;
@@ -1184,7 +1179,6 @@
         case Node::COMMENT_NODE:
         case Node::DOCUMENT_TYPE_NODE:
         case Node::ELEMENT_NODE:
-        case Node::ENTITY_REFERENCE_NODE:
         case Node::PROCESSING_INSTRUCTION_NODE:
         case Node::TEXT_NODE:
         case Node::XPATH_NAMESPACE_NODE:
@@ -1205,7 +1199,6 @@
         case Node::DOCUMENT_TYPE_NODE:
         case Node::ELEMENT_NODE:
         case Node::ENTITY_NODE:
-        case Node::ENTITY_REFERENCE_NODE:
         case Node::NOTATION_NODE:
         case Node::PROCESSING_INSTRUCTION_NODE:
         case Node::TEXT_NODE:
@@ -1308,7 +1301,6 @@
             case Node::DOCUMENT_FRAGMENT_NODE:
             case Node::DOCUMENT_NODE:
             case Node::ELEMENT_NODE:
-            case Node::ENTITY_REFERENCE_NODE:
             case Node::PROCESSING_INSTRUCTION_NODE:
             case Node::TEXT_NODE:
             case Node::XPATH_NAMESPACE_NODE:
@@ -1326,7 +1318,6 @@
         case Node::COMMENT_NODE:
         case Node::DOCUMENT_TYPE_NODE:
         case Node::ELEMENT_NODE:
-        case Node::ENTITY_REFERENCE_NODE:
         case Node::PROCESSING_INSTRUCTION_NODE:
         case Node::TEXT_NODE:
         case Node::XPATH_NAMESPACE_NODE:
@@ -1372,7 +1363,6 @@
             case Node::DOCUMENT_FRAGMENT_NODE:
             case Node::DOCUMENT_NODE:
             case Node::ELEMENT_NODE:
-            case Node::ENTITY_REFERENCE_NODE:
             case Node::PROCESSING_INSTRUCTION_NODE:
             case Node::TEXT_NODE:
             case Node::XPATH_NAMESPACE_NODE:
@@ -1420,20 +1410,12 @@
         case Node::CDATA_SECTION_NODE:
         case Node::COMMENT_NODE:
         case Node::ELEMENT_NODE:
-        case Node::ENTITY_REFERENCE_NODE:
         case Node::PROCESSING_INSTRUCTION_NODE:
         case Node::TEXT_NODE:
         case Node::XPATH_NAMESPACE_NODE:
             break;
     }
 
-    // NO_MODIFICATION_ALLOWED_ERR: Raised if an ancestor container of either boundary-point of
-    // the Range is read-only.
-    if (containedByReadOnly()) {
-        ec = NO_MODIFICATION_ALLOWED_ERR;
-        return;
-    }
-
     // Raise a HIERARCHY_REQUEST_ERR if m_start.container() doesn't accept children like newParent.
     Node* parentOfNewParent = m_start.container();
 
@@ -1518,33 +1500,11 @@
         
     Node* pastLast = pastLastNode();
     for (Node* n = firstNode(); n != pastLast; n = NodeTraversal::next(n)) {
-        if (n->isReadOnlyNode()) {
-            ec = NO_MODIFICATION_ALLOWED_ERR;
-            return;
-        }
         if (n->nodeType() == Node::DOCUMENT_TYPE_NODE) {
             ec = HIERARCHY_REQUEST_ERR;
             return;
         }
     }
-
-    if (containedByReadOnly()) {
-        ec = NO_MODIFICATION_ALLOWED_ERR;
-        return;
-    }
-}
-
-bool Range::containedByReadOnly() const
-{
-    for (Node* n = m_start.container(); n; n = n->parentNode()) {
-        if (n->isReadOnlyNode())
-            return true;
-    }
-    for (Node* n = m_end.container(); n; n = n->parentNode()) {
-        if (n->isReadOnlyNode())
-            return true;
-    }
-    return false;
 }
 
 Node* Range::firstNode() const
diff --git a/Source/core/dom/Range.h b/Source/core/dom/Range.h
index 7e65656..dfc33ec 100644
--- a/Source/core/dom/Range.h
+++ b/Source/core/dom/Range.h
@@ -51,6 +51,7 @@
     static PassRefPtr<Range> create(PassRefPtr<Document>);
     static PassRefPtr<Range> create(PassRefPtr<Document>, PassRefPtr<Node> startContainer, int startOffset, PassRefPtr<Node> endContainer, int endOffset);
     static PassRefPtr<Range> create(PassRefPtr<Document>, const Position&, const Position&);
+    static PassRefPtr<Range> create(ScriptExecutionContext*);
     ~Range();
 
     Document* ownerDocument() const { return m_ownerDocument.get(); }
@@ -157,7 +158,6 @@
     Node* checkNodeWOffset(Node*, int offset, ExceptionCode&) const;
     void checkNodeBA(Node*, ExceptionCode&) const;
     void checkDeleteExtract(ExceptionCode&);
-    bool containedByReadOnly() const;
     int maxStartOffset() const;
     int maxEndOffset() const;
 
diff --git a/Source/core/dom/Range.idl b/Source/core/dom/Range.idl
index 3504bad..2d825b1 100644
--- a/Source/core/dom/Range.idl
+++ b/Source/core/dom/Range.idl
@@ -20,7 +20,9 @@
 
 // Introduced in DOM Level 2:
 [
-    ImplementationLacksVTable
+    Constructor,
+    CallWith=ScriptExecutionContext,
+    ImplementationLacksVTable,
 ] interface Range {
 
     [GetterRaisesException] readonly attribute Node startContainer;
diff --git a/Source/core/dom/ScriptElement.cpp b/Source/core/dom/ScriptElement.cpp
index b39ba0f..a70eedb 100644
--- a/Source/core/dom/ScriptElement.cpp
+++ b/Source/core/dom/ScriptElement.cpp
@@ -24,6 +24,10 @@
 #include "config.h"
 #include "core/dom/ScriptElement.h"
 
+#include <wtf/StdLibExtras.h>
+#include <wtf/text/StringBuilder.h>
+#include <wtf/text/StringHash.h>
+#include <wtf/text/TextPosition.h>
 #include "HTMLNames.h"
 #include "bindings/v8/ScriptController.h"
 #include "bindings/v8/ScriptSourceCode.h"
@@ -46,13 +50,9 @@
 #include "core/page/ContentSecurityPolicy.h"
 #include "core/page/Frame.h"
 #include "core/page/Page.h"
-#include "core/page/SecurityOrigin.h"
 #include "core/page/Settings.h"
 #include "core/platform/MIMETypeRegistry.h"
-#include <wtf/StdLibExtras.h>
-#include <wtf/text/StringBuilder.h>
-#include <wtf/text/StringHash.h>
-#include <wtf/text/TextPosition.h>
+#include "origin/SecurityOrigin.h"
 
 #if ENABLE(SVG)
 #include "SVGNames.h"
diff --git a/Source/core/dom/ScriptExecutionContext.h b/Source/core/dom/ScriptExecutionContext.h
index 1275d79..adfbda3 100644
--- a/Source/core/dom/ScriptExecutionContext.h
+++ b/Source/core/dom/ScriptExecutionContext.h
@@ -100,9 +100,6 @@
     void didCreateDestructionObserver(ContextDestructionObserver*);
     void willDestroyDestructionObserver(ContextDestructionObserver*);
 
-    virtual void suspendScriptedAnimationControllerCallbacks() { }
-    virtual void resumeScriptedAnimationControllerCallbacks() { }
-
     // MessagePort is conceptually a kind of ActiveDOMObject, but it needs to be tracked separately for message dispatch.
     void processMessagePortMessagesSoon();
     void dispatchMessagePortEvents();
diff --git a/Source/core/dom/SecurityContext.cpp b/Source/core/dom/SecurityContext.cpp
index fbc460d..2c3d18f 100644
--- a/Source/core/dom/SecurityContext.cpp
+++ b/Source/core/dom/SecurityContext.cpp
@@ -27,11 +27,11 @@
 #include "config.h"
 #include "core/dom/SecurityContext.h"
 
+#include <wtf/text/StringBuilder.h>
 #include "core/dom/WebCoreMemoryInstrumentation.h"
 #include "core/html/parser/HTMLParserIdioms.h"
 #include "core/page/ContentSecurityPolicy.h"
-#include "core/page/SecurityOrigin.h"
-#include <wtf/text/StringBuilder.h>
+#include "origin/SecurityOrigin.h"
 
 namespace WebCore {
 
diff --git a/Source/core/dom/SecurityPolicyViolationEvent.idl b/Source/core/dom/SecurityPolicyViolationEvent.idl
index 590d8e6..aae2f7e 100644
--- a/Source/core/dom/SecurityPolicyViolationEvent.idl
+++ b/Source/core/dom/SecurityPolicyViolationEvent.idl
@@ -23,6 +23,7 @@
  */
 
 [
+    NoInterfaceObject,
     ConstructorTemplate=Event,
 ] interface SecurityPolicyViolationEvent : Event {
     [InitializedByEventConstructor] readonly attribute DOMString documentURI;
diff --git a/Source/core/dom/ShadowRoot.cpp b/Source/core/dom/ShadowRoot.cpp
index 48aa0ca..47d3eb0 100644
--- a/Source/core/dom/ShadowRoot.cpp
+++ b/Source/core/dom/ShadowRoot.cpp
@@ -27,7 +27,7 @@
 #include "config.h"
 #include "core/dom/ShadowRoot.h"
 
-#include "core/css/StyleResolver.h"
+#include "core/css/resolver/StyleResolver.h"
 #include "core/dom/ElementShadow.h"
 #include "core/dom/Text.h"
 #include "core/editing/markup.h"
@@ -128,7 +128,6 @@
     case COMMENT_NODE:
     case TEXT_NODE:
     case CDATA_SECTION_NODE:
-    case ENTITY_REFERENCE_NODE:
         return true;
     default:
         return false;
diff --git a/Source/core/dom/ShadowRoot.idl b/Source/core/dom/ShadowRoot.idl
index 8d95548..9fe8551 100644
--- a/Source/core/dom/ShadowRoot.idl
+++ b/Source/core/dom/ShadowRoot.idl
@@ -24,7 +24,9 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-interface ShadowRoot : DocumentFragment {
+[
+    NoInterfaceObject,
+] interface ShadowRoot : DocumentFragment {
     readonly attribute Element activeElement;
     attribute boolean applyAuthorStyles;
     attribute boolean resetStyleInheritance;
diff --git a/Source/core/dom/StyledElement.cpp b/Source/core/dom/StyledElement.cpp
index a329f7f..e975d03 100644
--- a/Source/core/dom/StyledElement.cpp
+++ b/Source/core/dom/StyledElement.cpp
@@ -33,7 +33,7 @@
 #include "core/css/CSSValuePool.h"
 #include "core/css/PropertySetCSSStyleDeclaration.h"
 #include "core/css/StylePropertySet.h"
-#include "core/css/StyleResolver.h"
+#include "core/css/resolver/StyleResolver.h"
 #include "core/dom/Attribute.h"
 #include "core/dom/Document.h"
 #include "core/dom/ScriptableDocumentParser.h"
diff --git a/Source/core/dom/Text.cpp b/Source/core/dom/Text.cpp
index 2fbc7b2..71721f2 100644
--- a/Source/core/dom/Text.cpp
+++ b/Source/core/dom/Text.cpp
@@ -34,7 +34,7 @@
 #include "core/rendering/svg/RenderSVGInlineText.h"
 #endif
 
-#include "core/css/StyleResolver.h"
+#include "core/css/resolver/StyleResolver.h"
 #include "core/rendering/style/StyleInheritedData.h"
 #include <wtf/text/CString.h>
 #include <wtf/text/StringBuilder.h>
@@ -48,6 +48,11 @@
     return adoptRef(new Text(document, data, CreateText));
 }
 
+PassRefPtr<Text> Text::create(ScriptExecutionContext* context, const String& data)
+{
+    return adoptRef(new Text(toDocument(context), data, CreateText));
+}
+
 PassRefPtr<Text> Text::createEditingText(Document* document, const String& data)
 {
     return adoptRef(new Text(document, data, CreateEditingText));
@@ -94,8 +99,6 @@
             continue;
         }
 
-        // We would need to visit EntityReference child text nodes if they existed
-        ASSERT(type != Node::ENTITY_REFERENCE_NODE || !n->hasChildNodes());
         break;
     }
     return t;
@@ -111,8 +114,6 @@
             continue;
         }
 
-        // We would need to visit EntityReference child text nodes if they existed
-        ASSERT(type != Node::ENTITY_REFERENCE_NODE || !n->hasChildNodes());
         break;
     }
     return t;
diff --git a/Source/core/dom/Text.h b/Source/core/dom/Text.h
index c105afd..d70c2c4 100644
--- a/Source/core/dom/Text.h
+++ b/Source/core/dom/Text.h
@@ -28,12 +28,14 @@
 namespace WebCore {
 
 class RenderText;
+class ScriptExecutionContext;
 
 class Text : public CharacterData {
 public:
     static const unsigned defaultLengthLimit = 1 << 16;
 
     static PassRefPtr<Text> create(Document*, const String&);
+    static PassRefPtr<Text> create(ScriptExecutionContext*, const String&);
     static PassRefPtr<Text> createWithLengthLimit(Document*, const String&, unsigned positionInString, unsigned lengthLimit = defaultLengthLimit);
     static PassRefPtr<Text> createEditingText(Document*, const String&);
 
diff --git a/Source/core/dom/Text.idl b/Source/core/dom/Text.idl
index 68e1b8d..10c9af9 100644
--- a/Source/core/dom/Text.idl
+++ b/Source/core/dom/Text.idl
@@ -17,6 +17,8 @@
  * Boston, MA 02110-1301, USA.
  */
 [
+    Constructor([Default=NullString] optional DOMString data),
+    CallWith=ScriptExecutionContext,
     CustomToV8,
     SkipVTableValidation,
 ] interface Text : CharacterData {
diff --git a/Source/core/dom/TextEvent.cpp b/Source/core/dom/TextEvent.cpp
index 7e5e6e9..516cf88 100644
--- a/Source/core/dom/TextEvent.cpp
+++ b/Source/core/dom/TextEvent.cpp
@@ -57,11 +57,6 @@
     return adoptRef(new TextEvent(view, data, TextEventInputDrop));
 }
 
-PassRefPtr<TextEvent> TextEvent::createForDictation(PassRefPtr<AbstractView> view, const String& data, const Vector<DictationAlternative>& dictationAlternatives)
-{
-    return adoptRef(new TextEvent(view, data, dictationAlternatives));
-}
-
 TextEvent::TextEvent()
     : m_inputType(TextEventInputKeyboard)
     , m_shouldSmartReplace(false)
@@ -93,17 +88,6 @@
     ScriptWrappable::init(this);
 }
 
-TextEvent::TextEvent(PassRefPtr<AbstractView> view, const String& data, const Vector<DictationAlternative>& dictationAlternatives)
-    : UIEvent(eventNames().textInputEvent, true, true, view, 0)
-    , m_inputType(TextEventInputDictation)
-    , m_data(data)
-    , m_shouldSmartReplace(false)
-    , m_shouldMatchStyle(false)
-    , m_dictationAlternatives(dictationAlternatives)
-{
-    ScriptWrappable::init(this);
-}
-
 TextEvent::~TextEvent()
 {
 }
diff --git a/Source/core/dom/TextEvent.h b/Source/core/dom/TextEvent.h
index 68e4aaa..90f06df 100644
--- a/Source/core/dom/TextEvent.h
+++ b/Source/core/dom/TextEvent.h
@@ -29,7 +29,6 @@
 
 #include "core/dom/TextEventInputType.h"
 #include "core/dom/UIEvent.h"
-#include "core/editing/DictationAlternative.h"
 
 namespace WebCore {
 
@@ -43,7 +42,6 @@
         static PassRefPtr<TextEvent> createForPlainTextPaste(PassRefPtr<AbstractView> view, const String& data, bool shouldSmartReplace);
         static PassRefPtr<TextEvent> createForFragmentPaste(PassRefPtr<AbstractView> view, PassRefPtr<DocumentFragment> data, bool shouldSmartReplace, bool shouldMatchStyle);
         static PassRefPtr<TextEvent> createForDrop(PassRefPtr<AbstractView> view, const String& data);
-        static PassRefPtr<TextEvent> createForDictation(PassRefPtr<AbstractView>, const String& data, const Vector<DictationAlternative>& dictationAlternatives);
 
         virtual ~TextEvent();
     
@@ -58,12 +56,10 @@
         bool isBackTab() const { return m_inputType == TextEventInputBackTab; }
         bool isPaste() const { return m_inputType == TextEventInputPaste; }
         bool isDrop() const { return m_inputType == TextEventInputDrop; }
-        bool isDictation() const { return m_inputType == TextEventInputDictation; }
 
         bool shouldSmartReplace() const { return m_shouldSmartReplace; }
         bool shouldMatchStyle() const { return m_shouldMatchStyle; }
         DocumentFragment* pastingFragment() const { return m_pastingFragment.get(); }
-        const Vector<DictationAlternative>& dictationAlternatives() const { return m_dictationAlternatives; }
 
     private:
         TextEvent();
@@ -71,7 +67,6 @@
         TextEvent(PassRefPtr<AbstractView>, const String& data, TextEventInputType = TextEventInputKeyboard);
         TextEvent(PassRefPtr<AbstractView>, const String& data, PassRefPtr<DocumentFragment>,
                   bool shouldSmartReplace, bool shouldMatchStyle);
-        TextEvent(PassRefPtr<AbstractView>, const String& data, const Vector<DictationAlternative>& dictationAlternatives);
 
         TextEventInputType m_inputType;
         String m_data;
@@ -79,7 +74,6 @@
         RefPtr<DocumentFragment> m_pastingFragment;
         bool m_shouldSmartReplace;
         bool m_shouldMatchStyle;
-        Vector<DictationAlternative> m_dictationAlternatives;
     };
 
 } // namespace WebCore
diff --git a/Source/core/dom/Touch.idl b/Source/core/dom/Touch.idl
index 4625083..f7a25b5 100644
--- a/Source/core/dom/Touch.idl
+++ b/Source/core/dom/Touch.idl
@@ -24,6 +24,7 @@
  */
 
 [
+    NoInterfaceObject,
     ImplementationLacksVTable
 ] interface Touch {
     readonly attribute long             clientX;
diff --git a/Source/core/dom/TouchEvent.idl b/Source/core/dom/TouchEvent.idl
index 236aff2..043024e 100644
--- a/Source/core/dom/TouchEvent.idl
+++ b/Source/core/dom/TouchEvent.idl
@@ -23,7 +23,9 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-interface TouchEvent : UIEvent {
+[
+    NoInterfaceObject,
+] interface TouchEvent : UIEvent {
     readonly attribute TouchList touches;
     readonly attribute TouchList targetTouches;
     readonly attribute TouchList changedTouches;
diff --git a/Source/core/dom/TouchList.idl b/Source/core/dom/TouchList.idl
index 0034249..e1410db 100644
--- a/Source/core/dom/TouchList.idl
+++ b/Source/core/dom/TouchList.idl
@@ -24,6 +24,7 @@
  */
 
 [
+    NoInterfaceObject,
     ImplementationLacksVTable
 ] interface TouchList {
     readonly attribute unsigned long length;
diff --git a/Source/core/dom/TreeScope.cpp b/Source/core/dom/TreeScope.cpp
index db2a3ff..851371f 100644
--- a/Source/core/dom/TreeScope.cpp
+++ b/Source/core/dom/TreeScope.cpp
@@ -441,4 +441,14 @@
     return 0;
 }
 
+bool TreeScope::isInclusiveAncestorOf(const TreeScope* scope) const
+{
+    ASSERT(scope);
+    for (; scope; scope = scope->parentTreeScope()) {
+        if (scope == this)
+            return true;
+    }
+    return false;
+}
+
 } // namespace WebCore
diff --git a/Source/core/dom/TreeScope.h b/Source/core/dom/TreeScope.h
index 0d04f88..ef5b678 100644
--- a/Source/core/dom/TreeScope.h
+++ b/Source/core/dom/TreeScope.h
@@ -127,6 +127,8 @@
 
     void removedLastRefToScope();
 
+    bool isInclusiveAncestorOf(const TreeScope*) const;
+
 protected:
     TreeScope(ContainerNode*, Document*);
     TreeScope(Document*);
diff --git a/Source/core/dom/TreeWalker.idl b/Source/core/dom/TreeWalker.idl
index 7a81fec..7bb72fb 100644
--- a/Source/core/dom/TreeWalker.idl
+++ b/Source/core/dom/TreeWalker.idl
@@ -20,6 +20,7 @@
 
 // Introduced in DOM Level 2:
 [
+    NoInterfaceObject,
     ImplementationLacksVTable
 ] interface TreeWalker {
     readonly attribute Node root;