Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(227)

Side by Side Diff: ash/common/wallpaper/wallpaper_controller.cc

Issue 2559503003: mash: Have chrome set itself as the wallpaper picker. (Closed)
Patch Set: Check for a null service manager connection. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/common/wallpaper/wallpaper_controller.h" 5 #include "ash/common/wallpaper/wallpaper_controller.h"
6 6
7 #include "ash/common/shell_delegate.h"
8 #include "ash/common/wallpaper/wallpaper_controller_observer.h" 7 #include "ash/common/wallpaper/wallpaper_controller_observer.h"
9 #include "ash/common/wallpaper/wallpaper_delegate.h" 8 #include "ash/common/wallpaper/wallpaper_delegate.h"
10 #include "ash/common/wallpaper/wallpaper_view.h" 9 #include "ash/common/wallpaper/wallpaper_view.h"
11 #include "ash/common/wallpaper/wallpaper_widget_controller.h" 10 #include "ash/common/wallpaper/wallpaper_widget_controller.h"
12 #include "ash/common/wm_root_window_controller.h" 11 #include "ash/common/wm_root_window_controller.h"
13 #include "ash/common/wm_shell.h" 12 #include "ash/common/wm_shell.h"
14 #include "ash/common/wm_window.h" 13 #include "ash/common/wm_window.h"
15 #include "ash/public/cpp/shell_window_ids.h" 14 #include "ash/public/cpp/shell_window_ids.h"
16 #include "base/bind.h" 15 #include "base/bind.h"
17 #include "base/logging.h" 16 #include "base/logging.h"
18 #include "base/task_runner.h" 17 #include "base/task_runner.h"
19 #include "components/wallpaper/wallpaper_resizer.h" 18 #include "components/wallpaper/wallpaper_resizer.h"
20 #include "content/public/common/service_names.mojom.h"
21 #include "services/service_manager/public/cpp/connector.h"
22 #include "ui/display/manager/managed_display_info.h" 19 #include "ui/display/manager/managed_display_info.h"
23 #include "ui/display/screen.h" 20 #include "ui/display/screen.h"
24 #include "ui/views/widget/widget.h" 21 #include "ui/views/widget/widget.h"
25 22
26 namespace ash { 23 namespace ash {
27 namespace { 24 namespace {
28 25
29 // How long to wait reloading the wallpaper after the display size has changed. 26 // How long to wait reloading the wallpaper after the display size has changed.
30 const int kWallpaperReloadDelayMs = 100; 27 const int kWallpaperReloadDelayMs = 100;
31 28
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 WallpaperControllerObserver* observer) { 62 WallpaperControllerObserver* observer) {
66 observers_.RemoveObserver(observer); 63 observers_.RemoveObserver(observer);
67 } 64 }
68 65
69 wallpaper::WallpaperLayout WallpaperController::GetWallpaperLayout() const { 66 wallpaper::WallpaperLayout WallpaperController::GetWallpaperLayout() const {
70 if (current_wallpaper_) 67 if (current_wallpaper_)
71 return current_wallpaper_->layout(); 68 return current_wallpaper_->layout();
72 return wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED; 69 return wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED;
73 } 70 }
74 71
75 bool WallpaperController::SetWallpaperImage(const gfx::ImageSkia& image, 72 void WallpaperController::SetWallpaperImage(const gfx::ImageSkia& image,
76 wallpaper::WallpaperLayout layout) { 73 wallpaper::WallpaperLayout layout) {
77 VLOG(1) << "SetWallpaper: image_id=" 74 VLOG(1) << "SetWallpaper: image_id="
78 << wallpaper::WallpaperResizer::GetImageId(image) 75 << wallpaper::WallpaperResizer::GetImageId(image)
79 << " layout=" << layout; 76 << " layout=" << layout;
80 77
81 if (WallpaperIsAlreadyLoaded(image, true /* compare_layouts */, layout)) { 78 if (WallpaperIsAlreadyLoaded(image, true /* compare_layouts */, layout)) {
82 VLOG(1) << "Wallpaper is already loaded"; 79 VLOG(1) << "Wallpaper is already loaded";
83 return false; 80 return;
84 } 81 }
85 82
86 current_wallpaper_.reset(new wallpaper::WallpaperResizer( 83 current_wallpaper_.reset(new wallpaper::WallpaperResizer(
87 image, GetMaxDisplaySizeInNative(), layout, task_runner_)); 84 image, GetMaxDisplaySizeInNative(), layout, task_runner_));
88 current_wallpaper_->StartResize(); 85 current_wallpaper_->StartResize();
89 86
90 for (auto& observer : observers_) 87 for (auto& observer : observers_)
91 observer.OnWallpaperDataChanged(); 88 observer.OnWallpaperDataChanged();
92 wallpaper_mode_ = WALLPAPER_IMAGE; 89 wallpaper_mode_ = WALLPAPER_IMAGE;
93 InstallDesktopControllerForAllWindows(); 90 InstallDesktopControllerForAllWindows();
94 return true;
95 } 91 }
96 92
97 void WallpaperController::CreateEmptyWallpaper() { 93 void WallpaperController::CreateEmptyWallpaper() {
98 current_wallpaper_.reset(); 94 current_wallpaper_.reset();
99 wallpaper_mode_ = WALLPAPER_IMAGE; 95 wallpaper_mode_ = WALLPAPER_IMAGE;
100 InstallDesktopControllerForAllWindows(); 96 InstallDesktopControllerForAllWindows();
101 } 97 }
102 98
103 bool WallpaperController::MoveToLockedContainer() { 99 bool WallpaperController::MoveToLockedContainer() {
104 if (locked_) 100 if (locked_)
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 180
185 // Compare layouts only if necessary. 181 // Compare layouts only if necessary.
186 if (compare_layouts && layout != current_wallpaper_->layout()) 182 if (compare_layouts && layout != current_wallpaper_->layout())
187 return false; 183 return false;
188 184
189 return wallpaper::WallpaperResizer::GetImageId(image) == 185 return wallpaper::WallpaperResizer::GetImageId(image) ==
190 current_wallpaper_->original_image_id(); 186 current_wallpaper_->original_image_id();
191 } 187 }
192 188
193 void WallpaperController::OpenSetWallpaperPage() { 189 void WallpaperController::OpenSetWallpaperPage() {
194 WmShell* shell = WmShell::Get(); 190 if (wallpaper_picker_ &&
195 service_manager::Connector* connector = 191 WmShell::Get()->wallpaper_delegate()->CanOpenSetWallpaperPage()) {
James Cook 2016/12/07 23:03:47 Aside: This will need to be mojo-ified someday.
msw 2016/12/07 23:12:55 Perhaps... This is on the ash-side, so this partic
196 shell->delegate()->GetShellConnector(); 192 wallpaper_picker_->Open();
197 if (!connector || !shell->wallpaper_delegate()->CanOpenSetWallpaperPage()) 193 }
198 return; 194 }
199 195
200 mojom::WallpaperManagerPtr wallpaper_manager; 196 void WallpaperController::SetWallpaperPicker(mojom::WallpaperPickerPtr picker) {
201 connector->ConnectToInterface(content::mojom::kBrowserServiceName, 197 wallpaper_picker_ = std::move(picker);
202 &wallpaper_manager);
203 wallpaper_manager->Open();
204 } 198 }
205 199
206 void WallpaperController::SetWallpaper(const SkBitmap& wallpaper, 200 void WallpaperController::SetWallpaper(const SkBitmap& wallpaper,
207 wallpaper::WallpaperLayout layout) { 201 wallpaper::WallpaperLayout layout) {
208 if (wallpaper.isNull()) 202 if (wallpaper.isNull())
209 return; 203 return;
210 204
211 SetWallpaperImage(gfx::ImageSkia::CreateFrom1xBitmap(wallpaper), layout); 205 SetWallpaperImage(gfx::ImageSkia::CreateFrom1xBitmap(wallpaper), layout);
212 } 206 }
213 207
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 return locked ? kShellWindowId_LockScreenWallpaperContainer 267 return locked ? kShellWindowId_LockScreenWallpaperContainer
274 : kShellWindowId_WallpaperContainer; 268 : kShellWindowId_WallpaperContainer;
275 } 269 }
276 270
277 void WallpaperController::UpdateWallpaper(bool clear_cache) { 271 void WallpaperController::UpdateWallpaper(bool clear_cache) {
278 current_wallpaper_.reset(); 272 current_wallpaper_.reset();
279 WmShell::Get()->wallpaper_delegate()->UpdateWallpaper(clear_cache); 273 WmShell::Get()->wallpaper_delegate()->UpdateWallpaper(clear_cache);
280 } 274 }
281 275
282 } // namespace ash 276 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698