Commit 8da49f1e authored by inferno@chromium.org's avatar 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.

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: http://svn.webkit.org/repository/webkit/trunk@145745 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent a89eff7b
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.
......@@ -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
......
......@@ -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)
......
......@@ -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;
......
......@@ -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;
......
......@@ -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
......
......@@ -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);
}
......
......@@ -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));
}
......
......@@ -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);
......
......@@ -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.
......
......@@ -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;
......
......@@ -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
......
......@@ -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)) {
......
......@@ -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);
......
......@@ -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());
......
......@@ -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();
......
......@@ -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)
......
......@@ -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;
......
......@@ -82,7 +82,7 @@ class DOMStringList;
public:
Document* document() const
{
return static_cast<Document*>(scriptExecutionContext());
return toDocument(scriptExecutionContext());
}
protected:
......
......@@ -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())
......
......@@ -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);
......
......@@ -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();
}
......
......@@ -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;
......
......@@ -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;
......
......@@ -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());
......
......@@ -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());
......
......@@ -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());
}
}
......
......@@ -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());
......
......@@ -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))
......
......@@ -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.
......
......@@ -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>();
......
......@@ -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;
......
......@@ -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())
......
......@@ -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())
......
......@@ -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:
......
......@@ -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;
......
......@@ -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;
......
......@@ -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);
}
}
......
......@@ -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())
......
......@@ -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());