Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: mojo/shell/shell.cc

Issue 1775113003: Morph CapabilityFilter into caps::Capabilities, which supports capability classes (yet unimplemente… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@44cattests
Patch Set: . Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/shell/shell.h ('k') | mojo/shell/tests/connect/connect_test_app_manifest.json » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "mojo/shell/shell.h" 5 #include "mojo/shell/shell.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 20 matching lines...) Expand all
31 #include "mojo/shell/public/interfaces/shell_client.mojom.h" 31 #include "mojo/shell/public/interfaces/shell_client.mojom.h"
32 #include "mojo/util/filename_util.h" 32 #include "mojo/util/filename_util.h"
33 33
34 namespace mojo { 34 namespace mojo {
35 namespace shell { 35 namespace shell {
36 namespace { 36 namespace {
37 const char kCatalogName[] = "mojo:catalog"; 37 const char kCatalogName[] = "mojo:catalog";
38 38
39 void EmptyResolverCallback(const String& resolved_name, 39 void EmptyResolverCallback(const String& resolved_name,
40 const String& resolved_instance, 40 const String& resolved_instance,
41 mojom::CapabilityFilterPtr base_filter, 41 mojom::CapabilitySpecPtr capabilities,
42 const String& file_url) {} 42 const String& file_url) {}
43 43
44 } 44 }
45 45
46 Identity CreateShellIdentity() { 46 Identity CreateShellIdentity() {
47 return Identity("mojo:shell", mojom::kRootUserID); 47 return Identity("mojo:shell", mojom::kRootUserID);
48 } 48 }
49 49
50 CapabilityFilter GetPermissiveCapabilityFilter() { 50 CapabilitySpec GetPermissiveCapabilities() {
51 CapabilityFilter filter; 51 CapabilitySpec capabilities;
52 AllowedInterfaces interfaces; 52 CapabilityRequest spec;
53 interfaces.insert("*"); 53 spec.interfaces.insert("*");
54 filter["*"] = interfaces; 54 capabilities.required["*"] = spec;
55 return filter; 55 return capabilities;
56 } 56 }
57 57
58 AllowedInterfaces GetAllowedInterfaces(const CapabilityFilter& filter, 58 CapabilityRequest GetCapabilityRequest(const CapabilitySpec& spec,
59 const Identity& identity) { 59 const Identity& identity) {
60 // Start by looking for interfaces specific to the supplied identity. 60 // Start by looking for specs specific to the supplied identity.
61 auto it = filter.find(identity.name()); 61 auto it = spec.required.find(identity.name());
62 if (it != filter.end()) 62 if (it != spec.required.end())
63 return it->second; 63 return it->second;
64 64
65 // Fall back to looking for a wildcard rule. 65 // Fall back to looking for a wildcard rule.
66 it = filter.find("*"); 66 it = spec.required.find("*");
67 if (filter.size() == 1 && it != filter.end()) 67 if (spec.required.size() == 1 && it != spec.required.end())
68 return it->second; 68 return it->second;
69 69
70 // Finally, nothing is allowed. 70 // Finally, nothing is allowed.
71 return AllowedInterfaces(); 71 return CapabilityRequest();
72 } 72 }
73 73
74 // Encapsulates a connection to an instance of an application, tracked by the 74 // Encapsulates a connection to an instance of an application, tracked by the
75 // shell's Shell. 75 // shell's Shell.
76 class Shell::Instance : public mojom::Connector, 76 class Shell::Instance : public mojom::Connector,
77 public mojom::PIDReceiver, 77 public mojom::PIDReceiver,
78 public ShellClient, 78 public ShellClient,
79 public InterfaceFactory<mojom::Shell>, 79 public InterfaceFactory<mojom::Shell>,
80 public mojom::Shell { 80 public mojom::Shell {
81 public: 81 public:
82 Instance(mojom::ShellClientPtr shell_client, 82 Instance(mojom::ShellClientPtr shell_client,
83 mojo::shell::Shell* shell, 83 mojo::shell::Shell* shell,
84 const Identity& identity, 84 const Identity& identity,
85 const CapabilityFilter& filter) 85 const CapabilitySpec& capabilities)
86 : shell_(shell), 86 : shell_(shell),
87 id_(GenerateUniqueID()), 87 id_(GenerateUniqueID()),
88 identity_(identity), 88 identity_(identity),
89 filter_(filter), 89 capabilities_(capabilities),
90 allow_any_application_(filter.size() == 1 && filter.count("*") == 1), 90 allow_any_application_(capabilities.required.size() == 1 &&
91 capabilities.required.count("*") == 1),
91 shell_client_(std::move(shell_client)), 92 shell_client_(std::move(shell_client)),
92 pid_receiver_binding_(this), 93 pid_receiver_binding_(this),
93 weak_factory_(this) { 94 weak_factory_(this) {
94 if (identity_.name() == "mojo:shell" || 95 if (identity_.name() == "mojo:shell" ||
95 shell_->GetLoaderForName(identity_.name())) { 96 shell_->GetLoaderForName(identity_.name())) {
96 pid_ = base::Process::Current().Pid(); 97 pid_ = base::Process::Current().Pid();
97 } 98 }
98 DCHECK_NE(mojom::kInvalidInstanceID, id_); 99 DCHECK_NE(mojom::kInvalidInstanceID, id_);
99 } 100 }
100 101
101 ~Instance() override {} 102 ~Instance() override {}
102 103
103 void InitializeClient() { 104 void InitializeClient() {
104 shell_client_->Initialize(connectors_.CreateInterfacePtrAndBind(this), 105 shell_client_->Initialize(connectors_.CreateInterfacePtrAndBind(this),
105 mojom::Identity::From(identity_), id_); 106 mojom::Identity::From(identity_), id_);
106 connectors_.set_connection_error_handler( 107 connectors_.set_connection_error_handler(
107 base::Bind(&mojo::shell::Shell::OnInstanceError, 108 base::Bind(&mojo::shell::Shell::OnInstanceError,
108 base::Unretained(shell_), base::Unretained(this))); 109 base::Unretained(shell_), base::Unretained(this)));
109 } 110 }
110 111
111 void ConnectToClient(scoped_ptr<ConnectParams> params) { 112 void ConnectToClient(scoped_ptr<ConnectParams> params) {
112 params->connect_callback().Run(mojom::ConnectResult::SUCCEEDED, 113 params->connect_callback().Run(mojom::ConnectResult::SUCCEEDED,
113 identity_.user_id(), id_); 114 identity_.user_id(), id_);
114 uint32_t source_id = mojom::kInvalidInstanceID; 115 uint32_t source_id = mojom::kInvalidInstanceID;
115 AllowedInterfaces interfaces; 116 CapabilityRequest spec;
116 interfaces.insert("*"); 117 spec.interfaces.insert("*");
117 Instance* source = shell_->GetExistingInstance(params->source()); 118 Instance* source = shell_->GetExistingInstance(params->source());
118 if (source) { 119 if (source) {
119 interfaces = GetAllowedInterfaces(source->filter_, identity_); 120 spec = GetCapabilityRequest(source->capabilities_, identity_);
120 source_id = source->id(); 121 source_id = source->id();
121 } 122 }
122 shell_client_->AcceptConnection( 123 shell_client_->AcceptConnection(
123 mojom::Identity::From(params->source()), source_id, 124 mojom::Identity::From(params->source()), source_id,
124 params->TakeRemoteInterfaces(), params->TakeLocalInterfaces(), 125 params->TakeRemoteInterfaces(), params->TakeLocalInterfaces(),
125 Array<String>::From(interfaces), params->target().name()); 126 mojom::CapabilityRequest::From(spec), params->target().name());
126 } 127 }
127 128
128 void StartWithClientProcessConnection( 129 void StartWithClientProcessConnection(
129 mojom::ShellClientRequest request, 130 mojom::ShellClientRequest request,
130 mojom::ClientProcessConnectionPtr client_process_connection) { 131 mojom::ClientProcessConnectionPtr client_process_connection) {
131 factory_.Bind(mojom::ShellClientFactoryPtrInfo( 132 factory_.Bind(mojom::ShellClientFactoryPtrInfo(
132 std::move(client_process_connection->shell_client_factory), 0u)); 133 std::move(client_process_connection->shell_client_factory), 0u));
133 pid_receiver_binding_.Bind( 134 pid_receiver_binding_.Bind(
134 std::move(client_process_connection->pid_receiver_request)); 135 std::move(client_process_connection->pid_receiver_request));
135 factory_->CreateShellClient(std::move(request), identity_.name()); 136 factory_->CreateShellClient(std::move(request), identity_.name());
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 return; 179 return;
179 if (!ValidateClientProcessConnection(&client_process_connection, target, 180 if (!ValidateClientProcessConnection(&client_process_connection, target,
180 callback)) { 181 callback)) {
181 return; 182 return;
182 } 183 }
183 // TODO(beng): Need to do the following additional policy validation of 184 // TODO(beng): Need to do the following additional policy validation of
184 // whether this instance is allowed to connect using: 185 // whether this instance is allowed to connect using:
185 // - a user id other than its own, kInheritUserID or kRootUserID. 186 // - a user id other than its own, kInheritUserID or kRootUserID.
186 // - a non-empty instance name. 187 // - a non-empty instance name.
187 // - a non-null client_process_connection. 188 // - a non-null client_process_connection.
188 if (!ValidateCapabilityFilter(target, callback)) 189 if (!ValidateCapabilities(target, callback))
189 return; 190 return;
190 191
191 scoped_ptr<ConnectParams> params(new ConnectParams); 192 scoped_ptr<ConnectParams> params(new ConnectParams);
192 params->set_source(identity_); 193 params->set_source(identity_);
193 params->set_target(target); 194 params->set_target(target);
194 params->set_remote_interfaces(std::move(remote_interfaces)); 195 params->set_remote_interfaces(std::move(remote_interfaces));
195 params->set_local_interfaces(std::move(local_interfaces)); 196 params->set_local_interfaces(std::move(local_interfaces));
196 params->set_client_process_connection(std::move(client_process_connection)); 197 params->set_client_process_connection(std::move(client_process_connection));
197 params->set_connect_callback(callback); 198 params->set_connect_callback(callback);
198 shell_->Connect(std::move(params)); 199 shell_->Connect(std::move(params));
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 << identity.user_id() << " Instance: " 257 << identity.user_id() << " Instance: "
257 << identity.instance(); 258 << identity.instance();
258 callback.Run(mojom::ConnectResult::INVALID_ARGUMENT, 259 callback.Run(mojom::ConnectResult::INVALID_ARGUMENT,
259 mojom::kInheritUserID, mojom::kInvalidInstanceID); 260 mojom::kInheritUserID, mojom::kInvalidInstanceID);
260 return false; 261 return false;
261 } 262 }
262 } 263 }
263 return true; 264 return true;
264 } 265 }
265 266
266 bool ValidateCapabilityFilter(const Identity& target, 267 bool ValidateCapabilities(const Identity& target,
267 const ConnectCallback& callback) { 268 const ConnectCallback& callback) {
268 if (allow_any_application_ || 269 if (allow_any_application_ ||
269 filter_.find(target.name()) != filter_.end()) { 270 capabilities_.required.find(target.name()) !=
271 capabilities_.required.end()) {
270 return true; 272 return true;
271 } 273 }
272 LOG(ERROR) << "CapabilityFilter prevented connection from: " << 274 LOG(ERROR) << "Capabilities prevented connection from: " <<
273 identity_.name() << " to: " << target.name(); 275 identity_.name() << " to: " << target.name();
274 callback.Run(mojom::ConnectResult::ACCESS_DENIED, 276 callback.Run(mojom::ConnectResult::ACCESS_DENIED,
275 mojom::kInheritUserID, mojom::kInvalidInstanceID); 277 mojom::kInheritUserID, mojom::kInvalidInstanceID);
276 return false; 278 return false;
277 } 279 }
278 280
279 uint32_t GenerateUniqueID() const { 281 uint32_t GenerateUniqueID() const {
280 static uint32_t id = mojom::kInvalidInstanceID; 282 static uint32_t id = mojom::kInvalidInstanceID;
281 ++id; 283 ++id;
282 CHECK_NE(mojom::kInvalidInstanceID, id); 284 CHECK_NE(mojom::kInvalidInstanceID, id);
283 return id; 285 return id;
284 } 286 }
285 287
286 void PIDAvailable(base::ProcessId pid) { 288 void PIDAvailable(base::ProcessId pid) {
287 pid_ = pid; 289 pid_ = pid;
288 shell_->NotifyPIDAvailable(id_, pid_); 290 shell_->NotifyPIDAvailable(id_, pid_);
289 } 291 }
290 292
291 mojo::shell::Shell* const shell_; 293 mojo::shell::Shell* const shell_;
292 // An id that identifies this instance. Distinct from pid, as a single process 294 // An id that identifies this instance. Distinct from pid, as a single process
293 // may vend multiple application instances, and this object may exist before a 295 // may vend multiple application instances, and this object may exist before a
294 // process is launched. 296 // process is launched.
295 const uint32_t id_; 297 const uint32_t id_;
296 const Identity identity_; 298 const Identity identity_;
297 const CapabilityFilter filter_; 299 const CapabilitySpec capabilities_;
298 const bool allow_any_application_; 300 const bool allow_any_application_;
299 mojom::ShellClientPtr shell_client_; 301 mojom::ShellClientPtr shell_client_;
300 Binding<mojom::PIDReceiver> pid_receiver_binding_; 302 Binding<mojom::PIDReceiver> pid_receiver_binding_;
301 BindingSet<mojom::Connector> connectors_; 303 BindingSet<mojom::Connector> connectors_;
302 BindingSet<mojom::Shell> shell_bindings_; 304 BindingSet<mojom::Shell> shell_bindings_;
303 mojom::ShellClientFactoryPtr factory_; 305 mojom::ShellClientFactoryPtr factory_;
304 NativeRunner* runner_ = nullptr; 306 NativeRunner* runner_ = nullptr;
305 base::ProcessId pid_ = base::kNullProcessId; 307 base::ProcessId pid_ = base::kNullProcessId;
306 base::WeakPtrFactory<Instance> weak_factory_; 308 base::WeakPtrFactory<Instance> weak_factory_;
307 309
(...skipping 15 matching lines...) Expand all
323 //////////////////////////////////////////////////////////////////////////////// 325 ////////////////////////////////////////////////////////////////////////////////
324 // Shell, public: 326 // Shell, public:
325 327
326 Shell::Shell(scoped_ptr<NativeRunnerFactory> native_runner_factory, 328 Shell::Shell(scoped_ptr<NativeRunnerFactory> native_runner_factory,
327 base::TaskRunner* file_task_runner, 329 base::TaskRunner* file_task_runner,
328 scoped_ptr<catalog::Store> catalog_store) 330 scoped_ptr<catalog::Store> catalog_store)
329 : file_task_runner_(file_task_runner), 331 : file_task_runner_(file_task_runner),
330 native_runner_factory_(std::move(native_runner_factory)), 332 native_runner_factory_(std::move(native_runner_factory)),
331 weak_ptr_factory_(this) { 333 weak_ptr_factory_(this) {
332 mojom::ShellClientRequest request; 334 mojom::ShellClientRequest request;
333 CreateInstance(CreateShellIdentity(), GetPermissiveCapabilityFilter(), 335 CreateInstance(CreateShellIdentity(), GetPermissiveCapabilities(), &request);
334 &request);
335 shell_connection_.reset(new ShellConnection(this, std::move(request))); 336 shell_connection_.reset(new ShellConnection(this, std::move(request)));
336 337
337 InitCatalog(std::move(catalog_store)); 338 InitCatalog(std::move(catalog_store));
338 } 339 }
339 340
340 Shell::~Shell() { 341 Shell::~Shell() {
341 TerminateShellConnections(); 342 TerminateShellConnections();
342 STLDeleteValues(&name_to_loader_); 343 STLDeleteValues(&name_to_loader_);
343 for (auto& runner : native_runners_) 344 for (auto& runner : native_runners_)
344 runner.reset(); 345 runner.reset();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 } 379 }
379 380
380 mojom::ShellClientRequest Shell::InitInstanceForEmbedder( 381 mojom::ShellClientRequest Shell::InitInstanceForEmbedder(
381 const std::string& name) { 382 const std::string& name) {
382 DCHECK(!embedder_instance_); 383 DCHECK(!embedder_instance_);
383 384
384 Identity target(name, mojom::kRootUserID); 385 Identity target(name, mojom::kRootUserID);
385 DCHECK(!GetExistingInstance(target)); 386 DCHECK(!GetExistingInstance(target));
386 387
387 mojom::ShellClientRequest request; 388 mojom::ShellClientRequest request;
388 embedder_instance_ = CreateInstance( 389 embedder_instance_ =
389 target, GetPermissiveCapabilityFilter(), &request); 390 CreateInstance(target, GetPermissiveCapabilities(), &request);
390 DCHECK(embedder_instance_); 391 DCHECK(embedder_instance_);
391 392
392 return request; 393 return request;
393 } 394 }
394 395
395 void Shell::SetLoaderForName(scoped_ptr<Loader> loader, 396 void Shell::SetLoaderForName(scoped_ptr<Loader> loader,
396 const std::string& name) { 397 const std::string& name) {
397 NameToLoaderMap::iterator it = name_to_loader_.find(name); 398 NameToLoaderMap::iterator it = name_to_loader_.find(name);
398 if (it != name_to_loader_.end()) 399 if (it != name_to_loader_.end())
399 delete it->second; 400 delete it->second;
(...skipping 26 matching lines...) Expand all
426 scoped_ptr<Loader> loader( 427 scoped_ptr<Loader> loader(
427 new catalog::Loader(file_task_runner_, std::move(store))); 428 new catalog::Loader(file_task_runner_, std::move(store)));
428 Loader* loader_raw = loader.get(); 429 Loader* loader_raw = loader.get();
429 std::string name = kCatalogName; 430 std::string name = kCatalogName;
430 SetLoaderForName(std::move(loader), name); 431 SetLoaderForName(std::move(loader), name);
431 432
432 mojom::ShellClientRequest request; 433 mojom::ShellClientRequest request;
433 // TODO(beng): Does the catalog actually have to be run with a permissive 434 // TODO(beng): Does the catalog actually have to be run with a permissive
434 // filter? 435 // filter?
435 Identity identity(name, mojom::kRootUserID); 436 Identity identity(name, mojom::kRootUserID);
436 CreateInstance(identity, GetPermissiveCapabilityFilter(), &request); 437 CreateInstance(identity, GetPermissiveCapabilities(), &request);
437 loader_raw->Load(name, std::move(request)); 438 loader_raw->Load(name, std::move(request));
438 439
439 ConnectToInterface(this, CreateShellIdentity(), name, &shell_resolver_); 440 ConnectToInterface(this, CreateShellIdentity(), name, &shell_resolver_);
440 441
441 // Seed the catalog with manifest info for the shell & catalog. 442 // Seed the catalog with manifest info for the shell & catalog.
442 if (file_task_runner_) { 443 if (file_task_runner_) {
443 shell_resolver_->ResolveMojoName(name, base::Bind(&EmptyResolverCallback)); 444 shell_resolver_->ResolveMojoName(name, base::Bind(&EmptyResolverCallback));
444 shell_resolver_->ResolveMojoName("mojo:shell", 445 shell_resolver_->ResolveMojoName("mojo:shell",
445 base::Bind(&EmptyResolverCallback)); 446 base::Bind(&EmptyResolverCallback));
446 } 447 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 } 489 }
489 490
490 bool Shell::ConnectToExistingInstance(scoped_ptr<ConnectParams>* params) { 491 bool Shell::ConnectToExistingInstance(scoped_ptr<ConnectParams>* params) {
491 Instance* instance = GetExistingOrRootInstance((*params)->target()); 492 Instance* instance = GetExistingOrRootInstance((*params)->target());
492 if (instance) 493 if (instance)
493 instance->ConnectToClient(std::move(*params)); 494 instance->ConnectToClient(std::move(*params));
494 return !!instance; 495 return !!instance;
495 } 496 }
496 497
497 Shell::Instance* Shell::CreateInstance(const Identity& target_id, 498 Shell::Instance* Shell::CreateInstance(const Identity& target_id,
498 const CapabilityFilter& filter, 499 const CapabilitySpec& capabilities,
499 mojom::ShellClientRequest* request) { 500 mojom::ShellClientRequest* request) {
500 CHECK(target_id.user_id() != mojom::kInheritUserID); 501 CHECK(target_id.user_id() != mojom::kInheritUserID);
501 mojom::ShellClientPtr shell_client; 502 mojom::ShellClientPtr shell_client;
502 *request = GetProxy(&shell_client); 503 *request = GetProxy(&shell_client);
503 Instance* instance = 504 Instance* instance =
504 new Instance(std::move(shell_client), this, target_id, filter); 505 new Instance(std::move(shell_client), this, target_id, capabilities);
505 DCHECK(identity_to_instance_.find(target_id) == 506 DCHECK(identity_to_instance_.find(target_id) ==
506 identity_to_instance_.end()); 507 identity_to_instance_.end());
507 identity_to_instance_[target_id] = instance; 508 identity_to_instance_[target_id] = instance;
508 mojom::InstanceInfoPtr info = instance->CreateInstanceInfo(); 509 mojom::InstanceInfoPtr info = instance->CreateInstanceInfo();
509 instance_listeners_.ForAllPtrs( 510 instance_listeners_.ForAllPtrs(
510 [this, &info](mojom::InstanceListener* listener) { 511 [this, &info](mojom::InstanceListener* listener) {
511 listener->InstanceCreated(info.Clone()); 512 listener->InstanceCreated(info.Clone());
512 }); 513 });
513 instance->InitializeClient(); 514 instance->InitializeClient();
514 return instance; 515 return instance;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 void Shell::OnShellClientFactoryLost(const Identity& which) { 557 void Shell::OnShellClientFactoryLost(const Identity& which) {
557 // Remove the mapping. 558 // Remove the mapping.
558 auto it = shell_client_factories_.find(which); 559 auto it = shell_client_factories_.find(which);
559 DCHECK(it != shell_client_factories_.end()); 560 DCHECK(it != shell_client_factories_.end());
560 shell_client_factories_.erase(it); 561 shell_client_factories_.erase(it);
561 } 562 }
562 563
563 void Shell::OnGotResolvedName(scoped_ptr<ConnectParams> params, 564 void Shell::OnGotResolvedName(scoped_ptr<ConnectParams> params,
564 const String& resolved_name, 565 const String& resolved_name,
565 const String& resolved_instance, 566 const String& resolved_instance,
566 mojom::CapabilityFilterPtr base_filter, 567 mojom::CapabilitySpecPtr capabilities_ptr,
567 const String& file_url) { 568 const String& file_url) {
568 std::string instance_name = params->target().instance(); 569 std::string instance_name = params->target().instance();
569 if (instance_name == GetNamePath(params->target().name()) && 570 if (instance_name == GetNamePath(params->target().name()) &&
570 resolved_instance != GetNamePath(resolved_name)) { 571 resolved_instance != GetNamePath(resolved_name)) {
571 instance_name = resolved_instance; 572 instance_name = resolved_instance;
572 } 573 }
573 Identity target(params->target().name(), params->target().user_id(), 574 Identity target(params->target().name(), params->target().user_id(),
574 instance_name); 575 instance_name);
575 params->set_target(target); 576 params->set_target(target);
576 577
577 // It's possible that when this manifest request was issued, another one was 578 // It's possible that when this manifest request was issued, another one was
578 // already in-progress and completed by the time this one did, and so the 579 // already in-progress and completed by the time this one did, and so the
579 // requested application may already be running. 580 // requested application may already be running.
580 if (ConnectToExistingInstance(&params)) 581 if (ConnectToExistingInstance(&params))
581 return; 582 return;
582 583
583 Identity source = params->source(); 584 Identity source = params->source();
584 // |base_filter| can be null when there is no manifest, e.g. for URL types 585 // |capabilities_ptr| can be null when there is no manifest, e.g. for URL
585 // not resolvable by the resolver. 586 // types not resolvable by the resolver.
586 CapabilityFilter filter = GetPermissiveCapabilityFilter(); 587 CapabilitySpec capabilities = GetPermissiveCapabilities();
587 if (!base_filter.is_null()) 588 if (!capabilities_ptr.is_null())
588 filter = base_filter->filter.To<CapabilityFilter>(); 589 capabilities = capabilities_ptr.To<CapabilitySpec>();
589 590
590 mojom::ClientProcessConnectionPtr client_process_connection = 591 mojom::ClientProcessConnectionPtr client_process_connection =
591 params->TakeClientProcessConnection(); 592 params->TakeClientProcessConnection();
592 mojom::ShellClientRequest request; 593 mojom::ShellClientRequest request;
593 Instance* instance = CreateInstance(target, filter, &request); 594 Instance* instance = CreateInstance(target, capabilities, &request);
594 instance->ConnectToClient(std::move(params)); 595 instance->ConnectToClient(std::move(params));
595 596
596 if (LoadWithLoader(target, &request)) 597 if (LoadWithLoader(target, &request))
597 return; 598 return;
598 599
599 CHECK(!file_url.is_null() && !base_filter.is_null()); 600 CHECK(!file_url.is_null() && !capabilities_ptr.is_null());
600 601
601 if (target.name() != resolved_name) { 602 if (target.name() != resolved_name) {
602 // In cases where a package alias is resolved, we have to use the instance 603 // In cases where a package alias is resolved, we have to use the instance
603 // from the original request rather than for the package itself, which will 604 // from the original request rather than for the package itself, which will
604 // always be the same. 605 // always be the same.
605 CreateShellClient( 606 CreateShellClient(
606 source, Identity(resolved_name, target.user_id(), instance_name), 607 source, Identity(resolved_name, target.user_id(), instance_name),
607 target.name(), std::move(request)); 608 target.name(), std::move(request));
608 } else { 609 } else {
609 if (!client_process_connection.is_null()) { 610 if (!client_process_connection.is_null()) {
(...skipping 28 matching lines...) Expand all
638 for (auto it = native_runners_.begin(); it != native_runners_.end(); ++it) { 639 for (auto it = native_runners_.begin(); it != native_runners_.end(); ++it) {
639 if (it->get() == runner) { 640 if (it->get() == runner) {
640 native_runners_.erase(it); 641 native_runners_.erase(it);
641 return; 642 return;
642 } 643 }
643 } 644 }
644 } 645 }
645 646
646 } // namespace shell 647 } // namespace shell
647 } // namespace mojo 648 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/shell.h ('k') | mojo/shell/tests/connect/connect_test_app_manifest.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698