OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h" | 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "ash/common/multi_profile_uma.h" | 11 #include "ash/common/multi_profile_uma.h" |
12 #include "ash/common/shelf/shelf_model.h" | 12 #include "ash/common/shelf/shelf_model.h" |
13 #include "ash/common/shelf/shelf_widget.h" | |
14 #include "ash/common/shelf/wm_shelf.h" | 13 #include "ash/common/shelf/wm_shelf.h" |
15 #include "ash/common/system/tray/system_tray_delegate.h" | 14 #include "ash/common/system/tray/system_tray_delegate.h" |
16 #include "ash/common/wm_shell.h" | 15 #include "ash/common/wm_shell.h" |
17 #include "ash/common/wm_window.h" | 16 #include "ash/common/wm_window.h" |
18 #include "ash/resources/grit/ash_resources.h" | 17 #include "ash/resources/grit/ash_resources.h" |
19 #include "ash/root_window_controller.h" | 18 #include "ash/root_window_controller.h" |
20 #include "ash/shell.h" | 19 #include "ash/shell.h" |
21 #include "ash/wm/window_util.h" | 20 #include "ash/wm/window_util.h" |
22 #include "base/command_line.h" | 21 #include "base/command_line.h" |
23 #include "base/macros.h" | 22 #include "base/macros.h" |
24 #include "base/strings/pattern.h" | 23 #include "base/strings/pattern.h" |
25 #include "base/strings/string_util.h" | 24 #include "base/strings/string_util.h" |
26 #include "base/strings/utf_string_conversions.h" | 25 #include "base/strings/utf_string_conversions.h" |
27 #include "base/threading/thread_task_runner_handle.h" | 26 #include "base/threading/thread_task_runner_handle.h" |
28 #include "base/values.h" | 27 #include "base/values.h" |
29 #include "build/build_config.h" | 28 #include "build/build_config.h" |
30 #include "chrome/browser/browser_process.h" | 29 #include "chrome/browser/browser_process.h" |
31 #include "chrome/browser/chrome_notification_types.h" | 30 #include "chrome/browser/chrome_notification_types.h" |
32 #include "chrome/browser/chromeos/extensions/gfx_utils.h" | 31 #include "chrome/browser/chromeos/extensions/gfx_utils.h" |
33 #include "chrome/browser/defaults.h" | 32 #include "chrome/browser/defaults.h" |
34 #include "chrome/browser/extensions/extension_app_icon_loader.h" | |
35 #include "chrome/browser/extensions/extension_util.h" | 33 #include "chrome/browser/extensions/extension_util.h" |
36 #include "chrome/browser/extensions/launch_util.h" | 34 #include "chrome/browser/extensions/launch_util.h" |
37 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 35 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
38 #include "chrome/browser/profiles/profile.h" | 36 #include "chrome/browser/profiles/profile.h" |
39 #include "chrome/browser/profiles/profile_manager.h" | 37 #include "chrome/browser/profiles/profile_manager.h" |
40 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" | 38 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" |
41 #include "chrome/browser/ui/app_list/arc/arc_app_icon_loader.h" | |
42 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" | 39 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" |
43 #include "chrome/browser/ui/ash/app_sync_ui_state.h" | 40 #include "chrome/browser/ui/ash/app_sync_ui_state.h" |
44 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" | 41 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" |
45 #include "chrome/browser/ui/ash/chrome_shell_delegate.h" | 42 #include "chrome/browser/ui/ash/chrome_shell_delegate.h" |
46 #include "chrome/browser/ui/ash/launcher/app_shortcut_launcher_item_controller.h
" | 43 #include "chrome/browser/ui/ash/launcher/app_shortcut_launcher_item_controller.h
" |
47 #include "chrome/browser/ui/ash/launcher/app_window_launcher_controller.h" | 44 #include "chrome/browser/ui/ash/launcher/app_window_launcher_controller.h" |
48 #include "chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.h" | 45 #include "chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.h" |
49 #include "chrome/browser/ui/ash/launcher/arc_app_deferred_launcher_controller.h" | 46 #include "chrome/browser/ui/ash/launcher/arc_app_deferred_launcher_controller.h" |
50 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h" | 47 #include "chrome/browser/ui/ash/launcher/arc_app_window_launcher_controller.h" |
51 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll
er.h" | 48 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll
er.h" |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 void ChromeLauncherControllerUserSwitchObserver::AddUser(Profile* profile) { | 178 void ChromeLauncherControllerUserSwitchObserver::AddUser(Profile* profile) { |
182 if (chrome::MultiUserWindowManager::GetMultiProfileMode() == | 179 if (chrome::MultiUserWindowManager::GetMultiProfileMode() == |
183 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED) | 180 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED) |
184 chrome::MultiUserWindowManager::GetInstance()->AddUser(profile); | 181 chrome::MultiUserWindowManager::GetInstance()->AddUser(profile); |
185 controller_->AdditionalUserAddedToSession(profile->GetOriginalProfile()); | 182 controller_->AdditionalUserAddedToSession(profile->GetOriginalProfile()); |
186 } | 183 } |
187 | 184 |
188 ChromeLauncherControllerImpl::ChromeLauncherControllerImpl( | 185 ChromeLauncherControllerImpl::ChromeLauncherControllerImpl( |
189 Profile* profile, | 186 Profile* profile, |
190 ash::ShelfModel* model) | 187 ash::ShelfModel* model) |
191 : model_(model), profile_(profile), weak_ptr_factory_(this) { | 188 : model_(model), weak_ptr_factory_(this) { |
192 DCHECK(model_); | 189 DCHECK(model_); |
193 if (!profile_) { | 190 if (!profile) { |
194 // If no profile was passed, we take the currently active profile and use it | 191 // If no profile was passed, we take the currently active profile and use it |
195 // as the owner of the current desktop. | 192 // as the owner of the current desktop. |
196 // Use the original profile as on chromeos we may get a temporary off the | 193 // Use the original profile as on chromeos we may get a temporary off the |
197 // record profile, unless in guest session (where off the record profile is | 194 // record profile, unless in guest session (where off the record profile is |
198 // the right one). | 195 // the right one). |
199 profile_ = ProfileManager::GetActiveUserProfile(); | 196 profile = ProfileManager::GetActiveUserProfile(); |
200 if (!profile_->IsGuestSession() && !profile_->IsSystemProfile()) | 197 if (!profile->IsGuestSession() && !profile->IsSystemProfile()) |
201 profile_ = profile_->GetOriginalProfile(); | 198 profile = profile->GetOriginalProfile(); |
202 | 199 |
203 app_sync_ui_state_ = AppSyncUIState::Get(profile_); | 200 app_sync_ui_state_ = AppSyncUIState::Get(profile); |
204 if (app_sync_ui_state_) | 201 if (app_sync_ui_state_) |
205 app_sync_ui_state_->AddObserver(this); | 202 app_sync_ui_state_->AddObserver(this); |
206 } | 203 } |
207 | 204 |
208 if (arc::ArcAuthService::IsAllowedForProfile(profile_)) { | 205 // All profile relevant settings get bound to the current profile. |
| 206 AttachProfile(profile); |
| 207 model_->AddObserver(this); |
| 208 |
| 209 if (arc::ArcAuthService::IsAllowedForProfile(this->profile())) |
209 arc_deferred_launcher_.reset(new ArcAppDeferredLauncherController(this)); | 210 arc_deferred_launcher_.reset(new ArcAppDeferredLauncherController(this)); |
210 } | |
211 | |
212 // All profile relevant settings get bound to the current profile. | |
213 AttachProfile(profile_); | |
214 model_->AddObserver(this); | |
215 | 211 |
216 // In multi profile mode we might have a window manager. We try to create it | 212 // In multi profile mode we might have a window manager. We try to create it |
217 // here. If the instantiation fails, the manager is not needed. | 213 // here. If the instantiation fails, the manager is not needed. |
218 chrome::MultiUserWindowManager::CreateInstance(); | 214 chrome::MultiUserWindowManager::CreateInstance(); |
219 | 215 |
220 // On Chrome OS using multi profile we want to switch the content of the shelf | 216 // On Chrome OS using multi profile we want to switch the content of the shelf |
221 // with a user change. Note that for unit tests the instance can be NULL. | 217 // with a user change. Note that for unit tests the instance can be NULL. |
222 if (chrome::MultiUserWindowManager::GetMultiProfileMode() != | 218 if (chrome::MultiUserWindowManager::GetMultiProfileMode() != |
223 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_OFF) { | 219 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_OFF) { |
224 user_switch_observer_.reset( | 220 user_switch_observer_.reset( |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 model_->RemoveItemAt(index); | 271 model_->RemoveItemAt(index); |
276 } | 272 } |
277 | 273 |
278 // Release all profile dependent resources. | 274 // Release all profile dependent resources. |
279 ReleaseProfile(); | 275 ReleaseProfile(); |
280 | 276 |
281 // Get rid of the multi user window manager instance. | 277 // Get rid of the multi user window manager instance. |
282 chrome::MultiUserWindowManager::DeleteInstance(); | 278 chrome::MultiUserWindowManager::DeleteInstance(); |
283 } | 279 } |
284 | 280 |
285 // static | |
286 ChromeLauncherControllerImpl* ChromeLauncherControllerImpl::CreateInstance( | |
287 Profile* profile, | |
288 ash::ShelfModel* model) { | |
289 // We do not check here for re-creation of the ChromeLauncherControllerImpl | |
290 // since it appears that it might be intentional that | |
291 // ChromeLauncherControllerImpl can be re-created. | |
292 ChromeLauncherControllerImpl* instance = | |
293 new ChromeLauncherControllerImpl(profile, model); | |
294 ChromeLauncherController::set_instance(instance); | |
295 return instance; | |
296 } | |
297 | |
298 void ChromeLauncherControllerImpl::Init() { | 281 void ChromeLauncherControllerImpl::Init() { |
299 CreateBrowserShortcutLauncherItem(); | 282 CreateBrowserShortcutLauncherItem(); |
300 UpdateAppLaunchersFromPref(); | 283 UpdateAppLaunchersFromPref(); |
301 | 284 |
302 // TODO(sky): update unit test so that this test isn't necessary. | 285 // TODO(sky): update unit test so that this test isn't necessary. |
303 if (ash::Shell::HasInstance()) | 286 if (ash::Shell::HasInstance()) |
304 SetVirtualKeyboardBehaviorFromPrefs(); | 287 SetVirtualKeyboardBehaviorFromPrefs(); |
305 | 288 |
306 prefs_observer_ = | 289 prefs_observer_ = |
307 ash::launcher::ChromeLauncherPrefsObserver::CreateIfNecessary(profile_); | 290 ash::launcher::ChromeLauncherPrefsObserver::CreateIfNecessary(profile()); |
308 } | 291 } |
309 | 292 |
310 ash::ShelfID ChromeLauncherControllerImpl::CreateAppLauncherItem( | 293 ash::ShelfID ChromeLauncherControllerImpl::CreateAppLauncherItem( |
311 LauncherItemController* controller, | 294 LauncherItemController* controller, |
312 const std::string& app_id, | 295 const std::string& app_id, |
313 ash::ShelfItemStatus status) { | 296 ash::ShelfItemStatus status) { |
314 CHECK(controller); | 297 CHECK(controller); |
315 int index = 0; | 298 int index = 0; |
316 // Panels are inserted on the left so as not to push all existing panels over. | 299 // Panels are inserted on the left so as not to push all existing panels over. |
317 if (controller->GetShelfItemType() != ash::TYPE_APP_PANEL) | 300 if (controller->GetShelfItemType() != ash::TYPE_APP_PANEL) |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 void ChromeLauncherControllerImpl::Unpin(ash::ShelfID id) { | 369 void ChromeLauncherControllerImpl::Unpin(ash::ShelfID id) { |
387 UnpinAndUpdatePrefs(id, true /* update_prefs */); | 370 UnpinAndUpdatePrefs(id, true /* update_prefs */); |
388 } | 371 } |
389 | 372 |
390 void ChromeLauncherControllerImpl::UnpinAndUpdatePrefs(ash::ShelfID id, | 373 void ChromeLauncherControllerImpl::UnpinAndUpdatePrefs(ash::ShelfID id, |
391 bool update_prefs) { | 374 bool update_prefs) { |
392 LauncherItemController* controller = GetLauncherItemController(id); | 375 LauncherItemController* controller = GetLauncherItemController(id); |
393 CHECK(controller); | 376 CHECK(controller); |
394 | 377 |
395 if (update_prefs) | 378 if (update_prefs) |
396 ash::launcher::RemovePinPosition(profile_, GetAppIDForShelfID(id)); | 379 ash::launcher::RemovePinPosition(profile(), GetAppIDForShelfID(id)); |
397 | 380 |
398 if (controller->type() == LauncherItemController::TYPE_APP || | 381 if (controller->type() == LauncherItemController::TYPE_APP || |
399 controller->locked()) { | 382 controller->locked()) { |
400 UnpinRunningAppInternal(model_->ItemIndexByID(id)); | 383 UnpinRunningAppInternal(model_->ItemIndexByID(id)); |
401 } else { | 384 } else { |
402 LauncherItemClosed(id); | 385 LauncherItemClosed(id); |
403 } | 386 } |
404 } | 387 } |
405 | 388 |
406 bool ChromeLauncherControllerImpl::IsPinned(ash::ShelfID id) { | 389 bool ChromeLauncherControllerImpl::IsPinned(ash::ShelfID id) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 if (!controller) | 457 if (!controller) |
475 return false; | 458 return false; |
476 return controller->IsOpen(); | 459 return controller->IsOpen(); |
477 } | 460 } |
478 | 461 |
479 bool ChromeLauncherControllerImpl::IsPlatformApp(ash::ShelfID id) { | 462 bool ChromeLauncherControllerImpl::IsPlatformApp(ash::ShelfID id) { |
480 if (!HasShelfIDToAppIDMapping(id)) | 463 if (!HasShelfIDToAppIDMapping(id)) |
481 return false; | 464 return false; |
482 | 465 |
483 std::string app_id = GetAppIDForShelfID(id); | 466 std::string app_id = GetAppIDForShelfID(id); |
484 const Extension* extension = GetExtensionForAppID(app_id, profile_); | 467 const Extension* extension = GetExtensionForAppID(app_id, profile()); |
485 // An extension can be synced / updated at any time and therefore not be | 468 // An extension can be synced / updated at any time and therefore not be |
486 // available. | 469 // available. |
487 return extension ? extension->is_platform_app() : false; | 470 return extension ? extension->is_platform_app() : false; |
488 } | 471 } |
489 | 472 |
490 void ChromeLauncherControllerImpl::LaunchApp(const std::string& app_id, | |
491 ash::LaunchSource source, | |
492 int event_flags) { | |
493 launcher_controller_helper_->LaunchApp(app_id, source, event_flags); | |
494 } | |
495 | |
496 void ChromeLauncherControllerImpl::ActivateApp(const std::string& app_id, | 473 void ChromeLauncherControllerImpl::ActivateApp(const std::string& app_id, |
497 ash::LaunchSource source, | 474 ash::LaunchSource source, |
498 int event_flags) { | 475 int event_flags) { |
499 // If there is an existing non-shortcut controller for this app, open it. | 476 // If there is an existing non-shortcut controller for this app, open it. |
500 ash::ShelfID id = GetShelfIDForAppID(app_id); | 477 ash::ShelfID id = GetShelfIDForAppID(app_id); |
501 if (id) { | 478 if (id) { |
502 LauncherItemController* controller = GetLauncherItemController(id); | 479 LauncherItemController* controller = GetLauncherItemController(id); |
503 controller->Activate(source); | 480 controller->Activate(source); |
504 return; | 481 return; |
505 } | 482 } |
506 | 483 |
507 // Create a temporary application launcher item and use it to see if there are | 484 // Create a temporary application launcher item and use it to see if there are |
508 // running instances. | 485 // running instances. |
509 std::unique_ptr<AppShortcutLauncherItemController> app_controller( | 486 std::unique_ptr<AppShortcutLauncherItemController> app_controller( |
510 AppShortcutLauncherItemController::Create(app_id, "", this)); | 487 AppShortcutLauncherItemController::Create(app_id, "", this)); |
511 if (!app_controller->GetRunningApplications().empty()) | 488 if (!app_controller->GetRunningApplications().empty()) |
512 app_controller->Activate(source); | 489 app_controller->Activate(source); |
513 else | 490 else |
514 LaunchApp(app_id, source, event_flags); | 491 LaunchApp(app_id, source, event_flags); |
515 } | 492 } |
516 | 493 |
517 extensions::LaunchType ChromeLauncherControllerImpl::GetLaunchType( | 494 extensions::LaunchType ChromeLauncherControllerImpl::GetLaunchType( |
518 ash::ShelfID id) { | 495 ash::ShelfID id) { |
519 const Extension* extension = | 496 const Extension* extension = |
520 GetExtensionForAppID(GetAppIDForShelfID(id), profile_); | 497 GetExtensionForAppID(GetAppIDForShelfID(id), profile()); |
521 | 498 |
522 // An extension can be unloaded/updated/unavailable at any time. | 499 // An extension can be unloaded/updated/unavailable at any time. |
523 if (!extension) | 500 if (!extension) |
524 return extensions::LAUNCH_TYPE_DEFAULT; | 501 return extensions::LAUNCH_TYPE_DEFAULT; |
525 | 502 |
526 return extensions::GetLaunchType(extensions::ExtensionPrefs::Get(profile_), | 503 return extensions::GetLaunchType(extensions::ExtensionPrefs::Get(profile()), |
527 extension); | 504 extension); |
528 } | 505 } |
529 | 506 |
530 void ChromeLauncherControllerImpl::SetLauncherItemImage( | 507 void ChromeLauncherControllerImpl::SetLauncherItemImage( |
531 ash::ShelfID shelf_id, | 508 ash::ShelfID shelf_id, |
532 const gfx::ImageSkia& image) { | 509 const gfx::ImageSkia& image) { |
533 int index = model_->ItemIndexByID(shelf_id); | 510 int index = model_->ItemIndexByID(shelf_id); |
534 if (index == -1) | 511 if (index == -1) |
535 return; | 512 return; |
536 ash::ShelfItem item = model_->items()[index]; | 513 ash::ShelfItem item = model_->items()[index]; |
(...skipping 11 matching lines...) Expand all Loading... |
548 return type == ash::TYPE_WINDOWED_APP; | 525 return type == ash::TYPE_WINDOWED_APP; |
549 } | 526 } |
550 | 527 |
551 void ChromeLauncherControllerImpl::SetLaunchType( | 528 void ChromeLauncherControllerImpl::SetLaunchType( |
552 ash::ShelfID id, | 529 ash::ShelfID id, |
553 extensions::LaunchType launch_type) { | 530 extensions::LaunchType launch_type) { |
554 LauncherItemController* controller = GetLauncherItemController(id); | 531 LauncherItemController* controller = GetLauncherItemController(id); |
555 if (!controller) | 532 if (!controller) |
556 return; | 533 return; |
557 | 534 |
558 extensions::SetLaunchType(profile_, controller->app_id(), launch_type); | 535 extensions::SetLaunchType(profile(), controller->app_id(), launch_type); |
559 } | |
560 | |
561 Profile* ChromeLauncherControllerImpl::GetProfile() { | |
562 return profile_; | |
563 } | 536 } |
564 | 537 |
565 void ChromeLauncherControllerImpl::UpdateAppState( | 538 void ChromeLauncherControllerImpl::UpdateAppState( |
566 content::WebContents* contents, | 539 content::WebContents* contents, |
567 AppState app_state) { | 540 AppState app_state) { |
568 std::string app_id = launcher_controller_helper_->GetAppID(contents); | 541 std::string app_id = launcher_controller_helper()->GetAppID(contents); |
569 | 542 |
570 // Check if the gMail app is loaded and it matches the given content. | 543 // Check if the gMail app is loaded and it matches the given content. |
571 // This special treatment is needed to address crbug.com/234268. | 544 // This special treatment is needed to address crbug.com/234268. |
572 if (app_id.empty() && ContentCanBeHandledByGmailApp(contents)) | 545 if (app_id.empty() && ContentCanBeHandledByGmailApp(contents)) |
573 app_id = kGmailAppId; | 546 app_id = kGmailAppId; |
574 | 547 |
575 // Check the old |app_id| for a tab. If the contents has changed we need to | 548 // Check the old |app_id| for a tab. If the contents has changed we need to |
576 // remove it from the previous app. | 549 // remove it from the previous app. |
577 if (web_contents_to_app_id_.find(contents) != web_contents_to_app_id_.end()) { | 550 if (web_contents_to_app_id_.find(contents) != web_contents_to_app_id_.end()) { |
578 std::string last_app_id = web_contents_to_app_id_[contents]; | 551 std::string last_app_id = web_contents_to_app_id_[contents]; |
(...skipping 19 matching lines...) Expand all Loading... |
598 app_state == APP_STATE_ACTIVE) | 571 app_state == APP_STATE_ACTIVE) |
599 ? ash::STATUS_ACTIVE | 572 ? ash::STATUS_ACTIVE |
600 : GetAppState(app_id)); | 573 : GetAppState(app_id)); |
601 } | 574 } |
602 } | 575 } |
603 | 576 |
604 ash::ShelfID ChromeLauncherControllerImpl::GetShelfIDForWebContents( | 577 ash::ShelfID ChromeLauncherControllerImpl::GetShelfIDForWebContents( |
605 content::WebContents* contents) { | 578 content::WebContents* contents) { |
606 DCHECK(contents); | 579 DCHECK(contents); |
607 | 580 |
608 std::string app_id = launcher_controller_helper_->GetAppID(contents); | 581 std::string app_id = launcher_controller_helper()->GetAppID(contents); |
609 | 582 |
610 if (app_id.empty() && ContentCanBeHandledByGmailApp(contents)) | 583 if (app_id.empty() && ContentCanBeHandledByGmailApp(contents)) |
611 app_id = kGmailAppId; | 584 app_id = kGmailAppId; |
612 | 585 |
613 ash::ShelfID id = GetShelfIDForAppID(app_id); | 586 ash::ShelfID id = GetShelfIDForAppID(app_id); |
614 | 587 |
615 if (app_id.empty() || !id) { | 588 if (app_id.empty() || !id) { |
616 int browser_index = model_->GetItemIndexForType(ash::TYPE_BROWSER_SHORTCUT); | 589 int browser_index = model_->GetItemIndexForType(ash::TYPE_BROWSER_SHORTCUT); |
617 return model_->items()[browser_index].id; | 590 return model_->items()[browser_index].id; |
618 } | 591 } |
(...skipping 26 matching lines...) Expand all Loading... |
645 ash::ShelfItemDelegate::PerformedAction | 618 ash::ShelfItemDelegate::PerformedAction |
646 ChromeLauncherControllerImpl::ActivateWindowOrMinimizeIfActive( | 619 ChromeLauncherControllerImpl::ActivateWindowOrMinimizeIfActive( |
647 ui::BaseWindow* window, | 620 ui::BaseWindow* window, |
648 bool allow_minimize) { | 621 bool allow_minimize) { |
649 // In separated desktop mode we might have to teleport a window back to the | 622 // In separated desktop mode we might have to teleport a window back to the |
650 // current user. | 623 // current user. |
651 if (chrome::MultiUserWindowManager::GetMultiProfileMode() == | 624 if (chrome::MultiUserWindowManager::GetMultiProfileMode() == |
652 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED) { | 625 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED) { |
653 aura::Window* native_window = window->GetNativeWindow(); | 626 aura::Window* native_window = window->GetNativeWindow(); |
654 const AccountId& current_account_id = | 627 const AccountId& current_account_id = |
655 multi_user_util::GetAccountIdFromProfile(GetProfile()); | 628 multi_user_util::GetAccountIdFromProfile(profile()); |
656 chrome::MultiUserWindowManager* manager = | 629 chrome::MultiUserWindowManager* manager = |
657 chrome::MultiUserWindowManager::GetInstance(); | 630 chrome::MultiUserWindowManager::GetInstance(); |
658 if (!manager->IsWindowOnDesktopOfUser(native_window, current_account_id)) { | 631 if (!manager->IsWindowOnDesktopOfUser(native_window, current_account_id)) { |
659 ash::MultiProfileUMA::RecordTeleportAction( | 632 ash::MultiProfileUMA::RecordTeleportAction( |
660 ash::MultiProfileUMA::TELEPORT_WINDOW_RETURN_BY_LAUNCHER); | 633 ash::MultiProfileUMA::TELEPORT_WINDOW_RETURN_BY_LAUNCHER); |
661 manager->ShowWindowForUser(native_window, current_account_id); | 634 manager->ShowWindowForUser(native_window, current_account_id); |
662 window->Activate(); | 635 window->Activate(); |
663 return ash::ShelfItemDelegate::kExistingWindowActivated; | 636 return ash::ShelfItemDelegate::kExistingWindowActivated; |
664 } | 637 } |
665 } | 638 } |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 bool ChromeLauncherControllerImpl::ContentCanBeHandledByGmailApp( | 737 bool ChromeLauncherControllerImpl::ContentCanBeHandledByGmailApp( |
765 content::WebContents* web_contents) { | 738 content::WebContents* web_contents) { |
766 ash::ShelfID id = GetShelfIDForAppID(kGmailAppId); | 739 ash::ShelfID id = GetShelfIDForAppID(kGmailAppId); |
767 if (id) { | 740 if (id) { |
768 const GURL url = web_contents->GetURL(); | 741 const GURL url = web_contents->GetURL(); |
769 // We need to extend the application matching for the gMail app beyond the | 742 // We need to extend the application matching for the gMail app beyond the |
770 // manifest file's specification. This is required because of the namespace | 743 // manifest file's specification. This is required because of the namespace |
771 // overlap with the offline app ("/mail/mu/"). | 744 // overlap with the offline app ("/mail/mu/"). |
772 if (!base::MatchPattern(url.path(), "/mail/mu/*") && | 745 if (!base::MatchPattern(url.path(), "/mail/mu/*") && |
773 base::MatchPattern(url.path(), "/mail/*") && | 746 base::MatchPattern(url.path(), "/mail/*") && |
774 GetExtensionForAppID(kGmailAppId, profile_) && | 747 GetExtensionForAppID(kGmailAppId, profile()) && |
775 GetExtensionForAppID(kGmailAppId, profile_)->OverlapsWithOrigin(url)) | 748 GetExtensionForAppID(kGmailAppId, profile())->OverlapsWithOrigin(url)) |
776 return true; | 749 return true; |
777 } | 750 } |
778 return false; | 751 return false; |
779 } | 752 } |
780 | 753 |
781 gfx::Image ChromeLauncherControllerImpl::GetAppListIcon( | 754 gfx::Image ChromeLauncherControllerImpl::GetAppListIcon( |
782 content::WebContents* web_contents) const { | 755 content::WebContents* web_contents) const { |
783 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 756 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
784 if (IsIncognito(web_contents)) | 757 if (IsIncognito(web_contents)) |
785 return rb.GetImageNamed(IDR_ASH_SHELF_LIST_INCOGNITO_BROWSER); | 758 return rb.GetImageNamed(IDR_ASH_SHELF_LIST_INCOGNITO_BROWSER); |
786 favicon::FaviconDriver* favicon_driver = | 759 favicon::FaviconDriver* favicon_driver = |
787 favicon::ContentFaviconDriver::FromWebContents(web_contents); | 760 favicon::ContentFaviconDriver::FromWebContents(web_contents); |
788 gfx::Image result = favicon_driver->GetFavicon(); | 761 gfx::Image result = favicon_driver->GetFavicon(); |
789 if (result.IsEmpty()) | 762 if (result.IsEmpty()) |
790 return rb.GetImageNamed(IDR_DEFAULT_FAVICON); | 763 return rb.GetImageNamed(IDR_DEFAULT_FAVICON); |
791 return result; | 764 return result; |
792 } | 765 } |
793 | 766 |
794 base::string16 ChromeLauncherControllerImpl::GetAppListTitle( | 767 base::string16 ChromeLauncherControllerImpl::GetAppListTitle( |
795 content::WebContents* web_contents) const { | 768 content::WebContents* web_contents) const { |
796 base::string16 title = web_contents->GetTitle(); | 769 base::string16 title = web_contents->GetTitle(); |
797 if (!title.empty()) | 770 if (!title.empty()) |
798 return title; | 771 return title; |
799 WebContentsToAppIDMap::const_iterator iter = | 772 WebContentsToAppIDMap::const_iterator iter = |
800 web_contents_to_app_id_.find(web_contents); | 773 web_contents_to_app_id_.find(web_contents); |
801 if (iter != web_contents_to_app_id_.end()) { | 774 if (iter != web_contents_to_app_id_.end()) { |
802 std::string app_id = iter->second; | 775 std::string app_id = iter->second; |
803 const extensions::Extension* extension = | 776 const extensions::Extension* extension = |
804 GetExtensionForAppID(app_id, profile_); | 777 GetExtensionForAppID(app_id, profile()); |
805 if (extension) | 778 if (extension) |
806 return base::UTF8ToUTF16(extension->name()); | 779 return base::UTF8ToUTF16(extension->name()); |
807 } | 780 } |
808 return l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE); | 781 return l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE); |
809 } | 782 } |
810 | 783 |
811 BrowserShortcutLauncherItemController* | 784 BrowserShortcutLauncherItemController* |
812 ChromeLauncherControllerImpl::GetBrowserShortcutLauncherItemController() { | 785 ChromeLauncherControllerImpl::GetBrowserShortcutLauncherItemController() { |
813 for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin(); | 786 for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin(); |
814 i != id_to_item_controller_map_.end(); ++i) { | 787 i != id_to_item_controller_map_.end(); ++i) { |
(...skipping 11 matching lines...) Expand all Loading... |
826 const ash::ShelfID id) { | 799 const ash::ShelfID id) { |
827 if (!HasShelfIDToAppIDMapping(id)) | 800 if (!HasShelfIDToAppIDMapping(id)) |
828 return NULL; | 801 return NULL; |
829 return id_to_item_controller_map_[id]; | 802 return id_to_item_controller_map_[id]; |
830 } | 803 } |
831 | 804 |
832 bool ChromeLauncherControllerImpl::ShelfBoundsChangesProbablyWithUser( | 805 bool ChromeLauncherControllerImpl::ShelfBoundsChangesProbablyWithUser( |
833 ash::WmShelf* shelf, | 806 ash::WmShelf* shelf, |
834 const AccountId& account_id) const { | 807 const AccountId& account_id) const { |
835 Profile* other_profile = multi_user_util::GetProfileFromAccountId(account_id); | 808 Profile* other_profile = multi_user_util::GetProfileFromAccountId(account_id); |
836 if (!other_profile || other_profile == profile_) | 809 if (!other_profile || other_profile == profile()) |
837 return false; | 810 return false; |
838 | 811 |
839 // Note: The Auto hide state from preferences is not the same as the actual | 812 // Note: The Auto hide state from preferences is not the same as the actual |
840 // visibility of the shelf. Depending on all the various states (full screen, | 813 // visibility of the shelf. Depending on all the various states (full screen, |
841 // no window on desktop, multi user, ..) the shelf could be shown - or not. | 814 // no window on desktop, multi user, ..) the shelf could be shown - or not. |
842 PrefService* prefs = profile_->GetPrefs(); | 815 PrefService* prefs = profile()->GetPrefs(); |
843 PrefService* other_prefs = other_profile->GetPrefs(); | 816 PrefService* other_prefs = other_profile->GetPrefs(); |
844 const int64_t display = GetDisplayIDForShelf(shelf); | 817 const int64_t display = GetDisplayIDForShelf(shelf); |
845 const bool currently_shown = | 818 const bool currently_shown = |
846 ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER == | 819 ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER == |
847 ash::launcher::GetShelfAutoHideBehaviorPref(prefs, display); | 820 ash::launcher::GetShelfAutoHideBehaviorPref(prefs, display); |
848 const bool other_shown = | 821 const bool other_shown = |
849 ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER == | 822 ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER == |
850 ash::launcher::GetShelfAutoHideBehaviorPref(other_prefs, display); | 823 ash::launcher::GetShelfAutoHideBehaviorPref(other_prefs, display); |
851 | 824 |
852 return currently_shown != other_shown || | 825 return currently_shown != other_shown || |
853 ash::launcher::GetShelfAlignmentPref(prefs, display) != | 826 ash::launcher::GetShelfAlignmentPref(prefs, display) != |
854 ash::launcher::GetShelfAlignmentPref(other_prefs, display); | 827 ash::launcher::GetShelfAlignmentPref(other_prefs, display); |
855 } | 828 } |
856 | 829 |
857 void ChromeLauncherControllerImpl::OnUserProfileReadyToSwitch( | 830 void ChromeLauncherControllerImpl::OnUserProfileReadyToSwitch( |
858 Profile* profile) { | 831 Profile* profile) { |
859 if (user_switch_observer_.get()) | 832 if (user_switch_observer_.get()) |
860 user_switch_observer_->OnUserProfileReadyToSwitch(profile); | 833 user_switch_observer_->OnUserProfileReadyToSwitch(profile); |
861 } | 834 } |
862 | 835 |
863 ArcAppDeferredLauncherController* | 836 ArcAppDeferredLauncherController* |
864 ChromeLauncherControllerImpl::GetArcDeferredLauncher() { | 837 ChromeLauncherControllerImpl::GetArcDeferredLauncher() { |
865 return arc_deferred_launcher_.get(); | 838 return arc_deferred_launcher_.get(); |
866 } | 839 } |
867 | 840 |
| 841 void ChromeLauncherControllerImpl::AttachProfile(Profile* profile_to_attach) { |
| 842 // The base class implementation updates the helper and app icon loaders. |
| 843 ChromeLauncherController::AttachProfile(profile_to_attach); |
| 844 |
| 845 pref_change_registrar_.Init(profile()->GetPrefs()); |
| 846 pref_change_registrar_.Add( |
| 847 prefs::kPolicyPinnedLauncherApps, |
| 848 base::Bind(&ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref, |
| 849 base::Unretained(this))); |
| 850 // Handling of prefs::kArcEnabled change should be called deferred to avoid |
| 851 // race condition when OnAppUninstalledPrepared for Arc apps is called after |
| 852 // UpdateAppLaunchersFromPref. |
| 853 pref_change_registrar_.Add( |
| 854 prefs::kArcEnabled, |
| 855 base::Bind( |
| 856 &ChromeLauncherControllerImpl::ScheduleUpdateAppLaunchersFromPref, |
| 857 base::Unretained(this))); |
| 858 pref_change_registrar_.Add( |
| 859 prefs::kShelfAlignmentLocal, |
| 860 base::Bind(&ChromeLauncherController::SetShelfAlignmentFromPrefs, |
| 861 base::Unretained(this))); |
| 862 pref_change_registrar_.Add( |
| 863 prefs::kShelfAutoHideBehaviorLocal, |
| 864 base::Bind(&ChromeLauncherController::SetShelfAutoHideBehaviorFromPrefs, |
| 865 base::Unretained(this))); |
| 866 pref_change_registrar_.Add( |
| 867 prefs::kShelfPreferences, |
| 868 base::Bind(&ChromeLauncherController::SetShelfBehaviorsFromPrefs, |
| 869 base::Unretained(this))); |
| 870 pref_change_registrar_.Add( |
| 871 prefs::kTouchVirtualKeyboardEnabled, |
| 872 base::Bind( |
| 873 &ChromeLauncherControllerImpl::SetVirtualKeyboardBehaviorFromPrefs, |
| 874 base::Unretained(this))); |
| 875 |
| 876 std::unique_ptr<LauncherAppUpdater> extension_app_updater( |
| 877 new LauncherExtensionAppUpdater(this, profile())); |
| 878 app_updaters_.push_back(std::move(extension_app_updater)); |
| 879 |
| 880 if (arc::ArcAuthService::IsAllowedForProfile(profile())) { |
| 881 std::unique_ptr<LauncherAppUpdater> arc_app_updater( |
| 882 new LauncherArcAppUpdater(this, profile())); |
| 883 app_updaters_.push_back(std::move(arc_app_updater)); |
| 884 } |
| 885 |
| 886 app_list::AppListSyncableService* app_service = |
| 887 app_list::AppListSyncableServiceFactory::GetForProfile(profile()); |
| 888 if (app_service) |
| 889 app_service->AddObserverAndStart(this); |
| 890 } |
| 891 |
868 /////////////////////////////////////////////////////////////////////////////// | 892 /////////////////////////////////////////////////////////////////////////////// |
869 // ash::ShelfDelegate: | 893 // ash::ShelfDelegate: |
870 | 894 |
871 void ChromeLauncherControllerImpl::OnShelfCreated(ash::WmShelf* shelf) { | |
872 PrefService* prefs = profile_->GetPrefs(); | |
873 const int64_t display = GetDisplayIDForShelf(shelf); | |
874 | |
875 shelf->SetAutoHideBehavior( | |
876 ash::launcher::GetShelfAutoHideBehaviorPref(prefs, display)); | |
877 | |
878 if (ash::ShelfWidget::ShelfAlignmentAllowed()) | |
879 shelf->SetAlignment(ash::launcher::GetShelfAlignmentPref(prefs, display)); | |
880 } | |
881 | |
882 void ChromeLauncherControllerImpl::OnShelfDestroyed(ash::WmShelf* shelf) {} | |
883 | |
884 void ChromeLauncherControllerImpl::OnShelfAlignmentChanged( | |
885 ash::WmShelf* shelf) { | |
886 ash::launcher::SetShelfAlignmentPref( | |
887 profile_->GetPrefs(), GetDisplayIDForShelf(shelf), shelf->alignment()); | |
888 } | |
889 | |
890 void ChromeLauncherControllerImpl::OnShelfAutoHideBehaviorChanged( | |
891 ash::WmShelf* shelf) { | |
892 ash::launcher::SetShelfAutoHideBehaviorPref(profile_->GetPrefs(), | |
893 GetDisplayIDForShelf(shelf), | |
894 shelf->auto_hide_behavior()); | |
895 } | |
896 | |
897 void ChromeLauncherControllerImpl::OnShelfAutoHideStateChanged( | |
898 ash::WmShelf* shelf) {} | |
899 | |
900 void ChromeLauncherControllerImpl::OnShelfVisibilityStateChanged( | |
901 ash::WmShelf* shelf) {} | |
902 | |
903 ash::ShelfID ChromeLauncherControllerImpl::GetShelfIDForAppID( | 895 ash::ShelfID ChromeLauncherControllerImpl::GetShelfIDForAppID( |
904 const std::string& app_id) { | 896 const std::string& app_id) { |
905 // Get shelf id for app_id and empty launch_id. | 897 // Get shelf id for app_id and empty launch_id. |
906 return GetShelfIDForAppIDAndLaunchID(app_id, ""); | 898 return GetShelfIDForAppIDAndLaunchID(app_id, ""); |
907 } | 899 } |
908 | 900 |
909 ash::ShelfID ChromeLauncherControllerImpl::GetShelfIDForAppIDAndLaunchID( | 901 ash::ShelfID ChromeLauncherControllerImpl::GetShelfIDForAppIDAndLaunchID( |
910 const std::string& app_id, | 902 const std::string& app_id, |
911 const std::string& launch_id) { | 903 const std::string& launch_id) { |
912 const std::string shelf_app_id = | 904 const std::string shelf_app_id = |
(...skipping 18 matching lines...) Expand all Loading... |
931 | 923 |
932 const std::string& ChromeLauncherControllerImpl::GetAppIDForShelfID( | 924 const std::string& ChromeLauncherControllerImpl::GetAppIDForShelfID( |
933 ash::ShelfID id) { | 925 ash::ShelfID id) { |
934 LauncherItemController* controller = GetLauncherItemController(id); | 926 LauncherItemController* controller = GetLauncherItemController(id); |
935 return controller ? controller->app_id() : base::EmptyString(); | 927 return controller ? controller->app_id() : base::EmptyString(); |
936 } | 928 } |
937 | 929 |
938 void ChromeLauncherControllerImpl::PinAppWithID(const std::string& app_id) { | 930 void ChromeLauncherControllerImpl::PinAppWithID(const std::string& app_id) { |
939 const std::string shelf_app_id = | 931 const std::string shelf_app_id = |
940 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(app_id); | 932 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(app_id); |
941 if (GetPinnableForAppID(shelf_app_id, profile_) == | 933 if (GetPinnableForAppID(shelf_app_id, profile()) == |
942 AppListControllerDelegate::PIN_EDITABLE) | 934 AppListControllerDelegate::PIN_EDITABLE) |
943 DoPinAppWithID(shelf_app_id); | 935 DoPinAppWithID(shelf_app_id); |
944 else | 936 else |
945 NOTREACHED(); | 937 NOTREACHED(); |
946 } | 938 } |
947 | 939 |
948 bool ChromeLauncherControllerImpl::IsAppPinned(const std::string& app_id) { | 940 bool ChromeLauncherControllerImpl::IsAppPinned(const std::string& app_id) { |
949 const std::string shelf_app_id = | 941 const std::string shelf_app_id = |
950 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(app_id); | 942 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(app_id); |
951 for (IDToItemControllerMap::const_iterator i = | 943 for (IDToItemControllerMap::const_iterator i = |
952 id_to_item_controller_map_.begin(); | 944 id_to_item_controller_map_.begin(); |
953 i != id_to_item_controller_map_.end(); ++i) { | 945 i != id_to_item_controller_map_.end(); ++i) { |
954 if (IsPinned(i->first) && i->second->app_id() == shelf_app_id) | 946 if (IsPinned(i->first) && i->second->app_id() == shelf_app_id) |
955 return true; | 947 return true; |
956 } | 948 } |
957 return false; | 949 return false; |
958 } | 950 } |
959 | 951 |
960 void ChromeLauncherControllerImpl::UnpinAppWithID(const std::string& app_id) { | 952 void ChromeLauncherControllerImpl::UnpinAppWithID(const std::string& app_id) { |
961 const std::string shelf_app_id = | 953 const std::string shelf_app_id = |
962 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(app_id); | 954 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(app_id); |
963 if (GetPinnableForAppID(shelf_app_id, profile_) == | 955 if (GetPinnableForAppID(shelf_app_id, profile()) == |
964 AppListControllerDelegate::PIN_EDITABLE) | 956 AppListControllerDelegate::PIN_EDITABLE) |
965 DoUnpinAppWithID(shelf_app_id, true /* update_prefs */); | 957 DoUnpinAppWithID(shelf_app_id, true /* update_prefs */); |
966 else | 958 else |
967 NOTREACHED(); | 959 NOTREACHED(); |
968 } | 960 } |
969 | 961 |
970 /////////////////////////////////////////////////////////////////////////////// | 962 /////////////////////////////////////////////////////////////////////////////// |
971 // LauncherAppUpdater::Delegate: | 963 // LauncherAppUpdater::Delegate: |
972 | 964 |
973 void ChromeLauncherControllerImpl::OnAppInstalled( | 965 void ChromeLauncherControllerImpl::OnAppInstalled( |
(...skipping 22 matching lines...) Expand all Loading... |
996 void ChromeLauncherControllerImpl::OnAppUninstalledPrepared( | 988 void ChromeLauncherControllerImpl::OnAppUninstalledPrepared( |
997 content::BrowserContext* browser_context, | 989 content::BrowserContext* browser_context, |
998 const std::string& app_id) { | 990 const std::string& app_id) { |
999 // Since we might have windowed apps of this type which might have | 991 // Since we might have windowed apps of this type which might have |
1000 // outstanding locks which needs to be removed. | 992 // outstanding locks which needs to be removed. |
1001 const Profile* profile = Profile::FromBrowserContext(browser_context); | 993 const Profile* profile = Profile::FromBrowserContext(browser_context); |
1002 if (GetShelfIDForAppID(app_id)) | 994 if (GetShelfIDForAppID(app_id)) |
1003 CloseWindowedAppsFromRemovedExtension(app_id, profile); | 995 CloseWindowedAppsFromRemovedExtension(app_id, profile); |
1004 | 996 |
1005 if (IsAppPinned(app_id)) { | 997 if (IsAppPinned(app_id)) { |
1006 if (profile == profile_) { | 998 if (profile == this->profile()) { |
1007 // Some apps may be removed locally. Don't remove pin position from sync | 999 // Some apps may be removed locally. Don't remove pin position from sync |
1008 // model. When needed, it is automatically deleted on app list model | 1000 // model. When needed, it is automatically deleted on app list model |
1009 // update. | 1001 // update. |
1010 DoUnpinAppWithID(app_id, false /* update_prefs */); | 1002 DoUnpinAppWithID(app_id, false /* update_prefs */); |
1011 } | 1003 } |
1012 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id); | 1004 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id); |
1013 if (app_icon_loader) | 1005 if (app_icon_loader) |
1014 app_icon_loader->ClearImage(app_id); | 1006 app_icon_loader->ClearImage(app_id); |
1015 } | 1007 } |
1016 } | 1008 } |
1017 | 1009 |
1018 /////////////////////////////////////////////////////////////////////////////// | 1010 /////////////////////////////////////////////////////////////////////////////// |
1019 // ChromeLauncherControllerImpl protected: | 1011 // ChromeLauncherControllerImpl protected: |
1020 | 1012 |
1021 ash::ShelfID ChromeLauncherControllerImpl::CreateAppShortcutLauncherItem( | 1013 ash::ShelfID ChromeLauncherControllerImpl::CreateAppShortcutLauncherItem( |
1022 const std::string& app_id, | 1014 const std::string& app_id, |
1023 int index) { | 1015 int index) { |
1024 return CreateAppShortcutLauncherItemWithType(app_id, index, | 1016 return CreateAppShortcutLauncherItemWithType(app_id, index, |
1025 ash::TYPE_APP_SHORTCUT); | 1017 ash::TYPE_APP_SHORTCUT); |
1026 } | 1018 } |
1027 | 1019 |
1028 void ChromeLauncherControllerImpl::SetLauncherControllerHelperForTest( | |
1029 LauncherControllerHelper* helper) { | |
1030 launcher_controller_helper_.reset(helper); | |
1031 } | |
1032 | |
1033 void ChromeLauncherControllerImpl::SetAppIconLoadersForTest( | |
1034 std::vector<std::unique_ptr<AppIconLoader>>& loaders) { | |
1035 app_icon_loaders_.clear(); | |
1036 for (auto& loader : loaders) | |
1037 app_icon_loaders_.push_back(std::move(loader)); | |
1038 } | |
1039 | |
1040 const std::string& ChromeLauncherControllerImpl::GetAppIdFromShelfIdForTest( | 1020 const std::string& ChromeLauncherControllerImpl::GetAppIdFromShelfIdForTest( |
1041 ash::ShelfID id) { | 1021 ash::ShelfID id) { |
1042 return id_to_item_controller_map_[id]->app_id(); | 1022 return id_to_item_controller_map_[id]->app_id(); |
1043 } | 1023 } |
1044 | 1024 |
1045 /////////////////////////////////////////////////////////////////////////////// | 1025 /////////////////////////////////////////////////////////////////////////////// |
1046 // ChromeLauncherControllerImpl private: | 1026 // ChromeLauncherControllerImpl private: |
1047 | 1027 |
1048 void ChromeLauncherControllerImpl::RememberUnpinnedRunningApplicationOrder() { | 1028 void ChromeLauncherControllerImpl::RememberUnpinnedRunningApplicationOrder() { |
1049 RunningAppListIds list; | 1029 RunningAppListIds list; |
1050 for (int i = 0; i < model_->item_count(); i++) { | 1030 for (int i = 0; i < model_->item_count(); i++) { |
1051 ash::ShelfItemType type = model_->items()[i].type; | 1031 ash::ShelfItemType type = model_->items()[i].type; |
1052 if (type == ash::TYPE_WINDOWED_APP || type == ash::TYPE_PLATFORM_APP) | 1032 if (type == ash::TYPE_WINDOWED_APP || type == ash::TYPE_PLATFORM_APP) |
1053 list.push_back(GetAppIDForShelfID(model_->items()[i].id)); | 1033 list.push_back(GetAppIDForShelfID(model_->items()[i].id)); |
1054 } | 1034 } |
1055 const std::string user_email = | 1035 const std::string user_email = |
1056 multi_user_util::GetAccountIdFromProfile(profile_).GetUserEmail(); | 1036 multi_user_util::GetAccountIdFromProfile(profile()).GetUserEmail(); |
1057 last_used_running_application_order_[user_email] = list; | 1037 last_used_running_application_order_[user_email] = list; |
1058 } | 1038 } |
1059 | 1039 |
1060 void ChromeLauncherControllerImpl::RestoreUnpinnedRunningApplicationOrder( | 1040 void ChromeLauncherControllerImpl::RestoreUnpinnedRunningApplicationOrder( |
1061 const std::string& user_id) { | 1041 const std::string& user_id) { |
1062 const RunningAppListIdMap::iterator app_id_list = | 1042 const RunningAppListIdMap::iterator app_id_list = |
1063 last_used_running_application_order_.find(user_id); | 1043 last_used_running_application_order_.find(user_id); |
1064 if (app_id_list == last_used_running_application_order_.end()) | 1044 if (app_id_list == last_used_running_application_order_.end()) |
1065 return; | 1045 return; |
1066 | 1046 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1190 | 1170 |
1191 for (int i = index + 1; i < max_index; ++i) { | 1171 for (int i = index + 1; i < max_index; ++i) { |
1192 const ash::ShelfID shelf_id_after = model_->items()[i].id; | 1172 const ash::ShelfID shelf_id_after = model_->items()[i].id; |
1193 if (IsPinned(shelf_id_after)) { | 1173 if (IsPinned(shelf_id_after)) { |
1194 const std::string app_id_after = GetAppIDForShelfID(shelf_id_after); | 1174 const std::string app_id_after = GetAppIDForShelfID(shelf_id_after); |
1195 DCHECK(!app_id_after.empty()); | 1175 DCHECK(!app_id_after.empty()); |
1196 app_ids_after.push_back(app_id_after); | 1176 app_ids_after.push_back(app_id_after); |
1197 } | 1177 } |
1198 } | 1178 } |
1199 | 1179 |
1200 ash::launcher::SetPinPosition(profile_, app_id, app_id_before, app_ids_after); | 1180 ash::launcher::SetPinPosition(profile(), app_id, app_id_before, |
| 1181 app_ids_after); |
1201 } | 1182 } |
1202 | 1183 |
1203 void ChromeLauncherControllerImpl::OnSyncModelUpdated() { | 1184 void ChromeLauncherControllerImpl::OnSyncModelUpdated() { |
1204 UpdateAppLaunchersFromPref(); | 1185 UpdateAppLaunchersFromPref(); |
1205 } | 1186 } |
1206 | 1187 |
1207 void ChromeLauncherControllerImpl::ScheduleUpdateAppLaunchersFromPref() { | 1188 void ChromeLauncherControllerImpl::ScheduleUpdateAppLaunchersFromPref() { |
1208 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1189 base::ThreadTaskRunnerHandle::Get()->PostTask( |
1209 FROM_HERE, | 1190 FROM_HERE, |
1210 base::Bind(&ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref, | 1191 base::Bind(&ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref, |
1211 weak_ptr_factory_.GetWeakPtr())); | 1192 weak_ptr_factory_.GetWeakPtr())); |
1212 } | 1193 } |
1213 | 1194 |
1214 void ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref() { | 1195 void ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref() { |
1215 // There are various functions which will trigger a |SyncPinPosition| call | 1196 // There are various functions which will trigger a |SyncPinPosition| call |
1216 // like a direct call to |DoPinAppWithID|, or an indirect call to the menu | 1197 // like a direct call to |DoPinAppWithID|, or an indirect call to the menu |
1217 // model which will use weights to re-arrange the icons to new positions. | 1198 // model which will use weights to re-arrange the icons to new positions. |
1218 // Since this function is meant to synchronize the "is state" with the | 1199 // Since this function is meant to synchronize the "is state" with the |
1219 // "sync state", it makes no sense to store any changes by this function back | 1200 // "sync state", it makes no sense to store any changes by this function back |
1220 // into the pref state. Therefore we tell |persistPinnedState| to ignore any | 1201 // into the pref state. Therefore we tell |persistPinnedState| to ignore any |
1221 // invocations while we are running. | 1202 // invocations while we are running. |
1222 base::AutoReset<bool> auto_reset(&ignore_persist_pinned_state_change_, true); | 1203 base::AutoReset<bool> auto_reset(&ignore_persist_pinned_state_change_, true); |
1223 const std::vector<std::string> pinned_apps = | 1204 const std::vector<std::string> pinned_apps = |
1224 ash::launcher::GetPinnedAppsFromPrefs(profile_->GetPrefs(), | 1205 ash::launcher::GetPinnedAppsFromPrefs(profile()->GetPrefs(), |
1225 launcher_controller_helper_.get()); | 1206 launcher_controller_helper()); |
1226 | 1207 |
1227 int index = 0; | 1208 int index = 0; |
1228 // Skip app list items if it exists. | 1209 // Skip app list items if it exists. |
1229 if (model_->items()[0].type == ash::TYPE_APP_LIST) | 1210 if (model_->items()[0].type == ash::TYPE_APP_LIST) |
1230 ++index; | 1211 ++index; |
1231 | 1212 |
1232 // Apply pins in two steps. At the first step, go through the list of apps to | 1213 // Apply pins in two steps. At the first step, go through the list of apps to |
1233 // pin, move existing pin to current position specified by |index| or create | 1214 // pin, move existing pin to current position specified by |index| or create |
1234 // the new pin at that position. | 1215 // the new pin at that position. |
1235 for (const auto& pref_app_id : pinned_apps) { | 1216 for (const auto& pref_app_id : pinned_apps) { |
1236 // Filter out apps that may be mapped wrongly. | 1217 // Filter out apps that may be mapped wrongly. |
1237 // TODO(khmel): b/31703859 is to refactore shelf mapping. | 1218 // TODO(khmel): b/31703859 is to refactore shelf mapping. |
1238 const std::string shelf_app_id = | 1219 const std::string shelf_app_id = |
1239 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(pref_app_id); | 1220 ArcAppWindowLauncherController::GetShelfAppIdFromArcAppId(pref_app_id); |
1240 if (shelf_app_id != pref_app_id) | 1221 if (shelf_app_id != pref_app_id) |
1241 continue; | 1222 continue; |
1242 | 1223 |
1243 // Update apps icon if applicable. | 1224 // Update apps icon if applicable. |
1244 OnAppUpdated(profile_, pref_app_id); | 1225 OnAppUpdated(profile(), pref_app_id); |
1245 | 1226 |
1246 // Find existing pin or app from the right of current |index|. | 1227 // Find existing pin or app from the right of current |index|. |
1247 int app_index = index; | 1228 int app_index = index; |
1248 for (; app_index < model_->item_count(); ++app_index) { | 1229 for (; app_index < model_->item_count(); ++app_index) { |
1249 const ash::ShelfItem& item = model_->items()[app_index]; | 1230 const ash::ShelfItem& item = model_->items()[app_index]; |
1250 const IDToItemControllerMap::iterator it = | 1231 const IDToItemControllerMap::iterator it = |
1251 id_to_item_controller_map_.find(item.id); | 1232 id_to_item_controller_map_.find(item.id); |
1252 if (it != id_to_item_controller_map_.end() && | 1233 if (it != id_to_item_controller_map_.end() && |
1253 it->second->app_id() == pref_app_id) { | 1234 it->second->app_id() == pref_app_id) { |
1254 break; | 1235 break; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1290 controller->type() == LauncherItemController::TYPE_APP) { | 1271 controller->type() == LauncherItemController::TYPE_APP) { |
1291 UnpinRunningAppInternal(index); | 1272 UnpinRunningAppInternal(index); |
1292 // Note, item can be moved to the right due weighting in shelf model. | 1273 // Note, item can be moved to the right due weighting in shelf model. |
1293 DCHECK_GE(model_->ItemIndexByID(item.id), index); | 1274 DCHECK_GE(model_->ItemIndexByID(item.id), index); |
1294 } else { | 1275 } else { |
1295 LauncherItemClosed(item.id); | 1276 LauncherItemClosed(item.id); |
1296 } | 1277 } |
1297 } | 1278 } |
1298 } | 1279 } |
1299 | 1280 |
1300 void ChromeLauncherControllerImpl::SetShelfAutoHideBehaviorFromPrefs() { | |
1301 for (ash::WmWindow* window : ash::WmShell::Get()->GetAllRootWindows()) { | |
1302 ash::WmShelf* shelf = ash::WmShelf::ForWindow(window); | |
1303 // TODO(jamescook): This check should not be necessary, but otherwise this | |
1304 // tries to set autohide state on a secondary display during login before | |
1305 // the ShelfView is created, which is not allowed. | |
1306 if (shelf->IsShelfInitialized()) { | |
1307 shelf->SetAutoHideBehavior(ash::launcher::GetShelfAutoHideBehaviorPref( | |
1308 profile_->GetPrefs(), GetDisplayIDForShelf(shelf))); | |
1309 } | |
1310 } | |
1311 } | |
1312 | |
1313 void ChromeLauncherControllerImpl::SetShelfAlignmentFromPrefs() { | |
1314 if (!ash::ShelfWidget::ShelfAlignmentAllowed()) | |
1315 return; | |
1316 | |
1317 for (ash::WmWindow* window : ash::WmShell::Get()->GetAllRootWindows()) { | |
1318 ash::WmShelf* shelf = ash::WmShelf::ForWindow(window); | |
1319 // TODO(jamescook): This check should not be necessary, but otherwise this | |
1320 // tries to set the alignment on a secondary display during login before the | |
1321 // ShelfLockingManager and ShelfView are created, which is not allowed. | |
1322 if (shelf->IsShelfInitialized()) { | |
1323 shelf->SetAlignment(ash::launcher::GetShelfAlignmentPref( | |
1324 profile_->GetPrefs(), GetDisplayIDForShelf(shelf))); | |
1325 } | |
1326 } | |
1327 } | |
1328 | |
1329 void ChromeLauncherControllerImpl::SetShelfBehaviorsFromPrefs() { | |
1330 SetShelfAutoHideBehaviorFromPrefs(); | |
1331 SetShelfAlignmentFromPrefs(); | |
1332 } | |
1333 | |
1334 void ChromeLauncherControllerImpl::SetVirtualKeyboardBehaviorFromPrefs() { | 1281 void ChromeLauncherControllerImpl::SetVirtualKeyboardBehaviorFromPrefs() { |
1335 const PrefService* service = profile_->GetPrefs(); | 1282 const PrefService* service = profile()->GetPrefs(); |
1336 const bool was_enabled = keyboard::IsKeyboardEnabled(); | 1283 const bool was_enabled = keyboard::IsKeyboardEnabled(); |
1337 if (!service->HasPrefPath(prefs::kTouchVirtualKeyboardEnabled)) { | 1284 if (!service->HasPrefPath(prefs::kTouchVirtualKeyboardEnabled)) { |
1338 keyboard::SetKeyboardShowOverride(keyboard::KEYBOARD_SHOW_OVERRIDE_NONE); | 1285 keyboard::SetKeyboardShowOverride(keyboard::KEYBOARD_SHOW_OVERRIDE_NONE); |
1339 } else { | 1286 } else { |
1340 const bool enable = | 1287 const bool enable = |
1341 service->GetBoolean(prefs::kTouchVirtualKeyboardEnabled); | 1288 service->GetBoolean(prefs::kTouchVirtualKeyboardEnabled); |
1342 keyboard::SetKeyboardShowOverride( | 1289 keyboard::SetKeyboardShowOverride( |
1343 enable ? keyboard::KEYBOARD_SHOW_OVERRIDE_ENABLED | 1290 enable ? keyboard::KEYBOARD_SHOW_OVERRIDE_ENABLED |
1344 : keyboard::KEYBOARD_SHOW_OVERRIDE_DISABLED); | 1291 : keyboard::KEYBOARD_SHOW_OVERRIDE_DISABLED); |
1345 } | 1292 } |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1483 | 1430 |
1484 void ChromeLauncherControllerImpl::SetShelfItemDelegate( | 1431 void ChromeLauncherControllerImpl::SetShelfItemDelegate( |
1485 ash::ShelfID id, | 1432 ash::ShelfID id, |
1486 ash::ShelfItemDelegate* item_delegate) { | 1433 ash::ShelfItemDelegate* item_delegate) { |
1487 DCHECK_GT(id, 0); | 1434 DCHECK_GT(id, 0); |
1488 DCHECK(item_delegate); | 1435 DCHECK(item_delegate); |
1489 model_->SetShelfItemDelegate( | 1436 model_->SetShelfItemDelegate( |
1490 id, std::unique_ptr<ash::ShelfItemDelegate>(item_delegate)); | 1437 id, std::unique_ptr<ash::ShelfItemDelegate>(item_delegate)); |
1491 } | 1438 } |
1492 | 1439 |
1493 void ChromeLauncherControllerImpl::AttachProfile(Profile* profile) { | |
1494 profile_ = profile; | |
1495 // Either add the profile to the list of known profiles and make it the active | |
1496 // one for some functions of LauncherControllerHelper or create a new one. | |
1497 if (!launcher_controller_helper_.get()) | |
1498 launcher_controller_helper_.reset(new LauncherControllerHelper(profile_)); | |
1499 else | |
1500 launcher_controller_helper_->SetCurrentUser(profile_); | |
1501 // TODO(skuhne): The AppIconLoaderImpl has the same problem. Each loaded | |
1502 // image is associated with a profile (its loader requires the profile). | |
1503 // Since icon size changes are possible, the icon could be requested to be | |
1504 // reloaded. However - having it not multi profile aware would cause problems | |
1505 // if the icon cache gets deleted upon user switch. | |
1506 std::unique_ptr<AppIconLoader> extension_app_icon_loader( | |
1507 new extensions::ExtensionAppIconLoader( | |
1508 profile_, extension_misc::EXTENSION_ICON_SMALL, this)); | |
1509 app_icon_loaders_.push_back(std::move(extension_app_icon_loader)); | |
1510 | |
1511 if (arc::ArcAuthService::IsAllowedForProfile(profile_)) { | |
1512 std::unique_ptr<AppIconLoader> arc_app_icon_loader(new ArcAppIconLoader( | |
1513 profile_, extension_misc::EXTENSION_ICON_SMALL, this)); | |
1514 app_icon_loaders_.push_back(std::move(arc_app_icon_loader)); | |
1515 } | |
1516 | |
1517 pref_change_registrar_.Init(profile_->GetPrefs()); | |
1518 pref_change_registrar_.Add( | |
1519 prefs::kPolicyPinnedLauncherApps, | |
1520 base::Bind(&ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref, | |
1521 base::Unretained(this))); | |
1522 // Handling of prefs::kArcEnabled change should be called deferred to avoid | |
1523 // race condition when OnAppUninstalledPrepared for Arc apps is called after | |
1524 // UpdateAppLaunchersFromPref. | |
1525 pref_change_registrar_.Add( | |
1526 prefs::kArcEnabled, | |
1527 base::Bind( | |
1528 &ChromeLauncherControllerImpl::ScheduleUpdateAppLaunchersFromPref, | |
1529 base::Unretained(this))); | |
1530 pref_change_registrar_.Add( | |
1531 prefs::kShelfAlignmentLocal, | |
1532 base::Bind(&ChromeLauncherControllerImpl::SetShelfAlignmentFromPrefs, | |
1533 base::Unretained(this))); | |
1534 pref_change_registrar_.Add( | |
1535 prefs::kShelfAutoHideBehaviorLocal, | |
1536 base::Bind( | |
1537 &ChromeLauncherControllerImpl::SetShelfAutoHideBehaviorFromPrefs, | |
1538 base::Unretained(this))); | |
1539 pref_change_registrar_.Add( | |
1540 prefs::kShelfPreferences, | |
1541 base::Bind(&ChromeLauncherControllerImpl::SetShelfBehaviorsFromPrefs, | |
1542 base::Unretained(this))); | |
1543 pref_change_registrar_.Add( | |
1544 prefs::kTouchVirtualKeyboardEnabled, | |
1545 base::Bind( | |
1546 &ChromeLauncherControllerImpl::SetVirtualKeyboardBehaviorFromPrefs, | |
1547 base::Unretained(this))); | |
1548 | |
1549 std::unique_ptr<LauncherAppUpdater> extension_app_updater( | |
1550 new LauncherExtensionAppUpdater(this, profile_)); | |
1551 app_updaters_.push_back(std::move(extension_app_updater)); | |
1552 | |
1553 if (arc::ArcAuthService::IsAllowedForProfile(profile_)) { | |
1554 std::unique_ptr<LauncherAppUpdater> arc_app_updater( | |
1555 new LauncherArcAppUpdater(this, profile_)); | |
1556 app_updaters_.push_back(std::move(arc_app_updater)); | |
1557 } | |
1558 | |
1559 app_list::AppListSyncableService* app_service = | |
1560 app_list::AppListSyncableServiceFactory::GetForProfile(profile_); | |
1561 if (app_service) | |
1562 app_service->AddObserverAndStart(this); | |
1563 } | |
1564 | |
1565 void ChromeLauncherControllerImpl::SetProfileForTest(Profile* profile) { | |
1566 profile_ = profile; | |
1567 } | |
1568 | |
1569 void ChromeLauncherControllerImpl::ReleaseProfile() { | 1440 void ChromeLauncherControllerImpl::ReleaseProfile() { |
1570 if (app_sync_ui_state_) | 1441 if (app_sync_ui_state_) |
1571 app_sync_ui_state_->RemoveObserver(this); | 1442 app_sync_ui_state_->RemoveObserver(this); |
1572 | 1443 |
1573 app_updaters_.clear(); | 1444 app_updaters_.clear(); |
1574 | 1445 |
1575 prefs_observer_.reset(); | 1446 prefs_observer_.reset(); |
1576 | 1447 |
1577 pref_change_registrar_.RemoveAll(); | 1448 pref_change_registrar_.RemoveAll(); |
1578 | 1449 |
1579 app_list::AppListSyncableService* app_service = | 1450 app_list::AppListSyncableService* app_service = |
1580 app_list::AppListSyncableServiceFactory::GetForProfile(profile_); | 1451 app_list::AppListSyncableServiceFactory::GetForProfile(profile()); |
1581 if (app_service) | 1452 if (app_service) |
1582 app_service->RemoveObserver(this); | 1453 app_service->RemoveObserver(this); |
1583 } | 1454 } |
1584 | 1455 |
1585 AppIconLoader* ChromeLauncherControllerImpl::GetAppIconLoaderForApp( | |
1586 const std::string& app_id) { | |
1587 for (const auto& app_icon_loader : app_icon_loaders_) { | |
1588 if (app_icon_loader->CanLoadImageForApp(app_id)) | |
1589 return app_icon_loader.get(); | |
1590 } | |
1591 | |
1592 return nullptr; | |
1593 } | |
1594 | |
1595 /////////////////////////////////////////////////////////////////////////////// | 1456 /////////////////////////////////////////////////////////////////////////////// |
1596 // ash::ShelfModelObserver: | 1457 // ash::ShelfModelObserver: |
1597 | 1458 |
1598 void ChromeLauncherControllerImpl::ShelfItemAdded(int index) { | 1459 void ChromeLauncherControllerImpl::ShelfItemAdded(int index) { |
1599 } | 1460 } |
1600 | 1461 |
1601 void ChromeLauncherControllerImpl::ShelfItemRemoved(int index, | 1462 void ChromeLauncherControllerImpl::ShelfItemRemoved(int index, |
1602 ash::ShelfID id) { | 1463 ash::ShelfID id) { |
1603 // TODO(skuhne): This fixes crbug.com/429870, but it does not answer why we | 1464 // TODO(skuhne): This fixes crbug.com/429870, but it does not answer why we |
1604 // get into this state in the first place. | 1465 // get into this state in the first place. |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1679 if (index == -1) | 1540 if (index == -1) |
1680 continue; | 1541 continue; |
1681 ash::ShelfItem item = model_->items()[index]; | 1542 ash::ShelfItem item = model_->items()[index]; |
1682 item.image = image; | 1543 item.image = image; |
1683 if (arc_deferred_launcher_) | 1544 if (arc_deferred_launcher_) |
1684 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image); | 1545 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image); |
1685 model_->Set(index, item); | 1546 model_->Set(index, item); |
1686 // It's possible we're waiting on more than one item, so don't break. | 1547 // It's possible we're waiting on more than one item, so don't break. |
1687 } | 1548 } |
1688 } | 1549 } |
OLD | NEW |