| 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/common/shell_window_ids.h" | 12 #include "ash/common/shell_window_ids.h" |
| 13 #include "ash/desktop_background/desktop_background_controller.h" | 13 #include "ash/desktop_background/desktop_background_controller.h" |
| 14 #include "ash/display/display_manager.h" |
| 14 #include "ash/host/ash_window_tree_host_init_params.h" | 15 #include "ash/host/ash_window_tree_host_init_params.h" |
| 15 #include "ash/host/ash_window_tree_host_platform.h" | 16 #include "ash/host/ash_window_tree_host_platform.h" |
| 16 #include "ash/material_design/material_design_controller.h" | 17 #include "ash/material_design/material_design_controller.h" |
| 17 #include "ash/public/interfaces/ash_window_type.mojom.h" | 18 #include "ash/public/interfaces/ash_window_type.mojom.h" |
| 18 #include "ash/public/interfaces/container.mojom.h" | 19 #include "ash/public/interfaces/container.mojom.h" |
| 19 #include "ash/root_window_settings.h" | 20 #include "ash/root_window_settings.h" |
| 20 #include "ash/shell.h" | 21 #include "ash/shell.h" |
| 21 #include "ash/shell_init_params.h" | 22 #include "ash/shell_init_params.h" |
| 22 #include "ash/sysui/app_list_presenter_mus.h" | 23 #include "ash/sysui/app_list_presenter_mus.h" |
| 23 #include "ash/sysui/keyboard_ui_mus.h" | 24 #include "ash/sysui/keyboard_ui_mus.h" |
| 24 #include "ash/sysui/shelf_delegate_mus.h" | 25 #include "ash/sysui/shelf_delegate_mus.h" |
| 25 #include "ash/sysui/shell_delegate_mus.h" | 26 #include "ash/sysui/shell_delegate_mus.h" |
| 26 #include "ash/sysui/stub_context_factory.h" | 27 #include "ash/sysui/stub_context_factory.h" |
| 28 #include "ash/sysui/user_wallpaper_delegate_mus.h" |
| 27 #include "base/bind.h" | 29 #include "base/bind.h" |
| 28 #include "base/files/file_path.h" | 30 #include "base/files/file_path.h" |
| 29 #include "base/path_service.h" | 31 #include "base/path_service.h" |
| 30 #include "base/threading/sequenced_worker_pool.h" | 32 #include "base/threading/sequenced_worker_pool.h" |
| 31 #include "components/mus/public/cpp/property_type_converters.h" | 33 #include "components/mus/public/cpp/property_type_converters.h" |
| 32 #include "services/catalog/public/cpp/resource_loader.h" | 34 #include "services/catalog/public/cpp/resource_loader.h" |
| 33 #include "services/shell/public/cpp/connector.h" | 35 #include "services/shell/public/cpp/connector.h" |
| 34 #include "ui/aura/env.h" | 36 #include "ui/aura/env.h" |
| 35 #include "ui/base/resource/resource_bundle.h" | 37 #include "ui/base/resource/resource_bundle.h" |
| 36 #include "ui/base/ui_base_paths.h" | 38 #include "ui/base/ui_base_paths.h" |
| 39 #include "ui/display/display.h" |
| 40 #include "ui/display/screen.h" |
| 37 #include "ui/message_center/message_center.h" | 41 #include "ui/message_center/message_center.h" |
| 38 #include "ui/platform_window/stub/stub_window.h" | 42 #include "ui/platform_window/stub/stub_window.h" |
| 39 #include "ui/views/mus/aura_init.h" | 43 #include "ui/views/mus/aura_init.h" |
| 40 #include "ui/views/mus/native_widget_mus.h" | 44 #include "ui/views/mus/native_widget_mus.h" |
| 41 #include "ui/views/mus/window_manager_connection.h" | 45 #include "ui/views/mus/window_manager_connection.h" |
| 42 #include "ui/views/views_delegate.h" | 46 #include "ui/views/views_delegate.h" |
| 43 | 47 |
| 44 #if defined(OS_CHROMEOS) | 48 #if defined(OS_CHROMEOS) |
| 45 #include "chromeos/audio/cras_audio_handler.h" | 49 #include "chromeos/audio/cras_audio_handler.h" |
| 46 #include "chromeos/dbus/dbus_thread_manager.h" | 50 #include "chromeos/dbus/dbus_thread_manager.h" |
| 47 #include "device/bluetooth/dbus/bluez_dbus_manager.h" | 51 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
| 48 #include "ui/events/devices/device_data_manager.h" | 52 #include "ui/events/devices/device_data_manager.h" |
| 49 #endif | 53 #endif |
| 50 | 54 |
| 51 using views::ViewsDelegate; | 55 using views::ViewsDelegate; |
| 52 | 56 |
| 53 namespace ash { | 57 namespace ash { |
| 54 namespace sysui { | 58 namespace sysui { |
| 55 | 59 |
| 56 namespace { | 60 namespace { |
| 57 | 61 |
| 58 const char kResourceFileStrings[] = "ash_resources_strings.pak"; | 62 const char kResourceFileStrings[] = "ash_resources_strings.pak"; |
| 59 const char kResourceFile100[] = "ash_resources_100_percent.pak"; | 63 const char kResourceFile100[] = "ash_resources_100_percent.pak"; |
| 60 const char kResourceFile200[] = "ash_resources_200_percent.pak"; | 64 const char kResourceFile200[] = "ash_resources_200_percent.pak"; |
| 61 | 65 |
| 62 // Tries to determine the corresponding mash container from widget init params. | 66 // Tries to determine the corresponding mash container from widget init params. |
| 63 mojom::Container GetContainerId(const views::Widget::InitParams& params) { | 67 ash::mojom::Container GetContainerId(const views::Widget::InitParams& params) { |
| 64 const int id = params.parent->id(); | 68 const int id = params.parent->id(); |
| 65 if (id == kShellWindowId_DesktopBackgroundContainer) | 69 if (id == kShellWindowId_DesktopBackgroundContainer) |
| 66 return mojom::Container::USER_BACKGROUND; | 70 return ash::mojom::Container::USER_BACKGROUND; |
| 67 if (id == kShellWindowId_ShelfContainer) | 71 if (id == kShellWindowId_ShelfContainer) |
| 68 return mojom::Container::USER_PRIVATE_SHELF; | 72 return ash::mojom::Container::USER_PRIVATE_SHELF; |
| 69 if (id == kShellWindowId_StatusContainer) | 73 if (id == kShellWindowId_StatusContainer) |
| 70 return mojom::Container::STATUS; | 74 return ash::mojom::Container::STATUS; |
| 71 | 75 |
| 72 // Determine the container based on Widget type. | 76 // Determine the container based on Widget type. |
| 73 switch (params.type) { | 77 switch (params.type) { |
| 74 case views::Widget::InitParams::Type::TYPE_BUBBLE: | 78 case views::Widget::InitParams::Type::TYPE_BUBBLE: |
| 75 return mojom::Container::BUBBLES; | 79 return ash::mojom::Container::BUBBLES; |
| 76 case views::Widget::InitParams::Type::TYPE_MENU: | 80 case views::Widget::InitParams::Type::TYPE_MENU: |
| 77 return mojom::Container::MENUS; | 81 return ash::mojom::Container::MENUS; |
| 78 case views::Widget::InitParams::Type::TYPE_TOOLTIP: | 82 case views::Widget::InitParams::Type::TYPE_TOOLTIP: |
| 79 return mojom::Container::DRAG_AND_TOOLTIPS; | 83 return ash::mojom::Container::DRAG_AND_TOOLTIPS; |
| 80 default: | 84 default: |
| 81 return mojom::Container::COUNT; | 85 return ash::mojom::Container::COUNT; |
| 82 } | 86 } |
| 83 } | 87 } |
| 84 | 88 |
| 85 // Tries to determine the corresponding ash window type from the ash container | 89 // Tries to determine the corresponding ash window type from the ash container |
| 86 // for the widget. | 90 // for the widget. |
| 87 mojom::AshWindowType GetAshWindowType(aura::Window* container) { | 91 ash::mojom::AshWindowType GetAshWindowType(aura::Window* container) { |
| 88 DCHECK(container); | 92 DCHECK(container); |
| 89 int id = container->id(); | 93 int id = container->id(); |
| 90 if (id == kShellWindowId_ShelfContainer) | 94 if (id == kShellWindowId_ShelfContainer) |
| 91 return mojom::AshWindowType::SHELF; | 95 return ash::mojom::AshWindowType::SHELF; |
| 92 if (id == kShellWindowId_StatusContainer) | 96 if (id == kShellWindowId_StatusContainer) |
| 93 return mojom::AshWindowType::STATUS_AREA; | 97 return ash::mojom::AshWindowType::STATUS_AREA; |
| 94 return mojom::AshWindowType::COUNT; | 98 return ash::mojom::AshWindowType::COUNT; |
| 95 } | 99 } |
| 96 | 100 |
| 97 // Creates a StubWindow, which means this window never receives any input event, | 101 // Creates a StubWindow, which means this window never receives any input event, |
| 98 // or displays anything to the user. | 102 // or displays anything to the user. |
| 99 class AshWindowTreeHostMus : public AshWindowTreeHostPlatform { | 103 class AshWindowTreeHostMus : public AshWindowTreeHostPlatform { |
| 100 public: | 104 public: |
| 101 explicit AshWindowTreeHostMus(const gfx::Rect& initial_bounds) | 105 explicit AshWindowTreeHostMus(const gfx::Rect& initial_bounds) |
| 102 : AshWindowTreeHostPlatform() { | 106 : AshWindowTreeHostPlatform() { |
| 103 std::unique_ptr<ui::PlatformWindow> window(new ui::StubWindow(this)); | 107 std::unique_ptr<ui::PlatformWindow> window(new ui::StubWindow(this)); |
| 104 window->SetBounds(initial_bounds); | 108 window->SetBounds(initial_bounds); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 133 ViewsDelegate::GetInstance()->set_native_widget_factory( | 137 ViewsDelegate::GetInstance()->set_native_widget_factory( |
| 134 ViewsDelegate::NativeWidgetFactory()); | 138 ViewsDelegate::NativeWidgetFactory()); |
| 135 } | 139 } |
| 136 | 140 |
| 137 private: | 141 private: |
| 138 views::NativeWidget* InitNativeWidget( | 142 views::NativeWidget* InitNativeWidget( |
| 139 const views::Widget::InitParams& params, | 143 const views::Widget::InitParams& params, |
| 140 views::internal::NativeWidgetDelegate* delegate) { | 144 views::internal::NativeWidgetDelegate* delegate) { |
| 141 std::map<std::string, std::vector<uint8_t>> properties; | 145 std::map<std::string, std::vector<uint8_t>> properties; |
| 142 if (params.parent) { | 146 if (params.parent) { |
| 143 mojom::Container container = GetContainerId(params); | 147 ash::mojom::Container container = GetContainerId(params); |
| 144 if (container != mojom::Container::COUNT) { | 148 if (container != ash::mojom::Container::COUNT) { |
| 145 properties[mojom::kWindowContainer_Property] = | 149 properties[ash::mojom::kWindowContainer_Property] = |
| 146 mojo::ConvertTo<std::vector<uint8_t>>( | 150 mojo::ConvertTo<std::vector<uint8_t>>( |
| 147 static_cast<int32_t>(container)); | 151 static_cast<int32_t>(container)); |
| 148 } | 152 } |
| 149 mojom::AshWindowType type = GetAshWindowType(params.parent); | 153 ash::mojom::AshWindowType type = GetAshWindowType(params.parent); |
| 150 if (type != mojom::AshWindowType::COUNT) { | 154 if (type != ash::mojom::AshWindowType::COUNT) { |
| 151 properties[mojom::kAshWindowType_Property] = | 155 properties[ash::mojom::kAshWindowType_Property] = |
| 152 mojo::ConvertTo<std::vector<uint8_t>>(static_cast<int32_t>(type)); | 156 mojo::ConvertTo<std::vector<uint8_t>>(static_cast<int32_t>(type)); |
| 153 } | 157 } |
| 154 } | 158 } |
| 155 | 159 |
| 156 // AshInit installs a stub implementation of ui::ContextFactory, so that the | 160 // AshInit installs a stub implementation of ui::ContextFactory, so that the |
| 157 // AshWindowTreeHost instances created do not actually show anything to the | 161 // AshWindowTreeHost instances created do not actually show anything to the |
| 158 // user. However, when creating a views::Widget instance, the | 162 // user. However, when creating a views::Widget instance, the |
| 159 // WindowManagerConnection creates a WindowTreeHostMus instance, which | 163 // WindowManagerConnection creates a WindowTreeHostMus instance, which |
| 160 // creates a ui::Compositor, and it needs a real ui::ContextFactory | 164 // creates a ui::Compositor, and it needs a real ui::ContextFactory |
| 161 // implementation. So, unset the context-factory here temporarily when | 165 // implementation. So, unset the context-factory here temporarily when |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 init_params.context_factory = new StubContextFactory; | 232 init_params.context_factory = new StubContextFactory; |
| 229 init_params.blocking_pool = worker_pool_.get(); | 233 init_params.blocking_pool = worker_pool_.get(); |
| 230 init_params.in_mus = true; | 234 init_params.in_mus = true; |
| 231 init_params.keyboard_factory = | 235 init_params.keyboard_factory = |
| 232 base::Bind(&KeyboardUIMus::Create, connector); | 236 base::Bind(&KeyboardUIMus::Create, connector); |
| 233 Shell::CreateInstance(init_params); | 237 Shell::CreateInstance(init_params); |
| 234 Shell::GetInstance()->CreateShelf(); | 238 Shell::GetInstance()->CreateShelf(); |
| 235 Shell::GetInstance()->UpdateAfterLoginStatusChange(user::LOGGED_IN_USER); | 239 Shell::GetInstance()->UpdateAfterLoginStatusChange(user::LOGGED_IN_USER); |
| 236 | 240 |
| 237 Shell::GetPrimaryRootWindow()->GetHost()->Show(); | 241 Shell::GetPrimaryRootWindow()->GetHost()->Show(); |
| 238 SetupWallpaper(SkColorSetARGB(255, 0, 255, 0)); | |
| 239 } | 242 } |
| 240 | 243 |
| 241 void InitializeResourceBundle(::shell::Connector* connector) { | 244 void InitializeResourceBundle(::shell::Connector* connector) { |
| 242 if (ui::ResourceBundle::HasSharedInstance()) | 245 if (ui::ResourceBundle::HasSharedInstance()) |
| 243 return; | 246 return; |
| 244 | 247 |
| 245 std::set<std::string> resource_paths; | 248 std::set<std::string> resource_paths; |
| 246 resource_paths.insert(kResourceFileStrings); | 249 resource_paths.insert(kResourceFileStrings); |
| 247 resource_paths.insert(kResourceFile100); | 250 resource_paths.insert(kResourceFile100); |
| 248 resource_paths.insert(kResourceFile200); | 251 resource_paths.insert(kResourceFile200); |
| 249 | 252 |
| 250 catalog::ResourceLoader loader; | 253 catalog::ResourceLoader loader; |
| 251 filesystem::mojom::DirectoryPtr directory; | 254 filesystem::mojom::DirectoryPtr directory; |
| 252 connector->ConnectToInterface("mojo:catalog", &directory); | 255 connector->ConnectToInterface("mojo:catalog", &directory); |
| 253 CHECK(loader.OpenFiles(std::move(directory), resource_paths)); | 256 CHECK(loader.OpenFiles(std::move(directory), resource_paths)); |
| 254 | 257 |
| 255 // Load ash resources and en-US strings; not 'common' (Chrome) resources. | 258 // Load ash resources and en-US strings; not 'common' (Chrome) resources. |
| 256 // TODO(msw): Check ResourceBundle::IsScaleFactorSupported; load 300% etc. | 259 // TODO(msw): Check ResourceBundle::IsScaleFactorSupported; load 300% etc. |
| 257 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( | 260 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( |
| 258 loader.TakeFile(kResourceFileStrings), | 261 loader.TakeFile(kResourceFileStrings), |
| 259 base::MemoryMappedFile::Region::kWholeFile); | 262 base::MemoryMappedFile::Region::kWholeFile); |
| 260 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 263 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 261 rb.AddDataPackFromFile(loader.TakeFile(kResourceFile100), | 264 rb.AddDataPackFromFile(loader.TakeFile(kResourceFile100), |
| 262 ui::SCALE_FACTOR_100P); | 265 ui::SCALE_FACTOR_100P); |
| 263 rb.AddDataPackFromFile(loader.TakeFile(kResourceFile200), | 266 rb.AddDataPackFromFile(loader.TakeFile(kResourceFile200), |
| 264 ui::SCALE_FACTOR_200P); | 267 ui::SCALE_FACTOR_200P); |
| 265 } | 268 } |
| 266 | 269 |
| 267 void SetupWallpaper(SkColor color) { | |
| 268 SkBitmap bitmap; | |
| 269 bitmap.allocN32Pixels(16, 16); | |
| 270 bitmap.eraseColor(color); | |
| 271 #if !defined(NDEBUG) | |
| 272 // In debug builds we generate a simple pattern that allows visually | |
| 273 // notice if transparency is broken. | |
| 274 { | |
| 275 SkAutoLockPixels alp(bitmap); | |
| 276 *bitmap.getAddr32(0, 0) = SkColorSetRGB(0, 0, 0); | |
| 277 } | |
| 278 #endif | |
| 279 gfx::ImageSkia wallpaper = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); | |
| 280 Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage( | |
| 281 wallpaper, wallpaper::WALLPAPER_LAYOUT_TILE); | |
| 282 } | |
| 283 | |
| 284 void InitializeComponents() { | 270 void InitializeComponents() { |
| 285 message_center::MessageCenter::Initialize(); | 271 message_center::MessageCenter::Initialize(); |
| 286 | 272 |
| 287 #if defined(OS_CHROMEOS) | 273 #if defined(OS_CHROMEOS) |
| 288 ui::DeviceDataManager::CreateInstance(); | 274 ui::DeviceDataManager::CreateInstance(); |
| 289 chromeos::DBusThreadManager::Initialize(); | 275 chromeos::DBusThreadManager::Initialize(); |
| 290 bluez::BluezDBusManager::Initialize( | 276 bluez::BluezDBusManager::Initialize( |
| 291 chromeos::DBusThreadManager::Get()->GetSystemBus(), | 277 chromeos::DBusThreadManager::Get()->GetSystemBus(), |
| 292 chromeos::DBusThreadManager::Get()->IsUsingStub( | 278 chromeos::DBusThreadManager::Get()->IsUsingStub( |
| 293 chromeos::DBusClientBundle::BLUETOOTH)); | 279 chromeos::DBusClientBundle::BLUETOOTH)); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 310 | 296 |
| 311 void SysUIApplication::Initialize(::shell::Connector* connector, | 297 void SysUIApplication::Initialize(::shell::Connector* connector, |
| 312 const ::shell::Identity& identity, | 298 const ::shell::Identity& identity, |
| 313 uint32_t id) { | 299 uint32_t id) { |
| 314 ash_init_.reset(new AshInit()); | 300 ash_init_.reset(new AshInit()); |
| 315 ash_init_->Initialize(connector, identity); | 301 ash_init_->Initialize(connector, identity); |
| 316 } | 302 } |
| 317 | 303 |
| 318 bool SysUIApplication::AcceptConnection(::shell::Connection* connection) { | 304 bool SysUIApplication::AcceptConnection(::shell::Connection* connection) { |
| 319 connection->AddInterface<mash::shelf::mojom::ShelfController>(this); | 305 connection->AddInterface<mash::shelf::mojom::ShelfController>(this); |
| 306 connection->AddInterface<mojom::WallpaperController>(this); |
| 320 return true; | 307 return true; |
| 321 } | 308 } |
| 322 | 309 |
| 323 void SysUIApplication::Create( | 310 void SysUIApplication::Create( |
| 324 ::shell::Connection* connection, | 311 ::shell::Connection* connection, |
| 325 mojo::InterfaceRequest<mash::shelf::mojom::ShelfController> request) { | 312 mash::shelf::mojom::ShelfControllerRequest request) { |
| 326 mash::shelf::mojom::ShelfController* shelf_controller = | 313 mash::shelf::mojom::ShelfController* shelf_controller = |
| 327 static_cast<ShelfDelegateMus*>(Shell::GetInstance()->GetShelfDelegate()); | 314 static_cast<ShelfDelegateMus*>(Shell::GetInstance()->GetShelfDelegate()); |
| 328 shelf_controller_bindings_.AddBinding(shelf_controller, std::move(request)); | 315 shelf_controller_bindings_.AddBinding(shelf_controller, std::move(request)); |
| 329 } | 316 } |
| 330 | 317 |
| 318 void SysUIApplication::Create(::shell::Connection* connection, |
| 319 mojom::WallpaperControllerRequest request) { |
| 320 mojom::WallpaperController* wallpaper_controller = |
| 321 static_cast<UserWallpaperDelegateMus*>( |
| 322 Shell::GetInstance()->user_wallpaper_delegate()); |
| 323 wallpaper_controller_bindings_.AddBinding(wallpaper_controller, |
| 324 std::move(request)); |
| 325 } |
| 326 |
| 331 } // namespace sysui | 327 } // namespace sysui |
| 332 } // namespace ash | 328 } // namespace ash |
| OLD | NEW |