OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "url/origin.h" | |
6 | |
7 #include <string.h> | |
8 | |
9 #include "base/logging.h" | |
10 #include "base/strings/string_number_conversions.h" | |
11 #include "url/gurl.h" | |
12 #include "url/url_canon.h" | |
13 #include "url/url_canon_stdstring.h" | |
14 #include "url/url_constants.h" | |
15 #include "url/url_util.h" | |
16 | |
17 namespace url { | |
18 | |
19 Origin::Origin() : unique_(true) { | |
20 } | |
21 | |
22 Origin::Origin(const GURL& url) : unique_(true) { | |
23 if (!url.is_valid() || (!url.IsStandard() && !url.SchemeIsBlob())) | |
24 return; | |
25 | |
26 if (url.SchemeIsFileSystem()) { | |
27 tuple_ = url::SchemeHostPort(*url.inner_url()); | |
28 } else if (url.SchemeIsBlob()) { | |
29 // TODO(mkwst): This relies on the fact that GURL pushes the unparseable | |
30 // bits and pieces of a non-standard scheme into the GURL's path. It seems | |
31 // fairly fragile, so it might be worth teaching GURL about blobs' data in | |
32 // the same way we've taught it about filesystems' inner URLs. | |
33 // | |
34 // Alternatively, we could just do what the URL spec says, which boils down | |
35 // 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
| |
36 tuple_ = url::SchemeHostPort(GURL(url.path())); | |
37 } else { | |
38 tuple_ = url::SchemeHostPort(url); | |
39 } | |
40 | |
41 unique_ = tuple_.IsInvalid(); | |
42 } | |
43 | |
44 Origin::~Origin() { | |
45 } | |
46 | |
47 std::string Origin::Serialize() const { | |
48 if (unique()) | |
49 return "null"; | |
50 | |
51 if (scheme() == kFileScheme) | |
52 return "file://"; | |
53 | |
54 return tuple_.Serialize(); | |
55 } | |
56 | |
57 bool Origin::IsSameOriginWith(const Origin& other) const { | |
58 if (unique_ || other.unique_) | |
59 return false; | |
60 | |
61 return tuple_.Equals(other.tuple_); | |
62 } | |
63 | |
64 bool Origin::operator<(const Origin& other) const { | |
65 return tuple_ < other.tuple_; | |
66 } | |
67 bool Origin::operator>(const Origin& other) const { | |
68 return tuple_ > other.tuple_; | |
69 } | |
70 | |
71 } // namespace url | |
OLD | NEW |