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

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: Compile fix Created 4 years, 3 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: content/common/origin_util.cc
diff --git a/content/common/origin_util.cc b/content/common/origin_util.cc
index 11873d63cfd9de6f8b7b2c4592d785abef089e42..7db0b2d620f299fc284c522fd4d91bd014793909 100644
--- a/content/common/origin_util.cc
+++ b/content/common/origin_util.cc
@@ -8,8 +8,10 @@
#include "base/macros.h"
#include "base/stl_util.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 +92,56 @@ 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;
+ }
+
+ std::string host = url.host();
nasko 2016/09/29 16:49:55 minor nit: I don't know how perf sensitive this ca
jww 2016/09/29 22:21:00 Done.
+
+ // This means that there is no suborigin before the dot, so there is no
nasko 2016/09/29 16:49:56 Technically it means there is no dot at all : ).
jww 2016/09/29 22:21:00 I don't understand. Are you referring to the fact
nasko 2016/09/30 17:40:07 I read the code with the interpretation that it is
+ // suborigin.
+ if (host.find('.') == 0)
nasko 2016/09/29 16:49:56 s/0/string::npos/?
jww 2016/09/29 22:21:00 See above response. I did intend for this to check
+ 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 (host.find('.') == (host.size() - 1))
nasko 2016/09/29 16:49:56 You could store the result of find from above and
jww 2016/09/29 22:21:00 Done.
+ return false;
+
+ return true;
+}
+
+std::string SuboriginFromUrl(const GURL& url) {
+ if (!HasSuborigin(url))
+ return "";
+
+ size_t suborigin_end = url.host().find(".");
+ return url.host().substr(0, suborigin_end);
nasko 2016/09/29 16:49:56 Check suborigin_end for equality of string::npos a
jww 2016/09/29 22:21:00 Done.
+}
+
+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);
+ }
+
+ size_t suborigin_end = url.host().find(".");
nasko 2016/09/29 16:49:56 Again, check for string::npos.
jww 2016/09/29 22:21:00 Done.
+ std::string new_host(url.host().substr(
+ suborigin_end + 1, url.host().length() - suborigin_end - 1));
+ replacements.SetHostStr(new_host);
+
+ return url.ReplaceComponents(replacements);
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698