OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef AcceptConnectionObserver_h | 5 #ifndef AcceptConnectionObserver_h |
6 #define AcceptConnectionObserver_h | 6 #define AcceptConnectionObserver_h |
7 | 7 |
8 #include "bindings/core/v8/ScriptPromiseResolver.h" | 8 #include "bindings/core/v8/ScriptPromiseResolver.h" |
9 #include "core/dom/ContextLifecycleObserver.h" | 9 #include "core/dom/ContextLifecycleObserver.h" |
10 #include "modules/ModulesExport.h" | 10 #include "modules/ModulesExport.h" |
11 #include "modules/navigatorconnect/ServicePortCollection.h" | 11 #include "modules/navigatorconnect/ServicePortCollection.h" |
12 #include "platform/heap/Handle.h" | 12 #include "platform/heap/Handle.h" |
13 #include "public/platform/modules/navigator_services/WebServicePort.h" | 13 #include "public/platform/modules/navigator_services/WebServicePort.h" |
14 | 14 |
15 namespace blink { | 15 namespace blink { |
16 | 16 |
17 class ExceptionState; | 17 class ExceptionState; |
18 class ExecutionContext; | 18 class ExecutionContext; |
19 class ScriptPromise; | 19 class ScriptPromise; |
20 class ScriptState; | 20 class ScriptState; |
21 class ScriptValue; | 21 class ScriptValue; |
22 | 22 |
23 // This class observes the service worker's handling of a CrossOriginConnectEven
t | 23 // This class observes the service worker's handling of a ServicePortConnectEven
t |
24 // and notified the client of the result. Created for each instance of | 24 // and notifies the client of the result. Created for each instance of |
25 // CrossOriginConnectEvent. | 25 // ServicePortConnectEvent. |
26 class MODULES_EXPORT AcceptConnectionObserver final : public GarbageCollectedFin
alized<AcceptConnectionObserver>, public ContextLifecycleObserver { | 26 class MODULES_EXPORT AcceptConnectionObserver final : public GarbageCollectedFin
alized<AcceptConnectionObserver>, public ContextLifecycleObserver { |
27 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(AcceptConnectionObserver); | 27 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(AcceptConnectionObserver); |
28 public: | 28 public: |
29 static AcceptConnectionObserver* create(ExecutionContext*, int eventID); | |
30 static AcceptConnectionObserver* create(ServicePortCollection*, PassOwnPtr<W
ebServicePortConnectEventCallbacks>, WebServicePortID, const KURL& targetURL); | 29 static AcceptConnectionObserver* create(ServicePortCollection*, PassOwnPtr<W
ebServicePortConnectEventCallbacks>, WebServicePortID, const KURL& targetURL); |
31 | 30 |
32 void contextDestroyed() override; | 31 void contextDestroyed() override; |
33 | 32 |
34 // Must be called after dispatching the event. Will cause the connection to | 33 // Must be called after dispatching the event. Will cause the connection to |
35 // be rejected if no call to acceptConnection or respondWith was made. | 34 // be rejected if no call to acceptConnection or respondWith was made. |
36 void didDispatchEvent(); | 35 void didDispatchEvent(); |
37 | 36 |
38 // Observes the promise and delays calling didHandleCrossOriginConnectEvent(
) | |
39 // until the given promise is resolved or rejected. | |
40 void acceptConnection(ScriptState*, ScriptPromise, ExceptionState&); | |
41 | |
42 // Observes the promise and delays calling didHandleServicePortConnectEvent(
) | 37 // Observes the promise and delays calling didHandleServicePortConnectEvent(
) |
43 // until the given promise is resolved or rejected. Returns a promise that | 38 // until the given promise is resolved or rejected. Returns a promise that |
44 // resolves to a ServicePort when the connection is accepted. | 39 // resolves to a ServicePort when the connection is accepted. |
45 ScriptPromise respondWith(ScriptState*, ScriptPromise, ExceptionState&); | 40 ScriptPromise respondWith(ScriptState*, ScriptPromise, ExceptionState&); |
46 | 41 |
47 void responseWasRejected(); | 42 void responseWasRejected(); |
48 void responseWasResolved(const ScriptValue&); | 43 void responseWasResolved(const ScriptValue&); |
49 | 44 |
50 DECLARE_VIRTUAL_TRACE(); | 45 DECLARE_VIRTUAL_TRACE(); |
51 | 46 |
52 private: | 47 private: |
53 class ThenFunction; | 48 class ThenFunction; |
54 | 49 |
55 AcceptConnectionObserver(ExecutionContext*, int eventID); | |
56 AcceptConnectionObserver(ServicePortCollection*, PassOwnPtr<WebServicePortCo
nnectEventCallbacks>, WebServicePortID, const KURL& targetURL); | 50 AcceptConnectionObserver(ServicePortCollection*, PassOwnPtr<WebServicePortCo
nnectEventCallbacks>, WebServicePortID, const KURL& targetURL); |
57 | 51 |
58 int m_eventID; | |
59 OwnPtr<WebServicePortConnectEventCallbacks> m_callbacks; | 52 OwnPtr<WebServicePortConnectEventCallbacks> m_callbacks; |
60 Member<ServicePortCollection> m_collection; | 53 Member<ServicePortCollection> m_collection; |
61 WebServicePortID m_portID; | 54 WebServicePortID m_portID; |
62 KURL m_targetURL; | 55 KURL m_targetURL; |
63 RefPtrWillBeMember<ScriptPromiseResolver> m_resolver; | 56 RefPtrWillBeMember<ScriptPromiseResolver> m_resolver; |
64 | 57 |
65 enum State { Initial, Pending, Done }; | 58 enum State { Initial, Pending, Done }; |
66 State m_state; | 59 State m_state; |
67 }; | 60 }; |
68 | 61 |
69 } // namespace blink | 62 } // namespace blink |
70 | 63 |
71 #endif // AcceptConnectionObserver_h | 64 #endif // AcceptConnectionObserver_h |
OLD | NEW |