proxying_url_loader_factory_impl.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef WEBLAYER_BROWSER_PROXYING_URL_LOADER_FACTORY_IMPL_H_
  5. #define WEBLAYER_BROWSER_PROXYING_URL_LOADER_FACTORY_IMPL_H_
  6. #include "mojo/public/cpp/bindings/receiver_set.h"
  7. #include "mojo/public/cpp/bindings/remote.h"
  8. #include "services/network/public/mojom/url_loader_factory.mojom.h"
  9. #include "url/gurl.h"
  10. namespace embedder_support {
  11. class WebResourceResponse;
  12. }
  13. namespace weblayer {
  14. // Used to service navigations when the WebResourceResponse was specified.
  15. // Otherwise it will forward the request to the original URLLoaderFactory.
  16. class ProxyingURLLoaderFactoryImpl : public network::mojom::URLLoaderFactory {
  17. public:
  18. ProxyingURLLoaderFactoryImpl(
  19. mojo::PendingReceiver<network::mojom::URLLoaderFactory> loader_receiver,
  20. mojo::PendingRemote<network::mojom::URLLoaderFactory>
  21. target_factory_remote,
  22. const GURL& url_for_response,
  23. std::unique_ptr<embedder_support::WebResourceResponse> response,
  24. int frame_tree_node_id,
  25. int navigation_entry_unique_id);
  26. ProxyingURLLoaderFactoryImpl(const ProxyingURLLoaderFactoryImpl&) = delete;
  27. ProxyingURLLoaderFactoryImpl& operator=(const ProxyingURLLoaderFactoryImpl&) =
  28. delete;
  29. static bool HasCachedInputStream(int frame_tree_node_id,
  30. int navigation_entry_unique_id);
  31. void CreateLoaderAndStart(
  32. mojo::PendingReceiver<network::mojom::URLLoader> loader,
  33. int32_t request_id,
  34. uint32_t options,
  35. const network::ResourceRequest& request,
  36. mojo::PendingRemote<network::mojom::URLLoaderClient> client,
  37. const net::MutableNetworkTrafficAnnotationTag& traffic_annotation)
  38. override;
  39. void Clone(mojo::PendingReceiver<network::mojom::URLLoaderFactory>
  40. loader_receiver) override;
  41. private:
  42. ~ProxyingURLLoaderFactoryImpl() override;
  43. void OnTargetFactoryError();
  44. void OnProxyBindingError();
  45. mojo::ReceiverSet<network::mojom::URLLoaderFactory> proxy_receivers_;
  46. mojo::Remote<network::mojom::URLLoaderFactory> target_factory_;
  47. GURL url_for_response_;
  48. std::unique_ptr<embedder_support::WebResourceResponse> response_;
  49. const int frame_tree_node_id_;
  50. const int navigation_entry_unique_id_;
  51. };
  52. } // namespace weblayer
  53. #endif // WEBLAYER_BROWSER_PROXYING_URL_LOADER_FACTORY_IMPL_H_