OLD | NEW |
| (Empty) |
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 | |
5 #import "ios/web/history_state_util.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "url/gurl.h" | |
9 | |
10 namespace web { | |
11 namespace history_state_util { | |
12 | |
13 bool IsHistoryStateChangeValid(const GURL& currentUrl, | |
14 const GURL& toUrl) { | |
15 // These two checks are very important to the security of the page. We cannot | |
16 // allow the page to change the state to an invalid URL. | |
17 CHECK(currentUrl.is_valid()); | |
18 CHECK(toUrl.is_valid()); | |
19 | |
20 return toUrl.GetOrigin() == currentUrl.GetOrigin(); | |
21 } | |
22 | |
23 GURL GetHistoryStateChangeUrl(const GURL& currentUrl, | |
24 const GURL& baseUrl, | |
25 const std::string& destination) { | |
26 if (!baseUrl.is_valid()) | |
27 return GURL(); | |
28 GURL toUrl = baseUrl.Resolve(destination); | |
29 | |
30 if (!toUrl.is_valid() || !IsHistoryStateChangeValid(currentUrl, toUrl)) | |
31 return GURL(); | |
32 | |
33 return toUrl; | |
34 } | |
35 | |
36 } // namespace history_state_util | |
37 } // namespace web | |
OLD | NEW |