Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Unified Diff: content/browser/devtools/devtools_url_request_interceptor.h

Issue 2739323003: DevTools protocol interception, blocking & modification of requests (Closed)
Patch Set: Add missing expects plus tweak test output of Network.interceptedRedirect for clarity Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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_

Powered by Google App Engine
This is Rietveld 408576698