OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef HEADLESS_PUBLIC_UTIL_GENERIC_URL_REQUEST_JOB_H_ | 5 #ifndef HEADLESS_PUBLIC_UTIL_GENERIC_URL_REQUEST_JOB_H_ |
6 #define HEADLESS_PUBLIC_UTIL_GENERIC_URL_REQUEST_JOB_H_ | 6 #define HEADLESS_PUBLIC_UTIL_GENERIC_URL_REQUEST_JOB_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <functional> | 9 #include <functional> |
10 #include <memory> | 10 #include <memory> |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 size_t response_data_size; | 51 size_t response_data_size; |
52 }; | 52 }; |
53 | 53 |
54 class Delegate { | 54 class Delegate { |
55 public: | 55 public: |
56 // Allows the delegate to rewrite the URL for a given request. Return true | 56 // Allows the delegate to rewrite the URL for a given request. Return true |
57 // to signal that the rewrite is in progress and |callback| will be called | 57 // to signal that the rewrite is in progress and |callback| will be called |
58 // with the result, or false to indicate that no rewriting is necessary. | 58 // with the result, or false to indicate that no rewriting is necessary. |
59 // Called on an arbitrary thread. | 59 // Called on an arbitrary thread. |
60 virtual bool BlockOrRewriteRequest(const GURL& url, | 60 virtual bool BlockOrRewriteRequest(const GURL& url, |
| 61 const std::string& devtools_id, |
61 const std::string& method, | 62 const std::string& method, |
62 const std::string& referrer, | 63 const std::string& referrer, |
63 RewriteCallback callback) = 0; | 64 RewriteCallback callback); |
| 65 // TODO(alexclarke): Make the above pure virtual and remove this. |
| 66 virtual bool BlockOrRewriteRequest(const GURL& url, |
| 67 const std::string& method, |
| 68 const std::string& referrer, |
| 69 RewriteCallback callback); |
64 | 70 |
65 // Allows the delegate to synchronously fulfill a request with a reply. | 71 // Allows the delegate to synchronously fulfill a request with a reply. |
66 // Called on an arbitrary thread. | 72 // Called on an arbitrary thread. |
67 virtual const HttpResponse* MaybeMatchResource( | 73 virtual const HttpResponse* MaybeMatchResource( |
68 const GURL& url, | 74 const GURL& url, |
| 75 const std::string& devtools_id, |
69 const std::string& method, | 76 const std::string& method, |
70 const net::HttpRequestHeaders& request_headers) = 0; | 77 const net::HttpRequestHeaders& request_headers); |
| 78 // TODO(alexclarke): Make the above pure virtual and remove this. |
| 79 virtual const HttpResponse* MaybeMatchResource( |
| 80 const GURL& url, |
| 81 const std::string& method, |
| 82 const net::HttpRequestHeaders& request_headers); |
71 | 83 |
72 // Signals that a resource load has finished. Called on an arbitrary thread. | 84 // Signals that a resource load has finished. Called on an arbitrary thread. |
73 virtual void OnResourceLoadComplete(const GURL& final_url, | 85 virtual void OnResourceLoadComplete(const GURL& final_url, |
| 86 const std::string& devtools_id, |
74 const std::string& mime_type, | 87 const std::string& mime_type, |
75 int http_response_code) = 0; | 88 int http_response_code); |
| 89 // TODO(alexclarke): Make the above pure virtual and remove this. |
| 90 virtual void OnResourceLoadComplete(const GURL& final_url, |
| 91 const std::string& mime_type, |
| 92 int http_response_code) {} |
76 | 93 |
77 protected: | 94 protected: |
78 virtual ~Delegate() {} | 95 virtual ~Delegate() {} |
79 }; | 96 }; |
80 | 97 |
81 // NOTE |url_request_dispatcher| and |delegate| must outlive the | 98 // NOTE |url_request_dispatcher| and |delegate| must outlive the |
82 // GenericURLRequestJob. | 99 // GenericURLRequestJob. |
83 GenericURLRequestJob(net::URLRequest* request, | 100 GenericURLRequestJob(net::URLRequest* request, |
84 net::NetworkDelegate* network_delegate, | 101 net::NetworkDelegate* network_delegate, |
85 URLRequestDispatcher* url_request_dispatcher, | 102 URLRequestDispatcher* url_request_dispatcher, |
(...skipping 24 matching lines...) Expand all Loading... |
110 const std::string& method, | 127 const std::string& method, |
111 const url::Origin& site_for_cookies); | 128 const url::Origin& site_for_cookies); |
112 | 129 |
113 void OnCookiesAvailable(const GURL& rewritten_url, | 130 void OnCookiesAvailable(const GURL& rewritten_url, |
114 const std::string& method, | 131 const std::string& method, |
115 const net::CookieList& cookie_list); | 132 const net::CookieList& cookie_list); |
116 | 133 |
117 std::unique_ptr<URLFetcher> url_fetcher_; | 134 std::unique_ptr<URLFetcher> url_fetcher_; |
118 net::HttpRequestHeaders extra_request_headers_; | 135 net::HttpRequestHeaders extra_request_headers_; |
119 scoped_refptr<net::HttpResponseHeaders> response_headers_; | 136 scoped_refptr<net::HttpResponseHeaders> response_headers_; |
| 137 std::string devtools_request_id_; |
120 Delegate* delegate_; // Not owned. | 138 Delegate* delegate_; // Not owned. |
121 const char* body_ = nullptr; // Not owned. | 139 const char* body_ = nullptr; // Not owned. |
122 int http_response_code_ = 0; | 140 int http_response_code_ = 0; |
123 size_t body_size_ = 0; | 141 size_t body_size_ = 0; |
124 size_t read_offset_ = 0; | 142 size_t read_offset_ = 0; |
125 base::TimeTicks response_time_; | 143 base::TimeTicks response_time_; |
126 | 144 |
127 base::WeakPtrFactory<GenericURLRequestJob> weak_factory_; | 145 base::WeakPtrFactory<GenericURLRequestJob> weak_factory_; |
128 | 146 |
129 DISALLOW_COPY_AND_ASSIGN(GenericURLRequestJob); | 147 DISALLOW_COPY_AND_ASSIGN(GenericURLRequestJob); |
130 }; | 148 }; |
131 | 149 |
132 } // namespace headless | 150 } // namespace headless |
133 | 151 |
134 #endif // HEADLESS_PUBLIC_UTIL_GENERIC_URL_REQUEST_JOB_H_ | 152 #endif // HEADLESS_PUBLIC_UTIL_GENERIC_URL_REQUEST_JOB_H_ |
OLD | NEW |