summaryrefslogtreecommitdiffstats
path: root/ios/web/history_state_util.mm
diff options
context:
space:
mode:
authorstuartmorgan <stuartmorgan@chromium.org>2015-03-09 12:19:15 -0700
committerCommit bot <commit-bot@chromium.org>2015-03-09 19:20:11 +0000
commitfc8c88d3db12845eb0b6c31f754f8664ba6466fe (patch)
treebdd66ee1c928032cd196c194f8f7d8730aab0572 /ios/web/history_state_util.mm
parent32af42a8103c97258a0eca1ec7255e7a849b82aa (diff)
downloadchromium_src-fc8c88d3db12845eb0b6c31f754f8664ba6466fe.zip
chromium_src-fc8c88d3db12845eb0b6c31f754f8664ba6466fe.tar.gz
chromium_src-fc8c88d3db12845eb0b6c31f754f8664ba6466fe.tar.bz2
Upstream various ios/web utilities and helpers
Upstreams miscellaneous helper classes and utility files that don't have other dependencies, and can thus be built and tested as-is. BUG=464810 Review URL: https://codereview.chromium.org/988383002 Cr-Commit-Position: refs/heads/master@{#319706}
Diffstat (limited to 'ios/web/history_state_util.mm')
-rw-r--r--ios/web/history_state_util.mm37
1 files changed, 37 insertions, 0 deletions
diff --git a/ios/web/history_state_util.mm b/ios/web/history_state_util.mm
new file mode 100644
index 0000000..bdb11bce
--- /dev/null
+++ b/ios/web/history_state_util.mm
@@ -0,0 +1,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