| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 virtual void BlockRequest(net::Error error) = 0; | 89 virtual void BlockRequest(net::Error error) = 0; |
| 90 | 90 |
| 91 // Allows the request to be completely re-written. | 91 // Allows the request to be completely re-written. |
| 92 virtual void ModifyRequest( | 92 virtual void ModifyRequest( |
| 93 const GURL& url, | 93 const GURL& url, |
| 94 const std::string& method, | 94 const std::string& method, |
| 95 const std::string& post_data, | 95 const std::string& post_data, |
| 96 const net::HttpRequestHeaders& request_headers) = 0; | 96 const net::HttpRequestHeaders& request_headers) = 0; |
| 97 | 97 |
| 98 struct MockResponseData { | 98 struct MockResponseData { |
| 99 int http_response_code = 0; | |
| 100 std::string response_data; | 99 std::string response_data; |
| 101 }; | 100 }; |
| 102 | 101 |
| 103 // Instead of fetching the request, |mock_response| is returned instead. | 102 // Instead of fetching the request, |mock_response| is returned instead. |
| 104 virtual void MockResponse( | 103 virtual void MockResponse( |
| 105 std::unique_ptr<MockResponseData> mock_response) = 0; | 104 std::unique_ptr<MockResponseData> mock_response) = 0; |
| 106 | 105 |
| 107 protected: | 106 protected: |
| 108 PendingRequest() {} | 107 PendingRequest() {} |
| 109 virtual ~PendingRequest() {} | 108 virtual ~PendingRequest() {} |
| (...skipping 23 matching lines...) Expand all Loading... |
| 133 | 132 |
| 134 // Notifies the delegate of any fetch failure. Called on an arbitrary | 133 // Notifies the delegate of any fetch failure. Called on an arbitrary |
| 135 // thread. | 134 // thread. |
| 136 virtual void OnResourceLoadFailed(const Request* request, | 135 virtual void OnResourceLoadFailed(const Request* request, |
| 137 net::Error error) = 0; | 136 net::Error error) = 0; |
| 138 | 137 |
| 139 // Signals that a resource load has finished. Called on an arbitrary thread. | 138 // Signals that a resource load has finished. Called on an arbitrary thread. |
| 140 virtual void OnResourceLoadComplete( | 139 virtual void OnResourceLoadComplete( |
| 141 const Request* request, | 140 const Request* request, |
| 142 const GURL& final_url, | 141 const GURL& final_url, |
| 143 int http_response_code, | |
| 144 scoped_refptr<net::HttpResponseHeaders> response_headers, | 142 scoped_refptr<net::HttpResponseHeaders> response_headers, |
| 145 const char* body, | 143 const char* body, |
| 146 size_t body_size) = 0; | 144 size_t body_size) = 0; |
| 147 | 145 |
| 148 protected: | 146 protected: |
| 149 virtual ~Delegate() {} | 147 virtual ~Delegate() {} |
| 150 }; | 148 }; |
| 151 | 149 |
| 152 // NOTE |url_request_dispatcher| and |delegate| must outlive the | 150 // NOTE |url_request_dispatcher| and |delegate| must outlive the |
| 153 // GenericURLRequestJob. | 151 // GenericURLRequestJob. |
| 154 GenericURLRequestJob(net::URLRequest* request, | 152 GenericURLRequestJob(net::URLRequest* request, |
| 155 net::NetworkDelegate* network_delegate, | 153 net::NetworkDelegate* network_delegate, |
| 156 URLRequestDispatcher* url_request_dispatcher, | 154 URLRequestDispatcher* url_request_dispatcher, |
| 157 std::unique_ptr<URLFetcher> url_fetcher, | 155 std::unique_ptr<URLFetcher> url_fetcher, |
| 158 Delegate* delegate); | 156 Delegate* delegate); |
| 159 ~GenericURLRequestJob() override; | 157 ~GenericURLRequestJob() override; |
| 160 | 158 |
| 161 // net::URLRequestJob implementation: | 159 // net::URLRequestJob implementation: |
| 162 void SetExtraRequestHeaders(const net::HttpRequestHeaders& headers) override; | 160 void SetExtraRequestHeaders(const net::HttpRequestHeaders& headers) override; |
| 163 void Start() override; | 161 void Start() override; |
| 164 int ReadRawData(net::IOBuffer* buf, int buf_size) override; | 162 int ReadRawData(net::IOBuffer* buf, int buf_size) override; |
| 165 int GetResponseCode() const override; | |
| 166 void GetResponseInfo(net::HttpResponseInfo* info) override; | 163 void GetResponseInfo(net::HttpResponseInfo* info) override; |
| 167 bool GetMimeType(std::string* mime_type) const override; | 164 bool GetMimeType(std::string* mime_type) const override; |
| 168 bool GetCharset(std::string* charset) override; | 165 bool GetCharset(std::string* charset) override; |
| 169 void GetLoadTimingInfo(net::LoadTimingInfo* load_timing_info) const override; | 166 void GetLoadTimingInfo(net::LoadTimingInfo* load_timing_info) const override; |
| 170 | 167 |
| 171 // URLFetcher::FetchResultListener implementation: | 168 // URLFetcher::FetchResultListener implementation: |
| 172 void OnFetchStartError(net::Error error) override; | 169 void OnFetchStartError(net::Error error) override; |
| 173 void OnFetchComplete(const GURL& final_url, | 170 void OnFetchComplete(const GURL& final_url, |
| 174 int http_response_code, | |
| 175 scoped_refptr<net::HttpResponseHeaders> response_headers, | 171 scoped_refptr<net::HttpResponseHeaders> response_headers, |
| 176 const char* body, | 172 const char* body, |
| 177 size_t body_size) override; | 173 size_t body_size) override; |
| 178 | 174 |
| 179 protected: | 175 protected: |
| 180 // Request implementation: | 176 // Request implementation: |
| 181 const net::URLRequest* GetURLRequest() const override; | 177 const net::URLRequest* GetURLRequest() const override; |
| 182 int GetFrameTreeNodeId() const override; | 178 int GetFrameTreeNodeId() const override; |
| 183 std::string GetDevToolsAgentHostId() const override; | 179 std::string GetDevToolsAgentHostId() const override; |
| 184 ResourceType GetResourceType() const override; | 180 ResourceType GetResourceType() const override; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 204 const net::CookieList& cookie_list); | 200 const net::CookieList& cookie_list); |
| 205 | 201 |
| 206 std::unique_ptr<URLFetcher> url_fetcher_; | 202 std::unique_ptr<URLFetcher> url_fetcher_; |
| 207 net::HttpRequestHeaders extra_request_headers_; | 203 net::HttpRequestHeaders extra_request_headers_; |
| 208 scoped_refptr<net::HttpResponseHeaders> response_headers_; | 204 scoped_refptr<net::HttpResponseHeaders> response_headers_; |
| 209 scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner_; | 205 scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner_; |
| 210 std::unique_ptr<MockResponseData> mock_response_; | 206 std::unique_ptr<MockResponseData> mock_response_; |
| 211 Delegate* delegate_; // Not owned. | 207 Delegate* delegate_; // Not owned. |
| 212 const content::ResourceRequestInfo* request_resource_info_; // Not owned. | 208 const content::ResourceRequestInfo* request_resource_info_; // Not owned. |
| 213 const char* body_ = nullptr; // Not owned. | 209 const char* body_ = nullptr; // Not owned. |
| 214 int http_response_code_ = 0; | |
| 215 size_t body_size_ = 0; | 210 size_t body_size_ = 0; |
| 216 size_t read_offset_ = 0; | 211 size_t read_offset_ = 0; |
| 217 base::TimeTicks response_time_; | 212 base::TimeTicks response_time_; |
| 218 | 213 |
| 219 base::WeakPtrFactory<GenericURLRequestJob> weak_factory_; | 214 base::WeakPtrFactory<GenericURLRequestJob> weak_factory_; |
| 220 | 215 |
| 221 DISALLOW_COPY_AND_ASSIGN(GenericURLRequestJob); | 216 DISALLOW_COPY_AND_ASSIGN(GenericURLRequestJob); |
| 222 }; | 217 }; |
| 223 | 218 |
| 224 } // namespace headless | 219 } // namespace headless |
| 225 | 220 |
| 226 #endif // HEADLESS_PUBLIC_UTIL_GENERIC_URL_REQUEST_JOB_H_ | 221 #endif // HEADLESS_PUBLIC_UTIL_GENERIC_URL_REQUEST_JOB_H_ |
| OLD | NEW |