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