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

Side by Side Diff: url/origin.h

Issue 1151843002: DO NOT LAND Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More. Created 5 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef URL_ORIGIN_H_ 5 #ifndef URL_ORIGIN_H_
6 #define URL_ORIGIN_H_ 6 #define URL_ORIGIN_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "url/gurl.h"
10 #include "url/url_export.h" 11 #include "url/url_export.h"
11 12
12 namespace url { 13 namespace url {
13 14
14 // Origin represents a Web Origin serialized to a string. 15 // Origin represents a scheme/host/port tuple, as described in RFC6454.
15 // See RFC6454 for details.
16 class URL_EXPORT Origin { 16 class URL_EXPORT Origin {
17 public: 17 public:
18 // Creates a unique Origin. Note that unique origins are not == to _any_
19 // other origin, including themselves.
18 Origin(); 20 Origin();
21
22 explicit Origin(const GURL& url);
19 explicit Origin(const std::string& origin); 23 explicit Origin(const std::string& origin);
Ryan Sleevi 2015/05/22 02:50:03 Not a fan of having a string constructor - gives u
20 24
21 const std::string& string() const { return string_; } 25 bool SchemeIs(const std::string& scheme) const;
22 26 bool SchemeIsCryptographic() const {
23 bool IsSameAs(const Origin& that) const { 27 return SchemeIs("https") || SchemeIs("wss");
24 return string_ == that.string_;
25 } 28 }
26 29
30 std::string scheme() const { return scheme_; }
31 std::string host() const { return host_; }
32 unsigned short port() const { return port_; }
33 bool unique() const { return unique_; }
34
35 // Returns a serialization of the origin, suitable for passing around via IPC.
36 // This is _not_ the serialization of the origin which ought to be displayed
37 // to a user in Chrome's UI.
38 std::string serialize() const;
39
40 // TODO(mkwst): Remove this.
41 std::string string() const { return serialize(); }
Ryan Sleevi 2015/05/22 02:50:03 Generally not a fan of classes managing their own
42
43 bool operator==(const Origin& other) const;
44 bool operator!=(const Origin& other) const;
Ryan Sleevi 2015/05/22 02:50:03 Blink vs Chrome will strike again - http://google-
45
27 private: 46 private:
47 void Init(const GURL& url);
48
49 std::string scheme_;
50 std::string host_;
51 unsigned short port_;
52 bool unique_;
53 bool is_default_port_;
54
28 std::string string_; 55 std::string string_;
29 }; 56 };
30 57
58 // Stream operator so Origin can be used in assertion statements.
59 URL_EXPORT std::ostream& operator<<(std::ostream& out, const url::Origin& url);
60
31 } // namespace url 61 } // namespace url
32 62
33 #endif // URL_ORIGIN_H_ 63 #endif // URL_ORIGIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698