summaryrefslogtreecommitdiffstats
path: root/ios/web/history_state_util.mm
blob: bdb11bce32bd95b82d608ffe1d2d0666e19ffa39 (plain)
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.

#import "ios/web/history_state_util.h"

#include "base/logging.h"
#include "url/gurl.h"

namespace web {
namespace history_state_util {

bool IsHistoryStateChangeValid(const GURL& currentUrl,
                               const GURL& toUrl) {
  // 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(currentUrl.is_valid());
  CHECK(toUrl.is_valid());

  return toUrl.GetOrigin() == currentUrl.GetOrigin();
}

GURL GetHistoryStateChangeUrl(const GURL& currentUrl,
                              const GURL& baseUrl,
                              const std::string& destination) {
  if (!baseUrl.is_valid())
    return GURL();
  GURL toUrl = baseUrl.Resolve(destination);

  if (!toUrl.is_valid() || !IsHistoryStateChangeValid(currentUrl, toUrl))
    return GURL();

  return toUrl;
}

}  // namespace history_state_util
}  // namespace web