signin_url_loader_throttle.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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_SIGNIN_URL_LOADER_THROTTLE_H_
  5. #define WEBLAYER_BROWSER_SIGNIN_URL_LOADER_THROTTLE_H_
  6. #include "base/memory/raw_ptr.h"
  7. #include "components/signin/core/browser/signin_header_helper.h"
  8. #include "content/public/browser/browser_context.h"
  9. #include "content/public/browser/web_contents.h"
  10. #include "net/http/http_request_headers.h"
  11. #include "third_party/blink/public/common/loader/url_loader_throttle.h"
  12. namespace net {
  13. class HttpResponseHeaders;
  14. }
  15. namespace weblayer {
  16. // Exposed for testing.
  17. extern const char kSignOutPath[];
  18. class SigninURLLoaderThrottle : public blink::URLLoaderThrottle {
  19. public:
  20. ~SigninURLLoaderThrottle() override;
  21. static std::unique_ptr<SigninURLLoaderThrottle> Create(
  22. content::BrowserContext* browser_context,
  23. content::WebContents::Getter web_contents_getter);
  24. // blink::URLLoaderThrottle
  25. void WillStartRequest(network::ResourceRequest* request,
  26. bool* defer) override;
  27. void WillRedirectRequest(
  28. net::RedirectInfo* redirect_info,
  29. const network::mojom::URLResponseHead& response_head,
  30. bool* defer,
  31. std::vector<std::string>* headers_to_remove,
  32. net::HttpRequestHeaders* modified_headers,
  33. net::HttpRequestHeaders* modified_cors_exempt_request_headers) override;
  34. void WillProcessResponse(const GURL& response_url,
  35. network::mojom::URLResponseHead* response_head,
  36. bool* defer) override;
  37. private:
  38. SigninURLLoaderThrottle(content::BrowserContext* browser_context,
  39. content::WebContents::Getter web_contents_getter);
  40. void ProcessRequest(const GURL& url,
  41. net::HttpRequestHeaders* original_headers,
  42. std::vector<std::string>* headers_to_remove,
  43. net::HttpRequestHeaders* modified_headers);
  44. void ProcessResponse(const net::HttpResponseHeaders* headers);
  45. raw_ptr<content::BrowserContext> browser_context_;
  46. content::WebContents::Getter web_contents_getter_;
  47. net::HttpRequestHeaders request_headers_;
  48. GURL request_url_;
  49. bool is_main_frame_ = false;
  50. bool response_header_processed_ = false;
  51. };
  52. } // namespace weblayer
  53. #endif // WEBLAYER_BROWSER_SIGNIN_URL_LOADER_THROTTLE_H_