#include "third_party/blink/renderer/modules/background_fetch/background_fetch_manager.h"
#include <utility>
#include "base/memory/scoped_refptr.h"
#include "base/ranges/algorithm.h"
#include "services/network/public/mojom/ip_address_space.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_union_request_requestorusvstringsequence_usvstring.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_union_request_usvstring.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_background_fetch_options.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_image_resource.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/fetch/body.h"
#include "third_party/blink/renderer/core/fetch/body_stream_buffer.h"
#include "third_party/blink/renderer/core/fetch/request.h"
#include "third_party/blink/renderer/core/frame/csp/content_security_policy.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/modules/background_fetch/background_fetch_bridge.h"
#include "third_party/blink/renderer/modules/background_fetch/background_fetch_icon_loader.h"
#include "third_party/blink/renderer/modules/background_fetch/background_fetch_registration.h"
#include "third_party/blink/renderer/modules/background_fetch/background_fetch_type_converters.h"
#include "third_party/blink/renderer/modules/service_worker/service_worker_registration.h"
#include "third_party/blink/renderer/platform/bindings/exception_code.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h"
#include "third_party/blink/renderer/platform/bindings/v8_throw_exception.h"
#include "third_party/blink/renderer/platform/blob/blob_data.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/instrumentation/use_counter.h"
#include "third_party/blink/renderer/platform/loader/cors/cors.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_utils.h"
#include "third_party/blink/renderer/platform/network/network_utils.h"
#include "third_party/blink/renderer/platform/weborigin/known_ports.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
#include "third_party/blink/renderer/platform/weborigin/kurl_hash.h"
#include "third_party/blink/renderer/platform/weborigin/security_origin.h"
#include "third_party/blink/renderer/platform/wtf/hash_set.h"
#include "third_party/skia/include/core/SkBitmap.h"
namespace blink {
namespace {
const char kEmptyRequestSequenceErrorMessage[] = …;
ScriptPromise<BackgroundFetchRegistration> RejectWithTypeError(
ScriptState* script_state,
const KURL& request_url,
const String& reason,
ExceptionState& exception_state) { … }
bool ShouldBlockDueToCSP(ExecutionContext* execution_context,
const KURL& request_url) { … }
bool ShouldBlockPort(const KURL& request_url) { … }
bool ShouldBlockCredentials(ExecutionContext* execution_context,
const KURL& request_url) { … }
bool ShouldBlockScheme(const KURL& request_url) { … }
bool ShouldBlockDanglingMarkup(const KURL& request_url) { … }
scoped_refptr<BlobDataHandle> ExtractBlobHandle(
Request* request,
ExceptionState& exception_state) { … }
}
BackgroundFetchManager::BackgroundFetchManager(
ServiceWorkerRegistration* registration)
: … { … }
ScriptPromise<BackgroundFetchRegistration> BackgroundFetchManager::fetch(
ScriptState* script_state,
const String& id,
const V8UnionRequestInfoOrRequestOrUSVStringSequence* requests,
const BackgroundFetchOptions* options,
ExceptionState& exception_state) { … }
void BackgroundFetchManager::DidLoadIcons(
const String& id,
Vector<mojom::blink::FetchAPIRequestPtr> requests,
mojom::blink::BackgroundFetchOptionsPtr options,
BackgroundFetchIconLoader* loader,
ScriptPromiseResolver<BackgroundFetchRegistration>* resolver,
const SkBitmap& icon,
int64_t ideal_to_chosen_icon_size) { … }
void BackgroundFetchManager::DidFetch(
ScriptPromiseResolver<BackgroundFetchRegistration>* resolver,
mojom::blink::BackgroundFetchError error,
BackgroundFetchRegistration* registration) { … }
ScriptPromise<IDLNullable<BackgroundFetchRegistration>>
BackgroundFetchManager::get(ScriptState* script_state,
const String& id,
ExceptionState& exception_state) { … }
Vector<mojom::blink::FetchAPIRequestPtr>
BackgroundFetchManager::CreateFetchAPIRequestVector(
ScriptState* script_state,
const V8UnionRequestInfoOrRequestOrUSVStringSequence* requests,
ExceptionState& exception_state) { … }
void BackgroundFetchManager::DidGetRegistration(
ScriptPromiseResolver<IDLNullable<BackgroundFetchRegistration>>* resolver,
mojom::blink::BackgroundFetchError error,
BackgroundFetchRegistration* registration) { … }
ScriptPromise<IDLArray<IDLString>> BackgroundFetchManager::getIds(
ScriptState* script_state,
ExceptionState& exception_state) { … }
void BackgroundFetchManager::DidGetDeveloperIds(
ScriptPromiseResolver<IDLArray<IDLString>>* resolver,
mojom::blink::BackgroundFetchError error,
const Vector<String>& developer_ids) { … }
void BackgroundFetchManager::Trace(Visitor* visitor) const { … }
void BackgroundFetchManager::ContextDestroyed() { … }
}