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

Side by Side Diff: url/origin.cc

Issue 1726323002: Have Permission{Manager,Service} use Origin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Blimp interface. Created 4 years, 9 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
« url/origin.h ('K') | « url/origin.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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 #include "url/origin.h" 5 #include "url/origin.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "url/gurl.h" 12 #include "url/gurl.h"
13 #include "url/url_canon.h" 13 #include "url/url_canon.h"
14 #include "url/url_canon_stdstring.h" 14 #include "url/url_canon_stdstring.h"
15 #include "url/url_constants.h" 15 #include "url/url_constants.h"
16 #include "url/url_util.h" 16 #include "url/url_util.h"
17 17
18 namespace url { 18 namespace url {
19 19
20 Origin::Origin() : unique_(true) { 20 Origin::Origin() : unique_(true), empty_(true) {}
21 }
22 21
23 Origin::Origin(const GURL& url) : unique_(true) { 22 Origin::Origin(const GURL& url) : unique_(true), empty_(url.is_empty()) {
24 if (!url.is_valid() || (!url.IsStandard() && !url.SchemeIsBlob())) 23 if (!url.is_valid() || (!url.IsStandard() && !url.SchemeIsBlob()))
25 return; 24 return;
26 25
27 if (url.SchemeIsFileSystem()) { 26 if (url.SchemeIsFileSystem()) {
28 tuple_ = SchemeHostPort(*url.inner_url()); 27 tuple_ = SchemeHostPort(*url.inner_url());
29 } else if (url.SchemeIsBlob()) { 28 } else if (url.SchemeIsBlob()) {
30 // If we're dealing with a 'blob:' URL, https://url.spec.whatwg.org/#origin 29 // If we're dealing with a 'blob:' URL, https://url.spec.whatwg.org/#origin
31 // defines the origin as the origin of the URL which results from parsing 30 // defines the origin as the origin of the URL which results from parsing
32 // the "path", which boils down to everything after the scheme. GURL's 31 // the "path", which boils down to everything after the scheme. GURL's
33 // 'GetContent()' gives us exactly that. 32 // 'GetContent()' gives us exactly that.
34 tuple_ = SchemeHostPort(GURL(url.GetContent())); 33 tuple_ = SchemeHostPort(GURL(url.GetContent()));
35 } else { 34 } else {
36 tuple_ = SchemeHostPort(url); 35 tuple_ = SchemeHostPort(url);
37 } 36 }
38 37
39 unique_ = tuple_.IsInvalid(); 38 unique_ = tuple_.IsInvalid();
40 } 39 }
41 40
41 Origin::Origin(const std::string& url_string) : Origin(GURL(url_string)) {}
42
42 Origin::Origin(base::StringPiece scheme, base::StringPiece host, uint16_t port) 43 Origin::Origin(base::StringPiece scheme, base::StringPiece host, uint16_t port)
43 : tuple_(scheme, host, port) { 44 : tuple_(scheme, host, port) {
44 unique_ = tuple_.IsInvalid(); 45 unique_ = tuple_.IsInvalid();
45 } 46 }
46 47
47 Origin::~Origin() { 48 Origin::~Origin() {
48 } 49 }
49 50
50 // static 51 // static
51 Origin Origin::UnsafelyCreateOriginWithoutNormalization( 52 Origin Origin::UnsafelyCreateOriginWithoutNormalization(
(...skipping 26 matching lines...) Expand all
78 79
79 std::ostream& operator<<(std::ostream& out, const url::Origin& origin) { 80 std::ostream& operator<<(std::ostream& out, const url::Origin& origin) {
80 return out << origin.Serialize(); 81 return out << origin.Serialize();
81 } 82 }
82 83
83 bool IsSameOriginWith(const GURL& a, const GURL& b) { 84 bool IsSameOriginWith(const GURL& a, const GURL& b) {
84 return Origin(a).IsSameOriginWith(Origin(b)); 85 return Origin(a).IsSameOriginWith(Origin(b));
85 } 86 }
86 87
87 } // namespace url 88 } // namespace url
OLDNEW
« url/origin.h ('K') | « url/origin.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698