protocol_handler_throttle.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2022 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 COMPONENTS_CUSTOM_HANDLERS_PROTOCOL_HANDLER_THROTTLE_H_
  5. #define COMPONENTS_CUSTOM_HANDLERS_PROTOCOL_HANDLER_THROTTLE_H_
  6. #include "base/memory/raw_ptr.h"
  7. #include "url/gurl.h"
  8. #include "third_party/blink/public/common/loader/url_loader_throttle.h"
  9. namespace custom_handlers {
  10. class ProtocolHandlerRegistry;
  11. class ProtocolHandlerThrottle : public blink::URLLoaderThrottle {
  12. public:
  13. explicit ProtocolHandlerThrottle(const ProtocolHandlerRegistry&);
  14. ~ProtocolHandlerThrottle() override = default;
  15. void WillStartRequest(network::ResourceRequest* request,
  16. bool* defer) override;
  17. void WillRedirectRequest(
  18. net::RedirectInfo* redirect_info,
  19. const network::mojom::URLResponseHead& response_head,
  20. bool* defer,
  21. std::vector<std::string>* to_be_removed_headers,
  22. net::HttpRequestHeaders* modified_headers,
  23. net::HttpRequestHeaders* modified_cors_exempt_headers) override;
  24. private:
  25. // If the @url has a custom protocol handler, the argument will return the
  26. // translated url.
  27. void TranslateUrl(GURL& url);
  28. // The ProtocolHandlerRegistry instance is a KeyedService which ownership is
  29. // managed by the BrowseContext.
  30. raw_ptr<const ProtocolHandlerRegistry> protocol_handler_registry_;
  31. };
  32. } // namespace custom_handlers
  33. #endif // COMPONENTS_CUSTOM_HANDLERS_PROTOCOL_HANDLER_THROTTLE_H_