Index: url/origin.cc |
diff --git a/url/origin.cc b/url/origin.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..96af38bbb0eab1e25ee6ac1fdb7dd20094bc609b |
--- /dev/null |
+++ b/url/origin.cc |
@@ -0,0 +1,71 @@ |
+// 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_ = url::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 we've taught it about filesystems' inner URLs. |
+ // |
+ // Alternatively, we could just do what the URL spec says, which boils down |
+ // to parsing the URL after stripping off the scheme. |
Ryan Sleevi
2015/07/10 11:59:53
something something "we" in comments.
But more im
Mike West
2015/07/17 09:58:09
Something something I (we!) still think that's a t
|
+ tuple_ = url::SchemeHostPort(GURL(url.path())); |
+ } else { |
+ tuple_ = url::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_; |
+} |
+bool Origin::operator>(const Origin& other) const { |
+ return tuple_ > other.tuple_; |
+} |
+ |
+} // namespace url |