Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / public / web / modules / serviceworker / WebServiceWorkerContextClient.h
blob9e0483c4a270ca25b15bb875174e71ed473b2130
1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
31 #ifndef WebServiceWorkerContextClient_h
32 #define WebServiceWorkerContextClient_h
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 #include <v8.h>
42 namespace blink {
44 struct WebCrossOriginServiceWorkerClient;
45 struct WebServiceWorkerClientQueryOptions;
46 class WebDataSource;
47 class WebServiceWorkerContextProxy;
48 class WebServiceWorkerNetworkProvider;
49 class WebServiceWorkerProvider;
50 class WebServiceWorkerResponse;
51 class WebString;
53 // This interface is implemented by the client. It is supposed to be created
54 // on the main thread and then passed on to the worker thread by a newly
55 // created WorkerGlobalScope. Unless otherwise noted, all methods of this class
56 // are called on the worker thread.
57 class WebServiceWorkerContextClient {
58 public:
59 virtual ~WebServiceWorkerContextClient() { }
61 // ServiceWorker specific method. Called when script accesses the
62 // the |scope| attribute of the ServiceWorkerGlobalScope. Immutable per spec.
63 virtual WebURL scope() const { return WebURL(); }
65 // ServiceWorker has prepared everything for script loading and is now ready for inspection.
66 virtual void workerReadyForInspection() { }
68 // The worker script is successfully loaded and a new thread is about to
69 // be started. Called on the main thread.
70 virtual void workerScriptLoaded() { }
72 // A new WorkerGlobalScope is created and started to run on the
73 // worker thread.
74 // This also gives back a proxy to the client to talk to the
75 // newly created WorkerGlobalScope. The proxy is held by WorkerGlobalScope
76 // and should not be held by the caller. No proxy methods should be called
77 // after willDestroyWorkerContext() is called.
78 virtual void workerContextStarted(WebServiceWorkerContextProxy*) { }
80 // WorkerGlobalScope is about to be destroyed. The client should clear
81 // the WebServiceWorkerGlobalScopeProxy when this is called.
82 virtual void willDestroyWorkerContext(v8::Local<v8::Context> context) { }
84 // WorkerGlobalScope is destroyed and the worker is ready to be terminated.
85 virtual void workerContextDestroyed() { }
87 // Starting worker context is failed. This could happen when loading
88 // worker script fails, or is asked to terminated before the context starts.
89 // This is called on the main thread.
90 virtual void workerContextFailedToStart() { }
92 // Called when the worker script is evaluated. |success| is true if the
93 // evaluation completed with no uncaught exception.
94 virtual void didEvaluateWorkerScript(bool success) { }
96 // Called when the worker context is initialized.
97 virtual void didInitializeWorkerContext(v8::Local<v8::Context> context, const blink::WebURL& url) { }
99 // Called when the WorkerGlobalScope had an error or an exception.
100 virtual void reportException(const WebString& errorMessage, int lineNumber, int columnNumber, const WebString& sourceURL) { }
102 // Called when the console message is reported.
103 virtual void reportConsoleMessage(int source, int level, const WebString& message, int lineNumber, const WebString& sourceURL) { }
105 // Inspector related messages.
106 virtual void sendDevToolsMessage(int callId, const WebString& message, const WebString& state) { }
108 // ServiceWorker specific method.
109 virtual void didHandleActivateEvent(int eventID, WebServiceWorkerEventResult result) { }
111 // ServiceWorker specific methods. Called after FetchEvent is handled by the
112 // ServiceWorker's script context. When no response is provided, the browser
113 // should fallback to native fetch.
114 virtual void didHandleFetchEvent(int fetchEventID) { }
115 virtual void didHandleFetchEvent(int fetchEventID, const WebServiceWorkerResponse& response) { }
117 // ServiceWorker specific method. Called after InstallEvent (dispatched
118 // via WebServiceWorkerContextProxy) is handled by the ServiceWorker's
119 // script context.
120 virtual void didHandleInstallEvent(int installEventID, WebServiceWorkerEventResult result) { }
122 // ServiceWorker specific method. Called after NotificationClickEvent
123 // (dispatched via WebServiceWorkerContextProxy) is handled by the
124 // ServiceWorker's script context.
125 virtual void didHandleNotificationClickEvent(int eventID, WebServiceWorkerEventResult result) { }
127 // ServiceWorker specific method. Called after PushEvent (dispatched via
128 // WebServiceWorkerContextProxy) is handled by the ServiceWorker's script
129 // context.
130 virtual void didHandlePushEvent(int pushEventID, WebServiceWorkerEventResult result) { }
132 // ServiceWorker specific method. Called after SyncEvent (dispatched via
133 // WebServiceWorkerContextProxy) is handled by the ServiceWorker's script
134 // context.
135 virtual void didHandleSyncEvent(int syncEventID, WebServiceWorkerEventResult result) { }
137 // Ownership of the returned object is transferred to the caller.
138 // This is called on the main thread.
139 virtual WebServiceWorkerNetworkProvider* createServiceWorkerNetworkProvider(WebDataSource*) { return nullptr; }
141 // Ownership of the returned object is transferred to the caller.
142 // This is called on the main thread.
143 virtual WebServiceWorkerProvider* createServiceWorkerProvider() { return nullptr; }
145 // Ownership of the passed callbacks is transferred to the callee, callee
146 // should delete the callbacks after calling either onSuccess or onError.
147 // WebServiceWorkerClientsInfo and WebServiceWorkerError ownerships are
148 // passed to the WebServiceWorkerClientsCallbacks implementation.
149 virtual void getClients(const WebServiceWorkerClientQueryOptions&, WebServiceWorkerClientsCallbacks* callbacks) { BLINK_ASSERT_NOT_REACHED(); }
151 // Ownership of the passed callbacks is transferred to the callee, callee
152 // should delete the callbacks after calling either onSuccess or onError.
153 // WebServiceWorkerClientInfo and WebServiceWorkerError ownerships are
154 // passed to the WebServiceWorkerClientsCallbacks implementation.
155 virtual void openWindow(const WebURL& url, WebServiceWorkerClientCallbacks*) { BLINK_ASSERT_NOT_REACHED(); }
157 // A suggestion to cache this metadata in association with this URL.
158 virtual void setCachedMetadata(const WebURL& url, const char* data, size_t size) { }
160 // A suggestion to clear the cached metadata in association with this URL.
161 virtual void clearCachedMetadata(const WebURL& url) { }
163 // Callee receives ownership of the passed vector.
164 // FIXME: Blob refs should be passed to maintain ref counts. crbug.com/351753
165 virtual void postMessageToClient(const WebString& uuid, const WebString&, WebMessagePortChannelArray*) { BLINK_ASSERT_NOT_REACHED(); }
167 // Callee receives ownership of the passed vector.
168 // FIXME: Blob refs should be passed to maintain ref counts. crbug.com/351753
169 virtual void postMessageToCrossOriginClient(const WebCrossOriginServiceWorkerClient&, const WebString&, WebMessagePortChannelArray*) { BLINK_ASSERT_NOT_REACHED(); }
171 // Ownership of the passed callbacks is transferred to the callee, callee
172 // should delete the callbacks after run.
173 virtual void skipWaiting(WebServiceWorkerSkipWaitingCallbacks*) { BLINK_ASSERT_NOT_REACHED(); }
175 // Ownership of the passed callbacks is transferred to the callee, callee
176 // should delete the callbacks after run.
177 virtual void claim(WebServiceWorkerClientsClaimCallbacks*) { BLINK_ASSERT_NOT_REACHED(); }
179 // Ownership of the passed callbacks is transferred to the callee, callee
180 // should delete the callback after calling either onSuccess or onError.
181 virtual void focus(const WebString& uuid, WebServiceWorkerClientCallbacks*) { BLINK_ASSERT_NOT_REACHED(); }
183 // Ownership of the passed callbacks is transferred to the callee, callee
184 // should delete the callbacks after calling either onSuccess or onError.
185 // WebServiceWorkerClientInfo and WebServiceWorkerError ownerships are
186 // passed to the WebServiceWorkerClientsCallbacks implementation.
187 virtual void navigate(const WebString& uuid, const WebURL&, WebServiceWorkerClientCallbacks*) { BLINK_ASSERT_NOT_REACHED(); }
190 } // namespace blink
192 #endif // WebServiceWorkerContextClient_h