Make is<>() / downcast<>() work for HTMLDocument and its subclasses
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 29 Sep 2014 16:58:42 +0000 (16:58 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 29 Sep 2014 16:58:42 +0000 (16:58 +0000)
https://bugs.webkit.org/show_bug.cgi?id=137169

Reviewed by Darin Adler.

Source/WebCore:

Make is<>() / downcast<>() work for HTMLDocument and its subclasses by
using the SPECIALIZE_TYPE_TRAITS_*() macro. Drop the DOCUMENT_TYPE_CASTS()
macro as it is no longer needed.

No new tests, no behavior change.

* bindings/js/JSDOMWindowCustom.cpp:
(WebCore::namedItemGetter):
(WebCore::JSDOMWindow::getOwnPropertySlot):
(WebCore::JSDOMWindow::getOwnPropertySlotByIndex):
* dom/Document.cpp:
(WebCore::Document::prepareForDestruction):
(WebCore::Document::processHttpEquiv):
(WebCore::eventTargetElementForDocument):
* dom/Document.h:
* dom/Element.cpp:
(WebCore::Element::insertedInto):
(WebCore::Element::removedFrom):
(WebCore::Element::updateName):
(WebCore::Element::updateId):
* html/HTMLDocument.h:
(WebCore::isHTMLDocument):
* html/HTMLElement.cpp:
(WebCore::HTMLElement::matchesReadWritePseudoClass):
* html/HTMLEmbedElement.cpp:
(WebCore::HTMLEmbedElement::updateWidget):
* html/HTMLImageElement.cpp:
(WebCore::HTMLImageElement::parseAttribute):
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::parseAttribute):
* html/HTMLObjectElement.cpp:
(WebCore::HTMLObjectElement::updateDocNamedItem):
* html/ImageDocument.cpp:
(WebCore::ImageDocumentParser::document):
* html/ImageDocument.h:
(WebCore::isImageDocument):
* html/MediaDocument.h:
(WebCore::isMediaDocument):
* html/PluginDocument.cpp:
(WebCore::PluginDocumentParser::createDocumentStructure):
* html/PluginDocument.h:
(WebCore::isPluginDocument):
* loader/SubframeLoader.cpp:
(WebCore::SubframeLoader::loadPlugin):
* page/DragController.cpp:
(WebCore::DragController::operationForLoad):
* page/FrameView.cpp:
(WebCore::determineLayerFlushThrottleState):

Source/WebKit/win:

Use is<>() / downcast<>() for HTMLDocument and its subclasses.

* DOMHTMLClasses.cpp:
(DOMHTMLDocument::URL):
(DOMHTMLDocument::body):
(DOMHTMLDocument::forms):

Source/WebKit2:

Use is<>() / downcast<>() for HTMLDocument and its subclasses.

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::pdfDocumentForPrintingFrame):

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

23 files changed:
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSDOMWindowCustom.cpp
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/dom/Element.cpp
Source/WebCore/html/HTMLDocument.h
Source/WebCore/html/HTMLElement.cpp
Source/WebCore/html/HTMLEmbedElement.cpp
Source/WebCore/html/HTMLImageElement.cpp
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLObjectElement.cpp
Source/WebCore/html/ImageDocument.cpp
Source/WebCore/html/ImageDocument.h
Source/WebCore/html/MediaDocument.h
Source/WebCore/html/PluginDocument.cpp
Source/WebCore/html/PluginDocument.h
Source/WebCore/loader/SubframeLoader.cpp
Source/WebCore/page/DragController.cpp
Source/WebCore/page/FrameView.cpp
Source/WebKit/win/ChangeLog
Source/WebKit/win/DOMHTMLClasses.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/WebPage/WebPage.cpp

