diff options
author | Steve Block <steveblock@google.com> | 2009-10-08 17:19:54 +0100 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2009-10-20 00:41:58 +0100 |
commit | 231d4e3152a9c27a73b6ac7badbe6be673aa3ddf (patch) | |
tree | a6c7e2d6cd7bfa7011cc39abbb436142d7a4a7c8 /WebCore/workers/WorkerContext.cpp | |
parent | e196732677050bd463301566a68a643b6d14b907 (diff) | |
download | external_webkit-231d4e3152a9c27a73b6ac7badbe6be673aa3ddf.zip external_webkit-231d4e3152a9c27a73b6ac7badbe6be673aa3ddf.tar.gz external_webkit-231d4e3152a9c27a73b6ac7badbe6be673aa3ddf.tar.bz2 |
Merge webkit.org at R49305 : Automatic merge by git.
Change-Id: I8968561bc1bfd72b8923b7118d3728579c6dbcc7
Diffstat (limited to 'WebCore/workers/WorkerContext.cpp')
-rw-r--r-- | WebCore/workers/WorkerContext.cpp | 101 |
1 files changed, 45 insertions, 56 deletions
diff --git a/WebCore/workers/WorkerContext.cpp b/WebCore/workers/WorkerContext.cpp index 722588f..f4d795b 100644 --- a/WebCore/workers/WorkerContext.cpp +++ b/WebCore/workers/WorkerContext.cpp @@ -50,6 +50,10 @@ #include "XMLHttpRequestException.h" #include <wtf/RefPtr.h> +#if ENABLE(NOTIFICATIONS) +#include "NotificationCenter.h" +#endif + namespace WebCore { WorkerContext::WorkerContext(const KURL& url, const String& userAgent, WorkerThread* thread) @@ -64,6 +68,12 @@ WorkerContext::WorkerContext(const KURL& url, const String& userAgent, WorkerThr WorkerContext::~WorkerContext() { + ASSERT(currentThread() == thread()->threadID()); +#if ENABLE(NOTIFICATIONS) + m_notifications.clear(); +#endif + // Notify proxy that we are going away. This can free the WorkerThread object, so do not access it after this. + thread()->workerReportingProxy().workerContextDestroyed(); } ScriptExecutionContext* WorkerContext::scriptExecutionContext() const @@ -109,7 +119,8 @@ void WorkerContext::close() return; m_closing = true; - m_thread->stop(); + // Notify parent that this context is closed. Parent is responsible for calling WorkerThread::stop(). + thread()->workerReportingProxy().workerContextClosed(); } WorkerNavigator* WorkerContext::navigator() const @@ -150,57 +161,6 @@ void WorkerContext::scriptImported(unsigned long, const String&) notImplemented(); } -void WorkerContext::addEventListener(const AtomicString& eventType, PassRefPtr<EventListener> eventListener, bool) -{ - EventListenersMap::iterator iter = m_eventListeners.find(eventType); - if (iter == m_eventListeners.end()) { - ListenerVector listeners; - listeners.append(eventListener); - m_eventListeners.add(eventType, listeners); - } else { - ListenerVector& listeners = iter->second; - for (ListenerVector::iterator listenerIter = listeners.begin(); listenerIter != listeners.end(); ++listenerIter) { - if (*listenerIter == eventListener) - return; - } - - listeners.append(eventListener); - m_eventListeners.add(eventType, listeners); - } -} - -void WorkerContext::removeEventListener(const AtomicString& eventType, EventListener* eventListener, bool) -{ - EventListenersMap::iterator iter = m_eventListeners.find(eventType); - if (iter == m_eventListeners.end()) - return; - - ListenerVector& listeners = iter->second; - for (ListenerVector::const_iterator listenerIter = listeners.begin(); listenerIter != listeners.end(); ++listenerIter) { - if (*listenerIter == eventListener) { - listeners.remove(listenerIter - listeners.begin()); - return; - } - } -} - -bool WorkerContext::dispatchEvent(PassRefPtr<Event> event, ExceptionCode& ec) -{ - if (!event || event->type().isEmpty()) { - ec = EventException::UNSPECIFIED_EVENT_TYPE_ERR; - return true; - } - - ListenerVector listenersCopy = m_eventListeners.get(event->type()); - for (ListenerVector::const_iterator listenerIter = listenersCopy.begin(); listenerIter != listenersCopy.end(); ++listenerIter) { - event->setTarget(this); - event->setCurrentTarget(this); - listenerIter->get()->handleEvent(event.get(), false); - } - - return !event->defaultPrevented(); -} - void WorkerContext::postTask(PassRefPtr<Task> task) { thread()->runLoop().postTask(task); @@ -228,6 +188,10 @@ void WorkerContext::clearInterval(int timeoutId) void WorkerContext::importScripts(const Vector<String>& urls, const String& callerURL, int callerLine, ExceptionCode& ec) { +#if !ENABLE(INSPECTOR) + UNUSED_PARAM(callerURL); + UNUSED_PARAM(callerLine); +#endif ec = 0; Vector<String>::const_iterator urlsEnd = urls.end(); Vector<KURL> completedURLs; @@ -239,12 +203,11 @@ void WorkerContext::importScripts(const Vector<String>& urls, const String& call } completedURLs.append(url); } - String securityOrigin = scriptExecutionContext()->securityOrigin()->toString(); Vector<KURL>::const_iterator end = completedURLs.end(); for (Vector<KURL>::const_iterator it = completedURLs.begin(); it != end; ++it) { WorkerScriptLoader scriptLoader; - scriptLoader.loadSynchronously(scriptExecutionContext(), *it, AllowCrossOriginRedirect); + scriptLoader.loadSynchronously(scriptExecutionContext(), *it, AllowCrossOriginRequests); // If the fetching attempt failed, throw a NETWORK_ERR exception and abort all these steps. if (scriptLoader.failed()) { @@ -253,7 +216,9 @@ void WorkerContext::importScripts(const Vector<String>& urls, const String& call } scriptExecutionContext()->scriptImported(scriptLoader.identifier(), scriptLoader.script()); +#if ENABLE(INSPECTOR) scriptExecutionContext()->addMessage(InspectorControllerDestination, JSMessageSource, LogMessageType, LogMessageLevel, "Worker script imported: \"" + *it + "\".", callerLine, callerURL); +#endif ScriptValue exception; m_script->evaluate(ScriptSourceCode(scriptLoader.script(), *it), &exception); @@ -268,10 +233,34 @@ void WorkerContext::reportException(const String& errorMessage, int lineNumber, { bool errorHandled = false; if (onerror()) - errorHandled = onerror()->reportError(errorMessage, sourceURL, lineNumber); + errorHandled = onerror()->reportError(this, errorMessage, sourceURL, lineNumber); if (!errorHandled) - forwardException(errorMessage, lineNumber, sourceURL); + thread()->workerReportingProxy().postExceptionToWorkerObject(errorMessage, lineNumber, sourceURL); +} + +void WorkerContext::addMessage(MessageDestination destination, MessageSource source, MessageType type, MessageLevel level, const String& message, unsigned lineNumber, const String& sourceURL) +{ + thread()->workerReportingProxy().postConsoleMessageToWorkerObject(destination, source, type, level, message, lineNumber, sourceURL); +} + +#if ENABLE(NOTIFICATIONS) +NotificationCenter* WorkerContext::webkitNotifications() const +{ + if (!m_notifications) + m_notifications = NotificationCenter::create(scriptExecutionContext(), m_thread->getNotificationPresenter()); + return m_notifications.get(); +} +#endif + +EventTargetData* WorkerContext::eventTargetData() +{ + return &m_eventTargetData; +} + +EventTargetData* WorkerContext::ensureEventTargetData() +{ + return &m_eventTargetData; } } // namespace WebCore |