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 RespondWithObserver_h | 5 #ifndef RespondWithObserver_h |
6 #define RespondWithObserver_h | 6 #define RespondWithObserver_h |
7 | 7 |
8 #include "core/dom/ContextLifecycleObserver.h" | 8 #include "core/dom/ContextLifecycleObserver.h" |
9 #include "core/events/EventTarget.h" | 9 #include "core/events/EventTarget.h" |
10 #include "modules/ModulesExport.h" | 10 #include "modules/ModulesExport.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 // notifies the client. | 25 // notifies the client. |
26 class MODULES_EXPORT RespondWithObserver : public GarbageCollectedFinalized<Resp
ondWithObserver>, public ContextLifecycleObserver { | 26 class MODULES_EXPORT RespondWithObserver : public GarbageCollectedFinalized<Resp
ondWithObserver>, public ContextLifecycleObserver { |
27 USING_GARBAGE_COLLECTED_MIXIN(RespondWithObserver); | 27 USING_GARBAGE_COLLECTED_MIXIN(RespondWithObserver); |
28 public: | 28 public: |
29 virtual ~RespondWithObserver(); | 29 virtual ~RespondWithObserver(); |
30 | 30 |
31 static RespondWithObserver* create(ExecutionContext*, int eventID, const KUR
L& requestURL, WebURLRequest::FetchRequestMode, WebURLRequest::FrameType, WebURL
Request::RequestContext, WaitUntilObserver*); | 31 static RespondWithObserver* create(ExecutionContext*, int eventID, const KUR
L& requestURL, WebURLRequest::FetchRequestMode, WebURLRequest::FrameType, WebURL
Request::RequestContext, WaitUntilObserver*); |
32 | 32 |
33 void contextDestroyed() override; | 33 void contextDestroyed() override; |
34 | 34 |
| 35 void willDispatchEvent(); |
35 void didDispatchEvent(DispatchEventResult dispatchResult); | 36 void didDispatchEvent(DispatchEventResult dispatchResult); |
36 | 37 |
37 // Observes the promise and delays calling didHandleFetchEvent() until the | 38 // Observes the promise and delays calling didHandleFetchEvent() until the |
38 // given promise is resolved or rejected. | 39 // given promise is resolved or rejected. |
39 void respondWith(ScriptState*, ScriptPromise, ExceptionState&); | 40 void respondWith(ScriptState*, ScriptPromise, ExceptionState&); |
40 | 41 |
41 void responseWasRejected(WebServiceWorkerResponseError); | 42 void responseWasRejected(WebServiceWorkerResponseError); |
42 virtual void responseWasFulfilled(const ScriptValue&); | 43 virtual void responseWasFulfilled(const ScriptValue&); |
43 | 44 |
44 DECLARE_VIRTUAL_TRACE(); | 45 DECLARE_VIRTUAL_TRACE(); |
45 | 46 |
46 protected: | 47 protected: |
47 RespondWithObserver(ExecutionContext*, int eventID, const KURL& requestURL,
WebURLRequest::FetchRequestMode, WebURLRequest::FrameType, WebURLRequest::Reques
tContext, WaitUntilObserver*); | 48 RespondWithObserver(ExecutionContext*, int eventID, const KURL& requestURL,
WebURLRequest::FetchRequestMode, WebURLRequest::FrameType, WebURLRequest::Reques
tContext, WaitUntilObserver*); |
48 | 49 |
49 private: | 50 private: |
50 class ThenFunction; | 51 class ThenFunction; |
51 | 52 |
52 int m_eventID; | 53 int m_eventID; |
53 KURL m_requestURL; | 54 KURL m_requestURL; |
54 WebURLRequest::FetchRequestMode m_requestMode; | 55 WebURLRequest::FetchRequestMode m_requestMode; |
55 WebURLRequest::FrameType m_frameType; | 56 WebURLRequest::FrameType m_frameType; |
56 WebURLRequest::RequestContext m_requestContext; | 57 WebURLRequest::RequestContext m_requestContext; |
57 | 58 |
| 59 double m_eventDispatchTime = 0; |
| 60 |
58 enum State { Initial, Pending, Done }; | 61 enum State { Initial, Pending, Done }; |
59 State m_state; | 62 State m_state; |
60 | 63 |
61 // RespondWith should ensure the ExtendableEvent is alive until the promise | 64 // RespondWith should ensure the ExtendableEvent is alive until the promise |
62 // passed to RespondWith is resolved. The lifecycle of the ExtendableEvent | 65 // passed to RespondWith is resolved. The lifecycle of the ExtendableEvent |
63 // is controlled by WaitUntilObserver, so not only | 66 // is controlled by WaitUntilObserver, so not only |
64 // WaitUntilObserver::ThenFunction but RespondWith needs to have a strong | 67 // WaitUntilObserver::ThenFunction but RespondWith needs to have a strong |
65 // reference to the WaitUntilObserver. | 68 // reference to the WaitUntilObserver. |
66 Member<WaitUntilObserver> m_observer; | 69 Member<WaitUntilObserver> m_observer; |
67 }; | 70 }; |
68 | 71 |
69 } // namespace blink | 72 } // namespace blink |
70 | 73 |
71 #endif // RespondWithObserver_h | 74 #endif // RespondWithObserver_h |
OLD | NEW |