| OLD | NEW | 
|---|
| 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 23 matching lines...) Expand all  Loading... | 
| 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 const char kShellName[] = "mojo:shell"; | 38 const char kShellName[] = "mojo:shell"; | 
| 39 const char kCapabilityClass_UserID[] = "user_id"; | 39 const char kCapabilityClass_UserID[] = "user_id"; | 
| 40 const char kCapabilityClass_ClientProcess[] = "client_process"; | 40 const char kCapabilityClass_ClientProcess[] = "client_process"; | 
| 41 const char kCapabilityClass_InstanceName[] = "instance_name"; | 41 const char kCapabilityClass_InstanceName[] = "instance_name"; | 
| 42 const char kCapabilityClass_AllUsers[] = "all_users"; | 42 const char kCapabilityClass_AllUsers[] = "all_users"; | 
| 43 | 43 | 
| 44 void EmptyResolverCallback(const String& resolved_name, | 44 void EmptyResolverCallback(mojom::ResolveResultPtr result) {} | 
| 45                            const String& resolved_instance, |  | 
| 46                            mojom::CapabilitySpecPtr capabilities, |  | 
| 47                            const String& file_url) {} |  | 
| 48 | 45 | 
| 49 } | 46 } | 
| 50 | 47 | 
| 51 Identity CreateShellIdentity() { | 48 Identity CreateShellIdentity() { | 
| 52   return Identity(kShellName, mojom::kRootUserID); | 49   return Identity(kShellName, mojom::kRootUserID); | 
| 53 } | 50 } | 
| 54 | 51 | 
| 55 Identity CreateCatalogIdentity() { | 52 Identity CreateCatalogIdentity() { | 
| 56   return Identity(kCatalogName, mojom::kRootUserID); | 53   return Identity(kCatalogName, mojom::kRootUserID); | 
| 57 } | 54 } | 
| (...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 676 void Shell::OnShellClientFactoryLost(const Identity& which) { | 673 void Shell::OnShellClientFactoryLost(const Identity& which) { | 
| 677   // Remove the mapping. | 674   // Remove the mapping. | 
| 678   auto it = shell_client_factories_.find(which); | 675   auto it = shell_client_factories_.find(which); | 
| 679   DCHECK(it != shell_client_factories_.end()); | 676   DCHECK(it != shell_client_factories_.end()); | 
| 680   shell_client_factories_.erase(it); | 677   shell_client_factories_.erase(it); | 
| 681 } | 678 } | 
| 682 | 679 | 
| 683 void Shell::OnGotResolvedName(mojom::ShellResolverPtr resolver, | 680 void Shell::OnGotResolvedName(mojom::ShellResolverPtr resolver, | 
| 684                               scoped_ptr<ConnectParams> params, | 681                               scoped_ptr<ConnectParams> params, | 
| 685                               mojom::ShellClientPtr client, | 682                               mojom::ShellClientPtr client, | 
| 686                               const String& resolved_name, | 683                               mojom::ResolveResultPtr result) { | 
| 687                               const String& resolved_instance, |  | 
| 688                               mojom::CapabilitySpecPtr capabilities_ptr, |  | 
| 689                               const String& file_url) { |  | 
| 690   std::string instance_name = params->target().instance(); | 684   std::string instance_name = params->target().instance(); | 
| 691   if (instance_name == GetNamePath(params->target().name()) && | 685   if (instance_name == GetNamePath(params->target().name()) && | 
| 692       resolved_instance != GetNamePath(resolved_name)) { | 686       result->qualifier != GetNamePath(result->resolved_name)) { | 
| 693     instance_name = resolved_instance; | 687     instance_name = result->qualifier; | 
| 694   } | 688   } | 
| 695   Identity target(params->target().name(), params->target().user_id(), | 689   Identity target(params->target().name(), params->target().user_id(), | 
| 696                   instance_name); | 690                   instance_name); | 
| 697   params->set_target(target); | 691   params->set_target(target); | 
| 698 | 692 | 
| 699   // It's possible that when this manifest request was issued, another one was | 693   // It's possible that when this manifest request was issued, another one was | 
| 700   // already in-progress and completed by the time this one did, and so the | 694   // already in-progress and completed by the time this one did, and so the | 
| 701   // requested application may already be running. | 695   // requested application may already be running. | 
| 702   if (ConnectToExistingInstance(¶ms)) | 696   if (ConnectToExistingInstance(¶ms)) | 
| 703     return; | 697     return; | 
| 704 | 698 | 
| 705   Identity source = params->source(); | 699   Identity source = params->source(); | 
| 706   // |capabilities_ptr| can be null when there is no manifest, e.g. for URL | 700   // |capabilities_ptr| can be null when there is no manifest, e.g. for URL | 
| 707   // types not resolvable by the resolver. | 701   // types not resolvable by the resolver. | 
| 708   CapabilitySpec capabilities = GetPermissiveCapabilities(); | 702   CapabilitySpec capabilities = GetPermissiveCapabilities(); | 
| 709   if (!capabilities_ptr.is_null()) | 703   if (!result->capabilities.is_null()) | 
| 710     capabilities = capabilities_ptr.To<CapabilitySpec>(); | 704     capabilities = result->capabilities.To<CapabilitySpec>(); | 
| 711 | 705 | 
| 712   // Clients that request "all_users" class from the shell are allowed to | 706   // Clients that request "all_users" class from the shell are allowed to | 
| 713   // field connection requests from any user. They also run with a synthetic | 707   // field connection requests from any user. They also run with a synthetic | 
| 714   // user id generated here. The user id provided via Connect() is ignored. | 708   // user id generated here. The user id provided via Connect() is ignored. | 
| 715   if (HasClass(capabilities, kCapabilityClass_AllUsers)) { | 709   if (HasClass(capabilities, kCapabilityClass_AllUsers)) { | 
| 716     singletons_.insert(target.name()); | 710     singletons_.insert(target.name()); | 
| 717     target.set_user_id(base::GenerateGUID()); | 711     target.set_user_id(base::GenerateGUID()); | 
| 718   } | 712   } | 
| 719 | 713 | 
| 720   mojom::ClientProcessConnectionPtr client_process_connection = | 714   mojom::ClientProcessConnectionPtr client_process_connection = | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
| 731     // Likewise if a ClientProcessConnection was given via Connect(), it | 725     // Likewise if a ClientProcessConnection was given via Connect(), it | 
| 732     // provides the ShellClient proxy to use. | 726     // provides the ShellClient proxy to use. | 
| 733     instance->StartWithClientProcessConnection( | 727     instance->StartWithClientProcessConnection( | 
| 734         std::move(client_process_connection)); | 728         std::move(client_process_connection)); | 
| 735   } else { | 729   } else { | 
| 736     // Otherwise we create a new ShellClient pipe. | 730     // Otherwise we create a new ShellClient pipe. | 
| 737     mojom::ShellClientRequest request = GetProxy(&client); | 731     mojom::ShellClientRequest request = GetProxy(&client); | 
| 738     if (LoadWithLoader(target, &request)) { | 732     if (LoadWithLoader(target, &request)) { | 
| 739       instance->StartWithClient(std::move(client)); | 733       instance->StartWithClient(std::move(client)); | 
| 740     } else { | 734     } else { | 
| 741       CHECK(!file_url.is_null() && !capabilities_ptr.is_null()); | 735       CHECK(!result->package_url.is_null() && !result->capabilities.is_null()); | 
| 742 | 736 | 
| 743       if (target.name() != resolved_name) { | 737       if (target.name() != result->resolved_name) { | 
| 744         instance->StartWithClient(std::move(client)); | 738         instance->StartWithClient(std::move(client)); | 
| 745         CreateShellClientWithFactory( | 739         Identity factory(result->resolved_name, target.user_id(), | 
| 746             source, Identity(resolved_name, target.user_id(), instance_name), | 740                          instance_name); | 
| 747             target.name(), std::move(request)); | 741         CreateShellClientWithFactory(source, factory, target.name(), | 
|  | 742                                      std::move(request)); | 
| 748       } else { | 743       } else { | 
| 749         instance->StartWithFilePath(util::UrlToFilePath(file_url.To<GURL>())); | 744         instance->StartWithFilePath( | 
|  | 745             util::UrlToFilePath(result->package_url.To<GURL>())); | 
| 750       } | 746       } | 
| 751     } | 747     } | 
| 752   } | 748   } | 
| 753 | 749 | 
| 754   // Now that the instance has a ShellClient, we can connect to it. | 750   // Now that the instance has a ShellClient, we can connect to it. | 
| 755   instance->ConnectToClient(std::move(params)); | 751   instance->ConnectToClient(std::move(params)); | 
| 756 } | 752 } | 
| 757 | 753 | 
| 758 bool Shell::LoadWithLoader(const Identity& target, | 754 bool Shell::LoadWithLoader(const Identity& target, | 
| 759                            mojom::ShellClientRequest* request) { | 755                            mojom::ShellClientRequest* request) { | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
| 779   for (auto it = native_runners_.begin(); it != native_runners_.end(); ++it) { | 775   for (auto it = native_runners_.begin(); it != native_runners_.end(); ++it) { | 
| 780     if (it->get() == runner) { | 776     if (it->get() == runner) { | 
| 781       native_runners_.erase(it); | 777       native_runners_.erase(it); | 
| 782       return; | 778       return; | 
| 783     } | 779     } | 
| 784   } | 780   } | 
| 785 } | 781 } | 
| 786 | 782 | 
| 787 }  // namespace shell | 783 }  // namespace shell | 
| 788 }  // namespace mojo | 784 }  // namespace mojo | 
| OLD | NEW | 
|---|