url_param_filterer.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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_URL_PARAM_FILTER_CORE_URL_PARAM_FILTERER_H_
  5. #define COMPONENTS_URL_PARAM_FILTER_CORE_URL_PARAM_FILTERER_H_
  6. #include "components/url_param_filter/core/url_param_classifications_loader.h"
  7. #include "components/url_param_filter/core/url_param_filter_classification.pb.h"
  8. #include "url/gurl.h"
  9. // Used to filter URL parameters based on backend classification rules. Note
  10. // that all functions, unless otherwise specified, do not normalize the query
  11. // string.
  12. namespace url_param_filter {
  13. namespace internal {
  14. // Given a URL, get the label just to the left of the site's eTLD (e.g.
  15. // subdomain.site.co.uk -> site). Returns `absl::nullopt` for IP addresses,
  16. // URLs that do not have hostnames, and other parsing errors.
  17. absl::optional<std::string> GetLabelFromHostname(const GURL& gurl);
  18. } // namespace internal
  19. // Represents the result of filtering; includes the resulting URL (which may be
  20. // unmodified), along with the count of params filtered.
  21. struct FilterResult {
  22. GURL filtered_url;
  23. int filtered_param_count;
  24. ClassificationExperimentStatus experimental_status;
  25. };
  26. // Filter the destination URL according to the parameter classifications for the
  27. // source and destination URLs. Used internally by the 2-arg overload, and
  28. // called directly from tests.
  29. // Currently experimental; not intended for broad consumption.
  30. FilterResult FilterUrl(const GURL& source_url,
  31. const GURL& destination_url,
  32. const ClassificationMap& classifications,
  33. const FilterClassification::UseCase use_case);
  34. // Filter the destination URL according to the default parameter classifications
  35. // for the source and destination URLs. Equivalent to calling the three-arg
  36. // version with a `use_case` of `UNKNOWN`. This overload is included for
  37. // backward compatibility and will be removed.
  38. // Currently experimental; not intended for broad consumption.
  39. FilterResult FilterUrl(const GURL& source_url, const GURL& destination_url);
  40. // Filter the destination URL according to the default parameter classifications
  41. // for the source and destination URLs, only if the classifications include the
  42. // passed-in `UseCase`.
  43. // Currently experimental; not intended for broad consumption.
  44. FilterResult FilterUrl(const GURL& source_url,
  45. const GURL& destination_url,
  46. const FilterClassification::UseCase use_case);
  47. } // namespace url_param_filter
  48. #endif // COMPONENTS_URL_PARAM_FILTER_CORE_URL_PARAM_FILTERER_H_