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