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 "modules/ModulesExport.h" | 9 #include "modules/ModulesExport.h" |
10 #include "platform/heap/Handle.h" | 10 #include "platform/heap/Handle.h" |
11 #include "public/platform/WebServiceWorkerResponseError.h" | 11 #include "public/platform/WebServiceWorkerResponseError.h" |
12 #include "public/platform/WebURLRequest.h" | 12 #include "public/platform/WebURLRequest.h" |
13 | 13 |
14 namespace blink { | 14 namespace blink { |
15 | 15 |
16 class ExceptionState; | 16 class ExceptionState; |
17 class ExecutionContext; | 17 class ExecutionContext; |
| 18 class ScriptPromise; |
18 class ScriptState; | 19 class ScriptState; |
19 class ScriptValue; | 20 class ScriptValue; |
20 | 21 |
21 // This class observes the service worker's handling of a FetchEvent and | 22 // This class observes the service worker's handling of a FetchEvent and |
22 // notifies the client. | 23 // notifies the client. |
23 class MODULES_EXPORT RespondWithObserver final : public GarbageCollectedFinalize
d<RespondWithObserver>, public ContextLifecycleObserver { | 24 class MODULES_EXPORT RespondWithObserver final : public GarbageCollectedFinalize
d<RespondWithObserver>, public ContextLifecycleObserver { |
24 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(RespondWithObserver); | 25 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(RespondWithObserver); |
25 public: | 26 public: |
26 static RespondWithObserver* create(ExecutionContext*, int eventID, const KUR
L& requestURL, WebURLRequest::FetchRequestMode, WebURLRequest::FrameType); | 27 static RespondWithObserver* create(ExecutionContext*, int eventID, const KUR
L& requestURL, WebURLRequest::FetchRequestMode, WebURLRequest::FrameType); |
27 | 28 |
28 void contextDestroyed() override; | 29 void contextDestroyed() override; |
29 | 30 |
30 void didDispatchEvent(bool defaultPrevented); | 31 void didDispatchEvent(bool defaultPrevented); |
31 | 32 |
32 // Observes the promise and delays calling didHandleFetchEvent() until the | 33 // Observes the promise and delays calling didHandleFetchEvent() until the |
33 // given promise is resolved or rejected. | 34 // given promise is resolved or rejected. |
34 void respondWith(ScriptState*, const ScriptValue&, ExceptionState&); | 35 void respondWith(ScriptState*, ScriptPromise&, ExceptionState&); |
35 | 36 |
36 void responseWasRejected(WebServiceWorkerResponseError); | 37 void responseWasRejected(WebServiceWorkerResponseError); |
37 void responseWasFulfilled(const ScriptValue&); | 38 void responseWasFulfilled(const ScriptValue&); |
38 | 39 |
39 DECLARE_VIRTUAL_TRACE(); | 40 DECLARE_VIRTUAL_TRACE(); |
40 | 41 |
41 private: | 42 private: |
42 class ThenFunction; | 43 class ThenFunction; |
43 | 44 |
44 RespondWithObserver(ExecutionContext*, int eventID, const KURL& requestURL,
WebURLRequest::FetchRequestMode, WebURLRequest::FrameType); | 45 RespondWithObserver(ExecutionContext*, int eventID, const KURL& requestURL,
WebURLRequest::FetchRequestMode, WebURLRequest::FrameType); |
45 | 46 |
46 int m_eventID; | 47 int m_eventID; |
47 KURL m_requestURL; | 48 KURL m_requestURL; |
48 WebURLRequest::FetchRequestMode m_requestMode; | 49 WebURLRequest::FetchRequestMode m_requestMode; |
49 WebURLRequest::FrameType m_frameType; | 50 WebURLRequest::FrameType m_frameType; |
50 | 51 |
51 enum State { Initial, Pending, Done }; | 52 enum State { Initial, Pending, Done }; |
52 State m_state; | 53 State m_state; |
53 }; | 54 }; |
54 | 55 |
55 } // namespace blink | 56 } // namespace blink |
56 | 57 |
57 #endif // RespondWithObserver_h | 58 #endif // RespondWithObserver_h |
OLD | NEW |