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

Unified Diff: origin.cc

Issue 2029803003: Update to Chromium //url at Chromium commit 79dc59ac7602413181079ecb463873e29a1d7d0a. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/domokit/gurl@master
Patch Set: Created 4 years, 7 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 | « origin.h ('k') | origin_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: origin.cc
diff --git a/origin.cc b/origin.cc
index cebf5dd85f430e086709c7b2240a2b988f6f2ced..9d0c4f08de0165e3a201408f22c8778d5b4acf4e 100644
--- a/origin.cc
+++ b/origin.cc
@@ -1,20 +1,82 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
+// Copyright 2015 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.
#include "url/origin.h"
+#include <string.h>
+
#include "base/logging.h"
-#include "base/strings/pattern.h"
+#include "base/strings/string_number_conversions.h"
+#include "url/gurl.h"
+#include "url/url_canon.h"
+#include "url/url_canon_stdstring.h"
+#include "url/url_constants.h"
+#include "url/url_util.h"
namespace url {
-Origin::Origin() : string_("null") {}
+Origin::Origin() : unique_(true) {
+}
+
+Origin::Origin(const GURL& url) : unique_(true) {
+ if (!url.is_valid() || (!url.IsStandard() && !url.SchemeIsBlob()))
+ return;
+
+ if (url.SchemeIsFileSystem()) {
+ tuple_ = SchemeHostPort(*url.inner_url());
+ } else if (url.SchemeIsBlob()) {
+ // If we're dealing with a 'blob:' URL, https://url.spec.whatwg.org/#origin
+ // defines the origin as the origin of the URL which results from parsing
+ // the "path", which boils down to everything after the scheme. GURL's
+ // 'GetContent()' gives us exactly that.
+ tuple_ = SchemeHostPort(GURL(url.GetContent()));
+ } else {
+ tuple_ = SchemeHostPort(url);
+ }
+
+ unique_ = tuple_.IsInvalid();
+}
+
+Origin::Origin(base::StringPiece scheme, base::StringPiece host, uint16 port)
+ : tuple_(scheme, host, port) {
+ unique_ = tuple_.IsInvalid();
+}
+
+Origin::~Origin() {
+}
+
+// static
+Origin Origin::UnsafelyCreateOriginWithoutNormalization(
+ base::StringPiece scheme,
+ base::StringPiece host,
+ uint16 port) {
+ return Origin(scheme, host, port);
+}
+
+std::string Origin::Serialize() const {
+ if (unique())
+ return "null";
+
+ if (scheme() == kFileScheme)
+ return "file://";
+
+ return tuple_.Serialize();
+}
+
+bool Origin::IsSameOriginWith(const Origin& other) const {
+ if (unique_ || other.unique_)
+ return false;
+
+ return tuple_.Equals(other.tuple_);
+}
+
+bool Origin::operator<(const Origin& other) const {
+ return tuple_ < other.tuple_;
+}
-Origin::Origin(const std::string& origin) : string_(origin) {
- DCHECK(origin == "null" || base::MatchPattern(origin, "?*://?*"));
- DCHECK_GT(origin.size(), 0u);
- DCHECK(origin == "file://" || origin[origin.size() - 1] != '/');
+std::ostream& operator<<(std::ostream& out, const url::Origin& origin) {
+ return out << origin.Serialize();
}
} // namespace url
« no previous file with comments | « origin.h ('k') | origin_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698