15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/* 25267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * Copyright (C) 2013 Google Inc. All rights reserved. 35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without 55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modification, are permitted provided that the following conditions are 65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * met: 75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * * Redistributions of source code must retain the above copyright 95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * notice, this list of conditions and the following disclaimer. 105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * * Redistributions in binary form must reproduce the above 115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * copyright notice, this list of conditions and the following disclaimer 125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * in the documentation and/or other materials provided with the 135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * distribution. 145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * * Neither the name of Google Inc. nor the names of its 155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * contributors may be used to endorse or promote products derived from 165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * this software without specific prior written permission. 175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */ 305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#ifndef WebServiceWorkerContextClient_h 3251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#define WebServiceWorkerContextClient_h 335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#include "WebWorkerPermissionClientProxy.h" 35323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)#include "public/platform/WebMessagePortChannel.h" 3610f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch#include "public/platform/WebServiceWorkerClientsInfo.h" 3707a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch#include "public/platform/WebServiceWorkerEventResult.h" 386f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch#include "public/platform/WebURL.h" 3951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 4051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)namespace blink { 415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 4243e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles)class WebDataSource; 43c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)class WebServiceWorkerCacheStorage; 4451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)class WebServiceWorkerContextProxy; 4543e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles)class WebServiceWorkerNetworkProvider; 46d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)class WebServiceWorkerResponse; 4710f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdochclass WebString; 485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 4943e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles)// This interface is implemented by the client. It is supposed to be created 50323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)// on the main thread and then passed on to the worker thread. 51a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)// by a newly created WorkerGlobalScope. All methods of this class, except 5243e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles)// for createServiceWorkerNetworkProvider() and workerContextFailedToStart(), 5343e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles)// are called on the worker thread. 5409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)// FIXME: Split this into EmbeddedWorkerContextClient and 5509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)// ServiceWorkerScriptContextClient when we decide to use EmbeddedWorker 5609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)// framework for other implementation (like SharedWorker). 5751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)class WebServiceWorkerContextClient { 585267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)public: 59a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) virtual ~WebServiceWorkerContextClient() { } 60a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 61c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) // ServiceWorker specific method. 62c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) virtual WebServiceWorkerCacheStorage* cacheStorage() { return 0; } 63c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) 646f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch // ServiceWorker specific method. Called when script accesses the 656f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch // the |scope| attribute of the ServiceWorkerGlobalScope. Immutable per spec. 666f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch virtual WebURL scope() const { return WebURL(); } 676f543c786fc42989f552b4daa774ca5ff32fa697Ben Murdoch 6876c265b59aa821ccbf8c75ab2bb0d036e97d2956Torne (Richard Coles) // If the worker was started with WebEmbeddedWorkerStartData indicating to pause 6976c265b59aa821ccbf8c75ab2bb0d036e97d2956Torne (Richard Coles) // after download, this method is called after the main script resource has been 7076c265b59aa821ccbf8c75ab2bb0d036e97d2956Torne (Richard Coles) // downloaded. The scope will not be created and the script will not be loaded until 7176c265b59aa821ccbf8c75ab2bb0d036e97d2956Torne (Richard Coles) // WebEmbeddedWorker.resumeAfterDownload() is invoked. 7276c265b59aa821ccbf8c75ab2bb0d036e97d2956Torne (Richard Coles) virtual void didPauseAfterDownload() { } 7376c265b59aa821ccbf8c75ab2bb0d036e97d2956Torne (Richard Coles) 749e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles) // ServiceWorker has prepared everything for script loading and is now ready for inspection. 759e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles) virtual void workerReadyForInspection() { } 769e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles) 7751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) // A new WorkerGlobalScope is created and started to run on the 7851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) // worker thread. 7951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) // This also gives back a proxy to the client to talk to the 8051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) // newly created WorkerGlobalScope. The proxy is held by WorkerGlobalScope 8151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) // and should not be held by the caller. No proxy methods should be called 8210f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch // after willDestroyWorkerContext() is called. 8351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) virtual void workerContextStarted(WebServiceWorkerContextProxy*) { } 845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 8510f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch // WorkerGlobalScope is about to be destroyed. The client should clear 8610f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch // the WebServiceWorkerGlobalScopeProxy when this is called. 87f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu virtual void willDestroyWorkerContext() { } 885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 89323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles) // WorkerGlobalScope is destroyed and the worker is ready to be terminated. 90323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles) virtual void workerContextDestroyed() { } 91323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles) 92a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // Starting worker context is failed. This could happen when loading 93a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // worker script fails, or is asked to terminated before the context starts. 94a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // This is called on the main thread. 95a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) virtual void workerContextFailedToStart() { } 96a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) 9709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) // Called when the WorkerGlobalScope had an error or an exception. 9809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) virtual void reportException(const WebString& errorMessage, int lineNumber, int columnNumber, const WebString& sourceURL) { } 9909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 10010f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch // Called when the console message is reported. 10110f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch virtual void reportConsoleMessage(int source, int level, const WebString& message, int lineNumber, const WebString& sourceURL) { } 10210f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch 10309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) // Inspector related messages. 10451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) virtual void dispatchDevToolsMessage(const WebString&) { } 10551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) virtual void saveDevToolsAgentState(const WebString&) { } 10609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 10707a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch // ServiceWorker specific method. 108e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles) virtual void didHandleActivateEvent(int eventID, WebServiceWorkerEventResult result) { } 10907a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch 11009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) // ServiceWorker specific method. Called after InstallEvent (dispatched 11109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) // via WebServiceWorkerContextProxy) is handled by the ServiceWorker's 11209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) // script context. 113e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles) virtual void didHandleInstallEvent(int installEventID, WebServiceWorkerEventResult result) { } 114d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) 115d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) // ServiceWorker specific methods. Called after FetchEvent is handled by the 116d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) // ServiceWorker's script context. When no response is provided, the browser 117d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) // should fallback to native fetch. 118d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) virtual void didHandleFetchEvent(int fetchEventID) { } 119d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) virtual void didHandleFetchEvent(int fetchEventID, const WebServiceWorkerResponse& response) { } 12043e7502580f146aa5b3db8267ba6dbb5c733a489Torne (Richard Coles) 12107a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch // ServiceWorker specific method. Called after SyncEvent (dispatched via 12207a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch // WebServiceWorkerContextProxy) is handled by the ServiceWorker's script 12307a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch // context. 12407a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch virtual void didHandleSyncEvent(int syncEventID) { } 12510f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch 12610f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch // Ownership of the returned object is transferred to the caller. 127e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles) virtual WebServiceWorkerNetworkProvider* createServiceWorkerNetworkProvider(WebDataSource*) { return 0; } 12810f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch 12910f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch // Ownership of the passed callbacks is transferred to the callee, callee 13010f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch // should delete the callbacks after calling either onSuccess or onError. 13110f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch // WebServiceWorkerClientsInfo and WebServiceWorkerError ownerships are 13210f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch // passed to the WebServiceWorkerClientsCallbacks implementation. 13310f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch virtual void getClients(WebServiceWorkerClientsCallbacks*) { BLINK_ASSERT_NOT_REACHED(); } 134323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles) 135323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles) // Callee receives ownership of the passed vector. 136323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles) // FIXME: Blob refs should be passed to maintain ref counts. crbug.com/351753 137323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles) virtual void postMessageToClient(int clientID, const WebString&, WebMessagePortChannelArray*) { BLINK_ASSERT_NOT_REACHED(); } 1385267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)}; 1395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 14051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)} // namespace blink 1415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 142c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)#endif // WebServiceWorkerContextClient_h 143