forked from Pissandshittium/pissandshittium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhistory_state_util.cc
37 lines (28 loc) · 1.09 KB
/
history_state_util.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#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) {
// These two checks are very important to the security of the page. We cannot
// allow the page to change the state to an invalid 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,
const std::string& 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;
}
} // namespace history_state_util
} // namespace web