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

Side by Side Diff: url/origin.cc

Issue 1224293002: Introduce 'url::Origin'. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@url-schemehostport
Patch Set: Jochen. 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 unified diff | Download patch
OLDNEW
(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;
brettw 2015/07/21 21:27:44 Indenting.
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 it's been taught about filesystems' inner URLs.
33 tuple_ = url::SchemeHostPort(GURL(url.path()));
34 } else {
35 tuple_ = url::SchemeHostPort(url);
36 }
37
38 unique_ = tuple_.IsInvalid();
39 }
40
41 Origin::~Origin() {
42 }
43
44 std::string Origin::Serialize() const {
45 if (unique())
46 return "null";
47
48 if (scheme() == kFileScheme)
49 return "file://";
50
51 return tuple_.Serialize();
52 }
53
54 bool Origin::IsSameOriginWith(const Origin& other) const {
55 if (unique_ || other.unique_)
56 return false;
57
58 return tuple_.Equals(other.tuple_);
59 }
60
61 bool Origin::operator<(const Origin& other) const {
62 return tuple_ < other.tuple_;
63 }
64
65 std::ostream& operator<<(std::ostream& out, const url::Origin& origin) {
66 return out << origin.Serialize().c_str();
Ryan Sleevi 2015/07/20 21:11:43 Why .c_str()? Why not just << and let the default
67 }
68
69 } // namespace url
OLDNEW
« 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