#include "CSSStyleSelector.h"
#include "Chrome.h"
#include "Console.h"
+#include "Crypto.h"
#include "DOMApplicationCache.h"
#include "DOMSelection.h"
#include "DOMSettableTokenList.h"
#include "Settings.h"
#include "Storage.h"
#include "StorageArea.h"
+#include "StorageInfo.h"
#include "StorageNamespace.h"
#include "StyleMedia.h"
#include "SuddenTermination.h"
#if ENABLE(FILE_SYSTEM)
#include "AsyncFileSystem.h"
#include "DOMFileSystem.h"
+#include "DOMFileSystemBase.h"
+#include "EntryCallback.h"
#include "ErrorCallback.h"
#include "FileError.h"
#include "FileSystemCallback.h"
#include "LocalFileSystem.h"
#endif
+#if ENABLE(REQUEST_ANIMATION_FRAME)
+#include "RequestAnimationFrameCallback.h"
+#endif
+
using std::min;
using std::max;
window.setHeight(min(max(100.0f, window.height()), screen.height()));
// Constrain the window position to the screen.
- window.setX(max(screen.x(), min(window.x(), screen.right() - window.width())));
- window.setY(max(screen.y(), min(window.y(), screen.bottom() - window.height())));
+ window.setX(max(screen.x(), min(window.x(), screen.maxX() - window.width())));
+ window.setY(max(screen.y(), min(window.y(), screen.maxY() - window.height())));
}
// FIXME: We can remove this function once V8 showModalDialog is changed to use DOMWindow.
DOMWindow::DOMWindow(Frame* frame)
: m_shouldPrintWhenFinishedLoading(false)
, m_frame(frame)
+ , m_printTimer(this, &DOMWindow::printTimerFired)
{
}
m_history->disconnectFrame();
m_history = 0;
+ m_crypto = 0;
+
if (m_locationbar)
m_locationbar->disconnectFrame();
m_locationbar = 0;
return m_history.get();
}
+Crypto* DOMWindow::crypto() const
+{
+ if (!m_crypto)
+ m_crypto = Crypto::create();
+ return m_crypto.get();
+}
+
BarInfo* DOMWindow::locationbar() const
{
if (!m_locationbar)
#endif
}
+void DOMWindow::resetGeolocation()
+{
+ // Geolocation should cancel activities and permission requests when the page is detached.
+ if (m_navigator)
+ m_navigator->resetGeolocation();
+}
+
#if ENABLE(INDEXED_DATABASE)
IDBFactory* DOMWindow::webkitIndexedDB() const
{
#endif
#if ENABLE(FILE_SYSTEM)
-void DOMWindow::requestFileSystem(int type, long long size, PassRefPtr<FileSystemCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
+void DOMWindow::webkitRequestFileSystem(int type, long long size, PassRefPtr<FileSystemCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
{
Document* document = this->document();
if (!document)
}
AsyncFileSystem::Type fileSystemType = static_cast<AsyncFileSystem::Type>(type);
- if (fileSystemType != AsyncFileSystem::Temporary && fileSystemType != AsyncFileSystem::Persistent) {
+ if (fileSystemType != AsyncFileSystem::Temporary && fileSystemType != AsyncFileSystem::Persistent && fileSystemType != AsyncFileSystem::External) {
DOMFileSystem::scheduleCallback(document, errorCallback, FileError::create(FileError::INVALID_MODIFICATION_ERR));
return;
}
LocalFileSystem::localFileSystem().requestFileSystem(document, fileSystemType, size, FileSystemCallbacks::create(successCallback, errorCallback, document), false);
}
+void DOMWindow::webkitResolveLocalFileSystemURL(const String& url, PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
+{
+ Document* document = this->document();
+ if (!document)
+ return;
+
+ SecurityOrigin* securityOrigin = document->securityOrigin();
+ KURL completedURL = document->completeURL(url);
+ if (!AsyncFileSystem::isAvailable() || !securityOrigin->canAccessFileSystem() || !securityOrigin->canRequest(completedURL)) {
+ DOMFileSystem::scheduleCallback(document, errorCallback, FileError::create(FileError::SECURITY_ERR));
+ return;
+ }
+
+ AsyncFileSystem::Type type;
+ String filePath;
+ if (!completedURL.isValid() || !DOMFileSystemBase::crackFileSystemURL(completedURL, type, filePath)) {
+ DOMFileSystem::scheduleCallback(document, errorCallback, FileError::create(FileError::ENCODING_ERR));
+ return;
+ }
+
+ LocalFileSystem::localFileSystem().readFileSystem(document, type, ResolveURICallbacks::create(successCallback, errorCallback, document, filePath));
+}
+
+COMPILE_ASSERT(static_cast<int>(DOMWindow::EXTERNAL) == static_cast<int>(AsyncFileSystem::External), enum_mismatch);
+
COMPILE_ASSERT(static_cast<int>(DOMWindow::TEMPORARY) == static_cast<int>(AsyncFileSystem::Temporary), enum_mismatch);
COMPILE_ASSERT(static_cast<int>(DOMWindow::PERSISTENT) == static_cast<int>(AsyncFileSystem::Persistent), enum_mismatch);
page->chrome()->print(m_frame);
}
+void DOMWindow::printTimerFired(Timer<DOMWindow>* timer)
+{
+ ASSERT_UNUSED(timer, timer == &m_printTimer);
+ print();
+}
+
void DOMWindow::stop()
{
if (!m_frame)
return String();
}
-static bool isSafeToConvertCharList(const String& string)
-{
- for (unsigned i = 0; i < string.length(); i++) {
- if (string[i] > 0xFF)
- return false;
- }
-
- return true;
-}
-
String DOMWindow::btoa(const String& stringToEncode, ExceptionCode& ec)
{
if (stringToEncode.isNull())
return String();
- if (!isSafeToConvertCharList(stringToEncode)) {
+ if (!stringToEncode.containsOnlyLatin1()) {
ec = INVALID_CHARACTER_ERR;
return String();
}
- Vector<char> in;
- in.append(stringToEncode.characters(), stringToEncode.length());
- Vector<char> out;
-
- base64Encode(in, out);
-
- return String(out.data(), out.size());
+ return base64Encode(stringToEncode.latin1());
}
String DOMWindow::atob(const String& encodedString, ExceptionCode& ec)
if (encodedString.isNull())
return String();
- if (!isSafeToConvertCharList(encodedString)) {
+ if (!encodedString.containsOnlyLatin1()) {
ec = INVALID_CHARACTER_ERR;
return String();
}
DOMTimer::removeById(context, timeoutId);
}
+#if ENABLE(REQUEST_ANIMATION_FRAME)
+int DOMWindow::webkitRequestAnimationFrame(PassRefPtr<RequestAnimationFrameCallback> callback, Element* e)
+{
+ if (Document* d = document())
+ return d->webkitRequestAnimationFrame(callback, e);
+ return 0;
+}
+
+void DOMWindow::webkitCancelRequestAnimationFrame(int id)
+{
+ if (Document* d = document())
+ d->webkitCancelRequestAnimationFrame(id);
+}
+#endif
+
bool DOMWindow::addEventListener(const AtomicString& eventType, PassRefPtr<EventListener> listener, bool useCapture)
{
if (!EventTarget::addEventListener(eventType, listener, useCapture))
void DOMWindow::dispatchLoadEvent()
{
RefPtr<Event> loadEvent(Event::create(eventNames().loadEvent, false, false));
- // The DocumentLoader (and thus its DocumentLoadTiming) might get destroyed while dispatching
- // the event, so protect it to prevent writing the end time into freed memory.
- if (RefPtr<DocumentLoader> documentLoader = m_frame ? m_frame->loader()->documentLoader() : 0) {
+ if (m_frame && m_frame->loader()->documentLoader() && !m_frame->loader()->documentLoader()->timing()->loadEventStart) {
+ // The DocumentLoader (and thus its DocumentLoadTiming) might get destroyed while dispatching
+ // the event, so protect it to prevent writing the end time into freed memory.
+ RefPtr<DocumentLoader> documentLoader = m_frame->loader()->documentLoader();
DocumentLoadTiming* timing = documentLoader->timing();
dispatchTimedEvent(loadEvent, document(), &timing->loadEventStart, &timing->loadEventEnd);
} else
// For load events, send a separate load event to the enclosing frame only.
// This is a DOM extension and is independent of bubbling/capturing rules of
// the DOM.
- Element* ownerElement = document()->ownerElement();
- if (ownerElement) {
- RefPtr<Event> ownerEvent = Event::create(eventNames().loadEvent, false, false);
- ownerEvent->setTarget(ownerElement);
- ownerElement->dispatchGenericEvent(ownerEvent.release());
- }
+ Element* ownerElement = m_frame ? m_frame->ownerElement() : 0;
+ if (ownerElement)
+ ownerElement->dispatchEvent(Event::create(eventNames().loadEvent, false, false));
- InspectorInstrumentation::mainResourceFiredLoadEvent(frame(), url());
+ InspectorInstrumentation::loadEventFired(frame(), url());
}
bool DOMWindow::dispatchEvent(PassRefPtr<Event> prpEvent, PassRefPtr<EventTarget> prpTarget)
*startTime = currentTime();
dispatchEvent(event, target);
*endTime = currentTime();
- ASSERT(*endTime >= *startTime);
}
void DOMWindow::removeAllEventListeners()
{
if (m_shouldPrintWhenFinishedLoading) {
m_shouldPrintWhenFinishedLoading = false;
- print();
+
+ m_printTimer.stop();
+ m_printTimer.startOneShot(0);
}
}
void DOMWindow::setLocation(const String& urlString, DOMWindow* activeWindow, DOMWindow* firstWindow, SetLocationLocking locking)
{
+ if (!m_frame)
+ return;
+
Frame* activeFrame = activeWindow->frame();
if (!activeFrame)
return;
if (!firstFrame)
return;
+ if (m_frame->page())
+ m_frame->page()->chrome()->willRunModalHTMLDialog(m_frame);
+
if (!canShowModalDialogNow(m_frame) || !firstWindow->allowPopUp())
return;
}
#endif
+#if ENABLE(QUOTA)
+StorageInfo* DOMWindow::webkitStorageInfo() const
+{
+ if (!m_storageInfo)
+ m_storageInfo = StorageInfo::create();
+ return m_storageInfo.get();
+}
+#endif
+
} // namespace WebCore