Replace static_casts with to* functions for document types.
authorinferno@chromium.org <inferno@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Mar 2013 20:29:08 +0000 (20:29 +0000)
committerinferno@chromium.org <inferno@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Mar 2013 20:29:08 +0000 (20:29 +0000)
https://bugs.webkit.org/show_bug.cgi?id=112225

Reviewed by Ryosuke Niwa.

Source/WebCore:

to* helper functions are preferred over static_cast calls since they
help to catch bad casts easily on the testing infrastructure.

* Modules/geolocation/Geolocation.cpp:
(WebCore::Geolocation::document):
....lot of files.

Source/WebKit2:

* WebProcess/InjectedBundle/API/mac/WKDOMDocument.mm: Remove the redundant helper.

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

88 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/geolocation/Geolocation.cpp
Source/WebCore/Modules/indexeddb/IDBFactory.cpp
Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp
Source/WebCore/Modules/mediastream/UserMediaRequest.cpp
Source/WebCore/Modules/notifications/Notification.cpp
Source/WebCore/Modules/speech/SpeechGrammar.cpp
Source/WebCore/Modules/speech/SpeechGrammarList.cpp
Source/WebCore/Modules/speech/SpeechRecognition.cpp
Source/WebCore/Modules/webaudio/OfflineAudioContext.cpp
Source/WebCore/Modules/webdatabase/DatabaseContext.cpp
Source/WebCore/Modules/websockets/ThreadableWebSocketChannel.cpp
Source/WebCore/Modules/websockets/WebSocket.cpp
Source/WebCore/Modules/websockets/WebSocketHandshake.cpp
Source/WebCore/Modules/websockets/WorkerThreadableWebSocketChannel.cpp
Source/WebCore/accessibility/AccessibilityRenderObject.cpp
Source/WebCore/bindings/js/DOMRequestState.h
Source/WebCore/bindings/js/JSAudioContextCustom.cpp
Source/WebCore/bindings/js/JSDOMBinding.h
Source/WebCore/bindings/js/JSDOMGlobalObject.cpp
Source/WebCore/bindings/js/JSDOMWindowCustom.cpp
Source/WebCore/bindings/js/JSHTMLDocumentCustom.cpp
Source/WebCore/bindings/js/JSLazyEventListener.cpp
Source/WebCore/bindings/js/JSNodeCustom.cpp
Source/WebCore/bindings/js/ScheduledAction.cpp
Source/WebCore/bindings/scripts/CodeGeneratorV8.pm
Source/WebCore/bindings/scripts/test/V8/V8TestObj.cpp
Source/WebCore/bindings/v8/PageScriptDebugServer.cpp
Source/WebCore/bindings/v8/ScheduledAction.cpp
Source/WebCore/bindings/v8/V8Binding.cpp
Source/WebCore/bindings/v8/V8EventListener.cpp
Source/WebCore/bindings/v8/V8LazyEventListener.cpp
Source/WebCore/bindings/v8/custom/V8DOMWindowCustom.cpp
Source/WebCore/bindings/v8/custom/V8DocumentCustom.cpp
Source/WebCore/bindings/v8/custom/V8NodeCustom.cpp
Source/WebCore/dom/ContainerNode.cpp
Source/WebCore/dom/CustomElementConstructor.h
Source/WebCore/dom/CustomElementRegistry.cpp
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/dom/DocumentType.cpp
Source/WebCore/dom/Element.cpp
Source/WebCore/dom/EventTarget.cpp
Source/WebCore/dom/NamedFlowCollection.cpp
Source/WebCore/dom/Node.cpp
Source/WebCore/dom/WindowEventContext.cpp
Source/WebCore/editing/MarkupAccumulator.cpp
Source/WebCore/html/HTMLDocument.h
Source/WebCore/html/HTMLFrameOwnerElement.cpp
Source/WebCore/html/HTMLIFrameElement.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/track/TextTrackCue.cpp
Source/WebCore/html/track/TextTrackCue.h
Source/WebCore/html/track/WebVTTParser.cpp
Source/WebCore/inspector/InspectorDOMAgent.cpp
Source/WebCore/inspector/InspectorInstrumentation.cpp
Source/WebCore/inspector/InspectorInstrumentation.h
Source/WebCore/loader/Prerenderer.cpp
Source/WebCore/loader/TextTrackLoader.cpp
Source/WebCore/loader/ThreadableLoader.cpp
Source/WebCore/loader/WorkerThreadableLoader.cpp
Source/WebCore/page/ContentSecurityPolicy.cpp
Source/WebCore/page/DOMWindow.cpp
Source/WebCore/page/DragController.cpp
Source/WebCore/page/EventHandler.cpp
Source/WebCore/page/EventSource.cpp
Source/WebCore/page/FocusController.cpp
Source/WebCore/page/Frame.cpp
Source/WebCore/page/FrameView.cpp
Source/WebCore/page/History.cpp
Source/WebCore/page/SpatialNavigation.cpp
Source/WebCore/page/TouchAdjustment.cpp
Source/WebCore/page/scrolling/ScrollingCoordinator.cpp
Source/WebCore/rendering/RenderText.cpp
Source/WebCore/rendering/RenderTreeAsText.cpp
Source/WebCore/svg/SVGDocument.h
Source/WebCore/svg/graphics/SVGImage.cpp
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/js/WebCoreTestSupport.cpp
Source/WebCore/testing/v8/WebCoreTestSupport.cpp
Source/WebKit/win/DOMHTMLClasses.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKDOMDocument.mm

index 57f58a2..6cc637e 100644 (file)
@@ -1,3 +1,17 @@
+2013-03-13  Abhishek Arya  <inferno@chromium.org>
+
+        Replace static_casts with to* functions for document types.
+        https://bugs.webkit.org/show_bug.cgi?id=112225
+
+        Reviewed by Ryosuke Niwa.
+
+        to* helper functions are preferred over static_cast calls since they
+        help to catch bad casts easily on the testing infrastructure.
+
+        * Modules/geolocation/Geolocation.cpp:
+        (WebCore::Geolocation::document):
+        ....lot of files.
+
 2013-03-13  Liam Quinn  <lquinn@blackberry.com>
 
         Handle XHTML entities in XHTML Mobile Profile 1.1 and 1.2. We previously only handled them in XHTML Mobile Profile 1.0.
index f987d0f..6202d29 100644 (file)
@@ -253,8 +253,7 @@ Geolocation::~Geolocation()
 
 Document* Geolocation::document() const
 {
-    ASSERT_WITH_SECURITY_IMPLICATION(!scriptExecutionContext() || scriptExecutionContext()->isDocument());
-    return static_cast<Document*>(scriptExecutionContext());
+    return toDocument(scriptExecutionContext());
 }
 
 Frame* Geolocation::frame() const
