OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 SERVICES_SHELL_PUBLIC_CPP_INTERFACE_REGISTRY_H_ | 5 #ifndef SERVICES_SHELL_PUBLIC_CPP_INTERFACE_REGISTRY_H_ |
6 #define SERVICES_SHELL_PUBLIC_CPP_INTERFACE_REGISTRY_H_ | 6 #define SERVICES_SHELL_PUBLIC_CPP_INTERFACE_REGISTRY_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <queue> | 9 #include <queue> |
10 #include <set> | 10 #include <set> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "mojo/public/cpp/bindings/binding.h" | 15 #include "mojo/public/cpp/bindings/binding.h" |
| 16 #include "services/shell/public/cpp/capabilities.h" |
| 17 #include "services/shell/public/cpp/identity.h" |
16 #include "services/shell/public/cpp/lib/callback_binder.h" | 18 #include "services/shell/public/cpp/lib/callback_binder.h" |
17 #include "services/shell/public/cpp/lib/interface_factory_binder.h" | 19 #include "services/shell/public/cpp/lib/interface_factory_binder.h" |
18 #include "services/shell/public/interfaces/interface_provider.mojom.h" | 20 #include "services/shell/public/interfaces/interface_provider.mojom.h" |
19 | 21 |
20 namespace shell { | 22 namespace shell { |
21 class Connection; | 23 class Connection; |
22 class InterfaceBinder; | 24 class InterfaceBinder; |
23 | 25 |
24 // An implementation of mojom::InterfaceProvider that allows the user to | 26 // An implementation of mojom::InterfaceProvider that allows the user to |
25 // register services to be exposed to another application. | 27 // register services to be exposed to another application. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 const std::string& interface_name) { | 59 const std::string& interface_name) { |
58 registry_->SetInterfaceBinderForName( | 60 registry_->SetInterfaceBinderForName( |
59 base::WrapUnique(binder), interface_name); | 61 base::WrapUnique(binder), interface_name); |
60 } | 62 } |
61 | 63 |
62 private: | 64 private: |
63 InterfaceRegistry* registry_; | 65 InterfaceRegistry* registry_; |
64 DISALLOW_COPY_AND_ASSIGN(TestApi); | 66 DISALLOW_COPY_AND_ASSIGN(TestApi); |
65 }; | 67 }; |
66 | 68 |
67 // Construct with a Connection (which may be null), and create an | 69 // Construct an InterfaceRegistry with no filtering rules applied. |
68 // InterfaceProvider pipe, the client end of which may be obtained by calling | 70 InterfaceRegistry(); |
69 // TakeClientHandle(). If |connection| is non-null, the Mojo Shell's | 71 |
70 // rules filtering which interfaces are allowed to be exposed to clients are | 72 // Construct an InterfaceRegistry with filtering rules as specified in |
71 // imposed on this registry. If null, they are not. | 73 // |capability_request| applied. |
72 explicit InterfaceRegistry(Connection* connection); | 74 InterfaceRegistry(const Identity& remote_identity, |
| 75 const CapabilityRequest& capability_request); |
73 ~InterfaceRegistry() override; | 76 ~InterfaceRegistry() override; |
74 | 77 |
75 // Sets a default handler for incoming interface requests which are allowed by | 78 // Sets a default handler for incoming interface requests which are allowed by |
76 // capability filters but have no registered handler in this registry. | 79 // capability filters but have no registered handler in this registry. |
77 void set_default_binder(const Binder& binder) { default_binder_ = binder; } | 80 void set_default_binder(const Binder& binder) { default_binder_ = binder; } |
78 | 81 |
79 void Bind(mojom::InterfaceProviderRequest local_interfaces_request); | 82 void Bind(mojom::InterfaceProviderRequest local_interfaces_request); |
80 | 83 |
81 base::WeakPtr<InterfaceRegistry> GetWeakPtr(); | 84 base::WeakPtr<InterfaceRegistry> GetWeakPtr(); |
82 | 85 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 | 139 |
137 // mojom::InterfaceProvider: | 140 // mojom::InterfaceProvider: |
138 void GetInterface(const mojo::String& interface_name, | 141 void GetInterface(const mojo::String& interface_name, |
139 mojo::ScopedMessagePipeHandle handle) override; | 142 mojo::ScopedMessagePipeHandle handle) override; |
140 | 143 |
141 // Returns true if the binder was set, false if it was not set (e.g. by | 144 // Returns true if the binder was set, false if it was not set (e.g. by |
142 // some filtering policy preventing this interface from being exposed). | 145 // some filtering policy preventing this interface from being exposed). |
143 bool SetInterfaceBinderForName(std::unique_ptr<InterfaceBinder> binder, | 146 bool SetInterfaceBinderForName(std::unique_ptr<InterfaceBinder> binder, |
144 const std::string& name); | 147 const std::string& name); |
145 | 148 |
| 149 // Returns true if |remote_identity_| is allowed to bind |interface_name|, |
| 150 // according to capability policy. |
| 151 bool CanBindRequestForInterface(const std::string& interface_name) const; |
| 152 |
146 mojom::InterfaceProviderRequest pending_request_; | 153 mojom::InterfaceProviderRequest pending_request_; |
147 | 154 |
148 mojo::Binding<mojom::InterfaceProvider> binding_; | 155 mojo::Binding<mojom::InterfaceProvider> binding_; |
149 Connection* connection_; | 156 const Identity remote_identity_; |
| 157 const CapabilityRequest capability_request_; |
| 158 const bool allow_all_interfaces_; |
150 | 159 |
151 NameToInterfaceBinderMap name_to_binder_; | 160 NameToInterfaceBinderMap name_to_binder_; |
152 | |
153 Binder default_binder_; | 161 Binder default_binder_; |
154 | 162 |
155 bool is_paused_ = false; | 163 bool is_paused_ = false; |
156 | 164 |
157 // Pending interface requests which can accumulate if GetInterface() is called | 165 // Pending interface requests which can accumulate if GetInterface() is called |
158 // while binding is paused. | 166 // while binding is paused. |
159 std::queue<std::pair<mojo::String, mojo::ScopedMessagePipeHandle>> | 167 std::queue<std::pair<mojo::String, mojo::ScopedMessagePipeHandle>> |
160 pending_interface_requests_; | 168 pending_interface_requests_; |
161 | 169 |
162 base::WeakPtrFactory<InterfaceRegistry> weak_factory_; | 170 base::WeakPtrFactory<InterfaceRegistry> weak_factory_; |
163 | 171 |
164 DISALLOW_COPY_AND_ASSIGN(InterfaceRegistry); | 172 DISALLOW_COPY_AND_ASSIGN(InterfaceRegistry); |
165 }; | 173 }; |
166 | 174 |
167 } // namespace shell | 175 } // namespace shell |
168 | 176 |
169 #endif // SERVICES_SHELL_PUBLIC_CPP_INTERFACE_REGISTRY_H_ | 177 #endif // SERVICES_SHELL_PUBLIC_CPP_INTERFACE_REGISTRY_H_ |
OLD | NEW |