Commit e1f61030 authored by Yuta Kasai's avatar Yuta Kasai Committed by Commit Bot

Service Worker: Add an experimental API FetchEvent#addPerformanceEntry

This CL starts to implement FetchEvent WorkerTiming. This feature enables a
service worker to attach PerformanceMark/PerformanceMeasure timings to a
request during the fetch event handler. The timings will then be exposed to the
page using PerformanceResourceTiming.

This patch extends PerformanceMark/Measure by
PerformanceEntry::toMojoPerformanceMarkOrMeasure() to pass them via Mojo pipe.
A pair of Mojo endpoints for FetchEventWorkerTiming is made in
ServiceWorkerSubresourceLoader::DispatchFetchEvent() and Mojo remote will be
moved to FetchEvent.
Mojo remote is null for navigation and subresources because it is unsupported
yet. This feature won't work after this patch is merged because Mojo receiver
and remote aren't be connected anywhere.
These will be connected in the other patch.

Explainer : https://github.com/wanderview/fetchevent-worker-timing/blob/master/explainer.md
Design doc: https://docs.google.com/document/d/1-ebnv7OFiVd3k2-jbtQGO5s3BKHIp7lRx3ujhgNKvB0

Bug: 900700
Change-Id: Ie6c870faf0309990ccf8dbd986091fb2f1597dc5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1903115
Commit-Queue: Yuta Kasai <yutakasai@google.com>
Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarNicolás Peña Moreno <npm@chromium.org>
Reviewed-by: default avatarMakoto Shimazu <shimazu@chromium.org>
Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#715171}
parent d9bcfac1
...@@ -262,6 +262,11 @@ void ServiceWorkerSubresourceLoader::DispatchFetchEvent() { ...@@ -262,6 +262,11 @@ void ServiceWorkerSubresourceLoader::DispatchFetchEvent() {
params->request = blink::mojom::FetchAPIRequest::From(resource_request_); params->request = blink::mojom::FetchAPIRequest::From(resource_request_);
params->client_id = controller_connector_->client_id(); params->client_id = controller_connector_->client_id();
// TODO(https://crbug.com/900700): Implement this, making the remote
// connected to a receiver which is passed to
// blink::PerformanceResourceTiming.
params->worker_timing_remote = mojo::NullRemote();
// TODO(falken): Grant the controller service worker's process access to files // TODO(falken): Grant the controller service worker's process access to files
// in the body, like ServiceWorkerFetchDispatcher::DispatchFetchEvent() does. // in the body, like ServiceWorkerFetchDispatcher::DispatchFetchEvent() does.
controller->DispatchFetchEventForSubresource( controller->DispatchFetchEventForSubresource(
......
...@@ -129,6 +129,8 @@ mojom("mojom_platform") { ...@@ -129,6 +129,8 @@ mojom("mojom_platform") {
"speech/speech_recognition_result.mojom", "speech/speech_recognition_result.mojom",
"speech/speech_recognizer.mojom", "speech/speech_recognizer.mojom",
"speech/speech_synthesis.mojom", "speech/speech_synthesis.mojom",
"timing/performance_mark_or_measure.mojom",
"timing/worker_timing_container.mojom",
"ukm/ukm.mojom", "ukm/ukm.mojom",
"user_agent/user_agent_metadata.mojom", "user_agent/user_agent_metadata.mojom",
"v8_cache_options.mojom", "v8_cache_options.mojom",
......
...@@ -7,6 +7,7 @@ module blink.mojom; ...@@ -7,6 +7,7 @@ module blink.mojom;
import "services/network/public/mojom/url_loader.mojom"; import "services/network/public/mojom/url_loader.mojom";
import "third_party/blink/public/mojom/blob/blob.mojom"; import "third_party/blink/public/mojom/blob/blob.mojom";
import "third_party/blink/public/mojom/fetch/fetch_api_request.mojom"; import "third_party/blink/public/mojom/fetch/fetch_api_request.mojom";
import "third_party/blink/public/mojom/timing/worker_timing_container.mojom";
// Used for service worker navigation preload, to create // Used for service worker navigation preload, to create
// FetchEvent#preloadResponse. // FetchEvent#preloadResponse.
...@@ -24,4 +25,9 @@ struct DispatchFetchEventParams { ...@@ -24,4 +25,9 @@ struct DispatchFetchEventParams {
string client_id; string client_id;
// FetchEvent#preloadResponse. // FetchEvent#preloadResponse.
FetchEventPreloadHandle? preload_handle; FetchEventPreloadHandle? preload_handle;
// This is currently always null because it's still being implemented.
// TODO(https://crbug.com/900700): Make this non-nullable when implementation
// is complete (including support for both navigation and subresource requests).
pending_remote<blink.mojom.WorkerTimingContainer>? worker_timing_remote;
}; };
npm@chromium.org
per-file *.mojom=set noparent
per-file *.mojom=file://ipc/SECURITY_OWNERS
# TEAM: speed-metrics-dev@chromium.org
# COMPONENT: Blink>PerformanceAPIs
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module blink.mojom;
import "mojo/public/mojom/base/big_buffer.mojom";
// This struct represents PerformanceMark and PerformanceMeasure.
// https://w3c.github.io/user-timing/#performancemark
// https://w3c.github.io/user-timing/#performancemeasure
struct PerformanceMarkOrMeasure {
enum EntryType{
kMark,
kMeasure,
};
string name;
EntryType entry_type;
double start_time;
double duration;
// Nullable because PerformanceMark and PerformanceMeasure might not have a
// detail.
mojo_base.mojom.BigBuffer? detail;
};
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module blink.mojom;
import "third_party/blink/public/mojom/timing/performance_mark_or_measure.mojom";
// Used to implement FetchEvent WorkerTiming (https://crbug.com/900700).
// A service worker uses this interface to send performance timings to a client
// (a document/worker controlled by the service worker) during the fetch event
// for a request. The client then incorporates the timings into the
// blink::PerformanceResourceTiming for the request. The client may be in a
// different renderer process than the service worker.
interface WorkerTimingContainer {
// Corresponds to FetchEvent#addPerformanceEntry.
// https://github.com/wanderview/fetchevent-worker-timing/blob/master/explainer.md
AddPerformanceEntry(PerformanceMarkOrMeasure entry);
};
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "third_party/blink/renderer/core/timing/performance_entry.h" #include "third_party/blink/renderer/core/timing/performance_entry.h"
#include "base/atomic_sequence_num.h" #include "base/atomic_sequence_num.h"
#include "third_party/blink/public/mojom/timing/performance_mark_or_measure.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/script_value.h" #include "third_party/blink/renderer/bindings/core/v8/script_value.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_object_builder.h" #include "third_party/blink/renderer/bindings/core/v8/v8_object_builder.h"
#include "third_party/blink/renderer/core/performance_entry_names.h" #include "third_party/blink/renderer/core/performance_entry_names.h"
...@@ -59,6 +60,22 @@ DOMHighResTimeStamp PerformanceEntry::duration() const { ...@@ -59,6 +60,22 @@ DOMHighResTimeStamp PerformanceEntry::duration() const {
return duration_; return duration_;
} }
mojom::blink::PerformanceMarkOrMeasurePtr
PerformanceEntry::ToMojoPerformanceMarkOrMeasure() {
DCHECK(EntryTypeEnum() == kMark || EntryTypeEnum() == kMeasure);
auto mojo_performance_mark_or_measure =
mojom::blink::PerformanceMarkOrMeasure::New();
mojo_performance_mark_or_measure->name = name_;
mojo_performance_mark_or_measure->entry_type =
EntryTypeEnum() == kMark
? mojom::blink::PerformanceMarkOrMeasure::EntryType::kMark
: mojom::blink::PerformanceMarkOrMeasure::EntryType::kMeasure;
mojo_performance_mark_or_measure->start_time = start_time_;
mojo_performance_mark_or_measure->duration = duration_;
// PerformanceMark/Measure overrides will add the detail field.
return mojo_performance_mark_or_measure;
}
PerformanceEntry::EntryType PerformanceEntry::ToEntryTypeEnum( PerformanceEntry::EntryType PerformanceEntry::ToEntryTypeEnum(
const AtomicString& entry_type) { const AtomicString& entry_type) {
if (entry_type == performance_entry_names::kLongtask) if (entry_type == performance_entry_names::kLongtask)
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_TIMING_PERFORMANCE_ENTRY_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_TIMING_PERFORMANCE_ENTRY_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_TIMING_PERFORMANCE_ENTRY_H_ #define THIRD_PARTY_BLINK_RENDERER_CORE_TIMING_PERFORMANCE_ENTRY_H_
#include "third_party/blink/public/mojom/timing/performance_mark_or_measure.mojom-blink-forward.h"
#include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/dom/dom_high_res_time_stamp.h" #include "third_party/blink/renderer/core/dom/dom_high_res_time_stamp.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h" #include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
...@@ -111,6 +112,13 @@ class CORE_EXPORT PerformanceEntry : public ScriptWrappable { ...@@ -111,6 +112,13 @@ class CORE_EXPORT PerformanceEntry : public ScriptWrappable {
return valid_timeline_entry_types.Contains(entry_type); return valid_timeline_entry_types.Contains(entry_type);
} }
// PerformanceMark/Measure override this and it returns Mojo structure pointer
// which has all members of PerformanceMark/Measure. Common data members are
// set by PerformanceMark/Measure calling
// PerformanceEntry::ToMojoPerformanceMarkOrMeasure().
virtual mojom::blink::PerformanceMarkOrMeasurePtr
ToMojoPerformanceMarkOrMeasure();
protected: protected:
PerformanceEntry(const AtomicString& name, PerformanceEntry(const AtomicString& name,
double start_time, double start_time,
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "third_party/blink/renderer/core/timing/performance_mark.h" #include "third_party/blink/renderer/core/timing/performance_mark.h"
#include "third_party/blink/public/mojom/timing/performance_mark_or_measure.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/script_value.h" #include "third_party/blink/renderer/bindings/core/v8/script_value.h"
#include "third_party/blink/renderer/bindings/core/v8/serialization/serialized_script_value.h" #include "third_party/blink/renderer/bindings/core/v8/serialization/serialized_script_value.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h" #include "third_party/blink/renderer/core/frame/local_dom_window.h"
...@@ -76,6 +77,14 @@ PerformanceEntryType PerformanceMark::EntryTypeEnum() const { ...@@ -76,6 +77,14 @@ PerformanceEntryType PerformanceMark::EntryTypeEnum() const {
return PerformanceEntry::EntryType::kMark; return PerformanceEntry::EntryType::kMark;
} }
mojom::blink::PerformanceMarkOrMeasurePtr
PerformanceMark::ToMojoPerformanceMarkOrMeasure() {
auto mojo_performance_mark_or_measure =
PerformanceEntry::ToMojoPerformanceMarkOrMeasure();
mojo_performance_mark_or_measure->detail = serialized_detail_->GetWireData();
return mojo_performance_mark_or_measure;
}
ScriptValue PerformanceMark::detail(ScriptState* script_state) { ScriptValue PerformanceMark::detail(ScriptState* script_state) {
v8::Isolate* isolate = script_state->GetIsolate(); v8::Isolate* isolate = script_state->GetIsolate();
if (!serialized_detail_) if (!serialized_detail_)
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_TIMING_PERFORMANCE_MARK_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_TIMING_PERFORMANCE_MARK_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_TIMING_PERFORMANCE_MARK_H_ #define THIRD_PARTY_BLINK_RENDERER_CORE_TIMING_PERFORMANCE_MARK_H_
#include "third_party/blink/public/mojom/timing/performance_mark_or_measure.mojom-blink-forward.h"
#include "third_party/blink/renderer/bindings/core/v8/serialization/serialized_script_value.h" #include "third_party/blink/renderer/bindings/core/v8/serialization/serialized_script_value.h"
#include "third_party/blink/renderer/core/timing/performance_entry.h" #include "third_party/blink/renderer/core/timing/performance_entry.h"
#include "third_party/blink/renderer/platform/bindings/trace_wrapper_v8_reference.h" #include "third_party/blink/renderer/platform/bindings/trace_wrapper_v8_reference.h"
...@@ -61,6 +62,8 @@ class CORE_EXPORT PerformanceMark final : public PerformanceEntry { ...@@ -61,6 +62,8 @@ class CORE_EXPORT PerformanceMark final : public PerformanceEntry {
AtomicString entryType() const override; AtomicString entryType() const override;
PerformanceEntryType EntryTypeEnum() const override; PerformanceEntryType EntryTypeEnum() const override;
mojom::blink::PerformanceMarkOrMeasurePtr ToMojoPerformanceMarkOrMeasure()
override;
ScriptValue detail(ScriptState*); ScriptValue detail(ScriptState*);
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "third_party/blink/renderer/core/timing/performance_measure.h" #include "third_party/blink/renderer/core/timing/performance_measure.h"
#include "third_party/blink/public/mojom/timing/performance_mark_or_measure.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/script_value.h" #include "third_party/blink/renderer/bindings/core/v8/script_value.h"
#include "third_party/blink/renderer/bindings/core/v8/serialization/serialized_script_value.h" #include "third_party/blink/renderer/bindings/core/v8/serialization/serialized_script_value.h"
#include "third_party/blink/renderer/core/performance_entry_names.h" #include "third_party/blink/renderer/core/performance_entry_names.h"
...@@ -67,6 +68,14 @@ PerformanceEntryType PerformanceMeasure::EntryTypeEnum() const { ...@@ -67,6 +68,14 @@ PerformanceEntryType PerformanceMeasure::EntryTypeEnum() const {
return PerformanceEntry::EntryType::kMeasure; return PerformanceEntry::EntryType::kMeasure;
} }
mojom::blink::PerformanceMarkOrMeasurePtr
PerformanceMeasure::ToMojoPerformanceMarkOrMeasure() {
auto mojo_performance_mark_or_measure =
PerformanceEntry::ToMojoPerformanceMarkOrMeasure();
mojo_performance_mark_or_measure->detail = serialized_detail_->GetWireData();
return mojo_performance_mark_or_measure;
}
void PerformanceMeasure::Trace(blink::Visitor* visitor) { void PerformanceMeasure::Trace(blink::Visitor* visitor) {
visitor->Trace(deserialized_detail_map_); visitor->Trace(deserialized_detail_map_);
PerformanceEntry::Trace(visitor); PerformanceEntry::Trace(visitor);
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#define THIRD_PARTY_BLINK_RENDERER_CORE_TIMING_PERFORMANCE_MEASURE_H_ #define THIRD_PARTY_BLINK_RENDERER_CORE_TIMING_PERFORMANCE_MEASURE_H_
#include "base/memory/scoped_refptr.h" #include "base/memory/scoped_refptr.h"
#include "third_party/blink/public/mojom/timing/performance_mark_or_measure.mojom-blink-forward.h"
#include "third_party/blink/renderer/bindings/core/v8/serialization/serialized_script_value.h" #include "third_party/blink/renderer/bindings/core/v8/serialization/serialized_script_value.h"
#include "third_party/blink/renderer/core/timing/performance_entry.h" #include "third_party/blink/renderer/core/timing/performance_entry.h"
#include "third_party/blink/renderer/platform/bindings/trace_wrapper_v8_reference.h" #include "third_party/blink/renderer/platform/bindings/trace_wrapper_v8_reference.h"
...@@ -38,7 +39,7 @@ namespace blink { ...@@ -38,7 +39,7 @@ namespace blink {
class ExceptionState; class ExceptionState;
class PerformanceMeasure final : public PerformanceEntry { class CORE_EXPORT PerformanceMeasure final : public PerformanceEntry {
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
public: public:
...@@ -60,6 +61,8 @@ class PerformanceMeasure final : public PerformanceEntry { ...@@ -60,6 +61,8 @@ class PerformanceMeasure final : public PerformanceEntry {
AtomicString entryType() const override; AtomicString entryType() const override;
PerformanceEntryType EntryTypeEnum() const override; PerformanceEntryType EntryTypeEnum() const override;
mojom::blink::PerformanceMarkOrMeasurePtr ToMojoPerformanceMarkOrMeasure()
override;
void Trace(blink::Visitor* visitor) override; void Trace(blink::Visitor* visitor) override;
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include "third_party/blink/renderer/modules/service_worker/fetch_event.h" #include "third_party/blink/renderer/modules/service_worker/fetch_event.h"
#include "base/memory/scoped_refptr.h" #include "base/memory/scoped_refptr.h"
#include "third_party/blink/public/mojom/timing/performance_mark_or_measure.mojom-blink.h"
#include "third_party/blink/public/mojom/timing/worker_timing_container.mojom-blink.h"
#include "third_party/blink/public/platform/modules/service_worker/web_service_worker_error.h" #include "third_party/blink/public/platform/modules/service_worker/web_service_worker_error.h"
#include "third_party/blink/public/platform/web_url_response.h" #include "third_party/blink/public/platform/web_url_response.h"
#include "third_party/blink/renderer/bindings/core/v8/to_v8_for_core.h" #include "third_party/blink/renderer/bindings/core/v8/to_v8_for_core.h"
...@@ -14,6 +16,8 @@ ...@@ -14,6 +16,8 @@
#include "third_party/blink/renderer/core/execution_context/execution_context.h" #include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/fetch/request.h" #include "third_party/blink/renderer/core/fetch/request.h"
#include "third_party/blink/renderer/core/fetch/response.h" #include "third_party/blink/renderer/core/fetch/response.h"
#include "third_party/blink/renderer/core/timing/performance_mark.h"
#include "third_party/blink/renderer/core/timing/performance_measure.h"
#include "third_party/blink/renderer/core/timing/worker_global_scope_performance.h" #include "third_party/blink/renderer/core/timing/worker_global_scope_performance.h"
#include "third_party/blink/renderer/modules/service_worker/fetch_respond_with_observer.h" #include "third_party/blink/renderer/modules/service_worker/fetch_respond_with_observer.h"
#include "third_party/blink/renderer/modules/service_worker/service_worker_error.h" #include "third_party/blink/renderer/modules/service_worker/service_worker_error.h"
...@@ -30,18 +34,8 @@ FetchEvent* FetchEvent::Create(ScriptState* script_state, ...@@ -30,18 +34,8 @@ FetchEvent* FetchEvent::Create(ScriptState* script_state,
const AtomicString& type, const AtomicString& type,
const FetchEventInit* initializer) { const FetchEventInit* initializer) {
return MakeGarbageCollected<FetchEvent>(script_state, type, initializer, return MakeGarbageCollected<FetchEvent>(script_state, type, initializer,
nullptr, nullptr, false); nullptr, nullptr, mojo::NullRemote(),
} false);
FetchEvent* FetchEvent::Create(ScriptState* script_state,
const AtomicString& type,
const FetchEventInit* initializer,
FetchRespondWithObserver* respond_with_observer,
WaitUntilObserver* wait_until_observer,
bool navigation_preload_sent) {
return MakeGarbageCollected<FetchEvent>(
script_state, type, initializer, respond_with_observer,
wait_until_observer, navigation_preload_sent);
} }
Request* FetchEvent::request() const { Request* FetchEvent::request() const {
...@@ -93,6 +87,8 @@ FetchEvent::FetchEvent(ScriptState* script_state, ...@@ -93,6 +87,8 @@ FetchEvent::FetchEvent(ScriptState* script_state,
const FetchEventInit* initializer, const FetchEventInit* initializer,
FetchRespondWithObserver* respond_with_observer, FetchRespondWithObserver* respond_with_observer,
WaitUntilObserver* wait_until_observer, WaitUntilObserver* wait_until_observer,
mojo::PendingRemote<mojom::blink::WorkerTimingContainer>
worker_timing_remote,
bool navigation_preload_sent) bool navigation_preload_sent)
: ExtendableEvent(type, initializer, wait_until_observer), : ExtendableEvent(type, initializer, wait_until_observer),
ContextClient(ExecutionContext::From(script_state)), ContextClient(ExecutionContext::From(script_state)),
...@@ -100,7 +96,8 @@ FetchEvent::FetchEvent(ScriptState* script_state, ...@@ -100,7 +96,8 @@ FetchEvent::FetchEvent(ScriptState* script_state,
preload_response_property_(MakeGarbageCollected<PreloadResponseProperty>( preload_response_property_(MakeGarbageCollected<PreloadResponseProperty>(
ExecutionContext::From(script_state), ExecutionContext::From(script_state),
this, this,
PreloadResponseProperty::kPreloadResponse)) { PreloadResponseProperty::kPreloadResponse)),
worker_timing_remote_(std::move(worker_timing_remote)) {
if (!navigation_preload_sent) if (!navigation_preload_sent)
preload_response_property_->ResolveWithUndefined(); preload_response_property_->ResolveWithUndefined();
...@@ -212,6 +209,24 @@ void FetchEvent::OnNavigationPreloadComplete( ...@@ -212,6 +209,24 @@ void FetchEvent::OnNavigationPreloadComplete(
->GenerateAndAddResourceTiming(*info); ->GenerateAndAddResourceTiming(*info);
} }
void FetchEvent::addPerformanceEntry(PerformanceMark* performance_mark) {
if (worker_timing_remote_) {
auto mojo_performance_mark =
performance_mark->ToMojoPerformanceMarkOrMeasure();
worker_timing_remote_->AddPerformanceEntry(
std::move(mojo_performance_mark));
}
}
void FetchEvent::addPerformanceEntry(PerformanceMeasure* performance_measure) {
if (worker_timing_remote_) {
auto mojo_performance_measure =
performance_measure->ToMojoPerformanceMarkOrMeasure();
worker_timing_remote_->AddPerformanceEntry(
std::move(mojo_performance_measure));
}
}
void FetchEvent::Trace(blink::Visitor* visitor) { void FetchEvent::Trace(blink::Visitor* visitor) {
visitor->Trace(observer_); visitor->Trace(observer_);
visitor->Trace(request_); visitor->Trace(request_);
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include <memory> #include <memory>
#include "third_party/blink/public/mojom/timing/performance_mark_or_measure.mojom-blink-forward.h"
#include "third_party/blink/public/mojom/timing/worker_timing_container.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/active_script_wrappable.h" #include "third_party/blink/renderer/bindings/core/v8/active_script_wrappable.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h" #include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_property.h" #include "third_party/blink/renderer/bindings/core/v8/script_promise_property.h"
...@@ -25,6 +27,8 @@ namespace blink { ...@@ -25,6 +27,8 @@ namespace blink {
class ExceptionState; class ExceptionState;
class FetchRespondWithObserver; class FetchRespondWithObserver;
class PerformanceMark;
class PerformanceMeasure;
class Request; class Request;
class Response; class Response;
class ScriptState; class ScriptState;
...@@ -49,18 +53,14 @@ class MODULES_EXPORT FetchEvent final ...@@ -49,18 +53,14 @@ class MODULES_EXPORT FetchEvent final
static FetchEvent* Create(ScriptState*, static FetchEvent* Create(ScriptState*,
const AtomicString& type, const AtomicString& type,
const FetchEventInit*); const FetchEventInit*);
static FetchEvent* Create(ScriptState*,
const AtomicString& type,
const FetchEventInit*,
FetchRespondWithObserver*,
WaitUntilObserver*,
bool navigation_preload_sent);
FetchEvent(ScriptState*, FetchEvent(ScriptState*,
const AtomicString& type, const AtomicString& type,
const FetchEventInit*, const FetchEventInit*,
FetchRespondWithObserver*, FetchRespondWithObserver*,
WaitUntilObserver*, WaitUntilObserver*,
mojo::PendingRemote<mojom::blink::WorkerTimingContainer>
worker_timing_remote,
bool navigation_preload_sent); bool navigation_preload_sent);
~FetchEvent() override; ~FetchEvent() override;
...@@ -71,6 +71,8 @@ class MODULES_EXPORT FetchEvent final ...@@ -71,6 +71,8 @@ class MODULES_EXPORT FetchEvent final
void respondWith(ScriptState*, ScriptPromise, ExceptionState&); void respondWith(ScriptState*, ScriptPromise, ExceptionState&);
ScriptPromise preloadResponse(ScriptState*); ScriptPromise preloadResponse(ScriptState*);
void addPerformanceEntry(PerformanceMark*);
void addPerformanceEntry(PerformanceMeasure*);
void OnNavigationPreloadResponse(ScriptState*, void OnNavigationPreloadResponse(ScriptState*,
std::unique_ptr<WebURLResponse>, std::unique_ptr<WebURLResponse>,
...@@ -96,6 +98,9 @@ class MODULES_EXPORT FetchEvent final ...@@ -96,6 +98,9 @@ class MODULES_EXPORT FetchEvent final
Member<PreloadResponseProperty> preload_response_property_; Member<PreloadResponseProperty> preload_response_property_;
std::unique_ptr<WebURLResponse> preload_response_; std::unique_ptr<WebURLResponse> preload_response_;
Member<DataPipeBytesConsumer::CompletionNotifier> body_completion_notifier_; Member<DataPipeBytesConsumer::CompletionNotifier> body_completion_notifier_;
// This is currently always null while https://crbug.com/900700 is being
// implemented.
mojo::Remote<mojom::blink::WorkerTimingContainer> worker_timing_remote_;
String client_id_; String client_id_;
String resulting_client_id_; String resulting_client_id_;
bool is_reload_; bool is_reload_;
......
...@@ -16,4 +16,10 @@ ...@@ -16,4 +16,10 @@
[CallWith=ScriptState, RaisesException] void respondWith(Promise<Response> r); [CallWith=ScriptState, RaisesException] void respondWith(Promise<Response> r);
[CallWith=ScriptState] readonly attribute Promise<any> preloadResponse; [CallWith=ScriptState] readonly attribute Promise<any> preloadResponse;
// FetchEvent#addPerformanceEntry
// https://github.com/wanderview/fetchevent-worker-timing/blob/master/explainer.md
[RuntimeEnabled=ServiceWorkerFetchEventWorkerTiming]
void addPerformanceEntry(PerformanceMark entry);
[RuntimeEnabled=ServiceWorkerFetchEventWorkerTiming]
void addPerformanceEntry(PerformanceMeasure entry);
}; };
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/pending_remote.h"
#include "third_party/blink/public/common/features.h" #include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/mojom/appcache/appcache.mojom-blink.h" #include "third_party/blink/public/mojom/appcache/appcache.mojom-blink.h"
#include "third_party/blink/public/mojom/timing/worker_timing_container.mojom-blink.h"
#include "third_party/blink/public/platform/modules/service_worker/web_service_worker_error.h" #include "third_party/blink/public/platform/modules/service_worker/web_service_worker_error.h"
#include "third_party/blink/public/platform/platform.h" #include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/web_url.h" #include "third_party/blink/public/platform/web_url.h"
...@@ -1402,9 +1403,12 @@ void ServiceWorkerGlobalScope::DispatchFetchEventInternal( ...@@ -1402,9 +1403,12 @@ void ServiceWorkerGlobalScope::DispatchFetchEventInternal(
!fetch_request.is_main_resource_load ? String() : params->client_id); !fetch_request.is_main_resource_load ? String() : params->client_id);
event_init->setIsReload(fetch_request.is_reload); event_init->setIsReload(fetch_request.is_reload);
ScriptState* script_state = ScriptController()->GetScriptState(); ScriptState* script_state = ScriptController()->GetScriptState();
FetchEvent* fetch_event = FetchEvent::Create( FetchEvent* fetch_event = MakeGarbageCollected<FetchEvent>(
script_state, event_type_names::kFetch, event_init, respond_with_observer, script_state, event_type_names::kFetch, event_init, respond_with_observer,
wait_until_observer, navigation_preload_sent); wait_until_observer,
mojo::PendingRemote<mojom::blink::WorkerTimingContainer>(
std::move(params->worker_timing_remote)),
navigation_preload_sent);
if (navigation_preload_sent) { if (navigation_preload_sent) {
// Keep |fetchEvent| until OnNavigationPreloadComplete() or // Keep |fetchEvent| until OnNavigationPreloadComplete() or
// onNavigationPreloadError() will be called. // onNavigationPreloadError() will be called.
......
...@@ -1500,6 +1500,10 @@ ...@@ -1500,6 +1500,10 @@
name: "ServiceWorkerClientLifecycleState", name: "ServiceWorkerClientLifecycleState",
status: "experimental", status: "experimental",
}, },
{
name: "ServiceWorkerFetchEventWorkerTiming",
status: "experimental",
},
{ {
name: "SetRootScroller", name: "SetRootScroller",
status: "experimental", status: "experimental",
......
...@@ -497,6 +497,7 @@ interface FetchEvent : ExtendableEvent ...@@ -497,6 +497,7 @@ interface FetchEvent : ExtendableEvent
getter preloadResponse getter preloadResponse
getter request getter request
getter resultingClientId getter resultingClientId
method addPerformanceEntry
method constructor method constructor
method respondWith method respondWith
interface File : Blob interface File : Blob
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment