Use is<>() / downcast<>() for Document
https://bugs.webkit.org/show_bug.cgi?id=137221
Reviewed by Andreas Kling.
Use is<>() / downcast<>() for Document instead of isDocumentNode() /
toDocument().
Source/WebCore:
No new tests, no behavior change.
* Modules/geolocation/Geolocation.cpp:
(WebCore::Geolocation::document):
(WebCore::Geolocation::frame):
(WebCore::Geolocation::page):
* Modules/indexeddb/IDBFactory.cpp:
* Modules/mediasource/SourceBuffer.cpp:
(WebCore::SourceBuffer::document):
* Modules/mediastream/RTCPeerConnection.cpp:
(WebCore::RTCPeerConnection::RTCPeerConnection):
* Modules/notifications/Notification.cpp:
(WebCore::Notification::Notification):
(WebCore::Notification::show):
(WebCore::Notification::permission):
(WebCore::Notification::requestPermission):
* Modules/webaudio/AudioContext.cpp:
(WebCore::AudioContext::document):
* Modules/webaudio/OfflineAudioContext.cpp:
(WebCore::OfflineAudioContext::create):
* Modules/webdatabase/DatabaseContext.cpp:
(WebCore::DatabaseContext::allowDatabaseAccess):
(WebCore::DatabaseContext::databaseExceededQuota):
* Modules/websockets/ThreadableWebSocketChannel.cpp:
(WebCore::ThreadableWebSocketChannel::create):
* Modules/websockets/WebSocket.cpp:
(WebCore::WebSocket::connect):
* Modules/websockets/WebSocketHandshake.cpp:
(WebCore::WebSocketHandshake::clientHandshakeMessage):
(WebCore::WebSocketHandshake::clientHandshakeRequest):
* Modules/websockets/WorkerThreadableWebSocketChannel.cpp:
(WebCore::WorkerThreadableWebSocketChannel::Peer::Peer):
* bindings/gobject/WebKitDOMPrivate.cpp:
(WebKit::wrap):
* bindings/js/DOMConstructorWithDocument.h:
(WebCore::DOMConstructorWithDocument::document):
* bindings/js/DOMRequestState.h:
(WebCore::DOMRequestState::DOMRequestState):
(WebCore::DOMRequestState::clear):
* bindings/js/JSAudioContextCustom.cpp:
(WebCore::constructJSAudioContext):
* bindings/js/JSDOMGlobalObject.cpp:
(WebCore::toJSDOMGlobalObject):
* bindings/js/JSLazyEventListener.cpp:
(WebCore::JSLazyEventListener::initializeJSFunction):
* bindings/js/JSNodeCustom.cpp:
(WebCore::createWrapperInline):
* bindings/js/ScheduledAction.cpp:
(WebCore::ScheduledAction::execute):
* bindings/js/ScriptState.cpp:
(WebCore::frameFromExecState):
* crypto/SubtleCrypto.cpp:
(WebCore::SubtleCrypto::document):
* dom/Comment.cpp:
(WebCore::Comment::create):
* dom/ContainerNode.cpp:
(WebCore::checkAcceptChild):
* dom/ContainerNodeAlgorithms.cpp:
(WebCore::ChildNodeInsertionNotifier::notifyDescendantInsertedIntoDocument):
* dom/Document.h:
(WebCore::isDocument):
* dom/DocumentFragment.cpp:
(WebCore::DocumentFragment::create):
* dom/Element.cpp:
(WebCore::Element::computeInheritedLanguage):
* dom/EventDispatcher.cpp:
(WebCore::WindowEventContext::WindowEventContext):
* dom/EventTarget.cpp:
(WebCore::EventTarget::fireEventListeners):
* dom/NamedFlowCollection.cpp:
(WebCore::NamedFlowCollection::document):
* dom/Node.cpp:
(WebCore::Node::isDefaultNamespace):
(WebCore::Node::lookupPrefix):
(WebCore::Node::lookupNamespaceURI):
(WebCore::Node::removedLastRef):
* dom/Range.cpp:
(WebCore::Range::create):
* dom/ScriptExecutionContext.cpp:
(WebCore::ScriptExecutionContext::dispatchErrorEvent):
* dom/Text.cpp:
(WebCore::Text::create):
* editing/MarkupAccumulator.cpp:
(WebCore::MarkupAccumulator::appendStartMarkup):
* html/HTMLDocument.h:
(WebCore::isHTMLDocument):
* html/HTMLNameCollection.h:
(WebCore::HTMLNameCollection::document):
* html/HTMLStyleElement.cpp:
(WebCore::HTMLStyleElement::insertedInto):
* html/ImageDocument.h:
(WebCore::isImageDocument):
* html/MediaDocument.h:
(WebCore::isMediaDocument):
* html/PluginDocument.h:
(WebCore::isPluginDocument):
* html/track/TextTrackCue.h:
(WebCore::TextTrackCue::ownerDocument):
* html/track/VTTCue.cpp:
(WebCore::VTTCue::initialize):
* html/track/VTTRegion.h:
(WebCore::VTTRegion::ownerDocument):
* inspector/InspectorDOMAgent.cpp:
(WebCore::InspectorDOMAgent::assertDocument):
(WebCore::InspectorDOMAgent::buildObjectForNode):
(WebCore::InspectorDOMAgent::innerParentNode):
* inspector/InspectorInstrumentation.cpp:
(WebCore::frameForScriptExecutionContext):
* inspector/InspectorInstrumentation.h:
(WebCore::InspectorInstrumentation::instrumentingAgentsForContext):
* loader/TextTrackLoader.cpp:
(WebCore::TextTrackLoader::corsPolicyPreventedLoad):
(WebCore::TextTrackLoader::notifyFinished):
(WebCore::TextTrackLoader::load):
* loader/ThreadableLoader.cpp:
(WebCore::ThreadableLoader::create):
(WebCore::ThreadableLoader::loadResourceSynchronously):
* loader/WorkerThreadableLoader.cpp:
(WebCore::WorkerThreadableLoader::MainThreadBridge::mainThreadCreateLoader):
* page/ContentSecurityPolicy.cpp:
(WebCore::ContentSecurityPolicy::reportViolation):
* page/Crypto.cpp:
(WebCore::Crypto::document):
* page/DOMTimer.cpp:
(WebCore::DOMTimer::install):
(WebCore::DOMTimer::fired):
* page/DOMWindow.cpp:
(WebCore::DOMWindow::focus):
(WebCore::DOMWindow::close):
(WebCore::DOMWindow::document):
(WebCore::DOMWindow::styleMedia):
(WebCore::DOMWindow::getComputedStyle):
* page/DragController.cpp:
(WebCore::DragController::dragExited):
(WebCore::DragController::dragEnteredOrUpdated):
* page/EventSource.cpp:
(WebCore::EventSource::create):
* page/FocusController.cpp:
(WebCore::FocusController::advanceFocusDirectionally):
* page/History.cpp:
(WebCore::History::go):
* page/SpatialNavigation.cpp:
(WebCore::scrollInDirection):
(WebCore::scrollableEnclosingBoxOrParentFrameForNodeInDirection):
(WebCore::canScrollInDirection):
(WebCore::nodeRectInAbsoluteCoordinates):
* svg/SVGDocument.h:
(WebCore::isSVGDocument):
* testing/Internals.cpp:
(WebCore::Internals::contextDocument):
(WebCore::Internals::frame):
(WebCore::Internals::updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks):
* testing/js/WebCoreTestSupport.cpp:
(WebCoreTestSupport::injectInternalsObject):
(WebCoreTestSupport::resetInternalsObject):
* workers/DefaultSharedWorkerRepository.cpp:
(WebCore::SharedWorkerProxy::addToWorkerDocuments):
* workers/WorkerMessagingProxy.cpp:
(WebCore::WorkerMessagingProxy::startWorkerGlobalScope):
* xml/XMLHttpRequest.cpp:
(WebCore::XMLHttpRequest::document):
(WebCore::XMLHttpRequest::open):
Source/WebKit2:
* WebProcess/InjectedBundle/API/mac/WKDOMDocument.mm:
(-[WKDOMDocument createElement:]):
(-[WKDOMDocument createTextNode:]):
(-[WKDOMDocument body]):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@174089 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index 84f3db9..81bd8d7 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,176 @@
+2014-09-29 Christophe Dumez <cdumez@apple.com>
+
+ Use is<>() / downcast<>() for Document
+ https://bugs.webkit.org/show_bug.cgi?id=137221
+
+ Reviewed by Andreas Kling.
+
+ Use is<>() / downcast<>() for Document instead of isDocumentNode() /
+ toDocument().
+
+ No new tests, no behavior change.
+
+ * Modules/geolocation/Geolocation.cpp:
+ (WebCore::Geolocation::document):
+ (WebCore::Geolocation::frame):
+ (WebCore::Geolocation::page):
+ * Modules/indexeddb/IDBFactory.cpp:
+ * Modules/mediasource/SourceBuffer.cpp:
+ (WebCore::SourceBuffer::document):
+ * Modules/mediastream/RTCPeerConnection.cpp:
+ (WebCore::RTCPeerConnection::RTCPeerConnection):
+ * Modules/notifications/Notification.cpp:
+ (WebCore::Notification::Notification):
+ (WebCore::Notification::show):
+ (WebCore::Notification::permission):
+ (WebCore::Notification::requestPermission):
+ * Modules/webaudio/AudioContext.cpp:
+ (WebCore::AudioContext::document):
+ * Modules/webaudio/OfflineAudioContext.cpp:
+ (WebCore::OfflineAudioContext::create):
+ * Modules/webdatabase/DatabaseContext.cpp:
+ (WebCore::DatabaseContext::allowDatabaseAccess):
+ (WebCore::DatabaseContext::databaseExceededQuota):
+ * Modules/websockets/ThreadableWebSocketChannel.cpp:
+ (WebCore::ThreadableWebSocketChannel::create):
+ * Modules/websockets/WebSocket.cpp:
+ (WebCore::WebSocket::connect):
+ * Modules/websockets/WebSocketHandshake.cpp:
+ (WebCore::WebSocketHandshake::clientHandshakeMessage):
+ (WebCore::WebSocketHandshake::clientHandshakeRequest):
+ * Modules/websockets/WorkerThreadableWebSocketChannel.cpp:
+ (WebCore::WorkerThreadableWebSocketChannel::Peer::Peer):
+ * bindings/gobject/WebKitDOMPrivate.cpp:
+ (WebKit::wrap):
+ * bindings/js/DOMConstructorWithDocument.h:
+ (WebCore::DOMConstructorWithDocument::document):
+ * bindings/js/DOMRequestState.h:
+ (WebCore::DOMRequestState::DOMRequestState):
+ (WebCore::DOMRequestState::clear):
+ * bindings/js/JSAudioContextCustom.cpp:
+ (WebCore::constructJSAudioContext):
+ * bindings/js/JSDOMGlobalObject.cpp:
+ (WebCore::toJSDOMGlobalObject):
+ * bindings/js/JSLazyEventListener.cpp:
+ (WebCore::JSLazyEventListener::initializeJSFunction):
+ * bindings/js/JSNodeCustom.cpp:
+ (WebCore::createWrapperInline):
+ * bindings/js/ScheduledAction.cpp:
+ (WebCore::ScheduledAction::execute):
+ * bindings/js/ScriptState.cpp:
+ (WebCore::frameFromExecState):
+ * crypto/SubtleCrypto.cpp:
+ (WebCore::SubtleCrypto::document):
+ * dom/Comment.cpp:
+ (WebCore::Comment::create):
+ * dom/ContainerNode.cpp:
+ (WebCore::checkAcceptChild):
+ * dom/ContainerNodeAlgorithms.cpp:
+ (WebCore::ChildNodeInsertionNotifier::notifyDescendantInsertedIntoDocument):
+ * dom/Document.h:
+ (WebCore::isDocument):
+ * dom/DocumentFragment.cpp:
+ (WebCore::DocumentFragment::create):
+ * dom/Element.cpp:
+ (WebCore::Element::computeInheritedLanguage):
+ * dom/EventDispatcher.cpp:
+ (WebCore::WindowEventContext::WindowEventContext):
+ * dom/EventTarget.cpp:
+ (WebCore::EventTarget::fireEventListeners):
+ * dom/NamedFlowCollection.cpp:
+ (WebCore::NamedFlowCollection::document):
+ * dom/Node.cpp:
+ (WebCore::Node::isDefaultNamespace):
+ (WebCore::Node::lookupPrefix):
+ (WebCore::Node::lookupNamespaceURI):
+ (WebCore::Node::removedLastRef):
+ * dom/Range.cpp:
+ (WebCore::Range::create):
+ * dom/ScriptExecutionContext.cpp:
+ (WebCore::ScriptExecutionContext::dispatchErrorEvent):
+ * dom/Text.cpp:
+ (WebCore::Text::create):
+ * editing/MarkupAccumulator.cpp:
+ (WebCore::MarkupAccumulator::appendStartMarkup):
+ * html/HTMLDocument.h:
+ (WebCore::isHTMLDocument):
+ * html/HTMLNameCollection.h:
+ (WebCore::HTMLNameCollection::document):
+ * html/HTMLStyleElement.cpp:
+ (WebCore::HTMLStyleElement::insertedInto):
+ * html/ImageDocument.h:
+ (WebCore::isImageDocument):
+ * html/MediaDocument.h:
+ (WebCore::isMediaDocument):
+ * html/PluginDocument.h:
+ (WebCore::isPluginDocument):
+ * html/track/TextTrackCue.h:
+ (WebCore::TextTrackCue::ownerDocument):
+ * html/track/VTTCue.cpp:
+ (WebCore::VTTCue::initialize):
+ * html/track/VTTRegion.h:
+ (WebCore::VTTRegion::ownerDocument):
+ * inspector/InspectorDOMAgent.cpp:
+ (WebCore::InspectorDOMAgent::assertDocument):
+ (WebCore::InspectorDOMAgent::buildObjectForNode):
+ (WebCore::InspectorDOMAgent::innerParentNode):
+ * inspector/InspectorInstrumentation.cpp:
+ (WebCore::frameForScriptExecutionContext):
+ * inspector/InspectorInstrumentation.h:
+ (WebCore::InspectorInstrumentation::instrumentingAgentsForContext):
+ * loader/TextTrackLoader.cpp:
+ (WebCore::TextTrackLoader::corsPolicyPreventedLoad):
+ (WebCore::TextTrackLoader::notifyFinished):
+ (WebCore::TextTrackLoader::load):
+ * loader/ThreadableLoader.cpp:
+ (WebCore::ThreadableLoader::create):
+ (WebCore::ThreadableLoader::loadResourceSynchronously):
+ * loader/WorkerThreadableLoader.cpp:
+ (WebCore::WorkerThreadableLoader::MainThreadBridge::mainThreadCreateLoader):
+ * page/ContentSecurityPolicy.cpp:
+ (WebCore::ContentSecurityPolicy::reportViolation):
+ * page/Crypto.cpp:
+ (WebCore::Crypto::document):
+ * page/DOMTimer.cpp:
+ (WebCore::DOMTimer::install):
+ (WebCore::DOMTimer::fired):
+ * page/DOMWindow.cpp:
+ (WebCore::DOMWindow::focus):
+ (WebCore::DOMWindow::close):
+ (WebCore::DOMWindow::document):
+ (WebCore::DOMWindow::styleMedia):
+ (WebCore::DOMWindow::getComputedStyle):
+ * page/DragController.cpp:
+ (WebCore::DragController::dragExited):
+ (WebCore::DragController::dragEnteredOrUpdated):
+ * page/EventSource.cpp:
+ (WebCore::EventSource::create):
+ * page/FocusController.cpp:
+ (WebCore::FocusController::advanceFocusDirectionally):
+ * page/History.cpp:
+ (WebCore::History::go):
+ * page/SpatialNavigation.cpp:
+ (WebCore::scrollInDirection):
+ (WebCore::scrollableEnclosingBoxOrParentFrameForNodeInDirection):
+ (WebCore::canScrollInDirection):
+ (WebCore::nodeRectInAbsoluteCoordinates):
+ * svg/SVGDocument.h:
+ (WebCore::isSVGDocument):
+ * testing/Internals.cpp:
+ (WebCore::Internals::contextDocument):
+ (WebCore::Internals::frame):
+ (WebCore::Internals::updateLayoutIgnorePendingStylesheetsAndRunPostLayoutTasks):
+ * testing/js/WebCoreTestSupport.cpp:
+ (WebCoreTestSupport::injectInternalsObject):
+ (WebCoreTestSupport::resetInternalsObject):
+ * workers/DefaultSharedWorkerRepository.cpp:
+ (WebCore::SharedWorkerProxy::addToWorkerDocuments):
+ * workers/WorkerMessagingProxy.cpp:
+ (WebCore::WorkerMessagingProxy::startWorkerGlobalScope):
+ * xml/XMLHttpRequest.cpp:
+ (WebCore::XMLHttpRequest::document):
+ (WebCore::XMLHttpRequest::open):
+
2014-09-29 David Hyatt <hyatt@apple.com>
REGRESSION (r168046): Confused column spans when combined with dynamic animations
diff --git a/Source/WebCore/Modules/geolocation/Geolocation.cpp b/Source/WebCore/Modules/geolocation/Geolocation.cpp
index 3da82a5..7d84811 100644
--- a/Source/WebCore/Modules/geolocation/Geolocation.cpp
+++ b/Source/WebCore/Modules/geolocation/Geolocation.cpp
@@ -250,17 +250,17 @@
Document* Geolocation::document() const
{
- return toDocument(scriptExecutionContext());
+ return downcast<Document>(scriptExecutionContext());
}
Frame* Geolocation::frame() const
{
- return document() ? document()->frame() : 0;
+ return document() ? document()->frame() : nullptr;
}
Page* Geolocation::page() const
{
- return document() ? document()->page() : 0;
+ return document() ? document()->page() : nullptr;
}
#if PLATFORM(IOS)
diff --git a/Source/WebCore/Modules/indexeddb/IDBFactory.cpp b/Source/WebCore/Modules/indexeddb/IDBFactory.cpp
index edafd7e..ce01007 100644
--- a/Source/WebCore/Modules/indexeddb/IDBFactory.cpp
+++ b/Source/WebCore/Modules/indexeddb/IDBFactory.cpp
@@ -68,10 +68,10 @@
namespace {
static bool isContextValid(ScriptExecutionContext* context)
{
- ASSERT(context->isDocument() || context->isWorkerGlobalScope());
- if (context->isDocument()) {
- Document* document = toDocument(context);
- return document->frame() && document->page() && (!document->page()->usesEphemeralSession() || SchemeRegistry::allowsDatabaseAccessInPrivateBrowsing(document->securityOrigin()->protocol()));
+ ASSERT(is<Document>(context) || context->isWorkerGlobalScope());
+ if (is<Document>(context)) {
+ Document& document = downcast<Document>(*context);
+ return document.frame() && document.page() && (!document.page()->usesEphemeralSession() || SchemeRegistry::allowsDatabaseAccessInPrivateBrowsing(document.securityOrigin()->protocol()));
}
return true;
}
@@ -79,9 +79,9 @@
static String getIndexedDBDatabasePath(ScriptExecutionContext* context)
{
ASSERT(isContextValid(context));
- if (context->isDocument()) {
- Document* document = toDocument(context);
- return document->page()->group().groupSettings().indexedDBDatabasePath();
+ if (is<Document>(context)) {
+ Document& document = downcast<Document>(*context);
+ return document.page()->group().groupSettings().indexedDBDatabasePath();
}
const GroupSettings* groupSettings = toWorkerGlobalScope(context)->groupSettings();
if (groupSettings)
diff --git a/Source/WebCore/Modules/mediasource/SourceBuffer.cpp b/Source/WebCore/Modules/mediasource/SourceBuffer.cpp
index 9f3c96a..ca534ce 100644
--- a/Source/WebCore/Modules/mediasource/SourceBuffer.cpp
+++ b/Source/WebCore/Modules/mediasource/SourceBuffer.cpp
@@ -1796,7 +1796,7 @@
Document& SourceBuffer::document() const
{
ASSERT(scriptExecutionContext());
- return *toDocument(scriptExecutionContext());
+ return downcast<Document>(*scriptExecutionContext());
}
} // namespace WebCore
diff --git a/Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp b/Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp
index 29dc192..3519c3d 100644
--- a/Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp
+++ b/Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp
@@ -178,7 +178,7 @@
, m_configuration(configuration)
, m_stopped(false)
{
- Document& document = toDocument(context);
+ Document& document = downcast<Document>(context);
if (!document.frame()) {
ec = NOT_SUPPORTED_ERR;
diff --git a/Source/WebCore/Modules/notifications/Notification.cpp b/Source/WebCore/Modules/notifications/Notification.cpp
index e9cb035..36ae61f 100644
--- a/Source/WebCore/Modules/notifications/Notification.cpp
+++ b/Source/WebCore/Modules/notifications/Notification.cpp
@@ -86,7 +86,7 @@
, m_state(Idle)
, m_taskTimer(std::make_unique<Timer<Notification>>(this, &Notification::taskTimerFired))
{
- m_notificationCenter = DOMWindowNotifications::webkitNotifications(toDocument(context).domWindow());
+ m_notificationCenter = DOMWindowNotifications::webkitNotifications(downcast<Document>(context).domWindow());
ASSERT(m_notificationCenter->client());
m_taskTimer->startOneShot(0);
@@ -135,9 +135,9 @@
// prevent double-showing
if (m_state == Idle && m_notificationCenter->client()) {
#if ENABLE(NOTIFICATIONS)
- if (!toDocument(scriptExecutionContext())->page())
+ if (!downcast<Document>(*scriptExecutionContext()).page())
return;
- if (NotificationController::from(toDocument(scriptExecutionContext())->page())->client()->checkPermission(scriptExecutionContext()) != NotificationClient::PermissionAllowed) {
+ if (NotificationController::from(downcast<Document>(*scriptExecutionContext()).page())->client()->checkPermission(scriptExecutionContext()) != NotificationClient::PermissionAllowed) {
dispatchErrorEvent();
return;
}
@@ -213,8 +213,8 @@
#if ENABLE(NOTIFICATIONS)
const String Notification::permission(ScriptExecutionContext* context)
{
- ASSERT(toDocument(context)->page());
- return permissionString(NotificationController::from(toDocument(context)->page())->client()->checkPermission(context));
+ ASSERT(downcast<Document>(*context).page());
+ return permissionString(NotificationController::from(downcast<Document>(*context).page())->client()->checkPermission(context));
}
const String Notification::permissionString(NotificationClient::Permission permission)
@@ -234,8 +234,8 @@
void Notification::requestPermission(ScriptExecutionContext* context, PassRefPtr<NotificationPermissionCallback> callback)
{
- ASSERT(toDocument(context)->page());
- NotificationController::from(toDocument(context)->page())->client()->requestPermission(context, callback);
+ ASSERT(downcast<Document>(*context).page());
+ NotificationController::from(downcast<Document>(*context).page())->client()->requestPermission(context, callback);
}
#endif
diff --git a/Source/WebCore/Modules/webaudio/AudioContext.cpp b/Source/WebCore/Modules/webaudio/AudioContext.cpp
index 364c0c6..cf9959f 100644
--- a/Source/WebCore/Modules/webaudio/AudioContext.cpp
+++ b/Source/WebCore/Modules/webaudio/AudioContext.cpp
@@ -325,7 +325,7 @@
Document* AudioContext::document() const
{
ASSERT(m_scriptExecutionContext);
- return toDocument(m_scriptExecutionContext);
+ return downcast<Document>(m_scriptExecutionContext);
}
PassRefPtr<AudioBuffer> AudioContext::createBuffer(unsigned numberOfChannels, size_t numberOfFrames, float sampleRate, ExceptionCode& ec)
diff --git a/Source/WebCore/Modules/webaudio/OfflineAudioContext.cpp b/Source/WebCore/Modules/webaudio/OfflineAudioContext.cpp
index 3bece30..309b1db 100644
--- a/Source/WebCore/Modules/webaudio/OfflineAudioContext.cpp
+++ b/Source/WebCore/Modules/webaudio/OfflineAudioContext.cpp
@@ -37,12 +37,12 @@
PassRefPtr<OfflineAudioContext> OfflineAudioContext::create(ScriptExecutionContext& context, unsigned numberOfChannels, size_t numberOfFrames, float sampleRate, ExceptionCode& ec)
{
// FIXME: add support for workers.
- if (!context.isDocument()) {
+ if (!is<Document>(context)) {
ec = NOT_SUPPORTED_ERR;
return nullptr;
}
- Document& document = toDocument(context);
+ Document& document = downcast<Document>(context);
if (numberOfChannels > 10 || !isSampleRateRangeGood(sampleRate)) {
ec = SYNTAX_ERR;
diff --git a/Source/WebCore/Modules/webdatabase/DatabaseContext.cpp b/Source/WebCore/Modules/webdatabase/DatabaseContext.cpp
index 28f076a..38da15a 100644
--- a/Source/WebCore/Modules/webdatabase/DatabaseContext.cpp
+++ b/Source/WebCore/Modules/webdatabase/DatabaseContext.cpp
@@ -218,9 +218,9 @@
bool DatabaseContext::allowDatabaseAccess() const
{
- if (m_scriptExecutionContext->isDocument()) {
- Document* document = toDocument(m_scriptExecutionContext);
- if (!document->page() || (document->page()->usesEphemeralSession() && !SchemeRegistry::allowsDatabaseAccessInPrivateBrowsing(document->securityOrigin()->protocol())))
+ if (is<Document>(*m_scriptExecutionContext)) {
+ Document& document = downcast<Document>(*m_scriptExecutionContext);
+ if (!document.page() || (document.page()->usesEphemeralSession() && !SchemeRegistry::allowsDatabaseAccessInPrivateBrowsing(document.securityOrigin()->protocol())))
return false;
return true;
}
@@ -231,10 +231,10 @@
void DatabaseContext::databaseExceededQuota(const String& name, DatabaseDetails details)
{
- if (m_scriptExecutionContext->isDocument()) {
- Document* document = toDocument(m_scriptExecutionContext);
- if (Page* page = document->page())
- page->chrome().client().exceededDatabaseQuota(document->frame(), name, details);
+ if (is<Document>(*m_scriptExecutionContext)) {
+ Document& document = downcast<Document>(*m_scriptExecutionContext);
+ if (Page* page = document.page())
+ page->chrome().client().exceededDatabaseQuota(document.frame(), name, details);
return;
}
ASSERT(m_scriptExecutionContext->isWorkerGlobalScope());
diff --git a/Source/WebCore/Modules/websockets/ThreadableWebSocketChannel.cpp b/Source/WebCore/Modules/websockets/ThreadableWebSocketChannel.cpp
index 5541c3e..1654dd5 100644
--- a/Source/WebCore/Modules/websockets/ThreadableWebSocketChannel.cpp
+++ b/Source/WebCore/Modules/websockets/ThreadableWebSocketChannel.cpp
@@ -64,7 +64,7 @@
return WorkerThreadableWebSocketChannel::create(workerGlobalScope, client, mode.toString());
}
- return WebSocketChannel::create(toDocument(context), client);
+ return WebSocketChannel::create(downcast<Document>(context), client);
}
} // namespace WebCore
diff --git a/Source/WebCore/Modules/websockets/WebSocket.cpp b/Source/WebCore/Modules/websockets/WebSocket.cpp
index db3ce8e..98bdce2 100644
--- a/Source/WebCore/Modules/websockets/WebSocket.cpp
+++ b/Source/WebCore/Modules/websockets/WebSocket.cpp
@@ -239,9 +239,9 @@
// FIXME: Convert this to check the isolated world's Content Security Policy once webkit.org/b/104520 is solved.
bool shouldBypassMainWorldContentSecurityPolicy = false;
- if (scriptExecutionContext()->isDocument()) {
- Document* document = toDocument(scriptExecutionContext());
- shouldBypassMainWorldContentSecurityPolicy = document->frame()->script().shouldBypassMainWorldContentSecurityPolicy();
+ if (is<Document>(scriptExecutionContext())) {
+ Document& document = downcast<Document>(*scriptExecutionContext());
+ shouldBypassMainWorldContentSecurityPolicy = document.frame()->script().shouldBypassMainWorldContentSecurityPolicy();
}
if (!shouldBypassMainWorldContentSecurityPolicy && !scriptExecutionContext()->contentSecurityPolicy()->allowConnectToSource(m_url)) {
m_state = CLOSED;
diff --git a/Source/WebCore/Modules/websockets/WebSocketHandshake.cpp b/Source/WebCore/Modules/websockets/WebSocketHandshake.cpp
index cce332b..f366a2d 100644
--- a/Source/WebCore/Modules/websockets/WebSocketHandshake.cpp
+++ b/Source/WebCore/Modules/websockets/WebSocketHandshake.cpp
@@ -196,9 +196,9 @@
fields.append("Sec-WebSocket-Protocol: " + m_clientProtocol);
URL url = httpURLForAuthenticationAndCookies();
- if (m_context->isDocument()) {
- Document* document = toDocument(m_context);
- String cookie = cookieRequestHeaderFieldValue(document, url);
+ if (is<Document>(m_context)) {
+ Document& document = downcast<Document>(*m_context);
+ String cookie = cookieRequestHeaderFieldValue(&document, url);
if (!cookie.isEmpty())
fields.append("Cookie: " + cookie);
// Set "Cookie2: <cookie>" if cookies 2 exists for url?
@@ -247,9 +247,9 @@
request.setHTTPHeaderField(HTTPHeaderName::SecWebSocketProtocol, m_clientProtocol);
URL url = httpURLForAuthenticationAndCookies();
- if (m_context->isDocument()) {
- Document* document = toDocument(m_context);
- String cookie = cookieRequestHeaderFieldValue(document, url);
+ if (is<Document>(*m_context)) {
+ Document& document = downcast<Document>(*m_context);
+ String cookie = cookieRequestHeaderFieldValue(&document, url);
if (!cookie.isEmpty())
request.setHTTPHeaderField(HTTPHeaderName::Cookie, cookie);
// Set "Cookie2: <cookie>" if cookies 2 exists for url?
diff --git a/Source/WebCore/Modules/websockets/WorkerThreadableWebSocketChannel.cpp b/Source/WebCore/Modules/websockets/WorkerThreadableWebSocketChannel.cpp
index 758193f..890cb1d 100644
--- a/Source/WebCore/Modules/websockets/WorkerThreadableWebSocketChannel.cpp
+++ b/Source/WebCore/Modules/websockets/WorkerThreadableWebSocketChannel.cpp
@@ -147,7 +147,7 @@
WorkerThreadableWebSocketChannel::Peer::Peer(PassRefPtr<ThreadableWebSocketChannelClientWrapper> clientWrapper, WorkerLoaderProxy& loaderProxy, ScriptExecutionContext* context, const String& taskMode)
: m_workerClientWrapper(clientWrapper)
, m_loaderProxy(loaderProxy)
- , m_mainWebSocketChannel(WebSocketChannel::create(toDocument(context), this))
+ , m_mainWebSocketChannel(WebSocketChannel::create(downcast<Document>(context), this))
, m_taskMode(taskMode)
{
ASSERT(isMainThread());
diff --git a/Source/WebCore/bindings/gobject/WebKitDOMPrivate.cpp b/Source/WebCore/bindings/gobject/WebKitDOMPrivate.cpp
index a4643e3..e6c9504c 100644
--- a/Source/WebCore/bindings/gobject/WebKitDOMPrivate.cpp
+++ b/Source/WebCore/bindings/gobject/WebKitDOMPrivate.cpp
@@ -100,9 +100,9 @@
case Node::COMMENT_NODE:
return WEBKIT_DOM_NODE(wrapComment(static_cast<Comment*>(node)));
case Node::DOCUMENT_NODE:
- if (toDocument(node)->isHTMLDocument())
- return WEBKIT_DOM_NODE(wrapHTMLDocument(static_cast<HTMLDocument*>(node)));
- return WEBKIT_DOM_NODE(wrapDocument(toDocument(node)));
+ if (is<HTMLDocument>(node))
+ return WEBKIT_DOM_NODE(wrapHTMLDocument(downcast<HTMLDocument>(node)));
+ return WEBKIT_DOM_NODE(wrapDocument(downcast<Document>(node)));
case Node::DOCUMENT_TYPE_NODE:
return WEBKIT_DOM_NODE(wrapDocumentType(static_cast<DocumentType*>(node)));
case Node::DOCUMENT_FRAGMENT_NODE:
diff --git a/Source/WebCore/bindings/js/DOMConstructorWithDocument.h b/Source/WebCore/bindings/js/DOMConstructorWithDocument.h
index 5c98f61..3e26988 100644
--- a/Source/WebCore/bindings/js/DOMConstructorWithDocument.h
+++ b/Source/WebCore/bindings/js/DOMConstructorWithDocument.h
@@ -32,7 +32,7 @@
public:
Document* document() const
{
- return toDocument(scriptExecutionContext());
+ return downcast<Document>(scriptExecutionContext());
}
protected:
diff --git a/Source/WebCore/bindings/js/DOMRequestState.h b/Source/WebCore/bindings/js/DOMRequestState.h
index 9071561..2a4714c 100644
--- a/Source/WebCore/bindings/js/DOMRequestState.h
+++ b/Source/WebCore/bindings/js/DOMRequestState.h
@@ -41,11 +41,11 @@
public:
explicit DOMRequestState(ScriptExecutionContext* scriptExecutionContext)
: m_scriptExecutionContext(scriptExecutionContext)
- , m_exec(0)
+ , m_exec(nullptr)
{
- if (m_scriptExecutionContext->isDocument()) {
- Document* document = toDocument(m_scriptExecutionContext);
- m_exec = execStateFromPage(mainThreadNormalWorld(), document->page());
+ if (is<Document>(*m_scriptExecutionContext)) {
+ Document& document = downcast<Document>(*m_scriptExecutionContext);
+ m_exec = execStateFromPage(mainThreadNormalWorld(), document.page());
} else {
WorkerGlobalScope* workerGlobalScope = static_cast<WorkerGlobalScope*>(m_scriptExecutionContext);
m_exec = execStateFromWorkerGlobalScope(workerGlobalScope);
@@ -54,8 +54,8 @@
void clear()
{
- m_scriptExecutionContext = 0;
- m_exec = 0;
+ m_scriptExecutionContext = nullptr;
+ m_exec = nullptr;
}
class Scope {
diff --git a/Source/WebCore/bindings/js/JSAudioContextCustom.cpp b/Source/WebCore/bindings/js/JSAudioContextCustom.cpp
index 34b45f3..5c8412a 100644
--- a/Source/WebCore/bindings/js/JSAudioContextCustom.cpp
+++ b/Source/WebCore/bindings/js/JSAudioContextCustom.cpp
@@ -53,10 +53,10 @@
if (!scriptExecutionContext)
return throwVMError(exec, createReferenceError(exec, "AudioContext constructor script execution context is unavailable"));
- if (!scriptExecutionContext->isDocument())
+ if (!is<Document>(scriptExecutionContext))
return throwVMError(exec, createReferenceError(exec, "AudioContext constructor called in a script execution context which is not a document"));
- Document& document = toDocument(*scriptExecutionContext);
+ Document& document = downcast<Document>(*scriptExecutionContext);
RefPtr<AudioContext> audioContext;
diff --git a/Source/WebCore/bindings/js/JSDOMGlobalObject.cpp b/Source/WebCore/bindings/js/JSDOMGlobalObject.cpp
index ac9dd75..99c402c 100644
--- a/Source/WebCore/bindings/js/JSDOMGlobalObject.cpp
+++ b/Source/WebCore/bindings/js/JSDOMGlobalObject.cpp
@@ -105,14 +105,14 @@
JSDOMGlobalObject* toJSDOMGlobalObject(ScriptExecutionContext* scriptExecutionContext, JSC::ExecState* exec)
{
- if (scriptExecutionContext->isDocument())
- return toJSDOMGlobalObject(toDocument(scriptExecutionContext), exec);
+ if (is<Document>(scriptExecutionContext))
+ return toJSDOMGlobalObject(downcast<Document>(scriptExecutionContext), exec);
if (scriptExecutionContext->isWorkerGlobalScope())
return toWorkerGlobalScope(scriptExecutionContext)->script()->workerGlobalScopeWrapper();
ASSERT_NOT_REACHED();
- return 0;
+ return nullptr;
}
JSDOMGlobalObject* toJSDOMGlobalObject(Document* document, DOMWrapperWorld& world)
@@ -122,14 +122,14 @@
JSDOMGlobalObject* toJSDOMGlobalObject(ScriptExecutionContext* scriptExecutionContext, DOMWrapperWorld& world)
{
- if (scriptExecutionContext->isDocument())
- return toJSDOMGlobalObject(toDocument(scriptExecutionContext), world);
+ if (is<Document>(scriptExecutionContext))
+ return toJSDOMGlobalObject(downcast<Document>(scriptExecutionContext), world);
if (scriptExecutionContext->isWorkerGlobalScope())
return toWorkerGlobalScope(scriptExecutionContext)->script()->workerGlobalScopeWrapper();
ASSERT_NOT_REACHED();
- return 0;
+ return nullptr;
}
} // namespace WebCore
diff --git a/Source/WebCore/bindings/js/JSLazyEventListener.cpp b/Source/WebCore/bindings/js/JSLazyEventListener.cpp
index 6e34d21..b2cc276 100644
--- a/Source/WebCore/bindings/js/JSLazyEventListener.cpp
+++ b/Source/WebCore/bindings/js/JSLazyEventListener.cpp
@@ -73,30 +73,30 @@
JSObject* JSLazyEventListener::initializeJSFunction(ScriptExecutionContext* executionContext) const
{
ASSERT(executionContext);
- ASSERT(executionContext->isDocument());
+ ASSERT(is<Document>(executionContext));
if (!executionContext)
- return 0;
+ return nullptr;
ASSERT(!m_code.isNull());
ASSERT(!m_eventParameterName.isNull());
if (m_code.isNull() || m_eventParameterName.isNull())
- return 0;
+ return nullptr;
- Document* document = toDocument(executionContext);
+ Document& document = downcast<Document>(*executionContext);
- if (!document->frame())
- return 0;
+ if (!document.frame())
+ return nullptr;
- if (!document->contentSecurityPolicy()->allowInlineEventHandlers(m_sourceURL, m_position.m_line))
- return 0;
+ if (!document.contentSecurityPolicy()->allowInlineEventHandlers(m_sourceURL, m_position.m_line))
+ return nullptr;
- ScriptController& script = document->frame()->script();
+ ScriptController& script = document.frame()->script();
if (!script.canExecuteScripts(AboutToExecuteScript) || script.isPaused())
- return 0;
+ return nullptr;
JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(executionContext, isolatedWorld());
if (!globalObject)
- return 0;
+ return nullptr;
ExecState* exec = globalObject->globalExec();
@@ -108,7 +108,7 @@
if (exec->hadException()) {
reportCurrentException(exec);
exec->clearException();
- return 0;
+ return nullptr;
}
JSFunction* listenerAsFunction = jsCast<JSFunction*>(jsFunction);
diff --git a/Source/WebCore/bindings/js/JSNodeCustom.cpp b/Source/WebCore/bindings/js/JSNodeCustom.cpp
index 7d08a20..cf80609 100644
--- a/Source/WebCore/bindings/js/JSNodeCustom.cpp
+++ b/Source/WebCore/bindings/js/JSNodeCustom.cpp
@@ -219,7 +219,7 @@
break;
case Node::DOCUMENT_NODE:
// we don't want to cache the document itself in the per-document dictionary
- return toJS(exec, globalObject, toDocument(node));
+ return toJS(exec, globalObject, downcast<Document>(node));
case Node::DOCUMENT_TYPE_NODE:
wrapper = CREATE_DOM_WRAPPER(globalObject, DocumentType, node);
break;
diff --git a/Source/WebCore/bindings/js/ScheduledAction.cpp b/Source/WebCore/bindings/js/ScheduledAction.cpp
index 37c7728..d11e454 100644
--- a/Source/WebCore/bindings/js/ScheduledAction.cpp
+++ b/Source/WebCore/bindings/js/ScheduledAction.cpp
@@ -74,8 +74,8 @@
void ScheduledAction::execute(ScriptExecutionContext* context)
{
- if (context->isDocument())
- execute(toDocument(context));
+ if (is<Document>(context))
+ execute(downcast<Document>(context));
else
execute(toWorkerGlobalScope(context));
}
diff --git a/Source/WebCore/bindings/js/ScriptState.cpp b/Source/WebCore/bindings/js/ScriptState.cpp
index 70dfd16..376cd25 100644
--- a/Source/WebCore/bindings/js/ScriptState.cpp
+++ b/Source/WebCore/bindings/js/ScriptState.cpp
@@ -58,7 +58,7 @@
Frame* frameFromExecState(JSC::ExecState* scriptState)
{
ScriptExecutionContext* context = scriptExecutionContextFromExecState(scriptState);
- Document* document = context && context->isDocument() ? toDocument(context) : nullptr;
+ Document* document = context && is<Document>(context) ? downcast<Document>(context) : nullptr;
return document ? document->frame() : nullptr;
}
diff --git a/Source/WebCore/crypto/SubtleCrypto.cpp b/Source/WebCore/crypto/SubtleCrypto.cpp
index 1bc58c0..68d820c 100644
--- a/Source/WebCore/crypto/SubtleCrypto.cpp
+++ b/Source/WebCore/crypto/SubtleCrypto.cpp
@@ -39,7 +39,7 @@
Document* SubtleCrypto::document() const
{
- return toDocument(scriptExecutionContext());
+ return downcast<Document>(scriptExecutionContext());
}
}
diff --git a/Source/WebCore/dom/Comment.cpp b/Source/WebCore/dom/Comment.cpp
index 51300e9..961e8f1 100644
--- a/Source/WebCore/dom/Comment.cpp
+++ b/Source/WebCore/dom/Comment.cpp
@@ -38,7 +38,7 @@
PassRefPtr<Comment> Comment::create(ScriptExecutionContext& context, const String& text)
{
- return adoptRef(new Comment(toDocument(context), text));
+ return adoptRef(new Comment(downcast<Document>(context), text));
}
String Comment::nodeName() const
diff --git a/Source/WebCore/dom/ContainerNode.cpp b/Source/WebCore/dom/ContainerNode.cpp
index b17b09f..653f697 100644
--- a/Source/WebCore/dom/ContainerNode.cpp
+++ b/Source/WebCore/dom/ContainerNode.cpp
@@ -202,8 +202,8 @@
if (containsConsideringHostElements(newChild, newParent))
return HIERARCHY_REQUEST_ERR;
- if (oldChild && newParent->isDocumentNode()) {
- if (!toDocument(newParent)->canReplaceChild(newChild, oldChild))
+ if (oldChild && is<Document>(newParent)) {
+ if (!downcast<Document>(*newParent).canReplaceChild(newChild, oldChild))
return HIERARCHY_REQUEST_ERR;
} else if (!isChildTypeAllowed(newParent, newChild))
return HIERARCHY_REQUEST_ERR;
diff --git a/Source/WebCore/dom/ContainerNodeAlgorithms.cpp b/Source/WebCore/dom/ContainerNodeAlgorithms.cpp
index 804a567..217918e 100644
--- a/Source/WebCore/dom/ContainerNodeAlgorithms.cpp
+++ b/Source/WebCore/dom/ContainerNodeAlgorithms.cpp
@@ -37,7 +37,7 @@
// we don't want to tell the rest of our children that they've been
// inserted into the document because they haven't.
if (node.inDocument() && child->parentNode() == &node)
- notifyNodeInsertedIntoDocument(*child.get());
+ notifyNodeInsertedIntoDocument(*child);
}
if (!node.isElementNode())
@@ -45,7 +45,7 @@
if (RefPtr<ShadowRoot> root = toElement(node).shadowRoot()) {
if (node.inDocument() && root->hostElement() == &node)
- notifyNodeInsertedIntoDocument(*root.get());
+ notifyNodeInsertedIntoDocument(*root);
}
}
diff --git a/Source/WebCore/dom/Document.h b/Source/WebCore/dom/Document.h
index 9f7a25d..c42d442 100644
--- a/Source/WebCore/dom/Document.h
+++ b/Source/WebCore/dom/Document.h
@@ -1740,12 +1740,10 @@
Element* eventTargetElementForDocument(Document*);
-SCRIPT_EXECUTION_CONTEXT_TYPE_CASTS(Document)
-
-inline bool isDocument(const Node& node) { return node.isDocumentNode(); }
-void isDocument(const Document&); // Catch unnecessary runtime check of type known at compile time.
-
-NODE_TYPE_CASTS(Document)
+SPECIALIZE_TYPE_TRAITS_BEGIN(Document)
+ static bool isDocument(const ScriptExecutionContext& context) { return context.isDocument(); }
+ static bool isDocument(const Node& node) { return node.isDocumentNode(); }
+SPECIALIZE_TYPE_TRAITS_END()
} // namespace WebCore
diff --git a/Source/WebCore/dom/DocumentFragment.cpp b/Source/WebCore/dom/DocumentFragment.cpp
index 7b1ba3a..67ecb17 100644
--- a/Source/WebCore/dom/DocumentFragment.cpp
+++ b/Source/WebCore/dom/DocumentFragment.cpp
@@ -43,7 +43,7 @@
PassRefPtr<DocumentFragment> DocumentFragment::create(ScriptExecutionContext& context)
{
- return adoptRef(new DocumentFragment(toDocument(context), Node::CreateDocumentFragment));
+ return adoptRef(new DocumentFragment(downcast<Document>(context), Node::CreateDocumentFragment));
}
String DocumentFragment::nodeName() const
diff --git a/Source/WebCore/dom/Element.cpp b/Source/WebCore/dom/Element.cpp
index 2da8e73..21ad566 100644
--- a/Source/WebCore/dom/Element.cpp
+++ b/Source/WebCore/dom/Element.cpp
@@ -2200,9 +2200,9 @@
if (const Attribute* attribute = elementData->findLanguageAttribute())
return attribute->value();
}
- } else if (currentNode->isDocumentNode()) {
+ } else if (is<Document>(currentNode)) {
// checking the MIME content-language
- return toDocument(currentNode)->contentLanguage();
+ return downcast<Document>(*currentNode).contentLanguage();
}
}
diff --git a/Source/WebCore/dom/EventDispatcher.cpp b/Source/WebCore/dom/EventDispatcher.cpp
index 5a0db4e..c6e25ed 100644
--- a/Source/WebCore/dom/EventDispatcher.cpp
+++ b/Source/WebCore/dom/EventDispatcher.cpp
@@ -60,10 +60,10 @@
WindowEventContext::WindowEventContext(PassRefPtr<Node> node, const EventContext* topEventContext)
{
Node* topLevelContainer = topEventContext ? topEventContext->node() : node.get();
- if (!topLevelContainer->isDocumentNode())
+ if (!is<Document>(topLevelContainer))
return;
- m_window = toDocument(topLevelContainer)->domWindow();
+ m_window = downcast<Document>(*topLevelContainer).domWindow();
m_target = topEventContext ? topEventContext->target() : node.get();
}
diff --git a/Source/WebCore/dom/EventTarget.cpp b/Source/WebCore/dom/EventTarget.cpp
index 265178c..4837d86 100644
--- a/Source/WebCore/dom/EventTarget.cpp
+++ b/Source/WebCore/dom/EventTarget.cpp
@@ -223,8 +223,8 @@
ScriptExecutionContext* context = scriptExecutionContext();
Document* document = nullptr;
InspectorInstrumentationCookie willDispatchEventCookie;
- if (context && context->isDocument()) {
- document = toDocument(context);
+ if (context && is<Document>(context)) {
+ document = downcast<Document>(context);
willDispatchEventCookie = InspectorInstrumentation::willDispatchEvent(document, *event, size > 0);
}
diff --git a/Source/WebCore/dom/NamedFlowCollection.cpp b/Source/WebCore/dom/NamedFlowCollection.cpp
index ee92f04..6867840 100644
--- a/Source/WebCore/dom/NamedFlowCollection.cpp
+++ b/Source/WebCore/dom/NamedFlowCollection.cpp
@@ -101,7 +101,7 @@
Document* NamedFlowCollection::document() const
{
ScriptExecutionContext* context = ContextDestructionObserver::scriptExecutionContext();
- return toDocument(context);
+ return downcast<Document>(context);
}
PassRefPtr<DOMNamedFlowCollection> NamedFlowCollection::createCSSOMSnapshot()
diff --git a/Source/WebCore/dom/Node.cpp b/Source/WebCore/dom/Node.cpp
index db97de2..ea92da8 100644
--- a/Source/WebCore/dom/Node.cpp
+++ b/Source/WebCore/dom/Node.cpp
@@ -1162,8 +1162,8 @@
return false;
}
case DOCUMENT_NODE:
- if (Element* de = toDocument(this)->documentElement())
- return de->isDefaultNamespace(namespaceURI);
+ if (Element* documentElement = downcast<Document>(*this).documentElement())
+ return documentElement->isDefaultNamespace(namespaceURI);
return false;
case ENTITY_NODE:
case NOTATION_NODE:
@@ -1195,8 +1195,8 @@
case ELEMENT_NODE:
return lookupNamespacePrefix(namespaceURI, static_cast<const Element *>(this));
case DOCUMENT_NODE:
- if (Element* de = toDocument(this)->documentElement())
- return de->lookupPrefix(namespaceURI);
+ if (Element* documentElement = downcast<Document>(*this).documentElement())
+ return documentElement->lookupPrefix(namespaceURI);
return String();
case ENTITY_NODE:
case NOTATION_NODE:
@@ -1253,8 +1253,8 @@
return String();
}
case DOCUMENT_NODE:
- if (Element* de = toDocument(this)->documentElement())
- return de->lookupNamespaceURI(prefix);
+ if (Element* documentElement = downcast<Document>(*this).documentElement())
+ return documentElement->lookupNamespaceURI(prefix);
return String();
case ENTITY_NODE:
case NOTATION_NODE:
@@ -2198,8 +2198,8 @@
// An explicit check for Document here is better than a virtual function since it is
// faster for non-Document nodes, and because the call to removedLastRef that is inlined
// at all deref call sites is smaller if it's a non-virtual function.
- if (isDocumentNode()) {
- toDocument(*this).removedLastRef();
+ if (is<Document>(*this)) {
+ downcast<Document>(*this).removedLastRef();
return;
}
diff --git a/Source/WebCore/dom/Range.cpp b/Source/WebCore/dom/Range.cpp
index 292fa5a..88b9b61 100644
--- a/Source/WebCore/dom/Range.cpp
+++ b/Source/WebCore/dom/Range.cpp
@@ -106,7 +106,7 @@
PassRefPtr<Range> Range::create(ScriptExecutionContext& context)
{
- return adoptRef(new Range(toDocument(context)));
+ return adoptRef(new Range(downcast<Document>(context)));
}
PassRefPtr<Range> Range::create(Document& ownerDocument, const VisiblePosition& visibleStart, const VisiblePosition& visibleEnd)
diff --git a/Source/WebCore/dom/ScriptExecutionContext.cpp b/Source/WebCore/dom/ScriptExecutionContext.cpp
index 5f405af..50a84c7 100644
--- a/Source/WebCore/dom/ScriptExecutionContext.cpp
+++ b/Source/WebCore/dom/ScriptExecutionContext.cpp
@@ -378,8 +378,8 @@
return false;
#if PLATFORM(IOS)
- if (target == target->toDOMWindow() && isDocument()) {
- Settings* settings = toDocument(this)->settings();
+ if (target == target->toDOMWindow() && is<Document>(*this)) {
+ Settings* settings = downcast<Document>(*this).settings();
if (settings && !settings->shouldDispatchJavaScriptWindowOnErrorEvents())
return false;
}
diff --git a/Source/WebCore/dom/Text.cpp b/Source/WebCore/dom/Text.cpp
index 79a45df..7d289b0 100644
--- a/Source/WebCore/dom/Text.cpp
+++ b/Source/WebCore/dom/Text.cpp
@@ -45,7 +45,7 @@
PassRefPtr<Text> Text::create(ScriptExecutionContext& context, const String& data)
{
- return adoptRef(new Text(toDocument(context), data, CreateText));
+ return adoptRef(new Text(downcast<Document>(context), data, CreateText));
}
PassRefPtr<Text> Text::createEditingText(Document& document, const String& data)
diff --git a/Source/WebCore/editing/MarkupAccumulator.cpp b/Source/WebCore/editing/MarkupAccumulator.cpp
index dbe9688..73e19ba 100644
--- a/Source/WebCore/editing/MarkupAccumulator.cpp
+++ b/Source/WebCore/editing/MarkupAccumulator.cpp
@@ -559,7 +559,7 @@
appendComment(result, downcast<Comment>(node).data());
break;
case Node::DOCUMENT_NODE:
- appendXMLDeclaration(result, toDocument(node));
+ appendXMLDeclaration(result, downcast<Document>(node));
break;
case Node::DOCUMENT_FRAGMENT_NODE:
break;
diff --git a/Source/WebCore/html/HTMLDocument.h b/Source/WebCore/html/HTMLDocument.h
index e5a09e9..0a9b5a2 100644
--- a/Source/WebCore/html/HTMLDocument.h
+++ b/Source/WebCore/html/HTMLDocument.h
@@ -99,7 +99,7 @@
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)); }
+ static bool isHTMLDocument(const Node& node) { return is<Document>(node) && isHTMLDocument(downcast<Document>(node)); }
SPECIALIZE_TYPE_TRAITS_END()
} // namespace WebCore
diff --git a/Source/WebCore/html/HTMLNameCollection.h b/Source/WebCore/html/HTMLNameCollection.h
index 80100f61..0914c54 100644
--- a/Source/WebCore/html/HTMLNameCollection.h
+++ b/Source/WebCore/html/HTMLNameCollection.h
@@ -35,7 +35,7 @@
public:
~HTMLNameCollection();
- Document& document() { return toDocument(ownerNode()); }
+ Document& document() { return downcast<Document>(ownerNode()); }
protected:
HTMLNameCollection(Document&, CollectionType, const AtomicString& name);
diff --git a/Source/WebCore/html/ImageDocument.h b/Source/WebCore/html/ImageDocument.h
index c9a2976..781d02c 100644
--- a/Source/WebCore/html/ImageDocument.h
+++ b/Source/WebCore/html/ImageDocument.h
@@ -84,7 +84,7 @@
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)); }
+ static bool isImageDocument(const Node& node) { return is<Document>(node) && isImageDocument(downcast<Document>(node)); }
SPECIALIZE_TYPE_TRAITS_END()
}
diff --git a/Source/WebCore/html/MediaDocument.h b/Source/WebCore/html/MediaDocument.h
index 7be9e61..ab5ed08 100644
--- a/Source/WebCore/html/MediaDocument.h
+++ b/Source/WebCore/html/MediaDocument.h
@@ -58,7 +58,7 @@
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)); }
+ static bool isMediaDocument(const Node& node) { return is<Document>(node) && isMediaDocument(downcast<Document>(node)); }
SPECIALIZE_TYPE_TRAITS_END()
}
diff --git a/Source/WebCore/html/PluginDocument.h b/Source/WebCore/html/PluginDocument.h
index 012fb97..18834d6 100644
--- a/Source/WebCore/html/PluginDocument.h
+++ b/Source/WebCore/html/PluginDocument.h
@@ -63,7 +63,7 @@
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)); }
+ static bool isPluginDocument(const Node& node) { return is<Document>(node) && isPluginDocument(downcast<Document>(node)); }
SPECIALIZE_TYPE_TRAITS_END()
}
diff --git a/Source/WebCore/html/track/TextTrackCue.h b/Source/WebCore/html/track/TextTrackCue.h
index f0ee66b..951fe8c 100644
--- a/Source/WebCore/html/track/TextTrackCue.h
+++ b/Source/WebCore/html/track/TextTrackCue.h
@@ -120,7 +120,7 @@
protected:
TextTrackCue(ScriptExecutionContext&, const MediaTime& start, const MediaTime& end);
- Document& ownerDocument() { return toDocument(m_scriptExecutionContext); }
+ Document& ownerDocument() { return downcast<Document>(m_scriptExecutionContext); }
private:
diff --git a/Source/WebCore/html/track/VTTCue.cpp b/Source/WebCore/html/track/VTTCue.cpp
index ab1988f..59cf6e9 100644
--- a/Source/WebCore/html/track/VTTCue.cpp
+++ b/Source/WebCore/html/track/VTTCue.cpp
@@ -288,8 +288,8 @@
m_writingDirection = Horizontal;
m_cueAlignment = Middle;
m_webVTTNodeTree = nullptr;
- m_cueBackdropBox = HTMLDivElement::create(toDocument(context));
- m_cueHighlightBox = HTMLSpanElement::create(spanTag, toDocument(context));
+ m_cueBackdropBox = HTMLDivElement::create(downcast<Document>(context));
+ m_cueHighlightBox = HTMLSpanElement::create(spanTag, downcast<Document>(context));
m_displayDirection = CSSValueLtr;
m_displaySize = 0;
m_snapToLines = true;
diff --git a/Source/WebCore/html/track/VTTRegion.h b/Source/WebCore/html/track/VTTRegion.h
index 40281a5..db965ab 100644
--- a/Source/WebCore/html/track/VTTRegion.h
+++ b/Source/WebCore/html/track/VTTRegion.h
@@ -98,7 +98,7 @@
private:
VTTRegion(ScriptExecutionContext&);
- Document* ownerDocument() { return toDocument(m_scriptExecutionContext); }
+ Document* ownerDocument() { return downcast<Document>(m_scriptExecutionContext); }
void prepareRegionDisplayTree();
diff --git a/Source/WebCore/inspector/InspectorDOMAgent.cpp b/Source/WebCore/inspector/InspectorDOMAgent.cpp
index bc3744d..cf2f745 100644
--- a/Source/WebCore/inspector/InspectorDOMAgent.cpp
+++ b/Source/WebCore/inspector/InspectorDOMAgent.cpp
@@ -379,11 +379,11 @@
Node* node = assertNode(errorString, nodeId);
if (!node)
return nullptr;
- if (!node->isDocumentNode()) {
+ if (!is<Document>(node)) {
*errorString = "Document is not available";
return nullptr;
}
- return toDocument(node);
+ return downcast<Document>(node);
}
Element* InspectorDOMAgent::assertElement(ErrorString* errorString, int nodeId)
@@ -1301,11 +1301,11 @@
value->setTemplateContent(buildObjectForNode(downcast<HTMLTemplateElement>(*element).content(), 0, nodesMap));
#endif
- } else if (node->isDocumentNode()) {
- Document* document = toDocument(node);
- value->setDocumentURL(documentURLString(document));
- value->setBaseURL(documentBaseURLString(document));
- value->setXmlVersion(document->xmlVersion());
+ } else if (is<Document>(node)) {
+ Document& document = downcast<Document>(*node);
+ value->setDocumentURL(documentURLString(&document));
+ value->setBaseURL(documentBaseURLString(&document));
+ value->setXmlVersion(document.xmlVersion());
} else if (is<DocumentType>(node)) {
DocumentType& docType = downcast<DocumentType>(*node);
value->setPublicId(docType.publicId());
@@ -1728,10 +1728,8 @@
Node* InspectorDOMAgent::innerParentNode(Node* node)
{
- if (node->isDocumentNode()) {
- Document* document = toDocument(node);
- return document->ownerElement();
- }
+ if (is<Document>(node))
+ return downcast<Document>(*node).ownerElement();
return node->parentNode();
}
diff --git a/Source/WebCore/inspector/InspectorInstrumentation.cpp b/Source/WebCore/inspector/InspectorInstrumentation.cpp
index 7b65b0b..ef008d3 100644
--- a/Source/WebCore/inspector/InspectorInstrumentation.cpp
+++ b/Source/WebCore/inspector/InspectorInstrumentation.cpp
@@ -100,8 +100,8 @@
static Frame* frameForScriptExecutionContext(ScriptExecutionContext* context)
{
Frame* frame = nullptr;
- if (context->isDocument())
- frame = toDocument(context)->frame();
+ if (is<Document>(context))
+ frame = downcast<Document>(context)->frame();
return frame;
}
diff --git a/Source/WebCore/inspector/InspectorInstrumentation.h b/Source/WebCore/inspector/InspectorInstrumentation.h
index d0a5bbb..b9e0ce5 100644
--- a/Source/WebCore/inspector/InspectorInstrumentation.h
+++ b/Source/WebCore/inspector/InspectorInstrumentation.h
@@ -2062,8 +2062,8 @@
{
if (!context)
return nullptr;
- if (context->isDocument())
- return instrumentingAgentsForPage(toDocument(context)->page());
+ if (is<Document>(context))
+ return instrumentingAgentsForPage(downcast<Document>(context)->page());
return instrumentingAgentsForNonDocumentContext(context);
}
diff --git a/Source/WebCore/loader/TextTrackLoader.cpp b/Source/WebCore/loader/TextTrackLoader.cpp
index 4b0f651..353cef2 100644
--- a/Source/WebCore/loader/TextTrackLoader.cpp
+++ b/Source/WebCore/loader/TextTrackLoader.cpp
@@ -117,7 +117,7 @@
void TextTrackLoader::corsPolicyPreventedLoad()
{
DEPRECATED_DEFINE_STATIC_LOCAL(String, consoleMessage, (ASCIILiteral("Cross-origin text track load denied by Cross-Origin Resource Sharing policy.")));
- Document* document = toDocument(m_scriptExecutionContext);
+ Document* document = downcast<Document>(m_scriptExecutionContext);
document->addConsoleMessage(MessageSource::Security, MessageLevel::Error, consoleMessage);
m_state = Failed;
}
@@ -126,7 +126,7 @@
{
ASSERT(m_resource == resource);
- Document* document = toDocument(m_scriptExecutionContext);
+ Document* document = downcast<Document>(m_scriptExecutionContext);
if (!m_crossOriginMode.isNull()
&& !document->securityOrigin()->canRequest(resource->response().url())
&& !resource->passesAccessControlCheck(document->securityOrigin())) {
@@ -155,8 +155,8 @@
{
cancelLoad();
- ASSERT(m_scriptExecutionContext->isDocument());
- Document* document = toDocument(m_scriptExecutionContext);
+ ASSERT(is<Document>(m_scriptExecutionContext));
+ Document* document = downcast<Document>(m_scriptExecutionContext);
CachedResourceRequest cueRequest(ResourceRequest(document->completeURL(url)));
if (!crossOriginMode.isNull()) {
diff --git a/Source/WebCore/loader/ThreadableLoader.cpp b/Source/WebCore/loader/ThreadableLoader.cpp
index 41a7c1a..2e8c2bf 100644
--- a/Source/WebCore/loader/ThreadableLoader.cpp
+++ b/Source/WebCore/loader/ThreadableLoader.cpp
@@ -59,7 +59,7 @@
if (context->isWorkerGlobalScope())
return WorkerThreadableLoader::create(toWorkerGlobalScope(context), client, WorkerRunLoop::defaultMode(), request, options);
- return DocumentThreadableLoader::create(toDocument(*context), *client, request, options);
+ return DocumentThreadableLoader::create(downcast<Document>(*context), *client, request, options);
}
void ThreadableLoader::loadResourceSynchronously(ScriptExecutionContext* context, const ResourceRequest& request, ThreadableLoaderClient& client, const ThreadableLoaderOptions& options)
@@ -71,7 +71,7 @@
return;
}
- DocumentThreadableLoader::loadResourceSynchronously(*toDocument(context), request, client, options);
+ DocumentThreadableLoader::loadResourceSynchronously(*downcast<Document>(context), request, client, options);
}
} // namespace WebCore
diff --git a/Source/WebCore/loader/WorkerThreadableLoader.cpp b/Source/WebCore/loader/WorkerThreadableLoader.cpp
index 6110ec3..85795a8 100644
--- a/Source/WebCore/loader/WorkerThreadableLoader.cpp
+++ b/Source/WebCore/loader/WorkerThreadableLoader.cpp
@@ -101,14 +101,14 @@
void WorkerThreadableLoader::MainThreadBridge::mainThreadCreateLoader(ScriptExecutionContext& context, MainThreadBridge* thisPtr, PassOwnPtr<CrossThreadResourceRequestData> requestData, ThreadableLoaderOptions options, const String& outgoingReferrer)
{
ASSERT(isMainThread());
- Document* document = toDocument(&context);
+ Document& document = downcast<Document>(context);
OwnPtr<ResourceRequest> request(ResourceRequest::adopt(requestData));
request->setHTTPReferrer(outgoingReferrer);
// FIXME: If the a site requests a local resource, then this will return a non-zero value but the sync path
// will return a 0 value. Either this should return 0 or the other code path should do a callback with
// a failure.
- thisPtr->m_mainThreadLoader = DocumentThreadableLoader::create(*document, *thisPtr, *request, options);
+ thisPtr->m_mainThreadLoader = DocumentThreadableLoader::create(document, *thisPtr, *request, options);
ASSERT(thisPtr->m_mainThreadLoader);
}
diff --git a/Source/WebCore/page/ContentSecurityPolicy.cpp b/Source/WebCore/page/ContentSecurityPolicy.cpp
index f9c5c98..44aff16 100644
--- a/Source/WebCore/page/ContentSecurityPolicy.cpp
+++ b/Source/WebCore/page/ContentSecurityPolicy.cpp
@@ -1577,20 +1577,20 @@
m_scriptExecutionContext->enforceSandboxFlags(mask);
}
-static String stripURLForUseInReport(Document* document, const URL& url)
+static String stripURLForUseInReport(Document& document, const URL& url)
{
if (!url.isValid())
return String();
if (!url.isHierarchical() || url.protocolIs("file"))
return url.protocol();
- return document->securityOrigin()->canRequest(url) ? url.strippedForUseAsReferrer() : SecurityOrigin::create(url)->toString();
+ return document.securityOrigin()->canRequest(url) ? url.strippedForUseAsReferrer() : SecurityOrigin::create(url)->toString();
}
#if ENABLE(CSP_NEXT)
-static void gatherSecurityPolicyViolationEventData(SecurityPolicyViolationEventInit& init, Document* document, const String& directiveText, const String& effectiveDirective, const URL& blockedURL, const String& header)
+static void gatherSecurityPolicyViolationEventData(SecurityPolicyViolationEventInit& init, Document& document, const String& directiveText, const String& effectiveDirective, const URL& blockedURL, const String& header)
{
- init.documentURI = document->url().string();
- init.referrer = document->referrer();
+ init.documentURI = document.url().string();
+ init.referrer = document.referrer();
init.blockedURI = stripURLForUseInReport(document, blockedURL);
init.violatedDirective = directiveText;
init.effectiveDirective = effectiveDirective;
@@ -1613,11 +1613,11 @@
logToConsole(consoleMessage, contextURL, contextLine, state);
// FIXME: Support sending reports from worker.
- if (!m_scriptExecutionContext->isDocument())
+ if (!is<Document>(*m_scriptExecutionContext))
return;
- Document* document = toDocument(m_scriptExecutionContext);
- Frame* frame = document->frame();
+ Document& document = downcast<Document>(*m_scriptExecutionContext);
+ Frame* frame = document.frame();
if (!frame)
return;
@@ -1626,7 +1626,7 @@
// FIXME: This code means that we're gathering information like line numbers twice. Once we can bring this out from behind the flag, we should reuse the data gathered here when generating the JSON report below.
SecurityPolicyViolationEventInit init;
gatherSecurityPolicyViolationEventData(init, document, directiveText, effectiveDirective, blockedURL, header);
- document->enqueueDocumentEvent(SecurityPolicyViolationEvent::create(eventNames().securitypolicyviolationEvent, init));
+ document.enqueueDocumentEvent(SecurityPolicyViolationEvent::create(eventNames().securitypolicyviolationEvent, init));
}
#endif
@@ -1644,8 +1644,8 @@
// harmless information.
RefPtr<InspectorObject> cspReport = InspectorObject::create();
- cspReport->setString(ASCIILiteral("document-uri"), document->url().strippedForUseAsReferrer());
- cspReport->setString(ASCIILiteral("referrer"), document->referrer());
+ cspReport->setString(ASCIILiteral("document-uri"), document.url().strippedForUseAsReferrer());
+ cspReport->setString(ASCIILiteral("referrer"), document.referrer());
cspReport->setString(ASCIILiteral("violated-directive"), directiveText);
#if ENABLE(CSP_NEXT)
if (experimentalFeaturesEnabled())
diff --git a/Source/WebCore/page/Crypto.cpp b/Source/WebCore/page/Crypto.cpp
index 3358730..8cc0af7 100644
--- a/Source/WebCore/page/Crypto.cpp
+++ b/Source/WebCore/page/Crypto.cpp
@@ -59,7 +59,7 @@
Document* Crypto::document() const
{
- return toDocument(scriptExecutionContext());
+ return downcast<Document>(scriptExecutionContext());
}
void Crypto::getRandomValues(ArrayBufferView* array, ExceptionCode& ec)
diff --git a/Source/WebCore/page/DOMTimer.cpp b/Source/WebCore/page/DOMTimer.cpp
index b7e18a0..aec9018 100644
--- a/Source/WebCore/page/DOMTimer.cpp
+++ b/Source/WebCore/page/DOMTimer.cpp
@@ -120,8 +120,8 @@
// is destroyed, or if explicitly cancelled by removeById.
DOMTimer* timer = new DOMTimer(context, WTF::move(action), timeout, singleShot);
#if PLATFORM(IOS)
- if (context->isDocument()) {
- Document& document = toDocument(*context);
+ if (is<Document>(context)) {
+ Document& document = downcast<Document>(*context);
bool didDeferTimeout = document.frame() && document.frame()->timersPaused();
if (!didDeferTimeout && timeout <= 100 && singleShot) {
WKSetObservedContentChange(WKContentIndeterminateChange);
@@ -173,8 +173,8 @@
#if PLATFORM(IOS)
Document* document = nullptr;
- if (context->isDocument()) {
- document = toDocument(context);
+ if (is<Document>(context)) {
+ document = downcast<Document>(context);
ASSERT(!document->frame()->timersPaused());
}
#endif
diff --git a/Source/WebCore/page/DOMWindow.cpp b/Source/WebCore/page/DOMWindow.cpp
index 2b2f204..41963f1 100644
--- a/Source/WebCore/page/DOMWindow.cpp
+++ b/Source/WebCore/page/DOMWindow.cpp
@@ -973,8 +973,8 @@
bool allowFocus = WindowFocusAllowedIndicator::windowFocusAllowed() || !m_frame->settings().windowFocusRestricted();
if (context) {
ASSERT(isMainThread());
- Document* activeDocument = toDocument(context);
- if (opener() && opener() != this && activeDocument->domWindow() == opener())
+ Document& activeDocument = downcast<Document>(*context);
+ if (opener() && opener() != this && activeDocument.domWindow() == opener())
allowFocus = true;
}
@@ -1025,11 +1025,7 @@
if (context) {
ASSERT(isMainThread());
- Document* activeDocument = toDocument(context);
- if (!activeDocument)
- return;
-
- if (!activeDocument->canNavigate(m_frame))
+ if (!downcast<Document>(*context).canNavigate(m_frame))
return;
}
@@ -1413,24 +1409,24 @@
Document* DOMWindow::document() const
{
ScriptExecutionContext* context = ContextDestructionObserver::scriptExecutionContext();
- return toDocument(context);
+ return downcast<Document>(context);
}
PassRefPtr<StyleMedia> DOMWindow::styleMedia() const
{
if (!isCurrentlyDisplayedInFrame())
- return 0;
+ return nullptr;
if (!m_media)
m_media = StyleMedia::create(m_frame);
return m_media.get();
}
-PassRefPtr<CSSStyleDeclaration> DOMWindow::getComputedStyle(Element* elt, const String& pseudoElt) const
+PassRefPtr<CSSStyleDeclaration> DOMWindow::getComputedStyle(Element* element, const String& pseudoElt) const
{
- if (!elt)
- return 0;
+ if (!element)
+ return nullptr;
- return CSSComputedStyleDeclaration::create(elt, false, pseudoElt);
+ return CSSComputedStyleDeclaration::create(element, false, pseudoElt);
}
PassRefPtr<CSSRuleList> DOMWindow::getMatchedCSSRules(Element* element, const String& pseudoElement, bool authorOnly) const
diff --git a/Source/WebCore/page/DragController.cpp b/Source/WebCore/page/DragController.cpp
index dd3f65a..616d131 100644
--- a/Source/WebCore/page/DragController.cpp
+++ b/Source/WebCore/page/DragController.cpp
@@ -192,10 +192,10 @@
m_page.mainFrame().eventHandler().cancelDragAndDrop(createMouseEvent(dragData), dataTransfer.get());
dataTransfer->setAccessPolicy(DataTransferAccessPolicy::Numb); // Invalidate dataTransfer here for security.
}
- mouseMovedIntoDocument(0);
+ mouseMovedIntoDocument(nullptr);
if (m_fileInputElementUnderMouse)
m_fileInputElementUnderMouse->setCanReceiveDroppedFiles(false);
- m_fileInputElementUnderMouse = 0;
+ m_fileInputElementUnderMouse = nullptr;
}
DragOperation DragController::dragUpdated(DragData& dragData)
@@ -255,7 +255,7 @@
m_dragDestinationAction = m_client.actionMaskForDrag(dragData);
if (m_dragDestinationAction == DragDestinationActionNone) {
- cancelDrag(); // FIXME: Why not call mouseMovedIntoDocument(0)?
+ cancelDrag(); // FIXME: Why not call mouseMovedIntoDocument(nullptr)?
return DragOperationNone;
}
diff --git a/Source/WebCore/page/EventSource.cpp b/Source/WebCore/page/EventSource.cpp
index 072dfaa..336e151 100644
--- a/Source/WebCore/page/EventSource.cpp
+++ b/Source/WebCore/page/EventSource.cpp
@@ -77,25 +77,25 @@
{
if (url.isEmpty()) {
ec = SYNTAX_ERR;
- return 0;
+ return nullptr;
}
URL fullURL = context.completeURL(url);
if (!fullURL.isValid()) {
ec = SYNTAX_ERR;
- return 0;
+ return nullptr;
}
// FIXME: Convert this to check the isolated world's Content Security Policy once webkit.org/b/104520 is solved.
bool shouldBypassMainWorldContentSecurityPolicy = false;
- if (context.isDocument()) {
- Document& document = toDocument(context);
+ if (is<Document>(context)) {
+ Document& document = downcast<Document>(context);
shouldBypassMainWorldContentSecurityPolicy = document.frame()->script().shouldBypassMainWorldContentSecurityPolicy();
}
if (!shouldBypassMainWorldContentSecurityPolicy && !context.contentSecurityPolicy()->allowConnectToSource(fullURL)) {
// FIXME: Should this be throwing an exception?
ec = SECURITY_ERR;
- return 0;
+ return nullptr;
}
RefPtr<EventSource> source = adoptRef(new EventSource(context, fullURL, eventSourceInit));
diff --git a/Source/WebCore/page/FocusController.cpp b/Source/WebCore/page/FocusController.cpp
index b176316..c14d097 100644
--- a/Source/WebCore/page/FocusController.cpp
+++ b/Source/WebCore/page/FocusController.cpp
@@ -876,8 +876,8 @@
Element* focusedElement = focusedDocument->focusedElement();
Node* container = focusedDocument;
- if (container->isDocumentNode())
- toDocument(container)->updateLayoutIgnorePendingStylesheets();
+ if (is<Document>(container))
+ downcast<Document>(*container).updateLayoutIgnorePendingStylesheets();
// Figure out the starting rect.
LayoutRect startingRect;
@@ -900,8 +900,8 @@
consumed = advanceFocusDirectionallyInContainer(container, startingRect, direction, event);
startingRect = nodeRectInAbsoluteCoordinates(container, true /* ignore border */);
container = scrollableEnclosingBoxOrParentFrameForNodeInDirection(direction, container);
- if (container && container->isDocumentNode())
- toDocument(container)->updateLayoutIgnorePendingStylesheets();
+ if (container && is<Document>(container))
+ downcast<Document>(*container).updateLayoutIgnorePendingStylesheets();
} while (!consumed && container);
return consumed;
diff --git a/Source/WebCore/page/History.cpp b/Source/WebCore/page/History.cpp
index 74cef4d..f289ea5 100644
--- a/Source/WebCore/page/History.cpp
+++ b/Source/WebCore/page/History.cpp
@@ -117,7 +117,7 @@
return;
ASSERT(isMainThread());
- Document* activeDocument = toDocument(context);
+ Document* activeDocument = downcast<Document>(context);
if (!activeDocument)
return;
diff --git a/Source/WebCore/page/SpatialNavigation.cpp b/Source/WebCore/page/SpatialNavigation.cpp
index e5fb05e..28d9d3d 100644
--- a/Source/WebCore/page/SpatialNavigation.cpp
+++ b/Source/WebCore/page/SpatialNavigation.cpp
@@ -366,8 +366,8 @@
bool scrollInDirection(Node* container, FocusDirection direction)
{
ASSERT(container);
- if (container->isDocumentNode())
- return scrollInDirection(toDocument(container)->frame(), direction);
+ if (is<Document>(container))
+ return scrollInDirection(downcast<Document>(*container).frame(), direction);
if (!container->renderBox())
return false;
@@ -435,11 +435,11 @@
ASSERT(node);
Node* parent = node;
do {
- if (parent->isDocumentNode())
- parent = toDocument(parent)->document().frame()->ownerElement();
+ if (is<Document>(parent))
+ parent = downcast<Document>(*parent).document().frame()->ownerElement();
else
parent = parent->parentNode();
- } while (parent && !canScrollInDirection(parent, direction) && !parent->isDocumentNode());
+ } while (parent && !canScrollInDirection(parent, direction) && !is<Document>(parent));
return parent;
}
@@ -451,8 +451,8 @@
if (is<HTMLSelectElement>(container))
return false;
- if (container->isDocumentNode())
- return canScrollInDirection(toDocument(container)->frame(), direction);
+ if (is<Document>(container))
+ return canScrollInDirection(downcast<Document>(*container).frame(), direction);
if (!isScrollableNode(container))
return false;
@@ -520,8 +520,8 @@
{
ASSERT(node && node->renderer() && !node->document().view()->needsLayout());
- if (node->isDocumentNode())
- return frameRectInAbsoluteCoordinates(toDocument(node)->frame());
+ if (is<Document>(node))
+ return frameRectInAbsoluteCoordinates(downcast<Document>(*node).frame());
LayoutRect rect = rectToAbsoluteCoordinates(node->document().frame(), node->boundingBox());
// For authors that use border instead of outline in their CSS, we compensate by ignoring the border when calculating
diff --git a/Source/WebCore/svg/SVGDocument.h b/Source/WebCore/svg/SVGDocument.h
index 996015e..6cacf03 100644
--- a/Source/WebCore/svg/SVGDocument.h
+++ b/Source/WebCore/svg/SVGDocument.h
@@ -54,7 +54,7 @@
SPECIALIZE_TYPE_TRAITS_BEGIN(SVGDocument)
static bool isSVGDocument(const Document& document) { return document.isSVGDocument(); }
- static bool isSVGDocument(const Node& node) { return node.isDocumentNode() && isSVGDocument(toDocument(node)); }
+ static bool isSVGDocument(const Node& node) { return is<Document>(node) && isSVGDocument(downcast<Document>(node)); }
SPECIALIZE_TYPE_TRAITS_END()
} // namespace WebCore
diff --git a/Source/WebCore/testing/Internals.cpp b/Source/WebCore/testing/Internals.cpp
index 88acd1f..4415750 100644
--- a/Source/WebCore/testing/Internals.cpp
+++ b/Source/WebCore/testing/Internals.cpp
@@ -319,13 +319,13 @@
Document* Internals::contextDocument() const
{
- return toDocument(scriptExecutionContext());
+ return downcast<Document>(scriptExecutionContext());
}
Frame* Internals::frame() const
{
if (!contextDocument())
- return 0;
+ return nullptr;
return contextDocument()->frame();
}
@@ -1916,8 +1916,8 @@
Document* document;
if (!node)
document = contextDocument();
- else if (node->isDocumentNode())
- document = toDocument(node);
+ else if (is<Document>(node))
+ document = downcast<Document>(node);
else if (is<HTMLIFrameElement>(node))
document = downcast<HTMLIFrameElement>(*node).contentDocument();
else {
diff --git a/Source/WebCore/testing/js/WebCoreTestSupport.cpp b/Source/WebCore/testing/js/WebCoreTestSupport.cpp
index 3b1b91c..aea8e4a 100644
--- a/Source/WebCore/testing/js/WebCoreTestSupport.cpp
+++ b/Source/WebCore/testing/js/WebCoreTestSupport.cpp
@@ -46,8 +46,8 @@
JSLockHolder lock(exec);
JSDOMGlobalObject* globalObject = jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject());
ScriptExecutionContext* scriptContext = globalObject->scriptExecutionContext();
- if (scriptContext->isDocument())
- globalObject->putDirect(exec->vm(), Identifier(exec, Internals::internalsId), toJS(exec, globalObject, Internals::create(toDocument(scriptContext))));
+ if (is<Document>(scriptContext))
+ globalObject->putDirect(exec->vm(), Identifier(exec, Internals::internalsId), toJS(exec, globalObject, Internals::create(downcast<Document>(scriptContext))));
}
void resetInternalsObject(JSContextRef context)
@@ -56,7 +56,7 @@
JSLockHolder lock(exec);
JSDOMGlobalObject* globalObject = jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject());
ScriptExecutionContext* scriptContext = globalObject->scriptExecutionContext();
- Page* page = toDocument(scriptContext)->frame()->page();
+ Page* page = downcast<Document>(scriptContext)->frame()->page();
Internals::resetToConsistentState(page);
InternalSettings::from(page)->resetToConsistentState();
}
diff --git a/Source/WebCore/workers/DefaultSharedWorkerRepository.cpp b/Source/WebCore/workers/DefaultSharedWorkerRepository.cpp
index 930c614..f9d0e3a 100644
--- a/Source/WebCore/workers/DefaultSharedWorkerRepository.cpp
+++ b/Source/WebCore/workers/DefaultSharedWorkerRepository.cpp
@@ -228,7 +228,7 @@
ASSERT(context);
ASSERT(!isClosing());
MutexLocker lock(m_workerDocumentsLock);
- m_workerDocuments.add(toDocument(context));
+ m_workerDocuments.add(downcast<Document>(context));
}
void SharedWorkerProxy::documentDetached(Document* document)
diff --git a/Source/WebCore/workers/WorkerMessagingProxy.cpp b/Source/WebCore/workers/WorkerMessagingProxy.cpp
index c3c18c0..2bcaa4b 100644
--- a/Source/WebCore/workers/WorkerMessagingProxy.cpp
+++ b/Source/WebCore/workers/WorkerMessagingProxy.cpp
@@ -83,11 +83,11 @@
{
// FIXME: This need to be revisited when we support nested worker one day
ASSERT(m_scriptExecutionContext);
- Document* document = toDocument(m_scriptExecutionContext);
- GroupSettings* settings = 0;
- if (document->page())
- settings = &document->page()->group().groupSettings();
- RefPtr<DedicatedWorkerThread> thread = DedicatedWorkerThread::create(scriptURL, userAgent, settings, sourceCode, *this, *this, startMode, document->contentSecurityPolicy()->deprecatedHeader(), document->contentSecurityPolicy()->deprecatedHeaderType(), document->topOrigin());
+ Document& document = downcast<Document>(*m_scriptExecutionContext);
+ GroupSettings* settings = nullptr;
+ if (document.page())
+ settings = &document.page()->group().groupSettings();
+ RefPtr<DedicatedWorkerThread> thread = DedicatedWorkerThread::create(scriptURL, userAgent, settings, sourceCode, *this, *this, startMode, document.contentSecurityPolicy()->deprecatedHeader(), document.contentSecurityPolicy()->deprecatedHeaderType(), document.topOrigin());
workerThreadCreated(thread);
thread->start();
InspectorInstrumentation::didStartWorkerGlobalScope(m_scriptExecutionContext.get(), this, scriptURL);
diff --git a/Source/WebCore/xml/XMLHttpRequest.cpp b/Source/WebCore/xml/XMLHttpRequest.cpp
index c2375c4..4d534ee 100644
--- a/Source/WebCore/xml/XMLHttpRequest.cpp
+++ b/Source/WebCore/xml/XMLHttpRequest.cpp
@@ -155,7 +155,7 @@
Document* XMLHttpRequest::document() const
{
ASSERT(scriptExecutionContext());
- return toDocument(scriptExecutionContext());
+ return downcast<Document>(scriptExecutionContext());
}
SecurityOrigin* XMLHttpRequest::securityOrigin() const
@@ -487,10 +487,10 @@
// FIXME: Convert this to check the isolated world's Content Security Policy once webkit.org/b/104520 is solved.
bool shouldBypassMainWorldContentSecurityPolicy = false;
- if (scriptExecutionContext()->isDocument()) {
- Document* document = toDocument(scriptExecutionContext());
- if (document->frame())
- shouldBypassMainWorldContentSecurityPolicy = document->frame()->script().shouldBypassMainWorldContentSecurityPolicy();
+ if (is<Document>(scriptExecutionContext())) {
+ Document& document = downcast<Document>(*scriptExecutionContext());
+ if (document.frame())
+ shouldBypassMainWorldContentSecurityPolicy = document.frame()->script().shouldBypassMainWorldContentSecurityPolicy();
}
if (!shouldBypassMainWorldContentSecurityPolicy && !scriptExecutionContext()->contentSecurityPolicy()->allowConnectToSource(url)) {
// FIXME: Should this be throwing an exception?
diff --git a/Source/WebKit2/ChangeLog b/Source/WebKit2/ChangeLog
index e8abc78..65b5693 100644
--- a/Source/WebKit2/ChangeLog
+++ b/Source/WebKit2/ChangeLog
@@ -1,3 +1,18 @@
+2014-09-29 Christophe Dumez <cdumez@apple.com>
+
+ Use is<>() / downcast<>() for Document
+ https://bugs.webkit.org/show_bug.cgi?id=137221
+
+ Reviewed by Andreas Kling.
+
+ Use is<>() / downcast<>() for Document instead of isDocumentNode() /
+ toDocument().
+
+ * WebProcess/InjectedBundle/API/mac/WKDOMDocument.mm:
+ (-[WKDOMDocument createElement:]):
+ (-[WKDOMDocument createTextNode:]):
+ (-[WKDOMDocument body]):
+
2014-09-29 Commit Queue <commit-queue@webkit.org>
Unreviewed, rolling out r174045.
diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKDOMDocument.mm b/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKDOMDocument.mm
index 5398b99..ddd7bd6 100644
--- a/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKDOMDocument.mm
+++ b/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKDOMDocument.mm
@@ -39,17 +39,17 @@
{
// FIXME: Do something about the exception.
WebCore::ExceptionCode ec = 0;
- return WebKit::toWKDOMElement(toDocument(_impl.get())->createElement(tagName, ec).get());
+ return WebKit::toWKDOMElement(WebCore::downcast<WebCore::Document>(*_impl).createElement(tagName, ec).get());
}
- (WKDOMText *)createTextNode:(NSString *)data
{
- return WebKit::toWKDOMText(toDocument(_impl.get())->createTextNode(data).get());
+ return WebKit::toWKDOMText(WebCore::downcast<WebCore::Document>(*_impl).createTextNode(data).get());
}
- (WKDOMElement *)body
{
- return WebKit::toWKDOMElement(toDocument(_impl.get())->body());
+ return WebKit::toWKDOMElement(WebCore::downcast<WebCore::Document>(*_impl).body());
}
@end