url_utils.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright 2014 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_DOM_DISTILLER_CORE_URL_UTILS_H_
  5. #define COMPONENTS_DOM_DISTILLER_CORE_URL_UTILS_H_
  6. #include <string>
  7. #include "base/strings/string_piece_forward.h"
  8. class GURL;
  9. namespace dom_distiller {
  10. namespace url_utils {
  11. // Returns the URL for viewing distilled content for an entry.
  12. // This is only used for testing.
  13. const GURL GetDistillerViewUrlFromEntryId(const std::string& scheme,
  14. const std::string& entry_id);
  15. // Returns the URL for viewing distilled content for |view_url|. This URL should
  16. // not be displayed to end users (except in DevTools and view-source). Instead,
  17. // users should always be shown the original page URL minus the http or https
  18. // scheme in the omnibox (i.e. in LocationBarModel::GetFormattedURL()).
  19. // A distilled page's true URL, the distiller view URL, should be returned
  20. // from WebContents::GetLastCommittedURL() and WebContents::GetVisibleURL().
  21. // This has the chrome-distiller scheme and the form
  22. // chrome-distiller://<hash>?<params>, where <params> are generated from
  23. // |view_url| and |start_time_ms|.
  24. const GURL GetDistillerViewUrlFromUrl(const std::string& scheme,
  25. const GURL& view_url,
  26. const std::string& title,
  27. int64_t start_time_ms = 0);
  28. // Returns the original article's URL from the distilled URL.
  29. // If |distilled_url| is not distilled, it is returned as is.
  30. // If |distilled_url| looks like distilled, but no original URL can be found,
  31. // an empty, invalid URL is returned.
  32. const GURL GetOriginalUrlFromDistillerUrl(const GURL& distilled_url);
  33. // Returns the starting time from the distilled URL.
  34. // Returns 0 when not available or on error.
  35. int64_t GetTimeFromDistillerUrl(const GURL& url);
  36. // Returns the title of the original page from the distilled URL. Returns an
  37. // empty string if not available or on error.
  38. std::string GetTitleFromDistillerUrl(const GURL& url);
  39. // Returns the value of the query parameter for the given |key| for a given URL.
  40. // If the URL is invalid or if the key is not found, returns an empty string.
  41. // If there are multiple keys found in the URL, returns the value for the first
  42. // key.
  43. std::string GetValueForKeyInUrl(const GURL& url, const std::string& key);
  44. // Returns the value of the query parameter for the given path.
  45. std::string GetValueForKeyInUrlPathQuery(const std::string& path,
  46. const std::string& key);
  47. // Returns whether it should be possible to distill the given |url|.
  48. bool IsUrlDistillable(const GURL& url);
  49. // Returns whether the given |url| is for a distilled page. This means the
  50. // format of the URL is proper for a distilled page and that it encodes a
  51. // valid article URL.
  52. bool IsDistilledPage(const GURL& url);
  53. // Returns whether the given |url| is formatted as if it were for a distilled
  54. // page, i.e. it is valid and has a chrome-distiller:// scheme.
  55. bool IsUrlDistilledFormat(const GURL& url);
  56. } // namespace url_utils
  57. } // namespace dom_distiller
  58. #endif // COMPONENTS_DOM_DISTILLER_CORE_URL_UTILS_H_