diff options
-rw-r--r-- | chrome/app/mash/BUILD.gn | 7 | ||||
-rw-r--r-- | chrome/app/mash/chrome_manifest.json | 5 | ||||
-rw-r--r-- | content/browser/BUILD.gn | 7 | ||||
-rw-r--r-- | content/browser/mojo/chrome_manifest.json | 14 | ||||
-rw-r--r-- | mojo/shell/shell.cc | 65 | ||||
-rw-r--r-- | mojo/shell/shell.h | 22 |
6 files changed, 76 insertions, 44 deletions
diff --git a/chrome/app/mash/BUILD.gn b/chrome/app/mash/BUILD.gn index deced6b..a941b0d 100644 --- a/chrome/app/mash/BUILD.gn +++ b/chrome/app/mash/BUILD.gn @@ -29,7 +29,6 @@ source_set("mash") { "//url", ] data_deps = [ - ":chrome_manifest", ":manifest", ] @@ -64,9 +63,3 @@ mojo_application_manifest("manifest") { packaged_applications += [ "font_service" ] } } - -mojo_application_manifest("chrome_manifest") { - type = "exe" - application_name = "chrome" - source = "chrome_manifest.json" -} diff --git a/chrome/app/mash/chrome_manifest.json b/chrome/app/mash/chrome_manifest.json deleted file mode 100644 index 97b6e06..0000000 --- a/chrome/app/mash/chrome_manifest.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "exe:chrome", - "display_name": "Chrome", - "capabilities": { "*": [ "*" ] } -} diff --git a/content/browser/BUILD.gn b/content/browser/BUILD.gn index ab78620..d9c4935 100644 --- a/content/browser/BUILD.gn +++ b/content/browser/BUILD.gn @@ -71,6 +71,7 @@ source_set("browser") { ] data_deps = [ + ":chrome_manifest", ":chrome_renderer_manifest", ] @@ -543,6 +544,12 @@ source_set("browser") { } } +mojo_application_manifest("chrome_manifest") { + type = "exe" + application_name = "chrome" + source = "mojo/chrome_manifest.json" +} + mojo_application_manifest("chrome_renderer_manifest") { type = "exe" application_name = "chrome_renderer" diff --git a/content/browser/mojo/chrome_manifest.json b/content/browser/mojo/chrome_manifest.json new file mode 100644 index 0000000..ef5e6de --- /dev/null +++ b/content/browser/mojo/chrome_manifest.json @@ -0,0 +1,14 @@ +{ + "manifest_version": 1, + "name": "exe:chrome", + "display_name": "Chrome", + "capabilities": { + "required": { + "*": { "interfaces": [ "*" ] }, + "mojo:shell": { + "classes": [ "client_process", "instance_name" ], + "interfaces": [ "*" ] + } + } + } +} diff --git a/mojo/shell/shell.cc b/mojo/shell/shell.cc index 9d24d0d..8056a60 100644 --- a/mojo/shell/shell.cc +++ b/mojo/shell/shell.cc @@ -439,36 +439,20 @@ void Shell::SetInstanceQuitCallback( } void Shell::Connect(scoped_ptr<ConnectParams> params) { - TRACE_EVENT_INSTANT1("mojo_shell", "Shell::Connect", - TRACE_EVENT_SCOPE_THREAD, "original_name", - params->target().name()); - DCHECK(IsValidName(params->target().name())); - DCHECK(base::IsValidGUID(params->target().user_id())); - DCHECK_NE(mojom::kInheritUserID, params->target().user_id()); - - // Connect to an existing matching instance, if possible. - if (ConnectToExistingInstance(¶ms)) - return; - - std::string name = params->target().name(); - shell_resolver_->ResolveMojoName( - name, - base::Bind(&Shell::OnGotResolvedName, - weak_ptr_factory_.GetWeakPtr(), base::Passed(¶ms))); + Connect(std::move(params), nullptr); } mojom::ShellClientRequest Shell::InitInstanceForEmbedder( const std::string& name) { - DCHECK(!embedder_instance_); + scoped_ptr<ConnectParams> params(new ConnectParams); - Identity target(name, mojom::kRootUserID); - DCHECK(!GetExistingInstance(target)); + Identity embedder_identity(name, mojom::kRootUserID); + params->set_source(embedder_identity); + params->set_target(embedder_identity); mojom::ShellClientPtr client; mojom::ShellClientRequest request = GetProxy(&client); - embedder_instance_ = - CreateInstance(target, GetPermissiveCapabilities(), std::move(client)); - DCHECK(embedder_instance_); + Connect(std::move(params), std::move(client)); return request; } @@ -535,6 +519,28 @@ void Shell::OnInstanceError(Instance* instance) { instance_quit_callback_.Run(identity); } +void Shell::Connect(scoped_ptr<ConnectParams> params, + mojom::ShellClientPtr client) { + TRACE_EVENT_INSTANT1("mojo_shell", "Shell::Connect", + TRACE_EVENT_SCOPE_THREAD, "original_name", + params->target().name()); + DCHECK(IsValidName(params->target().name())); + DCHECK(base::IsValidGUID(params->target().user_id())); + DCHECK_NE(mojom::kInheritUserID, params->target().user_id()); + DCHECK(!client.is_bound() || !identity_to_instance_.count(params->target())); + + // Connect to an existing matching instance, if possible. + if (!client.is_bound() && ConnectToExistingInstance(¶ms)) + return; + + std::string name = params->target().name(); + shell_resolver_->ResolveMojoName( + name, + base::Bind(&Shell::OnGotResolvedName, + weak_ptr_factory_.GetWeakPtr(), base::Passed(¶ms), + base::Passed(&client))); +} + Shell::Instance* Shell::GetExistingInstance(const Identity& identity) const { const auto& it = identity_to_instance_.find(identity); return it != identity_to_instance_.end() ? it->second : nullptr; @@ -627,6 +633,7 @@ void Shell::OnShellClientFactoryLost(const Identity& which) { } void Shell::OnGotResolvedName(scoped_ptr<ConnectParams> params, + mojom::ShellClientPtr client, const String& resolved_name, const String& resolved_instance, mojom::CapabilitySpecPtr capabilities_ptr, @@ -655,12 +662,20 @@ void Shell::OnGotResolvedName(scoped_ptr<ConnectParams> params, mojom::ClientProcessConnectionPtr client_process_connection = params->TakeClientProcessConnection(); - mojom::ShellClientPtr client; - mojom::ShellClientRequest request = GetProxy(&client); + + mojom::ShellClientRequest request; + if (!client.is_bound()) + request = GetProxy(&client); + Instance* instance = CreateInstance(target, capabilities, std::move(client)); instance->ConnectToClient(std::move(params)); - if (LoadWithLoader(target, &request)) + // If a ShellClientPtr was provided, there's no more work to do: someone + // is already holding a corresponding ShellClientRequest. + if (!request.is_pending()) + return; + + if (client_process_connection.is_null() && LoadWithLoader(target, &request)) return; CHECK(!file_url.is_null() && !capabilities_ptr.is_null()); diff --git a/mojo/shell/shell.h b/mojo/shell/shell.h index 9a3e2e9..b0b00c9 100644 --- a/mojo/shell/shell.h +++ b/mojo/shell/shell.h @@ -72,9 +72,8 @@ class Shell : public ShellClient { void Connect(scoped_ptr<ConnectParams> params); // Creates a new Instance identified as |name|. This is intended for use by - // the Shell's embedder to register itself with the shell. The name is never - // resolved and there must not be an existing instance associated with it. - // This must only be called once. + // the Shell's embedder to register itself with the shell. This must only be + // called once. mojom::ShellClientRequest InitInstanceForEmbedder(const std::string& name); // Sets the default Loader to be used if not overridden by SetLoaderForName(). @@ -106,6 +105,15 @@ class Shell : public ShellClient { // Removes a Instance when it encounters an error. void OnInstanceError(Instance* instance); + // Completes a connection between a source and target application as defined + // by |params|, exchanging InterfaceProviders between them. If no existing + // instance of the target application is running, one will be loaded. + // + // If |client| is not null, there must not be an instance of the target + // application already running. The shell will create a new instance and use + // |client| to control. + void Connect(scoped_ptr<ConnectParams> params, mojom::ShellClientPtr client); + // Returns a running instance matching |identity|. Instance* GetExistingInstance(const Identity& identity) const; // Like GetExistingInstance, but if no instance for |identity.user_id()| is @@ -139,12 +147,15 @@ class Shell : public ShellClient { // Callback when remote Catalog resolves mojo:foo to mojo:bar. // |params| are the params passed to Connect(). + // |client| if provided is a ShellClientPtr which should be used to manage the + // new application instance. This may be null. // |resolved_name| is the mojo: name identifying the physical package // application. // |file_url| is the resolved file:// URL of the physical package. - // |base_filter| is the CapabilitySpecPtr the requested application should be + // |capabilities| is the CapabilitySpecPtr the requested application should be // run with, from its manifest. void OnGotResolvedName(scoped_ptr<ConnectParams> params, + mojom::ShellClientPtr client, const String& resolved_name, const String& resolved_instance, mojom::CapabilitySpecPtr capabilities, @@ -174,9 +185,6 @@ class Shell : public ShellClient { // Counter used to assign ids to content handlers. uint32_t shell_client_factory_id_counter_; - // The Instance created by the shell embedder, if any. - Instance* embedder_instance_ = nullptr; - InterfacePtrSet<mojom::InstanceListener> instance_listeners_; base::Callback<void(const Identity&)> instance_quit_callback_; |