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

Unified Diff: third_party/WebKit/Source/modules/serviceworkers/FetchEvent.cpp

Issue 2922863002: Keep the wrapper of FetchEvent alive while waiting for the preload response. (Closed)
Patch Set: use ContextClient and add 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/serviceworkers/FetchEvent.cpp
diff --git a/third_party/WebKit/Source/modules/serviceworkers/FetchEvent.cpp b/third_party/WebKit/Source/modules/serviceworkers/FetchEvent.cpp
index a464f19d1283bdba45958c5665c665ec52c8d3cb..874c93562d661fae28bf730777d0a59fc9aabcf9 100644
--- a/third_party/WebKit/Source/modules/serviceworkers/FetchEvent.cpp
+++ b/third_party/WebKit/Source/modules/serviceworkers/FetchEvent.cpp
@@ -69,6 +69,13 @@ const AtomicString& FetchEvent::InterfaceName() const {
return EventNames::FetchEvent;
}
+bool FetchEvent::HasPendingActivity() const {
+ // Prevent V8 from garbage collecting the wrapper object while waiting for the
+ // preload response. This is in order to keep the resolver of preloadResponse
+ // Promise alive.
+ return waiting_for_preload_response_ && GetExecutionContext();
+}
+
FetchEvent::FetchEvent(ScriptState* script_state,
const AtomicString& type,
const FetchEventInit& initializer,
@@ -76,11 +83,13 @@ FetchEvent::FetchEvent(ScriptState* script_state,
WaitUntilObserver* wait_until_observer,
bool navigation_preload_sent)
: ExtendableEvent(type, initializer, wait_until_observer),
+ ContextClient(ExecutionContext::From(script_state)),
observer_(respond_with_observer),
preload_response_property_(new PreloadResponseProperty(
ExecutionContext::From(script_state),
this,
- PreloadResponseProperty::kPreloadResponse)) {
+ PreloadResponseProperty::kPreloadResponse)),
+ waiting_for_preload_response_(navigation_preload_sent) {
if (!navigation_preload_sent)
preload_response_property_->ResolveWithUndefined();
@@ -109,6 +118,8 @@ FetchEvent::FetchEvent(ScriptState* script_state,
}
}
+FetchEvent::~FetchEvent() {}
+
void FetchEvent::OnNavigationPreloadResponse(
ScriptState* script_state,
std::unique_ptr<WebURLResponse> response,
@@ -149,6 +160,7 @@ void FetchEvent::OnNavigationPreloadResponse(
void FetchEvent::OnNavigationPreloadError(
ScriptState* script_state,
std::unique_ptr<WebServiceWorkerError> error) {
+ waiting_for_preload_response_ = false;
if (!script_state->ContextIsValid())
return;
DCHECK(preload_response_property_);
@@ -163,6 +175,7 @@ void FetchEvent::OnNavigationPreloadComplete(
int64_t encoded_body_length,
int64_t decoded_body_length) {
DCHECK(preload_response_);
+ waiting_for_preload_response_ = false;
std::unique_ptr<WebURLResponse> response = std::move(preload_response_);
ResourceResponse resource_response = response->ToResourceResponse();
resource_response.SetEncodedDataLength(encoded_data_length);
@@ -188,6 +201,7 @@ DEFINE_TRACE(FetchEvent) {
visitor->Trace(request_);
visitor->Trace(preload_response_property_);
ExtendableEvent::Trace(visitor);
+ ContextClient::Trace(visitor);
}
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698