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

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: 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 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..a87671d0f3984bf23a6e87a7511c8f895537d250 100644
--- a/third_party/WebKit/Source/modules/serviceworkers/FetchEvent.cpp
+++ b/third_party/WebKit/Source/modules/serviceworkers/FetchEvent.cpp
@@ -69,6 +69,15 @@ 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 preload_response_property_->GetState() ==
+ PreloadResponseProperty::kPending &&
+ GetExecutionContext();
+}
+
FetchEvent::FetchEvent(ScriptState* script_state,
const AtomicString& type,
const FetchEventInit& initializer,
@@ -76,6 +85,7 @@ 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),
@@ -109,6 +119,8 @@ FetchEvent::FetchEvent(ScriptState* script_state,
}
}
+FetchEvent::~FetchEvent() {}
+
void FetchEvent::OnNavigationPreloadResponse(
ScriptState* script_state,
std::unique_ptr<WebURLResponse> response,
@@ -188,6 +200,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