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

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

Issue 2922283002: [Merge to M60] Keep the wrapper of FetchEvent alive while waiting for the preload response. (Closed)
Patch Set: 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 #include "modules/serviceworkers/FetchEvent.h" 5 #include "modules/serviceworkers/FetchEvent.h"
6 6
7 #include "bindings/core/v8/ToV8ForCore.h" 7 #include "bindings/core/v8/ToV8ForCore.h"
8 #include "core/dom/ExecutionContext.h" 8 #include "core/dom/ExecutionContext.h"
9 #include "core/timing/WorkerGlobalScopePerformance.h" 9 #include "core/timing/WorkerGlobalScopePerformance.h"
10 #include "modules/fetch/BytesConsumerForDataConsumerHandle.h" 10 #include "modules/fetch/BytesConsumerForDataConsumerHandle.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 } 62 }
63 63
64 ScriptPromise FetchEvent::preloadResponse(ScriptState* script_state) { 64 ScriptPromise FetchEvent::preloadResponse(ScriptState* script_state) {
65 return preload_response_property_->Promise(script_state->World()); 65 return preload_response_property_->Promise(script_state->World());
66 } 66 }
67 67
68 const AtomicString& FetchEvent::InterfaceName() const { 68 const AtomicString& FetchEvent::InterfaceName() const {
69 return EventNames::FetchEvent; 69 return EventNames::FetchEvent;
70 } 70 }
71 71
72 bool FetchEvent::HasPendingActivity() const {
73 // Prevent V8 from garbage collecting the wrapper object while waiting for the
74 // preload response. This is in order to keep the resolver of preloadResponse
75 // Promise alive.
76 return preload_response_property_->GetState() ==
77 PreloadResponseProperty::kPending &&
78 GetExecutionContext();
79 }
80
72 FetchEvent::FetchEvent(ScriptState* script_state, 81 FetchEvent::FetchEvent(ScriptState* script_state,
73 const AtomicString& type, 82 const AtomicString& type,
74 const FetchEventInit& initializer, 83 const FetchEventInit& initializer,
75 FetchRespondWithObserver* respond_with_observer, 84 FetchRespondWithObserver* respond_with_observer,
76 WaitUntilObserver* wait_until_observer, 85 WaitUntilObserver* wait_until_observer,
77 bool navigation_preload_sent) 86 bool navigation_preload_sent)
78 : ExtendableEvent(type, initializer, wait_until_observer), 87 : ExtendableEvent(type, initializer, wait_until_observer),
88 ContextClient(ExecutionContext::From(script_state)),
79 observer_(respond_with_observer), 89 observer_(respond_with_observer),
80 preload_response_property_(new PreloadResponseProperty( 90 preload_response_property_(new PreloadResponseProperty(
81 ExecutionContext::From(script_state), 91 ExecutionContext::From(script_state),
82 this, 92 this,
83 PreloadResponseProperty::kPreloadResponse)) { 93 PreloadResponseProperty::kPreloadResponse)) {
84 if (!navigation_preload_sent) 94 if (!navigation_preload_sent)
85 preload_response_property_->ResolveWithUndefined(); 95 preload_response_property_->ResolveWithUndefined();
86 96
87 client_id_ = initializer.clientId(); 97 client_id_ = initializer.clientId();
88 is_reload_ = initializer.isReload(); 98 is_reload_ = initializer.isReload();
(...skipping 13 matching lines...) Expand all
102 // Sets a hidden value in order to teach V8 the dependency from 112 // Sets a hidden value in order to teach V8 the dependency from
103 // the event to the request. 113 // the event to the request.
104 V8PrivateProperty::GetFetchEventRequest(script_state->GetIsolate()) 114 V8PrivateProperty::GetFetchEventRequest(script_state->GetIsolate())
105 .Set(event.As<v8::Object>(), request); 115 .Set(event.As<v8::Object>(), request);
106 // From the same reason as above, setHiddenValue can return false. 116 // From the same reason as above, setHiddenValue can return false.
107 // TODO(yhirano): Add an assertion that it returns true once the 117 // TODO(yhirano): Add an assertion that it returns true once the
108 // graceful shutdown mechanism is introduced. 118 // graceful shutdown mechanism is introduced.
109 } 119 }
110 } 120 }
111 121
122 FetchEvent::~FetchEvent() {}
123
112 void FetchEvent::OnNavigationPreloadResponse( 124 void FetchEvent::OnNavigationPreloadResponse(
113 ScriptState* script_state, 125 ScriptState* script_state,
114 std::unique_ptr<WebURLResponse> response, 126 std::unique_ptr<WebURLResponse> response,
115 std::unique_ptr<WebDataConsumerHandle> data_consume_handle) { 127 std::unique_ptr<WebDataConsumerHandle> data_consume_handle) {
116 if (!script_state->ContextIsValid()) 128 if (!script_state->ContextIsValid())
117 return; 129 return;
118 DCHECK(preload_response_property_); 130 DCHECK(preload_response_property_);
119 DCHECK(!preload_response_); 131 DCHECK(!preload_response_);
120 ScriptState::Scope scope(script_state); 132 ScriptState::Scope scope(script_state);
121 preload_response_ = std::move(response); 133 preload_response_ = std::move(response);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 info->AddFinalTransferSize(encoded_data_length); 193 info->AddFinalTransferSize(encoded_data_length);
182 WorkerGlobalScopePerformance::performance(*worker_global_scope) 194 WorkerGlobalScopePerformance::performance(*worker_global_scope)
183 ->AddResourceTiming(*info); 195 ->AddResourceTiming(*info);
184 } 196 }
185 197
186 DEFINE_TRACE(FetchEvent) { 198 DEFINE_TRACE(FetchEvent) {
187 visitor->Trace(observer_); 199 visitor->Trace(observer_);
188 visitor->Trace(request_); 200 visitor->Trace(request_);
189 visitor->Trace(preload_response_property_); 201 visitor->Trace(preload_response_property_);
190 ExtendableEvent::Trace(visitor); 202 ExtendableEvent::Trace(visitor);
203 ContextClient::Trace(visitor);
191 } 204 }
192 205
193 } // namespace blink 206 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698