summaryrefslogtreecommitdiff
path: root/Source/WebCore/page/DOMWindow.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@nokia.com>2012-08-21 10:57:44 +0200
committerSimon Hausmann <simon.hausmann@nokia.com>2012-08-21 10:57:44 +0200
commit5ef7c8a6a70875d4430752d146bdcb069605d71d (patch)
treef6256640b6c46d7da221435803cae65326817ba2 /Source/WebCore/page/DOMWindow.cpp
parentdecad929f578d8db641febc8740649ca6c574638 (diff)
downloadqtwebkit-5ef7c8a6a70875d4430752d146bdcb069605d71d.tar.gz
Imported WebKit commit 356d83016b090995d08ad568f2d2c243aa55e831 (http://svn.webkit.org/repository/webkit/trunk@126147)
New snapshot including various build fixes for newer Qt 5
Diffstat (limited to 'Source/WebCore/page/DOMWindow.cpp')
-rw-r--r--Source/WebCore/page/DOMWindow.cpp86
1 files changed, 41 insertions, 45 deletions
diff --git a/Source/WebCore/page/DOMWindow.cpp b/Source/WebCore/page/DOMWindow.cpp
index 448150363..d787a65bd 100644
--- a/Source/WebCore/page/DOMWindow.cpp
+++ b/Source/WebCore/page/DOMWindow.cpp
@@ -391,11 +391,19 @@ bool DOMWindow::canShowModalDialogNow(const Frame* frame)
return page->chrome()->canRunModalNow();
}
-DOMWindow::DOMWindow(Frame* frame)
- : FrameDestructionObserver(frame)
+DOMWindow::DOMWindow(Document* document)
+ : ContextDestructionObserver(document)
+ , FrameDestructionObserver(document->frame())
, m_shouldPrintWhenFinishedLoading(false)
, m_suspendedForPageCache(false)
{
+ ASSERT(frame());
+ ASSERT(DOMWindow::document());
+}
+
+void DOMWindow::didSecureTransitionTo(Document* document)
+{
+ observeContext(document);
}
DOMWindow::~DOMWindow()
@@ -429,9 +437,9 @@ DOMWindow::~DOMWindow()
else
willDestroyDocumentInFrame();
- // As the ASSERTs above indicate, this clear should only be necesary if this DOMWindow is suspended for the page cache.
+ // As the ASSERTs above indicate, this reset should only be necessary if this DOMWindow is suspended for the page cache.
// But we don't want to risk any of these objects hanging around after we've been destroyed.
- clearDOMWindowProperties();
+ resetDOMWindowProperties();
removeAllUnloadEventListeners(this);
removeAllBeforeUnloadEventListeners(this);
@@ -444,7 +452,7 @@ const AtomicString& DOMWindow::interfaceName() const
ScriptExecutionContext* DOMWindow::scriptExecutionContext() const
{
- return document();
+ return ContextDestructionObserver::scriptExecutionContext();
}
DOMWindow* DOMWindow::toDOMWindow()
@@ -457,11 +465,6 @@ PassRefPtr<MediaQueryList> DOMWindow::matchMedia(const String& media)
return document() ? document()->mediaQueryMatcher()->matchMedia(media) : 0;
}
-void DOMWindow::setSecurityOrigin(SecurityOrigin* securityOrigin)
-{
- m_securityOrigin = securityOrigin;
-}
-
Page* DOMWindow::page()
{
return frame() ? frame()->page() : 0;
@@ -471,7 +474,7 @@ void DOMWindow::frameDestroyed()
{
willDestroyDocumentInFrame();
FrameDestructionObserver::frameDestroyed();
- clearDOMWindowProperties();
+ resetDOMWindowProperties();
}
void DOMWindow::willDetachPage()
@@ -519,16 +522,12 @@ void DOMWindow::unregisterProperty(DOMWindowProperty* property)
m_properties.remove(property);
}
-void DOMWindow::clear()
+void DOMWindow::resetUnlessSuspendedForPageCache()
{
- // The main frame will always try to clear its DOMWindow when a new load is committed, even if that
- // DOMWindow is suspended in the page cache.
- // In those cases we need to make sure we don't actually clear it.
if (m_suspendedForPageCache)
return;
-
willDestroyDocumentInFrame();
- clearDOMWindowProperties();
+ resetDOMWindowProperties();
}
void DOMWindow::suspendForPageCache()
@@ -564,7 +563,7 @@ void DOMWindow::reconnectDOMWindowProperties()
properties[i]->reconnectFrameFromPageCache(m_frame);
}
-void DOMWindow::clearDOMWindowProperties()
+void DOMWindow::resetDOMWindowProperties()
{
m_properties.clear();
@@ -591,7 +590,7 @@ void DOMWindow::clearDOMWindowProperties()
bool DOMWindow::isCurrentlyDisplayedInFrame() const
{
- return m_frame && m_frame->domWindow() == this;
+ return m_frame && m_frame->document()->domWindow() == this;
}
#if ENABLE(ORIENTATION_EVENTS)
@@ -1257,7 +1256,7 @@ DOMWindow* DOMWindow::self() const
if (!m_frame)
return 0;
- return m_frame->domWindow();
+ return m_frame->document()->domWindow();
}
DOMWindow* DOMWindow::opener() const
@@ -1269,7 +1268,7 @@ DOMWindow* DOMWindow::opener() const
if (!opener)
return 0;
- return opener->domWindow();
+ return opener->document()->domWindow();
}
DOMWindow* DOMWindow::parent() const
@@ -1279,9 +1278,9 @@ DOMWindow* DOMWindow::parent() const
Frame* parent = m_frame->tree()->parent();
if (parent)
- return parent->domWindow();
+ return parent->document()->domWindow();
- return m_frame->domWindow();
+ return m_frame->document()->domWindow();
}
DOMWindow* DOMWindow::top() const
@@ -1293,17 +1292,14 @@ DOMWindow* DOMWindow::top() const
if (!page)
return 0;
- return m_frame->tree()->top()->domWindow();
+ return m_frame->tree()->top()->document()->domWindow();
}
Document* DOMWindow::document() const
{
- if (!isCurrentlyDisplayedInFrame())
- return 0;
-
- // FIXME: This function shouldn't need a frame to work.
- ASSERT(m_frame->document());
- return m_frame->document();
+ ScriptExecutionContext* context = ContextDestructionObserver::scriptExecutionContext();
+ ASSERT(!context || context->isDocument());
+ return static_cast<Document*>(context);
}
PassRefPtr<StyleMedia> DOMWindow::styleMedia() const
@@ -1580,10 +1576,10 @@ bool DOMWindow::addEventListener(const AtomicString& eventType, PassRefPtr<Event
else if (eventType == eventNames().beforeunloadEvent && allowsBeforeUnloadListeners(this))
addBeforeUnloadEventListener(this);
#if ENABLE(DEVICE_ORIENTATION)
- else if (eventType == eventNames().devicemotionEvent) {
+ else if (eventType == eventNames().devicemotionEvent && RuntimeEnabledFeatures::deviceMotionEnabled()) {
if (DeviceMotionController* controller = DeviceMotionController::from(page()))
controller->addListener(this);
- } else if (eventType == eventNames().deviceorientationEvent) {
+ } else if (eventType == eventNames().deviceorientationEvent && RuntimeEnabledFeatures::deviceOrientationEnabled()) {
if (DeviceOrientationController* controller = DeviceOrientationController::from(page()))
controller->addListener(this);
}
@@ -1755,14 +1751,14 @@ void DOMWindow::printErrorMessage(const String& message)
String DOMWindow::crossDomainAccessErrorMessage(DOMWindow* activeWindow)
{
- const KURL& activeWindowURL = activeWindow->url();
+ const KURL& activeWindowURL = activeWindow->document()->url();
if (activeWindowURL.isNull())
return String();
// FIXME: This error message should contain more specifics of why the same origin check has failed.
// Perhaps we should involve the security origin object in composing it.
// FIXME: This message, and other console messages, have extra newlines. Should remove them.
- return "Unsafe JavaScript attempt to access frame with URL " + m_url.string() + " from frame with URL " + activeWindowURL.string() + ". Domains, protocols and ports must match.\n";
+ return "Unsafe JavaScript attempt to access frame with URL " + document()->url().string() + " from frame with URL " + activeWindowURL.string() + ". Domains, protocols and ports must match.\n";
}
bool DOMWindow::isInsecureScriptAccess(DOMWindow* activeWindow, const String& urlString)
@@ -1781,7 +1777,7 @@ bool DOMWindow::isInsecureScriptAccess(DOMWindow* activeWindow, const String& ur
// FIXME: The name canAccess seems to be a roundabout way to ask "can execute script".
// Can we name the SecurityOrigin function better to make this more clear?
- if (activeWindow->securityOrigin()->canAccess(securityOrigin()))
+ if (activeWindow->document()->securityOrigin()->canAccess(document()->securityOrigin()))
return false;
}
@@ -1806,7 +1802,7 @@ Frame* DOMWindow::createWindow(const String& urlString, const AtomicString& fram
ResourceRequest request(completedURL, referrer);
FrameLoader::addHTTPOriginIfNeeded(request, firstFrame->loader()->outgoingOrigin());
- FrameLoadRequest frameRequest(activeWindow->securityOrigin(), request, frameName);
+ FrameLoadRequest frameRequest(activeWindow->document()->securityOrigin(), request, frameName);
// We pass the opener frame for the lookupFrame in case the active frame is different from
// the opener frame, and the name references a frame relative to the opener frame.
@@ -1818,17 +1814,17 @@ Frame* DOMWindow::createWindow(const String& urlString, const AtomicString& fram
newFrame->loader()->setOpener(openerFrame);
newFrame->page()->setOpenedByDOM();
- if (newFrame->domWindow()->isInsecureScriptAccess(activeWindow, completedURL))
+ if (newFrame->document()->domWindow()->isInsecureScriptAccess(activeWindow, completedURL))
return newFrame;
if (function)
- function(newFrame->domWindow(), functionContext);
+ function(newFrame->document()->domWindow(), functionContext);
if (created)
- newFrame->loader()->changeLocation(activeWindow->securityOrigin(), completedURL, referrer, false, false);
+ newFrame->loader()->changeLocation(activeWindow->document()->securityOrigin(), completedURL, referrer, false, false);
else if (!urlString.isEmpty()) {
bool lockHistory = !ScriptController::processingUserGesture();
- newFrame->navigationScheduler()->scheduleLocationChange(activeWindow->securityOrigin(), completedURL.string(), referrer, lockHistory, false);
+ newFrame->navigationScheduler()->scheduleLocationChange(activeWindow->document()->securityOrigin(), completedURL.string(), referrer, lockHistory, false);
}
return newFrame;
@@ -1870,11 +1866,11 @@ PassRefPtr<DOMWindow> DOMWindow::open(const String& urlString, const AtomicStrin
KURL completedURL = firstFrame->document()->completeURL(urlString);
- if (targetFrame->domWindow()->isInsecureScriptAccess(activeWindow, completedURL))
- return targetFrame->domWindow();
+ if (targetFrame->document()->domWindow()->isInsecureScriptAccess(activeWindow, completedURL))
+ return targetFrame->document()->domWindow();
if (urlString.isEmpty())
- return targetFrame->domWindow();
+ return targetFrame->document()->domWindow();
// For whatever reason, Firefox uses the first window rather than the active window to
// determine the outgoing referrer. We replicate that behavior here.
@@ -1885,7 +1881,7 @@ PassRefPtr<DOMWindow> DOMWindow::open(const String& urlString, const AtomicStrin
firstFrame->loader()->outgoingReferrer(),
lockHistory,
false);
- return targetFrame->domWindow();
+ return targetFrame->document()->domWindow();
}
WindowFeatures windowFeatures(windowFeaturesString);
@@ -1899,7 +1895,7 @@ PassRefPtr<DOMWindow> DOMWindow::open(const String& urlString, const AtomicStrin
windowFeatures.width = windowRect.width();
Frame* result = createWindow(urlString, frameName, windowFeatures, activeWindow, firstFrame, m_frame);
- return result ? result->domWindow() : 0;
+ return result ? result->document()->domWindow() : 0;
}
void DOMWindow::showModalDialog(const String& urlString, const String& dialogFeaturesString,