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

Unified Diff: url/origin.cc

Issue 1224293002: Introduce 'url::Origin'. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@url-schemehostport
Patch Set: Nits. Created 5 years, 5 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
« url/origin.h ('K') | « url/origin.h ('k') | url/origin_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: url/origin.cc
diff --git a/url/origin.cc b/url/origin.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e80eb72b9b3a8e730948d4da7f30269cbec8a685
--- /dev/null
+++ b/url/origin.cc
@@ -0,0 +1,69 @@
+// 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/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() : 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()) {
+ // TODO(mkwst): This relies on the fact that GURL pushes the unparseable
+ // bits and pieces of a non-standard scheme into the GURL's path. It seems
+ // fairly fragile, so it might be worth teaching GURL about blobs' data in
+ // the same way it's been taught about filesystems' inner URLs.
+ tuple_ = SchemeHostPort(GURL(url.path()));
+ } else {
+ tuple_ = SchemeHostPort(url);
+ }
+
+ unique_ = tuple_.IsInvalid();
+}
+
+Origin::~Origin() {
+}
+
+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_;
+}
+
+std::ostream& operator<<(std::ostream& out, const url::Origin& origin) {
+ return out << origin.Serialize();
+}
+
+} // namespace url
« url/origin.h ('K') | « url/origin.h ('k') | url/origin_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698