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

Side by Side Diff: chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.cc

Issue 2894443002: arc: Set custom icon in shelf for ARC apps. (Closed)
Patch Set: cleanup Created 3 years, 7 months 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 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 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h" 4 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h"
5 5
6 #include <string> 6 #include <string>
7 7
8 #include "ash/display/screen_orientation_controller_chromeos.h" 8 #include "ash/display/screen_orientation_controller_chromeos.h"
9 #include "ash/public/cpp/window_properties.h" 9 #include "ash/public/cpp/window_properties.h"
10 #include "ash/shared/app_types.h" 10 #include "ash/shared/app_types.h"
11 #include "ash/shelf/shelf_model.h" 11 #include "ash/shelf/shelf_model.h"
12 #include "ash/shell.h" 12 #include "ash/shell.h"
13 #include "ash/wm/maximize_mode/maximize_mode_controller.h" 13 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
14 #include "ash/wm/window_state.h" 14 #include "ash/wm/window_state.h"
15 #include "ash/wm/window_state_aura.h" 15 #include "ash/wm/window_state_aura.h"
16 #include "ash/wm/window_util.h" 16 #include "ash/wm/window_util.h"
17 #include "ash/wm_window.h" 17 #include "ash/wm_window.h"
18 #include "base/bind.h" 18 #include "base/bind.h"
19 #include "base/memory/ptr_util.h" 19 #include "base/memory/ptr_util.h"
20 #include "chrome/browser/chromeos/arc/arc_util.h" 20 #include "chrome/browser/chromeos/arc/arc_util.h"
21 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" 22 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h"
23 #include "chrome/browser/ui/ash/launcher/arc_app_window.h"
23 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_item_controller .h" 24 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_item_controller .h"
24 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" 25 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
25 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" 26 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
26 #include "components/arc/arc_bridge_service.h" 27 #include "components/arc/arc_bridge_service.h"
27 #include "components/exo/shell_surface.h" 28 #include "components/exo/shell_surface.h"
28 #include "components/signin/core/account_id/account_id.h" 29 #include "components/signin/core/account_id/account_id.h"
29 #include "components/user_manager/user_manager.h" 30 #include "components/user_manager/user_manager.h"
30 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree nOrientationLockType.h" 31 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree nOrientationLockType.h"
31 #include "ui/aura/client/aura_constants.h" 32 #include "ui/aura/client/aura_constants.h"
32 #include "ui/aura/env.h" 33 #include "ui/aura/env.h"
33 #include "ui/base/base_window.h" 34 #include "ui/base/base_window.h"
34 #include "ui/display/display.h" 35 #include "ui/display/display.h"
35 #include "ui/display/manager/display_manager.h" 36 #include "ui/display/manager/display_manager.h"
36 #include "ui/views/widget/widget.h" 37 #include "ui/views/widget/widget.h"
37 38
38 namespace { 39 namespace {
39 40
40 enum class FullScreenMode {
41 NOT_DEFINED, // Fullscreen mode was not defined.
42 ACTIVE, // Fullscreen is activated for an app.
43 NON_ACTIVE, // Fullscreen was not activated for an app.
44 };
45
46 blink::WebScreenOrientationLockType BlinkOrientationLockFromMojom( 41 blink::WebScreenOrientationLockType BlinkOrientationLockFromMojom(
47 arc::mojom::OrientationLock orientation_lock) { 42 arc::mojom::OrientationLock orientation_lock) {
48 DCHECK_NE(arc::mojom::OrientationLock::CURRENT, orientation_lock); 43 DCHECK_NE(arc::mojom::OrientationLock::CURRENT, orientation_lock);
49 switch (orientation_lock) { 44 switch (orientation_lock) {
50 case arc::mojom::OrientationLock::PORTRAIT: 45 case arc::mojom::OrientationLock::PORTRAIT:
51 return blink::kWebScreenOrientationLockPortrait; 46 return blink::kWebScreenOrientationLockPortrait;
52 case arc::mojom::OrientationLock::LANDSCAPE: 47 case arc::mojom::OrientationLock::LANDSCAPE:
53 return blink::kWebScreenOrientationLockLandscape; 48 return blink::kWebScreenOrientationLockLandscape;
54 case arc::mojom::OrientationLock::PORTRAIT_PRIMARY: 49 case arc::mojom::OrientationLock::PORTRAIT_PRIMARY:
55 return blink::kWebScreenOrientationLockPortraitPrimary; 50 return blink::kWebScreenOrientationLockPortraitPrimary;
56 case arc::mojom::OrientationLock::LANDSCAPE_PRIMARY: 51 case arc::mojom::OrientationLock::LANDSCAPE_PRIMARY:
57 return blink::kWebScreenOrientationLockLandscapePrimary; 52 return blink::kWebScreenOrientationLockLandscapePrimary;
58 case arc::mojom::OrientationLock::PORTRAIT_SECONDARY: 53 case arc::mojom::OrientationLock::PORTRAIT_SECONDARY:
59 return blink::kWebScreenOrientationLockPortraitSecondary; 54 return blink::kWebScreenOrientationLockPortraitSecondary;
60 case arc::mojom::OrientationLock::LANDSCAPE_SECONDARY: 55 case arc::mojom::OrientationLock::LANDSCAPE_SECONDARY:
61 return blink::kWebScreenOrientationLockLandscapeSecondary; 56 return blink::kWebScreenOrientationLockLandscapeSecondary;
62 default: 57 default:
63 return blink::kWebScreenOrientationLockAny; 58 return blink::kWebScreenOrientationLockAny;
64 } 59 }
65 } 60 }
66 61
67 } // namespace 62 } // namespace
68 63
69 using ash::ScreenOrientationController; 64 using ash::ScreenOrientationController;
70 65
71 // The information about the arc application window which has to be kept 66 // The information about the arc application window which has to be kept
72 // even when its AppWindow is not present. 67 // even when its AppWindow is not present.
73 class ArcAppWindowLauncherController::AppWindowInfo { 68 class ArcAppWindowLauncherController::AppWindowInfo {
msw 2017/05/18 18:26:59 I wonder if we could fix ArcAppWindow lifetimes so
khmel 2017/05/18 20:27:51 That is needed, in ARC AppWindow is optional and m
msw 2017/05/18 22:03:39 It's outside the scope of this CL, but couldn't we
khmel 2017/05/18 22:40:02 +1 to try to do this.
74 public: 69 public:
75 explicit AppWindowInfo(const arc::ArcAppShelfId& app_shelf_id) 70 explicit AppWindowInfo(const arc::ArcAppShelfId& app_shelf_id)
76 : app_shelf_id_(app_shelf_id) {} 71 : app_shelf_id_(app_shelf_id) {}
77 ~AppWindowInfo() = default; 72 ~AppWindowInfo() = default;
78 73
74 void SetDescription(const std::string& title,
75 const std::vector<uint8_t>& icon_data_png) {
76 title_ = title;
77 // Chrome has custom Play Store icon. Don't overwrite it.
78 if (app_shelf_id_.app_id() != arc::kPlayStoreAppId)
79 icon_data_png_ = icon_data_png;
80 if (app_window_)
81 app_window_->SetDescription(title_, icon_data_png_);
82 }
83
84 void SetAppWindow(std::unique_ptr<ArcAppWindow> window) {
85 app_window_ = std::move(window);
86 if (app_window_)
87 app_window_->SetDescription(title_, icon_data_png_);
msw 2017/05/18 18:26:59 Should the ArcAppWindow constructor just take a ti
khmel 2017/05/18 20:27:51 Restored to setter. However it seems adding this t
msw 2017/05/18 22:03:39 Your updated change here seems fine.
khmel 2017/05/18 22:40:02 Acknowledged.
88 }
89
79 const arc::ArcAppShelfId& app_shelf_id() const { return app_shelf_id_; } 90 const arc::ArcAppShelfId& app_shelf_id() const { return app_shelf_id_; }
80 91
81 bool has_requested_orientation_lock() const { 92 bool has_requested_orientation_lock() const {
82 return has_requested_orientation_lock_; 93 return has_requested_orientation_lock_;
83 } 94 }
84 95
85 void set_requested_orientation_lock(arc::mojom::OrientationLock lock) { 96 void set_requested_orientation_lock(arc::mojom::OrientationLock lock) {
86 has_requested_orientation_lock_ = true; 97 has_requested_orientation_lock_ = true;
87 requested_orientation_lock_ = lock; 98 requested_orientation_lock_ = lock;
88 } 99 }
89 100
90 arc::mojom::OrientationLock requested_orientation_lock() const { 101 arc::mojom::OrientationLock requested_orientation_lock() const {
91 return requested_orientation_lock_; 102 return requested_orientation_lock_;
92 } 103 }
93 104
94 void set_lock_completion_behavior( 105 void set_lock_completion_behavior(
95 ScreenOrientationController::LockCompletionBehavior lock_behavior) { 106 ScreenOrientationController::LockCompletionBehavior lock_behavior) {
96 lock_completion_behavior_ = lock_behavior; 107 lock_completion_behavior_ = lock_behavior;
97 } 108 }
98 109
99 ScreenOrientationController::LockCompletionBehavior lock_completion_behavior() 110 ScreenOrientationController::LockCompletionBehavior lock_completion_behavior()
100 const { 111 const {
101 return lock_completion_behavior_; 112 return lock_completion_behavior_;
102 } 113 }
103 114
104 void set_app_window(std::unique_ptr<AppWindow> window) { 115 ArcAppWindow* app_window() { return app_window_.get(); }
105 app_window_ = std::move(window);
106 }
107
108 AppWindow* app_window() { return app_window_.get(); }
109 116
110 private: 117 private:
111 const arc::ArcAppShelfId app_shelf_id_; 118 const arc::ArcAppShelfId app_shelf_id_;
112 bool has_requested_orientation_lock_ = false; 119 bool has_requested_orientation_lock_ = false;
113 120
114 // If true, the orientation should be locked to the specific 121 // If true, the orientation should be locked to the specific
115 // orientation after the requested_orientation_lock is applied. 122 // orientation after the requested_orientation_lock is applied.
116 // This is meaningful only if the orientation is one of ::NONE, 123 // This is meaningful only if the orientation is one of ::NONE,
117 // ::PORTRAIT or ::LANDSCAPE. 124 // ::PORTRAIT or ::LANDSCAPE.
118 ScreenOrientationController::LockCompletionBehavior 125 ScreenOrientationController::LockCompletionBehavior
119 lock_completion_behavior_ = 126 lock_completion_behavior_ =
120 ScreenOrientationController::LockCompletionBehavior::None; 127 ScreenOrientationController::LockCompletionBehavior::None;
121 arc::mojom::OrientationLock requested_orientation_lock_ = 128 arc::mojom::OrientationLock requested_orientation_lock_ =
122 arc::mojom::OrientationLock::NONE; 129 arc::mojom::OrientationLock::NONE;
123 std::unique_ptr<AppWindow> app_window_; 130 // Keeps overridden window title.
131 std::string title_;
132 // Keeps overridden window icon.
133 std::vector<uint8_t> icon_data_png_;
134 std::unique_ptr<ArcAppWindow> app_window_;
124 135
125 DISALLOW_COPY_AND_ASSIGN(AppWindowInfo); 136 DISALLOW_COPY_AND_ASSIGN(AppWindowInfo);
126 }; 137 };
127 138
128 // A ui::BaseWindow for a chromeos launcher to control ARC applications.
129 class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow {
130 public:
131 AppWindow(int task_id,
132 const arc::ArcAppShelfId& app_shelf_id,
133 views::Widget* widget,
134 ArcAppWindowLauncherController* owner)
135 : task_id_(task_id),
136 app_shelf_id_(app_shelf_id),
137 widget_(widget),
138 owner_(owner) {}
139 ~AppWindow() = default;
140
141 void SetController(ArcAppWindowLauncherItemController* controller) {
142 DCHECK(!controller_ && controller);
143 controller_ = controller;
144 }
145
146 void ResetController() { controller_ = nullptr; }
147
148 void SetFullscreenMode(FullScreenMode mode) {
149 DCHECK(mode != FullScreenMode::NOT_DEFINED);
150 fullscreen_mode_ = mode;
151 }
152
153 FullScreenMode fullscreen_mode() const { return fullscreen_mode_; }
154
155 int task_id() const { return task_id_; }
156
157 const arc::ArcAppShelfId& app_shelf_id() const { return app_shelf_id_; }
158
159 const ash::ShelfID& shelf_id() const { return shelf_id_; }
160
161 void set_shelf_id(const ash::ShelfID& shelf_id) { shelf_id_ = shelf_id; }
162
163 views::Widget* widget() const { return widget_; }
164
165 ArcAppWindowLauncherItemController* controller() { return controller_; }
166
167 // ui::BaseWindow:
168 bool IsActive() const override {
169 return widget_->IsActive() && owner_->active_task_id_ == task_id_;
170 }
171
172 bool IsMaximized() const override {
173 NOTREACHED();
174 return false;
175 }
176
177 bool IsMinimized() const override {
178 NOTREACHED();
179 return false;
180 }
181
182 bool IsFullscreen() const override {
183 NOTREACHED();
184 return false;
185 }
186
187 gfx::NativeWindow GetNativeWindow() const override {
188 return widget_->GetNativeWindow();
189 }
190
191 gfx::Rect GetRestoredBounds() const override {
192 NOTREACHED();
193 return gfx::Rect();
194 }
195
196 ui::WindowShowState GetRestoredState() const override {
197 NOTREACHED();
198 return ui::SHOW_STATE_NORMAL;
199 }
200
201 gfx::Rect GetBounds() const override {
202 NOTREACHED();
203 return gfx::Rect();
204 }
205
206 void Show() override { widget_->Show(); }
207
208 void ShowInactive() override { NOTREACHED(); }
209
210 void Hide() override { NOTREACHED(); }
211
212 void Close() override { arc::CloseTask(task_id_); }
213
214 void Activate() override { widget_->Activate(); }
215
216 void Deactivate() override { NOTREACHED(); }
217
218 void Maximize() override { NOTREACHED(); }
219
220 void Minimize() override { widget_->Minimize(); }
221
222 void Restore() override { NOTREACHED(); }
223
224 void SetBounds(const gfx::Rect& bounds) override { NOTREACHED(); }
225
226 void FlashFrame(bool flash) override { NOTREACHED(); }
227
228 bool IsAlwaysOnTop() const override {
229 NOTREACHED();
230 return false;
231 }
232
233 void SetAlwaysOnTop(bool always_on_top) override { NOTREACHED(); }
234
235 private:
236 const int task_id_;
237 const arc::ArcAppShelfId app_shelf_id_;
238 ash::ShelfID shelf_id_;
239 FullScreenMode fullscreen_mode_ = FullScreenMode::NOT_DEFINED;
240 // Unowned pointers
241 views::Widget* const widget_;
242 ArcAppWindowLauncherController* owner_;
243 ArcAppWindowLauncherItemController* controller_ = nullptr;
244 // Unowned pointer, represents host ARC window.
245
246 DISALLOW_COPY_AND_ASSIGN(AppWindow);
247 };
248
249 ArcAppWindowLauncherController::ArcAppWindowLauncherController( 139 ArcAppWindowLauncherController::ArcAppWindowLauncherController(
250 ChromeLauncherController* owner) 140 ChromeLauncherController* owner)
251 : AppWindowLauncherController(owner) { 141 : AppWindowLauncherController(owner) {
252 if (arc::IsArcAllowedForProfile(owner->profile())) { 142 if (arc::IsArcAllowedForProfile(owner->profile())) {
253 observed_profile_ = owner->profile(); 143 observed_profile_ = owner->profile();
254 StartObserving(observed_profile_); 144 StartObserving(observed_profile_);
255 } 145 }
256 } 146 }
257 147
258 ArcAppWindowLauncherController::~ArcAppWindowLauncherController() { 148 ArcAppWindowLauncherController::~ArcAppWindowLauncherController() {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 UnregisterApp(info_it->second.get()); 240 UnregisterApp(info_it->second.get());
351 } 241 }
352 } 242 }
353 243
354 ArcAppWindowLauncherController::AppWindowInfo* 244 ArcAppWindowLauncherController::AppWindowInfo*
355 ArcAppWindowLauncherController::GetAppWindowInfoForTask(int task_id) { 245 ArcAppWindowLauncherController::GetAppWindowInfoForTask(int task_id) {
356 const auto it = task_id_to_app_window_info_.find(task_id); 246 const auto it = task_id_to_app_window_info_.find(task_id);
357 return it == task_id_to_app_window_info_.end() ? nullptr : it->second.get(); 247 return it == task_id_to_app_window_info_.end() ? nullptr : it->second.get();
358 } 248 }
359 249
360 ArcAppWindowLauncherController::AppWindow* 250 ArcAppWindow* ArcAppWindowLauncherController::GetAppWindowForTask(int task_id) {
361 ArcAppWindowLauncherController::GetAppWindowForTask(int task_id) {
362 AppWindowInfo* info = GetAppWindowInfoForTask(task_id); 251 AppWindowInfo* info = GetAppWindowInfoForTask(task_id);
363 return info ? info->app_window() : nullptr; 252 return info ? info->app_window() : nullptr;
364 } 253 }
365 254
366 void ArcAppWindowLauncherController::AttachControllerToWindowsIfNeeded() { 255 void ArcAppWindowLauncherController::AttachControllerToWindowsIfNeeded() {
367 for (auto* window : observed_windows_) 256 for (auto* window : observed_windows_)
368 AttachControllerToWindowIfNeeded(window); 257 AttachControllerToWindowIfNeeded(window);
369 } 258 }
370 259
371 void ArcAppWindowLauncherController::AttachControllerToWindowIfNeeded( 260 void ArcAppWindowLauncherController::AttachControllerToWindowIfNeeded(
(...skipping 20 matching lines...) Expand all
392 // Create controller if we have task info. 281 // Create controller if we have task info.
393 AppWindowInfo* info = GetAppWindowInfoForTask(task_id); 282 AppWindowInfo* info = GetAppWindowInfoForTask(task_id);
394 if (!info) { 283 if (!info) {
395 VLOG(1) << "Could not find AppWindowInfo for task:" << task_id; 284 VLOG(1) << "Could not find AppWindowInfo for task:" << task_id;
396 return; 285 return;
397 } 286 }
398 287
399 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); 288 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window);
400 DCHECK(widget); 289 DCHECK(widget);
401 DCHECK(!info->app_window()); 290 DCHECK(!info->app_window());
402 info->set_app_window( 291 info->SetAppWindow(base::MakeUnique<ArcAppWindow>(
403 base::MakeUnique<AppWindow>(task_id, info->app_shelf_id(), widget, this)); 292 task_id, info->app_shelf_id(), widget, this));
404 RegisterApp(info); 293 RegisterApp(info);
405 DCHECK(info->app_window()->controller()); 294 DCHECK(info->app_window()->controller());
406 const ash::ShelfID shelf_id(info->app_window()->shelf_id()); 295 const ash::ShelfID shelf_id(info->app_window()->shelf_id());
407 window->SetProperty(ash::kShelfIDKey, new std::string(shelf_id.Serialize())); 296 window->SetProperty(ash::kShelfIDKey, new std::string(shelf_id.Serialize()));
408 if (ash::Shell::Get() 297 if (ash::Shell::Get()
409 ->maximize_mode_controller() 298 ->maximize_mode_controller()
410 ->IsMaximizeModeWindowManagerEnabled()) { 299 ->IsMaximizeModeWindowManagerEnabled()) {
411 SetOrientationLockForAppWindow(info->app_window()); 300 SetOrientationLockForAppWindow(info->app_window());
412 } 301 }
413 } 302 }
414 303
415 void ArcAppWindowLauncherController::OnAppReadyChanged( 304 void ArcAppWindowLauncherController::OnAppReadyChanged(
416 const std::string& arc_app_id, 305 const std::string& arc_app_id,
417 bool ready) { 306 bool ready) {
418 if (!ready) 307 if (!ready)
419 OnAppRemoved(arc_app_id); 308 OnAppRemoved(arc_app_id);
420 } 309 }
421 310
422 std::vector<int> ArcAppWindowLauncherController::GetTaskIdsForApp( 311 std::vector<int> ArcAppWindowLauncherController::GetTaskIdsForApp(
423 const std::string& arc_app_id) const { 312 const std::string& arc_app_id) const {
424 // Note, AppWindow is optional part for a task and it may be not created if 313 // Note, ArcAppWindow is optional part for a task and it may be not created if
425 // another full screen Android app is currently active. Use 314 // another full screen Android app is currently active. Use
426 // |task_id_to_app_window_info_| that keeps currently running tasks info. 315 // |task_id_to_app_window_info_| that keeps currently running tasks info.
427 std::vector<int> task_ids; 316 std::vector<int> task_ids;
428 for (const auto& it : task_id_to_app_window_info_) { 317 for (const auto& it : task_id_to_app_window_info_) {
429 const AppWindowInfo* app_window_info = it.second.get(); 318 const AppWindowInfo* app_window_info = it.second.get();
430 if (app_window_info->app_shelf_id().app_id() == arc_app_id) 319 if (app_window_info->app_shelf_id().app_id() == arc_app_id)
431 task_ids.push_back(it.first); 320 task_ids.push_back(it.first);
432 } 321 }
433 322
434 return task_ids; 323 return task_ids;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 376
488 task_id_to_app_window_info_.erase(it); 377 task_id_to_app_window_info_.erase(it);
489 } 378 }
490 379
491 void ArcAppWindowLauncherController::OnTaskSetActive(int32_t task_id) { 380 void ArcAppWindowLauncherController::OnTaskSetActive(int32_t task_id) {
492 if (observed_profile_ != owner()->profile()) { 381 if (observed_profile_ != owner()->profile()) {
493 active_task_id_ = task_id; 382 active_task_id_ = task_id;
494 return; 383 return;
495 } 384 }
496 385
497 AppWindow* previous_app_window = GetAppWindowForTask(active_task_id_); 386 ArcAppWindow* previous_app_window = GetAppWindowForTask(active_task_id_);
498 if (previous_app_window) { 387 if (previous_app_window) {
499 owner()->SetItemStatus(previous_app_window->shelf_id(), 388 owner()->SetItemStatus(previous_app_window->shelf_id(),
500 ash::STATUS_RUNNING); 389 ash::STATUS_RUNNING);
501 previous_app_window->SetFullscreenMode( 390 previous_app_window->SetFullscreenMode(
502 previous_app_window->widget() && 391 previous_app_window->widget() &&
503 previous_app_window->widget()->IsFullscreen() 392 previous_app_window->widget()->IsFullscreen()
504 ? FullScreenMode::ACTIVE 393 ? ArcAppWindow::FullScreenMode::ACTIVE
505 : FullScreenMode::NON_ACTIVE); 394 : ArcAppWindow::FullScreenMode::NON_ACTIVE);
506 } 395 }
507 396
508 active_task_id_ = task_id; 397 active_task_id_ = task_id;
509 398
510 AppWindow* current_app_window = GetAppWindowForTask(task_id); 399 ArcAppWindow* current_app_window = GetAppWindowForTask(task_id);
511 if (current_app_window) { 400 if (current_app_window) {
512 owner()->SetItemStatus( 401 if (current_app_window->widget() && current_app_window->IsActive()) {
513 current_app_window->shelf_id(), 402 owner()->SetItemStatus(current_app_window->shelf_id(),
514 current_app_window->widget() && current_app_window->IsActive() 403 ash::STATUS_ACTIVE);
515 ? ash::STATUS_ACTIVE 404 current_app_window->controller()->SetActiveWindow(
516 : ash::STATUS_RUNNING); 405 current_app_window->GetNativeWindow());
406 } else {
407 owner()->SetItemStatus(current_app_window->shelf_id(),
408 ash::STATUS_RUNNING);
409 }
517 // TODO(reveman): Figure out how to support fullscreen in interleaved 410 // TODO(reveman): Figure out how to support fullscreen in interleaved
518 // window mode. 411 // window mode.
519 // if (new_active_app_it->second->widget()) { 412 // if (new_active_app_it->second->widget()) {
520 // new_active_app_it->second->widget()->SetFullscreen( 413 // new_active_app_it->second->widget()->SetFullscreen(
521 // new_active_app_it->second->fullscreen_mode() == 414 // new_active_app_it->second->fullscreen_mode() ==
522 // FullScreenMode::ACTIVE); 415 // ArcAppWindow::FullScreenMode::ACTIVE);
523 // } 416 // }
524 } 417 }
525 } 418 }
526 419
527 void ArcAppWindowLauncherController::OnTaskOrientationLockRequested( 420 void ArcAppWindowLauncherController::OnTaskOrientationLockRequested(
528 int32_t task_id, 421 int32_t task_id,
529 const arc::mojom::OrientationLock orientation_lock) { 422 const arc::mojom::OrientationLock orientation_lock) {
530 // Don't save to AppInfo in prefs because this is requested in runtime. 423 // Don't save to AppInfo in prefs because this is requested in runtime.
531 AppWindowInfo* info = GetAppWindowInfoForTask(task_id); 424 AppWindowInfo* info = GetAppWindowInfoForTask(task_id);
532 DCHECK(info); 425 DCHECK(info);
533 if (!info) 426 if (!info)
534 return; 427 return;
535 428
536 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) { 429 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) {
537 info->set_lock_completion_behavior( 430 info->set_lock_completion_behavior(
538 ScreenOrientationController::LockCompletionBehavior::DisableSensor); 431 ScreenOrientationController::LockCompletionBehavior::DisableSensor);
539 if (!info->has_requested_orientation_lock()) { 432 if (!info->has_requested_orientation_lock()) {
540 info->set_requested_orientation_lock(arc::mojom::OrientationLock::NONE); 433 info->set_requested_orientation_lock(arc::mojom::OrientationLock::NONE);
541 } 434 }
542 } else { 435 } else {
543 info->set_requested_orientation_lock(orientation_lock); 436 info->set_requested_orientation_lock(orientation_lock);
544 info->set_lock_completion_behavior( 437 info->set_lock_completion_behavior(
545 ScreenOrientationController::LockCompletionBehavior::None); 438 ScreenOrientationController::LockCompletionBehavior::None);
546 } 439 }
547 440
548 if (ash::Shell::Get() 441 if (ash::Shell::Get()
549 ->maximize_mode_controller() 442 ->maximize_mode_controller()
550 ->IsMaximizeModeWindowManagerEnabled()) { 443 ->IsMaximizeModeWindowManagerEnabled()) {
551 AppWindow* app_window = info->app_window(); 444 ArcAppWindow* app_window = info->app_window();
552 if (app_window) 445 if (app_window)
553 SetOrientationLockForAppWindow(app_window); 446 SetOrientationLockForAppWindow(app_window);
554 } 447 }
555 } 448 }
556 449
450 void ArcAppWindowLauncherController::OnTaskSetDescription(
451 int32_t task_id,
452 const std::string& label,
453 const std::vector<uint8_t>& icon_png_data) {
454 AppWindowInfo* info = GetAppWindowInfoForTask(task_id);
455 if (!info)
msw 2017/05/18 18:26:59 nit: invert conditional and nest the function call
khmel 2017/05/18 20:27:51 Done.
456 return;
457 info->SetDescription(label, icon_png_data);
458 }
459
557 AppWindowLauncherItemController* 460 AppWindowLauncherItemController*
558 ArcAppWindowLauncherController::ControllerForWindow(aura::Window* window) { 461 ArcAppWindowLauncherController::ControllerForWindow(aura::Window* window) {
559 if (!window) 462 if (!window)
560 return nullptr; 463 return nullptr;
561 464
562 AppWindow* app_window = GetAppWindowForTask(active_task_id_); 465 ArcAppWindow* app_window = GetAppWindowForTask(active_task_id_);
563 if (app_window && 466 if (app_window &&
564 app_window->widget() == views::Widget::GetWidgetForNativeWindow(window)) { 467 app_window->widget() == views::Widget::GetWidgetForNativeWindow(window)) {
565 return app_window->controller(); 468 return app_window->controller();
566 } 469 }
567 470
568 for (auto& it : task_id_to_app_window_info_) { 471 for (auto& it : task_id_to_app_window_info_) {
569 AppWindow* app_window = it.second->app_window(); 472 ArcAppWindow* app_window = it.second->app_window();
570 if (app_window && 473 if (app_window &&
571 app_window->widget() == 474 app_window->widget() ==
572 views::Widget::GetWidgetForNativeWindow(window)) { 475 views::Widget::GetWidgetForNativeWindow(window)) {
573 return it.second->app_window()->controller(); 476 return it.second->app_window()->controller();
574 } 477 }
575 } 478 }
576 479
577 return nullptr; 480 return nullptr;
578 } 481 }
579 482
580 void ArcAppWindowLauncherController::OnWindowActivated( 483 void ArcAppWindowLauncherController::OnWindowActivated(
581 aura::client::ActivationChangeObserver::ActivationReason reason, 484 aura::client::ActivationChangeObserver::ActivationReason reason,
582 aura::Window* gained_active, 485 aura::Window* gained_active,
583 aura::Window* lost_active) { 486 aura::Window* lost_active) {
584 AppWindowLauncherController::OnWindowActivated(reason, gained_active, 487 AppWindowLauncherController::OnWindowActivated(reason, gained_active,
585 lost_active); 488 lost_active);
586 OnTaskSetActive(active_task_id_); 489 OnTaskSetActive(active_task_id_);
587 } 490 }
588 491
589 void ArcAppWindowLauncherController::OnMaximizeModeStarted() { 492 void ArcAppWindowLauncherController::OnMaximizeModeStarted() {
590 for (auto& it : task_id_to_app_window_info_) { 493 for (auto& it : task_id_to_app_window_info_) {
591 AppWindow* app_window = it.second->app_window(); 494 ArcAppWindow* app_window = it.second->app_window();
592 if (app_window) 495 if (app_window)
593 SetOrientationLockForAppWindow(app_window); 496 SetOrientationLockForAppWindow(app_window);
594 } 497 }
595 } 498 }
596 499
597 void ArcAppWindowLauncherController::OnMaximizeModeEnded() { 500 void ArcAppWindowLauncherController::OnMaximizeModeEnded() {
598 ash::ScreenOrientationController* orientation_controller = 501 ash::ScreenOrientationController* orientation_controller =
599 ash::Shell::Get()->screen_orientation_controller(); 502 ash::Shell::Get()->screen_orientation_controller();
600 // Don't unlock one by one because it'll switch to next rotation. 503 // Don't unlock one by one because it'll switch to next rotation.
601 orientation_controller->UnlockAll(); 504 orientation_controller->UnlockAll();
(...skipping 25 matching lines...) Expand all
627 const arc::ArcAppShelfId& app_shelf_id = app_window_info.app_shelf_id(); 530 const arc::ArcAppShelfId& app_shelf_id = app_window_info.app_shelf_id();
628 const auto it = app_shelf_group_to_controller_map_.find(app_shelf_id); 531 const auto it = app_shelf_group_to_controller_map_.find(app_shelf_id);
629 if (it != app_shelf_group_to_controller_map_.end()) { 532 if (it != app_shelf_group_to_controller_map_.end()) {
630 DCHECK_EQ(it->second->app_id(), app_shelf_id.ToString()); 533 DCHECK_EQ(it->second->app_id(), app_shelf_id.ToString());
631 it->second->AddTaskId(task_id); 534 it->second->AddTaskId(task_id);
632 return it->second; 535 return it->second;
633 } 536 }
634 537
635 std::unique_ptr<ArcAppWindowLauncherItemController> controller = 538 std::unique_ptr<ArcAppWindowLauncherItemController> controller =
636 base::MakeUnique<ArcAppWindowLauncherItemController>( 539 base::MakeUnique<ArcAppWindowLauncherItemController>(
637 app_shelf_id.ToString()); 540 app_shelf_id.ToString(), owner());
638 ArcAppWindowLauncherItemController* item_controller = controller.get(); 541 ArcAppWindowLauncherItemController* item_controller = controller.get();
639 const ash::ShelfID shelf_id(app_shelf_id.ToString()); 542 const ash::ShelfID shelf_id(app_shelf_id.ToString());
640 if (!owner()->GetItem(shelf_id)) { 543 if (!owner()->GetItem(shelf_id)) {
641 owner()->CreateAppLauncherItem(std::move(controller), ash::STATUS_RUNNING); 544 owner()->CreateAppLauncherItem(std::move(controller), ash::STATUS_RUNNING);
642 } else { 545 } else {
643 owner()->shelf_model()->SetShelfItemDelegate(shelf_id, 546 owner()->shelf_model()->SetShelfItemDelegate(shelf_id,
644 std::move(controller)); 547 std::move(controller));
645 owner()->SetItemStatus(shelf_id, ash::STATUS_RUNNING); 548 owner()->SetItemStatus(shelf_id, ash::STATUS_RUNNING);
646 } 549 }
647 item_controller->AddTaskId(task_id); 550 item_controller->AddTaskId(task_id);
648 app_shelf_group_to_controller_map_[app_shelf_id] = item_controller; 551 app_shelf_group_to_controller_map_[app_shelf_id] = item_controller;
649 return item_controller; 552 return item_controller;
650 } 553 }
651 554
652 void ArcAppWindowLauncherController::RegisterApp( 555 void ArcAppWindowLauncherController::RegisterApp(
653 AppWindowInfo* app_window_info) { 556 AppWindowInfo* app_window_info) {
654 AppWindow* app_window = app_window_info->app_window(); 557 ArcAppWindow* app_window = app_window_info->app_window();
655 ArcAppWindowLauncherItemController* controller = 558 ArcAppWindowLauncherItemController* controller =
656 AttachControllerToTask(app_window->task_id(), *app_window_info); 559 AttachControllerToTask(app_window->task_id(), *app_window_info);
657 DCHECK(!controller->app_id().empty()); 560 DCHECK(!controller->app_id().empty());
658 const ash::ShelfID shelf_id(controller->app_id()); 561 const ash::ShelfID shelf_id(controller->app_id());
659 DCHECK(owner()->GetItem(shelf_id)); 562 DCHECK(owner()->GetItem(shelf_id));
660 563
661 controller->AddWindow(app_window); 564 controller->AddWindow(app_window);
662 owner()->SetItemStatus(shelf_id, ash::STATUS_RUNNING); 565 owner()->SetItemStatus(shelf_id, ash::STATUS_RUNNING);
663 app_window->SetController(controller); 566 app_window->SetController(controller);
664 app_window->set_shelf_id(shelf_id); 567 app_window->set_shelf_id(shelf_id);
665 } 568 }
666 569
667 void ArcAppWindowLauncherController::UnregisterApp( 570 void ArcAppWindowLauncherController::UnregisterApp(
668 AppWindowInfo* app_window_info) { 571 AppWindowInfo* app_window_info) {
669 AppWindow* app_window = app_window_info->app_window(); 572 ArcAppWindow* app_window = app_window_info->app_window();
670 if (!app_window) 573 if (!app_window)
671 return; 574 return;
672 575
673 ArcAppWindowLauncherItemController* controller = app_window->controller(); 576 ArcAppWindowLauncherItemController* controller = app_window->controller();
674 if (controller) 577 if (controller)
675 controller->RemoveWindow(app_window); 578 controller->RemoveWindow(app_window);
676 app_window->ResetController(); 579 app_window->ResetController();
677 app_window_info->set_app_window(nullptr); 580 app_window_info->SetAppWindow(nullptr);
678 } 581 }
679 582
680 void ArcAppWindowLauncherController::SetOrientationLockForAppWindow( 583 void ArcAppWindowLauncherController::SetOrientationLockForAppWindow(
681 AppWindow* app_window) { 584 ArcAppWindow* app_window) {
682 ash::WmWindow* window = 585 ash::WmWindow* window =
683 ash::WmWindow::Get(app_window->widget()->GetNativeWindow()); 586 ash::WmWindow::Get(app_window->widget()->GetNativeWindow());
684 if (!window) 587 if (!window)
685 return; 588 return;
686 AppWindowInfo* info = GetAppWindowInfoForTask(app_window->task_id()); 589 AppWindowInfo* info = GetAppWindowInfoForTask(app_window->task_id());
687 arc::mojom::OrientationLock orientation_lock; 590 arc::mojom::OrientationLock orientation_lock;
688 591
689 ScreenOrientationController::LockCompletionBehavior lock_completion_behavior = 592 ScreenOrientationController::LockCompletionBehavior lock_completion_behavior =
690 ScreenOrientationController::LockCompletionBehavior::None; 593 ScreenOrientationController::LockCompletionBehavior::None;
691 if (info->has_requested_orientation_lock()) { 594 if (info->has_requested_orientation_lock()) {
(...skipping 23 matching lines...) Expand all
715 const std::string arc_app_id = exo::ShellSurface::GetApplicationId(window); 618 const std::string arc_app_id = exo::ShellSurface::GetApplicationId(window);
716 if (arc_app_id.empty()) 619 if (arc_app_id.empty())
717 return -1; 620 return -1;
718 621
719 int task_id = -1; 622 int task_id = -1;
720 if (sscanf(arc_app_id.c_str(), "org.chromium.arc.%d", &task_id) != 1) 623 if (sscanf(arc_app_id.c_str(), "org.chromium.arc.%d", &task_id) != 1)
721 return -1; 624 return -1;
722 625
723 return task_id; 626 return task_id;
724 } 627 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698