Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(281)

Side by Side Diff: third_party/WebKit/Source/modules/serviceworkers/FetchEvent.h

Issue 2922863002: Keep the wrapper of FetchEvent alive while waiting for the preload response. (Closed)
Patch Set: incorporated yhirano's comment Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 FetchEvent_h 5 #ifndef FetchEvent_h
6 #define FetchEvent_h 6 #define FetchEvent_h
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "bindings/core/v8/ScriptPromise.h" 10 #include "bindings/core/v8/ScriptPromise.h"
11 #include "bindings/core/v8/ScriptPromiseProperty.h" 11 #include "bindings/core/v8/ScriptPromiseProperty.h"
12 #include "core/dom/ContextLifecycleObserver.h"
12 #include "modules/EventModules.h" 13 #include "modules/EventModules.h"
13 #include "modules/ModulesExport.h" 14 #include "modules/ModulesExport.h"
14 #include "modules/fetch/Request.h" 15 #include "modules/fetch/Request.h"
15 #include "modules/serviceworkers/ExtendableEvent.h" 16 #include "modules/serviceworkers/ExtendableEvent.h"
16 #include "modules/serviceworkers/FetchEventInit.h" 17 #include "modules/serviceworkers/FetchEventInit.h"
17 #include "modules/serviceworkers/WaitUntilObserver.h" 18 #include "modules/serviceworkers/WaitUntilObserver.h"
19 #include "platform/bindings/ActiveScriptWrappable.h"
18 #include "platform/heap/Handle.h" 20 #include "platform/heap/Handle.h"
19 #include "platform/loader/fetch/ResourceResponse.h" 21 #include "platform/loader/fetch/ResourceResponse.h"
20 22
21 namespace blink { 23 namespace blink {
22 24
23 class ExceptionState; 25 class ExceptionState;
24 class FetchRespondWithObserver; 26 class FetchRespondWithObserver;
25 class Request; 27 class Request;
26 class Response; 28 class Response;
27 class ScriptState; 29 class ScriptState;
28 class WebDataConsumerHandle; 30 class WebDataConsumerHandle;
29 struct WebServiceWorkerError; 31 struct WebServiceWorkerError;
30 class WebURLResponse; 32 class WebURLResponse;
31 class WorkerGlobalScope; 33 class WorkerGlobalScope;
32 34
33 // A fetch event is dispatched by the client to a service worker's script 35 // A fetch event is dispatched by the client to a service worker's script
34 // context. FetchRespondWithObserver can be used to notify the client about the 36 // context. FetchRespondWithObserver can be used to notify the client about the
35 // service worker's response. 37 // service worker's response.
36 class MODULES_EXPORT FetchEvent final : public ExtendableEvent { 38 class MODULES_EXPORT FetchEvent final
39 : public ExtendableEvent,
40 public ActiveScriptWrappable<FetchEvent>,
41 public ContextClient {
37 DEFINE_WRAPPERTYPEINFO(); 42 DEFINE_WRAPPERTYPEINFO();
43 USING_GARBAGE_COLLECTED_MIXIN(FetchEvent);
38 44
39 public: 45 public:
40 using PreloadResponseProperty = ScriptPromiseProperty<Member<FetchEvent>, 46 using PreloadResponseProperty = ScriptPromiseProperty<Member<FetchEvent>,
41 Member<Response>, 47 Member<Response>,
42 Member<DOMException>>; 48 Member<DOMException>>;
43 static FetchEvent* Create(ScriptState*, 49 static FetchEvent* Create(ScriptState*,
44 const AtomicString& type, 50 const AtomicString& type,
45 const FetchEventInit&); 51 const FetchEventInit&);
46 static FetchEvent* Create(ScriptState*, 52 static FetchEvent* Create(ScriptState*,
47 const AtomicString& type, 53 const AtomicString& type,
48 const FetchEventInit&, 54 const FetchEventInit&,
49 FetchRespondWithObserver*, 55 FetchRespondWithObserver*,
50 WaitUntilObserver*, 56 WaitUntilObserver*,
51 bool navigation_preload_sent); 57 bool navigation_preload_sent);
52 58
59 ~FetchEvent() override;
60
53 Request* request() const; 61 Request* request() const;
54 String clientId() const; 62 String clientId() const;
55 bool isReload() const; 63 bool isReload() const;
56 64
57 void respondWith(ScriptState*, ScriptPromise, ExceptionState&); 65 void respondWith(ScriptState*, ScriptPromise, ExceptionState&);
58 ScriptPromise preloadResponse(ScriptState*); 66 ScriptPromise preloadResponse(ScriptState*);
59 67
60 void OnNavigationPreloadResponse(ScriptState*, 68 void OnNavigationPreloadResponse(ScriptState*,
61 std::unique_ptr<WebURLResponse>, 69 std::unique_ptr<WebURLResponse>,
62 std::unique_ptr<WebDataConsumerHandle>); 70 std::unique_ptr<WebDataConsumerHandle>);
63 void OnNavigationPreloadError(ScriptState*, 71 void OnNavigationPreloadError(ScriptState*,
64 std::unique_ptr<WebServiceWorkerError>); 72 std::unique_ptr<WebServiceWorkerError>);
65 void OnNavigationPreloadComplete(WorkerGlobalScope*, 73 void OnNavigationPreloadComplete(WorkerGlobalScope*,
66 double completion_time, 74 double completion_time,
67 int64_t encoded_data_length, 75 int64_t encoded_data_length,
68 int64_t encoded_body_length, 76 int64_t encoded_body_length,
69 int64_t decoded_body_length); 77 int64_t decoded_body_length);
70 78
71 const AtomicString& InterfaceName() const override; 79 const AtomicString& InterfaceName() const override;
72 80
81 // ScriptWrappable
82 bool HasPendingActivity() const override;
83
73 DECLARE_VIRTUAL_TRACE(); 84 DECLARE_VIRTUAL_TRACE();
74 85
75 protected: 86 protected:
76 FetchEvent(ScriptState*, 87 FetchEvent(ScriptState*,
77 const AtomicString& type, 88 const AtomicString& type,
78 const FetchEventInit&, 89 const FetchEventInit&,
79 FetchRespondWithObserver*, 90 FetchRespondWithObserver*,
80 WaitUntilObserver*, 91 WaitUntilObserver*,
81 bool navigation_preload_sent); 92 bool navigation_preload_sent);
82 93
83 private: 94 private:
84 Member<FetchRespondWithObserver> observer_; 95 Member<FetchRespondWithObserver> observer_;
85 Member<Request> request_; 96 Member<Request> request_;
86 Member<PreloadResponseProperty> preload_response_property_; 97 Member<PreloadResponseProperty> preload_response_property_;
87 std::unique_ptr<WebURLResponse> preload_response_; 98 std::unique_ptr<WebURLResponse> preload_response_;
88 String client_id_; 99 String client_id_;
89 bool is_reload_; 100 bool is_reload_;
90 }; 101 };
91 102
92 } // namespace blink 103 } // namespace blink
93 104
94 #endif // FetchEvent_h 105 #endif // FetchEvent_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698