OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "mojo/shell/public/cpp/lib/connector_impl.h" |
| 6 |
| 7 #include "mojo/shell/public/cpp/lib/connection_impl.h" |
| 8 |
| 9 namespace mojo { |
| 10 |
| 11 Connector::ConnectParams::ConnectParams(const std::string& url) |
| 12 : url_(url), |
| 13 filter_(shell::mojom::CapabilityFilter::New()), |
| 14 user_id_(shell::mojom::Connector::kUserInherit) { |
| 15 filter_->filter.SetToEmpty(); |
| 16 } |
| 17 Connector::ConnectParams::~ConnectParams() {} |
| 18 |
| 19 ConnectorImpl::ConnectorImpl(shell::mojom::ConnectorPtrInfo unbound_state) |
| 20 : unbound_state_(std::move(unbound_state)) {} |
| 21 ConnectorImpl::~ConnectorImpl() {} |
| 22 |
| 23 scoped_ptr<Connection> ConnectorImpl::Connect(const std::string& url) { |
| 24 ConnectParams params(url); |
| 25 params.set_filter(CreatePermissiveCapabilityFilter()); |
| 26 return Connect(¶ms); |
| 27 } |
| 28 |
| 29 scoped_ptr<Connection> ConnectorImpl::Connect(ConnectParams* params) { |
| 30 // Bind this object to the current thread the first time it is used to |
| 31 // connect. |
| 32 if (!connector_.is_bound()) { |
| 33 if (!unbound_state_.is_valid()) |
| 34 return nullptr; |
| 35 connector_.Bind(std::move(unbound_state_)); |
| 36 thread_checker_.reset(new base::ThreadChecker); |
| 37 } |
| 38 DCHECK(thread_checker_->CalledOnValidThread()); |
| 39 |
| 40 DCHECK(params); |
| 41 std::string application_url = params->url().spec(); |
| 42 // We allow all interfaces on outgoing connections since we are presumably in |
| 43 // a position to know who we're talking to. |
| 44 // TODO(beng): is this a valid assumption or do we need to figure some way to |
| 45 // filter here too? |
| 46 std::set<std::string> allowed; |
| 47 allowed.insert("*"); |
| 48 shell::mojom::InterfaceProviderPtr local_interfaces; |
| 49 shell::mojom::InterfaceProviderRequest local_request = |
| 50 GetProxy(&local_interfaces); |
| 51 shell::mojom::InterfaceProviderPtr remote_interfaces; |
| 52 shell::mojom::InterfaceProviderRequest remote_request = |
| 53 GetProxy(&remote_interfaces); |
| 54 scoped_ptr<internal::ConnectionImpl> registry(new internal::ConnectionImpl( |
| 55 application_url, application_url, |
| 56 shell::mojom::Connector::kInvalidApplicationID, params->user_id(), |
| 57 std::move(remote_interfaces), std::move(local_request), allowed)); |
| 58 connector_->Connect(application_url, |
| 59 params->user_id(), |
| 60 std::move(remote_request), |
| 61 std::move(local_interfaces), |
| 62 params->TakeFilter(), |
| 63 registry->GetConnectCallback()); |
| 64 return std::move(registry); |
| 65 } |
| 66 |
| 67 scoped_ptr<Connector> ConnectorImpl::Clone() { |
| 68 shell::mojom::ConnectorPtr connector; |
| 69 connector_->Clone(GetProxy(&connector)); |
| 70 return make_scoped_ptr( |
| 71 new ConnectorImpl(connector.PassInterface())); |
| 72 } |
| 73 |
| 74 } // namespace mojo |
OLD | NEW |