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" |
11 #include "platform/heap/Handle.h" | 11 #include "platform/heap/Handle.h" |
12 #include "public/platform/WebURLRequest.h" | 12 #include "public/platform/WebURLRequest.h" |
13 #include "public/platform/modules/serviceworker/WebServiceWorkerResponseError.h" | 13 #include "public/platform/modules/serviceworker/WebServiceWorkerResponseError.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 FetchEvent and | 23 // This class observes the service worker's handling of a FetchEvent and |
24 // notifies the client. | 24 // notifies the client. |
25 class MODULES_EXPORT RespondWithObserver final : public GarbageCollectedFinalize
d<RespondWithObserver>, public ContextLifecycleObserver { | 25 class MODULES_EXPORT RespondWithObserver : public GarbageCollectedFinalized<Resp
ondWithObserver>, public ContextLifecycleObserver { |
26 USING_GARBAGE_COLLECTED_MIXIN(RespondWithObserver); | 26 USING_GARBAGE_COLLECTED_MIXIN(RespondWithObserver); |
27 public: | 27 public: |
| 28 virtual ~RespondWithObserver(); |
| 29 |
28 static RespondWithObserver* create(ExecutionContext*, int eventID, const KUR
L& requestURL, WebURLRequest::FetchRequestMode, WebURLRequest::FrameType, WebURL
Request::RequestContext); | 30 static RespondWithObserver* create(ExecutionContext*, int eventID, const KUR
L& requestURL, WebURLRequest::FetchRequestMode, WebURLRequest::FrameType, WebURL
Request::RequestContext); |
29 | 31 |
30 void contextDestroyed() override; | 32 void contextDestroyed() override; |
31 | 33 |
32 void didDispatchEvent(DispatchEventResult dispatchResult); | 34 void didDispatchEvent(DispatchEventResult dispatchResult); |
33 | 35 |
34 // Observes the promise and delays calling didHandleFetchEvent() until the | 36 // Observes the promise and delays calling didHandleFetchEvent() until the |
35 // given promise is resolved or rejected. | 37 // given promise is resolved or rejected. |
36 void respondWith(ScriptState*, ScriptPromise, ExceptionState&); | 38 void respondWith(ScriptState*, ScriptPromise, ExceptionState&); |
37 | 39 |
38 void responseWasRejected(WebServiceWorkerResponseError); | 40 void responseWasRejected(WebServiceWorkerResponseError); |
39 void responseWasFulfilled(const ScriptValue&); | 41 virtual void responseWasFulfilled(const ScriptValue&); |
40 | 42 |
41 DECLARE_VIRTUAL_TRACE(); | 43 DECLARE_VIRTUAL_TRACE(); |
42 | 44 |
| 45 protected: |
| 46 RespondWithObserver(ExecutionContext*, int eventID, const KURL& requestURL,
WebURLRequest::FetchRequestMode, WebURLRequest::FrameType, WebURLRequest::Reques
tContext); |
| 47 |
43 private: | 48 private: |
44 class ThenFunction; | 49 class ThenFunction; |
45 | 50 |
46 RespondWithObserver(ExecutionContext*, int eventID, const KURL& requestURL,
WebURLRequest::FetchRequestMode, WebURLRequest::FrameType, WebURLRequest::Reques
tContext); | |
47 | |
48 int m_eventID; | 51 int m_eventID; |
49 KURL m_requestURL; | 52 KURL m_requestURL; |
50 WebURLRequest::FetchRequestMode m_requestMode; | 53 WebURLRequest::FetchRequestMode m_requestMode; |
51 WebURLRequest::FrameType m_frameType; | 54 WebURLRequest::FrameType m_frameType; |
52 WebURLRequest::RequestContext m_requestContext; | 55 WebURLRequest::RequestContext m_requestContext; |
53 | 56 |
54 enum State { Initial, Pending, Done }; | 57 enum State { Initial, Pending, Done }; |
55 State m_state; | 58 State m_state; |
56 }; | 59 }; |
57 | 60 |
58 } // namespace blink | 61 } // namespace blink |
59 | 62 |
60 #endif // RespondWithObserver_h | 63 #endif // RespondWithObserver_h |
OLD | NEW |