| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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 CONTENT_BROWSER_LOADER_URL_LOADER_REQUEST_HANDLER_H_ | 5 #ifndef CONTENT_BROWSER_LOADER_URL_LOADER_REQUEST_HANDLER_H_ |
| 6 #define CONTENT_BROWSER_LOADER_URL_LOADER_REQUEST_HANDLER_H_ | 6 #define CONTENT_BROWSER_LOADER_URL_LOADER_REQUEST_HANDLER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include "base/callback_forward.h" | 9 #include "base/callback_forward.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "content/public/common/url_loader.mojom.h" | 11 #include "content/public/common/url_loader.mojom.h" |
| 12 #include "content/public/common/url_loader_factory.mojom.h" | 12 #include "content/public/common/url_loader_factory.mojom.h" |
| 13 | 13 |
| 14 namespace content { | 14 namespace content { |
| 15 | 15 |
| 16 class ResourceContext; | 16 class ResourceContext; |
| 17 struct ResourceRequest; | 17 struct ResourceRequest; |
| 18 | 18 |
| 19 using StartLoaderCallback = | 19 using StartLoaderCallback = |
| 20 base::OnceCallback<void(mojom::URLLoaderRequest request, | 20 base::OnceCallback<void(mojom::URLLoaderRequest request, |
| 21 mojom::URLLoaderClientPtr client)>; | 21 mojom::URLLoaderClientPtr client)>; |
| 22 | 22 |
| 23 using LoaderCallback = base::OnceCallback<void(StartLoaderCallback)>; | 23 // Provided by handlers who provide fallback handling. |
| 24 using ResponseFallback = |
| 25 base::OnceCallback<bool(const ResourceResponseHead& response, |
| 26 mojom::URLLoaderClientPtr client, |
| 27 mojom::URLLoaderRequest request)>; |
| 28 |
| 29 using LoaderCallback = |
| 30 base::OnceCallback<void(StartLoaderCallback, ResponseFallback)>; |
| 24 | 31 |
| 25 // An instance of this class is a per-request object and kept around during | 32 // An instance of this class is a per-request object and kept around during |
| 26 // the lifetime of a request (including multiple redirect legs) on IO thread. | 33 // the lifetime of a request (including multiple redirect legs) on IO thread. |
| 27 class CONTENT_EXPORT URLLoaderRequestHandler { | 34 class CONTENT_EXPORT URLLoaderRequestHandler { |
| 28 public: | 35 public: |
| 29 URLLoaderRequestHandler() = default; | 36 URLLoaderRequestHandler() = default; |
| 30 virtual ~URLLoaderRequestHandler() = default; | 37 virtual ~URLLoaderRequestHandler() = default; |
| 31 | 38 |
| 32 // Calls |callback| with a non-null StartLoaderCallback if this handler | 39 // Calls |callback| with a non-null StartLoaderCallback if this handler |
| 33 // can handle the request, calls it with null callback otherwise. | 40 // can handle the request, calls it with null callback otherwise. |
| 34 virtual void MaybeCreateLoader(const ResourceRequest& resource_request, | 41 virtual void MaybeCreateLoader(const ResourceRequest& resource_request, |
| 35 ResourceContext* resource_context, | 42 ResourceContext* resource_context, |
| 36 LoaderCallback callback) = 0; | 43 LoaderCallback callback) = 0; |
| 37 | 44 |
| 38 // Returns the URLLoaderFactory if any to be used for subsequent URL requests | 45 // Returns the URLLoaderFactory if any to be used for subsequent URL requests |
| 39 // going forward. Subclasses who want to handle subresource requests etc may | 46 // going forward. Subclasses who want to handle subresource requests etc may |
| 40 // want to override this to return a custom factory. | 47 // want to override this to return a custom factory. |
| 41 virtual mojom::URLLoaderFactoryPtr MaybeCreateSubresourceFactory(); | 48 virtual mojom::URLLoaderFactoryPtr MaybeCreateSubresourceFactory(); |
| 42 }; | 49 }; |
| 43 | 50 |
| 44 } // namespace content | 51 } // namespace content |
| 45 | 52 |
| 46 #endif // CONTENT_BROWSER_LOADER_URL_LOADER_REQUEST_HANDLER_H_ | 53 #endif // CONTENT_BROWSER_LOADER_URL_LOADER_REQUEST_HANDLER_H_ |
| OLD | NEW |