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