| 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 |
| 11 #include "base/atomic_sequence_num.h" | 11 #include "base/atomic_sequence_num.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "mojo/common/common_type_converters.h" | 14 #include "mojo/common/common_type_converters.h" |
| 15 #include "mojo/common/url_type_converters.h" | 15 #include "mojo/common/url_type_converters.h" |
| 16 #include "mojo/shell/application_manager.h" | 16 #include "mojo/shell/application_manager.h" |
| 17 #include "mojo/shell/public/interfaces/content_handler.mojom.h" | |
| 18 | 17 |
| 19 namespace mojo { | 18 namespace mojo { |
| 20 namespace shell { | 19 namespace shell { |
| 21 | 20 |
| 22 ApplicationInstance::ApplicationInstance( | 21 ApplicationInstance::ApplicationInstance( |
| 23 mojom::ShellClientPtr shell_client, | 22 mojom::ShellClientPtr shell_client, |
| 24 ApplicationManager* manager, | 23 ApplicationManager* manager, |
| 25 const Identity& identity, | 24 const Identity& identity, |
| 26 uint32_t requesting_content_handler_id, | 25 uint32_t requesting_shell_client_factory_id, |
| 27 const mojom::Shell::ConnectToApplicationCallback& connect_callback, | 26 const mojom::Shell::ConnectToApplicationCallback& connect_callback, |
| 28 const base::Closure& on_application_end, | 27 const base::Closure& on_application_end, |
| 29 const String& application_name) | 28 const String& application_name) |
| 30 : manager_(manager), | 29 : manager_(manager), |
| 31 id_(GenerateUniqueID()), | 30 id_(GenerateUniqueID()), |
| 32 identity_(identity), | 31 identity_(identity), |
| 33 allow_any_application_(identity.filter().size() == 1 && | 32 allow_any_application_(identity.filter().size() == 1 && |
| 34 identity.filter().count("*") == 1), | 33 identity.filter().count("*") == 1), |
| 35 requesting_content_handler_id_(requesting_content_handler_id), | 34 requesting_shell_client_factory_id_(requesting_shell_client_factory_id), |
| 36 connect_callback_(connect_callback), | 35 connect_callback_(connect_callback), |
| 37 on_application_end_(on_application_end), | 36 on_application_end_(on_application_end), |
| 38 shell_client_(std::move(shell_client)), | 37 shell_client_(std::move(shell_client)), |
| 39 binding_(this), | 38 binding_(this), |
| 40 pid_receiver_binding_(this), | 39 pid_receiver_binding_(this), |
| 41 queue_requests_(false), | 40 queue_requests_(false), |
| 42 native_runner_(nullptr), | 41 native_runner_(nullptr), |
| 43 application_name_(application_name), | 42 application_name_(application_name), |
| 44 pid_(base::kNullProcessId) { | 43 pid_(base::kNullProcessId) { |
| 45 DCHECK_NE(Shell::kInvalidApplicationID, id_); | 44 DCHECK_NE(Shell::kInvalidApplicationID, id_); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 73 native_runner_ = native_runner; | 72 native_runner_ = native_runner; |
| 74 } | 73 } |
| 75 | 74 |
| 76 void ApplicationInstance::BindPIDReceiver( | 75 void ApplicationInstance::BindPIDReceiver( |
| 77 InterfaceRequest<mojom::PIDReceiver> pid_receiver) { | 76 InterfaceRequest<mojom::PIDReceiver> pid_receiver) { |
| 78 pid_receiver_binding_.Bind(std::move(pid_receiver)); | 77 pid_receiver_binding_.Bind(std::move(pid_receiver)); |
| 79 } | 78 } |
| 80 | 79 |
| 81 void ApplicationInstance::RunConnectCallback() { | 80 void ApplicationInstance::RunConnectCallback() { |
| 82 if (!connect_callback_.is_null()) | 81 if (!connect_callback_.is_null()) |
| 83 connect_callback_.Run(id_, requesting_content_handler_id_); | 82 connect_callback_.Run(id_, requesting_shell_client_factory_id_); |
| 84 } | 83 } |
| 85 | 84 |
| 86 // Shell implementation: | 85 // Shell implementation: |
| 87 void ApplicationInstance::ConnectToApplication( | 86 void ApplicationInstance::ConnectToApplication( |
| 88 URLRequestPtr app_request, | 87 URLRequestPtr app_request, |
| 89 shell::mojom::InterfaceProviderRequest remote_interfaces, | 88 shell::mojom::InterfaceProviderRequest remote_interfaces, |
| 90 shell::mojom::InterfaceProviderPtr local_interfaces, | 89 shell::mojom::InterfaceProviderPtr local_interfaces, |
| 91 mojom::CapabilityFilterPtr filter, | 90 mojom::CapabilityFilterPtr filter, |
| 92 const ConnectToApplicationCallback& callback) { | 91 const ConnectToApplicationCallback& callback) { |
| 93 std::string url_string = app_request->url.To<std::string>(); | 92 std::string url_string = app_request->url.To<std::string>(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 | 134 |
| 136 uint32_t ApplicationInstance::GenerateUniqueID() const { | 135 uint32_t ApplicationInstance::GenerateUniqueID() const { |
| 137 static uint32_t id = Shell::kInvalidApplicationID; | 136 static uint32_t id = Shell::kInvalidApplicationID; |
| 138 ++id; | 137 ++id; |
| 139 CHECK_NE(Shell::kInvalidApplicationID, id); | 138 CHECK_NE(Shell::kInvalidApplicationID, id); |
| 140 return id; | 139 return id; |
| 141 } | 140 } |
| 142 | 141 |
| 143 void ApplicationInstance::CallAcceptConnection( | 142 void ApplicationInstance::CallAcceptConnection( |
| 144 scoped_ptr<ConnectToApplicationParams> params) { | 143 scoped_ptr<ConnectToApplicationParams> params) { |
| 145 params->connect_callback().Run(id_, requesting_content_handler_id_); | 144 params->connect_callback().Run(id_, requesting_shell_client_factory_id_); |
| 146 AllowedInterfaces interfaces; | 145 AllowedInterfaces interfaces; |
| 147 interfaces.insert("*"); | 146 interfaces.insert("*"); |
| 148 if (!params->source().is_null()) | 147 if (!params->source().is_null()) |
| 149 interfaces = GetAllowedInterfaces(params->source().filter(), identity_); | 148 interfaces = GetAllowedInterfaces(params->source().filter(), identity_); |
| 150 | 149 |
| 151 ApplicationInstance* source = | 150 ApplicationInstance* source = |
| 152 manager_->GetApplicationInstance(params->source()); | 151 manager_->GetApplicationInstance(params->source()); |
| 153 uint32_t source_id = source ? source->id() : Shell::kInvalidApplicationID; | 152 uint32_t source_id = source ? source->id() : Shell::kInvalidApplicationID; |
| 154 shell_client_->AcceptConnection( | 153 shell_client_->AcceptConnection( |
| 155 params->source().url().spec(), source_id, params->TakeRemoteInterfaces(), | 154 params->source().url().spec(), source_id, params->TakeRemoteInterfaces(), |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 | 199 |
| 201 queue_requests_ = false; | 200 queue_requests_ = false; |
| 202 for (auto request : queued_client_requests_) | 201 for (auto request : queued_client_requests_) |
| 203 CallAcceptConnection(make_scoped_ptr(request)); | 202 CallAcceptConnection(make_scoped_ptr(request)); |
| 204 | 203 |
| 205 queued_client_requests_.clear(); | 204 queued_client_requests_.clear(); |
| 206 } | 205 } |
| 207 | 206 |
| 208 } // namespace shell | 207 } // namespace shell |
| 209 } // namespace mojo | 208 } // namespace mojo |
| OLD | NEW |