OLD | NEW |
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 "mojo/shell/identity.h" | 5 #include "mojo/shell/identity.h" |
6 | 6 |
7 #include "mojo/shell/query_util.h" | 7 #include "mojo/shell/query_util.h" |
8 | 8 |
9 namespace mojo { | 9 namespace mojo { |
10 namespace shell { | 10 namespace shell { |
| 11 namespace { |
11 | 12 |
12 Identity::Identity() {} | 13 // It's valid to specify mojo: URLs in the filter either as mojo:foo or |
| 14 // mojo://foo/ - but we store the filter in the latter form. |
| 15 CapabilityFilter CanonicalizeFilter(const CapabilityFilter& filter) { |
| 16 CapabilityFilter canonicalized; |
| 17 for (CapabilityFilter::const_iterator it = filter.begin(); |
| 18 it != filter.end(); |
| 19 ++it) { |
| 20 if (it->first == "*") |
| 21 canonicalized[it->first] = it->second; |
| 22 else |
| 23 canonicalized[GURL(it->first).spec()] = it->second; |
| 24 } |
| 25 return canonicalized; |
| 26 } |
| 27 |
| 28 } // namespace |
| 29 |
| 30 Identity::Identity() : filter_(GetPermissiveCapabilityFilter()) {} |
| 31 |
| 32 Identity::Identity(const GURL& in_url) |
| 33 : url(GetBaseURLAndQuery(in_url, nullptr)), |
| 34 qualifier(url.spec()), |
| 35 filter_(GetPermissiveCapabilityFilter()) {} |
13 | 36 |
14 Identity::Identity(const GURL& in_url, const std::string& in_qualifier) | 37 Identity::Identity(const GURL& in_url, const std::string& in_qualifier) |
15 : url(GetBaseURLAndQuery(in_url, nullptr)), | 38 : url(GetBaseURLAndQuery(in_url, nullptr)), |
16 qualifier(in_qualifier.empty() ? url.spec() : in_qualifier) {} | 39 qualifier(in_qualifier.empty() ? url.spec() : in_qualifier), |
| 40 filter_(GetPermissiveCapabilityFilter()) {} |
17 | 41 |
18 // explicit | 42 Identity::Identity(const GURL& in_url, |
19 Identity::Identity(const GURL& in_url) | 43 const std::string& in_qualifier, |
20 : url(GetBaseURLAndQuery(in_url, nullptr)), qualifier(url.spec()) {} | 44 CapabilityFilter filter) |
| 45 : url(GetBaseURLAndQuery(in_url, nullptr)), |
| 46 qualifier(in_qualifier.empty() ? url.spec() : in_qualifier), |
| 47 filter_(CanonicalizeFilter(filter)) {} |
| 48 |
| 49 Identity::~Identity() {} |
21 | 50 |
22 bool Identity::operator<(const Identity& other) const { | 51 bool Identity::operator<(const Identity& other) const { |
| 52 // We specifically don't include filter in the equivalence check because we |
| 53 // don't quite know how this should work yet. |
| 54 // TODO(beng): figure out how it should work. |
23 if (url != other.url) | 55 if (url != other.url) |
24 return url < other.url; | 56 return url < other.url; |
25 return qualifier < other.qualifier; | 57 return qualifier < other.qualifier; |
26 } | 58 } |
27 | 59 |
| 60 void Identity::SetFilter(const CapabilityFilter& filter) { |
| 61 filter_ = CanonicalizeFilter(filter); |
| 62 } |
| 63 |
28 } // namespace shell | 64 } // namespace shell |
29 } // namespace mojo | 65 } // namespace mojo |
OLD | NEW |