void SharedWorkerScriptLoader::notifyFinished() { if (m_scriptLoader.failed()) { m_worker->dispatchEvent(Event::create(eventNames().errorEvent, false, true)); delete this; } else { #if ENABLE(INSPECTOR) if (InspectorController* inspector = m_worker->scriptExecutionContext()->inspectorController()) inspector->scriptImported(m_scriptLoader.identifier(), m_scriptLoader.script()); #endif // Pass the script off to the worker, then send a connect event. m_webWorker->startWorkerContext(m_url, m_name, m_worker->scriptExecutionContext()->userAgent(m_url), m_scriptLoader.script()); sendConnect(); } }
void SharedWorkerScriptLoader::notifyFinished() { if (m_scriptLoader.failed()) { m_worker->dispatchEvent(Event::create(eventNames().errorEvent, false, true)); delete this; } else { // Pass the script off to the worker, then send a connect event. m_webWorker->startWorkerContext(m_url, m_name, m_worker->scriptExecutionContext()->userAgent(m_url), m_scriptLoader.script()); sendConnect(); } }
void SharedWorkerScriptLoader::load() { ASSERT(!m_loading); // If the shared worker is not yet running, load the script resource for it, otherwise just send it a connect event. if (m_webWorker->isStarted()) sendConnect(); else { m_scriptLoader.loadAsynchronously(m_worker->scriptExecutionContext(), m_url, DenyCrossOriginRequests, this); // Keep the worker + JS wrapper alive until the resource load is complete in case we need to dispatch an error event. m_worker->setPendingActivity(m_worker.get()); m_loading = true; } }
void WorkerContext::importScripts(const Vector<String>& urls, const String& callerURL, int callerLine, ExceptionCode& ec) { ec = 0; Vector<String>::const_iterator urlsEnd = urls.end(); Vector<KURL> completedURLs; for (Vector<String>::const_iterator it = urls.begin(); it != urlsEnd; ++it) { const KURL& url = scriptExecutionContext()->completeURL(*it); if (!url.isValid()) { ec = SYNTAX_ERR; return; } 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); // If the fetching attempt failed, throw a NETWORK_ERR exception and abort all these steps. 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(scriptLoader.script(), *it), &exception); if (!exception.hasNoValue()) { m_script->setException(exception); return; } } }