summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/WebKit/Source/core/workers/WorkerGlobalScope.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/WebKit/Source/core/workers/WorkerGlobalScope.cpp')
-rw-r--r--chromium/third_party/WebKit/Source/core/workers/WorkerGlobalScope.cpp146
1 files changed, 79 insertions, 67 deletions
diff --git a/chromium/third_party/WebKit/Source/core/workers/WorkerGlobalScope.cpp b/chromium/third_party/WebKit/Source/core/workers/WorkerGlobalScope.cpp
index cd8daa3ef8a..1b89c2ea747 100644
--- a/chromium/third_party/WebKit/Source/core/workers/WorkerGlobalScope.cpp
+++ b/chromium/third_party/WebKit/Source/core/workers/WorkerGlobalScope.cpp
@@ -44,13 +44,16 @@
#include "core/inspector/ScriptCallStack.h"
#include "core/inspector/WorkerInspectorController.h"
#include "core/loader/WorkerThreadableLoader.h"
-#include "core/frame/DOMWindow.h"
+#include "core/frame/LocalDOMWindow.h"
#include "core/workers/WorkerNavigator.h"
#include "core/workers/WorkerClients.h"
+#include "core/workers/WorkerConsole.h"
#include "core/workers/WorkerLocation.h"
+#include "core/workers/WorkerNavigator.h"
#include "core/workers/WorkerReportingProxy.h"
#include "core/workers/WorkerScriptLoader.h"
#include "core/workers/WorkerThread.h"
+#include "platform/network/ContentSecurityPolicyParsers.h"
#include "platform/weborigin/KURL.h"
#include "platform/weborigin/SecurityOrigin.h"
@@ -73,7 +76,7 @@ public:
virtual bool isCleanupTask() const { return true; }
};
-WorkerGlobalScope::WorkerGlobalScope(const KURL& url, const String& userAgent, WorkerThread* thread, double timeOrigin, PassOwnPtr<WorkerClients> workerClients)
+WorkerGlobalScope::WorkerGlobalScope(const KURL& url, const String& userAgent, WorkerThread* thread, double timeOrigin, PassOwnPtrWillBeRawPtr<WorkerClients> workerClients)
: m_url(url)
, m_userAgent(userAgent)
, m_script(adoptPtr(new WorkerScriptController(*this)))
@@ -83,33 +86,22 @@ WorkerGlobalScope::WorkerGlobalScope(const KURL& url, const String& userAgent, W
, m_eventQueue(WorkerEventQueue::create(this))
, m_workerClients(workerClients)
, m_timeOrigin(timeOrigin)
+ , m_terminationObserver(0)
{
ScriptWrappable::init(this);
setClient(this);
setSecurityOrigin(SecurityOrigin::create(url));
m_workerClients->reattachThread();
-
- // Notify proxy that a new WorkerGlobalScope has been created and started.
- this->thread()->workerReportingProxy().workerGlobalScopeStarted();
}
WorkerGlobalScope::~WorkerGlobalScope()
{
- ASSERT(thread()->isCurrentThread());
-
- // Make sure we have no observers.
- notifyObserversOfStop();
-
- // Notify proxy that we are going away. This can free the WorkerThread object, so do not access it after this.
- thread()->workerReportingProxy().workerGlobalScopeDestroyed();
-
- setClient(0);
}
-void WorkerGlobalScope::applyContentSecurityPolicyFromString(const String& policy, ContentSecurityPolicy::HeaderType contentSecurityPolicyType)
+void WorkerGlobalScope::applyContentSecurityPolicyFromString(const String& policy, ContentSecurityPolicyHeaderType contentSecurityPolicyType)
{
setContentSecurityPolicy(ContentSecurityPolicy::create(this));
- contentSecurityPolicy()->didReceiveHeader(policy, contentSecurityPolicyType);
+ contentSecurityPolicy()->didReceiveHeader(policy, contentSecurityPolicyType, ContentSecurityPolicyHeaderSourceHTTP);
}
ExecutionContext* WorkerGlobalScope::executionContext() const
@@ -195,17 +187,62 @@ void WorkerGlobalScope::clearInspector()
m_workerInspectorController.clear();
}
+void WorkerGlobalScope::registerTerminationObserver(TerminationObserver* observer)
+{
+ ASSERT(!m_terminationObserver);
+ ASSERT(observer);
+ m_terminationObserver = observer;
+}
+
+void WorkerGlobalScope::unregisterTerminationObserver(TerminationObserver* observer)
+{
+ ASSERT(observer);
+ ASSERT(m_terminationObserver == observer);
+ m_terminationObserver = 0;
+}
+
+void WorkerGlobalScope::wasRequestedToTerminate()
+{
+ if (m_terminationObserver)
+ m_terminationObserver->wasRequestedToTerminate();
+}
+
+void WorkerGlobalScope::dispose()
+{
+ ASSERT(thread()->isCurrentThread());
+
+ m_eventQueue->close();
+ clearScript();
+ clearInspector();
+ setClient(0);
+
+ // We do not clear the thread field of the
+ // WorkerGlobalScope. Other objects keep the worker global scope
+ // alive because they need its thread field to check that work is
+ // being carried out on the right thread. We therefore cannot clear
+ // the thread field before all references to the worker global
+ // scope are gone.
+}
+
void WorkerGlobalScope::importScripts(const Vector<String>& urls, ExceptionState& exceptionState)
{
ASSERT(contentSecurityPolicy());
+ ASSERT(executionContext());
+
+ ExecutionContext& executionContext = *this->executionContext();
+
Vector<String>::const_iterator urlsEnd = urls.end();
Vector<KURL> completedURLs;
for (Vector<String>::const_iterator it = urls.begin(); it != urlsEnd; ++it) {
- const KURL& url = executionContext()->completeURL(*it);
+ const KURL& url = executionContext.completeURL(*it);
if (!url.isValid()) {
exceptionState.throwDOMException(SyntaxError, "The URL '" + *it + "' is invalid.");
return;
}
+ if (!contentSecurityPolicy()->allowScriptFromSource(url)) {
+ exceptionState.throwDOMException(NetworkError, "The script at '" + url.elidedString() + "' failed to load.");
+ return;
+ }
completedURLs.append(url);
}
Vector<KURL>::const_iterator end = completedURLs.end();
@@ -213,7 +250,7 @@ void WorkerGlobalScope::importScripts(const Vector<String>& urls, ExceptionState
for (Vector<KURL>::const_iterator it = completedURLs.begin(); it != end; ++it) {
RefPtr<WorkerScriptLoader> scriptLoader(WorkerScriptLoader::create());
scriptLoader->setTargetType(ResourceRequest::TargetIsScript);
- scriptLoader->loadSynchronously(executionContext(), *it, AllowCrossOriginRequests);
+ scriptLoader->loadSynchronously(executionContext, *it, AllowCrossOriginRequests);
// If the fetching attempt failed, throw a NetworkError exception and abort all these steps.
if (scriptLoader->failed()) {
@@ -221,9 +258,9 @@ void WorkerGlobalScope::importScripts(const Vector<String>& urls, ExceptionState
return;
}
- InspectorInstrumentation::scriptImported(executionContext(), scriptLoader->identifier(), scriptLoader->script());
+ InspectorInstrumentation::scriptImported(&executionContext, scriptLoader->identifier(), scriptLoader->script());
- RefPtr<ErrorEvent> errorEvent;
+ RefPtrWillBeRawPtr<ErrorEvent> errorEvent = nullptr;
m_script->evaluate(ScriptSourceCode(scriptLoader->script(), scriptLoader->responseURL()), &errorEvent);
if (errorEvent) {
m_script->rethrowExceptionFromImportedScript(errorEvent.release());
@@ -237,7 +274,7 @@ EventTarget* WorkerGlobalScope::errorEventTarget()
return this;
}
-void WorkerGlobalScope::logExceptionToConsole(const String& errorMessage, const String& sourceURL, int lineNumber, int columnNumber, PassRefPtr<ScriptCallStack>)
+void WorkerGlobalScope::logExceptionToConsole(const String& errorMessage, const String& sourceURL, int lineNumber, int columnNumber, PassRefPtrWillBeRawPtr<ScriptCallStack>)
{
thread()->workerReportingProxy().reportException(errorMessage, lineNumber, columnNumber, sourceURL);
}
@@ -247,23 +284,23 @@ void WorkerGlobalScope::reportBlockedScriptExecutionToInspector(const String& di
InspectorInstrumentation::scriptExecutionBlockedByCSP(this, directiveText);
}
-void WorkerGlobalScope::addMessage(MessageSource source, MessageLevel level, const String& message, const String& sourceURL, unsigned lineNumber, ScriptState* state)
+void WorkerGlobalScope::addMessage(MessageSource source, MessageLevel level, const String& message, const String& sourceURL, unsigned lineNumber, ScriptState* scriptState)
{
if (!isContextThread()) {
postTask(AddConsoleMessageTask::create(source, level, message));
return;
}
thread()->workerReportingProxy().reportConsoleMessage(source, level, message, lineNumber, sourceURL);
- addMessageToWorkerConsole(source, level, message, sourceURL, lineNumber, 0, state);
+ addMessageToWorkerConsole(source, level, message, sourceURL, lineNumber, nullptr, scriptState);
}
-void WorkerGlobalScope::addMessageToWorkerConsole(MessageSource source, MessageLevel level, const String& message, const String& sourceURL, unsigned lineNumber, PassRefPtr<ScriptCallStack> callStack, ScriptState* state)
+void WorkerGlobalScope::addMessageToWorkerConsole(MessageSource source, MessageLevel level, const String& message, const String& sourceURL, unsigned lineNumber, PassRefPtrWillBeRawPtr<ScriptCallStack> callStack, ScriptState* scriptState)
{
ASSERT(isContextThread());
if (callStack)
InspectorInstrumentation::addMessageToConsole(this, source, LogMessageType, level, message, callStack);
else
- InspectorInstrumentation::addMessageToConsole(this, source, LogMessageType, level, message, sourceURL, lineNumber, 0, state);
+ InspectorInstrumentation::addMessageToConsole(this, source, LogMessageType, level, message, sourceURL, lineNumber, 0, scriptState);
}
bool WorkerGlobalScope::isContextThread() const
@@ -276,61 +313,36 @@ bool WorkerGlobalScope::isJSExecutionForbidden() const
return m_script->isExecutionForbidden();
}
-WorkerGlobalScope::Observer::Observer(WorkerGlobalScope* context)
- : m_context(context)
-{
- ASSERT(m_context && m_context->isContextThread());
- m_context->registerObserver(this);
-}
-
-WorkerGlobalScope::Observer::~Observer()
-{
- if (!m_context)
- return;
- ASSERT(m_context->isContextThread());
- m_context->unregisterObserver(this);
-}
-
-void WorkerGlobalScope::Observer::stopObserving()
-{
- if (!m_context)
- return;
- ASSERT(m_context->isContextThread());
- m_context->unregisterObserver(this);
- m_context = 0;
-}
-
-void WorkerGlobalScope::registerObserver(Observer* observer)
+bool WorkerGlobalScope::idleNotification()
{
- ASSERT(observer);
- m_workerObservers.add(observer);
+ return script()->idleNotification();
}
-void WorkerGlobalScope::unregisterObserver(Observer* observer)
+WorkerEventQueue* WorkerGlobalScope::eventQueue() const
{
- ASSERT(observer);
- m_workerObservers.remove(observer);
+ return m_eventQueue.get();
}
-void WorkerGlobalScope::notifyObserversOfStop()
+void WorkerGlobalScope::countFeature(UseCounter::Feature) const
{
- HashSet<Observer*>::iterator iter = m_workerObservers.begin();
- while (iter != m_workerObservers.end()) {
- WorkerGlobalScope::Observer* observer = *iter;
- observer->stopObserving();
- observer->notifyStop();
- iter = m_workerObservers.begin();
- }
+ // FIXME: How should we count features for shared/service workers?
}
-bool WorkerGlobalScope::idleNotification()
+void WorkerGlobalScope::countDeprecation(UseCounter::Feature) const
{
- return script()->idleNotification();
+ // FIXME: How should we count features for shared/service workers?
}
-WorkerEventQueue* WorkerGlobalScope::eventQueue() const
+void WorkerGlobalScope::trace(Visitor* visitor)
{
- return m_eventQueue.get();
+ visitor->trace(m_console);
+ visitor->trace(m_location);
+ visitor->trace(m_navigator);
+ visitor->trace(m_eventQueue);
+ visitor->trace(m_workerClients);
+ WillBeHeapSupplementable<WorkerGlobalScope>::trace(visitor);
+ ExecutionContext::trace(visitor);
+ EventTargetWithInlineData::trace(visitor);
}
} // namespace WebCore