| 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 "ash/sysui/sysui_application.h" | 5 #include "ash/sysui/sysui_application.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "ash/desktop_background/desktop_background_controller.h" | 12 #include "ash/desktop_background/desktop_background_controller.h" |
| 13 #include "ash/host/ash_window_tree_host_init_params.h" | 13 #include "ash/host/ash_window_tree_host_init_params.h" |
| 14 #include "ash/host/ash_window_tree_host_platform.h" | 14 #include "ash/host/ash_window_tree_host_platform.h" |
| 15 #include "ash/material_design/material_design_controller.h" | 15 #include "ash/material_design/material_design_controller.h" |
| 16 #include "ash/public/interfaces/ash_window_type.mojom.h" |
| 17 #include "ash/public/interfaces/container.mojom.h" |
| 16 #include "ash/root_window_settings.h" | 18 #include "ash/root_window_settings.h" |
| 17 #include "ash/shell.h" | 19 #include "ash/shell.h" |
| 18 #include "ash/shell_init_params.h" | 20 #include "ash/shell_init_params.h" |
| 19 #include "ash/shell_window_ids.h" | 21 #include "ash/shell_window_ids.h" |
| 20 #include "ash/sysui/app_list_presenter_mus.h" | 22 #include "ash/sysui/app_list_presenter_mus.h" |
| 21 #include "ash/sysui/keyboard_ui_mus.h" | 23 #include "ash/sysui/keyboard_ui_mus.h" |
| 22 #include "ash/sysui/shelf_delegate_mus.h" | 24 #include "ash/sysui/shelf_delegate_mus.h" |
| 23 #include "ash/sysui/shell_delegate_mus.h" | 25 #include "ash/sysui/shell_delegate_mus.h" |
| 24 #include "ash/sysui/stub_context_factory.h" | 26 #include "ash/sysui/stub_context_factory.h" |
| 25 #include "base/bind.h" | 27 #include "base/bind.h" |
| 26 #include "base/files/file_path.h" | 28 #include "base/files/file_path.h" |
| 27 #include "base/path_service.h" | 29 #include "base/path_service.h" |
| 28 #include "base/threading/sequenced_worker_pool.h" | 30 #include "base/threading/sequenced_worker_pool.h" |
| 29 #include "components/mus/public/cpp/property_type_converters.h" | 31 #include "components/mus/public/cpp/property_type_converters.h" |
| 30 #include "mash/wm/public/interfaces/ash_window_type.mojom.h" | |
| 31 #include "mash/wm/public/interfaces/container.mojom.h" | |
| 32 #include "services/catalog/public/cpp/resource_loader.h" | 32 #include "services/catalog/public/cpp/resource_loader.h" |
| 33 #include "services/shell/public/cpp/connector.h" | 33 #include "services/shell/public/cpp/connector.h" |
| 34 #include "ui/aura/env.h" | 34 #include "ui/aura/env.h" |
| 35 #include "ui/base/resource/resource_bundle.h" | 35 #include "ui/base/resource/resource_bundle.h" |
| 36 #include "ui/base/ui_base_paths.h" | 36 #include "ui/base/ui_base_paths.h" |
| 37 #include "ui/message_center/message_center.h" | 37 #include "ui/message_center/message_center.h" |
| 38 #include "ui/platform_window/stub/stub_window.h" | 38 #include "ui/platform_window/stub/stub_window.h" |
| 39 #include "ui/views/mus/aura_init.h" | 39 #include "ui/views/mus/aura_init.h" |
| 40 #include "ui/views/mus/native_widget_mus.h" | 40 #include "ui/views/mus/native_widget_mus.h" |
| 41 #include "ui/views/mus/window_manager_connection.h" | 41 #include "ui/views/mus/window_manager_connection.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 53 namespace ash { | 53 namespace ash { |
| 54 namespace sysui { | 54 namespace sysui { |
| 55 | 55 |
| 56 namespace { | 56 namespace { |
| 57 | 57 |
| 58 const char kResourceFileStrings[] = "ash_resources_strings.pak"; | 58 const char kResourceFileStrings[] = "ash_resources_strings.pak"; |
| 59 const char kResourceFile100[] = "ash_resources_100_percent.pak"; | 59 const char kResourceFile100[] = "ash_resources_100_percent.pak"; |
| 60 const char kResourceFile200[] = "ash_resources_200_percent.pak"; | 60 const char kResourceFile200[] = "ash_resources_200_percent.pak"; |
| 61 | 61 |
| 62 // Tries to determine the corresponding mash container from widget init params. | 62 // Tries to determine the corresponding mash container from widget init params. |
| 63 mash::wm::mojom::Container GetContainerId( | 63 mojom::Container GetContainerId(const views::Widget::InitParams& params) { |
| 64 const views::Widget::InitParams& params) { | |
| 65 const int id = params.parent->id(); | 64 const int id = params.parent->id(); |
| 66 if (id == kShellWindowId_DesktopBackgroundContainer) | 65 if (id == kShellWindowId_DesktopBackgroundContainer) |
| 67 return mash::wm::mojom::Container::USER_BACKGROUND; | 66 return mojom::Container::USER_BACKGROUND; |
| 68 if (id == kShellWindowId_ShelfContainer) | 67 if (id == kShellWindowId_ShelfContainer) |
| 69 return mash::wm::mojom::Container::USER_PRIVATE_SHELF; | 68 return mojom::Container::USER_PRIVATE_SHELF; |
| 70 if (id == kShellWindowId_StatusContainer) | 69 if (id == kShellWindowId_StatusContainer) |
| 71 return mash::wm::mojom::Container::STATUS; | 70 return mojom::Container::STATUS; |
| 72 | 71 |
| 73 // Determine the container based on Widget type. | 72 // Determine the container based on Widget type. |
| 74 switch (params.type) { | 73 switch (params.type) { |
| 75 case views::Widget::InitParams::Type::TYPE_BUBBLE: | 74 case views::Widget::InitParams::Type::TYPE_BUBBLE: |
| 76 return mash::wm::mojom::Container::BUBBLES; | 75 return mojom::Container::BUBBLES; |
| 77 case views::Widget::InitParams::Type::TYPE_MENU: | 76 case views::Widget::InitParams::Type::TYPE_MENU: |
| 78 return mash::wm::mojom::Container::MENUS; | 77 return mojom::Container::MENUS; |
| 79 case views::Widget::InitParams::Type::TYPE_TOOLTIP: | 78 case views::Widget::InitParams::Type::TYPE_TOOLTIP: |
| 80 return mash::wm::mojom::Container::DRAG_AND_TOOLTIPS; | 79 return mojom::Container::DRAG_AND_TOOLTIPS; |
| 81 default: | 80 default: |
| 82 return mash::wm::mojom::Container::COUNT; | 81 return mojom::Container::COUNT; |
| 83 } | 82 } |
| 84 } | 83 } |
| 85 | 84 |
| 86 // Tries to determine the corresponding ash window type from the ash container | 85 // Tries to determine the corresponding ash window type from the ash container |
| 87 // for the widget. | 86 // for the widget. |
| 88 mash::wm::mojom::AshWindowType GetAshWindowType(aura::Window* container) { | 87 mojom::AshWindowType GetAshWindowType(aura::Window* container) { |
| 89 DCHECK(container); | 88 DCHECK(container); |
| 90 int id = container->id(); | 89 int id = container->id(); |
| 91 if (id == kShellWindowId_ShelfContainer) | 90 if (id == kShellWindowId_ShelfContainer) |
| 92 return mash::wm::mojom::AshWindowType::SHELF; | 91 return mojom::AshWindowType::SHELF; |
| 93 if (id == kShellWindowId_StatusContainer) | 92 if (id == kShellWindowId_StatusContainer) |
| 94 return mash::wm::mojom::AshWindowType::STATUS_AREA; | 93 return mojom::AshWindowType::STATUS_AREA; |
| 95 return mash::wm::mojom::AshWindowType::COUNT; | 94 return mojom::AshWindowType::COUNT; |
| 96 } | 95 } |
| 97 | 96 |
| 98 // Creates a StubWindow, which means this window never receives any input event, | 97 // Creates a StubWindow, which means this window never receives any input event, |
| 99 // or displays anything to the user. | 98 // or displays anything to the user. |
| 100 class AshWindowTreeHostMus : public AshWindowTreeHostPlatform { | 99 class AshWindowTreeHostMus : public AshWindowTreeHostPlatform { |
| 101 public: | 100 public: |
| 102 explicit AshWindowTreeHostMus(const gfx::Rect& initial_bounds) | 101 explicit AshWindowTreeHostMus(const gfx::Rect& initial_bounds) |
| 103 : AshWindowTreeHostPlatform() { | 102 : AshWindowTreeHostPlatform() { |
| 104 std::unique_ptr<ui::PlatformWindow> window(new ui::StubWindow(this)); | 103 std::unique_ptr<ui::PlatformWindow> window(new ui::StubWindow(this)); |
| 105 window->SetBounds(initial_bounds); | 104 window->SetBounds(initial_bounds); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 134 ViewsDelegate::GetInstance()->set_native_widget_factory( | 133 ViewsDelegate::GetInstance()->set_native_widget_factory( |
| 135 ViewsDelegate::NativeWidgetFactory()); | 134 ViewsDelegate::NativeWidgetFactory()); |
| 136 } | 135 } |
| 137 | 136 |
| 138 private: | 137 private: |
| 139 views::NativeWidget* InitNativeWidget( | 138 views::NativeWidget* InitNativeWidget( |
| 140 const views::Widget::InitParams& params, | 139 const views::Widget::InitParams& params, |
| 141 views::internal::NativeWidgetDelegate* delegate) { | 140 views::internal::NativeWidgetDelegate* delegate) { |
| 142 std::map<std::string, std::vector<uint8_t>> properties; | 141 std::map<std::string, std::vector<uint8_t>> properties; |
| 143 if (params.parent) { | 142 if (params.parent) { |
| 144 mash::wm::mojom::Container container = GetContainerId(params); | 143 mojom::Container container = GetContainerId(params); |
| 145 if (container != mash::wm::mojom::Container::COUNT) { | 144 if (container != mojom::Container::COUNT) { |
| 146 properties[mash::wm::mojom::kWindowContainer_Property] = | 145 properties[mojom::kWindowContainer_Property] = |
| 147 mojo::ConvertTo<std::vector<uint8_t>>( | 146 mojo::ConvertTo<std::vector<uint8_t>>( |
| 148 static_cast<int32_t>(container)); | 147 static_cast<int32_t>(container)); |
| 149 } | 148 } |
| 150 mash::wm::mojom::AshWindowType type = GetAshWindowType(params.parent); | 149 mojom::AshWindowType type = GetAshWindowType(params.parent); |
| 151 if (type != mash::wm::mojom::AshWindowType::COUNT) { | 150 if (type != mojom::AshWindowType::COUNT) { |
| 152 properties[mash::wm::mojom::kAshWindowType_Property] = | 151 properties[mojom::kAshWindowType_Property] = |
| 153 mojo::ConvertTo<std::vector<uint8_t>>(static_cast<int32_t>(type)); | 152 mojo::ConvertTo<std::vector<uint8_t>>(static_cast<int32_t>(type)); |
| 154 } | 153 } |
| 155 } | 154 } |
| 156 | 155 |
| 157 // AshInit installs a stub implementation of ui::ContextFactory, so that the | 156 // AshInit installs a stub implementation of ui::ContextFactory, so that the |
| 158 // AshWindowTreeHost instances created do not actually show anything to the | 157 // AshWindowTreeHost instances created do not actually show anything to the |
| 159 // user. However, when creating a views::Widget instance, the | 158 // user. However, when creating a views::Widget instance, the |
| 160 // WindowManagerConnection creates a WindowTreeHostMus instance, which | 159 // WindowManagerConnection creates a WindowTreeHostMus instance, which |
| 161 // creates a ui::Compositor, and it needs a real ui::ContextFactory | 160 // creates a ui::Compositor, and it needs a real ui::ContextFactory |
| 162 // implementation. So, unset the context-factory here temporarily when | 161 // implementation. So, unset the context-factory here temporarily when |
| (...skipping 23 matching lines...) Expand all Loading... |
| 186 } // namespace | 185 } // namespace |
| 187 | 186 |
| 188 class AshInit { | 187 class AshInit { |
| 189 public: | 188 public: |
| 190 AshInit() : worker_pool_(new base::SequencedWorkerPool(2, "AshWorkerPool")) { | 189 AshInit() : worker_pool_(new base::SequencedWorkerPool(2, "AshWorkerPool")) { |
| 191 ui::RegisterPathProvider(); | 190 ui::RegisterPathProvider(); |
| 192 } | 191 } |
| 193 | 192 |
| 194 ~AshInit() { worker_pool_->Shutdown(); } | 193 ~AshInit() { worker_pool_->Shutdown(); } |
| 195 | 194 |
| 196 aura::Window* root() { return ash::Shell::GetPrimaryRootWindow(); } | 195 aura::Window* root() { return Shell::GetPrimaryRootWindow(); } |
| 197 | 196 |
| 198 void Initialize(::shell::Connector* connector, | 197 void Initialize(::shell::Connector* connector, |
| 199 const ::shell::Identity& identity) { | 198 const ::shell::Identity& identity) { |
| 200 InitializeResourceBundle(connector); | 199 InitializeResourceBundle(connector); |
| 201 aura_init_.reset(new views::AuraInit(connector, "views_mus_resources.pak")); | 200 aura_init_.reset(new views::AuraInit(connector, "views_mus_resources.pak")); |
| 202 ash::MaterialDesignController::Initialize(); | 201 MaterialDesignController::Initialize(); |
| 203 views::WindowManagerConnection::Create(connector, identity); | 202 views::WindowManagerConnection::Create(connector, identity); |
| 204 | 203 |
| 205 display::Screen* screen = display::Screen::GetScreen(); | 204 display::Screen* screen = display::Screen::GetScreen(); |
| 206 DCHECK(screen); | 205 DCHECK(screen); |
| 207 gfx::Size size = screen->GetPrimaryDisplay().bounds().size(); | 206 gfx::Size size = screen->GetPrimaryDisplay().bounds().size(); |
| 208 | 207 |
| 209 // Uninstall the ScreenMus installed by WindowManagerConnection, so that ash | 208 // Uninstall the ScreenMus installed by WindowManagerConnection, so that ash |
| 210 // installs and uses the ScreenAsh. This can be removed once ash learns to | 209 // installs and uses the ScreenAsh. This can be removed once ash learns to |
| 211 // talk to mus for managing displays. | 210 // talk to mus for managing displays. |
| 212 // TODO(mfomitchev): We need to fix this. http://crbug.com/607300 | 211 // TODO(mfomitchev): We need to fix this. http://crbug.com/607300 |
| 213 display::Screen::SetScreenInstance(nullptr); | 212 display::Screen::SetScreenInstance(nullptr); |
| 214 | 213 |
| 215 // Install some hook so that the WindowTreeHostMus created for widgets can | 214 // Install some hook so that the WindowTreeHostMus created for widgets can |
| 216 // be hooked up correctly. | 215 // be hooked up correctly. |
| 217 native_widget_factory_.reset(new NativeWidgetFactory()); | 216 native_widget_factory_.reset(new NativeWidgetFactory()); |
| 218 | 217 |
| 219 ash::AshWindowTreeHost::SetFactory(base::Bind(&CreateWindowTreeHostMus)); | 218 AshWindowTreeHost::SetFactory(base::Bind(&CreateWindowTreeHostMus)); |
| 220 | 219 |
| 221 std::unique_ptr<ash::AppListPresenterMus> app_list_presenter = | 220 std::unique_ptr<AppListPresenterMus> app_list_presenter = |
| 222 base::WrapUnique(new ash::AppListPresenterMus(connector)); | 221 base::WrapUnique(new AppListPresenterMus(connector)); |
| 223 ash_delegate_ = new ShellDelegateMus(std::move(app_list_presenter)); | 222 ash_delegate_ = new ShellDelegateMus(std::move(app_list_presenter)); |
| 224 | 223 |
| 225 InitializeComponents(); | 224 InitializeComponents(); |
| 226 | 225 |
| 227 ash::ShellInitParams init_params; | 226 ShellInitParams init_params; |
| 228 init_params.delegate = ash_delegate_; | 227 init_params.delegate = ash_delegate_; |
| 229 init_params.context_factory = new StubContextFactory; | 228 init_params.context_factory = new StubContextFactory; |
| 230 init_params.blocking_pool = worker_pool_.get(); | 229 init_params.blocking_pool = worker_pool_.get(); |
| 231 init_params.in_mus = true; | 230 init_params.in_mus = true; |
| 232 init_params.keyboard_factory = | 231 init_params.keyboard_factory = |
| 233 base::Bind(&KeyboardUIMus::Create, connector); | 232 base::Bind(&KeyboardUIMus::Create, connector); |
| 234 ash::Shell::CreateInstance(init_params); | 233 Shell::CreateInstance(init_params); |
| 235 ash::Shell::GetInstance()->CreateShelf(); | 234 Shell::GetInstance()->CreateShelf(); |
| 236 ash::Shell::GetInstance()->UpdateAfterLoginStatusChange( | 235 Shell::GetInstance()->UpdateAfterLoginStatusChange(user::LOGGED_IN_USER); |
| 237 ash::user::LOGGED_IN_USER); | |
| 238 | 236 |
| 239 ash::Shell::GetPrimaryRootWindow()->GetHost()->Show(); | 237 Shell::GetPrimaryRootWindow()->GetHost()->Show(); |
| 240 SetupWallpaper(SkColorSetARGB(255, 0, 255, 0)); | 238 SetupWallpaper(SkColorSetARGB(255, 0, 255, 0)); |
| 241 } | 239 } |
| 242 | 240 |
| 243 void InitializeResourceBundle(::shell::Connector* connector) { | 241 void InitializeResourceBundle(::shell::Connector* connector) { |
| 244 if (ui::ResourceBundle::HasSharedInstance()) | 242 if (ui::ResourceBundle::HasSharedInstance()) |
| 245 return; | 243 return; |
| 246 | 244 |
| 247 std::set<std::string> resource_paths; | 245 std::set<std::string> resource_paths; |
| 248 resource_paths.insert(kResourceFileStrings); | 246 resource_paths.insert(kResourceFileStrings); |
| 249 resource_paths.insert(kResourceFile100); | 247 resource_paths.insert(kResourceFile100); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 272 bitmap.eraseColor(color); | 270 bitmap.eraseColor(color); |
| 273 #if !defined(NDEBUG) | 271 #if !defined(NDEBUG) |
| 274 // In debug builds we generate a simple pattern that allows visually | 272 // In debug builds we generate a simple pattern that allows visually |
| 275 // notice if transparency is broken. | 273 // notice if transparency is broken. |
| 276 { | 274 { |
| 277 SkAutoLockPixels alp(bitmap); | 275 SkAutoLockPixels alp(bitmap); |
| 278 *bitmap.getAddr32(0, 0) = SkColorSetRGB(0, 0, 0); | 276 *bitmap.getAddr32(0, 0) = SkColorSetRGB(0, 0, 0); |
| 279 } | 277 } |
| 280 #endif | 278 #endif |
| 281 gfx::ImageSkia wallpaper = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); | 279 gfx::ImageSkia wallpaper = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); |
| 282 ash::Shell::GetInstance() | 280 Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage( |
| 283 ->desktop_background_controller() | 281 wallpaper, wallpaper::WALLPAPER_LAYOUT_TILE); |
| 284 ->SetWallpaperImage(wallpaper, wallpaper::WALLPAPER_LAYOUT_TILE); | |
| 285 } | 282 } |
| 286 | 283 |
| 287 void InitializeComponents() { | 284 void InitializeComponents() { |
| 288 message_center::MessageCenter::Initialize(); | 285 message_center::MessageCenter::Initialize(); |
| 289 | 286 |
| 290 #if defined(OS_CHROMEOS) | 287 #if defined(OS_CHROMEOS) |
| 291 ui::DeviceDataManager::CreateInstance(); | 288 ui::DeviceDataManager::CreateInstance(); |
| 292 chromeos::DBusThreadManager::Initialize(); | 289 chromeos::DBusThreadManager::Initialize(); |
| 293 bluez::BluezDBusManager::Initialize( | 290 bluez::BluezDBusManager::Initialize( |
| 294 chromeos::DBusThreadManager::Get()->GetSystemBus(), | 291 chromeos::DBusThreadManager::Get()->GetSystemBus(), |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 void SysUIApplication::Create( | 323 void SysUIApplication::Create( |
| 327 ::shell::Connection* connection, | 324 ::shell::Connection* connection, |
| 328 mojo::InterfaceRequest<mash::shelf::mojom::ShelfController> request) { | 325 mojo::InterfaceRequest<mash::shelf::mojom::ShelfController> request) { |
| 329 mash::shelf::mojom::ShelfController* shelf_controller = | 326 mash::shelf::mojom::ShelfController* shelf_controller = |
| 330 static_cast<ShelfDelegateMus*>(Shell::GetInstance()->GetShelfDelegate()); | 327 static_cast<ShelfDelegateMus*>(Shell::GetInstance()->GetShelfDelegate()); |
| 331 shelf_controller_bindings_.AddBinding(shelf_controller, std::move(request)); | 328 shelf_controller_bindings_.AddBinding(shelf_controller, std::move(request)); |
| 332 } | 329 } |
| 333 | 330 |
| 334 } // namespace sysui | 331 } // namespace sysui |
| 335 } // namespace ash | 332 } // namespace ash |
| OLD | NEW |