| Index: content/browser/devtools/devtools_url_request_interceptor.h
|
| diff --git a/content/browser/devtools/devtools_url_request_interceptor.h b/content/browser/devtools/devtools_url_request_interceptor.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..dc34b21a6178c7cbb6fda363585a545ff868390d
|
| --- /dev/null
|
| +++ b/content/browser/devtools/devtools_url_request_interceptor.h
|
| @@ -0,0 +1,74 @@
|
| +// Copyright 2017 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 CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_URL_REQUEST_INTERCEPTOR_H_
|
| +#define CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_URL_REQUEST_INTERCEPTOR_H_
|
| +
|
| +#include "base/macros.h"
|
| +#include "base/memory/weak_ptr.h"
|
| +#include "content/browser/devtools/protocol/network.h"
|
| +#include "net/url_request/url_request_interceptor.h"
|
| +
|
| +namespace content {
|
| +
|
| +// An interceptor that creates DevToolsURLInterceptorRequestJobs for requests
|
| +// from pages where interception has been enabled via
|
| +// Network.enableFetchInterception.
|
| +class DevToolsURLRequestInterceptor : public net::URLRequestInterceptor {
|
| + public:
|
| + DevToolsURLRequestInterceptor();
|
| + ~DevToolsURLRequestInterceptor() override;
|
| +
|
| + net::URLRequestJob* MaybeInterceptRequest(
|
| + net::URLRequest* request,
|
| + net::NetworkDelegate* network_delegate) const override;
|
| +
|
| + net::URLRequestJob* MaybeInterceptRedirect(
|
| + net::URLRequest* request,
|
| + net::NetworkDelegate* network_delegate,
|
| + const GURL& location) const override;
|
| +
|
| + net::URLRequestJob* MaybeInterceptResponse(
|
| + net::URLRequest* request,
|
| + net::NetworkDelegate* network_delegate) const override;
|
| +
|
| + // Ideally this inner class wouldn't exist but the interface methods are
|
| + // const :(
|
| + class State {
|
| + public:
|
| + State();
|
| + ~State();
|
| +
|
| + void RegisterSubRequest(const net::URLRequest* request);
|
| + void UnregisterSubRequest(const net::URLRequest* request);
|
| +
|
| + // Returns true if |request| as a currently registered request.
|
| + bool IsSubRequest(const net::URLRequest* request) const;
|
| +
|
| + // To make the user's life easier we make sure requests in a redirect chain
|
| + // all have the same id.
|
| + void ExpectRequestAfterRedirect(const net::URLRequest* request,
|
| + std::string id);
|
| +
|
| + std::string GetNewId();
|
| + std::string GetRedirectChainParentId(const net::URLRequest* request);
|
| +
|
| + base::WeakPtr<State> GetWeakPtr() { return weak_ptr_factory_.GetWeakPtr(); }
|
| +
|
| + private:
|
| + std::unordered_set<const net::URLRequest*> sub_requests_;
|
| + std::unordered_map<const net::URLRequest*, std::string> expected_redirects_;
|
| + size_t next_id_;
|
| + base::WeakPtrFactory<State> weak_ptr_factory_;
|
| + };
|
| +
|
| + private:
|
| + std::unique_ptr<State> state_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(DevToolsURLRequestInterceptor);
|
| +};
|
| +
|
| +} // namespace content
|
| +
|
| +#endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_URL_REQUEST_INTERCEPTOR_H_
|
|
|