diff --git a/mojo/mojo_shell.gyp b/mojo/mojo_shell.gyp index 51f5b0b0fc2030..a4290af72fad41 100644 --- a/mojo/mojo_shell.gyp +++ b/mojo/mojo_shell.gyp @@ -28,6 +28,10 @@ 'shell/package_manager.h', 'shell/query_util.cc', 'shell/query_util.h', + 'shell/shell_application_delegate.cc', + 'shell/shell_application_delegate.h', + 'shell/shell_application_loader.cc', + 'shell/shell_application_loader.h', 'shell/static_application_loader.cc', 'shell/static_application_loader.h', 'shell/switches.cc', @@ -43,6 +47,7 @@ '<(DEPTH)/mojo/mojo_base.gyp:mojo_common_lib', '<(DEPTH)/mojo/mojo_base.gyp:mojo_environment_chromium', '<(DEPTH)/mojo/mojo_base.gyp:mojo_url_type_converters', + '<(DEPTH)/mojo/mojo_shell.gyp:mojo_shell_interfaces', '<(DEPTH)/url/url.gyp:url_lib', ], }, { @@ -118,5 +123,16 @@ 'includes': [ '../third_party/mojo/mojom_bindings_generator_explicit.gypi', ], + }, { + 'target_name': 'mojo_shell_interfaces', + 'type': 'none', + 'variables': { + 'mojom_files': [ + 'shell/application_manager.mojom', + ], + }, + 'includes': [ + '../third_party/mojo/mojom_bindings_generator_explicit.gypi', + ], }], } diff --git a/mojo/shell/BUILD.gn b/mojo/shell/BUILD.gn index 089d9ef877206f..e7bd7abf9704a1 100644 --- a/mojo/shell/BUILD.gn +++ b/mojo/shell/BUILD.gn @@ -29,6 +29,10 @@ source_set("shell") { "package_manager.h", "query_util.cc", "query_util.h", + "shell_application_delegate.cc", + "shell_application_delegate.h", + "shell_application_loader.cc", + "shell_application_loader.h", "static_application_loader.cc", "static_application_loader.h", "switches.cc", @@ -45,6 +49,7 @@ source_set("shell") { "//url", ] deps = [ + ":interfaces", "//base/third_party/dynamic_annotations", "//crypto:crypto", "//mojo/application/public/cpp:sources", @@ -107,3 +112,9 @@ mojom("test_bindings") { "test.mojom", ] } + +mojom("interfaces") { + sources = [ + "application_manager.mojom", + ] +} diff --git a/mojo/shell/application_manager.cc b/mojo/shell/application_manager.cc index add0bd8f02b35d..688cdf48f428a5 100644 --- a/mojo/shell/application_manager.cc +++ b/mojo/shell/application_manager.cc @@ -15,6 +15,7 @@ #include "mojo/shell/fetcher.h" #include "mojo/shell/package_manager.h" #include "mojo/shell/query_util.h" +#include "mojo/shell/shell_application_loader.h" #include "mojo/shell/switches.h" #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h" @@ -50,11 +51,7 @@ bool ApplicationManager::TestAPI::HasRunningInstanceForURL( ApplicationManager::ApplicationManager( scoped_ptr package_manager) - : package_manager_(package_manager.Pass()), - task_runner_(nullptr), - weak_ptr_factory_(this) { - package_manager_->SetApplicationManager(this); -} + : ApplicationManager(package_manager.Pass(), nullptr, nullptr) {} ApplicationManager::ApplicationManager( scoped_ptr package_manager, @@ -65,6 +62,8 @@ ApplicationManager::ApplicationManager( native_runner_factory_(native_runner_factory.Pass()), weak_ptr_factory_(this) { package_manager_->SetApplicationManager(this); + SetLoaderForURL(make_scoped_ptr(new ShellApplicationLoader(this)), + GURL("mojo:shell")); } ApplicationManager::~ApplicationManager() { diff --git a/mojo/shell/application_manager.mojom b/mojo/shell/application_manager.mojom new file mode 100644 index 00000000000000..c9135bb6209c62 --- /dev/null +++ b/mojo/shell/application_manager.mojom @@ -0,0 +1,14 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +module mojo.shell.mojom; + +interface ApplicationManager { + // Instructs the ApplicationManager to create an instance for an existing + // process at the other end of |channel|, and perform applicable + // initialization. This assumes the target process will bind the other end of + // channel to an implementation of ChildController and bind an Application + // request there. + CreateInstanceForHandle(handle channel); +}; diff --git a/mojo/shell/shell_application_delegate.cc b/mojo/shell/shell_application_delegate.cc new file mode 100644 index 00000000000000..00c4485b324ac8 --- /dev/null +++ b/mojo/shell/shell_application_delegate.cc @@ -0,0 +1,35 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "mojo/shell/shell_application_delegate.h" + +#include "mojo/application/public/cpp/application_connection.h" + +namespace mojo { +namespace shell { + +ShellApplicationDelegate::ShellApplicationDelegate( + mojo::shell::ApplicationManager* manager) + : manager_(manager) {} +ShellApplicationDelegate::~ShellApplicationDelegate() {} + +void ShellApplicationDelegate::Initialize(ApplicationImpl* app) {} +bool ShellApplicationDelegate::ConfigureIncomingConnection( + ApplicationConnection* connection) { + connection->AddService(this); + return true; +} + +void ShellApplicationDelegate::Create( + ApplicationConnection* connection, + InterfaceRequest request) { + bindings_.AddBinding(this, request.Pass()); +} + +void ShellApplicationDelegate::CreateInstanceForHandle(ScopedHandle channel) { + // TODO(beng): create the instance. +} + +} // namespace shell +} // namespace mojo diff --git a/mojo/shell/shell_application_delegate.h b/mojo/shell/shell_application_delegate.h new file mode 100644 index 00000000000000..e0dcce3953c0cf --- /dev/null +++ b/mojo/shell/shell_application_delegate.h @@ -0,0 +1,50 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef MOJO_SHELL_SHELL_APPLICATION_DELEGATE_H_ +#define MOJO_SHELL_SHELL_APPLICATION_DELEGATE_H_ + +#include "mojo/application/public/cpp/application_delegate.h" + +#include "base/macros.h" +#include "mojo/application/public/cpp/interface_factory.h" +#include "mojo/common/weak_binding_set.h" +#include "mojo/shell/application_manager.mojom.h" + +namespace mojo { +namespace shell { +class ApplicationManager; + +class ShellApplicationDelegate + : public ApplicationDelegate, + public InterfaceFactory, + public mojom::ApplicationManager { + public: + explicit ShellApplicationDelegate(mojo::shell::ApplicationManager* manager); + ~ShellApplicationDelegate() override; + + private: + // Overridden from ApplicationDelegate: + void Initialize(ApplicationImpl* app) override; + bool ConfigureIncomingConnection(ApplicationConnection* connection) override; + + // Overridden from InterfaceFactory: + void Create( + ApplicationConnection* connection, + InterfaceRequest request) override; + + // Overridden from mojom::ApplicationManager: + void CreateInstanceForHandle(ScopedHandle channel) override; + + mojo::shell::ApplicationManager* manager_; + + WeakBindingSet bindings_; + + DISALLOW_COPY_AND_ASSIGN(ShellApplicationDelegate); +}; + +} // namespace shell +} // namespace mojo + +#endif // MOJO_SHELL_SHELL_APPLICATION_DELEGATE_H_ diff --git a/mojo/shell/shell_application_loader.cc b/mojo/shell/shell_application_loader.cc new file mode 100644 index 00000000000000..469da91590289d --- /dev/null +++ b/mojo/shell/shell_application_loader.cc @@ -0,0 +1,26 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "mojo/shell/shell_application_loader.h" + +#include "mojo/application/public/cpp/application_impl.h" +#include "mojo/shell/shell_application_delegate.h" + +namespace mojo { +namespace shell { + +ShellApplicationLoader::ShellApplicationLoader(ApplicationManager* manager) + : manager_(manager) {} +ShellApplicationLoader::~ShellApplicationLoader() {} + +void ShellApplicationLoader::Load( + const GURL& url, + InterfaceRequest application_request) { + DCHECK(application_request.is_pending()); + app_.reset(new ApplicationImpl(new ShellApplicationDelegate(manager_), + application_request.Pass())); +} + +} // namespace shell +} // namespace mojo diff --git a/mojo/shell/shell_application_loader.h b/mojo/shell/shell_application_loader.h new file mode 100644 index 00000000000000..7ffd365e35355d --- /dev/null +++ b/mojo/shell/shell_application_loader.h @@ -0,0 +1,36 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef MOJO_SHELL_SHELL_APPLICATION_LOADER_H_ +#define MOJO_SHELL_SHELL_APPLICATION_LOADER_H_ + +#include "base/macros.h" +#include "mojo/shell/application_loader.h" + +namespace mojo { +class ApplicationImpl; +namespace shell { + +class ShellApplicationLoader : public ApplicationLoader { + public: + explicit ShellApplicationLoader(ApplicationManager* manager); + ~ShellApplicationLoader() override; + + private: + // Overridden from ApplicationLoader: + void Load( + const GURL& url, + InterfaceRequest application_request) override; + + scoped_ptr app_; + + ApplicationManager* manager_; + + DISALLOW_COPY_AND_ASSIGN(ShellApplicationLoader); +}; + +} // namespace shell +} // namespace mojo + +#endif // MOJO_SHELL_SHELL_APPLICATION_LOADER_H_