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
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
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 ServiceWorkerGlobalScopeProxy_h
32 #define ServiceWorkerGlobalScopeProxy_h
34 #include "core/workers/WorkerReportingProxy.h"
35 #include "platform/heap/Handle.h"
36 #include "platform/weborigin/KURL.h"
37 #include "public/platform/WebString.h"
38 #include "public/web/WebServiceWorkerContextProxy.h"
39 #include "wtf/Forward.h"
40 #include "wtf/OwnPtr.h"
46 class ServiceWorkerGlobalScope
;
47 class WebEmbeddedWorkerImpl
;
48 class WebServiceWorkerContextClient
;
49 class WebServiceWorkerRequest
;
50 struct WebSyncRegistration
;
52 // This class is created and destructed on the main thread, but live most
53 // of its time as a resident of the worker thread.
54 // All methods other than its ctor/dtor are called on the worker thread.
56 // This implements WebServiceWorkerContextProxy, which connects ServiceWorker's
57 // WorkerGlobalScope and embedder/chrome, and implements ServiceWorker-specific
58 // events/upcall methods that are to be called by embedder/chromium,
61 // An instance of this class is supposed to outlive until
62 // workerThreadTerminated() is called by its corresponding
64 class ServiceWorkerGlobalScopeProxy final
65 : public WebServiceWorkerContextProxy
66 , public WorkerReportingProxy
{
67 WTF_MAKE_NONCOPYABLE(ServiceWorkerGlobalScopeProxy
);
68 WTF_MAKE_FAST_ALLOCATED(ServiceWorkerGlobalScopeProxy
);
70 static PassOwnPtr
<ServiceWorkerGlobalScopeProxy
> create(WebEmbeddedWorkerImpl
&, Document
&, WebServiceWorkerContextClient
&);
71 ~ServiceWorkerGlobalScopeProxy() override
;
73 // WebServiceWorkerContextProxy overrides:
74 void setRegistration(WebPassOwnPtr
<WebServiceWorkerRegistration::Handle
>) override
;
75 void dispatchActivateEvent(int) override
;
76 void dispatchCrossOriginMessageEvent(const WebCrossOriginServiceWorkerClient
&, const WebString
& message
, const WebMessagePortChannelArray
&) override
;
77 void dispatchFetchEvent(int, const WebServiceWorkerRequest
&) override
;
78 void dispatchGeofencingEvent(int, WebGeofencingEventType
, const WebString
& regionID
, const WebCircularGeofencingRegion
&) override
;
79 void dispatchInstallEvent(int) override
;
80 void dispatchMessageEvent(const WebString
& message
, const WebMessagePortChannelArray
&) override
;
81 void dispatchNotificationClickEvent(int, int64_t notificationID
, const WebNotificationData
&, int actionIndex
) override
;
82 void dispatchPushEvent(int, const WebString
& data
) override
;
83 void dispatchServicePortConnectEvent(WebServicePortConnectEventCallbacks
*, const WebURL
& targetURL
, const WebString
& origin
, WebServicePortID
) override
;
84 void dispatchSyncEvent(int, const WebSyncRegistration
&) override
;
86 // WorkerReportingProxy overrides:
87 void reportException(const String
& errorMessage
, int lineNumber
, int columnNumber
, const String
& sourceURL
, int exceptionId
) override
;
88 void reportConsoleMessage(PassRefPtrWillBeRawPtr
<ConsoleMessage
>) override
;
89 void postMessageToPageInspector(const String
&) override
;
90 void postWorkerConsoleAgentEnabled() override
{ }
91 void didEvaluateWorkerScript(bool success
) override
;
92 void didInitializeWorkerContext() override
;
93 void workerGlobalScopeStarted(WorkerGlobalScope
*) override
;
94 void workerGlobalScopeClosed() override
;
95 void willDestroyWorkerGlobalScope() override
;
96 void workerThreadTerminated() override
;
99 ServiceWorkerGlobalScopeProxy(WebEmbeddedWorkerImpl
&, Document
&, WebServiceWorkerContextClient
&);
101 WebEmbeddedWorkerImpl
& m_embeddedWorker
;
102 Document
& m_document
;
105 WebServiceWorkerContextClient
& m_client
;
107 ServiceWorkerGlobalScope
* m_workerGlobalScope
;
112 #endif // ServiceWorkerGlobalScopeProxy_h