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