#include "ios/web/history_state_util.h"
#include "base/check.h"
#include "url/gurl.h"
namespace web {
namespace history_state_util {
bool IsHistoryStateChangeValid(const GURL& current_url, const GURL& to_url) {
CHECK(current_url.is_valid());
CHECK(to_url.is_valid());
return to_url.DeprecatedGetOriginAsURL() ==
current_url.DeprecatedGetOriginAsURL();
}
GURL GetHistoryStateChangeUrl(const GURL& current_url,
const GURL& base_url,
std::string_view destination) {
if (!base_url.is_valid()) {
return GURL();
}
GURL to_url = base_url.Resolve(destination);
if (!to_url.is_valid() || !IsHistoryStateChangeValid(current_url, to_url)) {
return GURL();
}
return to_url;
}
}
}