OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/application/public/cpp/application_impl.h" | 5 #include "mojo/application/public/cpp/application_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "mojo/application/public/cpp/application_delegate.h" | 11 #include "mojo/application/public/cpp/application_delegate.h" |
12 #include "mojo/application/public/cpp/lib/service_registry.h" | 12 #include "mojo/application/public/cpp/lib/service_registry.h" |
13 #include "mojo/public/cpp/bindings/interface_ptr.h" | 13 #include "mojo/public/cpp/bindings/interface_ptr.h" |
14 #include "mojo/public/cpp/environment/logging.h" | 14 #include "mojo/public/cpp/environment/logging.h" |
15 | 15 |
16 namespace mojo { | 16 namespace mojo { |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 void DefaultTerminationClosure() { | 20 void DefaultTerminationClosure() { |
21 if (base::MessageLoop::current() && | 21 if (base::MessageLoop::current() && |
22 base::MessageLoop::current()->is_running()) | 22 base::MessageLoop::current()->is_running()) |
23 base::MessageLoop::current()->Quit(); | 23 base::MessageLoop::current()->Quit(); |
24 } | 24 } |
25 | 25 |
26 } // namespace | 26 } // namespace |
27 | 27 |
| 28 template <typename E, typename T> |
| 29 struct TypeConverter<std::set<E>, Array<T>> { |
| 30 static std::set<E> Convert(const Array<T>& input) { |
| 31 std::set<E> result; |
| 32 if (!input.is_null()) { |
| 33 for (size_t i = 0; i < input.size(); ++i) |
| 34 result.insert(TypeConverter<E, T>::Convert(input[i])); |
| 35 } |
| 36 return result; |
| 37 } |
| 38 }; |
| 39 |
28 ApplicationImpl::ApplicationImpl(ApplicationDelegate* delegate, | 40 ApplicationImpl::ApplicationImpl(ApplicationDelegate* delegate, |
29 InterfaceRequest<Application> request) | 41 InterfaceRequest<Application> request) |
30 : ApplicationImpl(delegate, request.Pass(), | 42 : ApplicationImpl(delegate, request.Pass(), |
31 base::Bind(&DefaultTerminationClosure)) { | 43 base::Bind(&DefaultTerminationClosure)) { |
32 } | 44 } |
33 | 45 |
34 ApplicationImpl::ApplicationImpl(ApplicationDelegate* delegate, | 46 ApplicationImpl::ApplicationImpl(ApplicationDelegate* delegate, |
35 InterfaceRequest<Application> request, | 47 InterfaceRequest<Application> request, |
36 const base::Closure& termination_closure) | 48 const base::Closure& termination_closure) |
37 : delegate_(delegate), | 49 : delegate_(delegate), |
(...skipping 20 matching lines...) Expand all Loading... |
58 } | 70 } |
59 | 71 |
60 ApplicationImpl::~ApplicationImpl() { | 72 ApplicationImpl::~ApplicationImpl() { |
61 DCHECK(!in_destructor_); | 73 DCHECK(!in_destructor_); |
62 in_destructor_ = true; | 74 in_destructor_ = true; |
63 ClearConnections(); | 75 ClearConnections(); |
64 app_lifetime_helper_.ApplicationTerminated(); | 76 app_lifetime_helper_.ApplicationTerminated(); |
65 } | 77 } |
66 | 78 |
67 ApplicationConnection* ApplicationImpl::ConnectToApplication( | 79 ApplicationConnection* ApplicationImpl::ConnectToApplication( |
68 mojo::URLRequestPtr request) { | 80 mojo::URLRequestPtr request, |
| 81 CapabilityFilterPtr filter) { |
69 if (!shell_) | 82 if (!shell_) |
70 return nullptr; | 83 return nullptr; |
71 ServiceProviderPtr local_services; | 84 ServiceProviderPtr local_services; |
72 InterfaceRequest<ServiceProvider> local_request = GetProxy(&local_services); | 85 InterfaceRequest<ServiceProvider> local_request = GetProxy(&local_services); |
73 ServiceProviderPtr remote_services; | 86 ServiceProviderPtr remote_services; |
74 std::string application_url = request->url.To<std::string>(); | 87 std::string application_url = request->url.To<std::string>(); |
75 shell_->ConnectToApplication(request.Pass(), GetProxy(&remote_services), | 88 shell_->ConnectToApplication(request.Pass(), GetProxy(&remote_services), |
76 local_services.Pass()); | 89 local_services.Pass(), filter.Pass()); |
| 90 // We allow all interfaces on outgoing connections since we are presumably in |
| 91 // a position to know who we're talking to. |
| 92 // TODO(beng): is this a valid assumption or do we need to figure some way to |
| 93 // filter here too? |
| 94 std::set<std::string> allowed; |
| 95 allowed.insert("*"); |
77 internal::ServiceRegistry* registry = new internal::ServiceRegistry( | 96 internal::ServiceRegistry* registry = new internal::ServiceRegistry( |
78 this, application_url, application_url, remote_services.Pass(), | 97 this, application_url, application_url, remote_services.Pass(), |
79 local_request.Pass()); | 98 local_request.Pass(), allowed); |
80 if (!delegate_->ConfigureOutgoingConnection(registry)) { | 99 if (!delegate_->ConfigureOutgoingConnection(registry)) { |
81 registry->CloseConnection(); | 100 registry->CloseConnection(); |
82 return nullptr; | 101 return nullptr; |
83 } | 102 } |
84 outgoing_service_registries_.push_back(registry); | 103 outgoing_service_registries_.push_back(registry); |
85 return registry; | 104 return registry; |
86 } | 105 } |
87 | 106 |
88 void ApplicationImpl::CloseConnection(ApplicationConnection* connection) { | 107 void ApplicationImpl::CloseConnection(ApplicationConnection* connection) { |
89 if (!in_destructor_) | 108 if (!in_destructor_) |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 | 153 |
135 void ApplicationImpl::QuitNow() { | 154 void ApplicationImpl::QuitNow() { |
136 delegate_->Quit(); | 155 delegate_->Quit(); |
137 termination_closure_.Run(); | 156 termination_closure_.Run(); |
138 } | 157 } |
139 | 158 |
140 void ApplicationImpl::AcceptConnection( | 159 void ApplicationImpl::AcceptConnection( |
141 const String& requestor_url, | 160 const String& requestor_url, |
142 InterfaceRequest<ServiceProvider> services, | 161 InterfaceRequest<ServiceProvider> services, |
143 ServiceProviderPtr exposed_services, | 162 ServiceProviderPtr exposed_services, |
| 163 Array<String> allowed_interfaces, |
144 const String& url) { | 164 const String& url) { |
145 internal::ServiceRegistry* registry = new internal::ServiceRegistry( | 165 internal::ServiceRegistry* registry = new internal::ServiceRegistry( |
146 this, url, requestor_url, exposed_services.Pass(), services.Pass()); | 166 this, url, requestor_url, exposed_services.Pass(), services.Pass(), |
| 167 allowed_interfaces.To<std::set<std::string>>()); |
147 if (!delegate_->ConfigureIncomingConnection(registry)) { | 168 if (!delegate_->ConfigureIncomingConnection(registry)) { |
148 registry->CloseConnection(); | 169 registry->CloseConnection(); |
149 return; | 170 return; |
150 } | 171 } |
151 incoming_service_registries_.push_back(registry); | 172 incoming_service_registries_.push_back(registry); |
152 | 173 |
153 // If we were quitting because we thought there were no more services for this | 174 // If we were quitting because we thought there were no more services for this |
154 // app in use, then that has changed so cancel the quit request. | 175 // app in use, then that has changed so cancel the quit request. |
155 if (quit_requested_) | 176 if (quit_requested_) |
156 quit_requested_ = false; | 177 quit_requested_ = false; |
(...skipping 17 matching lines...) Expand all Loading... |
174 // than the one to the shell. | 195 // than the one to the shell. |
175 bool quit_now = delegate_->OnShellConnectionError(); | 196 bool quit_now = delegate_->OnShellConnectionError(); |
176 if (quit_now) | 197 if (quit_now) |
177 QuitNow(); | 198 QuitNow(); |
178 if (!ptr) | 199 if (!ptr) |
179 return; | 200 return; |
180 shell_ = nullptr; | 201 shell_ = nullptr; |
181 } | 202 } |
182 | 203 |
183 } // namespace mojo | 204 } // namespace mojo |
OLD | NEW |