| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/shell/application_instance.h" | 5 #include "mojo/shell/application_instance.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 } | 37 } |
| 38 | 38 |
| 39 ApplicationInstance::~ApplicationInstance() { | 39 ApplicationInstance::~ApplicationInstance() { |
| 40 for (auto request : queued_client_requests_) | 40 for (auto request : queued_client_requests_) |
| 41 request->connect_callback().Run(kInvalidApplicationID); | 41 request->connect_callback().Run(kInvalidApplicationID); |
| 42 STLDeleteElements(&queued_client_requests_); | 42 STLDeleteElements(&queued_client_requests_); |
| 43 } | 43 } |
| 44 | 44 |
| 45 void ApplicationInstance::InitializeApplication() { | 45 void ApplicationInstance::InitializeApplication() { |
| 46 shell_client_->Initialize(binding_.CreateInterfacePtrAndBind(), | 46 shell_client_->Initialize(binding_.CreateInterfacePtrAndBind(), |
| 47 identity_.url().spec(), id_); | 47 identity_.url().spec(), id_, identity_.user_id()); |
| 48 binding_.set_connection_error_handler([this]() { OnConnectionError(); }); | 48 binding_.set_connection_error_handler([this]() { OnConnectionError(); }); |
| 49 } | 49 } |
| 50 | 50 |
| 51 void ApplicationInstance::ConnectToClient(scoped_ptr<ConnectParams> params) { | 51 void ApplicationInstance::ConnectToClient(scoped_ptr<ConnectParams> params) { |
| 52 if (queue_requests_) { | 52 if (queue_requests_) { |
| 53 queued_client_requests_.push_back(params.release()); | 53 queued_client_requests_.push_back(params.release()); |
| 54 return; | 54 return; |
| 55 } | 55 } |
| 56 | 56 |
| 57 CallAcceptConnection(std::move(params)); | 57 CallAcceptConnection(std::move(params)); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void ApplicationInstance::SetNativeRunner(NativeRunner* native_runner) { | 60 void ApplicationInstance::SetNativeRunner(NativeRunner* native_runner) { |
| 61 native_runner_ = native_runner; | 61 native_runner_ = native_runner; |
| 62 } | 62 } |
| 63 | 63 |
| 64 void ApplicationInstance::BindPIDReceiver( | 64 void ApplicationInstance::BindPIDReceiver( |
| 65 InterfaceRequest<mojom::PIDReceiver> pid_receiver) { | 65 InterfaceRequest<mojom::PIDReceiver> pid_receiver) { |
| 66 pid_receiver_binding_.Bind(std::move(pid_receiver)); | 66 pid_receiver_binding_.Bind(std::move(pid_receiver)); |
| 67 } | 67 } |
| 68 | 68 |
| 69 // Shell implementation: | 69 // Shell implementation: |
| 70 void ApplicationInstance::Connect( | 70 void ApplicationInstance::Connect( |
| 71 const String& app_url, | 71 const String& app_url, |
| 72 uint32_t user_id, |
| 72 shell::mojom::InterfaceProviderRequest remote_interfaces, | 73 shell::mojom::InterfaceProviderRequest remote_interfaces, |
| 73 shell::mojom::InterfaceProviderPtr local_interfaces, | 74 shell::mojom::InterfaceProviderPtr local_interfaces, |
| 74 mojom::CapabilityFilterPtr filter, | 75 mojom::CapabilityFilterPtr filter, |
| 75 const ConnectCallback& callback) { | 76 const ConnectCallback& callback) { |
| 76 GURL url = app_url.To<GURL>(); | 77 GURL url = app_url.To<GURL>(); |
| 77 if (!url.is_valid()) { | 78 if (!url.is_valid()) { |
| 78 LOG(ERROR) << "Error: invalid URL: " << app_url; | 79 LOG(ERROR) << "Error: invalid URL: " << app_url; |
| 79 callback.Run(kInvalidApplicationID); | 80 callback.Run(kInvalidApplicationID); |
| 80 return; | 81 return; |
| 81 } | 82 } |
| 82 if (allow_any_application_ || | 83 if (allow_any_application_ || |
| 83 identity_.filter().find(url.spec()) != identity_.filter().end()) { | 84 identity_.filter().find(url.spec()) != identity_.filter().end()) { |
| 84 CapabilityFilter capability_filter = GetPermissiveCapabilityFilter(); | 85 CapabilityFilter capability_filter = GetPermissiveCapabilityFilter(); |
| 85 if (!filter.is_null()) | 86 if (!filter.is_null()) |
| 86 capability_filter = filter->filter.To<CapabilityFilter>(); | 87 capability_filter = filter->filter.To<CapabilityFilter>(); |
| 87 | 88 |
| 88 scoped_ptr<ConnectParams> params(new ConnectParams); | 89 scoped_ptr<ConnectParams> params(new ConnectParams); |
| 89 params->SetSource(this); | 90 params->set_source(identity_); |
| 90 params->set_target(Identity(url, std::string(), capability_filter)); | 91 params->set_target( |
| 92 Identity(url, std::string(), user_id, capability_filter)); |
| 91 params->set_remote_interfaces(std::move(remote_interfaces)); | 93 params->set_remote_interfaces(std::move(remote_interfaces)); |
| 92 params->set_local_interfaces(std::move(local_interfaces)); | 94 params->set_local_interfaces(std::move(local_interfaces)); |
| 93 params->set_connect_callback(callback); | 95 params->set_connect_callback(callback); |
| 94 manager_->Connect(std::move(params)); | 96 manager_->Connect(std::move(params)); |
| 95 } else { | 97 } else { |
| 96 LOG(WARNING) << "CapabilityFilter prevented connection from: " << | 98 LOG(WARNING) << "CapabilityFilter prevented connection from: " << |
| 97 identity_.url() << " to: " << url.spec(); | 99 identity_.url() << " to: " << url.spec(); |
| 98 callback.Run(kInvalidApplicationID); | 100 callback.Run(kInvalidApplicationID); |
| 99 } | 101 } |
| 100 } | 102 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 123 params->connect_callback().Run(id_); | 125 params->connect_callback().Run(id_); |
| 124 AllowedInterfaces interfaces; | 126 AllowedInterfaces interfaces; |
| 125 interfaces.insert("*"); | 127 interfaces.insert("*"); |
| 126 if (!params->source().is_null()) | 128 if (!params->source().is_null()) |
| 127 interfaces = GetAllowedInterfaces(params->source().filter(), identity_); | 129 interfaces = GetAllowedInterfaces(params->source().filter(), identity_); |
| 128 | 130 |
| 129 ApplicationInstance* source = | 131 ApplicationInstance* source = |
| 130 manager_->GetApplicationInstance(params->source()); | 132 manager_->GetApplicationInstance(params->source()); |
| 131 uint32_t source_id = source ? source->id() : Shell::kInvalidApplicationID; | 133 uint32_t source_id = source ? source->id() : Shell::kInvalidApplicationID; |
| 132 shell_client_->AcceptConnection( | 134 shell_client_->AcceptConnection( |
| 133 params->source().url().spec(), source_id, params->TakeRemoteInterfaces(), | 135 params->source().url().spec(), params->source().user_id(), source_id, |
| 134 params->TakeLocalInterfaces(), Array<String>::From(interfaces), | 136 params->TakeRemoteInterfaces(), params->TakeLocalInterfaces(), |
| 135 params->target().url().spec()); | 137 Array<String>::From(interfaces), params->target().url().spec()); |
| 136 } | 138 } |
| 137 | 139 |
| 138 void ApplicationInstance::OnConnectionError() { | 140 void ApplicationInstance::OnConnectionError() { |
| 139 std::vector<ConnectParams*> queued_client_requests; | 141 std::vector<ConnectParams*> queued_client_requests; |
| 140 queued_client_requests_.swap(queued_client_requests); | 142 queued_client_requests_.swap(queued_client_requests); |
| 141 auto manager = manager_; | 143 auto manager = manager_; |
| 142 manager_->OnApplicationInstanceError(this); | 144 manager_->OnApplicationInstanceError(this); |
| 143 //|this| is deleted. | 145 //|this| is deleted. |
| 144 | 146 |
| 145 // If any queued requests came to shell during time it was shutting down, | 147 // If any queued requests came to shell during time it was shutting down, |
| 146 // start them now. | 148 // start them now. |
| 147 for (auto request : queued_client_requests) | 149 for (auto request : queued_client_requests) |
| 148 manager->Connect(make_scoped_ptr(request)); | 150 manager->Connect(make_scoped_ptr(request)); |
| 149 } | 151 } |
| 150 | 152 |
| 151 void ApplicationInstance::OnQuitRequestedResult(bool can_quit) { | 153 void ApplicationInstance::OnQuitRequestedResult(bool can_quit) { |
| 152 if (can_quit) | 154 if (can_quit) |
| 153 return; | 155 return; |
| 154 | 156 |
| 155 queue_requests_ = false; | 157 queue_requests_ = false; |
| 156 for (auto request : queued_client_requests_) | 158 for (auto request : queued_client_requests_) |
| 157 CallAcceptConnection(make_scoped_ptr(request)); | 159 CallAcceptConnection(make_scoped_ptr(request)); |
| 158 | 160 |
| 159 queued_client_requests_.clear(); | 161 queued_client_requests_.clear(); |
| 160 } | 162 } |
| 161 | 163 |
| 162 } // namespace shell | 164 } // namespace shell |
| 163 } // namespace mojo | 165 } // namespace mojo |
| OLD | NEW |