diff options
author | rockot <rockot@chromium.org> | 2016-03-13 18:00:23 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-14 01:01:55 +0000 |
commit | 90f8fccd97c06ddfd0c0e9b7350a4f7fffccfb36 (patch) | |
tree | eb54d8257797401b425c5d50c412dfb4c5f48b86 /mojo | |
parent | 5992ebf47d431338cd0b460e18c61064462ad14e (diff) | |
download | chromium_src-90f8fccd97c06ddfd0c0e9b7350a4f7fffccfb36.zip chromium_src-90f8fccd97c06ddfd0c0e9b7350a4f7fffccfb36.tar.gz chromium_src-90f8fccd97c06ddfd0c0e9b7350a4f7fffccfb36.tar.bz2 |
Use chrome manifest with embedded shell
Moves chrome_manifest.json out of chrome/app/mash
and into content/browser. Changes Shell to use the
resolver when connecting to exe:chrome even when
embedded in the browser.
This brings embedded and external shell behavior
closer together as the manifest will now be used
for the browser app both in and out of mash.
As such, it fixes the fact that the browser cannot
currently connect to exe:chrome_renderer due to
recent changes around capability classes and client
process connections.
BUG=None
Review URL: https://codereview.chromium.org/1787083003
Cr-Commit-Position: refs/heads/master@{#380913}
Diffstat (limited to 'mojo')
-rw-r--r-- | mojo/shell/shell.cc | 65 | ||||
-rw-r--r-- | mojo/shell/shell.h | 22 |
2 files changed, 55 insertions, 32 deletions
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_; |