index 2c8350e..999e3c8 100644 (file)
@@ -1,3 +1,59 @@
+2014-09-29  Christophe Dumez  <cdumez@apple.com>
+
+        Make is<>() / downcast<>() work for HTMLDocument and its subclasses
+        https://bugs.webkit.org/show_bug.cgi?id=137169
+
+        Reviewed by Darin Adler.
+
+        Make is<>() / downcast<>() work for HTMLDocument and its subclasses by
+        using the SPECIALIZE_TYPE_TRAITS_*() macro. Drop the DOCUMENT_TYPE_CASTS()
+        macro as it is no longer needed.
+
+        No new tests, no behavior change.
+
+        * bindings/js/JSDOMWindowCustom.cpp:
+        (WebCore::namedItemGetter):
+        (WebCore::JSDOMWindow::getOwnPropertySlot):
+        (WebCore::JSDOMWindow::getOwnPropertySlotByIndex):
+        * dom/Document.cpp:
+        (WebCore::Document::prepareForDestruction):
+        (WebCore::Document::processHttpEquiv):
+        (WebCore::eventTargetElementForDocument):
+        * dom/Document.h:
+        * dom/Element.cpp:
+        (WebCore::Element::insertedInto):
+        (WebCore::Element::removedFrom):
+        (WebCore::Element::updateName):
+        (WebCore::Element::updateId):
+        * html/HTMLDocument.h:
+        (WebCore::isHTMLDocument):
+        * html/HTMLElement.cpp:
+        (WebCore::HTMLElement::matchesReadWritePseudoClass):
+        * html/HTMLEmbedElement.cpp:
+        (WebCore::HTMLEmbedElement::updateWidget):
+        * html/HTMLImageElement.cpp:
+        (WebCore::HTMLImageElement::parseAttribute):
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::parseAttribute):
+        * html/HTMLObjectElement.cpp:
+        (WebCore::HTMLObjectElement::updateDocNamedItem):
+        * html/ImageDocument.cpp:
+        (WebCore::ImageDocumentParser::document):
+        * html/ImageDocument.h:
+        (WebCore::isImageDocument):
+        * html/MediaDocument.h:
+        (WebCore::isMediaDocument):
+        * html/PluginDocument.cpp:
+        (WebCore::PluginDocumentParser::createDocumentStructure):
+        * html/PluginDocument.h:
+        (WebCore::isPluginDocument):
+        * loader/SubframeLoader.cpp:
+        (WebCore::SubframeLoader::loadPlugin):
+        * page/DragController.cpp:
+        (WebCore::DragController::operationForLoad):
+        * page/FrameView.cpp:
+        (WebCore::determineLayerFlushThrottleState):
+
 2014-09-29  Bruno de Oliveira Abinader  <bruno.d@partner.samsung.com>
 
         Revert "Support for :enabled selector on Anchor & Area elements"
