| 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/mus/sysui_application.h" | 5 #include "ash/mus/sysui_application.h" |
| 6 | 6 |
| 7 #include <map> |
| 8 #include <set> |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 7 #include "ash/desktop_background/desktop_background_controller.h" | 12 #include "ash/desktop_background/desktop_background_controller.h" |
| 8 #include "ash/host/ash_window_tree_host_init_params.h" | 13 #include "ash/host/ash_window_tree_host_init_params.h" |
| 9 #include "ash/host/ash_window_tree_host_platform.h" | 14 #include "ash/host/ash_window_tree_host_platform.h" |
| 10 #include "ash/mus/keyboard_ui_mus.h" | 15 #include "ash/mus/keyboard_ui_mus.h" |
| 11 #include "ash/mus/shelf_delegate_mus.h" | 16 #include "ash/mus/shelf_delegate_mus.h" |
| 12 #include "ash/mus/shell_delegate_mus.h" | 17 #include "ash/mus/shell_delegate_mus.h" |
| 13 #include "ash/mus/stub_context_factory.h" | 18 #include "ash/mus/stub_context_factory.h" |
| 14 #include "ash/root_window_settings.h" | 19 #include "ash/root_window_settings.h" |
| 15 #include "ash/shell.h" | 20 #include "ash/shell.h" |
| 16 #include "ash/shell_init_params.h" | 21 #include "ash/shell_init_params.h" |
| 17 #include "ash/shell_window_ids.h" | 22 #include "ash/shell_window_ids.h" |
| 18 #include "base/bind.h" | 23 #include "base/bind.h" |
| 19 #include "base/files/file_path.h" | 24 #include "base/files/file_path.h" |
| 20 #include "base/path_service.h" | 25 #include "base/path_service.h" |
| 21 #include "base/threading/sequenced_worker_pool.h" | 26 #include "base/threading/sequenced_worker_pool.h" |
| 22 #include "components/mus/public/cpp/property_type_converters.h" | 27 #include "components/mus/public/cpp/property_type_converters.h" |
| 28 #include "components/resource_provider/public/cpp/resource_loader.h" |
| 23 #include "mash/wm/public/interfaces/ash_window_type.mojom.h" | 29 #include "mash/wm/public/interfaces/ash_window_type.mojom.h" |
| 24 #include "mash/wm/public/interfaces/container.mojom.h" | 30 #include "mash/wm/public/interfaces/container.mojom.h" |
| 25 #include "ui/aura/env.h" | 31 #include "ui/aura/env.h" |
| 26 #include "ui/base/resource/resource_bundle.h" | 32 #include "ui/base/resource/resource_bundle.h" |
| 27 #include "ui/base/ui_base_paths.h" | 33 #include "ui/base/ui_base_paths.h" |
| 28 #include "ui/message_center/message_center.h" | 34 #include "ui/message_center/message_center.h" |
| 29 #include "ui/platform_window/stub/stub_window.h" | 35 #include "ui/platform_window/stub/stub_window.h" |
| 30 #include "ui/views/mus/aura_init.h" | 36 #include "ui/views/mus/aura_init.h" |
| 31 #include "ui/views/mus/native_widget_mus.h" | 37 #include "ui/views/mus/native_widget_mus.h" |
| 32 #include "ui/views/mus/window_manager_connection.h" | 38 #include "ui/views/mus/window_manager_connection.h" |
| 33 #include "ui/views/views_delegate.h" | 39 #include "ui/views/views_delegate.h" |
| 34 | 40 |
| 35 #if defined(OS_CHROMEOS) | 41 #if defined(OS_CHROMEOS) |
| 36 #include "chromeos/audio/cras_audio_handler.h" | 42 #include "chromeos/audio/cras_audio_handler.h" |
| 37 #include "chromeos/dbus/dbus_thread_manager.h" | 43 #include "chromeos/dbus/dbus_thread_manager.h" |
| 38 #include "device/bluetooth/dbus/bluez_dbus_manager.h" | 44 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
| 39 #include "ui/events/devices/device_data_manager.h" | 45 #include "ui/events/devices/device_data_manager.h" |
| 40 #endif | 46 #endif |
| 41 | 47 |
| 42 using views::ViewsDelegate; | 48 using views::ViewsDelegate; |
| 43 | 49 |
| 44 namespace ash { | 50 namespace ash { |
| 45 namespace sysui { | 51 namespace sysui { |
| 46 | 52 |
| 47 namespace { | 53 namespace { |
| 48 | 54 |
| 55 const char kResourceFileStrings[] = "ash_resources_strings.pak"; |
| 56 const char kResourceFile100[] = "ash_resources_100_percent.pak"; |
| 57 const char kResourceFile200[] = "ash_resources_200_percent.pak"; |
| 58 |
| 49 // Tries to determine the corresponding mash container from widget init params. | 59 // Tries to determine the corresponding mash container from widget init params. |
| 50 mash::wm::mojom::Container GetContainerId( | 60 mash::wm::mojom::Container GetContainerId( |
| 51 const views::Widget::InitParams& params) { | 61 const views::Widget::InitParams& params) { |
| 52 const int id = params.parent->id(); | 62 const int id = params.parent->id(); |
| 53 if (id == kShellWindowId_DesktopBackgroundContainer) | 63 if (id == kShellWindowId_DesktopBackgroundContainer) |
| 54 return mash::wm::mojom::Container::USER_BACKGROUND; | 64 return mash::wm::mojom::Container::USER_BACKGROUND; |
| 55 // mash::wm::ShelfLayout manages both the shelf and the status area. | 65 // mash::wm::ShelfLayout manages both the shelf and the status area. |
| 56 if (id == kShellWindowId_ShelfContainer || | 66 if (id == kShellWindowId_ShelfContainer || |
| 57 id == kShellWindowId_StatusContainer) { | 67 id == kShellWindowId_StatusContainer) { |
| 58 return mash::wm::mojom::Container::USER_SHELF; | 68 return mash::wm::mojom::Container::USER_SHELF; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 | 180 |
| 171 DISALLOW_COPY_AND_ASSIGN(NativeWidgetFactory); | 181 DISALLOW_COPY_AND_ASSIGN(NativeWidgetFactory); |
| 172 }; | 182 }; |
| 173 | 183 |
| 174 } // namespace | 184 } // namespace |
| 175 | 185 |
| 176 class AshInit { | 186 class AshInit { |
| 177 public: | 187 public: |
| 178 AshInit() : worker_pool_(new base::SequencedWorkerPool(2, "AshWorkerPool")) { | 188 AshInit() : worker_pool_(new base::SequencedWorkerPool(2, "AshWorkerPool")) { |
| 179 ui::RegisterPathProvider(); | 189 ui::RegisterPathProvider(); |
| 180 InitializeResourceBundle(); | |
| 181 } | 190 } |
| 182 | 191 |
| 183 ~AshInit() { worker_pool_->Shutdown(); } | 192 ~AshInit() { worker_pool_->Shutdown(); } |
| 184 | 193 |
| 185 aura::Window* root() { return ash::Shell::GetPrimaryRootWindow(); } | 194 aura::Window* root() { return ash::Shell::GetPrimaryRootWindow(); } |
| 186 | 195 |
| 187 void Initialize(mojo::Connector* connector) { | 196 void Initialize(mojo::Connector* connector) { |
| 197 InitializeResourceBundle(connector); |
| 188 aura_init_.reset(new views::AuraInit(connector, "views_mus_resources.pak")); | 198 aura_init_.reset(new views::AuraInit(connector, "views_mus_resources.pak")); |
| 189 views::WindowManagerConnection::Create(connector); | 199 views::WindowManagerConnection::Create(connector); |
| 190 | 200 |
| 191 gfx::Screen* screen = gfx::Screen::GetScreen(); | 201 gfx::Screen* screen = gfx::Screen::GetScreen(); |
| 192 DCHECK(screen); | 202 DCHECK(screen); |
| 193 gfx::Size size = screen->GetPrimaryDisplay().bounds().size(); | 203 gfx::Size size = screen->GetPrimaryDisplay().bounds().size(); |
| 194 | 204 |
| 195 // Uninstall the ScreenMus installed by WindowManagerConnection, so that ash | 205 // Uninstall the ScreenMus installed by WindowManagerConnection, so that ash |
| 196 // installs and uses the ScreenAsh. This can be removed once ash learns to | 206 // installs and uses the ScreenAsh. This can be removed once ash learns to |
| 197 // talk to mus for managing displays. | 207 // talk to mus for managing displays. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 215 base::Bind(&KeyboardUIMus::Create, connector); | 225 base::Bind(&KeyboardUIMus::Create, connector); |
| 216 ash::Shell::CreateInstance(init_params); | 226 ash::Shell::CreateInstance(init_params); |
| 217 ash::Shell::GetInstance()->CreateShelf(); | 227 ash::Shell::GetInstance()->CreateShelf(); |
| 218 ash::Shell::GetInstance()->UpdateAfterLoginStatusChange( | 228 ash::Shell::GetInstance()->UpdateAfterLoginStatusChange( |
| 219 ash::user::LOGGED_IN_USER); | 229 ash::user::LOGGED_IN_USER); |
| 220 | 230 |
| 221 ash::Shell::GetPrimaryRootWindow()->GetHost()->Show(); | 231 ash::Shell::GetPrimaryRootWindow()->GetHost()->Show(); |
| 222 SetupWallpaper(SkColorSetARGB(255, 0, 255, 0)); | 232 SetupWallpaper(SkColorSetARGB(255, 0, 255, 0)); |
| 223 } | 233 } |
| 224 | 234 |
| 225 void InitializeResourceBundle() { | 235 void InitializeResourceBundle(mojo::Connector* connector) { |
| 236 if (ui::ResourceBundle::HasSharedInstance()) |
| 237 return; |
| 238 |
| 239 std::set<std::string> resource_paths; |
| 240 resource_paths.insert(kResourceFileStrings); |
| 241 resource_paths.insert(kResourceFile100); |
| 242 resource_paths.insert(kResourceFile200); |
| 243 |
| 244 resource_provider::ResourceLoader loader(connector, resource_paths); |
| 245 if (!loader.BlockUntilLoaded()) |
| 246 return; |
| 247 |
| 226 // Load ash resources and en-US strings; not 'common' (Chrome) resources. | 248 // Load ash resources and en-US strings; not 'common' (Chrome) resources. |
| 227 // TODO(msw): Do not load 'test' resources (include sys lang; rename paks?). | |
| 228 // TODO(msw): Use the ResourceProvider interface to load these pak files. | |
| 229 // TODO(msw): Check ResourceBundle::IsScaleFactorSupported; load 300% etc. | 249 // TODO(msw): Check ResourceBundle::IsScaleFactorSupported; load 300% etc. |
| 230 base::FilePath path; | 250 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( |
| 231 PathService::Get(base::DIR_MODULE, &path); | 251 loader.ReleaseFile(kResourceFileStrings), |
| 232 base::FilePath ash_test_strings = | 252 base::MemoryMappedFile::Region::kWholeFile); |
| 233 path.Append(FILE_PATH_LITERAL("ash_test_strings.pak")); | |
| 234 base::FilePath ash_test_resources_100 = | |
| 235 path.Append(FILE_PATH_LITERAL("ash_test_resources_100_percent.pak")); | |
| 236 base::FilePath ash_test_resources_200 = | |
| 237 path.Append(FILE_PATH_LITERAL("ash_test_resources_200_percent.pak")); | |
| 238 | |
| 239 ui::ResourceBundle::InitSharedInstanceWithPakPath(ash_test_strings); | |
| 240 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 253 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 241 rb.AddDataPackFromPath(ash_test_resources_100, ui::SCALE_FACTOR_100P); | 254 rb.AddDataPackFromFile(loader.ReleaseFile(kResourceFile100), |
| 242 rb.AddDataPackFromPath(ash_test_resources_200, ui::SCALE_FACTOR_200P); | 255 ui::SCALE_FACTOR_100P); |
| 256 rb.AddDataPackFromFile(loader.ReleaseFile(kResourceFile200), |
| 257 ui::SCALE_FACTOR_200P); |
| 243 } | 258 } |
| 244 | 259 |
| 245 void SetupWallpaper(SkColor color) { | 260 void SetupWallpaper(SkColor color) { |
| 246 SkBitmap bitmap; | 261 SkBitmap bitmap; |
| 247 bitmap.allocN32Pixels(16, 16); | 262 bitmap.allocN32Pixels(16, 16); |
| 248 bitmap.eraseColor(color); | 263 bitmap.eraseColor(color); |
| 249 #if !defined(NDEBUG) | 264 #if !defined(NDEBUG) |
| 250 // In debug builds we generate a simple pattern that allows visually | 265 // In debug builds we generate a simple pattern that allows visually |
| 251 // notice if transparency is broken. | 266 // notice if transparency is broken. |
| 252 { | 267 { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 void SysUIApplication::Create( | 317 void SysUIApplication::Create( |
| 303 mojo::Connection* connection, | 318 mojo::Connection* connection, |
| 304 mojo::InterfaceRequest<mash::shelf::mojom::ShelfController> request) { | 319 mojo::InterfaceRequest<mash::shelf::mojom::ShelfController> request) { |
| 305 mash::shelf::mojom::ShelfController* shelf_controller = | 320 mash::shelf::mojom::ShelfController* shelf_controller = |
| 306 static_cast<ShelfDelegateMus*>(Shell::GetInstance()->GetShelfDelegate()); | 321 static_cast<ShelfDelegateMus*>(Shell::GetInstance()->GetShelfDelegate()); |
| 307 shelf_controller_bindings_.AddBinding(shelf_controller, std::move(request)); | 322 shelf_controller_bindings_.AddBinding(shelf_controller, std::move(request)); |
| 308 } | 323 } |
| 309 | 324 |
| 310 } // namespace sysui | 325 } // namespace sysui |
| 311 } // namespace ash | 326 } // namespace ash |
| OLD | NEW |