diff options
author | Ben Murdoch <benm@google.com> | 2009-08-11 17:01:47 +0100 |
---|---|---|
committer | Ben Murdoch <benm@google.com> | 2009-08-11 18:21:02 +0100 |
commit | 0bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5 (patch) | |
tree | 2943df35f62d885c89d01063cc528dd73b480fea /WebCore/workers/WorkerContext.cpp | |
parent | 7e7a70bfa49a1122b2597a1e6367d89eb4035eca (diff) | |
download | external_webkit-0bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5.zip external_webkit-0bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5.tar.gz external_webkit-0bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5.tar.bz2 |
Merge in WebKit r47029.
Diffstat (limited to 'WebCore/workers/WorkerContext.cpp')
-rw-r--r-- | WebCore/workers/WorkerContext.cpp | 75 |
1 files changed, 27 insertions, 48 deletions
diff --git a/WebCore/workers/WorkerContext.cpp b/WebCore/workers/WorkerContext.cpp index 0b8778a..722588f 100644 --- a/WebCore/workers/WorkerContext.cpp +++ b/WebCore/workers/WorkerContext.cpp @@ -36,16 +36,15 @@ #include "DOMWindow.h" #include "Event.h" #include "EventException.h" -#include "MessageEvent.h" +#include "MessagePort.h" #include "NotImplemented.h" -#include "ResourceRequest.h" #include "ScriptSourceCode.h" #include "ScriptValue.h" #include "SecurityOrigin.h" -#include "WorkerImportScriptsClient.h" #include "WorkerLocation.h" #include "WorkerNavigator.h" #include "WorkerObjectProxy.h" +#include "WorkerScriptLoader.h" #include "WorkerThread.h" #include "WorkerThreadableLoader.h" #include "XMLHttpRequestException.h" @@ -65,9 +64,6 @@ WorkerContext::WorkerContext(const KURL& url, const String& userAgent, WorkerThr WorkerContext::~WorkerContext() { - ASSERT(currentThread() == m_thread->threadID()); - - m_thread->workerObjectProxy().workerContextDestroyed(); } ScriptExecutionContext* WorkerContext::scriptExecutionContext() const @@ -131,17 +127,15 @@ bool WorkerContext::hasPendingActivity() const if (iter->first->hasPendingActivity()) return true; } - return false; -} -void WorkerContext::reportException(const String& errorMessage, int lineNumber, const String& sourceURL) -{ - m_thread->workerObjectProxy().postExceptionToWorkerObject(errorMessage, lineNumber, sourceURL); -} + // Keep the worker active as long as there is a MessagePort with pending activity or that is remotely entangled. + HashSet<MessagePort*>::const_iterator messagePortsEnd = messagePorts().end(); + for (HashSet<MessagePort*>::const_iterator iter = messagePorts().begin(); iter != messagePortsEnd; ++iter) { + if ((*iter)->hasPendingActivity() || ((*iter)->isEntangled() && !(*iter)->locallyEntangledPort())) + return true; + } -void WorkerContext::addMessage(MessageDestination destination, MessageSource source, MessageLevel level, const String& message, unsigned lineNumber, const String& sourceURL) -{ - m_thread->workerObjectProxy().postConsoleMessageToWorkerObject(destination, source, level, message, lineNumber, sourceURL); + return false; } void WorkerContext::resourceRetrievedByXMLHttpRequest(unsigned long, const ScriptString&) @@ -156,14 +150,6 @@ void WorkerContext::scriptImported(unsigned long, const String&) notImplemented(); } -void WorkerContext::postMessage(const String& message) -{ - if (m_closing) - return; - - m_thread->workerObjectProxy().postMessageToWorkerObject(message); -} - void WorkerContext::addEventListener(const AtomicString& eventType, PassRefPtr<EventListener> eventListener, bool) { EventListenersMap::iterator iter = m_eventListeners.find(eventType); @@ -240,23 +226,6 @@ void WorkerContext::clearInterval(int timeoutId) DOMTimer::removeById(scriptExecutionContext(), timeoutId); } -void WorkerContext::dispatchMessage(const String& message) -{ - // Since close() stops the thread event loop, this should not ever get called while closing. - ASSERT(!m_closing); - RefPtr<Event> evt = MessageEvent::create(message, "", "", 0, 0); - - if (m_onmessageListener.get()) { - evt->setTarget(this); - evt->setCurrentTarget(this); - m_onmessageListener->handleEvent(evt.get(), false); - } - - ExceptionCode ec = 0; - dispatchEvent(evt.release(), ec); - ASSERT(!ec); -} - void WorkerContext::importScripts(const Vector<String>& urls, const String& callerURL, int callerLine, ExceptionCode& ec) { ec = 0; @@ -274,20 +243,20 @@ void WorkerContext::importScripts(const Vector<String>& urls, const String& call Vector<KURL>::const_iterator end = completedURLs.end(); for (Vector<KURL>::const_iterator it = completedURLs.begin(); it != end; ++it) { - ResourceRequest request(*it); - request.setHTTPMethod("GET"); - request.setHTTPOrigin(securityOrigin); - WorkerImportScriptsClient client(scriptExecutionContext(), *it, callerURL, callerLine); - WorkerThreadableLoader::loadResourceSynchronously(this, request, client, AllowStoredCredentials, AllowDifferentRedirectOrigin); - + WorkerScriptLoader scriptLoader; + scriptLoader.loadSynchronously(scriptExecutionContext(), *it, AllowCrossOriginRedirect); + // If the fetching attempt failed, throw a NETWORK_ERR exception and abort all these steps. - if (client.failed()) { + if (scriptLoader.failed()) { ec = XMLHttpRequestException::NETWORK_ERR; return; } + scriptExecutionContext()->scriptImported(scriptLoader.identifier(), scriptLoader.script()); + scriptExecutionContext()->addMessage(InspectorControllerDestination, JSMessageSource, LogMessageType, LogMessageLevel, "Worker script imported: \"" + *it + "\".", callerLine, callerURL); + ScriptValue exception; - m_script->evaluate(ScriptSourceCode(client.script(), *it), &exception); + m_script->evaluate(ScriptSourceCode(scriptLoader.script(), *it), &exception); if (!exception.hasNoValue()) { m_script->setException(exception); return; @@ -295,6 +264,16 @@ void WorkerContext::importScripts(const Vector<String>& urls, const String& call } } +void WorkerContext::reportException(const String& errorMessage, int lineNumber, const String& sourceURL) +{ + bool errorHandled = false; + if (onerror()) + errorHandled = onerror()->reportError(errorMessage, sourceURL, lineNumber); + + if (!errorHandled) + forwardException(errorMessage, lineNumber, sourceURL); +} + } // namespace WebCore #endif // ENABLE(WORKERS) |