index 8d2e55f..63958cc 100644 (file)
@@ -80,19 +80,19 @@ static EncodedJSValue namedItemGetter(ExecState* exec, JSObject* slotBase, Encod
 
     ASSERT(BindingSecurity::shouldAllowAccessToDOMWindow(exec, thisObj->impl()));
     ASSERT(document);
-    ASSERT(document->isHTMLDocument());
+    ASSERT(is<HTMLDocument>(document));
 
     AtomicStringImpl* atomicPropertyName = propertyName.publicName();
-    if (!atomicPropertyName || !toHTMLDocument(*document).hasWindowNamedItem(*atomicPropertyName))
+    if (!atomicPropertyName || !downcast<HTMLDocument>(*document).hasWindowNamedItem(*atomicPropertyName))
         return JSValue::encode(jsUndefined());
 
-    if (UNLIKELY(toHTMLDocument(*document).windowNamedItemContainsMultipleElements(*atomicPropertyName))) {
+    if (UNLIKELY(downcast<HTMLDocument>(*document).windowNamedItemContainsMultipleElements(*atomicPropertyName))) {
         RefPtr<HTMLCollection> collection = document->windowNamedItems(atomicPropertyName);
         ASSERT(collection->length() > 1);
         return JSValue::encode(toJS(exec, thisObj->globalObject(), WTF::getPtr(collection)));
     }
 
-    return JSValue::encode(toJS(exec, thisObj->globalObject(), toHTMLDocument(*document).windowNamedItem(*atomicPropertyName)));
+    return JSValue::encode(toJS(exec, thisObj->globalObject(), downcast<HTMLDocument>(*document).windowNamedItem(*atomicPropertyName)));
 }
 
 #if ENABLE(USER_MESSAGE_HANDLERS)
@@ -244,9 +244,9 @@ bool JSDOMWindow::getOwnPropertySlot(JSObject* object, ExecState* exec, Property
 
     // Allow shortcuts like 'Image1' instead of document.images.Image1
     Document* document = thisObject->impl().frame()->document();
-    if (document->isHTMLDocument()) {
+    if (is<HTMLDocument>(document)) {
         AtomicStringImpl* atomicPropertyName = propertyName.publicName();
-        if (atomicPropertyName && toHTMLDocument(*document).hasWindowNamedItem(*atomicPropertyName)) {
+        if (atomicPropertyName && downcast<HTMLDocument>(*document).hasWindowNamedItem(*atomicPropertyName)) {
             slot.setCustom(thisObject, ReadOnly | DontDelete | DontEnum, namedItemGetter);
             return true;
         }
@@ -321,9 +321,9 @@ bool JSDOMWindow::getOwnPropertySlotByIndex(JSObject* object, ExecState* exec, u
 
     // Allow shortcuts like 'Image1' instead of document.images.Image1
     Document* document = thisObject->impl().frame()->document();
-    if (document->isHTMLDocument()) {
+    if (is<HTMLDocument>(document)) {
         AtomicStringImpl* atomicPropertyName = propertyName.publicName();
-        if (atomicPropertyName && toHTMLDocument(*document).hasWindowNamedItem(*atomicPropertyName)) {
+        if (atomicPropertyName && downcast<HTMLDocument>(*document).hasWindowNamedItem(*atomicPropertyName)) {
             slot.setCustom(thisObject, ReadOnly | DontDelete | DontEnum, namedItemGetter);
             return true;
         }
index 5a900f0..8e83e91 100644 (file)
@@ -2107,8 +2107,8 @@ void Document::prepareForDestruction()
     if (hasLivingRenderTree())
         destroyRenderTree();
 
-    if (isPluginDocument())
-        toPluginDocument(this)->detachFromPluginElement();
+    if (is<PluginDocument>(*this))
+        downcast<PluginDocument>(*this).detachFromPluginElement();
 
 #if ENABLE(POINTER_LOCK)
     if (page())
@@ -2879,9 +2879,9 @@ void Document::processHttpEquiv(const String& equiv, const String& content)
 
     case HTTPHeaderName::SetCookie:
         // FIXME: make setCookie work on XML documents too; e.g. in case of <html:meta .....>
-        if (isHTMLDocument()) {
+        if (is<HTMLDocument>(*this)) {
             // Exception (for sandboxed documents) ignored.
-            toHTMLDocument(*this).setCookie(content, IGNORE_EXCEPTION);
+            downcast<HTMLDocument>(*this).setCookie(content, IGNORE_EXCEPTION);
         }
         break;
 
@@ -5900,19 +5900,17 @@ IntSize Document::initialViewportSize() const
 }
 #endif
 
-Element* eventTargetElementForDocument(Document* doc)
+Element* eventTargetElementForDocument(Document* document)
 {
-    if (!doc)
+    if (!document)
         return nullptr;
-    Element* element = doc->focusedElement();
-    if (!element && doc->isPluginDocument()) {
-        PluginDocument* pluginDocument = toPluginDocument(doc);
-        element = pluginDocument->pluginElement();
-    }
-    if (!element && doc->isHTMLDocument())
-        element = doc->body();
+    Element* element = document->focusedElement();
+    if (!element && is<PluginDocument>(document))
+        element = downcast<PluginDocument>(*document).pluginElement();
+    if (!element && is<HTMLDocument>(document))
+        element = document->body();
     if (!element)
-        element = doc->documentElement();
+        element = document->documentElement();
     return element;
 }
 
index 37d4fd3..9f7a25d 100644 (file)
@@ -1747,9 +1747,6 @@ void isDocument(const Document&); // Catch unnecessary runtime check of type kno
 
 NODE_TYPE_CASTS(Document)
 
-#define DOCUMENT_TYPE_CASTS(ToClassName) \
-    TYPE_CASTS_BASE(ToClassName, Document, document, WebCore::is##ToClassName(*document), WebCore::is##ToClassName(document))
-
 } // namespace WebCore
 
 namespace WTF {
index 6a9f870..ce98369 100644 (file)
@@ -1338,7 +1338,7 @@ Node::InsertionNotificationRequest Element::insertedInto(ContainerNode& insertio
         elementRareData()->clearClassListValueForQuirksMode();
 
     TreeScope* newScope = &insertionPoint.treeScope();
-    HTMLDocument* newDocument = !wasInDocument && inDocument() && newScope->documentScope().isHTMLDocument() ? toHTMLDocument(&newScope->documentScope()) : nullptr;
+    HTMLDocument* newDocument = !wasInDocument && inDocument() && is<HTMLDocument>(newScope->documentScope()) ? &downcast<HTMLDocument>(newScope->documentScope()) : nullptr;
     if (newScope != &treeScope())
         newScope = nullptr;
 
@@ -1381,7 +1381,7 @@ void Element::removedFrom(ContainerNode& insertionPoint)
 
     if (insertionPoint.isInTreeScope()) {
         TreeScope* oldScope = &insertionPoint.treeScope();
-        HTMLDocument* oldDocument = inDocument() && oldScope->documentScope().isHTMLDocument() ? toHTMLDocument(&oldScope->documentScope()) : nullptr;
+        HTMLDocument* oldDocument = inDocument() && is<HTMLDocument>(oldScope->documentScope()) ? &downcast<HTMLDocument>(oldScope->documentScope()) : nullptr;
         if (oldScope != &treeScope() || !isInTreeScope())
             oldScope = nullptr;
 
@@ -2588,9 +2588,9 @@ inline void Element::updateName(const AtomicString& oldName, const AtomicString&
 
     if (!inDocument())
         return;
-    if (!document().isHTMLDocument())
+    if (!is<HTMLDocument>(document()))
         return;
-    updateNameForDocument(toHTMLDocument(document()), oldName, newName);
+    updateNameForDocument(downcast<HTMLDocument>(document()), oldName, newName);
 }
 
 void Element::updateNameForTreeScope(TreeScope& scope, const AtomicString& oldName, const AtomicString& newName)
@@ -2636,9 +2636,9 @@ inline void Element::updateId(const AtomicString& oldId, const AtomicString& new
 
     if (!inDocument())
         return;
-    if (!document().isHTMLDocument())
+    if (!is<HTMLDocument>(document()))
         return;
-    updateIdForDocument(toHTMLDocument(document()), oldId, newId, UpdateHTMLDocumentNamedItemMapsOnlyIfDiffersFromNameAttribute);
+    updateIdForDocument(downcast<HTMLDocument>(document()), oldId, newId, UpdateHTMLDocumentNamedItemMapsOnlyIfDiffersFromNameAttribute);
 }
 
 void Element::updateIdForTreeScope(TreeScope& scope, const AtomicString& oldId, const AtomicString& newId)
index a26f5db..e5a09e9 100644 (file)
@@ -97,10 +97,10 @@ private:
     DocumentOrderedMap m_windowNamedItem;
 };
 
-inline bool isHTMLDocument(const Document& document) { return document.isHTMLDocument(); }
-void isHTMLDocument(const HTMLDocument&); // Catch unnecessary runtime check of type known at compile time.
-
-DOCUMENT_TYPE_CASTS(HTMLDocument)
+SPECIALIZE_TYPE_TRAITS_BEGIN(HTMLDocument)
+    static bool isHTMLDocument(const Document& document) { return document.isHTMLDocument(); }
+    static bool isHTMLDocument(const Node& node) { return node.isDocumentNode() && isHTMLDocument(toDocument(node)); }
+SPECIALIZE_TYPE_TRAITS_END()
 
 } // namespace WebCore
 
index 3788f7a..43f57a6 100644 (file)
@@ -379,10 +379,8 @@ bool HTMLElement::matchesReadWritePseudoClass() const
     } while (currentElement);
 
     const Document& document = this->document();
-    if (document.isHTMLDocument()) {
-        const HTMLDocument& htmlDocument = toHTMLDocument(document);
-        return htmlDocument.inDesignMode();
-    }
+    if (is<HTMLDocument>(document))
+        return downcast<HTMLDocument>(document).inDesignMode();
     return false;
 }
 
index c02ecdb..c1901ee 100644 (file)
@@ -166,11 +166,11 @@ void HTMLEmbedElement::updateWidget(PluginCreationOption pluginCreationOption)
     Ref<HTMLEmbedElement> protect(*this); // Loading the plugin might remove us from the document.
     bool beforeLoadAllowedLoad = guardedDispatchBeforeLoadEvent(m_url);
     if (!beforeLoadAllowedLoad) {
-        if (document().isPluginDocument()) {
+        if (is<PluginDocument>(document())) {
             // Plugins inside plugin documents load differently than other plugins. By the time
             // we are here in a plugin document, the load of the plugin (which is the plugin document's
             // main resource) has already started. We need to explicitly cancel the main resource load here.
-            toPluginDocument(&document())->cancelManualPluginLoad();
+            downcast<PluginDocument>(document()).cancelManualPluginLoad();
         }
         return;
     }
index 3099790..32fb7dc 100644 (file)
@@ -182,8 +182,8 @@ void HTMLImageElement::parseAttribute(const QualifiedName& name, const AtomicStr
     } else {
         if (name == nameAttr) {
             bool willHaveName = !value.isNull();
-            if (hasName() != willHaveName && inDocument() && document().isHTMLDocument()) {
-                HTMLDocument& document = toHTMLDocument(this->document());
+            if (hasName() != willHaveName && inDocument() && is<HTMLDocument>(document())) {
+                HTMLDocument& document = downcast<HTMLDocument>(this->document());
                 const AtomicString& id = getIdAttribute();
                 if (!id.isEmpty() && id != getNameAttribute()) {
                     if (willHaveName)
index 74f943e..95213f7 100644 (file)
@@ -1795,11 +1795,11 @@ void HTMLMediaElement::mediaLoadingFailedFatally(MediaPlayer::NetworkState error
     setShouldDelayLoadEvent(false);
 
     // 6 - Abort the overall resource selection algorithm.
-    m_currentSourceNode = 0;
+    m_currentSourceNode = nullptr;
 
 #if PLATFORM(COCOA)
-    if (document().isMediaDocument())
-        toMediaDocument(document()).mediaElementSawUnsupportedTracks();
+    if (is<MediaDocument>(document()))
+        downcast<MediaDocument>(document()).mediaElementSawUnsupportedTracks();
 #endif
 }
 
@@ -4208,8 +4208,8 @@ void HTMLMediaElement::mediaPlayerSawUnsupportedTracks(MediaPlayer*)
     // The MediaPlayer came across content it cannot completely handle.
     // This is normally acceptable except when we are in a standalone
     // MediaDocument. If so, tell the document what has happened.
-    if (document().isMediaDocument())
-        toMediaDocument(document()).mediaElementSawUnsupportedTracks();
+    if (is<MediaDocument>(document()))
+        downcast<MediaDocument>(document()).mediaElementSawUnsupportedTracks();
 }
 
 void HTMLMediaElement::mediaPlayerResourceNotSupported(MediaPlayer*)
index 7f3a525..6040ad8 100644 (file)
@@ -435,8 +435,8 @@ void HTMLObjectElement::updateDocNamedItem()
             isNamedItem = false;
         child = child->nextSibling();
     }
-    if (isNamedItem != wasNamedItem && inDocument() && document().isHTMLDocument()) {
-        HTMLDocument& document = toHTMLDocument(this->document());
+    if (isNamedItem != wasNamedItem && inDocument() && is<HTMLDocument>(document())) {
+        HTMLDocument& document = downcast<HTMLDocument>(this->document());
 
         const AtomicString& id = getIdAttribute();
         if (!id.isEmpty()) {
index fb66768..1ebec77 100644 (file)
@@ -176,7 +176,7 @@ inline ImageDocument& ImageDocumentParser::document() const
 {
     // Only used during parsing, so document is guaranteed to be non-null.
     ASSERT(RawDataDocumentParser::document());
-    return toImageDocument(*RawDataDocumentParser::document());
+    return downcast<ImageDocument>(*RawDataDocumentParser::document());
 }
 
 void ImageDocumentParser::appendBytes(DocumentWriter&, const char*, size_t)
index 39625b9..c9a2976 100644 (file)
@@ -82,10 +82,10 @@ private:
     bool m_shouldShrinkImage;
 };
 
-inline bool isImageDocument(const Document& document) { return document.isImageDocument(); }
-void isImageDocument(const ImageDocument&); // Catch unnecessary runtime check of type known at compile time.
-
-DOCUMENT_TYPE_CASTS(ImageDocument)
+SPECIALIZE_TYPE_TRAITS_BEGIN(ImageDocument)
+    static bool isImageDocument(const Document& document) { return document.isImageDocument(); }
+    static bool isImageDocument(const Node& node) { return node.isDocumentNode() && isImageDocument(toDocument(node)); }
+SPECIALIZE_TYPE_TRAITS_END()
 
 }
 
index 57ccd51..7be9e61 100644 (file)
@@ -56,10 +56,10 @@ private:
     String m_outgoingReferrer;
 };
 
-inline bool isMediaDocument(const Document& document) { return document.isMediaDocument(); }
-void isMediaDocument(const MediaDocument&); // Catch unnecessary runtime check of type known at compile time.
-
-DOCUMENT_TYPE_CASTS(MediaDocument)
+SPECIALIZE_TYPE_TRAITS_BEGIN(MediaDocument)
+    static bool isMediaDocument(const Document& document) { return document.isMediaDocument(); }
+    static bool isMediaDocument(const Node& node) { return node.isDocumentNode() && isMediaDocument(toDocument(node)); }
+SPECIALIZE_TYPE_TRAITS_END()
 
 }
 
index 8b0f52e..b22087b 100644 (file)
@@ -104,7 +104,7 @@ void PluginDocumentParser::createDocumentStructure()
     if (loader)
         m_embedElement->setAttribute(typeAttr, loader->writer().mimeType());
 
-    toPluginDocument(document())->setPluginElement(m_embedElement);
+    downcast<PluginDocument>(*document()).setPluginElement(m_embedElement);
 
     body->appendChild(embedElement, IGNORE_EXCEPTION);
 }
index 78491d0..012fb97 100644 (file)
@@ -61,10 +61,10 @@ private:
     RefPtr<HTMLPlugInElement> m_pluginElement;
 };
 
-inline bool isPluginDocument(const Document& document) { return document.isPluginDocument(); }
-void isPluginDocument(const PluginDocument&); // Catch unnecessary runtime check of type known at compile time.
-
-DOCUMENT_TYPE_CASTS(PluginDocument)
+SPECIALIZE_TYPE_TRAITS_BEGIN(PluginDocument)
+    static bool isPluginDocument(const Document& document) { return document.isPluginDocument(); }
+    static bool isPluginDocument(const Node& node) { return node.isDocumentNode() && isPluginDocument(toDocument(node)); }
+SPECIALIZE_TYPE_TRAITS_END()
 
 }
 
index 4adc572..73bc52b 100644 (file)
@@ -393,7 +393,7 @@ bool SubframeLoader::loadPlugin(HTMLPlugInImageElement& pluginElement, const URL
     pluginElement.subframeLoaderWillCreatePlugIn(url);
 
     IntSize contentSize = roundedIntSize(LayoutSize(renderer->contentWidth(), renderer->contentHeight()));
-    bool loadManually = document()->isPluginDocument() && !m_containsPlugins && toPluginDocument(document())->shouldLoadPluginManually();
+    bool loadManually = is<PluginDocument>(document()) && !m_containsPlugins && downcast<PluginDocument>(*document()).shouldLoadPluginManually();
 
 #if PLATFORM(IOS)
     // On iOS, we only tell the plugin to be in full page mode if the containing plugin document is the top level document.
index ac40589..303b3a1 100644 (file)
@@ -397,8 +397,8 @@ DragOperation DragController::operationForLoad(DragData& dragData)
 
     bool pluginDocumentAcceptsDrags = false;
 
-    if (doc && doc->isPluginDocument()) {
-        const Widget* widget = toPluginDocument(doc)->pluginWidget();
+    if (doc && is<PluginDocument>(doc)) {
+        const Widget* widget = downcast<PluginDocument>(*doc).pluginWidget();
         const PluginViewBase* pluginView = (widget && widget->isPluginViewBase()) ? toPluginViewBase(widget) : nullptr;
 
         if (pluginView)
index fdfb6cc..bcb5044 100644 (file)
@@ -2311,7 +2311,7 @@ static LayerFlushThrottleState::Flags determineLayerFlushThrottleState(Page& pag
         return 0;
     // Disable for image documents so large GIF animations don't get throttled during loading.
     auto* document = page.mainFrame().document();
-    if (!document || isImageDocument(*document))
+    if (!document || is<ImageDocument>(*document))
         return 0;
     return LayerFlushThrottleState::Enabled;
 }
index 8b4b2ec..f6712fe 100644 (file)
@@ -1,3 +1,17 @@
+2014-09-29  Christophe Dumez  <cdumez@apple.com>
+
+        Make is<>() / downcast<>() work for HTMLDocument and its subclasses
+        https://bugs.webkit.org/show_bug.cgi?id=137169
+
+        Reviewed by Darin Adler.
+
+        Use is<>() / downcast<>() for HTMLDocument and its subclasses.
+
+        * DOMHTMLClasses.cpp:
+        (DOMHTMLDocument::URL):
+        (DOMHTMLDocument::body):
+        (DOMHTMLDocument::forms):
+
 2014-09-28  Gyuyoung Kim  <gyuyoung.kim@samsung.com>
 
         Use std::unique_ptr for ContextMenuController
index 5a9f7a1..005e6ce 100644 (file)
@@ -250,18 +250,18 @@ HRESULT STDMETHODCALLTYPE DOMHTMLDocument::URL(
     if (!result)
         return E_POINTER;
 
-    *result = BString(toHTMLDocument(m_document)->url()).release();
+    *result = BString(downcast<HTMLDocument>(*m_document).url()).release();
     return S_OK;
 }
     
 HRESULT STDMETHODCALLTYPE DOMHTMLDocument::body( 
         /* [retval][out] */ IDOMHTMLElement** bodyElement)
 {
-    *bodyElement = 0;
-    if (!m_document || !m_document->isHTMLDocument())
+    *bodyElement = nullptr;
+    if (!m_document || !is<HTMLDocument>(m_document))
         return E_FAIL;
 
-    HTMLDocument& htmlDoc = toHTMLDocument(*m_document);
+    HTMLDocument& htmlDoc = downcast<HTMLDocument>(*m_document);
     COMPtr<IDOMElement> domElement;
     domElement.adoptRef(DOMHTMLElement::createInstance(htmlDoc.body()));
     if (domElement)
@@ -300,11 +300,11 @@ HRESULT STDMETHODCALLTYPE DOMHTMLDocument::links(
 HRESULT STDMETHODCALLTYPE DOMHTMLDocument::forms( 
         /* [retval][out] */ IDOMHTMLCollection** collection)
 {
-    *collection = 0;
-    if (!m_document || !m_document->isHTMLDocument())
+    *collection = nullptr;
+    if (!m_document || !is<HTMLDocument>(m_document))
         return E_FAIL;
 
-    HTMLDocument& htmlDoc = toHTMLDocument(*m_document);
+    HTMLDocument& htmlDoc = downcast<HTMLDocument>(*m_document);
     RefPtr<HTMLCollection> forms = htmlDoc.forms();
     *collection = DOMHTMLCollection::createInstance(forms.get());
     return S_OK;
index 386becf..ba7e0a6 100644 (file)
@@ -1,3 +1,15 @@
+2014-09-29  Christophe Dumez  <cdumez@apple.com>
+
+        Make is<>() / downcast<>() work for HTMLDocument and its subclasses
+        https://bugs.webkit.org/show_bug.cgi?id=137169
+
+        Reviewed by Darin Adler.
+
+        Use is<>() / downcast<>() for HTMLDocument and its subclasses.
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::pdfDocumentForPrintingFrame):
+
 2014-09-29  Tibor Meszaros  <tmeszaros.u-szeged@partner.samsung.com>
 
         Fix !ENABLE(INSPECTOR) build after r173929
index 57abf0a..f4980d2 100644 (file)
@@ -3688,14 +3688,14 @@ RetainPtr<PDFDocument> WebPage::pdfDocumentForPrintingFrame(Frame* coreFrame)
 {
     Document* document = coreFrame->document();
     if (!document)
-        return 0;
+        return nullptr;
 
-    if (!document->isPluginDocument())
-        return 0;
+    if (!is<PluginDocument>(document))
+        return nullptr;
 
-    PluginView* pluginView = static_cast<PluginView*>(toPluginDocument(document)->pluginWidget());
+    PluginView* pluginView = static_cast<PluginView*>(downcast<PluginDocument>(*document).pluginWidget());
     if (!pluginView)
-        return 0;
+        return nullptr;
 
     return pluginView->pdfDocumentForPrinting();
 }