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 <algorithm> | 5 #include <algorithm> |
6 #include <utility> | 6 #include <utility> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "mojo/converters/network/network_type_converters.h" | 10 #include "mojo/converters/network/network_type_converters.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 ConnectParams params(url); | 66 ConnectParams params(url); |
67 params.set_filter(CreatePermissiveCapabilityFilter()); | 67 params.set_filter(CreatePermissiveCapabilityFilter()); |
68 return Connect(¶ms); | 68 return Connect(¶ms); |
69 } | 69 } |
70 | 70 |
71 scoped_ptr<Connection> ShellConnection::Connect(ConnectParams* params) { | 71 scoped_ptr<Connection> ShellConnection::Connect(ConnectParams* params) { |
72 if (!shell_) | 72 if (!shell_) |
73 return nullptr; | 73 return nullptr; |
74 DCHECK(params); | 74 DCHECK(params); |
75 URLRequestPtr request = params->TakeRequest(); | 75 URLRequestPtr request = params->TakeRequest(); |
76 ServiceProviderPtr local_services; | |
77 InterfaceRequest<ServiceProvider> local_request = GetProxy(&local_services); | |
78 ServiceProviderPtr remote_services; | |
79 std::string application_url = request->url.To<std::string>(); | 76 std::string application_url = request->url.To<std::string>(); |
80 // We allow all interfaces on outgoing connections since we are presumably in | 77 // We allow all interfaces on outgoing connections since we are presumably in |
81 // a position to know who we're talking to. | 78 // a position to know who we're talking to. |
82 // TODO(beng): is this a valid assumption or do we need to figure some way to | 79 // TODO(beng): is this a valid assumption or do we need to figure some way to |
83 // filter here too? | 80 // filter here too? |
84 std::set<std::string> allowed; | 81 std::set<std::string> allowed; |
85 allowed.insert("*"); | 82 allowed.insert("*"); |
86 InterfaceRequest<ServiceProvider> remote_services_proxy = | 83 InterfaceProviderPtr local_interfaces; |
87 GetProxy(&remote_services); | 84 InterfaceRequest<InterfaceProvider> local_request = |
| 85 GetProxy(&local_interfaces); |
| 86 InterfaceProviderPtr remote_interfaces; |
| 87 InterfaceRequest<InterfaceProvider> remote_request = |
| 88 GetProxy(&remote_interfaces); |
88 scoped_ptr<internal::ConnectionImpl> registry(new internal::ConnectionImpl( | 89 scoped_ptr<internal::ConnectionImpl> registry(new internal::ConnectionImpl( |
89 application_url, application_url, | 90 application_url, application_url, |
90 shell::mojom::Shell::kInvalidApplicationID, std::move(remote_services), | 91 shell::mojom::Shell::kInvalidApplicationID, std::move(remote_interfaces), |
91 std::move(local_request), allowed)); | 92 std::move(local_request), allowed)); |
92 shell_->ConnectToApplication(std::move(request), | 93 shell_->ConnectToApplication(std::move(request), |
93 std::move(remote_services_proxy), | 94 std::move(remote_request), |
94 std::move(local_services), params->TakeFilter(), | 95 std::move(local_interfaces), |
| 96 params->TakeFilter(), |
95 registry->GetConnectToApplicationCallback()); | 97 registry->GetConnectToApplicationCallback()); |
96 return std::move(registry); | 98 return std::move(registry); |
97 } | 99 } |
98 | 100 |
99 void ShellConnection::Quit() { | 101 void ShellConnection::Quit() { |
100 // We can't quit immediately, since there could be in-flight requests from the | 102 // We can't quit immediately, since there could be in-flight requests from the |
101 // shell. So check with it first. | 103 // shell. So check with it first. |
102 if (shell_) { | 104 if (shell_) { |
103 quit_requested_ = true; | 105 quit_requested_ = true; |
104 shell_->QuitApplication(); | 106 shell_->QuitApplication(); |
(...skipping 10 matching lines...) Expand all Loading... |
115 const mojo::String& url, | 117 const mojo::String& url, |
116 uint32_t id) { | 118 uint32_t id) { |
117 shell_ = std::move(shell); | 119 shell_ = std::move(shell); |
118 shell_.set_connection_error_handler([this]() { OnConnectionError(); }); | 120 shell_.set_connection_error_handler([this]() { OnConnectionError(); }); |
119 client_->Initialize(this, url, id); | 121 client_->Initialize(this, url, id); |
120 } | 122 } |
121 | 123 |
122 void ShellConnection::AcceptConnection( | 124 void ShellConnection::AcceptConnection( |
123 const String& requestor_url, | 125 const String& requestor_url, |
124 uint32_t requestor_id, | 126 uint32_t requestor_id, |
125 InterfaceRequest<ServiceProvider> services, | 127 InterfaceRequest<InterfaceProvider> local_interfaces, |
126 ServiceProviderPtr exposed_services, | 128 InterfaceProviderPtr remote_interfaces, |
127 Array<String> allowed_interfaces, | 129 Array<String> allowed_interfaces, |
128 const String& url) { | 130 const String& url) { |
129 scoped_ptr<Connection> registry(new internal::ConnectionImpl( | 131 scoped_ptr<Connection> registry(new internal::ConnectionImpl( |
130 url, requestor_url, requestor_id, std::move(exposed_services), | 132 url, requestor_url, requestor_id, std::move(remote_interfaces), |
131 std::move(services), allowed_interfaces.To<std::set<std::string>>())); | 133 std::move(local_interfaces), |
| 134 allowed_interfaces.To<std::set<std::string>>())); |
132 if (!client_->AcceptConnection(registry.get())) | 135 if (!client_->AcceptConnection(registry.get())) |
133 return; | 136 return; |
134 | 137 |
135 // If we were quitting because we thought there were no more services for this | 138 // If we were quitting because we thought there were no more interfaces for |
136 // app in use, then that has changed so cancel the quit request. | 139 // this app in use, then that has changed so cancel the quit request. |
137 if (quit_requested_) | 140 if (quit_requested_) |
138 quit_requested_ = false; | 141 quit_requested_ = false; |
139 | 142 |
140 incoming_connections_.push_back(std::move(registry)); | 143 incoming_connections_.push_back(std::move(registry)); |
141 } | 144 } |
142 | 145 |
143 void ShellConnection::OnQuitRequested(const Callback<void(bool)>& callback) { | 146 void ShellConnection::OnQuitRequested(const Callback<void(bool)>& callback) { |
144 // If by the time we got the reply from the shell, more requests had come in | 147 // If by the time we got the reply from the shell, more requests had come in |
145 // then we don't want to quit the app anymore so we return false. Otherwise | 148 // then we don't want to quit the app anymore so we return false. Otherwise |
146 // |quit_requested_| is true so we tell the shell to proceed with the quit. | 149 // |quit_requested_| is true so we tell the shell to proceed with the quit. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 shell::mojom::CapabilityFilterPtr CreatePermissiveCapabilityFilter() { | 182 shell::mojom::CapabilityFilterPtr CreatePermissiveCapabilityFilter() { |
180 shell::mojom::CapabilityFilterPtr filter( | 183 shell::mojom::CapabilityFilterPtr filter( |
181 shell::mojom::CapabilityFilter::New()); | 184 shell::mojom::CapabilityFilter::New()); |
182 Array<String> all_interfaces; | 185 Array<String> all_interfaces; |
183 all_interfaces.push_back("*"); | 186 all_interfaces.push_back("*"); |
184 filter->filter.insert("*", std::move(all_interfaces)); | 187 filter->filter.insert("*", std::move(all_interfaces)); |
185 return filter; | 188 return filter; |
186 } | 189 } |
187 | 190 |
188 } // namespace mojo | 191 } // namespace mojo |
OLD | NEW |