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

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

Issue 2282023002: arc: Support window recreation. (Closed)
Patch Set: use SetTaskActive instead of Launch Created 4 years, 3 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 19 matching lines...) Expand all
30 #include "components/user_manager/user_manager.h" 30 #include "components/user_manager/user_manager.h"
31 #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"
32 #include "ui/aura/client/aura_constants.h" 32 #include "ui/aura/client/aura_constants.h"
33 #include "ui/aura/env.h" 33 #include "ui/aura/env.h"
34 #include "ui/base/base_window.h" 34 #include "ui/base/base_window.h"
35 #include "ui/display/display.h" 35 #include "ui/display/display.h"
36 #include "ui/views/widget/widget.h" 36 #include "ui/views/widget/widget.h"
37 37
38 namespace { 38 namespace {
39 39
40 constexpr int kAppInstanceRequiredVersion = 3;
41 constexpr char kAppInstanceConsumer[] = "ArcAppWindowLauncherController";
42
40 enum class FullScreenMode { 43 enum class FullScreenMode {
41 NOT_DEFINED, // Fullscreen mode was not defined. 44 NOT_DEFINED, // Fullscreen mode was not defined.
42 ACTIVE, // Fullscreen is activated for an app. 45 ACTIVE, // Fullscreen is activated for an app.
43 NON_ACTIVE, // Fullscreen was not activated for an app. 46 NON_ACTIVE, // Fullscreen was not activated for an app.
44 }; 47 };
45 48
46 arc::mojom::OrientationLock GetCurrentOrientation() { 49 arc::mojom::OrientationLock GetCurrentOrientation() {
47 if (!display::Display::HasInternalDisplay()) 50 if (!display::Display::HasInternalDisplay())
48 return arc::mojom::OrientationLock::NONE; 51 return arc::mojom::OrientationLock::NONE;
49 display::Display internal_display = 52 display::Display internal_display =
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 } 157 }
155 158
156 void Show() override { 159 void Show() override {
157 // TODO(khmel): support window minimizing. 160 // TODO(khmel): support window minimizing.
158 } 161 }
159 162
160 void ShowInactive() override { NOTREACHED(); } 163 void ShowInactive() override { NOTREACHED(); }
161 164
162 void Hide() override { NOTREACHED(); } 165 void Hide() override { NOTREACHED(); }
163 166
164 void Close() override { 167 void Close() override { arc::CloseTask(task_id_); }
165 arc::mojom::AppInstance* app_instance = GetAppInstance();
166 if (!app_instance)
167 return;
168 app_instance->CloseTask(task_id_);
169 }
170 168
171 void Activate() override { 169 void Activate() override { arc::SetTaskActive(task_id_); }
172 arc::mojom::AppInstance* app_instance = GetAppInstance();
173 if (!app_instance)
174 return;
175 app_instance->SetTaskActive(task_id_);
176 if (widget_)
177 widget_->Activate();
178 }
179 170
180 void Deactivate() override { NOTREACHED(); } 171 void Deactivate() override { NOTREACHED(); }
181 172
182 void Maximize() override { NOTREACHED(); } 173 void Maximize() override { NOTREACHED(); }
183 174
184 void Minimize() override { 175 void Minimize() override {
185 if (widget_) 176 if (widget_)
186 widget_->Minimize(); 177 widget_->Minimize();
187 } 178 }
188 179
(...skipping 17 matching lines...) Expand all
206 void set_requested_orientation_lock(arc::mojom::OrientationLock lock) { 197 void set_requested_orientation_lock(arc::mojom::OrientationLock lock) {
207 has_requested_orientation_lock_ = true; 198 has_requested_orientation_lock_ = true;
208 requested_orientation_lock_ = lock; 199 requested_orientation_lock_ = lock;
209 } 200 }
210 201
211 bool has_requested_orientation_lock() const { 202 bool has_requested_orientation_lock() const {
212 return has_requested_orientation_lock_; 203 return has_requested_orientation_lock_;
213 } 204 }
214 205
215 private: 206 private:
216 arc::mojom::AppInstance* GetAppInstance() {
217 arc::ArcBridgeService* bridge_service = arc::ArcBridgeService::Get();
218 arc::mojom::AppInstance* app_instance =
219 bridge_service ? bridge_service->app()->instance() : nullptr;
220 if (!app_instance) {
221 VLOG(2) << "Arc Bridge is not available.";
222 return nullptr;
223 }
224
225 if (bridge_service->app()->version() < 3) {
226 VLOG(2) << "Arc Bridge has old version for apps."
227 << bridge_service->app()->version();
228 return nullptr;
229 }
230 return app_instance;
231 }
232
233 int task_id_; 207 int task_id_;
234 ash::ShelfID shelf_id_ = 0; 208 ash::ShelfID shelf_id_ = 0;
235 std::string app_id_; 209 std::string app_id_;
236 FullScreenMode fullscreen_mode_ = FullScreenMode::NOT_DEFINED; 210 FullScreenMode fullscreen_mode_ = FullScreenMode::NOT_DEFINED;
237 // Unowned pointers 211 // Unowned pointers
238 ArcAppWindowLauncherController* owner_; 212 ArcAppWindowLauncherController* owner_;
239 ArcAppWindowLauncherItemController* controller_ = nullptr; 213 ArcAppWindowLauncherItemController* controller_ = nullptr;
240 // Unowned pointer, represents host Arc window. 214 // Unowned pointer, represents host Arc window.
241 views::Widget* widget_ = nullptr; 215 views::Widget* widget_ = nullptr;
242 216
243 arc::mojom::OrientationLock requested_orientation_lock_ = 217 arc::mojom::OrientationLock requested_orientation_lock_ =
244 arc::mojom::OrientationLock::NONE; 218 arc::mojom::OrientationLock::NONE;
245 bool has_requested_orientation_lock_ = false; 219 bool has_requested_orientation_lock_ = false;
246 220
247 DISALLOW_COPY_AND_ASSIGN(AppWindow); 221 DISALLOW_COPY_AND_ASSIGN(AppWindow);
248 }; 222 };
249 223
250 struct ArcAppWindowLauncherController::TaskInfo {
251 TaskInfo(const std::string& package_name, const std::string& activity_name)
252 : package_name(package_name), activity_name(activity_name) {}
253 ~TaskInfo() {}
254
255 std::string package_name;
256 std::string activity_name;
257 };
258
259 ArcAppWindowLauncherController::ArcAppWindowLauncherController( 224 ArcAppWindowLauncherController::ArcAppWindowLauncherController(
260 ChromeLauncherController* owner, 225 ChromeLauncherController* owner,
261 ash::ShelfDelegate* shelf_delegate) 226 ash::ShelfDelegate* shelf_delegate)
262 : AppWindowLauncherController(owner), shelf_delegate_(shelf_delegate) { 227 : AppWindowLauncherController(owner), shelf_delegate_(shelf_delegate) {
263 if (arc::ArcAuthService::IsAllowedForProfile(owner->GetProfile())) { 228 if (arc::ArcAuthService::IsAllowedForProfile(owner->GetProfile())) {
264 observed_profile_ = owner->GetProfile(); 229 observed_profile_ = owner->GetProfile();
265 StartObserving(observed_profile_); 230 StartObserving(observed_profile_);
266 } 231 }
267 } 232 }
268 233
(...skipping 22 matching lines...) Expand all
291 const std::string& user_email) { 256 const std::string& user_email) {
292 for (auto& it : task_id_to_app_window_) { 257 for (auto& it : task_id_to_app_window_) {
293 AppWindow* app_window = it.second.get(); 258 AppWindow* app_window = it.second.get();
294 if (user_email == 259 if (user_email ==
295 user_manager::UserManager::Get() 260 user_manager::UserManager::Get()
296 ->GetPrimaryUser() 261 ->GetPrimaryUser()
297 ->GetAccountId() 262 ->GetAccountId()
298 .GetUserEmail()) { 263 .GetUserEmail()) {
299 RegisterApp(app_window); 264 RegisterApp(app_window);
300 } else { 265 } else {
301 UnregisterApp(app_window); 266 UnregisterApp(app_window, true);
302 } 267 }
303 } 268 }
304 } 269 }
305 270
306 void ArcAppWindowLauncherController::AdditionalUserAddedToSession( 271 void ArcAppWindowLauncherController::AdditionalUserAddedToSession(
307 Profile* profile) { 272 Profile* profile) {
308 DCHECK(!arc::ArcAuthService::IsAllowedForProfile(profile)); 273 DCHECK(!arc::ArcAuthService::IsAllowedForProfile(profile));
309 } 274 }
310 275
311 void ArcAppWindowLauncherController::OnWindowInitialized(aura::Window* window) { 276 void ArcAppWindowLauncherController::OnWindowInitialized(aura::Window* window) {
(...skipping 12 matching lines...) Expand all
324 MayAttachContollerToWindow(window); 289 MayAttachContollerToWindow(window);
325 } 290 }
326 291
327 void ArcAppWindowLauncherController::OnWindowDestroying(aura::Window* window) { 292 void ArcAppWindowLauncherController::OnWindowDestroying(aura::Window* window) {
328 auto it = 293 auto it =
329 std::find(observed_windows_.begin(), observed_windows_.end(), window); 294 std::find(observed_windows_.begin(), observed_windows_.end(), window);
330 DCHECK(it != observed_windows_.end()); 295 DCHECK(it != observed_windows_.end());
331 observed_windows_.erase(it); 296 observed_windows_.erase(it);
332 window->RemoveObserver(this); 297 window->RemoveObserver(this);
333 298
334 for (auto& it : task_id_to_app_window_) { 299 auto it_app_window =
335 if (it.second->GetNativeWindow() == window) { 300 std::find_if(task_id_to_app_window_.begin(), task_id_to_app_window_.end(),
336 OnTaskDestroyed(it.second->task_id()); 301 [window](const TaskIdToAppWindow::value_type& pair) {
337 break; 302 return pair.second->GetNativeWindow() == window;
338 } 303 });
304 if (it_app_window != task_id_to_app_window_.end()) {
305 // Note, window may be recreated in some cases, so do not close controller
306 // on window destroying. Controller will be closed onTaskDestroyed event
307 // which is generated when actual task is destroyed.
308 UnregisterApp(it_app_window->second.get(), false);
309 task_id_to_app_window_.erase(it_app_window);
339 } 310 }
340 } 311 }
341 312
342 ArcAppWindowLauncherController::AppWindow* 313 ArcAppWindowLauncherController::AppWindow*
343 ArcAppWindowLauncherController::GetAppWindowForTask(int task_id) { 314 ArcAppWindowLauncherController::GetAppWindowForTask(int task_id) {
344 TaskIdToAppWindow::iterator it = task_id_to_app_window_.find(task_id); 315 TaskIdToAppWindow::iterator it = task_id_to_app_window_.find(task_id);
345 if (it == task_id_to_app_window_.end()) 316 if (it == task_id_to_app_window_.end())
346 return nullptr; 317 return nullptr;
347 return it->second.get(); 318 return it->second.get();
348 } 319 }
(...skipping 17 matching lines...) Expand all
366 if (!observing_shell_) { 337 if (!observing_shell_) {
367 observing_shell_ = true; 338 observing_shell_ = true;
368 ash::WmShell::Get()->AddShellObserver(this); 339 ash::WmShell::Get()->AddShellObserver(this);
369 } 340 }
370 341
371 // Check if we have controller for this task. 342 // Check if we have controller for this task.
372 if (GetAppWindowForTask(task_id)) 343 if (GetAppWindowForTask(task_id))
373 return; 344 return;
374 345
375 // Create controller if we have task info. 346 // Create controller if we have task info.
376 TaskIdToTaskInfoMap::iterator it = task_id_to_task_info_.find(task_id); 347 TaskIdToShelfAppIdMap::iterator it = task_id_to_shelf_app_id_.find(task_id);
377 if (it == task_id_to_task_info_.end()) 348 if (it == task_id_to_shelf_app_id_.end())
378 return; 349 return;
379 350
380 const TaskInfo& task_info = *it->second; 351 const std::string& app_id = it->second;
381 const std::string app_id =
382 GetShelfAppIdFromArcAppId(ArcAppListPrefs::GetAppId(
383 task_info.package_name, task_info.activity_name));
384 352
385 std::unique_ptr<AppWindow> app_window(new AppWindow(task_id, app_id, this)); 353 std::unique_ptr<AppWindow> app_window(new AppWindow(task_id, app_id, this));
386 app_window->set_widget(views::Widget::GetWidgetForNativeWindow(window)); 354 app_window->set_widget(views::Widget::GetWidgetForNativeWindow(window));
387 RegisterApp(app_window.get()); 355 RegisterApp(app_window.get());
388 DCHECK(app_window->controller()); 356 DCHECK(app_window->controller());
389 ash::SetShelfIDForWindow(app_window->shelf_id(), window); 357 ash::SetShelfIDForWindow(app_window->shelf_id(), window);
390 chrome::MultiUserWindowManager::GetInstance()->SetWindowOwner( 358 chrome::MultiUserWindowManager::GetInstance()->SetWindowOwner(
391 window, 359 window,
392 user_manager::UserManager::Get()->GetPrimaryUser()->GetAccountId()); 360 user_manager::UserManager::Get()->GetPrimaryUser()->GetAccountId());
393 if (ash::WmShell::Get() 361 if (ash::WmShell::Get()
394 ->maximize_mode_controller() 362 ->maximize_mode_controller()
395 ->IsMaximizeModeWindowManagerEnabled()) { 363 ->IsMaximizeModeWindowManagerEnabled()) {
396 SetOrientationLockForAppWindow(app_window.get()); 364 SetOrientationLockForAppWindow(app_window.get());
397 } 365 }
398 task_id_to_app_window_[task_id] = std::move(app_window); 366 task_id_to_app_window_[task_id] = std::move(app_window);
399
400 // TaskInfo is no longer needed. Discard it.
401 task_id_to_task_info_.erase(task_id);
402 } 367 }
403 368
404 void ArcAppWindowLauncherController::OnAppReadyChanged( 369 void ArcAppWindowLauncherController::OnAppReadyChanged(
405 const std::string& app_id, 370 const std::string& app_id,
406 bool ready) { 371 bool ready) {
407 if (!ready) 372 if (!ready)
408 OnAppRemoved(app_id); 373 OnAppRemoved(app_id);
409 } 374 }
410 375
411 void ArcAppWindowLauncherController::OnAppRemoved(const std::string& app_id) { 376 void ArcAppWindowLauncherController::OnAppRemoved(const std::string& app_id) {
(...skipping 15 matching lines...) Expand all
427 OnTaskDestroyed(task_id); 392 OnTaskDestroyed(task_id);
428 393
429 DCHECK(app_controller_map_.find(shelf_app_id) == app_controller_map_.end()); 394 DCHECK(app_controller_map_.find(shelf_app_id) == app_controller_map_.end());
430 } 395 }
431 396
432 void ArcAppWindowLauncherController::OnTaskCreated( 397 void ArcAppWindowLauncherController::OnTaskCreated(
433 int task_id, 398 int task_id,
434 const std::string& package_name, 399 const std::string& package_name,
435 const std::string& activity_name) { 400 const std::string& activity_name) {
436 DCHECK(!GetAppWindowForTask(task_id)); 401 DCHECK(!GetAppWindowForTask(task_id));
437 std::unique_ptr<TaskInfo> task_info( 402 task_id_to_shelf_app_id_[task_id] = GetShelfAppIdFromArcAppId(
438 new TaskInfo(package_name, activity_name)); 403 ArcAppListPrefs::GetAppId(package_name, activity_name));
439 task_id_to_task_info_[task_id] = std::move(task_info);
440 404
441 for (auto* window : observed_windows_) 405 for (auto* window : observed_windows_)
442 MayAttachContollerToWindow(window); 406 MayAttachContollerToWindow(window);
443 } 407 }
444 408
445 void ArcAppWindowLauncherController::OnTaskDestroyed(int task_id) { 409 void ArcAppWindowLauncherController::OnTaskDestroyed(int task_id) {
446 task_id_to_task_info_.erase(task_id); 410 auto it = task_id_to_app_window_.find(task_id);
411 if (it != task_id_to_app_window_.end()) {
412 AppWindow* app_window = it->second.get();
413 UnregisterApp(app_window, true);
414 task_id_to_app_window_.erase(it);
415 }
447 416
448 TaskIdToAppWindow::iterator it = task_id_to_app_window_.find(task_id); 417 // Check if we may close controller now, at this point we can safely remove
449 if (it == task_id_to_app_window_.end()) 418 // controllers without window.
419 auto it_app_id = task_id_to_shelf_app_id_.find(task_id);
420 if (it_app_id == task_id_to_shelf_app_id_.end())
450 return; 421 return;
451 422
452 AppWindow* app_window = it->second.get(); 423 const std::string& app_id = it_app_id->second;
453 UnregisterApp(app_window); 424 AppControllerMap::iterator it_controller = app_controller_map_.find(app_id);
425 if (it_controller != app_controller_map_.end()) {
426 ArcAppWindowLauncherItemController* controller = it_controller->second;
427 controller->RemoveTaskId(task_id);
428 if (!controller->window_count()) {
429 owner()->CloseLauncherItem(controller->shelf_id());
430 app_controller_map_.erase(it_controller);
431 }
432 }
454 433
455 task_id_to_app_window_.erase(it); 434 task_id_to_shelf_app_id_.erase(it_app_id);
456 } 435 }
457 436
458 void ArcAppWindowLauncherController::OnTaskSetActive(int32_t task_id) { 437 void ArcAppWindowLauncherController::OnTaskSetActive(int32_t task_id) {
459 if (observed_profile_ != owner()->GetProfile()) 438 if (observed_profile_ != owner()->GetProfile())
460 return; 439 return;
461 440
462 TaskIdToAppWindow::iterator previous_active_app_it = 441 TaskIdToAppWindow::iterator previous_active_app_it =
463 task_id_to_app_window_.find(active_task_id_); 442 task_id_to_app_window_.find(active_task_id_);
464 if (previous_active_app_it != task_id_to_app_window_.end()) { 443 if (previous_active_app_it != task_id_to_app_window_.end()) {
465 owner()->SetItemStatus(previous_active_app_it->second->shelf_id(), 444 owner()->SetItemStatus(previous_active_app_it->second->shelf_id(),
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 if (shelf_id == 0) { 559 if (shelf_id == 0) {
581 // Map Play Store shelf icon to Arc Support host, to share one entry. 560 // Map Play Store shelf icon to Arc Support host, to share one entry.
582 shelf_id = owner()->CreateAppLauncherItem(controller, app_id, 561 shelf_id = owner()->CreateAppLauncherItem(controller, app_id,
583 ash::STATUS_RUNNING); 562 ash::STATUS_RUNNING);
584 } else { 563 } else {
585 owner()->SetItemController(shelf_id, controller); 564 owner()->SetItemController(shelf_id, controller);
586 } 565 }
587 app_controller_map_[app_id] = controller; 566 app_controller_map_[app_id] = controller;
588 } 567 }
589 controller->AddWindow(app_window); 568 controller->AddWindow(app_window);
569 controller->AddTaskId(app_window->task_id());
590 owner()->SetItemStatus(shelf_id, ash::STATUS_RUNNING); 570 owner()->SetItemStatus(shelf_id, ash::STATUS_RUNNING);
591 app_window->SetController(controller); 571 app_window->SetController(controller);
592 app_window->set_shelf_id(shelf_id); 572 app_window->set_shelf_id(shelf_id);
593 } 573 }
594 574
595 void ArcAppWindowLauncherController::UnregisterApp(AppWindow* app_window) { 575 void ArcAppWindowLauncherController::UnregisterApp(AppWindow* app_window,
576 bool close_controller) {
596 const std::string app_id = app_window->app_id(); 577 const std::string app_id = app_window->app_id();
597 DCHECK(!app_id.empty()); 578 DCHECK(!app_id.empty());
598 AppControllerMap::iterator it = app_controller_map_.find(app_id); 579 AppControllerMap::iterator it = app_controller_map_.find(app_id);
599 DCHECK(it != app_controller_map_.end()); 580 DCHECK(it != app_controller_map_.end());
600 581
601 ArcAppWindowLauncherItemController* controller = it->second; 582 ArcAppWindowLauncherItemController* controller = it->second;
602 controller->RemoveWindow(app_window); 583 controller->RemoveWindow(app_window);
603 if (!controller->window_count()) { 584 if (close_controller && !controller->window_count()) {
604 ash::ShelfID shelf_id = app_window->shelf_id(); 585 ash::ShelfID shelf_id = app_window->shelf_id();
605 owner()->CloseLauncherItem(shelf_id); 586 owner()->CloseLauncherItem(shelf_id);
606 app_controller_map_.erase(it); 587 app_controller_map_.erase(it);
607 } 588 }
608 app_window->ResetController(); 589 app_window->ResetController();
609 } 590 }
610 591
611 void ArcAppWindowLauncherController::SetOrientationLockForAppWindow( 592 void ArcAppWindowLauncherController::SetOrientationLockForAppWindow(
612 AppWindow* app_window) { 593 AppWindow* app_window) {
613 ash::WmWindow* window = 594 ash::WmWindow* window =
(...skipping 15 matching lines...) Expand all
629 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) { 610 if (orientation_lock == arc::mojom::OrientationLock::CURRENT) {
630 // Resolve the orientation when it first resolved. 611 // Resolve the orientation when it first resolved.
631 orientation_lock = GetCurrentOrientation(); 612 orientation_lock = GetCurrentOrientation();
632 app_window->set_requested_orientation_lock(orientation_lock); 613 app_window->set_requested_orientation_lock(orientation_lock);
633 } 614 }
634 615
635 ash::Shell* shell = ash::Shell::GetInstance(); 616 ash::Shell* shell = ash::Shell::GetInstance();
636 shell->screen_orientation_controller()->LockOrientationForWindow( 617 shell->screen_orientation_controller()->LockOrientationForWindow(
637 window, BlinkOrientationLockFromMojom(orientation_lock)); 618 window, BlinkOrientationLockFromMojom(orientation_lock));
638 } 619 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698