OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_URL_REQUEST_INTERCEPTOR_H_ |
| 6 #define CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_URL_REQUEST_INTERCEPTOR_H_ |
| 7 |
| 8 #include "base/macros.h" |
| 9 #include "base/memory/weak_ptr.h" |
| 10 #include "content/browser/devtools/protocol/network.h" |
| 11 #include "net/url_request/url_request_interceptor.h" |
| 12 |
| 13 namespace content { |
| 14 |
| 15 // An interceptor that creates DevToolsURLInterceptorRequestJobs for requests |
| 16 // from pages where interception has been enabled via |
| 17 // Network.enableFetchInterception. |
| 18 class DevToolsURLRequestInterceptor : public net::URLRequestInterceptor { |
| 19 public: |
| 20 DevToolsURLRequestInterceptor(); |
| 21 ~DevToolsURLRequestInterceptor() override; |
| 22 |
| 23 net::URLRequestJob* MaybeInterceptRequest( |
| 24 net::URLRequest* request, |
| 25 net::NetworkDelegate* network_delegate) const override; |
| 26 |
| 27 net::URLRequestJob* MaybeInterceptRedirect( |
| 28 net::URLRequest* request, |
| 29 net::NetworkDelegate* network_delegate, |
| 30 const GURL& location) const override; |
| 31 |
| 32 net::URLRequestJob* MaybeInterceptResponse( |
| 33 net::URLRequest* request, |
| 34 net::NetworkDelegate* network_delegate) const override; |
| 35 |
| 36 // Ideally this inner class wouldn't exist but the interface methods are |
| 37 // const :( |
| 38 class State { |
| 39 public: |
| 40 State(); |
| 41 ~State(); |
| 42 |
| 43 void RegisterSubRequest(const net::URLRequest* request); |
| 44 void UnregisterSubRequest(const net::URLRequest* request); |
| 45 |
| 46 // Returns true if |request| as a currently registered request. |
| 47 bool IsSubRequest(const net::URLRequest* request) const; |
| 48 |
| 49 // To make the user's life easier we make sure requests in a redirect chain |
| 50 // all have the same id. |
| 51 void ExpectRequestAfterRedirect(const net::URLRequest* request, |
| 52 std::string id); |
| 53 |
| 54 std::string GetNewId(); |
| 55 std::string GetRedirectChainParentId(const net::URLRequest* request); |
| 56 |
| 57 base::WeakPtr<State> GetWeakPtr() { return weak_ptr_factory_.GetWeakPtr(); } |
| 58 |
| 59 private: |
| 60 std::unordered_set<const net::URLRequest*> sub_requests_; |
| 61 std::unordered_map<const net::URLRequest*, std::string> expected_redirects_; |
| 62 size_t next_id_; |
| 63 base::WeakPtrFactory<State> weak_ptr_factory_; |
| 64 }; |
| 65 |
| 66 private: |
| 67 std::unique_ptr<State> state_; |
| 68 |
| 69 DISALLOW_COPY_AND_ASSIGN(DevToolsURLRequestInterceptor); |
| 70 }; |
| 71 |
| 72 } // namespace content |
| 73 |
| 74 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_URL_REQUEST_INTERCEPTOR_H_ |
OLD | NEW |