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> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 17 #include "headless/public/headless_export.h" |
17 #include "headless/public/util/managed_dispatch_url_request_job.h" | 18 #include "headless/public/util/managed_dispatch_url_request_job.h" |
18 #include "headless/public/util/url_fetcher.h" | 19 #include "headless/public/util/url_fetcher.h" |
19 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
20 #include "net/url_request/url_request.h" | 21 #include "net/url_request/url_request.h" |
21 #include "url/gurl.h" | 22 #include "url/gurl.h" |
22 | 23 |
23 namespace net { | 24 namespace net { |
24 class HttpResponseHeaders; | 25 class HttpResponseHeaders; |
25 class IOBuffer; | 26 class IOBuffer; |
26 } // namespace net | 27 } // namespace net |
27 | 28 |
28 namespace content { | 29 namespace content { |
29 class ResourceRequestInfo; | 30 class ResourceRequestInfo; |
30 } // namespace content | 31 } // namespace content |
31 | 32 |
32 namespace headless { | 33 namespace headless { |
33 | 34 |
34 class HeadlessBrowserContext; | 35 class HeadlessBrowserContext; |
35 class URLRequestDispatcher; | 36 class URLRequestDispatcher; |
36 | 37 |
37 // Wrapper around net::URLRequest with helpers to access select metadata. | 38 // Wrapper around net::URLRequest with helpers to access select metadata. |
38 class Request { | 39 class HEADLESS_EXPORT Request { |
39 public: | 40 public: |
40 virtual uint64_t GetRequestId() const = 0; | 41 virtual uint64_t GetRequestId() const = 0; |
41 | 42 |
42 virtual const net::URLRequest* GetURLRequest() const = 0; | 43 virtual const net::URLRequest* GetURLRequest() const = 0; |
43 | 44 |
44 // The frame from which the request came from. | 45 // The frame from which the request came from. |
45 virtual int GetFrameTreeNodeId() const = 0; | 46 virtual int GetFrameTreeNodeId() const = 0; |
46 | 47 |
47 // The devtools agent host id for the page where the request came from. | 48 // The devtools agent host id for the page where the request came from. |
48 virtual std::string GetDevToolsAgentHostId() const = 0; | 49 virtual std::string GetDevToolsAgentHostId() const = 0; |
(...skipping 28 matching lines...) Expand all Loading... |
77 protected: | 78 protected: |
78 Request() {} | 79 Request() {} |
79 virtual ~Request() {} | 80 virtual ~Request() {} |
80 | 81 |
81 private: | 82 private: |
82 DISALLOW_COPY_AND_ASSIGN(Request); | 83 DISALLOW_COPY_AND_ASSIGN(Request); |
83 }; | 84 }; |
84 | 85 |
85 // Details of a pending request received by GenericURLRequestJob which must be | 86 // Details of a pending request received by GenericURLRequestJob which must be |
86 // either Allowed, Blocked, Modified or have it's response Mocked. | 87 // either Allowed, Blocked, Modified or have it's response Mocked. |
87 class PendingRequest { | 88 class HEADLESS_EXPORT PendingRequest { |
88 public: | 89 public: |
89 virtual const Request* GetRequest() const = 0; | 90 virtual const Request* GetRequest() const = 0; |
90 | 91 |
91 // Allows the request to proceed as normal. | 92 // Allows the request to proceed as normal. |
92 virtual void AllowRequest() = 0; | 93 virtual void AllowRequest() = 0; |
93 | 94 |
94 // Causes the request to fail with the specified |error|. | 95 // Causes the request to fail with the specified |error|. |
95 virtual void BlockRequest(net::Error error) = 0; | 96 virtual void BlockRequest(net::Error error) = 0; |
96 | 97 |
97 // Allows the request to be completely re-written. | 98 // Allows the request to be completely re-written. |
(...skipping 24 matching lines...) Expand all Loading... |
122 // | 123 // |
123 // 1. The delegate can extension observe / cancel and redirect requests | 124 // 1. The delegate can extension observe / cancel and redirect requests |
124 // 2. The delegate can optionally provide the results, otherwise the specifed | 125 // 2. The delegate can optionally provide the results, otherwise the specifed |
125 // fetcher is invoked. | 126 // fetcher is invoked. |
126 class HEADLESS_EXPORT GenericURLRequestJob | 127 class HEADLESS_EXPORT GenericURLRequestJob |
127 : public ManagedDispatchURLRequestJob, | 128 : public ManagedDispatchURLRequestJob, |
128 public URLFetcher::ResultListener, | 129 public URLFetcher::ResultListener, |
129 public PendingRequest, | 130 public PendingRequest, |
130 public Request { | 131 public Request { |
131 public: | 132 public: |
132 class Delegate { | 133 class HEADLESS_EXPORT Delegate { |
133 public: | 134 public: |
134 // Notifies the delegate of an PendingRequest which must either be | 135 // Notifies the delegate of an PendingRequest which must either be |
135 // allowed, blocked, modifed or it's response mocked. Called on an arbitrary | 136 // allowed, blocked, modifed or it's response mocked. Called on an arbitrary |
136 // thread. | 137 // thread. |
137 virtual void OnPendingRequest(PendingRequest* pending_request) = 0; | 138 virtual void OnPendingRequest(PendingRequest* pending_request) = 0; |
138 | 139 |
139 // Notifies the delegate of any fetch failure. Called on an arbitrary | 140 // Notifies the delegate of any fetch failure. Called on an arbitrary |
140 // thread. | 141 // thread. |
141 virtual void OnResourceLoadFailed(const Request* request, | 142 virtual void OnResourceLoadFailed(const Request* request, |
142 net::Error error) = 0; | 143 net::Error error) = 0; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 static uint64_t next_request_id_; | 225 static uint64_t next_request_id_; |
225 | 226 |
226 base::WeakPtrFactory<GenericURLRequestJob> weak_factory_; | 227 base::WeakPtrFactory<GenericURLRequestJob> weak_factory_; |
227 | 228 |
228 DISALLOW_COPY_AND_ASSIGN(GenericURLRequestJob); | 229 DISALLOW_COPY_AND_ASSIGN(GenericURLRequestJob); |
229 }; | 230 }; |
230 | 231 |
231 } // namespace headless | 232 } // namespace headless |
232 | 233 |
233 #endif // HEADLESS_PUBLIC_UTIL_GENERIC_URL_REQUEST_JOB_H_ | 234 #endif // HEADLESS_PUBLIC_UTIL_GENERIC_URL_REQUEST_JOB_H_ |
OLD | NEW |