Changeset 224295 in webkit
- Timestamp:
- Nov 1, 2017 2:23:52 PM (6 years ago)
- Location:
- trunk/Source
- Files:
-
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r224290 r224295 1 2017-11-01 Brady Eidson <beidson@apple.com> 2 3 Plumbing for handling SW scripts failing to evaluate 4 https://bugs.webkit.org/show_bug.cgi?id=178926 5 6 Reviewed by Chris Dumez. 7 8 No new tests (Currently no observable behavior change). 9 10 In an upcoming patch we'll actually run the appropriate observable steps for when 11 a ServiceWorker script fails to evaluate. 12 13 This is a standalone refactoring + plumbing patch that will make the observable changes 14 easier to review. 15 16 * bindings/js/WorkerScriptController.cpp: 17 (WebCore::WorkerScriptController::evaluate): 18 * bindings/js/WorkerScriptController.h: 19 (WebCore::WorkerScriptController::workerGlobalScopeWrapper): 20 (WebCore::WorkerScriptController::vm): 21 (WebCore::WorkerScriptController::initScriptIfNeeded): 22 23 * workers/WorkerMessagingProxy.cpp: 24 (WebCore::WorkerMessagingProxy::startWorkerGlobalScope): 25 26 * workers/WorkerThread.cpp: 27 (WebCore::WorkerThread::start): 28 (WebCore::WorkerThread::workerThread): 29 * workers/WorkerThread.h: 30 31 * workers/service/context/SWContextManager.cpp: 32 (WebCore::SWContextManager::registerServiceWorkerThreadForUpdate): 33 (WebCore::SWContextManager::registerServiceWorkerThread): Deleted. 34 * workers/service/context/SWContextManager.h: 35 36 * workers/service/context/ServiceWorkerThread.h: 37 (WebCore::ServiceWorkerThread::serverConnectionIdentifier const): 38 (WebCore::ServiceWorkerThread::contextData const): 39 40 * workers/service/context/ServiceWorkerThreadProxy.cpp: 41 (WebCore::ServiceWorkerThreadProxy::create): 42 (WebCore::ServiceWorkerThreadProxy::ServiceWorkerThreadProxy): 43 44 * workers/service/server/SWServer.cpp: 45 (WebCore::SWServer::updateWorker): 46 (WebCore::SWServer::createWorker): Deleted. 47 * workers/service/server/SWServer.h: 48 49 * workers/service/server/SWServerRegistration.cpp: 50 (WebCore::SWServerRegistration::scriptFetchFinished): 51 (WebCore::SWServerRegistration::scriptContextFailedToStart): 52 1 53 2017-11-01 Ryosuke Niwa <rniwa@webkit.org> 2 54 -
trunk/Source/WebCore/bindings/js/WorkerScriptController.cpp
r223746 r224295 121 121 } 122 122 123 void WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode )123 void WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode, String* returnedExceptionMessage) 124 124 { 125 125 if (isExecutionForbidden()) … … 127 127 128 128 NakedPtr<JSC::Exception> exception; 129 evaluate(sourceCode, exception );129 evaluate(sourceCode, exception, returnedExceptionMessage); 130 130 if (exception) { 131 131 JSLockHolder lock(vm()); … … 134 134 } 135 135 136 void WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode, NakedPtr<JSC::Exception>& returnedException )136 void WorkerScriptController::evaluate(const ScriptSourceCode& sourceCode, NakedPtr<JSC::Exception>& returnedException, String* returnedExceptionMessage) 137 137 { 138 138 if (isExecutionForbidden()) … … 158 158 String sourceURL = sourceCode.url().string(); 159 159 JSC::Strong<JSC::Unknown> error; 160 if (m_workerGlobalScope->sanitizeScriptError(errorMessage, lineNumber, columnNumber, sourceURL, error, sourceCode.cachedScript())) 160 if (m_workerGlobalScope->sanitizeScriptError(errorMessage, lineNumber, columnNumber, sourceURL, error, sourceCode.cachedScript())) { 161 if (returnedExceptionMessage) 162 *returnedExceptionMessage = errorMessage; 161 163 returnedException = JSC::Exception::create(vm, createError(exec, errorMessage.impl())); 164 } 162 165 } 163 166 } -
trunk/Source/WebCore/bindings/js/WorkerScriptController.h
r218951 r224295 40 40 namespace WebCore { 41 41 42 43 44 45 42 class JSWorkerGlobalScope; 43 class ScriptSourceCode; 44 class WorkerConsoleClient; 45 class WorkerGlobalScope; 46 46 47 48 49 50 51 47 class WorkerScriptController { 48 WTF_MAKE_NONCOPYABLE(WorkerScriptController); WTF_MAKE_FAST_ALLOCATED; 49 public: 50 WorkerScriptController(WorkerGlobalScope*); 51 ~WorkerScriptController(); 52 52 53 54 55 56 57 53 JSWorkerGlobalScope* workerGlobalScopeWrapper() 54 { 55 initScriptIfNeeded(); 56 return m_workerGlobalScopeWrapper.get(); 57 } 58 58 59 void evaluate(const ScriptSourceCode&);60 void evaluate(const ScriptSourceCode&, NakedPtr<JSC::Exception>& returnedException);59 void evaluate(const ScriptSourceCode&, String* returnedExceptionMessage = nullptr); 60 void evaluate(const ScriptSourceCode&, NakedPtr<JSC::Exception>& returnedException, String* returnedExceptionMessage = nullptr); 61 61 62 62 void setException(JSC::Exception*); 63 63 64 65 66 67 68 69 70 64 // Async request to terminate a JS run execution. Eventually causes termination 65 // exception raised during JS execution, if the worker thread happens to run JS. 66 // After JS execution was terminated in this way, the Worker thread has to use 67 // forbidExecution()/isExecutionForbidden() to guard against reentry into JS. 68 // Can be called from any thread. 69 void scheduleExecutionTermination(); 70 bool isTerminatingExecution() const; 71 71 72 73 74 75 72 // Called on Worker thread when JS exits with termination exception caused by forbidExecution() request, 73 // or by Worker thread termination code to prevent future entry into JS. 74 void forbidExecution(); 75 bool isExecutionForbidden() const; 76 76 77 78 77 void disableEval(const String& errorMessage); 78 void disableWebAssembly(const String& errorMessage); 79 79 80 81 82 83 80 JSC::VM& vm() { return *m_vm; } 81 82 void releaseHeapAccess(); 83 void acquireHeapAccess(); 84 84 85 86 85 void addTimerSetNotification(JSC::JSRunLoopTimer::TimerNotificationCallback); 86 void removeTimerSetNotification(JSC::JSRunLoopTimer::TimerNotificationCallback); 87 87 88 89 88 void attachDebugger(JSC::Debugger*); 89 void detachDebugger(JSC::Debugger*); 90 90 91 92 93 94 95 96 97 91 private: 92 void initScriptIfNeeded() 93 { 94 if (!m_workerGlobalScopeWrapper) 95 initScript(); 96 } 97 void initScript(); 98 98 99 100 101 102 103 104 105 106 99 RefPtr<JSC::VM> m_vm; 100 WorkerGlobalScope* m_workerGlobalScope; 101 JSC::Strong<JSWorkerGlobalScope> m_workerGlobalScopeWrapper; 102 std::unique_ptr<WorkerConsoleClient> m_consoleClient; 103 bool m_executionForbidden { false }; 104 bool m_isTerminatingExecution { false }; 105 mutable Lock m_scheduledTerminationMutex; 106 }; 107 107 108 108 } // namespace WebCore -
trunk/Source/WebCore/workers/WorkerMessagingProxy.cpp
r224147 r224295 92 92 93 93 workerThreadCreated(thread.get()); 94 thread->start( );94 thread->start(nullptr); 95 95 96 96 m_inspectorProxy->workerStarted(m_scriptExecutionContext.get(), thread.ptr(), scriptURL); -
trunk/Source/WebCore/workers/WorkerThread.cpp
r224147 r224295 129 129 } 130 130 131 bool WorkerThread::start( )131 bool WorkerThread::start(WTF::Function<void(const String&)>&& evaluateCallback) 132 132 { 133 133 // Mutex protection is necessary to ensure that m_thread is initialized when the thread starts. … … 136 136 if (m_thread) 137 137 return true; 138 139 m_evaluateCallback = WTFMove(evaluateCallback); 138 140 139 141 m_thread = Thread::create("WebCore: Worker", [this] { … … 182 184 } 183 185 184 scriptController->evaluate(ScriptSourceCode(m_startupData->m_sourceCode, m_startupData->m_scriptURL)); 186 String exceptionMessage; 187 scriptController->evaluate(ScriptSourceCode(m_startupData->m_sourceCode, m_startupData->m_scriptURL), &exceptionMessage); 188 189 RunLoop::main().dispatch([evaluateCallback = WTFMove(m_evaluateCallback), message = exceptionMessage.isolatedCopy()] { 190 if (evaluateCallback) 191 evaluateCallback(message); 192 }); 193 185 194 // Free the startup data to cause its member variable deref's happen on the worker's thread (since 186 195 // all ref/derefs of these objects are happening on the thread at this point). Note that -
trunk/Source/WebCore/workers/WorkerThread.h
r224147 r224295 30 30 #include <runtime/RuntimeFlags.h> 31 31 #include <wtf/Forward.h> 32 #include <wtf/Function.h> 32 33 #include <wtf/RefCounted.h> 33 34 … … 63 64 virtual ~WorkerThread(); 64 65 65 WEBCORE_EXPORT bool start( );66 WEBCORE_EXPORT bool start(WTF::Function<void(const String&)>&& evaluateCallback); 66 67 void stop(); 67 68 … … 115 116 116 117 std::unique_ptr<WorkerThreadStartupData> m_startupData; 118 119 WTF::Function<void(const String&)> m_evaluateCallback; 117 120 118 121 #if ENABLE(NOTIFICATIONS) -
trunk/Source/WebCore/workers/service/context/SWContextManager.cpp
r224113 r224295 48 48 } 49 49 50 void SWContextManager::registerServiceWorkerThread (Ref<ServiceWorkerThreadProxy>&& serviceWorkerThreadProxy)50 void SWContextManager::registerServiceWorkerThreadForUpdate(Ref<ServiceWorkerThreadProxy>&& serviceWorkerThreadProxy) 51 51 { 52 52 auto serviceWorkerIdentifier = serviceWorkerThreadProxy->identifier(); 53 auto* threadProxy = serviceWorkerThreadProxy.ptr(); 53 54 auto result = m_workerMap.add(serviceWorkerIdentifier, WTFMove(serviceWorkerThreadProxy)); 54 55 ASSERT_UNUSED(result, result.isNewEntry); 56 57 threadProxy->thread().start([serviceWorkerIdentifier](const String& exceptionMessage) { 58 SWContextManager::singleton().connection()->serviceWorkerStartedWithMessage(serviceWorkerIdentifier, exceptionMessage); 59 }); 55 60 } 56 61 -
trunk/Source/WebCore/workers/service/context/SWContextManager.h
r224113 r224295 46 46 47 47 virtual void postMessageToServiceWorkerClient(const ServiceWorkerClientIdentifier& destinationIdentifier, Ref<SerializedScriptValue>&& message, uint64_t sourceServiceWorkerIdentifier, const String& sourceOrigin) = 0; 48 virtual void serviceWorkerStartedWithMessage(uint64_t serviceWorkerIdentifier, const String& exceptionMessage) = 0; 48 49 }; 49 50 … … 51 52 WEBCORE_EXPORT Connection* connection() const; 52 53 53 WEBCORE_EXPORT void registerServiceWorkerThread (Ref<ServiceWorkerThreadProxy>&&);54 WEBCORE_EXPORT void registerServiceWorkerThreadForUpdate(Ref<ServiceWorkerThreadProxy>&&); 54 55 WEBCORE_EXPORT ServiceWorkerThreadProxy* serviceWorkerThreadProxy(uint64_t) const; 55 56 WEBCORE_EXPORT void postMessageToServiceWorkerGlobalScope(uint64_t destinationServiceWorkerIdentifier, Ref<SerializedScriptValue>&& message, const ServiceWorkerClientIdentifier& sourceIdentifier, const String& sourceOrigin); -
trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.h
r224147 r224295 58 58 WEBCORE_EXPORT void postMessageToServiceWorkerGlobalScope(Ref<SerializedScriptValue>&&, std::unique_ptr<MessagePortChannelArray>&&, const ServiceWorkerClientIdentifier& sourceIdentifier, const String& sourceOrigin); 59 59 60 uint64_t serverConnectionIdentifier() const { return m_serverConnectionIdentifier; } 61 const ServiceWorkerContextData& contextData() const { return m_data; } 62 60 63 protected: 61 64 Ref<WorkerGlobalScope> createWorkerGlobalScope(const URL&, const String& identifier, const String& userAgent, const ContentSecurityPolicyResponseHeaders&, bool shouldBypassMainWorldContentSecurityPolicy, Ref<SecurityOrigin>&& topOrigin, MonotonicTime timeOrigin, PAL::SessionID) final; -
trunk/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.cpp
r224147 r224295 39 39 Ref<ServiceWorkerThreadProxy> ServiceWorkerThreadProxy::create(PageConfiguration&& pageConfiguration, uint64_t serverConnectionIdentifier, const ServiceWorkerContextData& data, PAL::SessionID sessionID, CacheStorageProvider& cacheStorageProvider) 40 40 { 41 auto serviceWorker = adoptRef(*new ServiceWorkerThreadProxy { WTFMove(pageConfiguration), serverConnectionIdentifier, data, sessionID, cacheStorageProvider }); 42 serviceWorker->m_serviceWorkerThread->start(); 43 return serviceWorker; 41 return adoptRef(*new ServiceWorkerThreadProxy { WTFMove(pageConfiguration), serverConnectionIdentifier, data, sessionID, cacheStorageProvider }); 44 42 } 45 43 … … 62 60 , m_sessionID(sessionID) 63 61 { 64 m_serviceWorkerThread->start();65 62 } 66 63 -
trunk/Source/WebCore/workers/service/server/SWServer.cpp
r223964 r224295 180 180 } 181 181 182 Ref<SWServerWorker> SWServer:: createWorker(Connection& connection, const ServiceWorkerRegistrationKey& registrationKey, const URL& url, const String& script, WorkerType type)182 Ref<SWServerWorker> SWServer::updateWorker(Connection& connection, const ServiceWorkerRegistrationKey& registrationKey, const URL& url, const String& script, WorkerType type) 183 183 { 184 184 String workerID = createCanonicalUUIDString(); … … 187 187 ASSERT(result.isNewEntry); 188 188 189 connection. startServiceWorkerContext({ registrationKey, workerID, script, url });189 connection.updateServiceWorkerContext({ registrationKey, workerID, script, url }); 190 190 191 191 return result.iterator->value.get(); -
trunk/Source/WebCore/workers/service/server/SWServer.h
r223964 r224295 73 73 74 74 // Messages to the SW host WebProcess 75 virtual void startServiceWorkerContext(const ServiceWorkerContextData&) = 0;75 virtual void updateServiceWorkerContext(const ServiceWorkerContextData&) = 0; 76 76 77 77 SWServer& m_server; … … 90 90 void postTaskReply(CrossThreadTask&&); 91 91 92 Ref<SWServerWorker> createWorker(Connection&, const ServiceWorkerRegistrationKey&, const URL&, const String& script, WorkerType);92 Ref<SWServerWorker> updateWorker(Connection&, const ServiceWorkerRegistrationKey&, const URL&, const String& script, WorkerType); 93 93 94 94 private: -
trunk/Source/WebCore/workers/service/server/SWServerRegistration.cpp
r224218 r224295 85 85 86 86 // FIXME: Support the proper worker type (classic vs module) 87 m_server. createWorker(connection, m_registrationKey, m_currentJob->scriptURL, result.script, WorkerType::Classic);87 m_server.updateWorker(connection, m_registrationKey, m_currentJob->scriptURL, result.script, WorkerType::Classic); 88 88 } 89 89 90 90 void SWServerRegistration::scriptContextFailedToStart(SWServer::Connection&, const String& workerID, const String& message) 91 91 { 92 // FIXME: Install has failed. Run the install failed substeps 93 // Run the Update Worker State algorithm passing registration’s installing worker and redundant as the arguments. 94 // Run the Update Registration State algorithm passing registration, "installing" and null as the arguments. 95 // If newestWorker is null, invoke Clear Registration algorithm passing registration as its argument. 96 92 97 UNUSED_PARAM(workerID); 93 94 rejectCurrentJob(ExceptionData { UnknownError, message }); 98 UNUSED_PARAM(message); 95 99 } 96 100 -
trunk/Source/WebKit/ChangeLog
r224284 r224295 1 2017-11-01 Brady Eidson <beidson@apple.com> 2 3 Plumbing for handling SW scripts failing to evaluate 4 https://bugs.webkit.org/show_bug.cgi?id=178926 5 6 Reviewed by Chris Dumez. 7 8 * StorageProcess/ServiceWorker/WebSWServerConnection.cpp: 9 (WebKit::WebSWServerConnection::updateServiceWorkerContext): 10 (WebKit::WebSWServerConnection::setContextConnection): 11 (WebKit::WebSWServerConnection::startServiceWorkerContext): Deleted. 12 * StorageProcess/ServiceWorker/WebSWServerConnection.h: 13 14 * WebProcess/Storage/WebSWContextManagerConnection.cpp: 15 (WebKit::WebSWContextManagerConnection::updateServiceWorker): 16 (WebKit::WebSWContextManagerConnection::serviceWorkerStartedWithMessage): 17 (WebKit::WebSWContextManagerConnection::startServiceWorker): Deleted. 18 * WebProcess/Storage/WebSWContextManagerConnection.h: 19 * WebProcess/Storage/WebSWContextManagerConnection.messages.in: 20 1 21 2017-11-01 Frederic Wang <fwang@igalia.com> 2 22 -
trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp
r224113 r224295 97 97 } 98 98 99 void WebSWServerConnection:: startServiceWorkerContext(const ServiceWorkerContextData& data)99 void WebSWServerConnection::updateServiceWorkerContext(const ServiceWorkerContextData& data) 100 100 { 101 if (sendToContextProcess(Messages::WebSWContextManagerConnection:: StartServiceWorker(identifier(), data)))101 if (sendToContextProcess(Messages::WebSWContextManagerConnection::UpdateServiceWorker(identifier(), data))) 102 102 return; 103 103 … … 158 158 m_contextConnection = connection; 159 159 160 // We can now start any pending service worker contexts.160 // We can now start any pending service worker updates. 161 161 for (auto& pendingContextData : m_pendingContextDatas) 162 startServiceWorkerContext(pendingContextData);162 updateServiceWorkerContext(pendingContextData); 163 163 164 164 m_pendingContextDatas.clear(); -
trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h
r224113 r224295 72 72 73 73 // Messages to the SW context WebProcess 74 void startServiceWorkerContext(const WebCore::ServiceWorkerContextData&) final;74 void updateServiceWorkerContext(const WebCore::ServiceWorkerContextData&) final; 75 75 76 76 IPC::Connection* messageSenderConnection() final { return m_contentConnection.ptr(); } -
trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp
r224153 r224295 96 96 } 97 97 98 void WebSWContextManagerConnection:: startServiceWorker(uint64_t serverConnectionIdentifier, const ServiceWorkerContextData& data)98 void WebSWContextManagerConnection::updateServiceWorker(uint64_t serverConnectionIdentifier, const ServiceWorkerContextData& data) 99 99 { 100 100 // FIXME: Provide a sensical session ID. … … 108 108 }; 109 109 fillWithEmptyClients(pageConfiguration); 110 111 // FIXME: This method should be moved directly to WebCore::SWContextManager::Connection 112 // If it weren't for ServiceWorkerFrameLoaderClient's dependence on WebDocumentLoader, this could already happen. 110 113 auto frameLoaderClient = std::make_unique<ServiceWorkerFrameLoaderClient>(sessionID, m_pageID, ++m_previousServiceWorkerID); 111 114 pageConfiguration.loaderClientForMainFrame = frameLoaderClient.release(); 112 115 113 116 auto serviceWorkerThreadProxy = ServiceWorkerThreadProxy::create(WTFMove(pageConfiguration), serverConnectionIdentifier, data, sessionID, WebProcess::singleton().cacheStorageProvider()); 114 auto serviceWorkerIdentifier = serviceWorkerThreadProxy->identifier(); 115 SWContextManager::singleton().registerServiceWorkerThread(WTFMove(serviceWorkerThreadProxy)); 117 SWContextManager::singleton().registerServiceWorkerThreadForUpdate(WTFMove(serviceWorkerThreadProxy)); 116 118 117 LOG(ServiceWorker, "Context process PID: %i started worker thread %s\n", getpid(), data.workerID.utf8().data()); 119 LOG(ServiceWorker, "Context process PID: %i created worker thread %s\n", getpid(), data.workerID.utf8().data()); 120 } 118 121 119 m_connectionToStorageProcess->send(Messages::StorageProcess::ServiceWorkerContextStarted(serverConnectionIdentifier, data.registrationKey, serviceWorkerIdentifier, data.workerID), 0); 122 void WebSWContextManagerConnection::serviceWorkerStartedWithMessage(uint64_t serviceWorkerIdentifier, const String& exceptionMessage) 123 { 124 auto* threadProxy = SWContextManager::singleton().serviceWorkerThreadProxy(serviceWorkerIdentifier); 125 ASSERT(threadProxy); 126 127 auto& data = threadProxy->thread().contextData(); 128 129 if (exceptionMessage.isEmpty()) 130 m_connectionToStorageProcess->send(Messages::StorageProcess::ServiceWorkerContextStarted(threadProxy->thread().serverConnectionIdentifier(), data.registrationKey, serviceWorkerIdentifier, data.workerID), 0); 131 else 132 m_connectionToStorageProcess->send(Messages::StorageProcess::ServiceWorkerContextFailedToStart(threadProxy->thread().serverConnectionIdentifier(), data.registrationKey, data.workerID, exceptionMessage), 0); 120 133 } 121 134 -
trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h
r224113 r224295 55 55 56 56 // IPC messages. 57 void startServiceWorker(uint64_t serverConnectionIdentifier, const WebCore::ServiceWorkerContextData&); 57 void serviceWorkerStartedWithMessage(uint64_t serviceWorkerIdentifier, const String& exceptionMessage) final; 58 void updateServiceWorker(uint64_t serverConnectionIdentifier, const WebCore::ServiceWorkerContextData&); 58 59 void startFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, uint64_t serviceWorkerIdentifier, WebCore::ResourceRequest&&, WebCore::FetchOptions&&); 59 60 void postMessageToServiceWorkerGlobalScope(uint64_t destinationServiceWorkerIdentifier, const IPC::DataReference& message, const WebCore::ServiceWorkerClientIdentifier& sourceIdentifier, const String& sourceOrigin); -
trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in
r224113 r224295 24 24 25 25 messages -> WebSWContextManagerConnection { 26 StartServiceWorker(uint64_t serverConnectionIdentifier, struct WebCore::ServiceWorkerContextData contextData)26 UpdateServiceWorker(uint64_t serverConnectionIdentifier, struct WebCore::ServiceWorkerContextData contextData) 27 27 StartFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, uint64_t serviceWorkerIdentifier, WebCore::ResourceRequest request, struct WebCore::FetchOptions options) 28 28 PostMessageToServiceWorkerGlobalScope(uint64_t destinationServiceWorkerIdentifier, IPC::DataReference message, struct WebCore::ServiceWorkerClientIdentifier sourceIdentifier, String sourceOrigin)
Note: See TracChangeset
for help on using the changeset viewer.