blob: bcc5278656bea2c04333701f19d6cb10dc933543 [file] [log] [blame]
// 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 "base/callback_forward.h"
#include "base/macros.h"
#include "content/common/content_export.h"
#include "services/network/public/mojom/url_loader.mojom.h"
namespace network {
struct ResourceRequest;
namespace content {
class ResourceContext;
// URLLoaderRequestInterceptor is given a chance to create a URLLoader and
// intercept a navigation request before the request is handed off to the
// default URLLoader, e.g. the one from the network service.
// URLLoaderRequestInterceptor is a per-request object and kept around during
// the lifetime of a navigation request (including multiple redirect legs).
class URLLoaderRequestInterceptor {
URLLoaderRequestInterceptor() = default;
virtual ~URLLoaderRequestInterceptor() = default;
using RequestHandler =
base::OnceCallback<void(const network::ResourceRequest& resource_request,
using LoaderCallback = base::OnceCallback<void(RequestHandler)>;
// Asks this handler to handle this resource load request.
// The handler must invoke |callback| eventually with either a non-null
// RequestHandler indicating its willingness to handle the request, or a null
// RequestHandler to indicate that someone else should handle the request.
// The |tentative_resource_request| passed to this function and the resource
// request later passed to the RequestHandler given to |callback| may not be
// exactly the same. See documentation for
// NavigationLoaderInterceptor::MaybeCreateLoader.
virtual void MaybeCreateLoader(
const network::ResourceRequest& tentative_resource_request,
ResourceContext* resource_context,
LoaderCallback callback) = 0;
} // namespace content