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/capability_filter.h" | 5 #include "mojo/shell/capability_filter.h" |
6 | 6 |
| 7 #include "mojo/shell/identity.h" |
| 8 |
7 namespace mojo { | 9 namespace mojo { |
8 namespace shell { | 10 namespace shell { |
9 | 11 |
10 CapabilityFilter GetPermissiveCapabilityFilter() { | 12 CapabilityFilter GetPermissiveCapabilityFilter() { |
11 CapabilityFilter filter; | 13 CapabilityFilter filter; |
12 AllowedInterfaces interfaces; | 14 AllowedInterfaces interfaces; |
13 interfaces.insert("*"); | 15 interfaces.insert("*"); |
14 filter["*"] = interfaces; | 16 filter["*"] = interfaces; |
15 return filter; | 17 return filter; |
16 } | 18 } |
17 | 19 |
| 20 AllowedInterfaces GetAllowedInterfaces(const CapabilityFilter& filter, |
| 21 const Identity& identity) { |
| 22 // Start by looking for interfaces specific to the supplied identity. |
| 23 auto it = filter.find(identity.url.spec()); |
| 24 if (it != filter.end()) |
| 25 return it->second; |
| 26 |
| 27 // Fall back to looking for a wildcard rule. |
| 28 it = filter.find("*"); |
| 29 if (filter.size() == 1 && it != filter.end()) |
| 30 return it->second; |
| 31 |
| 32 // Finally, nothing is allowed. |
| 33 return AllowedInterfaces(); |
| 34 } |
| 35 |
18 } // namespace shell | 36 } // namespace shell |
19 } // namespace mojo | 37 } // namespace mojo |
OLD | NEW |