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