| 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 15 matching lines...) Expand all Loading... |
| 26 id_(GenerateUniqueID()), | 26 id_(GenerateUniqueID()), |
| 27 identity_(identity), | 27 identity_(identity), |
| 28 allow_any_application_(identity.filter().size() == 1 && | 28 allow_any_application_(identity.filter().size() == 1 && |
| 29 identity.filter().count("*") == 1), | 29 identity.filter().count("*") == 1), |
| 30 shell_client_(std::move(shell_client)), | 30 shell_client_(std::move(shell_client)), |
| 31 binding_(this), | 31 binding_(this), |
| 32 pid_receiver_binding_(this), | 32 pid_receiver_binding_(this), |
| 33 queue_requests_(false), | 33 queue_requests_(false), |
| 34 native_runner_(nullptr), | 34 native_runner_(nullptr), |
| 35 pid_(base::kNullProcessId) { | 35 pid_(base::kNullProcessId) { |
| 36 DCHECK_NE(Shell::kInvalidApplicationID, id_); | 36 DCHECK_NE(kInvalidApplicationID, id_); |
| 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(), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 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::GetConnector(mojom::ConnectorRequest request) { |
| 71 connectors_.AddBinding(this, std::move(request)); |
| 72 } |
| 73 |
| 74 void ApplicationInstance::QuitApplication() { |
| 75 queue_requests_ = true; |
| 76 shell_client_->OnQuitRequested( |
| 77 base::Bind(&ApplicationInstance::OnQuitRequestedResult, |
| 78 base::Unretained(this))); |
| 79 } |
| 80 |
| 81 // Connector implementation: |
| 70 void ApplicationInstance::Connect( | 82 void ApplicationInstance::Connect( |
| 71 const String& app_url, | 83 const String& app_url, |
| 72 uint32_t user_id, | 84 uint32_t user_id, |
| 73 shell::mojom::InterfaceProviderRequest remote_interfaces, | 85 shell::mojom::InterfaceProviderRequest remote_interfaces, |
| 74 shell::mojom::InterfaceProviderPtr local_interfaces, | 86 shell::mojom::InterfaceProviderPtr local_interfaces, |
| 75 mojom::CapabilityFilterPtr filter, | 87 mojom::CapabilityFilterPtr filter, |
| 76 const ConnectCallback& callback) { | 88 const ConnectCallback& callback) { |
| 77 GURL url = app_url.To<GURL>(); | 89 GURL url = app_url.To<GURL>(); |
| 78 if (!url.is_valid()) { | 90 if (!url.is_valid()) { |
| 79 LOG(ERROR) << "Error: invalid URL: " << app_url; | 91 LOG(ERROR) << "Error: invalid URL: " << app_url; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 94 params->set_local_interfaces(std::move(local_interfaces)); | 106 params->set_local_interfaces(std::move(local_interfaces)); |
| 95 params->set_connect_callback(callback); | 107 params->set_connect_callback(callback); |
| 96 manager_->Connect(std::move(params)); | 108 manager_->Connect(std::move(params)); |
| 97 } else { | 109 } else { |
| 98 LOG(WARNING) << "CapabilityFilter prevented connection from: " << | 110 LOG(WARNING) << "CapabilityFilter prevented connection from: " << |
| 99 identity_.url() << " to: " << url.spec(); | 111 identity_.url() << " to: " << url.spec(); |
| 100 callback.Run(kInvalidApplicationID); | 112 callback.Run(kInvalidApplicationID); |
| 101 } | 113 } |
| 102 } | 114 } |
| 103 | 115 |
| 104 void ApplicationInstance::QuitApplication() { | 116 void ApplicationInstance::Clone(mojom::ConnectorRequest request) { |
| 105 queue_requests_ = true; | 117 connectors_.AddBinding(this, std::move(request)); |
| 106 shell_client_->OnQuitRequested( | |
| 107 base::Bind(&ApplicationInstance::OnQuitRequestedResult, | |
| 108 base::Unretained(this))); | |
| 109 } | 118 } |
| 110 | 119 |
| 111 void ApplicationInstance::SetPID(uint32_t pid) { | 120 void ApplicationInstance::SetPID(uint32_t pid) { |
| 112 // This will call us back to update pid_. | 121 // This will call us back to update pid_. |
| 113 manager_->ApplicationPIDAvailable(id_, pid); | 122 manager_->ApplicationPIDAvailable(id_, pid); |
| 114 } | 123 } |
| 115 | 124 |
| 116 uint32_t ApplicationInstance::GenerateUniqueID() const { | 125 uint32_t ApplicationInstance::GenerateUniqueID() const { |
| 117 static uint32_t id = Shell::kInvalidApplicationID; | 126 static uint32_t id = kInvalidApplicationID; |
| 118 ++id; | 127 ++id; |
| 119 CHECK_NE(Shell::kInvalidApplicationID, id); | 128 CHECK_NE(kInvalidApplicationID, id); |
| 120 return id; | 129 return id; |
| 121 } | 130 } |
| 122 | 131 |
| 123 void ApplicationInstance::CallAcceptConnection( | 132 void ApplicationInstance::CallAcceptConnection( |
| 124 scoped_ptr<ConnectParams> params) { | 133 scoped_ptr<ConnectParams> params) { |
| 125 params->connect_callback().Run(id_); | 134 params->connect_callback().Run(id_); |
| 126 AllowedInterfaces interfaces; | 135 AllowedInterfaces interfaces; |
| 127 interfaces.insert("*"); | 136 interfaces.insert("*"); |
| 128 if (!params->source().is_null()) | 137 if (!params->source().is_null()) |
| 129 interfaces = GetAllowedInterfaces(params->source().filter(), identity_); | 138 interfaces = GetAllowedInterfaces(params->source().filter(), identity_); |
| 130 | 139 |
| 131 ApplicationInstance* source = | 140 ApplicationInstance* source = |
| 132 manager_->GetApplicationInstance(params->source()); | 141 manager_->GetApplicationInstance(params->source()); |
| 133 uint32_t source_id = source ? source->id() : Shell::kInvalidApplicationID; | 142 uint32_t source_id = source ? source->id() : kInvalidApplicationID; |
| 134 shell_client_->AcceptConnection( | 143 shell_client_->AcceptConnection( |
| 135 params->source().url().spec(), params->source().user_id(), source_id, | 144 params->source().url().spec(), params->source().user_id(), source_id, |
| 136 params->TakeRemoteInterfaces(), params->TakeLocalInterfaces(), | 145 params->TakeRemoteInterfaces(), params->TakeLocalInterfaces(), |
| 137 Array<String>::From(interfaces), params->target().url().spec()); | 146 Array<String>::From(interfaces), params->target().url().spec()); |
| 138 } | 147 } |
| 139 | 148 |
| 140 void ApplicationInstance::OnConnectionError() { | 149 void ApplicationInstance::OnConnectionError() { |
| 141 std::vector<ConnectParams*> queued_client_requests; | 150 std::vector<ConnectParams*> queued_client_requests; |
| 142 queued_client_requests_.swap(queued_client_requests); | 151 queued_client_requests_.swap(queued_client_requests); |
| 143 auto manager = manager_; | 152 auto manager = manager_; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 156 | 165 |
| 157 queue_requests_ = false; | 166 queue_requests_ = false; |
| 158 for (auto request : queued_client_requests_) | 167 for (auto request : queued_client_requests_) |
| 159 CallAcceptConnection(make_scoped_ptr(request)); | 168 CallAcceptConnection(make_scoped_ptr(request)); |
| 160 | 169 |
| 161 queued_client_requests_.clear(); | 170 queued_client_requests_.clear(); |
| 162 } | 171 } |
| 163 | 172 |
| 164 } // namespace shell | 173 } // namespace shell |
| 165 } // namespace mojo | 174 } // namespace mojo |
| OLD | NEW |