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/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "mojo/public/cpp/bindings/interface_ptr.h" | 11 #include "mojo/public/cpp/bindings/interface_ptr.h" |
| 12 #include "mojo/shell/public/cpp/connector.h" |
12 #include "mojo/shell/public/cpp/lib/connection_impl.h" | 13 #include "mojo/shell/public/cpp/lib/connection_impl.h" |
| 14 #include "mojo/shell/public/cpp/lib/connector_impl.h" |
13 #include "mojo/shell/public/cpp/shell_client.h" | 15 #include "mojo/shell/public/cpp/shell_client.h" |
14 #include "mojo/shell/public/cpp/shell_connection.h" | 16 #include "mojo/shell/public/cpp/shell_connection.h" |
15 | 17 |
16 namespace mojo { | 18 namespace mojo { |
17 | 19 |
18 namespace { | 20 namespace { |
19 | 21 |
20 void DefaultTerminationClosure() { | 22 void DefaultTerminationClosure() { |
21 if (base::MessageLoop::current() && | 23 if (base::MessageLoop::current() && |
22 base::MessageLoop::current()->is_running()) | 24 base::MessageLoop::current()->is_running()) |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 ShellConnection* connection_; | 79 ShellConnection* connection_; |
78 scoped_refptr<base::SingleThreadTaskRunner> app_task_runner_; | 80 scoped_refptr<base::SingleThreadTaskRunner> app_task_runner_; |
79 | 81 |
80 #ifndef NDEBUG | 82 #ifndef NDEBUG |
81 scoped_refptr<base::SingleThreadTaskRunner> clone_task_runner_; | 83 scoped_refptr<base::SingleThreadTaskRunner> clone_task_runner_; |
82 #endif | 84 #endif |
83 | 85 |
84 DISALLOW_COPY_AND_ASSIGN(AppRefCountImpl); | 86 DISALLOW_COPY_AND_ASSIGN(AppRefCountImpl); |
85 }; | 87 }; |
86 | 88 |
87 | |
88 ShellConnection::ConnectParams::ConnectParams(const std::string& url) | |
89 : url_(url), | |
90 filter_(shell::mojom::CapabilityFilter::New()), | |
91 user_id_(shell::mojom::Shell::kUserInherit) { | |
92 filter_->filter.SetToEmpty(); | |
93 } | |
94 ShellConnection::ConnectParams::~ConnectParams() {} | |
95 | |
96 //////////////////////////////////////////////////////////////////////////////// | 89 //////////////////////////////////////////////////////////////////////////////// |
97 // ShellConnection, public: | 90 // ShellConnection, public: |
98 | 91 |
99 ShellConnection::ShellConnection( | 92 ShellConnection::ShellConnection( |
100 mojo::ShellClient* client, | 93 mojo::ShellClient* client, |
101 InterfaceRequest<shell::mojom::ShellClient> request) | 94 InterfaceRequest<shell::mojom::ShellClient> request) |
102 : ShellConnection(client, | 95 : ShellConnection(client, |
103 std::move(request), | 96 std::move(request), |
104 base::Bind(&DefaultTerminationClosure)) {} | 97 base::Bind(&DefaultTerminationClosure)) {} |
105 | 98 |
(...skipping 12 matching lines...) Expand all Loading... |
118 | 111 |
119 void ShellConnection::WaitForInitialize() { | 112 void ShellConnection::WaitForInitialize() { |
120 DCHECK(!shell_.is_bound()); | 113 DCHECK(!shell_.is_bound()); |
121 binding_.WaitForIncomingMethodCall(); | 114 binding_.WaitForIncomingMethodCall(); |
122 } | 115 } |
123 | 116 |
124 //////////////////////////////////////////////////////////////////////////////// | 117 //////////////////////////////////////////////////////////////////////////////// |
125 // ShellConnection, Shell implementation: | 118 // ShellConnection, Shell implementation: |
126 | 119 |
127 scoped_ptr<Connection> ShellConnection::Connect(const std::string& url) { | 120 scoped_ptr<Connection> ShellConnection::Connect(const std::string& url) { |
128 ConnectParams params(url); | 121 return connector_->Connect(url); |
129 params.set_filter(CreatePermissiveCapabilityFilter()); | |
130 return Connect(¶ms); | |
131 } | 122 } |
132 | 123 |
133 scoped_ptr<Connection> ShellConnection::Connect(ConnectParams* params) { | 124 scoped_ptr<Connection> ShellConnection::Connect( |
134 if (!shell_) | 125 Connector::ConnectParams* params) { |
135 return nullptr; | 126 return connector_->Connect(params); |
136 DCHECK(params); | 127 } |
137 std::string application_url = params->url().spec(); | 128 |
138 // We allow all interfaces on outgoing connections since we are presumably in | 129 scoped_ptr<Connector> ShellConnection::CloneConnector() const { |
139 // a position to know who we're talking to. | 130 return connector_->Clone(); |
140 // TODO(beng): is this a valid assumption or do we need to figure some way to | |
141 // filter here too? | |
142 std::set<std::string> allowed; | |
143 allowed.insert("*"); | |
144 shell::mojom::InterfaceProviderPtr local_interfaces; | |
145 shell::mojom::InterfaceProviderRequest local_request = | |
146 GetProxy(&local_interfaces); | |
147 shell::mojom::InterfaceProviderPtr remote_interfaces; | |
148 shell::mojom::InterfaceProviderRequest remote_request = | |
149 GetProxy(&remote_interfaces); | |
150 scoped_ptr<internal::ConnectionImpl> registry(new internal::ConnectionImpl( | |
151 application_url, application_url, | |
152 shell::mojom::Shell::kInvalidApplicationID, params->user_id(), | |
153 std::move(remote_interfaces), std::move(local_request), allowed)); | |
154 shell_->Connect(application_url, | |
155 params->user_id(), | |
156 std::move(remote_request), | |
157 std::move(local_interfaces), | |
158 params->TakeFilter(), | |
159 registry->GetConnectCallback()); | |
160 return std::move(registry); | |
161 } | 131 } |
162 | 132 |
163 void ShellConnection::Quit() { | 133 void ShellConnection::Quit() { |
164 // We can't quit immediately, since there could be in-flight requests from the | 134 // We can't quit immediately, since there could be in-flight requests from the |
165 // shell. So check with it first. | 135 // shell. So check with it first. |
166 if (shell_) { | 136 if (shell_) { |
167 quit_requested_ = true; | 137 quit_requested_ = true; |
168 shell_->QuitApplication(); | 138 shell_->QuitApplication(); |
169 } else { | 139 } else { |
170 QuitNow(); | 140 QuitNow(); |
171 } | 141 } |
172 } | 142 } |
173 | 143 |
174 scoped_ptr<AppRefCount> ShellConnection::CreateAppRefCount() { | 144 scoped_ptr<AppRefCount> ShellConnection::CreateAppRefCount() { |
175 AddRef(); | 145 AddRef(); |
176 return make_scoped_ptr( | 146 return make_scoped_ptr( |
177 new AppRefCountImpl(this, base::MessageLoop::current()->task_runner())); | 147 new AppRefCountImpl(this, base::MessageLoop::current()->task_runner())); |
178 } | 148 } |
179 | 149 |
180 //////////////////////////////////////////////////////////////////////////////// | 150 //////////////////////////////////////////////////////////////////////////////// |
181 // ShellConnection, shell::mojom::ShellClient implementation: | 151 // ShellConnection, shell::mojom::ShellClient implementation: |
182 | 152 |
183 void ShellConnection::Initialize(shell::mojom::ShellPtr shell, | 153 void ShellConnection::Initialize(shell::mojom::ShellPtr shell, |
184 const mojo::String& url, | 154 const mojo::String& url, |
185 uint32_t id, | 155 uint32_t id, |
186 uint32_t user_id) { | 156 uint32_t user_id) { |
187 shell_ = std::move(shell); | 157 shell_ = std::move(shell); |
188 shell_.set_connection_error_handler([this]() { OnConnectionError(); }); | 158 shell_.set_connection_error_handler([this]() { OnConnectionError(); }); |
| 159 |
| 160 shell::mojom::ConnectorPtr connector; |
| 161 shell_->GetConnector(GetProxy(&connector)); |
| 162 connector_.reset(new ConnectorImpl(connector.PassInterface())); |
| 163 |
189 client_->Initialize(this, url, id, user_id); | 164 client_->Initialize(this, url, id, user_id); |
190 } | 165 } |
191 | 166 |
192 void ShellConnection::AcceptConnection( | 167 void ShellConnection::AcceptConnection( |
193 const String& requestor_url, | 168 const String& requestor_url, |
194 uint32_t requestor_id, | 169 uint32_t requestor_id, |
195 uint32_t requestor_user_id, | 170 uint32_t requestor_user_id, |
196 shell::mojom::InterfaceProviderRequest local_interfaces, | 171 shell::mojom::InterfaceProviderRequest local_interfaces, |
197 shell::mojom::InterfaceProviderPtr remote_interfaces, | 172 shell::mojom::InterfaceProviderPtr remote_interfaces, |
198 Array<String> allowed_interfaces, | 173 Array<String> allowed_interfaces, |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 shell::mojom::CapabilityFilterPtr CreatePermissiveCapabilityFilter() { | 238 shell::mojom::CapabilityFilterPtr CreatePermissiveCapabilityFilter() { |
264 shell::mojom::CapabilityFilterPtr filter( | 239 shell::mojom::CapabilityFilterPtr filter( |
265 shell::mojom::CapabilityFilter::New()); | 240 shell::mojom::CapabilityFilter::New()); |
266 Array<String> all_interfaces; | 241 Array<String> all_interfaces; |
267 all_interfaces.push_back("*"); | 242 all_interfaces.push_back("*"); |
268 filter->filter.insert("*", std::move(all_interfaces)); | 243 filter->filter.insert("*", std::move(all_interfaces)); |
269 return filter; | 244 return filter; |
270 } | 245 } |
271 | 246 |
272 } // namespace mojo | 247 } // namespace mojo |
OLD | NEW |