Commit a6baa669 authored by Mugdha Lakhani's avatar Mugdha Lakhani Committed by Commit Bot

[Background Fetch] Implement BackgroundFetchRecord.

This will be required to implement match() and matchAll() on
BackgroundFetchRegistration in a follow-up CL.

Bug: 869918
Change-Id: I9ed88076488a035f313b9d16e0f41b3c168a0a09
Reviewed-on: https://chromium-review.googlesource.com/1169465Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Mugdha Lakhani <nator@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582574}
parent 699e98d1
...@@ -36,6 +36,11 @@ interface BackgroundFetchManager ...@@ -36,6 +36,11 @@ interface BackgroundFetchManager
method fetch method fetch
method get method get
method getIds method getIds
interface BackgroundFetchRecord
attribute @@toStringTag
getter request
getter responseReady
method constructor
interface BackgroundFetchRegistration : EventTarget interface BackgroundFetchRegistration : EventTarget
attribute @@toStringTag attribute @@toStringTag
getter downloadTotal getter downloadTotal
......
...@@ -20,6 +20,8 @@ blink_modules_sources("background_fetch") { ...@@ -20,6 +20,8 @@ blink_modules_sources("background_fetch") {
"background_fetch_icon_loader.h", "background_fetch_icon_loader.h",
"background_fetch_manager.cc", "background_fetch_manager.cc",
"background_fetch_manager.h", "background_fetch_manager.h",
"background_fetch_record.cc",
"background_fetch_record.h",
"background_fetch_registration.cc", "background_fetch_registration.cc",
"background_fetch_registration.h", "background_fetch_registration.h",
"background_fetch_settled_event.cc", "background_fetch_settled_event.cc",
......
// Copyright 2018 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.
#include "third_party/blink/renderer/modules/background_fetch/background_fetch_record.h"
#include "third_party/blink/renderer/core/fetch/request.h"
#include "third_party/blink/renderer/core/fetch/response.h"
namespace blink {
BackgroundFetchRecord::BackgroundFetchRecord(Request* request,
Response* response)
: request_(request), response_(response) {
DCHECK(request_);
}
BackgroundFetchRecord::~BackgroundFetchRecord() = default;
ScriptPromise BackgroundFetchRecord::responseReady(ScriptState* script_state) {
if (!response_ready_property_) {
response_ready_property_ =
new ResponseReadyProperty(ExecutionContext::From(script_state), this,
ResponseReadyProperty::kResponseReady);
}
if (!response_) {
response_ = Response::Create(ExecutionContext::From(script_state),
nullptr /* FetchResponseData */);
}
DCHECK(response_);
response_ready_property_->Resolve(response_);
return response_ready_property_->Promise(script_state->World());
}
Request* BackgroundFetchRecord::request() const {
return request_;
}
void BackgroundFetchRecord::Trace(blink::Visitor* visitor) {
visitor->Trace(request_);
visitor->Trace(response_);
visitor->Trace(response_ready_property_);
ScriptWrappable::Trace(visitor);
}
} // namespace blink
// Copyright 2018 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.
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_BACKGROUND_FETCH_BACKGROUND_FETCH_RECORD_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_BACKGROUND_FETCH_BACKGROUND_FETCH_RECORD_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/core/dom/dom_exception.h"
#include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
namespace blink {
class Request;
class Response;
class MODULES_EXPORT BackgroundFetchRecord final : public ScriptWrappable {
DEFINE_WRAPPERTYPEINFO();
public:
explicit BackgroundFetchRecord(Request* request,
Response* response = nullptr);
~BackgroundFetchRecord() override;
Request* request() const;
ScriptPromise responseReady(ScriptState* script_state);
void Trace(blink::Visitor* visitor) override;
private:
using ResponseReadyProperty =
ScriptPromiseProperty<Member<BackgroundFetchRecord>,
Member<Response>,
Member<DOMException>>;
Member<Request> request_;
Member<Response> response_;
Member<ResponseReadyProperty> response_ready_property_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_BACKGROUND_FETCH_BACKGROUND_FETCH_RECORD_H_
// Copyright 2018 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.
// https://wicg.github.io/background-fetch/#background-fetch-record
[
Exposed=(ServiceWorker),
RuntimeEnabled=BackgroundFetch
] interface BackgroundFetchRecord {
readonly attribute Request request;
[CallWith=ScriptState] readonly attribute Promise<Response> responseReady;
};
\ No newline at end of file
...@@ -69,6 +69,7 @@ modules_idl_files = ...@@ -69,6 +69,7 @@ modules_idl_files =
"background_fetch/background_fetch_fail_event.idl", "background_fetch/background_fetch_fail_event.idl",
"background_fetch/background_fetch_fetch.idl", "background_fetch/background_fetch_fetch.idl",
"background_fetch/background_fetch_manager.idl", "background_fetch/background_fetch_manager.idl",
"background_fetch/background_fetch_record.idl",
"background_fetch/background_fetch_registration.idl", "background_fetch/background_fetch_registration.idl",
"background_fetch/background_fetch_settled_event.idl", "background_fetch/background_fetch_settled_event.idl",
"background_fetch/background_fetch_settled_fetch.idl", "background_fetch/background_fetch_settled_fetch.idl",
......
...@@ -6,13 +6,14 @@ ...@@ -6,13 +6,14 @@
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_BINDINGS_SCRIPT_PROMISE_PROPERTIES_H_ #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_BINDINGS_SCRIPT_PROMISE_PROPERTIES_H_
// See ScriptPromiseProperty.h // See ScriptPromiseProperty.h
#define SCRIPT_PROMISE_PROPERTIES(P, ...) \ #define SCRIPT_PROMISE_PROPERTIES(P, ...) \
P(ScriptPromise, kReady##__VA_ARGS__) \ P(ScriptPromise, kReady##__VA_ARGS__) \
P(ScriptPromise, kClosed##__VA_ARGS__) \ P(ScriptPromise, kClosed##__VA_ARGS__) \
P(ScriptPromise, kFinished##__VA_ARGS__) \ P(ScriptPromise, kFinished##__VA_ARGS__) \
P(ScriptPromise, kLoaded##__VA_ARGS__) \ P(ScriptPromise, kLoaded##__VA_ARGS__) \
P(ScriptPromise, kReleased##__VA_ARGS__) \ P(ScriptPromise, kReleased##__VA_ARGS__) \
P(ScriptPromise, kUserChoice##__VA_ARGS__) \ P(ScriptPromise, kResponseReady##__VA_ARGS__) \
P(ScriptPromise, kUserChoice##__VA_ARGS__) \
P(ScriptPromise, kPreloadResponse##__VA_ARGS__) P(ScriptPromise, kPreloadResponse##__VA_ARGS__)
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_BINDINGS_SCRIPT_PROMISE_PROPERTIES_H_ #endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_BINDINGS_SCRIPT_PROMISE_PROPERTIES_H_
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