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