extension_url_loader_throttle.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright 2018 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 EXTENSIONS_RENDERER_EXTENSION_URL_LOADER_THROTTLE_H_
  5. #define EXTENSIONS_RENDERER_EXTENSION_URL_LOADER_THROTTLE_H_
  6. #include <string>
  7. #include <vector>
  8. #include "third_party/blink/public/common/loader/url_loader_throttle.h"
  9. #include "url/gurl.h"
  10. namespace extensions {
  11. class ExtensionThrottleManager;
  12. // This class monitors requests issued by extensions and throttles the request
  13. // if there are too many requests made within a short time to urls with the same
  14. // scheme, host, port and path. For the exact criteria for throttling, please
  15. // also see extension_throttle_manager.cc.
  16. class ExtensionURLLoaderThrottle : public blink::URLLoaderThrottle {
  17. public:
  18. explicit ExtensionURLLoaderThrottle(ExtensionThrottleManager* manager);
  19. ExtensionURLLoaderThrottle(const ExtensionURLLoaderThrottle&) = delete;
  20. ExtensionURLLoaderThrottle& operator=(const ExtensionURLLoaderThrottle&) =
  21. delete;
  22. ~ExtensionURLLoaderThrottle() override;
  23. // blink::URLLoaderThrottle:
  24. void WillStartRequest(network::ResourceRequest* request,
  25. bool* defer) override;
  26. void WillRedirectRequest(
  27. net::RedirectInfo* redirect_info,
  28. const network::mojom::URLResponseHead& response_head,
  29. bool* defer,
  30. std::vector<std::string>* to_be_removed_request_headers,
  31. net::HttpRequestHeaders* modified_request_headers,
  32. net::HttpRequestHeaders* modified_cors_exempt_request_headers) override;
  33. void WillProcessResponse(const GURL& response_url,
  34. network::mojom::URLResponseHead* response_head,
  35. bool* defer) override;
  36. private:
  37. // blink::URLLoaderThrottle:
  38. void DetachFromCurrentSequence() override;
  39. ExtensionThrottleManager* manager_ = nullptr;
  40. GURL start_request_url_;
  41. };
  42. } // namespace extensions
  43. #endif // EXTENSIONS_RENDERER_EXTENSION_URL_LOADER_THROTTLE_H_