index d0120f6..4b02b11 100644 (file)
@@ -70,7 +70,7 @@ static bool isContextValid(ScriptExecutionContext* context)
 {
     ASSERT(context->isDocument() || context->isWorkerContext());
     if (context->isDocument()) {
-        Document* document = static_cast<Document*>(context);
+        Document* document = toDocument(context);
         return document->frame() && document->page();
     }
 #if !ENABLE(WORKERS)
@@ -84,7 +84,7 @@ static String getIndexedDBDatabasePath(ScriptExecutionContext* context)
 {
     ASSERT(isContextValid(context));
     if (context->isDocument()) {
-        Document* document = static_cast<Document*>(context);
+        Document* document = toDocument(context);
         return document->page()->group().groupSettings()->indexedDBDatabasePath();
     }
 #if ENABLE(WORKERS)
index 6f19eaf..4ea6e50 100644 (file)
@@ -139,8 +139,7 @@ RTCPeerConnection::RTCPeerConnection(ScriptExecutionContext* context, PassRefPtr
     , m_scheduledEventTimer(this, &RTCPeerConnection::scheduledEventTimerFired)
     , m_stopped(false)
 {
-    ASSERT(m_scriptExecutionContext->isDocument());
-    Document* document = static_cast<Document*>(m_scriptExecutionContext);
+    Document* document = toDocument(m_scriptExecutionContext);
 
     if (!document->frame()) {
         ec = NOT_SUPPORTED_ERR;
index b949400..663193c 100644 (file)
@@ -118,8 +118,7 @@ MediaConstraints* UserMediaRequest::videoConstraints() const
 Document* UserMediaRequest::ownerDocument()
 {
     if (m_scriptExecutionContext) {
-        ASSERT(m_scriptExecutionContext->isDocument());
-        return static_cast<Document*>(m_scriptExecutionContext);
+        return toDocument(m_scriptExecutionContext);
     }
 
     return 0;
index 52ec618..b398772 100644 (file)
@@ -109,8 +109,7 @@ Notification::Notification(ScriptExecutionContext* context, const String& title)
     , m_state(Idle)
     , m_taskTimer(adoptPtr(new Timer<Notification>(this, &Notification::taskTimerFired)))
 {
-    ASSERT_WITH_SECURITY_IMPLICATION(context->isDocument());
-    m_notificationCenter = DOMWindowNotifications::webkitNotifications(static_cast<Document*>(context)->domWindow());
+    m_notificationCenter = DOMWindowNotifications::webkitNotifications(toDocument(context)->domWindow());
     
     ASSERT(m_notificationCenter->client());
     m_taskTimer->startOneShot(0);
@@ -171,9 +170,9 @@ void Notification::show()
     // prevent double-showing
     if (m_state == Idle && m_notificationCenter->client()) {
 #if ENABLE(NOTIFICATIONS)
-        if (!static_cast<Document*>(scriptExecutionContext())->page())
+        if (!toDocument(scriptExecutionContext())->page())
             return;
-        if (NotificationController::from(static_cast<Document*>(scriptExecutionContext())->page())->client()->checkPermission(scriptExecutionContext()) != NotificationClient::PermissionAllowed) {
+        if (NotificationController::from(toDocument(scriptExecutionContext())->page())->client()->checkPermission(scriptExecutionContext()) != NotificationClient::PermissionAllowed) {
             dispatchErrorEvent();
             return;
         }
@@ -259,9 +258,8 @@ void Notification::taskTimerFired(Timer<Notification>* timer)
 #if ENABLE(NOTIFICATIONS)
 const String& Notification::permission(ScriptExecutionContext* context)
 {
-    ASSERT_WITH_SECURITY_IMPLICATION(context->isDocument());
-    ASSERT(static_cast<Document*>(context)->page());
-    return permissionString(NotificationController::from(static_cast<Document*>(context)->page())->client()->checkPermission(context));
+    ASSERT(toDocument(context)->page());
+    return permissionString(NotificationController::from(toDocument(context)->page())->client()->checkPermission(context));
 }
 
 const String& Notification::permissionString(NotificationClient::Permission permission)
@@ -285,9 +283,8 @@ const String& Notification::permissionString(NotificationClient::Permission perm
 
 void Notification::requestPermission(ScriptExecutionContext* context, PassRefPtr<NotificationPermissionCallback> callback)
 {
-    ASSERT_WITH_SECURITY_IMPLICATION(context->isDocument());
-    ASSERT(static_cast<Document*>(context)->page());
-    NotificationController::from(static_cast<Document*>(context)->page())->client()->requestPermission(context, callback);
+    ASSERT(toDocument(context)->page());
+    NotificationController::from(toDocument(context)->page())->client()->requestPermission(context, callback);
 }
 #endif
 
index 50a1406..59d42f9 100644 (file)
@@ -45,8 +45,7 @@ PassRefPtr<SpeechGrammar> SpeechGrammar::create(const KURL& src, double weight)
 
 void SpeechGrammar::setSrc(ScriptExecutionContext* scriptExecutionContext, const String& src)
 {
-    ASSERT_WITH_SECURITY_IMPLICATION(scriptExecutionContext->isDocument());
-    Document* document = static_cast<Document*>(scriptExecutionContext);
+    Document* document = toDocument(scriptExecutionContext);
     m_src = document->completeURL(src);
 }
 
index 9853ef7..c3ddbe1 100644 (file)
@@ -48,8 +48,7 @@ SpeechGrammar* SpeechGrammarList::item(unsigned long index) const
 
 void SpeechGrammarList::addFromUri(ScriptExecutionContext* scriptExecutionContext, const String& src, double weight)
 {
-    ASSERT_WITH_SECURITY_IMPLICATION(scriptExecutionContext->isDocument());
-    Document* document = static_cast<Document*>(scriptExecutionContext);
+    Document* document = toDocument(scriptExecutionContext);
     m_grammars.append(SpeechGrammar::create(document->completeURL(src), weight));
 }
 
index beda827..212b201 100644 (file)
@@ -171,8 +171,7 @@ SpeechRecognition::SpeechRecognition(ScriptExecutionContext* context)
     , m_stoppedByActiveDOMObject(false)
     , m_started(false)
 {
-    ASSERT(scriptExecutionContext()->isDocument());
-    Document* document = static_cast<Document*>(scriptExecutionContext());
+    Document* document = toDocument(scriptExecutionContext());
 
     Page* page = document->page();
     ASSERT(page);
index 3fe3627..e22012b 100644 (file)
@@ -43,7 +43,7 @@ PassRefPtr<OfflineAudioContext> OfflineAudioContext::create(ScriptExecutionConte
         return 0;
     }
 
-    Document* document = static_cast<Document*>(context);
+    Document* document = toDocument(context);
 
     // FIXME: offline contexts have limitations on supported sample-rates.
     // Currently all AudioContexts must have the same sample-rate.
index 0e818ae..798b399 100644 (file)
@@ -205,7 +205,7 @@ bool DatabaseContext::stopDatabases(DatabaseTaskSynchronizer* cleanupSync)
 bool DatabaseContext::allowDatabaseAccess() const
 {
     if (m_scriptExecutionContext->isDocument()) {
-        Document* document = static_cast<Document*>(m_scriptExecutionContext);
+        Document* document = toDocument(m_scriptExecutionContext);
         if (!document->page() || (document->page()->settings()->privateBrowsingEnabled() && !SchemeRegistry::allowsDatabaseAccessInPrivateBrowsing(document->securityOrigin()->protocol())))
             return false;
         return true;
@@ -218,7 +218,7 @@ bool DatabaseContext::allowDatabaseAccess() const
 void DatabaseContext::databaseExceededQuota(const String& name, DatabaseDetails details)
 {
     if (m_scriptExecutionContext->isDocument()) {
-        Document* document = static_cast<Document*>(m_scriptExecutionContext);
+        Document* document = toDocument(m_scriptExecutionContext);
         if (Page* page = document->page())
             page->chrome()->client()->exceededDatabaseQuota(document->frame(), name, details);
         return;
index 95f45ea..9e51849 100644 (file)
@@ -65,8 +65,7 @@ PassRefPtr<ThreadableWebSocketChannel> ThreadableWebSocketChannel::create(Script
     }
 #endif // ENABLE(WORKERS)
 
-    ASSERT_WITH_SECURITY_IMPLICATION(context->isDocument());
-    return WebSocketChannel::create(static_cast<Document*>(context), client);
+    return WebSocketChannel::create(toDocument(context), client);
 }
 
 } // namespace WebCore
index 16545a4..c33c747 100644 (file)
@@ -243,7 +243,7 @@ void WebSocket::connect(const String& url, const Vector<String>& protocols, Exce
     // 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 = static_cast<Document*>(scriptExecutionContext());
+        Document* document = toDocument(scriptExecutionContext());
         shouldBypassMainWorldContentSecurityPolicy = document->frame()->script()->shouldBypassMainWorldContentSecurityPolicy();
     }
     if (!shouldBypassMainWorldContentSecurityPolicy && !scriptExecutionContext()->contentSecurityPolicy()->allowConnectToSource(m_url)) {
index fd8d36d..cdc3bc4 100644 (file)
@@ -199,7 +199,7 @@ CString WebSocketHandshake::clientHandshakeMessage() const
 
     KURL url = httpURLForAuthenticationAndCookies();
     if (m_context->isDocument()) {
-        Document* document = static_cast<Document*>(m_context);
+        Document* document = toDocument(m_context);
         String cookie = cookieRequestHeaderFieldValue(document, url);
         if (!cookie.isEmpty())
             fields.append("Cookie: " + cookie);
@@ -251,7 +251,7 @@ PassRefPtr<WebSocketHandshakeRequest> WebSocketHandshake::clientHandshakeRequest
 
     KURL url = httpURLForAuthenticationAndCookies();
     if (m_context->isDocument()) {
-        Document* document = static_cast<Document*>(m_context);
+        Document* document = toDocument(m_context);
         String cookie = cookieRequestHeaderFieldValue(document, url);
         if (!cookie.isEmpty())
             request->addHeaderField("Cookie", cookie);
index 143c8f2..b16dfd2 100644 (file)
@@ -147,7 +147,7 @@ void WorkerThreadableWebSocketChannel::resume()
 WorkerThreadableWebSocketChannel::Peer::Peer(PassRefPtr<ThreadableWebSocketChannelClientWrapper> clientWrapper, WorkerLoaderProxy& loaderProxy, ScriptExecutionContext* context, const String& taskMode)
     : m_workerClientWrapper(clientWrapper)
     , m_loaderProxy(loaderProxy)
-    , m_mainWebSocketChannel(WebSocketChannel::create(static_cast<Document*>(context), this))
+    , m_mainWebSocketChannel(WebSocketChannel::create(toDocument(context), this))
     , m_taskMode(taskMode)
 {
     ASSERT(isMainThread());
index 41e9ca1..e5f0589 100644 (file)
@@ -2801,7 +2801,7 @@ AccessibilitySVGRoot* AccessibilityRenderObject::remoteSVGRootElement() const
     if (!doc || !doc->isSVGDocument())
         return 0;
     
-    SVGSVGElement* rootElement = static_cast<SVGDocument*>(doc)->rootElement();
+    SVGSVGElement* rootElement = toSVGDocument(doc)->rootElement();
     if (!rootElement)
         return 0;
     RenderObject* rendererRoot = rootElement->renderer();
index 32d4edc..41d336e 100644 (file)
@@ -48,7 +48,7 @@ public:
         , m_exec(0)
     {
         if (m_scriptExecutionContext->isDocument()) {
-            Document* document = static_cast<Document*>(m_scriptExecutionContext);
+            Document* document = toDocument(m_scriptExecutionContext);
             m_exec = scriptStateFromPage(mainThreadNormalWorld(), document->page());
         } else {
 #if ENABLE(WORKERS)
index 61d787d..129e65d 100644 (file)
@@ -64,7 +64,7 @@ EncodedJSValue JSC_HOST_CALL JSAudioContextConstructor::constructJSAudioContext(
     if (!scriptExecutionContext->isDocument())
         return throwVMError(exec, createReferenceError(exec, "AudioContext constructor called in a script execution context which is not a document"));
 
-    Document* document = static_cast<Document*>(scriptExecutionContext);
+    Document* document = toDocument(scriptExecutionContext);
 
     RefPtr<AudioContext> audioContext;
     
index af69983..bb0d89c 100644 (file)
@@ -82,7 +82,7 @@ class DOMStringList;
     public:
         Document* document() const
         {
-            return static_cast<Document*>(scriptExecutionContext());
+            return toDocument(scriptExecutionContext());
         }
 
     protected:
index d5a95b1..91ffab8 100644 (file)
@@ -113,7 +113,7 @@ JSDOMGlobalObject* toJSDOMGlobalObject(Document* document, JSC::ExecState* exec)
 JSDOMGlobalObject* toJSDOMGlobalObject(ScriptExecutionContext* scriptExecutionContext, JSC::ExecState* exec)
 {
     if (scriptExecutionContext->isDocument())
-        return toJSDOMGlobalObject(static_cast<Document*>(scriptExecutionContext), exec);
+        return toJSDOMGlobalObject(toDocument(scriptExecutionContext), exec);
 
 #if ENABLE(WORKERS)
     if (scriptExecutionContext->isWorkerContext())
@@ -132,7 +132,7 @@ JSDOMGlobalObject* toJSDOMGlobalObject(Document* document, DOMWrapperWorld* worl
 JSDOMGlobalObject* toJSDOMGlobalObject(ScriptExecutionContext* scriptExecutionContext, DOMWrapperWorld* world)
 {
     if (scriptExecutionContext->isDocument())
-        return toJSDOMGlobalObject(static_cast<Document*>(scriptExecutionContext), world);
+        return toJSDOMGlobalObject(toDocument(scriptExecutionContext), world);
 
 #if ENABLE(WORKERS)
     if (scriptExecutionContext->isWorkerContext())
index 25b5339..f2d92b4 100644 (file)
@@ -260,7 +260,7 @@ bool JSDOMWindow::getOwnPropertySlot(JSCell* cell, ExecState* exec, PropertyName
     Document* document = thisObject->impl()->frame()->document();
     if (document->isHTMLDocument()) {
         AtomicStringImpl* atomicPropertyName = findAtomicString(propertyName);
-        if (atomicPropertyName && (static_cast<HTMLDocument*>(document)->hasNamedItem(atomicPropertyName) || document->hasElementWithId(atomicPropertyName))) {
+        if (atomicPropertyName && (toHTMLDocument(document)->hasNamedItem(atomicPropertyName) || document->hasElementWithId(atomicPropertyName))) {
             slot.setCustom(thisObject, namedItemGetter);
             return true;
         }
@@ -336,7 +336,7 @@ bool JSDOMWindow::getOwnPropertySlotByIndex(JSCell* cell, ExecState* exec, unsig
     Document* document = thisObject->impl()->frame()->document();
     if (document->isHTMLDocument()) {
         AtomicStringImpl* atomicPropertyName = findAtomicString(propertyName);
-        if (atomicPropertyName && (static_cast<HTMLDocument*>(document)->hasNamedItem(atomicPropertyName) || document->hasElementWithId(atomicPropertyName))) {
+        if (atomicPropertyName && (toHTMLDocument(document)->hasNamedItem(atomicPropertyName) || document->hasElementWithId(atomicPropertyName))) {
             slot.setCustom(thisObject, namedItemGetter);
             return true;
         }
@@ -407,7 +407,7 @@ bool JSDOMWindow::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, Pr
     Document* document = thisObject->impl()->frame()->document();
     if (document->isHTMLDocument()) {
         AtomicStringImpl* atomicPropertyName = findAtomicString(propertyName);
-        if (atomicPropertyName && (static_cast<HTMLDocument*>(document)->hasNamedItem(atomicPropertyName) || document->hasElementWithId(atomicPropertyName))) {
+        if (atomicPropertyName && (toHTMLDocument(document)->hasNamedItem(atomicPropertyName) || document->hasElementWithId(atomicPropertyName))) {
             PropertySlot slot;
             slot.setCustom(thisObject, namedItemGetter);
             descriptor.setDescriptor(slot.getValue(exec, propertyName), ReadOnly | DontDelete | DontEnum);
index 3c6893b..e6885e1 100644 (file)
@@ -60,7 +60,7 @@ bool JSHTMLDocument::canGetItemsForName(ExecState*, HTMLDocument* document, Prop
 JSValue JSHTMLDocument::nameGetter(ExecState* exec, JSValue slotBase, PropertyName propertyName)
 {
     JSHTMLDocument* thisObj = jsCast<JSHTMLDocument*>(asObject(slotBase));
-    HTMLDocument* document = static_cast<HTMLDocument*>(thisObj->impl());
+    HTMLDocument* document = toHTMLDocument(thisObj->impl());
 
     RefPtr<HTMLCollection> collection = document->documentNamedItems(propertyNameToAtomicString(propertyName));
 
@@ -89,7 +89,7 @@ JSValue JSHTMLDocument::all(ExecState* exec) const
     if (v)
         return v;
 
-    return toJS(exec, globalObject(), static_cast<HTMLDocument*>(impl())->all());
+    return toJS(exec, globalObject(), toHTMLDocument(impl())->all());
 }
 
 void JSHTMLDocument::setAll(ExecState* exec, JSValue value)
@@ -104,7 +104,7 @@ JSValue JSHTMLDocument::open(ExecState* exec)
 {
     // For compatibility with other browsers, pass open calls with more than 2 parameters to the window.
     if (exec->argumentCount() > 2) {
-        Frame* frame = static_cast<HTMLDocument*>(impl())->frame();
+        Frame* frame = toHTMLDocument(impl())->frame();
         if (frame) {
             JSDOMWindowShell* wrapper = toJSDOMWindowShell(frame, currentWorld(exec));
             if (wrapper) {
@@ -124,7 +124,7 @@ JSValue JSHTMLDocument::open(ExecState* exec)
     Document* activeDocument = asJSDOMWindow(exec->lexicalGlobalObject())->impl()->document();
 
     // In the case of two parameters or fewer, do a normal document open.
-    static_cast<HTMLDocument*>(impl())->open(activeDocument);
+    toHTMLDocument(impl())->open(activeDocument);
     return this;
 }
 
@@ -157,13 +157,13 @@ static inline void documentWrite(ExecState* exec, HTMLDocument* document, Newlin
 
 JSValue JSHTMLDocument::write(ExecState* exec)
 {
-    documentWrite(exec, static_cast<HTMLDocument*>(impl()), DoNotAddNewline);
+    documentWrite(exec, toHTMLDocument(impl()), DoNotAddNewline);
     return jsUndefined();
 }
 
 JSValue JSHTMLDocument::writeln(ExecState* exec)
 {
-    documentWrite(exec, static_cast<HTMLDocument*>(impl()), DoAddNewline);
+    documentWrite(exec, toHTMLDocument(impl()), DoAddNewline);
     return jsUndefined();
 }
 
index 87449af..3df6644 100644 (file)
@@ -82,7 +82,7 @@ JSObject* JSLazyEventListener::initializeJSFunction(ScriptExecutionContext* exec
     if (m_code.isNull() || m_eventParameterName.isNull())
         return 0;
 
-    Document* document = static_cast<Document*>(executionContext);
+    Document* document = toDocument(executionContext);
 
     if (!document->frame())
         return 0;
index 99f2d55..0f74aa5 100644 (file)
@@ -243,7 +243,7 @@ static ALWAYS_INLINE JSValue createWrapperInline(ExecState* exec, JSDOMGlobalObj
             break;
         case Node::DOCUMENT_NODE:
             // we don't want to cache the document itself in the per-document dictionary
-            return toJS(exec, globalObject, static_cast<Document*>(node));
+            return toJS(exec, globalObject, toDocument(node));
         case Node::DOCUMENT_TYPE_NODE:
             wrapper = CREATE_DOM_WRAPPER(exec, globalObject, DocumentType, node);
             break;
index fe51c84..a8c0c83 100644 (file)
@@ -77,7 +77,7 @@ ScheduledAction::ScheduledAction(ExecState* exec, JSValue function, DOMWrapperWo
 void ScheduledAction::execute(ScriptExecutionContext* context)
 {
     if (context->isDocument())
-        execute(static_cast<Document*>(context));
+        execute(toDocument(context));
 #if ENABLE(WORKERS)
     else {
         ASSERT(context->isWorkerContext());
index ef20f9f..8fed18e 100644 (file)
@@ -3220,7 +3220,7 @@ END
             my $enableFunction = GetContextEnableFunction($runtimeFunc->signature);
             my $conditionalString = $codeGenerator->GenerateConditionalString($runtimeFunc->signature);
             push(@implContent, "\n#if ${conditionalString}\n") if $conditionalString;
-            push(@implContent, "    if (context && context->isDocument() && ${enableFunction}(static_cast<Document*>(context))) {\n");
+            push(@implContent, "    if (context && context->isDocument() && ${enableFunction}(toDocument(context))) {\n");
             my $name = $runtimeFunc->signature->name;
             push(@implContent, <<END);
         proto->Set(v8::String::NewSymbol("${name}"), v8::FunctionTemplate::New(${interfaceName}V8Internal::${name}MethodCallback, v8Undefined(), defaultSignature)->GetFunction());
index 0a4cc33..e72d16e 100644 (file)
@@ -3195,10 +3195,10 @@ void V8TestObj::installPerContextPrototypeProperties(v8::Handle<v8::Object> prot
     UNUSED_PARAM(defaultSignature); // In some cases, it will not be used.
 
     ScriptExecutionContext* context = toScriptExecutionContext(proto->CreationContext());
-    if (context && context->isDocument() && ContextFeatures::enabledPerContextMethod1Enabled(static_cast<Document*>(context))) {
+    if (context && context->isDocument() && ContextFeatures::enabledPerContextMethod1Enabled(toDocument(context))) {
         proto->Set(v8::String::NewSymbol("enabledPerContextMethod1"), v8::FunctionTemplate::New(TestObjV8Internal::enabledPerContextMethod1MethodCallback, v8Undefined(), defaultSignature)->GetFunction());
     }
-    if (context && context->isDocument() && ContextFeatures::featureNameEnabled(static_cast<Document*>(context))) {
+    if (context && context->isDocument() && ContextFeatures::featureNameEnabled(toDocument(context))) {
         proto->Set(v8::String::NewSymbol("enabledPerContextMethod2"), v8::FunctionTemplate::New(TestObjV8Internal::enabledPerContextMethod2MethodCallback, v8Undefined(), defaultSignature)->GetFunction());
     }
 }
index f95e2aa..27e8015 100644 (file)
@@ -134,7 +134,7 @@ void PageScriptDebugServer::setClientMessageLoop(PassOwnPtr<ClientMessageLoop> c
 void PageScriptDebugServer::compileScript(ScriptState* state, const String& expression, const String& sourceURL, String* scriptId, String* exceptionMessage)
 {
     ScriptExecutionContext* scriptExecutionContext = state->scriptExecutionContext();
-    RefPtr<Frame> protect = static_cast<Document*>(scriptExecutionContext)->frame();
+    RefPtr<Frame> protect = toDocument(scriptExecutionContext)->frame();
     ScriptDebugServer::compileScript(state, expression, sourceURL, scriptId, exceptionMessage);
     if (!scriptId->isNull())
         m_compiledScriptURLs.set(*scriptId, sourceURL);
@@ -151,7 +151,7 @@ void PageScriptDebugServer::runScript(ScriptState* state, const String& scriptId
     String sourceURL = m_compiledScriptURLs.take(scriptId);
 
     ScriptExecutionContext* scriptExecutionContext = state->scriptExecutionContext();
-    Frame* frame = static_cast<Document*>(scriptExecutionContext)->frame();
+    Frame* frame = toDocument(scriptExecutionContext)->frame();
     InspectorInstrumentationCookie cookie;
     if (frame)
         cookie = InspectorInstrumentation::willEvaluateScript(frame, sourceURL, TextPosition::minimumPosition().m_line.oneBasedInt());
index e5ae7c3..ae2f172 100644 (file)
@@ -78,7 +78,7 @@ ScheduledAction::~ScheduledAction()
 void ScheduledAction::execute(ScriptExecutionContext* context)
 {
     if (context->isDocument()) {
-        Frame* frame = static_cast<Document*>(context)->frame();
+        Frame* frame = toDocument(context)->frame();
         if (!frame)
             return;
         if (!frame->script()->canExecuteScripts(AboutToExecuteScript))
index c5053ba..eb8ac4a 100644 (file)
@@ -261,7 +261,7 @@ Frame* toFrameIfNotDetached(v8::Handle<v8::Context> context)
 v8::Local<v8::Context> toV8Context(ScriptExecutionContext* context, const WorldContextHandle& worldContext)
 {
     if (context->isDocument()) {
-        if (Frame* frame = static_cast<Document*>(context)->frame())
+        if (Frame* frame = toDocument(context)->frame())
             return worldContext.adjustedContext(frame->script());
 #if ENABLE(WORKERS)
     } else if (context->isWorkerContext()) {
@@ -275,7 +275,7 @@ v8::Local<v8::Context> toV8Context(ScriptExecutionContext* context, const WorldC
 v8::Local<v8::Context> toV8Context(ScriptExecutionContext* context, DOMWrapperWorld* world)
 {
     if (context->isDocument()) {
-        if (Frame* frame = static_cast<Document*>(context)->frame()) {
+        if (Frame* frame = toDocument(context)->frame()) {
             // FIXME: Store the DOMWrapperWorld for the main world in the v8::Context so callers
             // that are looking up their world with DOMWrapperWorld::isolatedWorld(v8::Context::GetCurrent())
             // won't end up passing null here when later trying to get their v8::Context back.
index 871c328..cb80f32 100644 (file)
@@ -85,7 +85,7 @@ v8::Local<v8::Value> V8EventListener::callListenerFunction(ScriptExecutionContex
     if (!context->isDocument())
         return v8::Local<v8::Value>();
 
-    Frame* frame = static_cast<Document*>(context)->frame();
+    Frame* frame = toDocument(context)->frame();
     if (!frame)
         return v8::Local<v8::Value>();
 
index a74e5b0..929b503 100644 (file)
@@ -93,7 +93,7 @@ v8::Local<v8::Value> V8LazyEventListener::callListenerFunction(ScriptExecutionCo
     if (!context->isDocument())
         return v8::Local<v8::Value>();
 
-    Frame* frame = static_cast<Document*>(context)->frame();
+    Frame* frame = toDocument(context)->frame();
     if (!frame)
         return v8::Local<v8::Value>();
 
@@ -113,13 +113,13 @@ void V8LazyEventListener::prepareListenerObject(ScriptExecutionContext* context)
     if (hasExistingListenerObject())
         return;
 
-    if (context->isDocument() && !static_cast<Document*>(context)->contentSecurityPolicy()->allowInlineEventHandlers(m_sourceURL, m_position.m_line))
+    if (context->isDocument() && !toDocument(context)->contentSecurityPolicy()->allowInlineEventHandlers(m_sourceURL, m_position.m_line))
         return;
 
     v8::HandleScope handleScope;
 
     ASSERT(context->isDocument());
-    Frame* frame = static_cast<Document*>(context)->frame();
+    Frame* frame = toDocument(context)->frame();
     ASSERT(frame);
     if (!frame->script()->canExecuteScripts(NotAboutToExecuteScript))
         return;
index fb742b4..595bdf8 100644 (file)
@@ -483,7 +483,7 @@ v8::Handle<v8::Value> V8DOMWindow::namedPropertyGetter(v8::Local<v8::String> nam
     Document* doc = frame->document();
 
     if (doc && doc->isHTMLDocument()) {
-        if (static_cast<HTMLDocument*>(doc)->hasNamedItem(propName.impl()) || doc->hasElementWithId(propName.impl())) {
+        if (toHTMLDocument(doc)->hasNamedItem(propName.impl()) || doc->hasElementWithId(propName.impl())) {
             RefPtr<HTMLCollection> items = doc->windowNamedItems(propName);
             if (!items->isEmpty()) {
                 if (items->hasExactlyOneItem())
index 608e708..3d71ea6 100644 (file)
@@ -93,10 +93,10 @@ v8::Handle<v8::Object> wrap(Document* impl, v8::Handle<v8::Object> creationConte
 {
     ASSERT(impl);
     if (impl->isHTMLDocument())
-        return wrap(static_cast<HTMLDocument*>(impl), creationContext, isolate);
+        return wrap(toHTMLDocument(impl), creationContext, isolate);
 #if ENABLE(SVG)
     if (impl->isSVGDocument())
-        return wrap(static_cast<SVGDocument*>(impl), creationContext, isolate);
+        return wrap(toSVGDocument(impl), creationContext, isolate);
 #endif
     v8::Handle<v8::Object> wrapper = V8Document::createWrapper(impl, creationContext, isolate);
     if (wrapper.IsEmpty())
index 7c2ff9d..c17f6e3 100644 (file)
@@ -149,7 +149,7 @@ v8::Handle<v8::Object> wrap(Node* impl, v8::Handle<v8::Object> creationContext,
     case Node::COMMENT_NODE:
         return wrap(static_cast<Comment*>(impl), creationContext, isolate);
     case Node::DOCUMENT_NODE:
-        return wrap(static_cast<Document*>(impl), creationContext, isolate);
+        return wrap(toDocument(impl), creationContext, isolate);
     case Node::DOCUMENT_TYPE_NODE:
         return wrap(static_cast<DocumentType*>(impl), creationContext, isolate);
     case Node::DOCUMENT_FRAGMENT_NODE:
index 7b3831b..5ccd7ac 100644 (file)
@@ -203,7 +203,7 @@ static inline ExceptionCode checkAcceptChild(ContainerNode* newParent, Node* new
         return HIERARCHY_REQUEST_ERR;
 
     if (oldChild && newParent->isDocumentNode()) {
-        if (!static_cast<Document*>(newParent)->canReplaceChild(newChild, oldChild))
+        if (!toDocument(newParent)->canReplaceChild(newChild, oldChild))
             return HIERARCHY_REQUEST_ERR;
     } else if (!isChildTypeAllowed(newParent, newChild))
         return HIERARCHY_REQUEST_ERR;
index 844e0e8..ce1bee2 100644 (file)
@@ -54,7 +54,7 @@ public:
 
     virtual ~CustomElementConstructor();
 
-    Document* document() const { return static_cast<Document*>(m_scriptExecutionContext); }
+    Document* document() const { return toDocument(m_scriptExecutionContext); }
     const QualifiedName& name() const { return m_name; }
 
     PassRefPtr<Element> createElement() const;
index d8b0cd9..48863bb 100644 (file)
@@ -164,7 +164,7 @@ PassRefPtr<Element> CustomElementRegistry::createElement(const QualifiedName& na
 
 inline Document* CustomElementRegistry::document() const
 {
-    return static_cast<Document*>(m_scriptExecutionContext);
+    return toDocument(m_scriptExecutionContext);
 }
 
 }
index c5847af..9d5e74e 100644 (file)
@@ -2864,7 +2864,7 @@ void Document::processHttpEquiv(const String& equiv, const String& content)
         // FIXME: make setCookie work on XML documents too; e.g. in case of <html:meta .....>
         if (isHTMLDocument()) {
             // Exception (for sandboxed documents) ignored.
-            static_cast<HTMLDocument*>(this)->setCookie(content, IGNORE_EXCEPTION);
+            toHTMLDocument(this)->setCookie(content, IGNORE_EXCEPTION);
         }
     } else if (equalIgnoringCase(equiv, "content-language"))
         setContentLanguage(content);
@@ -5755,7 +5755,7 @@ Node* eventTargetNodeForDocument(Document* doc)
         return 0;
     Node* node = doc->focusedNode();
     if (!node && doc->isPluginDocument()) {
-        PluginDocument* pluginDocument = static_cast<PluginDocument*>(doc);
+        PluginDocument* pluginDocument = toPluginDocument(doc);
         node =  pluginDocument->pluginNode();
     }
     if (!node && doc->isHTMLDocument())
index a41a05d..6dab749 100644 (file)
@@ -1214,7 +1214,7 @@ private:
     typedef void (*ArgumentsCallback)(const String& keyString, const String& valueString, Document*, void* data);
     void processArguments(const String& features, void* data, ArgumentsCallback);
 
-    virtual bool isDocument() const { return true; }
+    virtual bool isDocument() const OVERRIDE { return true; }
 
     virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
 
@@ -1583,6 +1583,33 @@ inline const Document* Document::templateDocument() const
 }
 #endif
 
+inline Document* toDocument(ScriptExecutionContext* scriptExecutionContext)
+{
+    ASSERT_WITH_SECURITY_IMPLICATION(!scriptExecutionContext || scriptExecutionContext->isDocument());
+    return static_cast<Document*>(scriptExecutionContext);
+}
+
+inline const Document* toDocument(const ScriptExecutionContext* scriptExecutionContext)
+{
+    ASSERT_WITH_SECURITY_IMPLICATION(!scriptExecutionContext || scriptExecutionContext->isDocument());
+    return static_cast<const Document*>(scriptExecutionContext);
+}
+
+inline Document* toDocument(Node* node)
+{
+    ASSERT_WITH_SECURITY_IMPLICATION(!node || node->isDocumentNode());
+    return static_cast<Document*>(node);
+}
+
+inline const Document* toDocument(const Node* node)
+{
+    ASSERT_WITH_SECURITY_IMPLICATION(!node || node->isDocumentNode());
+    return static_cast<const Document*>(node);
+}
+
+// This will catch anyone doing an unnecessary cast.
+void toDocument(const Document*);
+
 // Put these methods here, because they require the Document definition, but we really want to inline them.
 
 inline bool Node::isDocumentNode() const
index cd1d485..bc9177b 100644 (file)
@@ -65,7 +65,7 @@ Node::InsertionNotificationRequest DocumentType::insertedInto(ContainerNode* ins
     // Our document node can be null if we were created by a DOMImplementation.  We use the parent() instead.
     ASSERT(parentNode() && parentNode()->isDocumentNode());
     if (parentNode() && parentNode()->isDocumentNode()) {
-        Document* doc = static_cast<Document*>(parentNode());
+        Document* doc = toDocument(parentNode());
         if (!doc->doctype())
             doc->setDocType(this);
     }
index 663049a..9d38043 100644 (file)
@@ -2199,7 +2199,7 @@ AtomicString Element::computeInheritedLanguage() const
             }
         } else if (n->isDocumentNode()) {
             // checking the MIME content-language
-            value = static_cast<const Document*>(n)->contentLanguage();
+            value = toDocument(n)->contentLanguage();
         }
 
         n = n->parentNode();
@@ -2682,10 +2682,10 @@ void Element::updateNamedItemRegistration(const AtomicString& oldName, const Ato
         return;
 
     if (!oldName.isEmpty())
-        static_cast<HTMLDocument*>(document())->removeNamedItem(oldName);
+        toHTMLDocument(document())->removeNamedItem(oldName);
 
     if (!newName.isEmpty())
-        static_cast<HTMLDocument*>(document())->addNamedItem(newName);
+        toHTMLDocument(document())->addNamedItem(newName);
 }
 
 void Element::updateExtraNamedItemRegistration(const AtomicString& oldId, const AtomicString& newId)
@@ -2694,10 +2694,10 @@ void Element::updateExtraNamedItemRegistration(const AtomicString& oldId, const
         return;
 
     if (!oldId.isEmpty())
-        static_cast<HTMLDocument*>(document())->removeExtraNamedItem(oldId);
+        toHTMLDocument(document())->removeExtraNamedItem(oldId);
 
     if (!newId.isEmpty())
-        static_cast<HTMLDocument*>(document())->addExtraNamedItem(newId);
+        toHTMLDocument(document())->addExtraNamedItem(newId);
 }
 
 PassRefPtr<HTMLCollection> Element::ensureCachedHTMLCollection(CollectionType type)
index c11d20f..c093ec1 100644 (file)
@@ -207,7 +207,7 @@ bool EventTarget::fireEventListeners(Event* event)
     if (!prefixedTypeName.isEmpty()) {
         ScriptExecutionContext* context = scriptExecutionContext();
         if (context && context->isDocument()) {
-            Document* document = static_cast<Document*>(context);
+            Document* document = toDocument(context);
             if (document->domWindow()) {
                 if (listenerPrefixedVector)
                     if (listenerUnprefixedVector)
@@ -263,7 +263,7 @@ void EventTarget::fireEventListeners(Event* event, EventTargetData* d, EventList
     if (userEventWasHandled) {
         ScriptExecutionContext* context = scriptExecutionContext();
         if (context && context->isDocument()) {
-            Document* document = static_cast<Document*>(context);
+            Document* document = toDocument(context);
             document->resetLastHandledUserGestureTimestamp();
         }
     }
index 2bb940c..f9c073d 100644 (file)
@@ -103,8 +103,7 @@ void NamedFlowCollection::discardNamedFlow(WebKitNamedFlow* namedFlow)
 Document* NamedFlowCollection::document() const
 {
     ScriptExecutionContext* context = ContextDestructionObserver::scriptExecutionContext();
-    ASSERT(!context || context->isDocument());
-    return static_cast<Document*>(context);
+    return toDocument(context);
 }
 
 PassRefPtr<DOMNamedFlowCollection> NamedFlowCollection::createCSSOMSnapshot()
index 3cb0e6f..e0f9632 100644 (file)
@@ -1492,7 +1492,7 @@ bool Node::isDefaultNamespace(const AtomicString& namespaceURIMaybeEmpty) const
             return false;
         }
         case DOCUMENT_NODE:
-            if (Element* de = static_cast<const Document*>(this)->documentElement())
+            if (Element* de = toDocument(this)->documentElement())
                 return de->isDefaultNamespace(namespaceURI);
             return false;
         case ENTITY_NODE:
@@ -1525,7 +1525,7 @@ String Node::lookupPrefix(const AtomicString &namespaceURI) const
         case ELEMENT_NODE:
             return lookupNamespacePrefix(namespaceURI, static_cast<const Element *>(this));
         case DOCUMENT_NODE:
-            if (Element* de = static_cast<const Document*>(this)->documentElement())
+            if (Element* de = toDocument(this)->documentElement())
                 return de->lookupPrefix(namespaceURI);
             return String();
         case ENTITY_NODE:
@@ -1583,7 +1583,7 @@ String Node::lookupNamespaceURI(const String &prefix) const
             return String();
         }
         case DOCUMENT_NODE:
-            if (Element* de = static_cast<const Document*>(this)->documentElement())
+            if (Element* de = toDocument(this)->documentElement())
                 return de->lookupNamespaceURI(prefix);
             return String();
         case ENTITY_NODE:
index 0709330..d63ee39 100644 (file)
@@ -46,7 +46,7 @@ WindowEventContext::WindowEventContext(Event* event, PassRefPtr<Node> node, cons
     if (!topLevelContainer->isDocumentNode())
         return;
 
-    m_window = static_cast<Document*>(topLevelContainer)->domWindow();
+    m_window = toDocument(topLevelContainer)->domWindow();
     m_target = topEventContext ? topEventContext->target() : node.get();
 }
 
index e3abb95..05811ea 100644 (file)
@@ -501,7 +501,7 @@ void MarkupAccumulator::appendStartMarkup(StringBuilder& result, const Node* nod
         appendComment(result, static_cast<const Comment*>(node)->data());
         break;
     case Node::DOCUMENT_NODE:
-        appendXMLDeclaration(result, static_cast<const Document*>(node));
+        appendXMLDeclaration(result, toDocument(node));
         break;
     case Node::DOCUMENT_FRAGMENT_NODE:
         break;
index 2aaa798..5142072 100644 (file)
@@ -107,6 +107,21 @@ inline bool HTMLDocument::hasExtraNamedItem(AtomicStringImpl* name)
     return m_extraNamedItemCounts.contains(name);
 }
 
+inline HTMLDocument* toHTMLDocument(Document* document)
+{
+    ASSERT_WITH_SECURITY_IMPLICATION(!document || document->isHTMLDocument());
+    return static_cast<HTMLDocument*>(document);
+}
+
+inline const HTMLDocument* toHTMLDocument(const Document* document)
+{
+    ASSERT_WITH_SECURITY_IMPLICATION(!document || document->isHTMLDocument());
+    return static_cast<const HTMLDocument*>(document);
+}
+
+// This will catch anyone doing an unnecessary cast.
+void toHTMLDocument(const HTMLDocument*);
+
 } // namespace WebCore
 
 #endif // HTMLDocument_h
index e6c3e2f..252522e 100644 (file)
@@ -117,7 +117,7 @@ SVGDocument* HTMLFrameOwnerElement::getSVGDocument(ExceptionCode& ec) const
 {
     Document* doc = contentDocument();
     if (doc && doc->isSVGDocument())
-        return static_cast<SVGDocument*>(doc);
+        return toSVGDocument(doc);
     // Spec: http://www.w3.org/TR/SVG/struct.html#InterfaceGetSVGDocument
     ec = NOT_SUPPORTED_ERR;
     return 0;
index 4d8648b..8b017e6 100644 (file)
@@ -81,7 +81,7 @@ void HTMLIFrameElement::parseAttribute(const QualifiedName& name, const AtomicSt
 {
     if (name == nameAttr) {
         if (inDocument() && document()->isHTMLDocument() && !isInShadowTree()) {
-            HTMLDocument* document = static_cast<HTMLDocument*>(this->document());
+            HTMLDocument* document = toHTMLDocument(this->document());
             document->removeExtraNamedItem(m_name);
             document->addExtraNamedItem(value);
         }
@@ -113,7 +113,7 @@ Node::InsertionNotificationRequest HTMLIFrameElement::insertedInto(ContainerNode
 {
     InsertionNotificationRequest result = HTMLFrameElementBase::insertedInto(insertionPoint);
     if (insertionPoint->inDocument() && document()->isHTMLDocument() && !insertionPoint->isInShadowTree())
-        static_cast<HTMLDocument*>(document())->addExtraNamedItem(m_name);
+        toHTMLDocument(document())->addExtraNamedItem(m_name);
     return result;
 }
 
@@ -121,7 +121,7 @@ void HTMLIFrameElement::removedFrom(ContainerNode* insertionPoint)
 {
     HTMLFrameElementBase::removedFrom(insertionPoint);
     if (insertionPoint->inDocument() && document()->isHTMLDocument() && !insertionPoint->isInShadowTree())
-        static_cast<HTMLDocument*>(document())->removeExtraNamedItem(m_name);
+        toHTMLDocument(document())->removeExtraNamedItem(m_name);
 }
 
 bool HTMLIFrameElement::shouldDisplaySeamlessly() const
index cf8eae6..ac5c0b2 100644 (file)
@@ -3624,7 +3624,7 @@ void HTMLMediaElement::mediaPlayerSawUnsupportedTracks(MediaPlayer*)
     // This is normally acceptable except when we are in a standalone
     // MediaDocument. If so, tell the document what has happened.
     if (ownerDocument()->isMediaDocument()) {
-        MediaDocument* mediaDocument = static_cast<MediaDocument*>(ownerDocument());
+        MediaDocument* mediaDocument = toMediaDocument(ownerDocument());
         mediaDocument->mediaElementSawUnsupportedTracks();
     }
 }
index f4d6758..24e1929 100644 (file)
@@ -442,7 +442,7 @@ void HTMLObjectElement::updateDocNamedItem()
         child = child->nextSibling();
     }
     if (isNamedItem != wasNamedItem && document()->isHTMLDocument()) {
-        HTMLDocument* document = static_cast<HTMLDocument*>(this->document());
+        HTMLDocument* document = toHTMLDocument(this->document());
         if (isNamedItem) {
             document->addNamedItem(getNameAttribute());
             document->addExtraNamedItem(getIdAttribute());
index da24fa6..331daa3 100644 (file)
@@ -84,7 +84,7 @@ public:
 
     ImageDocument* document() const
     {
-        return static_cast<ImageDocument*>(RawDataDocumentParser::document());
+        return toImageDocument(RawDataDocumentParser::document());
     }
     
 private:
index faf9207..f6f998e 100644 (file)
@@ -71,7 +71,22 @@ private:
     // Whether the image should be shrunk or not
     bool m_shouldShrinkImage;
 };
-    
+
+inline ImageDocument* toImageDocument(Document* document)
+{
+    ASSERT_WITH_SECURITY_IMPLICATION(!document || document->isImageDocument());
+    return static_cast<ImageDocument*>(document);
+}
+
+inline const ImageDocument* toImageDocument(const Document* document)
+{
+    ASSERT_WITH_SECURITY_IMPLICATION(!document || document->isImageDocument());
+    return static_cast<const ImageDocument*>(document);
+}
+
+// This will catch anyone doing an unnecessary cast.
+void toImageDocument(const ImageDocument*);
+
 }
 
 #endif // ImageDocument_h
index 2d81296..ec777ae 100644 (file)
@@ -54,7 +54,22 @@ private:
 
     Timer<MediaDocument> m_replaceMediaElementTimer;
 };
-    
+
+inline MediaDocument* toMediaDocument(Document* document)
+{
+    ASSERT_WITH_SECURITY_IMPLICATION(!document || document->isMediaDocument());
+    return static_cast<MediaDocument*>(document);
+}
+
+inline const MediaDocument* toMediaDocument(const Document* document)
+{
+    ASSERT_WITH_SECURITY_IMPLICATION(!document || document->isMediaDocument());
+    return static_cast<const MediaDocument*>(document);
+}
+
+// This will catch anyone doing an unnecessary cast.
+void toMediaDocument(const MediaDocument*);
+
 }
 
 #endif
index c99e350..8ed5672 100644 (file)
@@ -97,7 +97,7 @@ void PluginDocumentParser::createDocumentStructure()
     if (loader)
         m_embedElement->setAttribute(typeAttr, loader->writer()->mimeType());
 
-    static_cast<PluginDocument*>(document())->setPluginNode(m_embedElement);
+    toPluginDocument(document())->setPluginNode(m_embedElement);
 
     body->appendChild(embedElement, IGNORE_EXCEPTION);
 }
index b21943b..5ee3d22 100644 (file)
@@ -202,7 +202,7 @@ TextTrackCue::TextTrackCue(ScriptExecutionContext* context, double start, double
     , m_isActive(false)
     , m_pauseOnExit(false)
     , m_snapToLines(true)
-    , m_cueBackgroundBox(HTMLDivElement::create(static_cast<Document*>(context)))
+    , m_cueBackgroundBox(HTMLDivElement::create(toDocument(context)))
     , m_displayTreeShouldChange(true)
 {
     ASSERT(m_scriptExecutionContext->isDocument());
index 89dd252..b5c5cf4 100644 (file)
@@ -193,7 +193,7 @@ protected:
 
     TextTrackCue(ScriptExecutionContext*, double start, double end, const String& content);
 
-    Document* ownerDocument() { return static_cast<Document*>(m_scriptExecutionContext); }
+    Document* ownerDocument() { return toDocument(m_scriptExecutionContext); }
 
     virtual PassRefPtr<TextTrackCueBox> createDisplayTree();
     PassRefPtr<TextTrackCueBox> displayTreeInternal();
index 2d0f381..d383a84 100644 (file)
@@ -244,7 +244,7 @@ PassRefPtr<DocumentFragment>  WebVTTParser::createDocumentFragmentFromCueText(co
         return 0;
 
     ASSERT(m_scriptExecutionContext->isDocument());
-    Document* document = static_cast<Document*>(m_scriptExecutionContext);
+    Document* document = toDocument(m_scriptExecutionContext);
     
     RefPtr<DocumentFragment> fragment = DocumentFragment::create(document);
     m_currentNode = fragment;
index eee7d4f..1090fe5 100644 (file)
@@ -378,7 +378,7 @@ Document* InspectorDOMAgent::assertDocument(ErrorString* errorString, int nodeId
         *errorString = "Document is not available";
         return 0;
     }
-    return static_cast<Document*>(node);
+    return toDocument(node);
 }
 
 Element* InspectorDOMAgent::assertElement(ErrorString* errorString, int nodeId)
@@ -733,7 +733,7 @@ void InspectorDOMAgent::setOuterHTML(ErrorString* errorString, int nodeId, const
     if (!node)
         return;
 
-    Document* document = node->isDocumentNode() ? static_cast<Document*>(node) : node->ownerDocument();
+    Document* document = node->isDocumentNode() ? toDocument(node) : node->ownerDocument();
     if (!document || !document->isHTMLDocument()) {
         *errorString = "Not an HTML document";
         return;
@@ -1354,7 +1354,7 @@ PassRefPtr<TypeBuilder::DOM::Node> InspectorDOMAgent::buildObjectForNode(Node* n
 #endif
 
     } else if (node->isDocumentNode()) {
-        Document* document = static_cast<Document*>(node);
+        Document* document = toDocument(node);
         value->setDocumentURL(documentURLString(document));
         value->setBaseURL(documentBaseURLString(document));
         value->setXmlVersion(document->xmlVersion());
@@ -1489,7 +1489,7 @@ unsigned InspectorDOMAgent::innerChildNodeCount(Node* node)
 Node* InspectorDOMAgent::innerParentNode(Node* node)
 {
     if (node->isDocumentNode()) {
-        Document* document = static_cast<Document*>(node);
+        Document* document = toDocument(node);
         return document->ownerElement();
     }
     return node->parentNode();
index 4bdad57..ff0f0b8 100644 (file)
@@ -117,7 +117,7 @@ static Frame* frameForScriptExecutionContext(ScriptExecutionContext* context)
 {
     Frame* frame = 0;
     if (context->isDocument())
-        frame = static_cast<Document*>(context)->frame();
+        frame = toDocument(context)->frame();
     return frame;
 }
 
index 53d8ffa..b4a8322 100644 (file)
@@ -2056,7 +2056,7 @@ inline InstrumentingAgents* InspectorInstrumentation::instrumentingAgentsForCont
     if (!context)
         return 0;
     if (context->isDocument())
-        return instrumentingAgentsForPage(static_cast<Document*>(context)->page());
+        return instrumentingAgentsForPage(toDocument(context)->page());
 #if ENABLE(WORKERS)
     return instrumentingAgentsForNonDocumentContext(context);
 #else
index 3c705ff..51ea25e 100644 (file)
@@ -130,7 +130,7 @@ void Prerenderer::resume()
 Document* Prerenderer::document()
 {
     ASSERT(scriptExecutionContext()->isDocument());
-    return static_cast<Document*>(scriptExecutionContext());
+    return toDocument(scriptExecutionContext());
 }
 
 PrerendererClient* Prerenderer::client()
index 26bc8cb..00a1d8f 100644 (file)
@@ -117,7 +117,7 @@ void TextTrackLoader::deprecatedDidReceiveCachedResource(CachedResource* resourc
 void TextTrackLoader::corsPolicyPreventedLoad()
 {
     DEFINE_STATIC_LOCAL(String, consoleMessage, (ASCIILiteral("Cross-origin text track load denied by Cross-Origin Resource Sharing policy.")));
-    Document* document = static_cast<Document*>(m_scriptExecutionContext);
+    Document* document = toDocument(m_scriptExecutionContext);
     document->addConsoleMessage(SecurityMessageSource, ErrorMessageLevel, consoleMessage);
     m_state = Failed;
 }
@@ -126,7 +126,7 @@ void TextTrackLoader::notifyFinished(CachedResource* resource)
 {
     ASSERT(m_cachedCueData == resource);
 
-    Document* document = static_cast<Document*>(m_scriptExecutionContext);
+    Document* document = toDocument(m_scriptExecutionContext);
     if (!m_crossOriginMode.isNull()
         && !document->securityOrigin()->canRequest(resource->response().url())
         && !resource->passesAccessControlCheck(document->securityOrigin())) {
@@ -154,7 +154,7 @@ bool TextTrackLoader::load(const KURL& url, const String& crossOriginMode)
         return false;
 
     ASSERT(m_scriptExecutionContext->isDocument());
-    Document* document = static_cast<Document*>(m_scriptExecutionContext);
+    Document* document = toDocument(m_scriptExecutionContext);
     CachedResourceRequest cueRequest(ResourceRequest(document->completeURL(url)));
 
     if (!crossOriginMode.isNull()) {
index 53e3478..bfc7f3a 100644 (file)
@@ -50,8 +50,7 @@ PassRefPtr<ThreadableLoader> ThreadableLoader::create(ScriptExecutionContext* co
         return WorkerThreadableLoader::create(static_cast<WorkerContext*>(context), client, WorkerRunLoop::defaultMode(), request, options);
 #endif // ENABLE(WORKERS)
 
-    ASSERT_WITH_SECURITY_IMPLICATION(context->isDocument());
-    return DocumentThreadableLoader::create(static_cast<Document*>(context), client, request, options);
+    return DocumentThreadableLoader::create(toDocument(context), client, request, options);
 }
 
 void ThreadableLoader::loadResourceSynchronously(ScriptExecutionContext* context, const ResourceRequest& request, ThreadableLoaderClient& client, const ThreadableLoaderOptions& options)
@@ -65,8 +64,7 @@ void ThreadableLoader::loadResourceSynchronously(ScriptExecutionContext* context
     }
 #endif // ENABLE(WORKERS)
 
-    ASSERT_WITH_SECURITY_IMPLICATION(context->isDocument());
-    DocumentThreadableLoader::loadResourceSynchronously(static_cast<Document*>(context), request, client, options);
+    DocumentThreadableLoader::loadResourceSynchronously(toDocument(context), request, client, options);
 }
 
 } // namespace WebCore
index 4461889..4d0d6f4 100644 (file)
@@ -107,8 +107,7 @@ WorkerThreadableLoader::MainThreadBridge::~MainThreadBridge()
 void WorkerThreadableLoader::MainThreadBridge::mainThreadCreateLoader(ScriptExecutionContext* context, MainThreadBridge* thisPtr, PassOwnPtr<CrossThreadResourceRequestData> requestData, ThreadableLoaderOptions options, const String& outgoingReferrer)
 {
     ASSERT(isMainThread());
-    ASSERT_WITH_SECURITY_IMPLICATION(context->isDocument());
-    Document* document = static_cast<Document*>(context);
+    Document* document = toDocument(context);
 
     OwnPtr<ResourceRequest> request(ResourceRequest::adopt(requestData));
     request->setHTTPReferrer(outgoingReferrer);
index 59c6f51..63c20d2 100644 (file)
@@ -1432,7 +1432,7 @@ void ContentSecurityPolicy::copyStateFrom(const ContentSecurityPolicy* other)
 void ContentSecurityPolicy::didReceiveHeader(const String& header, HeaderType type)
 {
     if (m_scriptExecutionContext->isDocument()) {
-        Document* document = static_cast<Document*>(m_scriptExecutionContext);
+        Document* document = toDocument(m_scriptExecutionContext);
         if (document->domWindow())
             FeatureObserver::observe(document->domWindow(), getFeatureObserverType(type));
     }
@@ -1676,7 +1676,7 @@ void ContentSecurityPolicy::reportViolation(const String& directiveText, const S
     if (!m_scriptExecutionContext->isDocument())
         return;
 
-    Document* document = static_cast<Document*>(m_scriptExecutionContext);
+    Document* document = toDocument(m_scriptExecutionContext);
     Frame* frame = document->frame();
     if (!frame)
         return;
index 4d83342..9b01595 100644 (file)
@@ -920,7 +920,7 @@ void DOMWindow::focus(ScriptExecutionContext* context)
     bool allowFocus = WindowFocusAllowedIndicator::windowFocusAllowed() || !m_frame->settings()->windowFocusRestricted();
     if (context) {
         ASSERT(isMainThread());
-        Document* activeDocument = static_cast<Document*>(context);
+        Document* activeDocument = toDocument(context);
         if (opener() && activeDocument->domWindow() == opener())
             allowFocus = true;
     }
@@ -973,7 +973,7 @@ void DOMWindow::close(ScriptExecutionContext* context)
 
     if (context) {
         ASSERT(isMainThread());
-        Document* activeDocument = static_cast<Document*>(context);
+        Document* activeDocument = toDocument(context);
         if (!activeDocument)
             return;
 
@@ -1323,8 +1323,7 @@ DOMWindow* DOMWindow::top() const
 Document* DOMWindow::document() const
 {
     ScriptExecutionContext* context = ContextDestructionObserver::scriptExecutionContext();
-    ASSERT_WITH_SECURITY_IMPLICATION(!context || context->isDocument());
-    return static_cast<Document*>(context);
+    return toDocument(context);
 }
 
 PassRefPtr<StyleMedia> DOMWindow::styleMedia() const
index 84ab95b..ccc4cf6 100644 (file)
@@ -414,7 +414,7 @@ DragOperation DragController::operationForLoad(DragData* dragData)
     bool pluginDocumentAcceptsDrags = false;
 
     if (doc && doc->isPluginDocument()) {
-        const Widget* widget = static_cast<PluginDocument*>(doc)->pluginWidget();
+        const Widget* widget = toPluginDocument(doc)->pluginWidget();
         const PluginViewBase* pluginView = (widget && widget->isPluginViewBase()) ? static_cast<const PluginViewBase*>(widget) : 0;
 
         if (pluginView)
index 94a8402..ff14497 100644 (file)
@@ -664,10 +664,10 @@ bool EventHandler::handleMousePressEvent(const MouseEventWithHitTestResults& eve
 
 #if ENABLE(SVG)
     if (m_frame->document()->isSVGDocument()
-        && static_cast<SVGDocument*>(m_frame->document())->zoomAndPanEnabled()) {
+        && toSVGDocument(m_frame->document())->zoomAndPanEnabled()) {
         if (event.event().shiftKey() && singleClick) {
             m_svgPan = true;
-            static_cast<SVGDocument*>(m_frame->document())->startPan(m_frame->view()->windowToContents(event.event().position()));
+            toSVGDocument(m_frame->document())->startPan(m_frame->view()->windowToContents(event.event().position()));
             return true;
         }
     }
@@ -1694,7 +1694,7 @@ bool EventHandler::handleMouseMoveEvent(const PlatformMouseEvent& mouseEvent, Hi
 
 #if ENABLE(SVG)
     if (m_svgPan) {
-        static_cast<SVGDocument*>(m_frame->document())->updatePan(m_frame->view()->windowToContents(m_lastKnownMousePosition));
+        toSVGDocument(m_frame->document())->updatePan(m_frame->view()->windowToContents(m_lastKnownMousePosition));
         return true;
     }
 #endif
@@ -1843,7 +1843,7 @@ bool EventHandler::handleMouseReleaseEvent(const PlatformMouseEvent& mouseEvent)
 #if ENABLE(SVG)
     if (m_svgPan) {
         m_svgPan = false;
-        static_cast<SVGDocument*>(m_frame->document())->updatePan(m_frame->view()->windowToContents(m_lastKnownMousePosition));
+        toSVGDocument(m_frame->document())->updatePan(m_frame->view()->windowToContents(m_lastKnownMousePosition));
         return true;
     }
 #endif
index 1622a0c..c6ca0c9 100644 (file)
@@ -88,7 +88,7 @@ PassRefPtr<EventSource> EventSource::create(ScriptExecutionContext* context, con
     // 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 = static_cast<Document*>(context);
+        Document* document = toDocument(context);
         shouldBypassMainWorldContentSecurityPolicy = document->frame()->script()->shouldBypassMainWorldContentSecurityPolicy();
     }
     if (!shouldBypassMainWorldContentSecurityPolicy && !context->contentSecurityPolicy()->allowConnectToSource(fullURL)) {
index 6f59e13..e811ea1 100644 (file)
@@ -848,7 +848,7 @@ bool FocusController::advanceFocusDirectionally(FocusDirection direction, Keyboa
     Node* container = focusedDocument;
 
     if (container->isDocumentNode())
-        static_cast<Document*>(container)->updateLayoutIgnorePendingStylesheets();
+        toDocument(container)->updateLayoutIgnorePendingStylesheets();
         
     // Figure out the starting rect.
     LayoutRect startingRect;
@@ -869,7 +869,7 @@ bool FocusController::advanceFocusDirectionally(FocusDirection direction, Keyboa
         startingRect = nodeRectInAbsoluteCoordinates(container, true /* ignore border */);
         container = scrollableEnclosingBoxOrParentFrameForNodeInDirection(direction, container);
         if (container && container->isDocumentNode())
-            static_cast<Document*>(container)->updateLayoutIgnorePendingStylesheets();
+            toDocument(container)->updateLayoutIgnorePendingStylesheets();
     } while (!consumed && container);
 
     return consumed;
index ecd1752..2e8d1be 100644 (file)
@@ -931,7 +931,7 @@ void Frame::setPageAndTextZoomFactors(float pageZoomFactor, float textZoomFactor
     // Respect SVGs zoomAndPan="disabled" property in standalone SVG documents.
     // FIXME: How to handle compound documents + zoomAndPan="disabled"? Needs SVG WG clarification.
     if (document->isSVGDocument()) {
-        if (!static_cast<SVGDocument*>(document)->zoomAndPanEnabled())
+        if (!toSVGDocument(document)->zoomAndPanEnabled())
             return;
     }
 #endif
index 1f57e0c..f6abb19 100644 (file)
@@ -1792,7 +1792,7 @@ bool FrameView::scrollToAnchor(const String& name)
 
 #if ENABLE(SVG)
     if (m_frame->document()->isSVGDocument()) {
-        if (SVGSVGElement* svg = static_cast<SVGDocument*>(m_frame->document())->rootElement()) {
+        if (SVGSVGElement* svg = toSVGDocument(m_frame->document())->rootElement()) {
             svg->setupInitialView(name, anchorNode);
             if (!anchorNode)
                 return true;
index 87d8506..58aefc4 100644 (file)
@@ -116,7 +116,7 @@ void History::go(ScriptExecutionContext* context, int distance)
         return;
 
     ASSERT(isMainThread());
-    Document* activeDocument = static_cast<Document*>(context);
+    Document* activeDocument = toDocument(context);
     if (!activeDocument)
         return;
 
index 338c389..6007fc7 100644 (file)
@@ -371,7 +371,7 @@ bool scrollInDirection(Node* container, FocusDirection direction)
 {
     ASSERT(container);
     if (container->isDocumentNode())
-        return scrollInDirection(static_cast<Document*>(container)->frame(), direction);
+        return scrollInDirection(toDocument(container)->frame(), direction);
 
     if (!container->renderBox())
         return false;
@@ -440,7 +440,7 @@ Node* scrollableEnclosingBoxOrParentFrameForNodeInDirection(FocusDirection direc
     Node* parent = node;
     do {
         if (parent->isDocumentNode())
-            parent = static_cast<Document*>(parent)->document()->frame()->ownerElement();
+            parent = toDocument(parent)->document()->frame()->ownerElement();
         else
             parent = parent->parentNode();
     } while (parent && !canScrollInDirection(parent, direction) && !parent->isDocumentNode());
@@ -452,7 +452,7 @@ bool canScrollInDirection(const Node* container, FocusDirection direction)
 {
     ASSERT(container);
     if (container->isDocumentNode())
-        return canScrollInDirection(static_cast<const Document*>(container)->frame(), direction);
+        return canScrollInDirection(toDocument(container)->frame(), direction);
 
     if (!isScrollableNode(container))
         return false;
@@ -521,7 +521,7 @@ LayoutRect nodeRectInAbsoluteCoordinates(Node* node, bool ignoreBorder)
     ASSERT(node && node->renderer() && !node->document()->view()->needsLayout());
 
     if (node->isDocumentNode())
-        return frameRectInAbsoluteCoordinates(static_cast<Document*>(node)->frame());
+        return frameRectInAbsoluteCoordinates(toDocument(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
index f6cba25..26607d4 100644 (file)
@@ -227,7 +227,7 @@ static inline Node* parentShadowHostOrOwner(const Node* node)
     if (Node* ancestor = node->parentOrShadowHostNode())
         return ancestor;
     if (node->isDocumentNode())
-        return static_cast<const Document*>(node)->ownerElement();
+        return toDocument(node)->ownerElement();
     return 0;
 }
 
index e196572..8a81055 100644 (file)
@@ -210,7 +210,7 @@ static void accumulateDocumentEventTargetRects(Vector<IntRect>& rects, const Doc
         }
 
         if (touchTarget->isDocumentNode() && touchTarget != document) {
-            accumulateDocumentEventTargetRects(rects, static_cast<const Document*>(touchTarget));
+            accumulateDocumentEventTargetRects(rects, toDocument(touchTarget));
             continue;
         }
 
index aa6b034..7195e50 100644 (file)
@@ -154,7 +154,7 @@ RenderText::RenderText(Node* node, PassRefPtr<StringImpl> str)
     // FIXME: Some clients of RenderText (and subclasses) pass Document as node to create anonymous renderer.
     // They should be switched to passing null and using setDocumentForAnonymous.
     if (node && node->isDocumentNode())
-        setDocumentForAnonymous(static_cast<Document*>(node));
+        setDocumentForAnonymous(toDocument(node));
 
     m_isAllASCII = m_text.containsOnlyASCII();
     m_canUseSimpleFontCodePath = computeCanUseSimpleFontCodePath();
index 1191f61..d3f8d74 100644 (file)
@@ -824,7 +824,7 @@ static void writeSelection(TextStream& ts, const RenderObject* o)
     if (!n || !n->isDocumentNode())
         return;
 
-    Document* doc = static_cast<Document*>(n);
+    Document* doc = toDocument(n);
     Frame* frame = doc->frame();
     if (!frame)
         return;
index a637872..527eab8 100644 (file)
@@ -58,6 +58,21 @@ private:
     FloatPoint m_translate;
 };
 
+inline SVGDocument* toSVGDocument(Document* document)
+{
+    ASSERT_WITH_SECURITY_IMPLICATION(!document || document->isSVGDocument());
+    return static_cast<SVGDocument*>(document);
+}
+
+inline const SVGDocument* toSVGDocument(const Document* document)
+{
+    ASSERT_WITH_SECURITY_IMPLICATION(!document || document->isSVGDocument());
+    return static_cast<const SVGDocument*>(document);
+}
+
+// This will catch anyone doing an unnecessary cast.
+void toSVGDocument(const SVGDocument*);
+
 } // namespace WebCore
 
 #endif // ENABLE(SVG)
index 4013484..0c8ba40 100644 (file)
@@ -66,7 +66,7 @@ void SVGImage::setContainerSize(const IntSize& size)
         return;
 
     Frame* frame = m_page->mainFrame();
-    SVGSVGElement* rootElement = static_cast<SVGDocument*>(frame->document())->rootElement();
+    SVGSVGElement* rootElement = toSVGDocument(frame->document())->rootElement();
     if (!rootElement)
         return;
     RenderSVGRoot* renderer = toRenderSVGRoot(rootElement->renderer());
@@ -84,7 +84,7 @@ IntSize SVGImage::size() const
     if (!m_page)
         return IntSize();
     Frame* frame = m_page->mainFrame();
-    SVGSVGElement* rootElement = static_cast<SVGDocument*>(frame->document())->rootElement();
+    SVGSVGElement* rootElement = toSVGDocument(frame->document())->rootElement();
     if (!rootElement)
         return IntSize();
 
@@ -213,7 +213,7 @@ RenderBox* SVGImage::embeddedContentBox() const
     if (!m_page)
         return 0;
     Frame* frame = m_page->mainFrame();
-    SVGSVGElement* rootElement = static_cast<SVGDocument*>(frame->document())->rootElement();
+    SVGSVGElement* rootElement = toSVGDocument(frame->document())->rootElement();
     if (!rootElement)
         return 0;
     return toRenderBox(rootElement->renderer());
@@ -232,7 +232,7 @@ bool SVGImage::hasRelativeWidth() const
     if (!m_page)
         return false;
     Frame* frame = m_page->mainFrame();
-    SVGSVGElement* rootElement = static_cast<SVGDocument*>(frame->document())->rootElement();
+    SVGSVGElement* rootElement = toSVGDocument(frame->document())->rootElement();
     if (!rootElement)
         return false;
     return rootElement->intrinsicWidth().isPercent();
@@ -243,7 +243,7 @@ bool SVGImage::hasRelativeHeight() const
     if (!m_page)
         return false;
     Frame* frame = m_page->mainFrame();
-    SVGSVGElement* rootElement = static_cast<SVGDocument*>(frame->document())->rootElement();
+    SVGSVGElement* rootElement = toSVGDocument(frame->document())->rootElement();
     if (!rootElement)
         return false;
     return rootElement->intrinsicHeight().isPercent();
@@ -254,7 +254,7 @@ void SVGImage::computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrin
     if (!m_page)
         return;
     Frame* frame = m_page->mainFrame();
-    SVGSVGElement* rootElement = static_cast<SVGDocument*>(frame->document())->rootElement();
+    SVGSVGElement* rootElement = toSVGDocument(frame->document())->rootElement();
     if (!rootElement)
         return;
 
@@ -274,7 +274,7 @@ void SVGImage::startAnimation(bool /* catchUpIfNecessary */)
     if (!m_page)
         return;
     Frame* frame = m_page->mainFrame();
-    SVGSVGElement* rootElement = static_cast<SVGDocument*>(frame->document())->rootElement();
+    SVGSVGElement* rootElement = toSVGDocument(frame->document())->rootElement();
     if (!rootElement)
         return;
     rootElement->unpauseAnimations();
@@ -286,7 +286,7 @@ void SVGImage::stopAnimation()
     if (!m_page)
         return;
     Frame* frame = m_page->mainFrame();
-    SVGSVGElement* rootElement = static_cast<SVGDocument*>(frame->document())->rootElement();
+    SVGSVGElement* rootElement = toSVGDocument(frame->document())->rootElement();
     if (!rootElement)
         return;
     rootElement->pauseAnimations();
index c825b43..3c39fa1 100644 (file)
@@ -282,7 +282,7 @@ Internals::Internals(Document* document)
 
 Document* Internals::contextDocument() const
 {
-    return static_cast<Document*>(scriptExecutionContext());
+    return toDocument(scriptExecutionContext());
 }
 
 Frame* Internals::frame() const
index 0981da8..b2ef7f7 100644 (file)
@@ -46,7 +46,7 @@ void injectInternalsObject(JSContextRef context)
     JSDOMGlobalObject* globalObject = jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject());
     ScriptExecutionContext* scriptContext = globalObject->scriptExecutionContext();
     if (scriptContext->isDocument())
-        globalObject->putDirect(exec->globalData(), Identifier(exec, Internals::internalsId), toJS(exec, globalObject, Internals::create(static_cast<Document*>(scriptContext))));
+        globalObject->putDirect(exec->globalData(), Identifier(exec, Internals::internalsId), toJS(exec, globalObject, Internals::create(toDocument(scriptContext))));
 }
 
 void resetInternalsObject(JSContextRef context)
@@ -55,8 +55,7 @@ void resetInternalsObject(JSContextRef context)
     JSLockHolder lock(exec);
     JSDOMGlobalObject* globalObject = jsCast<JSDOMGlobalObject*>(exec->lexicalGlobalObject());
     ScriptExecutionContext* scriptContext = globalObject->scriptExecutionContext();
-    ASSERT_WITH_SECURITY_IMPLICATION(scriptContext->isDocument());
-    Page* page = static_cast<Document*>(scriptContext)->frame()->page();
+    Page* page = toDocument(scriptContext)->frame()->page();
     Internals::resetToConsistentState(page);
     InternalSettings::from(page)->resetToConsistentState();
 }
index b6c0014..4f006d1 100644 (file)
@@ -46,7 +46,7 @@ void injectInternalsObject(v8::Local<v8::Context> context)
 
     ScriptExecutionContext* scriptContext = getScriptExecutionContext();
     if (scriptContext->isDocument())
-        context->Global()->Set(v8::String::New(Internals::internalsId), toV8(Internals::create(static_cast<Document*>(scriptContext)), v8::Handle<v8::Object>(), context->GetIsolate()));
+        context->Global()->Set(v8::String::New(Internals::internalsId), toV8(Internals::create(toDocument(scriptContext)), v8::Handle<v8::Object>(), context->GetIsolate()));
 }
 
 void resetInternalsObject(v8::Local<v8::Context> context)
@@ -59,8 +59,7 @@ void resetInternalsObject(v8::Local<v8::Context> context)
     v8::HandleScope scope;
 
     ScriptExecutionContext* scriptContext = getScriptExecutionContext();
-    ASSERT_WITH_SECURITY_IMPLICATION(scriptContext->isDocument());
-    Page* page = static_cast<Document*>(scriptContext)->frame()->page();
+    Page* page = toDocument(scriptContext)->frame()->page();
     Internals::resetToConsistentState(page);
     InternalSettings::from(page)->resetToConsistentState();
 }
index 5500025..05db55a 100644 (file)
@@ -250,7 +250,7 @@ HRESULT STDMETHODCALLTYPE DOMHTMLDocument::URL(
     if (!result)
         return E_POINTER;
 
-    *result = BString(static_cast<HTMLDocument*>(m_document)->url()).release();
+    *result = BString(toHTMLDocument(m_document)->url()).release();
     return S_OK;
 }
     
@@ -261,7 +261,7 @@ HRESULT STDMETHODCALLTYPE DOMHTMLDocument::body(
     if (!m_document || !m_document->isHTMLDocument())
         return E_FAIL;
 
-    HTMLDocument* htmlDoc = static_cast<HTMLDocument*>(m_document);
+    HTMLDocument* htmlDoc = toHTMLDocument(m_document);
     COMPtr<IDOMElement> domElement;
     domElement.adoptRef(DOMHTMLElement::createInstance(htmlDoc->body()));
     if (domElement)
@@ -304,7 +304,7 @@ HRESULT STDMETHODCALLTYPE DOMHTMLDocument::forms(
     if (!m_document || !m_document->isHTMLDocument())
         return E_FAIL;
 
-    HTMLDocument* htmlDoc = static_cast<HTMLDocument*>(m_document);
+    HTMLDocument* htmlDoc = toHTMLDocument(m_document);
     RefPtr<HTMLCollection> forms = htmlDoc->forms();
     *collection = DOMHTMLCollection::createInstance(forms.get());
     return S_OK;
index d7ec13d..f03a4c3 100644 (file)
@@ -1,3 +1,12 @@
+2013-03-13  Abhishek Arya  <inferno@chromium.org>
+
+        Replace static_casts with to* functions for document types.
+        https://bugs.webkit.org/show_bug.cgi?id=112225
+
+        Reviewed by Ryosuke Niwa.
+
+        * WebProcess/InjectedBundle/API/mac/WKDOMDocument.mm: Remove the redundant helper.
+
 2013-03-13  Zan Dobersek  <zdobersek@igalia.com>
 
         [GTK] Build fixes after 145552
index 99f5150..f355da8 100644 (file)
 #import <WebCore/HTMLElement.h>
 #import <WebCore/Text.h>
 
-static inline WebCore::Document* toDocument(WebCore::Node* node)
-{
-    ASSERT(!node || node->isDocumentNode());
-    return static_cast<WebCore::Document*>(node);
-}
-
 @implementation WKDOMDocument
 
 - (WKDOMElement *)createElement:(NSString *)tagName