Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Unified Diff: ios/web/history_state_util.mm

Issue 988383002: Upstream various ios/web utilities and helpers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@web-public-upstreaming
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/web/history_state_util.mm
diff --git a/ios/web/history_state_util.mm b/ios/web/history_state_util.mm
new file mode 100644
index 0000000000000000000000000000000000000000..bdb11bce32bd95b82d608ffe1d2d0666e19ffa39
--- /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

Powered by Google App Engine
This is Rietveld 408576698