| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <memory> | 5 #include <memory> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "ash/public/cpp/shelf_types.h" |
| 9 #include "ash/public/cpp/window_properties.h" |
| 8 #include "base/macros.h" | 10 #include "base/macros.h" |
| 9 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 10 #include "mash/public/interfaces/launchable.mojom.h" | 12 #include "mash/public/interfaces/launchable.mojom.h" |
| 11 #include "mojo/public/cpp/bindings/binding_set.h" | 13 #include "mojo/public/cpp/bindings/binding_set.h" |
| 12 #include "services/service_manager/public/c/main.h" | 14 #include "services/service_manager/public/c/main.h" |
| 13 #include "services/service_manager/public/cpp/binder_registry.h" | 15 #include "services/service_manager/public/cpp/binder_registry.h" |
| 14 #include "services/service_manager/public/cpp/connector.h" | 16 #include "services/service_manager/public/cpp/connector.h" |
| 15 #include "services/service_manager/public/cpp/service.h" | 17 #include "services/service_manager/public/cpp/service.h" |
| 16 #include "services/service_manager/public/cpp/service_context.h" | 18 #include "services/service_manager/public/cpp/service_context.h" |
| 17 #include "services/service_manager/public/cpp/service_runner.h" | 19 #include "services/service_manager/public/cpp/service_runner.h" |
| 20 #include "ui/aura/window.h" |
| 18 #include "ui/views/examples/example_base.h" | 21 #include "ui/views/examples/example_base.h" |
| 19 #include "ui/views/examples/examples_window.h" | 22 #include "ui/views/examples/examples_window.h" |
| 20 #include "ui/views/mus/aura_init.h" | 23 #include "ui/views/mus/aura_init.h" |
| 24 #include "ui/views/widget/widget.h" |
| 21 | 25 |
| 22 class ViewsExamples : public service_manager::Service, | 26 class ViewsExamples : public service_manager::Service, |
| 23 public mash::mojom::Launchable { | 27 public mash::mojom::Launchable { |
| 24 public: | 28 public: |
| 25 ViewsExamples() { | 29 ViewsExamples() { |
| 26 registry_.AddInterface<mash::mojom::Launchable>( | 30 registry_.AddInterface<mash::mojom::Launchable>( |
| 27 base::Bind(&ViewsExamples::Create, base::Unretained(this))); | 31 base::Bind(&ViewsExamples::Create, base::Unretained(this))); |
| 28 } | 32 } |
| 29 ~ViewsExamples() override {} | 33 ~ViewsExamples() override {} |
| 30 | 34 |
| 31 private: | 35 private: |
| 32 // service_manager::Service: | 36 // service_manager::Service: |
| 33 void OnStart() override { | 37 void OnStart() override { |
| 34 aura_init_ = base::MakeUnique<views::AuraInit>( | 38 aura_init_ = base::MakeUnique<views::AuraInit>( |
| 35 context()->connector(), context()->identity(), | 39 context()->connector(), context()->identity(), |
| 36 "views_mus_resources.pak", std::string(), nullptr, | 40 "views_mus_resources.pak", std::string(), nullptr, |
| 37 views::AuraInit::Mode::AURA_MUS); | 41 views::AuraInit::Mode::AURA_MUS); |
| 42 ash::RegisterWindowPropertiesForTransportAndMirroring(); |
| 38 } | 43 } |
| 39 void OnBindInterface(const service_manager::BindSourceInfo& source_info, | 44 void OnBindInterface(const service_manager::BindSourceInfo& source_info, |
| 40 const std::string& interface_name, | 45 const std::string& interface_name, |
| 41 mojo::ScopedMessagePipeHandle interface_pipe) override { | 46 mojo::ScopedMessagePipeHandle interface_pipe) override { |
| 42 registry_.BindInterface(source_info, interface_name, | 47 registry_.BindInterface(source_info, interface_name, |
| 43 std::move(interface_pipe)); | 48 std::move(interface_pipe)); |
| 44 } | 49 } |
| 45 | 50 |
| 46 // mash::mojom::Launchable: | 51 // mash::mojom::Launchable: |
| 47 void Launch(uint32_t what, mash::mojom::LaunchMode how) override { | 52 void Launch(uint32_t what, mash::mojom::LaunchMode how) override { |
| 48 views::examples::ShowExamplesWindow(views::examples::QUIT_ON_CLOSE); | 53 views::Widget* widget = |
| 54 views::examples::ShowExamplesWindow(views::examples::QUIT_ON_CLOSE); |
| 55 aura::Window* window = widget->GetNativeWindow(); |
| 56 const ash::ShelfID shelf_id("org.chromium.mash.views_examples"); |
| 57 window->SetProperty(ash::kShelfIDKey, |
| 58 new std::string(shelf_id.Serialize())); |
| 59 window->SetProperty<int>(ash::kShelfItemTypeKey, ash::TYPE_DIALOG); |
| 49 } | 60 } |
| 50 | 61 |
| 51 void Create(const service_manager::BindSourceInfo& source_info, | 62 void Create(const service_manager::BindSourceInfo& source_info, |
| 52 mash::mojom::LaunchableRequest request) { | 63 mash::mojom::LaunchableRequest request) { |
| 53 bindings_.AddBinding(this, std::move(request)); | 64 bindings_.AddBinding(this, std::move(request)); |
| 54 } | 65 } |
| 55 | 66 |
| 56 mojo::BindingSet<mash::mojom::Launchable> bindings_; | 67 mojo::BindingSet<mash::mojom::Launchable> bindings_; |
| 57 | 68 |
| 58 service_manager::BinderRegistry registry_; | 69 service_manager::BinderRegistry registry_; |
| 59 | 70 |
| 60 std::unique_ptr<views::AuraInit> aura_init_; | 71 std::unique_ptr<views::AuraInit> aura_init_; |
| 61 | 72 |
| 62 DISALLOW_COPY_AND_ASSIGN(ViewsExamples); | 73 DISALLOW_COPY_AND_ASSIGN(ViewsExamples); |
| 63 }; | 74 }; |
| 64 | 75 |
| 65 MojoResult ServiceMain(MojoHandle service_request_handle) { | 76 MojoResult ServiceMain(MojoHandle service_request_handle) { |
| 66 return service_manager::ServiceRunner(new ViewsExamples) | 77 return service_manager::ServiceRunner(new ViewsExamples) |
| 67 .Run(service_request_handle); | 78 .Run(service_request_handle); |
| 68 } | 79 } |
| OLD | NEW |