1a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)/* 2a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * Copyright (C) 2013 Google Inc. All rights reserved. 3a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * 4a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without 5a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * modification, are permitted provided that the following conditions are 6a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * met: 7a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * 8a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * * Redistributions of source code must retain the above copyright 9a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * notice, this list of conditions and the following disclaimer. 10a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * * Redistributions in binary form must reproduce the above 11a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * copyright notice, this list of conditions and the following disclaimer 12a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * in the documentation and/or other materials provided with the 13a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * distribution. 14a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * * Neither the name of Google Inc. nor the names of its 15a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * contributors may be used to endorse or promote products derived from 16a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * this software without specific prior written permission. 17a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * 18a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) */ 30a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 31a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#ifndef WebEmbeddedWorkerImpl_h 32a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#define WebEmbeddedWorkerImpl_h 33a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 34f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu#include "public/web/WebContentSecurityPolicy.h" 357242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci#include "public/web/WebDevToolsAgentClient.h" 36f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu#include "public/web/WebEmbeddedWorker.h" 37f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu#include "public/web/WebEmbeddedWorkerStartData.h" 38f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu#include "public/web/WebFrameClient.h" 39a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 40c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink { 41a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 42a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)class ServiceWorkerGlobalScopeProxy; 4343e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles)class WebServiceWorkerNetworkProvider; 44a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)class WebView; 459e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles)class WorkerInspectorProxy; 46e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)class WorkerScriptLoader; 47e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)class WorkerThread; 48a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 49c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)class WebEmbeddedWorkerImpl FINAL 50c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) : public WebEmbeddedWorker 517242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci , public WebFrameClient 527242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci , public WebDevToolsAgentClient { 53a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) WTF_MAKE_NONCOPYABLE(WebEmbeddedWorkerImpl); 54a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)public: 55a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) WebEmbeddedWorkerImpl( 56a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) PassOwnPtr<WebServiceWorkerContextClient>, 57a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) PassOwnPtr<WebWorkerPermissionClientProxy>); 58a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) virtual ~WebEmbeddedWorkerImpl(); 59a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 60c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) // Terminate all WebEmbeddedWorkerImpl for testing purposes. 61c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) // Note that this only schedules termination and 62c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) // does not synchronously wait for it to complete. 63c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) static void terminateAll(); 64c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) 65a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // WebEmbeddedWorker overrides. 66a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) virtual void startWorkerContext(const WebEmbeddedWorkerStartData&) OVERRIDE; 6776c265b59aa821ccbf8c75ab2bb0d036e97d2956Torne (Richard Coles) virtual void resumeAfterDownload() OVERRIDE; 68a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) virtual void terminateWorkerContext() OVERRIDE; 69f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu virtual void resumeWorkerContext() OVERRIDE; 709e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles) virtual void attachDevTools(const WebString& hostId) OVERRIDE; 719e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles) virtual void reattachDevTools(const WebString& hostId, const WebString& savedState) OVERRIDE; 72f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu virtual void detachDevTools() OVERRIDE; 73f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu virtual void dispatchDevToolsMessage(const WebString&) OVERRIDE; 74f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu 759e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles) void postMessageToPageInspector(const WTF::String&); 769e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles) 77a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)private: 78a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) class Loader; 79a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) class LoaderProxy; 80a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 81a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) void prepareShadowPageForLoader(); 82a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 8309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) // WebFrameClient overrides. 8443e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles) virtual void willSendRequest( 85a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch WebLocalFrame*, unsigned identifier, WebURLRequest&, 8643e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles) const WebURLResponse& redirectResponse) OVERRIDE; 87a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch virtual void didFinishDocumentLoad(WebLocalFrame*) OVERRIDE; 8809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 897242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci // WebDevToolsAgentClient overrides. 907242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci virtual void sendMessageToInspectorFrontend(const WebString&) OVERRIDE; 917242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci virtual void saveAgentRuntimeState(const WebString&) OVERRIDE; 927242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci virtual void resumeStartup() OVERRIDE; 937242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci 947242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci void startScriptLoader(WebLocalFrame*); 9509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) void onScriptLoaderFinished(); 9676c265b59aa821ccbf8c75ab2bb0d036e97d2956Torne (Richard Coles) void startWorkerThread(); 97a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 98a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) WebEmbeddedWorkerStartData m_workerStartData; 99a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 100a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) OwnPtr<WebServiceWorkerContextClient> m_workerContextClient; 101323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles) 102323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles) // This is kept until startWorkerContext is called, and then passed on 103323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles) // to WorkerContext. 104a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) OwnPtr<WebWorkerPermissionClientProxy> m_permissionClient; 105a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 10643e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles) // We retain ownership of this one which is for use on the 10743e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles) // main thread only. 10843e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles) OwnPtr<WebServiceWorkerNetworkProvider> m_networkProvider; 10943e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles) 110a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // Kept around only while main script loading is ongoing. 111a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) OwnPtr<Loader> m_mainScriptLoader; 112a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 113e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles) RefPtr<WorkerThread> m_workerThread; 114a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) OwnPtr<LoaderProxy> m_loaderProxy; 115a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) OwnPtr<ServiceWorkerGlobalScopeProxy> m_workerGlobalScopeProxy; 1169e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles) OwnPtr<WorkerInspectorProxy> m_workerInspectorProxy; 117a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 118a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // 'shadow page' - created to proxy loading requests from the worker. 119a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // Both WebView and WebFrame objects are close()'ed (where they're 120a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // deref'ed) when this EmbeddedWorkerImpl is destructed, therefore they 121a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // are guaranteed to exist while this object is around. 122a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) WebView* m_webView; 123a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) WebFrame* m_mainFrame; 124a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 125a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) bool m_askedToTerminate; 12676c265b59aa821ccbf8c75ab2bb0d036e97d2956Torne (Richard Coles) 1277242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci enum WaitingForDebuggerState { 1287242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci WaitingForDebuggerBeforeLoadingScript, 1297242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci WaitingForDebuggerAfterScriptLoaded, 1307242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci NotWaitingForDebugger 1317242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci }; 1327242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci 13376c265b59aa821ccbf8c75ab2bb0d036e97d2956Torne (Richard Coles) enum { 13476c265b59aa821ccbf8c75ab2bb0d036e97d2956Torne (Richard Coles) DontPauseAfterDownload, 13576c265b59aa821ccbf8c75ab2bb0d036e97d2956Torne (Richard Coles) DoPauseAfterDownload, 13676c265b59aa821ccbf8c75ab2bb0d036e97d2956Torne (Richard Coles) IsPausedAfterDownload 13776c265b59aa821ccbf8c75ab2bb0d036e97d2956Torne (Richard Coles) } m_pauseAfterDownloadState; 1387242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci 1397242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci WaitingForDebuggerState m_waitingForDebuggerState; 140a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)}; 141a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 142a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)} // namespace blink 143a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 144a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#endif // WebEmbeddedWorkerImpl_h 145