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

Unified Diff: content/common/origin_util.cc

Issue 2005783005: Re-enable storage for Suborigins. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Rebase on ToT Created 4 years, 2 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
« no previous file with comments | « content/browser/dom_storage/dom_storage_context_impl.cc ('k') | content/common/origin_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/common/origin_util.cc
diff --git a/content/common/origin_util.cc b/content/common/origin_util.cc
index 11873d63cfd9de6f8b7b2c4592d785abef089e42..4af685acc31a38c9b8164e6f4c90eebdd5f2ac4d 100644
--- a/content/common/origin_util.cc
+++ b/content/common/origin_util.cc
@@ -4,12 +4,17 @@
#include "content/public/common/origin_util.h"
+#include <string>
+
#include "base/lazy_instance.h"
#include "base/macros.h"
#include "base/stl_util.h"
+#include "base/strings/string_piece.h"
#include "content/public/common/content_client.h"
+#include "content/public/common/url_constants.h"
#include "net/base/url_util.h"
#include "url/gurl.h"
+#include "url/url_constants.h"
namespace content {
@@ -90,4 +95,63 @@ void ResetSchemesAndOriginsWhitelistForTesting() {
g_trustworthy_whitelist.Get().Reset();
}
+bool HasSuborigin(const GURL& url) {
+ if (!url.is_valid())
+ return false;
+
+ if (url.scheme() != kHttpSuboriginScheme &&
+ url.scheme() != kHttpsSuboriginScheme) {
+ return false;
+ }
+
+ base::StringPiece host_piece = url.host_piece();
+ size_t first_period = host_piece.find('.');
+
+ // If the first period is the first position in the hostname, or there is no
+ // period at all, there is no suborigin serialized in the hostname.
+ if (first_period == 0 || first_period == base::StringPiece::npos)
+ return false;
+
+ // If there's nothing after the first dot, then there is no host for the
+ // physical origin, which is not a valid suborigin serialization.
+ if (first_period == (host_piece.size() - 1))
+ return false;
+
+ return true;
+}
+
+std::string SuboriginFromUrl(const GURL& url) {
+ if (!HasSuborigin(url))
+ return "";
+
+ std::string host = url.host();
+ size_t suborigin_end = host.find(".");
+ return (suborigin_end == std::string::npos) ? ""
+ : host.substr(0, suborigin_end);
+}
+
+GURL StripSuboriginFromUrl(const GURL& url) {
+ if (!HasSuborigin(url))
+ return url;
+
+ GURL::Replacements replacements;
+ if (url.scheme() == kHttpSuboriginScheme) {
+ replacements.SetSchemeStr(url::kHttpScheme);
+ } else {
+ DCHECK(url.scheme() == kHttpsSuboriginScheme);
+ replacements.SetSchemeStr(url::kHttpsScheme);
+ }
+
+ std::string host = url.host();
+ size_t suborigin_end = host.find(".");
+ std::string new_host(
+ (suborigin_end == std::string::npos)
+ ? ""
+ : host.substr(suborigin_end + 1,
+ url.host().length() - suborigin_end - 1));
+ replacements.SetHostStr(new_host);
+
+ return url.ReplaceComponents(replacements);
+}
+
} // namespace content
« no previous file with comments | « content/browser/dom_storage/dom_storage_context_impl.cc ('k') | content/common/origin_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698