| 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/public/cpp/names.h" |
| 7 #include "mojo/shell/public/interfaces/shell.mojom.h" | 8 #include "mojo/shell/public/interfaces/shell.mojom.h" |
| 8 | 9 |
| 9 namespace mojo { | 10 namespace mojo { |
| 10 namespace shell { | 11 namespace shell { |
| 11 namespace { | |
| 12 | |
| 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 | 12 |
| 30 Identity::Identity() {} | 13 Identity::Identity() {} |
| 31 | 14 |
| 32 Identity::Identity(const GURL& url) | 15 Identity::Identity(const std::string& name) |
| 33 : Identity(url, url.spec(), mojom::Connector::kUserRoot) {} | 16 : Identity(name, GetNamePath(name), mojom::Connector::kUserRoot) {} |
| 34 | 17 |
| 35 Identity::Identity(const GURL& url, const std::string& qualifier, | 18 Identity::Identity(const std::string& name, const std::string& qualifier, |
| 36 uint32_t user_id) | 19 uint32_t user_id) |
| 37 : url_(url), | 20 : name_(name), |
| 38 qualifier_(qualifier.empty() ? url_.spec() : qualifier), | 21 qualifier_(qualifier.empty() ? GetNamePath(name_) : qualifier), |
| 39 user_id_(user_id) {} | 22 user_id_(user_id) {} |
| 40 | 23 |
| 41 Identity::~Identity() {} | 24 Identity::~Identity() {} |
| 42 | 25 |
| 43 bool Identity::operator<(const Identity& other) const { | 26 bool Identity::operator<(const Identity& other) const { |
| 44 // We specifically don't include filter in the equivalence check because we | 27 // We specifically don't include filter in the equivalence check because we |
| 45 // don't quite know how this should work yet. | 28 // don't quite know how this should work yet. |
| 46 // TODO(beng): figure out how it should work. | 29 // TODO(beng): figure out how it should work. |
| 47 if (url_ != other.url_) | 30 if (name_ != other.name_) |
| 48 return url_ < other.url_; | 31 return name_ < other.name_; |
| 49 if (qualifier_ != other.qualifier_) | 32 if (qualifier_ != other.qualifier_) |
| 50 return qualifier_ < other.qualifier_; | 33 return qualifier_ < other.qualifier_; |
| 51 return user_id_ < other.user_id_; | 34 return user_id_ < other.user_id_; |
| 52 } | 35 } |
| 53 | 36 |
| 54 bool Identity::operator==(const Identity& other) const { | 37 bool Identity::operator==(const Identity& other) const { |
| 55 // We specifically don't include filter in the equivalence check because we | 38 // We specifically don't include filter in the equivalence check because we |
| 56 // don't quite know how this should work yet. | 39 // don't quite know how this should work yet. |
| 57 // TODO(beng): figure out how it should work. | 40 // TODO(beng): figure out how it should work. |
| 58 return other.url_ == url_ && other.qualifier_ == qualifier_ && | 41 return other.name_ == name_ && other.qualifier_ == qualifier_ && |
| 59 other.user_id_ == user_id_; | 42 other.user_id_ == user_id_; |
| 60 } | 43 } |
| 61 | 44 |
| 62 void Identity::SetFilter(const CapabilityFilter& filter) { | |
| 63 filter_ = CanonicalizeFilter(filter); | |
| 64 } | |
| 65 | |
| 66 Identity CreateShellIdentity() { | 45 Identity CreateShellIdentity() { |
| 67 Identity id = | 46 Identity id = Identity("mojo:shell", "", mojom::Connector::kUserRoot); |
| 68 Identity(GURL("mojo://shell/"), "", mojom::Connector::kUserRoot); | 47 id.set_filter(GetPermissiveCapabilityFilter()); |
| 69 id.SetFilter(GetPermissiveCapabilityFilter()); | |
| 70 return id; | 48 return id; |
| 71 } | 49 } |
| 72 | 50 |
| 73 } // namespace shell | 51 } // namespace shell |
| 74 } // namespace mojo | 52 } // namespace mojo |
| OLD | NEW |