diff options
-rw-r--r-- | mash/BUILD.gn | 2 | ||||
-rw-r--r-- | mash/init/BUILD.gn | 33 | ||||
-rw-r--r-- | mash/init/init.cc | 69 | ||||
-rw-r--r-- | mash/init/init.h | 63 | ||||
-rw-r--r-- | mash/init/main.cc | 12 | ||||
-rw-r--r-- | mash/init/manifest.json | 5 | ||||
-rw-r--r-- | mash/init/public/interfaces/BUILD.gn | 11 | ||||
-rw-r--r-- | mash/init/public/interfaces/login.mojom | 10 | ||||
-rw-r--r-- | mash/login/BUILD.gn | 42 | ||||
-rw-r--r-- | mash/login/login.cc | 129 | ||||
-rw-r--r-- | mash/login/login.h | 46 | ||||
-rw-r--r-- | mash/login/main.cc | 12 | ||||
-rw-r--r-- | mash/login/manifest.json | 5 | ||||
-rw-r--r-- | mash/shell/shell_application_delegate.cc | 7 | ||||
-rw-r--r-- | mash/wm/root_window_controller.cc | 4 | ||||
-rw-r--r-- | mash/wm/window_manager.cc | 5 | ||||
-rw-r--r-- | mash/wm/window_manager.h | 2 | ||||
-rw-r--r-- | mash/wm/window_manager_application.cc | 2 | ||||
-rw-r--r-- | mash/wm/window_manager_application.h | 7 |
19 files changed, 457 insertions, 9 deletions
diff --git a/mash/BUILD.gn b/mash/BUILD.gn index e2b703f..7ac88a7 100644 --- a/mash/BUILD.gn +++ b/mash/BUILD.gn @@ -12,6 +12,8 @@ group("all") { ":tests", "//components/leveldb", "//mash/example", + "//mash/init", + "//mash/login", "//mash/screenlock", "//mash/shell", "//mash/task_viewer", diff --git a/mash/init/BUILD.gn b/mash/init/BUILD.gn new file mode 100644 index 0000000..010fb38 --- /dev/null +++ b/mash/init/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright 2016 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. + +import("//build/config/ui.gni") +import("//mojo/public/mojo_application.gni") +import("//mojo/public/mojo_application_manifest.gni") +import("//mojo/public/tools/bindings/mojom.gni") +import("//tools/grit/repack.gni") + +mojo_native_application("init") { + output_name = "mash_init" + sources = [ + "init.cc", + "init.h", + "main.cc", + ] + + deps = [ + ":manifest", + "//base", + "//components/mus/public/cpp", + "//mash/init/public/interfaces", + "//mojo/public/cpp/bindings", + "//mojo/services/tracing/public/cpp", + "//mojo/shell/public/cpp", + ] +} + +mojo_application_manifest("manifest") { + application_name = "mash_init" + source = "manifest.json" +} diff --git a/mash/init/init.cc b/mash/init/init.cc new file mode 100644 index 0000000..f8e1d6b --- /dev/null +++ b/mash/init/init.cc @@ -0,0 +1,69 @@ +// Copyright 2016 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 "mash/init/init.h" + +#include "base/bind.h" +#include "base/command_line.h" +#include "mojo/shell/public/cpp/connection.h" +#include "mojo/shell/public/cpp/connector.h" + +namespace mash { +namespace init { + +Init::Init() : connector_(nullptr) {} +Init::~Init() {} + +void Init::Initialize(mojo::Connector* connector, const std::string& url, + uint32_t id, uint32_t user_id) { + connector_ = connector; + mus_connection_ = connector_->Connect("mojo:mus"); + StartWindowManager(); + StartLogin(); +} + +void Init::LoginAs(uint32_t user_id) { + connections_["mojo:mash_login"].reset(); + connections_["mojo:desktop_wm"].reset(); + mojo::Connector::ConnectParams params("mojo:mash_shell"); + params.set_user_id(user_id); + connector_->Connect(¶ms); +} + +void Init::Create(mojo::Connection* connection, mojom::LoginRequest request) { + login_bindings_.AddBinding(this, std::move(request)); +} + +void Init::StartWindowManager() { + mojo::Connector::ConnectParams params("mojo:desktop_wm"); + params.set_user_id(2); + StartRestartableService( + ¶ms, + base::Bind(&Init::StartWindowManager, base::Unretained(this))); +} + +void Init::StartLogin() { + mojo::Connector::ConnectParams params("mojo:mash_login"); + params.set_user_id(2); + StartRestartableService( + ¶ms, + base::Bind(&Init::StartLogin, base::Unretained(this))); +} + +void Init::StartRestartableService(mojo::Connector::ConnectParams* params, + const base::Closure& restart_callback) { + // TODO(beng): This would be the place to insert logic that counted restarts + // to avoid infinite crash-restart loops. + scoped_ptr<mojo::Connection> connection = connector_->Connect(params); + // Note: |connection| may be null if we've lost our connection to the shell. + if (connection) { + connection->SetRemoteInterfaceProviderConnectionErrorHandler( + restart_callback); + connection->AddInterface<mojom::Login>(this); + connections_[params->name()] = std::move(connection); + } +} + +} // namespace init +} // namespace main diff --git a/mash/init/init.h b/mash/init/init.h new file mode 100644 index 0000000..10a8a0e --- /dev/null +++ b/mash/init/init.h @@ -0,0 +1,63 @@ +// Copyright 2016 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 MASH_INIT_INIT_H_ +#define MASH_INIT_INIT_H_ + +#include <map> + +#include "base/callback.h" +#include "base/macros.h" +#include "base/memory/scoped_ptr.h" +#include "mash/init/public/interfaces/login.mojom.h" +#include "mojo/public/cpp/bindings/binding_set.h" +#include "mojo/shell/public/cpp/connector.h" +#include "mojo/shell/public/cpp/shell_client.h" + +namespace mojo { +class Connection; +} + +namespace mash { +namespace init{ + +class Init : public mojo::ShellClient, + public mojom::Login, + public mojo::InterfaceFactory<mojom::Login> { + public: + Init(); + ~Init() override; + + private: + // mojo::ShellClient: + void Initialize(mojo::Connector* connector, const std::string& url, + uint32_t id, uint32_t user_id) override; + + // mojom::Login: + void LoginAs(uint32_t user_id) override; + + // mojo::InterfaceFactory<mojom::Login>: + void Create(mojo::Connection* connection, + mojom::LoginRequest request) override; + + void StartWindowManager(); + void StartLogin(); + + // Starts the application at |url|, running |restart_callback| if the + // connection to the application is closed. + void StartRestartableService(mojo::Connector::ConnectParams* params, + const base::Closure& restart_callback); + + mojo::Connector* connector_; + std::map<std::string, scoped_ptr<mojo::Connection>> connections_; + mojo::BindingSet<mojom::Login> login_bindings_; + scoped_ptr<mojo::Connection> mus_connection_; + + DISALLOW_COPY_AND_ASSIGN(Init); +}; + +} // namespace init +} // namespace mash + +#endif // MASH_INIT_INIT_H_ diff --git a/mash/init/main.cc b/mash/init/main.cc new file mode 100644 index 0000000..65d4789 --- /dev/null +++ b/mash/init/main.cc @@ -0,0 +1,12 @@ +// Copyright 2016 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 "mash/init/init.h" +#include "mojo/public/c/system/main.h" +#include "mojo/shell/public/cpp/application_runner.h" + +MojoResult MojoMain(MojoHandle shell_handle) { + mojo::ApplicationRunner runner(new mash::init::Init); + return runner.Run(shell_handle); +} diff --git a/mash/init/manifest.json b/mash/init/manifest.json new file mode 100644 index 0000000..d55a0a75 --- /dev/null +++ b/mash/init/manifest.json @@ -0,0 +1,5 @@ +{ + "name": "mojo:mash_init", + "display_name": "Root Controller", + "capabilities": { "*": [ "*" ] } +} diff --git a/mash/init/public/interfaces/BUILD.gn b/mash/init/public/interfaces/BUILD.gn new file mode 100644 index 0000000..0ea747b --- /dev/null +++ b/mash/init/public/interfaces/BUILD.gn @@ -0,0 +1,11 @@ +# Copyright 2016 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. + +import("//mojo/public/tools/bindings/mojom.gni") + +mojom("interfaces") { + sources = [ + "login.mojom", + ] +} diff --git a/mash/init/public/interfaces/login.mojom b/mash/init/public/interfaces/login.mojom new file mode 100644 index 0000000..3ea6f10 --- /dev/null +++ b/mash/init/public/interfaces/login.mojom @@ -0,0 +1,10 @@ +// Copyright 2016 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 mash.init.mojom; + +interface Login { + LoginAs(uint32 user_id); +}; + diff --git a/mash/login/BUILD.gn b/mash/login/BUILD.gn new file mode 100644 index 0000000..e6ea919 --- /dev/null +++ b/mash/login/BUILD.gn @@ -0,0 +1,42 @@ +# Copyright 2016 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. + +import("//build/config/ui.gni") +import("//mojo/public/mojo_application.gni") +import("//mojo/public/mojo_application_manifest.gni") +import("//mojo/public/tools/bindings/mojom.gni") +import("//tools/grit/repack.gni") + +mojo_native_application("login") { + output_name = "mash_login" + sources = [ + "login.cc", + "login.h", + "main.cc", + ] + + deps = [ + ":manifest", + "//base", + "//components/mus/public/cpp", + "//mash/init/public/interfaces", + "//mash/wm/public/interfaces", + "//mojo/public/cpp/bindings", + "//mojo/services/tracing/public/cpp", + "//mojo/shell/public/cpp", + "//ui/views", + "//ui/views/mus:for_mojo_application", + ] + + resources = [ "$root_out_dir/views_mus_resources.pak" ] + + data_deps = [ + "//components/mus", + ] +} + +mojo_application_manifest("manifest") { + application_name = "mash_login" + source = "manifest.json" +} diff --git a/mash/login/login.cc b/mash/login/login.cc new file mode 100644 index 0000000..e301b3f --- /dev/null +++ b/mash/login/login.cc @@ -0,0 +1,129 @@ +// Copyright 2016 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 "mash/login/login.h" + +#include "base/macros.h" +#include "base/message_loop/message_loop.h" +#include "base/strings/utf_string_conversions.h" +#include "components/mus/public/cpp/property_type_converters.h" +#include "mash/wm/public/interfaces/container.mojom.h" +#include "mojo/public/cpp/bindings/binding.h" +#include "mojo/shell/public/cpp/connector.h" +#include "ui/views/background.h" +#include "ui/views/controls/button/label_button.h" +#include "ui/views/mus/aura_init.h" +#include "ui/views/mus/native_widget_mus.h" +#include "ui/views/mus/window_manager_connection.h" +#include "ui/views/widget/widget_delegate.h" + +namespace mash { +namespace login { +namespace { + +class LoginView : public views::WidgetDelegateView, + public views::ButtonListener { + public: + explicit LoginView(Login* login) + : login_(login), + login_button_1_( + new views::LabelButton(this, base::ASCIIToUTF16("Timothy"))), + login_button_2_( + new views::LabelButton(this, base::ASCIIToUTF16("Jimothy"))) { + set_background(views::Background::CreateSolidBackground(SK_ColorRED)); + login_button_1_->SetStyle(views::Button::STYLE_BUTTON); + login_button_2_->SetStyle(views::Button::STYLE_BUTTON); + AddChildView(login_button_1_); + AddChildView(login_button_2_); + } + ~LoginView() override {} + + private: + // Overridden from views::WidgetDelegate: + views::View* GetContentsView() override { return this; } + base::string16 GetWindowTitle() const override { + // TODO(beng): use resources. + return base::ASCIIToUTF16("Login"); + } + + // Overridden from views::View: + void Layout() override { + gfx::Rect button_box = GetLocalBounds(); + button_box.Inset(10, 10); + + gfx::Size ps1 = login_button_1_->GetPreferredSize(); + gfx::Size ps2 = login_button_2_->GetPreferredSize(); + + DCHECK(ps1.height() == ps2.height()); + + // The 10 is inter-button spacing. + button_box.set_x((button_box.width() - ps1.width() - ps2.width() - 10) / 2); + button_box.set_y((button_box.height() - ps1.height()) / 2); + + login_button_1_->SetBounds(button_box.x(), button_box.y(), ps1.width(), + ps1.height()); + login_button_2_->SetBounds(login_button_1_->bounds().right() + 10, + button_box.y(), ps2.width(), ps2.height()); + } + + // Overridden from views::ButtonListener: + void ButtonPressed(views::Button* sender, const ui::Event& event) override { + // Login... + mojo::Connector::ConnectParams params("mojo:mash_shell"); + if (sender == login_button_1_) { + login_->login()->LoginAs(3); + } else if (sender == login_button_2_) { + login_->login()->LoginAs(4); + } else { + NOTREACHED(); + } + base::MessageLoop::current()->QuitWhenIdle(); + } + + Login* login_; + views::LabelButton* login_button_1_; + views::LabelButton* login_button_2_; + + DISALLOW_COPY_AND_ASSIGN(LoginView); +}; + +} // namespace + +Login::Login() {} +Login::~Login() {} + +void Login::Initialize(mojo::Connector* connector, const std::string& url, + uint32_t id, uint32_t user_id) { + tracing_.Initialize(connector, url); + + aura_init_.reset(new views::AuraInit(connector, "views_mus_resources.pak")); + views::WindowManagerConnection::Create(connector); + + views::Widget* widget = new views::Widget; + views::Widget::InitParams params( + views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); + params.delegate = new LoginView(this); + + std::map<std::string, std::vector<uint8_t>> properties; + properties[mash::wm::mojom::kWindowContainer_Property] = + mojo::TypeConverter<const std::vector<uint8_t>, int32_t>::Convert( + static_cast<int32_t>(mash::wm::mojom::Container::LOGIN_WINDOWS)); + mus::Window* window = + views::WindowManagerConnection::Get()->NewWindow(properties); + params.native_widget = new views::NativeWidgetMus( + widget, connector, window, mus::mojom::SurfaceType::DEFAULT); + widget->Init(params); + widget->Show(); +} + +bool Login::AcceptConnection(mojo::Connection* connection) { + if (connection->GetRemoteApplicationName() == "mojo:mash_init") { + connection->GetInterface(&login_); + return true; + } + return false; +} + +} // namespace login +} // namespace main diff --git a/mash/login/login.h b/mash/login/login.h new file mode 100644 index 0000000..2a70b1a --- /dev/null +++ b/mash/login/login.h @@ -0,0 +1,46 @@ +// Copyright 2016 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 MASH_LOGIN_LOGIN_H_ +#define MASH_LOGIN_LOGIN_H_ + +#include <map> + +#include "base/macros.h" +#include "base/memory/scoped_ptr.h" +#include "mash/init/public/interfaces/login.mojom.h" +#include "mojo/services/tracing/public/cpp/tracing_impl.h" +#include "mojo/shell/public/cpp/shell_client.h" + +namespace views { +class AuraInit; +} + +namespace mash { +namespace login { + +class Login : public mojo::ShellClient { + public: + Login(); + ~Login() override; + + init::mojom::Login* login() { return login_.get(); } + + private: + // mojo::ShellClient: + void Initialize(mojo::Connector* connector, const std::string& url, + uint32_t id, uint32_t user_id) override; + bool AcceptConnection(mojo::Connection* connection) override; + + mojo::TracingImpl tracing_; + scoped_ptr<views::AuraInit> aura_init_; + init::mojom::LoginPtr login_; + + DISALLOW_COPY_AND_ASSIGN(Login); +}; + +} // namespace login +} // namespace mash + +#endif // MASH_LOGIN_LOGIN_H_ diff --git a/mash/login/main.cc b/mash/login/main.cc new file mode 100644 index 0000000..12b1804 --- /dev/null +++ b/mash/login/main.cc @@ -0,0 +1,12 @@ +// Copyright 2016 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 "mash/login/login.h" +#include "mojo/public/c/system/main.h" +#include "mojo/shell/public/cpp/application_runner.h" + +MojoResult MojoMain(MojoHandle shell_handle) { + mojo::ApplicationRunner runner(new mash::login::Login); + return runner.Run(shell_handle); +} diff --git a/mash/login/manifest.json b/mash/login/manifest.json new file mode 100644 index 0000000..bec0be46 --- /dev/null +++ b/mash/login/manifest.json @@ -0,0 +1,5 @@ +{ + "name": "mojo:mash_login", + "display_name": "Login", + "capabilities": { "*": [ "*" ] } +} diff --git a/mash/shell/shell_application_delegate.cc b/mash/shell/shell_application_delegate.cc index c37dac9..c46f0e2 100644 --- a/mash/shell/shell_application_delegate.cc +++ b/mash/shell/shell_application_delegate.cc @@ -29,7 +29,7 @@ void ShellApplicationDelegate::Initialize(mojo::Connector* connector, } bool ShellApplicationDelegate::AcceptConnection(mojo::Connection* connection) { - connection->AddInterface<mash::shell::mojom::Shell>(this); + connection->AddInterface<mojom::Shell>(this); return true; } @@ -62,8 +62,8 @@ void ShellApplicationDelegate::UnlockScreen() { void ShellApplicationDelegate::Create( mojo::Connection* connection, - mojo::InterfaceRequest<mash::shell::mojom::Shell> r) { - bindings_.AddBinding(this, std::move(r)); + mojom::ShellRequest request) { + bindings_.AddBinding(this, std::move(request)); } void ShellApplicationDelegate::StartWindowManager() { @@ -116,6 +116,7 @@ void ShellApplicationDelegate::StartRestartableService( if (connection) { connection->SetRemoteInterfaceProviderConnectionErrorHandler( restart_callback); + connection->AddInterface<mojom::Shell>(this); connections_[url] = std::move(connection); } } diff --git a/mash/wm/root_window_controller.cc b/mash/wm/root_window_controller.cc index 03de79e..a554310 100644 --- a/mash/wm/root_window_controller.cc +++ b/mash/wm/root_window_controller.cc @@ -144,9 +144,7 @@ void RootWindowController::OnEmbed(mus::Window* root) { AddAccelerators(); - mash::shell::mojom::ShellPtr shell; - app_->connector()->ConnectToInterface("mojo:mash_shell", &shell); - window_manager_->Initialize(this, std::move(shell)); + window_manager_->Initialize(this, app_->mash_shell()); shadow_controller_.reset(new ShadowController(root->connection())); diff --git a/mash/wm/window_manager.cc b/mash/wm/window_manager.cc index f57af0a..707daa2 100644 --- a/mash/wm/window_manager.cc +++ b/mash/wm/window_manager.cc @@ -39,7 +39,7 @@ WindowManager::~WindowManager() { } void WindowManager::Initialize(RootWindowController* root_controller, - mash::shell::mojom::ShellPtr shell) { + mash::shell::mojom::Shell* shell) { DCHECK(root_controller); DCHECK(!root_controller_); root_controller_ = root_controller; @@ -66,7 +66,8 @@ void WindowManager::Initialize(RootWindowController* root_controller, window_manager_client_->SetFrameDecorationValues( std::move(frame_decoration_values)); - shell->AddScreenlockStateListener(binding_.CreateInterfacePtrAndBind()); + if (shell) + shell->AddScreenlockStateListener(binding_.CreateInterfacePtrAndBind()); } gfx::Rect WindowManager::CalculateDefaultBounds(mus::Window* window) const { diff --git a/mash/wm/window_manager.h b/mash/wm/window_manager.h index 7dbe07e..1c79976 100644 --- a/mash/wm/window_manager.h +++ b/mash/wm/window_manager.h @@ -28,7 +28,7 @@ class WindowManager : public mus::WindowObserver, ~WindowManager() override; void Initialize(RootWindowController* root_controller, - mash::shell::mojom::ShellPtr shell); + mash::shell::mojom::Shell* shell); mus::WindowManagerClient* window_manager_client() { return window_manager_client_; diff --git a/mash/wm/window_manager_application.cc b/mash/wm/window_manager_application.cc index 5f5089a..f9ff9ea 100644 --- a/mash/wm/window_manager_application.cc +++ b/mash/wm/window_manager_application.cc @@ -124,6 +124,8 @@ void WindowManagerApplication::Initialize(mojo::Connector* connector, bool WindowManagerApplication::AcceptConnection(mojo::Connection* connection) { connection->AddInterface<mash::wm::mojom::UserWindowController>(this); connection->AddInterface<mus::mojom::AcceleratorRegistrar>(this); + if (connection->GetRemoteApplicationName() == "mojo:mash_shell") + connection->GetInterface(&mash_shell_); return true; } diff --git a/mash/wm/window_manager_application.h b/mash/wm/window_manager_application.h index a716990..b10c1e4 100644 --- a/mash/wm/window_manager_application.h +++ b/mash/wm/window_manager_application.h @@ -17,6 +17,7 @@ #include "components/mus/public/interfaces/window_manager.mojom.h" #include "components/mus/public/interfaces/window_manager_factory.mojom.h" #include "components/mus/public/interfaces/window_tree_host.mojom.h" +#include "mash/shell/public/interfaces/shell.mojom.h" #include "mash/wm/public/interfaces/user_window_controller.mojom.h" #include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/binding_set.h" @@ -74,6 +75,10 @@ class WindowManagerApplication void AddRootWindowsObserver(RootWindowsObserver* observer); void RemoveRootWindowsObserver(RootWindowsObserver* observer); + mash::shell::mojom::Shell* mash_shell() { + return mash_shell_.get(); + } + private: void OnAcceleratorRegistrarDestroyed(AcceleratorRegistrarImpl* registrar); @@ -119,6 +124,8 @@ class WindowManagerApplication mojo::Binding<mus::mojom::WindowManagerFactory> window_manager_factory_binding_; + mash::shell::mojom::ShellPtr mash_shell_; + base::ObserverList<RootWindowsObserver> root_windows_observers_; DISALLOW_COPY_AND_ASSIGN(WindowManagerApplication); |