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

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

Issue 2398773003: Orientation request may arrive before the window is created. (Closed)
Patch Set: Created 4 years, 2 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/common/shelf/shelf_delegate.h" 8 #include "ash/common/shelf/shelf_delegate.h"
9 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" 9 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h"
10 #include "ash/common/wm/window_state.h" 10 #include "ash/common/wm/window_state.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 case arc::mojom::OrientationLock::PORTRAIT_SECONDARY: 80 case arc::mojom::OrientationLock::PORTRAIT_SECONDARY:
81 return blink::WebScreenOrientationLockPortraitSecondary; 81 return blink::WebScreenOrientationLockPortraitSecondary;
82 case arc::mojom::OrientationLock::LANDSCAPE_SECONDARY: 82 case arc::mojom::OrientationLock::LANDSCAPE_SECONDARY:
83 return blink::WebScreenOrientationLockLandscapeSecondary; 83 return blink::WebScreenOrientationLockLandscapeSecondary;
84 default: 84 default:
85 return blink::WebScreenOrientationLockAny; 85 return blink::WebScreenOrientationLockAny;
86 } 86 }
87 } 87 }
88 88
89 int GetWindowTaskId(aura::Window* window) { 89 int GetWindowTaskId(aura::Window* window) {
90 const std::string window_app_id = exo::ShellSurface::GetApplicationId(window); 90 const std::string arc_app_id = exo::ShellSurface::GetApplicationId(window);
91 if (window_app_id.empty()) 91 if (arc_app_id.empty())
92 return -1; 92 return -1;
93 93
94 int task_id = -1; 94 int task_id = -1;
95 if (sscanf(window_app_id.c_str(), "org.chromium.arc.%d", &task_id) != 1) 95 if (sscanf(arc_app_id.c_str(), "org.chromium.arc.%d", &task_id) != 1)
96 return -1; 96 return -1;
97 97
98 return task_id; 98 return task_id;
99 } 99 }
100 100
101 } // namespace 101 } // namespace
102 102
103 // The information about the arc application window which has to be kept
104 // even when its AppWindow is not present.
105 class ArcAppWindowLauncherController::AppWindowInfo {
106 public:
107 explicit AppWindowInfo(const std::string& shelf_app_id)
108 : shelf_app_id_(shelf_app_id) {}
109 ~AppWindowInfo() {}
110
111 const std::string& shelf_app_id() const { return shelf_app_id_; }
112
113 bool has_requested_orientation_lock() const {
114 return has_requested_orientation_lock_;
115 }
116
117 void set_requested_orientation_lock(arc::mojom::OrientationLock lock) {
118 has_requested_orientation_lock_ = true;
119 requested_orientation_lock_ = lock;
120 }
121
122 arc::mojom::OrientationLock requested_orientation_lock() const {
123 return requested_orientation_lock_;
124 }
125
126 void set_app_window(std::unique_ptr<AppWindow> window) {
127 app_window_ = std::move(window);
128 }
129
130 AppWindow* app_window() { return app_window_.get(); }
131
132 private:
133 std::string shelf_app_id_;
134 bool has_requested_orientation_lock_ = false;
135 arc::mojom::OrientationLock requested_orientation_lock_ =
136 arc::mojom::OrientationLock::NONE;
137 std::unique_ptr<AppWindow> app_window_;
138
139 DISALLOW_COPY_AND_ASSIGN(AppWindowInfo);
140 };
141
142 // A ui::BaseWindow for a chromeos launcher to control ARC applications.
103 class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow { 143 class ArcAppWindowLauncherController::AppWindow : public ui::BaseWindow {
104 public: 144 public:
105 AppWindow(int task_id, 145 AppWindow(int task_id,
106 const std::string app_id,
107 views::Widget* widget, 146 views::Widget* widget,
108 ArcAppWindowLauncherController* owner) 147 ArcAppWindowLauncherController* owner)
109 : task_id_(task_id), app_id_(app_id), widget_(widget), owner_(owner) {} 148 : task_id_(task_id), widget_(widget), owner_(owner) {}
110 ~AppWindow() {} 149 ~AppWindow() {}
111 150
112 void SetController(ArcAppWindowLauncherItemController* controller) { 151 void SetController(ArcAppWindowLauncherItemController* controller) {
113 DCHECK(!controller_ && controller); 152 DCHECK(!controller_ && controller);
114 controller_ = controller; 153 controller_ = controller;
115 } 154 }
116 155
117 void ResetController() { controller_ = nullptr; } 156 void ResetController() { controller_ = nullptr; }
118 157
119 void SetFullscreenMode(FullScreenMode mode) { 158 void SetFullscreenMode(FullScreenMode mode) {
120 DCHECK(mode != FullScreenMode::NOT_DEFINED); 159 DCHECK(mode != FullScreenMode::NOT_DEFINED);
121 fullscreen_mode_ = mode; 160 fullscreen_mode_ = mode;
122 } 161 }
123 162
124 FullScreenMode fullscreen_mode() const { return fullscreen_mode_; } 163 FullScreenMode fullscreen_mode() const { return fullscreen_mode_; }
125 164
126 int task_id() const { return task_id_; } 165 int task_id() const { return task_id_; }
127 166
128 ash::ShelfID shelf_id() const { return shelf_id_; } 167 ash::ShelfID shelf_id() const { return shelf_id_; }
129 168
130 void set_shelf_id(ash::ShelfID shelf_id) { shelf_id_ = shelf_id; } 169 void set_shelf_id(ash::ShelfID shelf_id) { shelf_id_ = shelf_id; }
131 170
132 views::Widget* widget() const { return widget_; } 171 views::Widget* widget() const { return widget_; }
133 172
134 ArcAppWindowLauncherItemController* controller() { return controller_; } 173 ArcAppWindowLauncherItemController* controller() { return controller_; }
135 174
136 const std::string& app_id() { return app_id_; }
137
138 // ui::BaseWindow: 175 // ui::BaseWindow:
139 bool IsActive() const override { 176 bool IsActive() const override {
140 return widget_->IsActive() && owner_->active_task_id_ == task_id_; 177 return widget_->IsActive() && owner_->active_task_id_ == task_id_;
141 } 178 }
142 179
143 bool IsMaximized() const override { 180 bool IsMaximized() const override {
144 NOTREACHED(); 181 NOTREACHED();
145 return false; 182 return false;
146 } 183 }
147 184
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 233
197 void FlashFrame(bool flash) override { NOTREACHED(); } 234 void FlashFrame(bool flash) override { NOTREACHED(); }
198 235
199 bool IsAlwaysOnTop() const override { 236 bool IsAlwaysOnTop() const override {
200 NOTREACHED(); 237 NOTREACHED();
201 return false; 238 return false;
202 } 239 }
203 240
204 void SetAlwaysOnTop(bool always_on_top) override { NOTREACHED(); } 241 void SetAlwaysOnTop(bool always_on_top) override { NOTREACHED(); }
205 242
206 arc::mojom::OrientationLock requested_orientation_lock() const {
207 return requested_orientation_lock_;
208 }
209
210 void set_requested_orientation_lock(arc::mojom::OrientationLock lock) {
211 has_requested_orientation_lock_ = true;
212 requested_orientation_lock_ = lock;
213 }
214
215 bool has_requested_orientation_lock() const {
216 return has_requested_orientation_lock_;
217 }
218
219 private: 243 private:
220 int task_id_; 244 int task_id_;
221 ash::ShelfID shelf_id_ = 0; 245 ash::ShelfID shelf_id_ = 0;
222 std::string app_id_;
223 FullScreenMode fullscreen_mode_ = FullScreenMode::NOT_DEFINED; 246 FullScreenMode fullscreen_mode_ = FullScreenMode::NOT_DEFINED;
224 // Unowned pointers 247 // Unowned pointers
225 views::Widget* const widget_; 248 views::Widget* const widget_;
226 ArcAppWindowLauncherController* owner_; 249 ArcAppWindowLauncherController* owner_;
227 ArcAppWindowLauncherItemController* controller_ = nullptr; 250 ArcAppWindowLauncherItemController* controller_ = nullptr;
228 // Unowned pointer, represents host Arc window. 251 // Unowned pointer, represents host Arc window.
229 252
230 arc::mojom::OrientationLock requested_orientation_lock_ =
231 arc::mojom::OrientationLock::NONE;
232 bool has_requested_orientation_lock_ = false;
233
234 DISALLOW_COPY_AND_ASSIGN(AppWindow); 253 DISALLOW_COPY_AND_ASSIGN(AppWindow);
235 }; 254 };
236 255
237 ArcAppWindowLauncherController::ArcAppWindowLauncherController( 256 ArcAppWindowLauncherController::ArcAppWindowLauncherController(
238 ChromeLauncherController* owner, 257 ChromeLauncherController* owner,
239 ash::ShelfDelegate* shelf_delegate) 258 ash::ShelfDelegate* shelf_delegate)
240 : AppWindowLauncherController(owner), shelf_delegate_(shelf_delegate) { 259 : AppWindowLauncherController(owner), shelf_delegate_(shelf_delegate) {
241 if (arc::ArcAuthService::IsAllowedForProfile(owner->GetProfile())) { 260 if (arc::ArcAuthService::IsAllowedForProfile(owner->GetProfile())) {
242 observed_profile_ = owner->GetProfile(); 261 observed_profile_ = owner->GetProfile();
243 StartObserving(observed_profile_); 262 StartObserving(observed_profile_);
(...skipping 26 matching lines...) Expand all
270 const std::string& primary_user_email = user_manager::UserManager::Get() 289 const std::string& primary_user_email = user_manager::UserManager::Get()
271 ->GetPrimaryUser() 290 ->GetPrimaryUser()
272 ->GetAccountId() 291 ->GetAccountId()
273 .GetUserEmail(); 292 .GetUserEmail();
274 if (user_email == primary_user_email) { 293 if (user_email == primary_user_email) {
275 // Restore existing Arc window and create controllers for them. 294 // Restore existing Arc window and create controllers for them.
276 AttachControllerToWindowsIfNeeded(); 295 AttachControllerToWindowsIfNeeded();
277 296
278 // Make sure that we created items for all apps, not only which have a 297 // Make sure that we created items for all apps, not only which have a
279 // window. 298 // window.
280 for (const auto& it : task_id_to_shelf_app_id_) 299 for (const auto& info : task_id_to_app_window_info_)
281 AttachControllerToTask(it.second, it.first); 300 AttachControllerToTask(info.second->shelf_app_id(), info.first);
282 301
283 // Update active status. 302 // Update active status.
284 OnTaskSetActive(active_task_id_); 303 OnTaskSetActive(active_task_id_);
285 } else { 304 } else {
286 // Remove all Arc apps and destroy its controllers. There is no mapping 305 // Remove all Arc apps and destroy its controllers. There is no mapping
287 // task id to app window because it is not safe when controller is missing. 306 // task id to app window because it is not safe when controller is missing.
288 for (auto& it : task_id_to_app_window_) { 307 for (auto& it : task_id_to_app_window_info_)
289 AppWindow* app_window = it.second.get(); 308 UnregisterApp(it.second.get(), true);
290 UnregisterApp(app_window, true);
291 }
292 task_id_to_app_window_.clear();
293 309
294 // Some controllers might have no windows attached, for example background 310 // Some controllers might have no windows attached, for example background
295 // task when foreground tasks is in full screen. 311 // task when foreground tasks is in full screen.
296 for (const auto& it : app_controller_map_) 312 for (const auto& it : app_controller_map_)
297 owner()->CloseLauncherItem(it.second->shelf_id()); 313 owner()->CloseLauncherItem(it.second->shelf_id());
298 app_controller_map_.clear(); 314 app_controller_map_.clear();
299 } 315 }
300 } 316 }
301 317
302 void ArcAppWindowLauncherController::AdditionalUserAddedToSession( 318 void ArcAppWindowLauncherController::AdditionalUserAddedToSession(
(...skipping 29 matching lines...) Expand all
332 AttachControllerToWindowIfNeeded(window); 348 AttachControllerToWindowIfNeeded(window);
333 } 349 }
334 350
335 void ArcAppWindowLauncherController::OnWindowDestroying(aura::Window* window) { 351 void ArcAppWindowLauncherController::OnWindowDestroying(aura::Window* window) {
336 auto it = 352 auto it =
337 std::find(observed_windows_.begin(), observed_windows_.end(), window); 353 std::find(observed_windows_.begin(), observed_windows_.end(), window);
338 DCHECK(it != observed_windows_.end()); 354 DCHECK(it != observed_windows_.end());
339 observed_windows_.erase(it); 355 observed_windows_.erase(it);
340 window->RemoveObserver(this); 356 window->RemoveObserver(this);
341 357
342 auto it_app_window = 358 auto info_it = std::find_if(
343 std::find_if(task_id_to_app_window_.begin(), task_id_to_app_window_.end(), 359 task_id_to_app_window_info_.begin(), task_id_to_app_window_info_.end(),
344 [window](const TaskIdToAppWindow::value_type& pair) { 360 [window](TaskIdToAppWindowInfo::value_type& pair) {
345 return pair.second->GetNativeWindow() == window; 361 return pair.second->app_window() &&
346 }); 362 pair.second->app_window()->GetNativeWindow() == window;
347 if (it_app_window != task_id_to_app_window_.end()) { 363 });
364 if (info_it != task_id_to_app_window_info_.end()) {
348 // Note, window may be recreated in some cases, so do not close controller 365 // Note, window may be recreated in some cases, so do not close controller
349 // on window destroying. Controller will be closed onTaskDestroyed event 366 // on window destroying. Controller will be closed onTaskDestroyed event
350 // which is generated when actual task is destroyed. 367 // which is generated when actual task is destroyed.
351 UnregisterApp(it_app_window->second.get(), false); 368 UnregisterApp(info_it->second.get(), false);
352 task_id_to_app_window_.erase(it_app_window);
353 } 369 }
354 } 370 }
355 371
372 ArcAppWindowLauncherController::AppWindowInfo*
373 ArcAppWindowLauncherController::GetAppWindowInfoForTask(int task_id) {
374 const auto it = task_id_to_app_window_info_.find(task_id);
375 return it == task_id_to_app_window_info_.end() ? nullptr : it->second.get();
376 }
377
356 ArcAppWindowLauncherController::AppWindow* 378 ArcAppWindowLauncherController::AppWindow*
357 ArcAppWindowLauncherController::GetAppWindowForTask(int task_id) { 379 ArcAppWindowLauncherController::GetAppWindowForTask(int task_id) {
358 TaskIdToAppWindow::iterator it = task_id_to_app_window_.find(task_id); 380 AppWindowInfo* info = GetAppWindowInfoForTask(task_id);
359 if (it == task_id_to_app_window_.end()) 381 return info ? info->app_window() : nullptr;
360 return nullptr;
361 return it->second.get();
362 } 382 }
363 383
364 void ArcAppWindowLauncherController::AttachControllerToWindowsIfNeeded() { 384 void ArcAppWindowLauncherController::AttachControllerToWindowsIfNeeded() {
365 for (auto* window : observed_windows_) 385 for (auto* window : observed_windows_)
366 AttachControllerToWindowIfNeeded(window); 386 AttachControllerToWindowIfNeeded(window);
367 } 387 }
368 388
369 void ArcAppWindowLauncherController::AttachControllerToWindowIfNeeded( 389 void ArcAppWindowLauncherController::AttachControllerToWindowIfNeeded(
370 aura::Window* window) { 390 aura::Window* window) {
371 const int task_id = GetWindowTaskId(window); 391 const int task_id = GetWindowTaskId(window);
372 if (task_id <= 0) 392 if (task_id <= 0)
373 return; 393 return;
374 394
375 // We need to add the observer after exo started observing shell 395 // We need to add the observer after exo started observing shell
376 // because we want to update the orientation after exo send 396 // because we want to update the orientation after exo send
377 // the layout switch information. 397 // the layout switch information.
378 if (!observing_shell_) { 398 if (!observing_shell_) {
379 observing_shell_ = true; 399 observing_shell_ = true;
380 ash::WmShell::Get()->AddShellObserver(this); 400 ash::WmShell::Get()->AddShellObserver(this);
381 } 401 }
382 402
383 // Check if we have controller for this task. 403 // Check if we have controller for this task.
384 if (GetAppWindowForTask(task_id)) 404 if (GetAppWindowForTask(task_id))
385 return; 405 return;
386 406
387 // Create controller if we have task info. 407 // Create controller if we have task info.
388 TaskIdToShelfAppIdMap::iterator it = task_id_to_shelf_app_id_.find(task_id); 408 AppWindowInfo* info = GetAppWindowInfoForTask(task_id);
389 if (it == task_id_to_shelf_app_id_.end()) 409 if (!info) {
410 VLOG(1) << "Could not find AppWindowInfo for task:" << task_id;
390 return; 411 return;
391 412 }
392 const std::string& app_id = it->second;
393 413
394 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); 414 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window);
395 DCHECK(widget); 415 DCHECK(widget);
396 std::unique_ptr<AppWindow> app_window( 416 DCHECK(!info->app_window());
397 new AppWindow(task_id, app_id, widget, this)); 417 info->set_app_window(base::MakeUnique<AppWindow>(task_id, widget, this));
398 RegisterApp(app_window.get()); 418 RegisterApp(info);
399 DCHECK(app_window->controller()); 419 DCHECK(info->app_window()->controller());
400 ash::SetShelfIDForWindow(app_window->shelf_id(), window); 420 ash::SetShelfIDForWindow(info->app_window()->shelf_id(), window);
401 if (ash::WmShell::Get() 421 if (ash::WmShell::Get()
402 ->maximize_mode_controller() 422 ->maximize_mode_controller()
403 ->IsMaximizeModeWindowManagerEnabled()) { 423 ->IsMaximizeModeWindowManagerEnabled()) {
404 SetOrientationLockForAppWindow(app_window.get()); 424 SetOrientationLockForAppWindow(info->app_window());
405 } 425 }
406 task_id_to_app_window_[task_id] = std::move(app_window);
407 } 426 }
408 427
409 void ArcAppWindowLauncherController::OnAppReadyChanged( 428 void ArcAppWindowLauncherController::OnAppReadyChanged(
410 const std::string& app_id, 429 const std::string& arc_app_id,
411 bool ready) { 430 bool ready) {
412 if (!ready) 431 if (!ready)
413 OnAppRemoved(app_id); 432 OnAppRemoved(arc_app_id);
414 } 433 }
415 434
416 void ArcAppWindowLauncherController::OnAppRemoved(const std::string& app_id) { 435 void ArcAppWindowLauncherController::OnAppRemoved(
417 const std::string shelf_app_id = GetShelfAppIdFromArcAppId(app_id); 436 const std::string& arc_app_id) {
437 const std::string shelf_app_id = GetShelfAppIdFromArcAppId(arc_app_id);
418 438
419 AppControllerMap::const_iterator it = app_controller_map_.find(shelf_app_id); 439 const auto it = app_controller_map_.find(shelf_app_id);
420 if (it == app_controller_map_.end()) 440 if (it == app_controller_map_.end())
421 return; 441 return;
422 442
423 const ArcAppWindowLauncherItemController* controller = it->second; 443 const ArcAppWindowLauncherItemController* controller = it->second;
424 444
425 std::vector<int> task_ids_to_remove; 445 std::vector<int> task_ids_to_remove;
426 for (auto* window : controller->windows()) { 446 for (auto* window : controller->windows()) {
427 AppWindow* app_window = static_cast<AppWindow*>(window); 447 AppWindow* app_window = static_cast<AppWindow*>(window);
428 task_ids_to_remove.push_back(app_window->task_id()); 448 task_ids_to_remove.push_back(app_window->task_id());
429 } 449 }
430 450
431 for (const auto task_id : task_ids_to_remove) 451 for (const auto task_id : task_ids_to_remove)
432 OnTaskDestroyed(task_id); 452 OnTaskDestroyed(task_id);
433 453
434 DCHECK(app_controller_map_.find(shelf_app_id) == app_controller_map_.end()); 454 DCHECK(app_controller_map_.find(shelf_app_id) == app_controller_map_.end());
435 } 455 }
436 456
437 void ArcAppWindowLauncherController::OnTaskCreated( 457 void ArcAppWindowLauncherController::OnTaskCreated(
438 int task_id, 458 int task_id,
439 const std::string& package_name, 459 const std::string& package_name,
440 const std::string& activity_name) { 460 const std::string& activity_name) {
441 DCHECK(!GetAppWindowForTask(task_id)); 461 DCHECK(!GetAppWindowForTask(task_id));
442 const std::string shelf_app_id = GetShelfAppIdFromArcAppId( 462 const std::string arc_app_id =
443 ArcAppListPrefs::GetAppId(package_name, activity_name)); 463 ArcAppListPrefs::GetAppId(package_name, activity_name);
444 task_id_to_shelf_app_id_[task_id] = shelf_app_id; 464 const std::string shelf_app_id = GetShelfAppIdFromArcAppId(arc_app_id);
445 465 task_id_to_app_window_info_[task_id] =
466 base::MakeUnique<AppWindowInfo>(shelf_app_id);
446 // Don't create shelf icon for non-primary user. 467 // Don't create shelf icon for non-primary user.
447 if (observed_profile_ != owner()->GetProfile()) 468 if (observed_profile_ != owner()->GetProfile())
448 return; 469 return;
449 470
450 AttachControllerToWindowsIfNeeded(); 471 AttachControllerToWindowsIfNeeded();
451 472
452 // Some tasks can be started in background and might have no window until 473 // Some tasks can be started in background and might have no window until
453 // pushed to the front. We need its representation on the shelf to give a user 474 // pushed to the front. We need its representation on the shelf to give a user
454 // control over it. 475 // control over it.
455 AttachControllerToTask(shelf_app_id, task_id); 476 AttachControllerToTask(shelf_app_id, task_id);
456 } 477 }
457 478
458 void ArcAppWindowLauncherController::OnTaskDestroyed(int task_id) { 479 void ArcAppWindowLauncherController::OnTaskDestroyed(int task_id) {
459 auto it = task_id_to_app_window_.find(task_id); 480 auto it = task_id_to_app_window_info_.find(task_id);
460 if (it != task_id_to_app_window_.end()) { 481 if (it == task_id_to_app_window_info_.end())
461 AppWindow* app_window = it->second.get(); 482 return;
462 UnregisterApp(app_window, true); 483 UnregisterApp(it->second.get(), true);
463 task_id_to_app_window_.erase(it);
464 }
465 484
466 // Check if we may close controller now, at this point we can safely remove 485 // Check if we may close controller now, at this point we can safely remove
467 // controllers without window. 486 // controllers without window.
468 auto it_app_id = task_id_to_shelf_app_id_.find(task_id); 487 const std::string& shelf_app_id = it->second->shelf_app_id();
469 if (it_app_id == task_id_to_shelf_app_id_.end())
470 return;
471 488
472 const std::string& app_id = it_app_id->second; 489 const auto it_controller = app_controller_map_.find(shelf_app_id);
473 AppControllerMap::iterator it_controller = app_controller_map_.find(app_id);
474 if (it_controller != app_controller_map_.end()) { 490 if (it_controller != app_controller_map_.end()) {
475 ArcAppWindowLauncherItemController* controller = it_controller->second; 491 ArcAppWindowLauncherItemController* controller = it_controller->second;
476 controller->RemoveTaskId(task_id); 492 controller->RemoveTaskId(task_id);
477 if (!controller->window_count()) { 493 if (!controller->window_count()) {
478 owner()->CloseLauncherItem(controller->shelf_id()); 494 owner()->CloseLauncherItem(controller->shelf_id());
479 app_controller_map_.erase(it_controller); 495 app_controller_map_.erase(it_controller);
480 } 496 }
481 } 497 }
482 498
483 task_id_to_shelf_app_id_.erase(it_app_id); 499 task_id_to_app_window_info_.erase(it);
484 } 500 }
485 501
486 void ArcAppWindowLauncherController::OnTaskSetActive(int32_t task_id) { 502 void ArcAppWindowLauncherController::OnTaskSetActive(int32_t task_id) {
487 if (observed_profile_ != owner()->GetProfile()) { 503 if (observed_profile_ != owner()->GetProfile()) {
488 active_task_id_ = task_id; 504 active_task_id_ = task_id;
489 return; 505 return;
490 } 506 }
491 507
492 TaskIdToAppWindow::iterator previous_active_app_it = 508 AppWindow* previous_app_window = GetAppWindowForTask(active_task_id_);
493 task_id_to_app_window_.find(active_task_id_); 509 if (previous_app_window) {
494 if (previous_active_app_it != task_id_to_app_window_.end()) { 510 owner()->SetItemStatus(previous_app_window->shelf_id(),
495 owner()->SetItemStatus(previous_active_app_it->second->shelf_id(),
496 ash::STATUS_RUNNING); 511 ash::STATUS_RUNNING);
497 previous_active_app_it->second->SetFullscreenMode( 512 previous_app_window->SetFullscreenMode(
498 previous_active_app_it->second->widget() && 513 previous_app_window->widget() &&
499 previous_active_app_it->second->widget()->IsFullscreen() 514 previous_app_window->widget()->IsFullscreen()
500 ? FullScreenMode::ACTIVE 515 ? FullScreenMode::ACTIVE
501 : FullScreenMode::NON_ACTIVE); 516 : FullScreenMode::NON_ACTIVE);
502 } 517 }
503 518
504 active_task_id_ = task_id; 519 active_task_id_ = task_id;
505 520
506 TaskIdToAppWindow::iterator new_active_app_it = 521 AppWindow* current_app_window = GetAppWindowForTask(task_id);
507 task_id_to_app_window_.find(active_task_id_); 522 if (current_app_window) {
508 if (new_active_app_it != task_id_to_app_window_.end()) {
509 owner()->SetItemStatus( 523 owner()->SetItemStatus(
510 new_active_app_it->second->shelf_id(), 524 current_app_window->shelf_id(),
511 new_active_app_it->second->widget() && 525 current_app_window->widget() && current_app_window->IsActive()
512 new_active_app_it->second->widget()->IsActive()
513 ? ash::STATUS_ACTIVE 526 ? ash::STATUS_ACTIVE
514 : ash::STATUS_RUNNING); 527 : ash::STATUS_RUNNING);
515 // TODO(reveman): Figure out how to support fullscreen in interleaved 528 // TODO(reveman): Figure out how to support fullscreen in interleaved
516 // window mode. 529 // window mode.
517 // if (new_active_app_it->second->widget()) { 530 // if (new_active_app_it->second->widget()) {
518 // new_active_app_it->second->widget()->SetFullscreen( 531 // new_active_app_it->second->widget()->SetFullscreen(
519 // new_active_app_it->second->fullscreen_mode() == 532 // new_active_app_it->second->fullscreen_mode() ==
520 // FullScreenMode::ACTIVE); 533 // FullScreenMode::ACTIVE);
521 // } 534 // }
522 } 535 }
523 } 536 }
524 537
525 void ArcAppWindowLauncherController::OnTaskOrientationLockRequested( 538 void ArcAppWindowLauncherController::OnTaskOrientationLockRequested(
526 int32_t task_id, 539 int32_t task_id,
527 const arc::mojom::OrientationLock orientation_lock) { 540 const arc::mojom::OrientationLock orientation_lock) {
528 // Don't save to AppInfo because this is requested in runtime. 541 // Don't save to AppInfo in prefs because this is requested in runtime.
529 TaskIdToAppWindow::iterator app_it = task_id_to_app_window_.find(task_id); 542 AppWindowInfo* info = GetAppWindowInfoForTask(task_id);
530 if (app_it == task_id_to_app_window_.end()) 543 DCHECK(info);
544 if (!info)
531 return; 545 return;
532 AppWindow* app_window = app_it->second.get(); 546 info->set_requested_orientation_lock(orientation_lock);
533 app_window->set_requested_orientation_lock(orientation_lock);
534 547
535 if (ash::WmShell::Get() 548 if (ash::WmShell::Get()
536 ->maximize_mode_controller() 549 ->maximize_mode_controller()
537 ->IsMaximizeModeWindowManagerEnabled()) { 550 ->IsMaximizeModeWindowManagerEnabled()) {
538 SetOrientationLockForAppWindow(app_window); 551 AppWindow* app_window = info->app_window();
552 if (app_window)
553 SetOrientationLockForAppWindow(app_window);
539 } 554 }
540 } 555 }
541 556
542 AppWindowLauncherItemController* 557 AppWindowLauncherItemController*
543 ArcAppWindowLauncherController::ControllerForWindow(aura::Window* window) { 558 ArcAppWindowLauncherController::ControllerForWindow(aura::Window* window) {
544 AppWindow* app_window = GetAppWindowForTask(active_task_id_); 559 AppWindow* app_window = GetAppWindowForTask(active_task_id_);
545 if (app_window && 560 if (app_window &&
546 app_window->widget() == views::Widget::GetWidgetForNativeWindow(window)) { 561 app_window->widget() == views::Widget::GetWidgetForNativeWindow(window)) {
547 return app_window->controller(); 562 return app_window->controller();
548 } 563 }
549 564
550 for (auto& it : task_id_to_app_window_) { 565 for (auto& it : task_id_to_app_window_info_) {
551 if (it.second->widget() == views::Widget::GetWidgetForNativeWindow(window)) 566 AppWindow* app_window = it.second->app_window();
552 return it.second->controller(); 567 if (app_window &&
568 app_window->widget() ==
569 views::Widget::GetWidgetForNativeWindow(window)) {
570 return it.second->app_window()->controller();
571 }
553 } 572 }
554 573
555 return nullptr; 574 return nullptr;
556 } 575 }
557 576
558 void ArcAppWindowLauncherController::OnWindowActivated( 577 void ArcAppWindowLauncherController::OnWindowActivated(
559 aura::client::ActivationChangeObserver::ActivationReason reason, 578 aura::client::ActivationChangeObserver::ActivationReason reason,
560 aura::Window* gained_active, 579 aura::Window* gained_active,
561 aura::Window* lost_active) { 580 aura::Window* lost_active) {
562 OnTaskSetActive(active_task_id_); 581 OnTaskSetActive(active_task_id_);
563 } 582 }
564 583
565 void ArcAppWindowLauncherController::OnMaximizeModeStarted() { 584 void ArcAppWindowLauncherController::OnMaximizeModeStarted() {
566 for (auto& it : task_id_to_app_window_) 585 for (auto& it : task_id_to_app_window_info_) {
567 SetOrientationLockForAppWindow(it.second.get()); 586 AppWindow* app_window = it.second->app_window();
587 if (app_window)
588 SetOrientationLockForAppWindow(app_window);
589 }
568 } 590 }
569 591
570 void ArcAppWindowLauncherController::OnMaximizeModeEnded() { 592 void ArcAppWindowLauncherController::OnMaximizeModeEnded() {
571 ash::ScreenOrientationController* orientation_controller = 593 ash::ScreenOrientationController* orientation_controller =
572 ash::Shell::GetInstance()->screen_orientation_controller(); 594 ash::Shell::GetInstance()->screen_orientation_controller();
573 // Don't unlock one by one because it'll switch to next rotation. 595 // Don't unlock one by one because it'll switch to next rotation.
574 orientation_controller->UnlockAll(); 596 orientation_controller->UnlockAll();
575 } 597 }
576 598
577 void ArcAppWindowLauncherController::StartObserving(Profile* profile) { 599 void ArcAppWindowLauncherController::StartObserving(Profile* profile) {
(...skipping 12 matching lines...) Expand all
590 prefs->RemoveObserver(this); 612 prefs->RemoveObserver(this);
591 aura::Env* env = aura::Env::GetInstanceDontCreate(); 613 aura::Env* env = aura::Env::GetInstanceDontCreate();
592 if (env) 614 if (env)
593 env->RemoveObserver(this); 615 env->RemoveObserver(this);
594 } 616 }
595 617
596 ArcAppWindowLauncherItemController* 618 ArcAppWindowLauncherItemController*
597 ArcAppWindowLauncherController::AttachControllerToTask( 619 ArcAppWindowLauncherController::AttachControllerToTask(
598 const std::string& shelf_app_id, 620 const std::string& shelf_app_id,
599 int task_id) { 621 int task_id) {
600 AppControllerMap::const_iterator it = app_controller_map_.find(shelf_app_id); 622 const auto it = app_controller_map_.find(shelf_app_id);
601 if (it != app_controller_map_.end()) { 623 if (it != app_controller_map_.end()) {
602 DCHECK_EQ(it->second->app_id(), shelf_app_id); 624 DCHECK_EQ(it->second->app_id(), shelf_app_id);
603 it->second->AddTaskId(task_id); 625 it->second->AddTaskId(task_id);
604 return it->second; 626 return it->second;
605 } 627 }
606 628
607 ArcAppWindowLauncherItemController* controller = 629 ArcAppWindowLauncherItemController* controller =
608 new ArcAppWindowLauncherItemController(shelf_app_id, owner()); 630 new ArcAppWindowLauncherItemController(shelf_app_id, owner());
609 const ash::ShelfID shelf_id = 631 const ash::ShelfID shelf_id =
610 shelf_delegate_->GetShelfIDForAppID(shelf_app_id); 632 shelf_delegate_->GetShelfIDForAppID(shelf_app_id);
611 if (!shelf_id) { 633 if (!shelf_id) {
612 owner()->CreateAppLauncherItem(controller, shelf_app_id, 634 owner()->CreateAppLauncherItem(controller, shelf_app_id,
613 ash::STATUS_RUNNING); 635 ash::STATUS_RUNNING);
614 } else { 636 } else {
615 owner()->SetItemController(shelf_id, controller); 637 owner()->SetItemController(shelf_id, controller);
616 owner()->SetItemStatus(shelf_id, ash::STATUS_RUNNING); 638 owner()->SetItemStatus(shelf_id, ash::STATUS_RUNNING);
617 } 639 }
618 controller->AddTaskId(task_id); 640 controller->AddTaskId(task_id);
619 app_controller_map_[shelf_app_id] = controller; 641 app_controller_map_[shelf_app_id] = controller;
620 return controller; 642 return controller;
621 } 643 }
622 644
623 void ArcAppWindowLauncherController::RegisterApp(AppWindow* app_window) { 645 void ArcAppWindowLauncherController::RegisterApp(
624 const std::string app_id = app_window->app_id(); 646 AppWindowInfo* app_window_info) {
625 DCHECK(!app_id.empty()); 647 const std::string shelf_app_id = app_window_info->shelf_app_id();
626 648 DCHECK(!shelf_app_id.empty());
649 AppWindow* app_window = app_window_info->app_window();
627 ArcAppWindowLauncherItemController* controller = 650 ArcAppWindowLauncherItemController* controller =
628 AttachControllerToTask(app_id, app_window->task_id()); 651 AttachControllerToTask(shelf_app_id, app_window->task_id());
629 DCHECK(controller); 652 DCHECK(controller);
630 653
631 const ash::ShelfID shelf_id = shelf_delegate_->GetShelfIDForAppID(app_id); 654 const ash::ShelfID shelf_id =
655 shelf_delegate_->GetShelfIDForAppID(shelf_app_id);
632 DCHECK(shelf_id); 656 DCHECK(shelf_id);
633 657
634 controller->AddWindow(app_window); 658 controller->AddWindow(app_window);
635 owner()->SetItemStatus(shelf_id, ash::STATUS_RUNNING); 659 owner()->SetItemStatus(shelf_id, ash::STATUS_RUNNING);
636 app_window->SetController(controller); 660 app_window->SetController(controller);
637 app_window->set_shelf_id(shelf_id); 661 app_window->set_shelf_id(shelf_id);
638 } 662 }
639 663
640 void ArcAppWindowLauncherController::UnregisterApp(AppWindow* app_window, 664 void ArcAppWindowLauncherController::UnregisterApp(
641 bool close_controller) { 665 AppWindowInfo* app_window_info,
642 const std::string app_id = app_window->app_id(); 666 bool close_controller) {
643 667 AppWindow* app_window = app_window_info->app_window();
644 DCHECK(!app_id.empty()); 668 if (!app_window)
645 AppControllerMap::iterator it = app_controller_map_.find(app_id); 669 return;
670 const std::string& shelf_app_id = app_window_info->shelf_app_id();
671 DCHECK(app_window);
672 DCHECK(!shelf_app_id.empty());
673 const auto it = app_controller_map_.find(shelf_app_id);
646 CHECK(it != app_controller_map_.end()); 674 CHECK(it != app_controller_map_.end());
647 675
648 ArcAppWindowLauncherItemController* controller = it->second; 676 ArcAppWindowLauncherItemController* controller = it->second;
649 controller->RemoveWindow(app_window); 677 controller->RemoveWindow(app_window);
650 if (close_controller && !controller->window_count()) { 678 if (close_controller && !controller->window_count()) {
651 ash::ShelfID shelf_id = app_window->shelf_id(); 679 ash::ShelfID shelf_id = app_window->shelf_id();
652 owner()->CloseLauncherItem(shelf_id); 680 owner()->CloseLauncherItem(shelf_id);
653 app_controller_map_.erase(it); 681 app_controller_map_.erase(it);
654 } 682 }
655 app_window->ResetController(); 683 app_window->ResetController();
684 app_window_info->set_app_window(nullptr);
656 } 685 }
657 686
658 void ArcAppWindowLauncherController::SetOrientationLockForAppWindow( 687 void ArcAppWindowLauncherController::SetOrientationLockForAppWindow(
659 AppWindow* app_window) { 688 AppWindow* app_window) {
660 ash::WmWindow* window = 689 ash::WmWindow* window =
661 ash::WmLookup::Get()->GetWindowForWidget(app_window->widget()); 690 ash::WmLookup::Get()->GetWindowForWidget(app_window->widget());
662 if (!window) 691 if (!window)
663 return; 692 return;
693 AppWindowInfo* info = GetAppWindowInfoForTask(app_window->task_id());
664 arc::mojom::OrientationLock orientation_lock; 694 arc::mojom::OrientationLock orientation_lock;
665 if (app_window->has_requested_orientation_lock()) { 695
666 orientation_lock = app_window->requested_orientation_lock(); 696 if (info->has_requested_orientation_lock()) {
697 orientation_lock = info->requested_orientation_lock();
667 } else { 698 } else {
668 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(observed_profile_); 699 ArcAppListPrefs* prefs = ArcAppListPrefs::Get(observed_profile_);
669 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = 700 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info =
670 prefs->GetApp(app_window->app_id()); 701 prefs->GetApp(info->shelf_app_id());
671 if (!app_info) 702 if (!app_info)
672 return; 703 return;
673 orientation_lock = app_info->orientation_lock; 704 orientation_lock = app_info->orientation_lock;
674 } 705 }
675 706
676 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) { 707 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) {
677 // Resolve the orientation when it first resolved. 708 // Resolve the orientation when it first resolved.
678 orientation_lock = GetCurrentOrientation(); 709 orientation_lock = GetCurrentOrientation();
679 app_window->set_requested_orientation_lock(orientation_lock); 710 info->set_requested_orientation_lock(orientation_lock);
680 } 711 }
681
682 ash::Shell* shell = ash::Shell::GetInstance(); 712 ash::Shell* shell = ash::Shell::GetInstance();
683 shell->screen_orientation_controller()->LockOrientationForWindow( 713 shell->screen_orientation_controller()->LockOrientationForWindow(
684 window, BlinkOrientationLockFromMojom(orientation_lock)); 714 window, BlinkOrientationLockFromMojom(orientation_lock));
685 } 715 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698