history_state_util.cc 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright 2012 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. #include "ios/web/history_state_util.h"
  5. #include "base/check.h"
  6. #include "url/gurl.h"
  7. namespace web {
  8. namespace history_state_util {
  9. bool IsHistoryStateChangeValid(const GURL& current_url, const GURL& to_url) {
  10. // These two checks are very important to the security of the page. We cannot
  11. // allow the page to change the state to an invalid URL.
  12. CHECK(current_url.is_valid());
  13. CHECK(to_url.is_valid());
  14. return to_url.DeprecatedGetOriginAsURL() ==
  15. current_url.DeprecatedGetOriginAsURL();
  16. }
  17. GURL GetHistoryStateChangeUrl(const GURL& current_url,
  18. const GURL& base_url,
  19. const std::string& destination) {
  20. if (!base_url.is_valid())
  21. return GURL();
  22. GURL to_url = base_url.Resolve(destination);
  23. if (!to_url.is_valid() || !IsHistoryStateChangeValid(current_url, to_url))
  24. return GURL();
  25. return to_url;
  26. }
  27. } // namespace history_state_util
  28. } // namespace web