| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef WebServiceWorkerContextClient_h | 31 #include "public/web/modules/serviceworker/WebServiceWorkerContextClient.h" |
| 32 #define WebServiceWorkerContextClient_h | |
| 33 | |
| 34 #include "public/platform/WebMessagePortChannel.h" | |
| 35 #include "public/platform/WebServiceWorkerClientsClaimCallbacks.h" | |
| 36 #include "public/platform/WebServiceWorkerClientsInfo.h" | |
| 37 #include "public/platform/WebServiceWorkerEventResult.h" | |
| 38 #include "public/platform/WebServiceWorkerSkipWaitingCallbacks.h" | |
| 39 #include "public/platform/WebURL.h" | |
| 40 | |
| 41 namespace blink { | |
| 42 | |
| 43 struct WebCrossOriginServiceWorkerClient; | |
| 44 struct WebServiceWorkerClientQueryOptions; | |
| 45 class WebDataSource; | |
| 46 class WebServiceWorkerContextProxy; | |
| 47 class WebServiceWorkerNetworkProvider; | |
| 48 class WebServiceWorkerProvider; | |
| 49 class WebServiceWorkerResponse; | |
| 50 class WebString; | |
| 51 | |
| 52 // This interface is implemented by the client. It is supposed to be created | |
| 53 // on the main thread and then passed on to the worker thread by a newly | |
| 54 // created WorkerGlobalScope. Unless otherwise noted, all methods of this class | |
| 55 // are called on the worker thread. | |
| 56 // | |
| 57 // FIXME: Split this into EmbeddedWorkerContextClient and | |
| 58 // ServiceWorkerScriptContextClient when we decide to use EmbeddedWorker | |
| 59 // framework for other implementation (like SharedWorker). | |
| 60 class WebServiceWorkerContextClient { | |
| 61 public: | |
| 62 virtual ~WebServiceWorkerContextClient() { } | |
| 63 | |
| 64 // ServiceWorker specific method. Called when script accesses the | |
| 65 // the |scope| attribute of the ServiceWorkerGlobalScope. Immutable per spec
. | |
| 66 virtual WebURL scope() const { return WebURL(); } | |
| 67 | |
| 68 // ServiceWorker has prepared everything for script loading and is now ready
for inspection. | |
| 69 virtual void workerReadyForInspection() { } | |
| 70 | |
| 71 // A new WorkerGlobalScope is created and started to run on the | |
| 72 // worker thread. | |
| 73 // This also gives back a proxy to the client to talk to the | |
| 74 // newly created WorkerGlobalScope. The proxy is held by WorkerGlobalScope | |
| 75 // and should not be held by the caller. No proxy methods should be called | |
| 76 // after willDestroyWorkerContext() is called. | |
| 77 virtual void workerContextStarted(WebServiceWorkerContextProxy*) { } | |
| 78 | |
| 79 // WorkerGlobalScope is about to be destroyed. The client should clear | |
| 80 // the WebServiceWorkerGlobalScopeProxy when this is called. | |
| 81 virtual void willDestroyWorkerContext() { } | |
| 82 | |
| 83 // WorkerGlobalScope is destroyed and the worker is ready to be terminated. | |
| 84 virtual void workerContextDestroyed() { } | |
| 85 | |
| 86 // Starting worker context is failed. This could happen when loading | |
| 87 // worker script fails, or is asked to terminated before the context starts. | |
| 88 // This is called on the main thread. | |
| 89 virtual void workerContextFailedToStart() { } | |
| 90 | |
| 91 // Called when the worker script is evaluated. |success| is true if the | |
| 92 // evaluation completed with no uncaught exception. | |
| 93 virtual void didEvaluateWorkerScript(bool success) { } | |
| 94 | |
| 95 // Called when the WorkerGlobalScope had an error or an exception. | |
| 96 virtual void reportException(const WebString& errorMessage, int lineNumber,
int columnNumber, const WebString& sourceURL) { } | |
| 97 | |
| 98 // Called when the console message is reported. | |
| 99 virtual void reportConsoleMessage(int source, int level, const WebString& me
ssage, int lineNumber, const WebString& sourceURL) { } | |
| 100 | |
| 101 // Inspector related messages. | |
| 102 virtual void sendDevToolsMessage(int callId, const WebString& message, const
WebString& state) { } | |
| 103 | |
| 104 // ServiceWorker specific method. | |
| 105 virtual void didHandleActivateEvent(int eventID, WebServiceWorkerEventResult
result) { } | |
| 106 | |
| 107 // ServiceWorker specific methods. Called after FetchEvent is handled by the | |
| 108 // ServiceWorker's script context. When no response is provided, the browser | |
| 109 // should fallback to native fetch. | |
| 110 virtual void didHandleFetchEvent(int fetchEventID) { } | |
| 111 virtual void didHandleFetchEvent(int fetchEventID, const WebServiceWorkerRes
ponse& response) { } | |
| 112 | |
| 113 // ServiceWorker specific method. Called after InstallEvent (dispatched | |
| 114 // via WebServiceWorkerContextProxy) is handled by the ServiceWorker's | |
| 115 // script context. | |
| 116 virtual void didHandleInstallEvent(int installEventID, WebServiceWorkerEvent
Result result) { } | |
| 117 | |
| 118 // ServiceWorker specific method. Called after NotificationClickEvent | |
| 119 // (dispatched via WebServiceWorkerContextProxy) is handled by the | |
| 120 // ServiceWorker's script context. | |
| 121 virtual void didHandleNotificationClickEvent(int eventID, WebServiceWorkerEv
entResult result) { } | |
| 122 | |
| 123 // ServiceWorker specific method. Called after PushEvent (dispatched via | |
| 124 // WebServiceWorkerContextProxy) is handled by the ServiceWorker's script | |
| 125 // context. | |
| 126 virtual void didHandlePushEvent(int pushEventID, WebServiceWorkerEventResult
result) { } | |
| 127 | |
| 128 // ServiceWorker specific method. Called after SyncEvent (dispatched via | |
| 129 // WebServiceWorkerContextProxy) is handled by the ServiceWorker's script | |
| 130 // context. | |
| 131 virtual void didHandleSyncEvent(int syncEventID, WebServiceWorkerEventResult
result) { } | |
| 132 | |
| 133 // Ownership of the returned object is transferred to the caller. | |
| 134 // This is called on the main thread. | |
| 135 virtual WebServiceWorkerNetworkProvider* createServiceWorkerNetworkProvider(
WebDataSource*) { return nullptr; } | |
| 136 | |
| 137 // Ownership of the returned object is transferred to the caller. | |
| 138 // This is called on the main thread. | |
| 139 virtual WebServiceWorkerProvider* createServiceWorkerProvider() { return nul
lptr; } | |
| 140 | |
| 141 // Ownership of the passed callbacks is transferred to the callee, callee | |
| 142 // should delete the callbacks after calling either onSuccess or onError. | |
| 143 // WebServiceWorkerClientsInfo and WebServiceWorkerError ownerships are | |
| 144 // passed to the WebServiceWorkerClientsCallbacks implementation. | |
| 145 virtual void getClients(const WebServiceWorkerClientQueryOptions&, WebServic
eWorkerClientsCallbacks* callbacks) { BLINK_ASSERT_NOT_REACHED(); } | |
| 146 | |
| 147 // Ownership of the passed callbacks is transferred to the callee, callee | |
| 148 // should delete the callbacks after calling either onSuccess or onError. | |
| 149 // WebServiceWorkerClientInfo and WebServiceWorkerError ownerships are | |
| 150 // passed to the WebServiceWorkerClientsCallbacks implementation. | |
| 151 virtual void openWindow(const WebURL& url, WebServiceWorkerClientCallbacks*)
{ BLINK_ASSERT_NOT_REACHED(); } | |
| 152 | |
| 153 // A suggestion to cache this metadata in association with this URL. | |
| 154 virtual void setCachedMetadata(const WebURL& url, const char* data, size_t s
ize) { } | |
| 155 | |
| 156 // A suggestion to clear the cached metadata in association with this URL. | |
| 157 virtual void clearCachedMetadata(const WebURL& url) { } | |
| 158 | |
| 159 // Callee receives ownership of the passed vector. | |
| 160 // FIXME: Blob refs should be passed to maintain ref counts. crbug.com/35175
3 | |
| 161 virtual void postMessageToClient(const WebString& uuid, const WebString&, We
bMessagePortChannelArray*) { BLINK_ASSERT_NOT_REACHED(); } | |
| 162 | |
| 163 // Callee receives ownership of the passed vector. | |
| 164 // FIXME: Blob refs should be passed to maintain ref counts. crbug.com/35175
3 | |
| 165 virtual void postMessageToCrossOriginClient(const WebCrossOriginServiceWorke
rClient&, const WebString&, WebMessagePortChannelArray*) { BLINK_ASSERT_NOT_REAC
HED(); } | |
| 166 | |
| 167 // Ownership of the passed callbacks is transferred to the callee, callee | |
| 168 // should delete the callbacks after run. | |
| 169 virtual void skipWaiting(WebServiceWorkerSkipWaitingCallbacks*) { BLINK_ASSE
RT_NOT_REACHED(); } | |
| 170 | |
| 171 // Ownership of the passed callbacks is transferred to the callee, callee | |
| 172 // should delete the callbacks after run. | |
| 173 virtual void claim(WebServiceWorkerClientsClaimCallbacks*) { BLINK_ASSERT_NO
T_REACHED(); } | |
| 174 | |
| 175 // Ownership of the passed callbacks is transferred to the callee, callee | |
| 176 // should delete the callback after calling either onSuccess or onError. | |
| 177 virtual void focus(const WebString& uuid, WebServiceWorkerClientCallbacks*)
{ BLINK_ASSERT_NOT_REACHED(); } | |
| 178 | |
| 179 // Ownership of the passed callbacks is transferred to the callee, callee | |
| 180 // should delete the callbacks after calling either onSuccess or onError. | |
| 181 // WebServiceWorkerClientInfo and WebServiceWorkerError ownerships are | |
| 182 // passed to the WebServiceWorkerClientsCallbacks implementation. | |
| 183 virtual void navigate(const WebString& uuid, const WebURL&, WebServiceWorker
ClientCallbacks*) { BLINK_ASSERT_NOT_REACHED(); } | |
| 184 }; | |
| 185 | |
| 186 } // namespace blink | |
| 187 | |
| 188 #endif // WebServiceWorkerContextClient_h | |
| OLD | NEW |