Chromium Code Reviews| Index: chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.cc |
| diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.cc b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.cc |
| index 468e7dfc5f7094ebe2546718044e231e1a8078c7..1ae2658ee90e9c88387413605772d6e6b5d58558 100644 |
| --- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.cc |
| +++ b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.cc |
| @@ -433,46 +433,6 @@ void ChromeLauncherControllerImpl::CloseLauncherItem(ash::ShelfID id) { |
| } |
| } |
| -AppListControllerDelegate::Pinnable ChromeLauncherControllerImpl::GetPinnable( |
| - const std::string& app_id) { |
| - for (size_t i = 0; i < kPinProhibitedExtensionIdsLength; ++i) { |
| - if (kPinProhibitedExtensionIds[i] == app_id) |
| - return AppListControllerDelegate::NO_PIN; |
| - } |
| - |
| - const base::ListValue* pref = |
| - profile_->GetPrefs()->GetList(prefs::kPolicyPinnedLauncherApps); |
| - if (!pref) |
| - return AppListControllerDelegate::PIN_EDITABLE; |
| - |
| - // Pinned ARC apps policy defines the package name of the apps, that must |
| - // be pinned. All the launch activities of any package in policy are pinned. |
| - // In turn the input parameter to this function is app_id, which |
| - // is 32 chars hash. In case of ARC app this is a hash of |
| - // (package name + activity). This means that we must identify the package |
| - // from the hash, and check if this package is pinned by policy. |
| - const ArcAppListPrefs* const arc_prefs = ArcAppListPrefs::Get(GetProfile()); |
| - std::string arc_app_packege_name; |
| - if (arc_prefs) { |
| - std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = |
| - arc_prefs->GetApp(app_id); |
| - if (app_info) |
| - arc_app_packege_name = app_info->package_name; |
| - } |
| - |
| - for (size_t index = 0; index < pref->GetSize(); ++index) { |
| - const base::DictionaryValue* app = nullptr; |
| - std::string app_id_or_package; |
| - if (pref->GetDictionary(index, &app) && |
| - app->GetString(ash::kPinnedAppsPrefAppIDPath, &app_id_or_package) && |
| - (app_id == app_id_or_package || |
| - arc_app_packege_name == app_id_or_package)) { |
| - return AppListControllerDelegate::PIN_FIXED; |
| - } |
| - } |
| - return AppListControllerDelegate::PIN_EDITABLE; |
| -} |
| - |
| void ChromeLauncherControllerImpl::Pin(ash::ShelfID id) { |
| DCHECK(HasShelfIDToAppIDMapping(id)); |
| @@ -631,53 +591,6 @@ extensions::LaunchType ChromeLauncherControllerImpl::GetLaunchType( |
| extension); |
| } |
| -ash::ShelfID ChromeLauncherControllerImpl::GetShelfIDForAppID( |
| - const std::string& app_id) { |
| - for (IDToItemControllerMap::const_iterator i = |
| - id_to_item_controller_map_.begin(); |
| - i != id_to_item_controller_map_.end(); ++i) { |
| - if (i->second->type() == LauncherItemController::TYPE_APP_PANEL) |
| - continue; // Don't include panels |
| - if (i->second->app_id() == app_id) |
| - return i->first; |
| - } |
| - return 0; |
| -} |
| - |
| -bool ChromeLauncherControllerImpl::HasShelfIDToAppIDMapping( |
| - ash::ShelfID id) const { |
| - return id_to_item_controller_map_.find(id) != |
| - id_to_item_controller_map_.end(); |
| -} |
| - |
| -const std::string& ChromeLauncherControllerImpl::GetAppIDForShelfID( |
| - ash::ShelfID id) { |
| - LauncherItemController* controller = GetLauncherItemController(id); |
| - return controller ? controller->app_id() : base::EmptyString(); |
| -} |
| - |
| -void ChromeLauncherControllerImpl::OnAppImageUpdated( |
| - const std::string& id, |
| - const gfx::ImageSkia& image) { |
| - // TODO: need to get this working for shortcuts. |
| - for (IDToItemControllerMap::const_iterator i = |
| - id_to_item_controller_map_.begin(); |
| - i != id_to_item_controller_map_.end(); ++i) { |
| - LauncherItemController* controller = i->second; |
| - if (controller->app_id() != id) |
| - continue; |
| - if (controller->image_set_by_controller()) |
| - continue; |
| - int index = model_->ItemIndexByID(i->first); |
| - if (index == -1) |
| - continue; |
| - ash::ShelfItem item = model_->items()[index]; |
| - item.image = image; |
| - model_->Set(index, item); |
| - // It's possible we're waiting on more than one item, so don't break. |
| - } |
| -} |
| - |
| void ChromeLauncherControllerImpl::SetLauncherItemImage( |
| ash::ShelfID shelf_id, |
| const gfx::ImageSkia& image) { |
| @@ -689,16 +602,6 @@ void ChromeLauncherControllerImpl::SetLauncherItemImage( |
| model_->Set(index, item); |
| } |
| -bool ChromeLauncherControllerImpl::IsAppPinned(const std::string& app_id) { |
| - for (IDToItemControllerMap::const_iterator i = |
| - id_to_item_controller_map_.begin(); |
| - i != id_to_item_controller_map_.end(); ++i) { |
| - if (IsPinned(i->first) && i->second->app_id() == app_id) |
| - return true; |
| - } |
| - return false; |
| -} |
| - |
| bool ChromeLauncherControllerImpl::IsWindowedAppInLauncher( |
| const std::string& app_id) { |
| int index = model_->ItemIndexByID(GetShelfIDForAppID(app_id)); |
| @@ -709,13 +612,6 @@ bool ChromeLauncherControllerImpl::IsWindowedAppInLauncher( |
| return type == ash::TYPE_WINDOWED_APP; |
| } |
| -void ChromeLauncherControllerImpl::PinAppWithID(const std::string& app_id) { |
| - if (GetPinnable(app_id) == AppListControllerDelegate::PIN_EDITABLE) |
| - DoPinAppWithID(app_id); |
| - else |
| - NOTREACHED(); |
| -} |
| - |
| void ChromeLauncherControllerImpl::SetLaunchType( |
| ash::ShelfID id, |
| extensions::LaunchType launch_type) { |
| @@ -726,25 +622,6 @@ void ChromeLauncherControllerImpl::SetLaunchType( |
| extensions::SetLaunchType(profile_, controller->app_id(), launch_type); |
| } |
| -void ChromeLauncherControllerImpl::UnpinAppWithID(const std::string& app_id) { |
| - if (GetPinnable(app_id) == AppListControllerDelegate::PIN_EDITABLE) |
| - DoUnpinAppWithID(app_id); |
| - else |
| - NOTREACHED(); |
| -} |
| - |
| -void ChromeLauncherControllerImpl::OnSetShelfItemDelegate( |
| - ash::ShelfID id, |
| - ash::ShelfItemDelegate* item_delegate) { |
| - // TODO(skuhne): This fixes crbug.com/429870, but it does not answer why we |
| - // get into this state in the first place. |
| - IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); |
| - if (iter == id_to_item_controller_map_.end() || item_delegate == iter->second) |
| - return; |
| - LOG(ERROR) << "Unexpected change of shelf item id: " << id; |
| - id_to_item_controller_map_.erase(iter); |
| -} |
| - |
| void ChromeLauncherControllerImpl::PersistPinnedState() { |
| if (ignore_persist_pinned_state_change_) |
| return; |
| @@ -923,11 +800,247 @@ ChromeLauncherControllerImpl::ActivateWindowOrMinimizeIfActive( |
| return ash::ShelfItemDelegate::kExistingWindowActivated; |
| } |
| +void ChromeLauncherControllerImpl::ActiveUserChanged( |
| + const std::string& user_email) { |
| + // Store the order of running applications for the user which gets inactive. |
| + RememberUnpinnedRunningApplicationOrder(); |
| + // Coming here the default profile is already switched. All profile specific |
| + // resources get released and the new profile gets attached instead. |
| + ReleaseProfile(); |
| + // When coming here, the active user has already be changed so that we can |
| + // set it as active. |
| + AttachProfile(ProfileManager::GetActiveUserProfile()); |
| + // Update the V1 applications. |
| + browser_status_monitor_->ActiveUserChanged(user_email); |
| + // Switch the running applications to the new user. |
| + for (auto& controller : app_window_controllers_) |
| + controller->ActiveUserChanged(user_email); |
| + // Update the user specific shell properties from the new user profile. |
| + UpdateAppLaunchersFromPref(); |
| + SetShelfBehaviorsFromPrefs(); |
| + SetVirtualKeyboardBehaviorFromPrefs(); |
| + |
| + // Restore the order of running, but unpinned applications for the activated |
| + // user. |
| + RestoreUnpinnedRunningApplicationOrder(user_email); |
| + // Inform the system tray of the change. |
| + ash::WmShell::Get()->system_tray_delegate()->ActiveUserWasChanged(); |
| + // Force on-screen keyboard to reset. |
| + if (keyboard::IsKeyboardEnabled()) |
| + ash::Shell::GetInstance()->CreateKeyboard(); |
| +} |
| + |
| +void ChromeLauncherControllerImpl::AdditionalUserAddedToSession( |
| + Profile* profile) { |
| + // Switch the running applications to the new user. |
| + for (auto& controller : app_window_controllers_) |
| + controller->AdditionalUserAddedToSession(profile); |
| +} |
| + |
| +ChromeLauncherAppMenuItems ChromeLauncherControllerImpl::GetApplicationList( |
| + const ash::ShelfItem& item, |
| + int event_flags) { |
| + // Make sure that there is a controller associated with the id and that the |
| + // extension itself is a valid application and not a panel. |
| + LauncherItemController* controller = GetLauncherItemController(item.id); |
| + if (!controller || !GetShelfIDForAppID(controller->app_id())) |
| + return ChromeLauncherAppMenuItems(); |
| + |
| + return controller->GetApplicationList(event_flags); |
| +} |
| + |
| +std::vector<content::WebContents*> |
| +ChromeLauncherControllerImpl::GetV1ApplicationsFromAppId( |
| + const std::string& app_id) { |
| + ash::ShelfID id = GetShelfIDForAppID(app_id); |
| + |
| + // If there is no such an item pinned to the launcher, no menu gets created. |
| + if (id) { |
| + LauncherItemController* controller = GetLauncherItemController(id); |
| + DCHECK(controller); |
| + if (controller->type() == LauncherItemController::TYPE_SHORTCUT) |
| + return GetV1ApplicationsFromController(controller); |
| + } |
| + return std::vector<content::WebContents*>(); |
| +} |
| + |
| +void ChromeLauncherControllerImpl::ActivateShellApp(const std::string& app_id, |
| + int index) { |
| + ash::ShelfID id = GetShelfIDForAppID(app_id); |
| + if (id) { |
| + LauncherItemController* controller = GetLauncherItemController(id); |
| + if (controller && controller->type() == LauncherItemController::TYPE_APP) { |
| + AppWindowLauncherItemController* app_window_controller = |
| + static_cast<AppWindowLauncherItemController*>(controller); |
| + app_window_controller->ActivateIndexedApp(index); |
| + } |
| + } |
| +} |
| + |
| +bool ChromeLauncherControllerImpl::IsWebContentHandledByApplication( |
| + content::WebContents* web_contents, |
| + const std::string& app_id) { |
| + if ((web_contents_to_app_id_.find(web_contents) != |
| + web_contents_to_app_id_.end()) && |
| + (web_contents_to_app_id_[web_contents] == app_id)) |
| + return true; |
| + return (app_id == kGmailAppId && ContentCanBeHandledByGmailApp(web_contents)); |
| +} |
| + |
| +bool ChromeLauncherControllerImpl::ContentCanBeHandledByGmailApp( |
| + content::WebContents* web_contents) { |
| + ash::ShelfID id = GetShelfIDForAppID(kGmailAppId); |
| + if (id) { |
| + const GURL url = web_contents->GetURL(); |
| + // We need to extend the application matching for the gMail app beyond the |
| + // manifest file's specification. This is required because of the namespace |
| + // overlap with the offline app ("/mail/mu/"). |
| + if (!base::MatchPattern(url.path(), "/mail/mu/*") && |
| + base::MatchPattern(url.path(), "/mail/*") && |
| + GetExtensionForAppID(kGmailAppId) && |
| + GetExtensionForAppID(kGmailAppId)->OverlapsWithOrigin(url)) |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| +gfx::Image ChromeLauncherControllerImpl::GetAppListIcon( |
| + content::WebContents* web_contents) const { |
| + ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| + if (IsIncognito(web_contents)) |
| + return rb.GetImageNamed(IDR_ASH_SHELF_LIST_INCOGNITO_BROWSER); |
| + favicon::FaviconDriver* favicon_driver = |
| + favicon::ContentFaviconDriver::FromWebContents(web_contents); |
| + gfx::Image result = favicon_driver->GetFavicon(); |
| + if (result.IsEmpty()) |
| + return rb.GetImageNamed(IDR_DEFAULT_FAVICON); |
| + return result; |
| +} |
| + |
| +base::string16 ChromeLauncherControllerImpl::GetAppListTitle( |
| + content::WebContents* web_contents) const { |
| + base::string16 title = web_contents->GetTitle(); |
| + if (!title.empty()) |
| + return title; |
| + WebContentsToAppIDMap::const_iterator iter = |
| + web_contents_to_app_id_.find(web_contents); |
| + if (iter != web_contents_to_app_id_.end()) { |
| + std::string app_id = iter->second; |
| + const extensions::Extension* extension = GetExtensionForAppID(app_id); |
| + if (extension) |
| + return base::UTF8ToUTF16(extension->name()); |
| + } |
| + return l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE); |
| +} |
| + |
| +BrowserShortcutLauncherItemController* |
| +ChromeLauncherControllerImpl::GetBrowserShortcutLauncherItemController() { |
| + for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin(); |
| + i != id_to_item_controller_map_.end(); ++i) { |
| + int index = model_->ItemIndexByID(i->first); |
| + const ash::ShelfItem& item = model_->items()[index]; |
| + if (item.type == ash::TYPE_BROWSER_SHORTCUT) |
| + return static_cast<BrowserShortcutLauncherItemController*>(i->second); |
| + } |
| + NOTREACHED() |
| + << "There should be always be a BrowserShortcutLauncherItemController."; |
| + return nullptr; |
| +} |
| + |
| +LauncherItemController* ChromeLauncherControllerImpl::GetLauncherItemController( |
| + const ash::ShelfID id) { |
| + if (!HasShelfIDToAppIDMapping(id)) |
| + return NULL; |
| + return id_to_item_controller_map_[id]; |
| +} |
| + |
| +bool ChromeLauncherControllerImpl::IsBrowserFromActiveUser(Browser* browser) { |
| + // If running multi user mode with separate desktops, we have to check if the |
| + // browser is from the active user. |
| + if (chrome::MultiUserWindowManager::GetMultiProfileMode() != |
| + chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED) |
| + return true; |
| + return multi_user_util::IsProfileFromActiveUser(browser->profile()); |
| +} |
| + |
| +bool ChromeLauncherControllerImpl::ShelfBoundsChangesProbablyWithUser( |
| + ash::Shelf* shelf, |
| + const std::string& user_id) const { |
| + Profile* other_profile = multi_user_util::GetProfileFromAccountId( |
| + AccountId::FromUserEmail(user_id)); |
| + if (other_profile == profile_) |
| + return false; |
| + |
| + // Note: The Auto hide state from preferences is not the same as the actual |
| + // visibility of the shelf. Depending on all the various states (full screen, |
| + // no window on desktop, multi user, ..) the shelf could be shown - or not. |
| + PrefService* prefs = profile_->GetPrefs(); |
| + PrefService* other_prefs = other_profile->GetPrefs(); |
| + const int64_t display = GetDisplayIDForShelf(shelf); |
| + bool currently_shown = ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER == |
| + ash::GetShelfAutoHideBehaviorPref(prefs, display); |
| + bool other_shown = ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER == |
| + ash::GetShelfAutoHideBehaviorPref(other_prefs, display); |
| + |
| + return currently_shown != other_shown || |
| + ash::GetShelfAlignmentPref(prefs, display) != |
| + ash::GetShelfAlignmentPref(other_prefs, display); |
| +} |
| + |
| +void ChromeLauncherControllerImpl::OnUserProfileReadyToSwitch( |
| + Profile* profile) { |
| + if (user_switch_observer_.get()) |
| + user_switch_observer_->OnUserProfileReadyToSwitch(profile); |
| +} |
| + |
| +AppListControllerDelegate::Pinnable ChromeLauncherControllerImpl::GetPinnable( |
| + const std::string& app_id) { |
| + for (size_t i = 0; i < kPinProhibitedExtensionIdsLength; ++i) { |
| + if (kPinProhibitedExtensionIds[i] == app_id) |
| + return AppListControllerDelegate::NO_PIN; |
| + } |
| + |
| + const base::ListValue* pref = |
| + profile_->GetPrefs()->GetList(prefs::kPolicyPinnedLauncherApps); |
| + if (!pref) |
| + return AppListControllerDelegate::PIN_EDITABLE; |
| + |
| + // Pinned ARC apps policy defines the package name of the apps, that must |
| + // be pinned. All the launch activities of any package in policy are pinned. |
| + // In turn the input parameter to this function is app_id, which |
| + // is 32 chars hash. In case of ARC app this is a hash of |
| + // (package name + activity). This means that we must identify the package |
| + // from the hash, and check if this package is pinned by policy. |
| + const ArcAppListPrefs* const arc_prefs = ArcAppListPrefs::Get(GetProfile()); |
| + std::string arc_app_packege_name; |
| + if (arc_prefs) { |
| + std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = |
| + arc_prefs->GetApp(app_id); |
| + if (app_info) |
| + arc_app_packege_name = app_info->package_name; |
| + } |
| + |
| + for (size_t index = 0; index < pref->GetSize(); ++index) { |
| + const base::DictionaryValue* app = nullptr; |
| + std::string app_id_or_package; |
| + if (pref->GetDictionary(index, &app) && |
| + app->GetString(ash::kPinnedAppsPrefAppIDPath, &app_id_or_package) && |
| + (app_id == app_id_or_package || |
| + arc_app_packege_name == app_id_or_package)) { |
| + return AppListControllerDelegate::PIN_FIXED; |
| + } |
| + } |
| + return AppListControllerDelegate::PIN_EDITABLE; |
| +} |
| + |
| ArcAppDeferredLauncherController* |
| ChromeLauncherControllerImpl::GetArcDeferredLauncher() { |
| return arc_deferred_launcher_.get(); |
| } |
| +/////////////////////////////////////////////////////////////////////////////// |
| +// ash::ShelfDelegate: |
| + |
| void ChromeLauncherControllerImpl::OnShelfCreated(ash::Shelf* shelf) { |
| PrefService* prefs = profile_->GetPrefs(); |
| const int64_t display = GetDisplayIDForShelf(shelf); |
| @@ -952,11 +1065,90 @@ void ChromeLauncherControllerImpl::OnShelfAutoHideBehaviorChanged( |
| shelf->auto_hide_behavior()); |
| } |
| -void ChromeLauncherControllerImpl::OnShelfAutoHideStateChanged( |
| - ash::Shelf* shelf) {} |
| +void ChromeLauncherControllerImpl::OnShelfAutoHideStateChanged( |
| + ash::Shelf* shelf) {} |
| + |
| +void ChromeLauncherControllerImpl::OnShelfVisibilityStateChanged( |
| + ash::Shelf* shelf) {} |
| + |
| +ash::ShelfID ChromeLauncherControllerImpl::GetShelfIDForAppID( |
| + const std::string& app_id) { |
| + for (IDToItemControllerMap::const_iterator i = |
| + id_to_item_controller_map_.begin(); |
| + i != id_to_item_controller_map_.end(); ++i) { |
| + if (i->second->type() == LauncherItemController::TYPE_APP_PANEL) |
| + continue; // Don't include panels |
| + if (i->second->app_id() == app_id) |
| + return i->first; |
| + } |
| + return 0; |
| +} |
| + |
| +bool ChromeLauncherControllerImpl::HasShelfIDToAppIDMapping( |
| + ash::ShelfID id) const { |
| + return id_to_item_controller_map_.find(id) != |
| + id_to_item_controller_map_.end(); |
| +} |
| + |
| +const std::string& ChromeLauncherControllerImpl::GetAppIDForShelfID( |
| + ash::ShelfID id) { |
| + LauncherItemController* controller = GetLauncherItemController(id); |
| + return controller ? controller->app_id() : base::EmptyString(); |
| +} |
| + |
| +bool ChromeLauncherControllerImpl::GetAppIDForShelfIDConst( |
|
msw
2016/06/13 19:15:25
This is unused and not actually a ShelfDelegate ov
mfomitchev
2016/06/13 20:32:29
This, will remove in a separate CL (don't want to
|
| + ash::ShelfID id, |
| + std::string* app_id) const { |
| + auto app = id_to_item_controller_map_.find(id); |
| + if (app == id_to_item_controller_map_.end()) { |
| + return false; |
| + } else { |
| + *app_id = app->second->app_id(); |
| + return true; |
| + } |
| +} |
| + |
| +void ChromeLauncherControllerImpl::PinAppWithID(const std::string& app_id) { |
| + if (GetPinnable(app_id) == AppListControllerDelegate::PIN_EDITABLE) |
| + DoPinAppWithID(app_id); |
| + else |
| + NOTREACHED(); |
| +} |
| + |
| +bool ChromeLauncherControllerImpl::IsAppPinned(const std::string& app_id) { |
| + for (IDToItemControllerMap::const_iterator i = |
| + id_to_item_controller_map_.begin(); |
| + i != id_to_item_controller_map_.end(); ++i) { |
| + if (IsPinned(i->first) && i->second->app_id() == app_id) |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| +void ChromeLauncherControllerImpl::UnpinAppWithID(const std::string& app_id) { |
| + if (GetPinnable(app_id) == AppListControllerDelegate::PIN_EDITABLE) |
| + DoUnpinAppWithID(app_id); |
| + else |
| + NOTREACHED(); |
| +} |
| + |
| +/////////////////////////////////////////////////////////////////////////////// |
| +// ash::ShelfItemDelegateManagerObserver: |
| -void ChromeLauncherControllerImpl::OnShelfVisibilityStateChanged( |
| - ash::Shelf* shelf) {} |
| +void ChromeLauncherControllerImpl::OnSetShelfItemDelegate( |
| + ash::ShelfID id, |
| + ash::ShelfItemDelegate* item_delegate) { |
| + // TODO(skuhne): This fixes crbug.com/429870, but it does not answer why we |
| + // get into this state in the first place. |
| + IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); |
| + if (iter == id_to_item_controller_map_.end() || item_delegate == iter->second) |
| + return; |
| + LOG(ERROR) << "Unexpected change of shelf item id: " << id; |
| + id_to_item_controller_map_.erase(iter); |
| +} |
| + |
| +/////////////////////////////////////////////////////////////////////////////// |
| +// ash::ShelfModelObserver: |
| void ChromeLauncherControllerImpl::ShelfItemAdded(int index) { |
| // The app list launcher can get added to the shelf after we applied the |
| @@ -993,42 +1185,15 @@ void ChromeLauncherControllerImpl::ShelfItemChanged( |
| int index, |
| const ash::ShelfItem& old_item) {} |
| -void ChromeLauncherControllerImpl::ActiveUserChanged( |
| - const std::string& user_email) { |
| - // Store the order of running applications for the user which gets inactive. |
| - RememberUnpinnedRunningApplicationOrder(); |
| - // Coming here the default profile is already switched. All profile specific |
| - // resources get released and the new profile gets attached instead. |
| - ReleaseProfile(); |
| - // When coming here, the active user has already be changed so that we can |
| - // set it as active. |
| - AttachProfile(ProfileManager::GetActiveUserProfile()); |
| - // Update the V1 applications. |
| - browser_status_monitor_->ActiveUserChanged(user_email); |
| - // Switch the running applications to the new user. |
| - for (auto& controller : app_window_controllers_) |
| - controller->ActiveUserChanged(user_email); |
| - // Update the user specific shell properties from the new user profile. |
| - UpdateAppLaunchersFromPref(); |
| - SetShelfBehaviorsFromPrefs(); |
| - SetVirtualKeyboardBehaviorFromPrefs(); |
| +/////////////////////////////////////////////////////////////////////////////// |
| +// ash::WindowTreeHostManager::Observer: |
| - // Restore the order of running, but unpinned applications for the activated |
| - // user. |
| - RestoreUnpinnedRunningApplicationOrder(user_email); |
| - // Inform the system tray of the change. |
| - ash::WmShell::Get()->system_tray_delegate()->ActiveUserWasChanged(); |
| - // Force on-screen keyboard to reset. |
| - if (keyboard::IsKeyboardEnabled()) |
| - ash::Shell::GetInstance()->CreateKeyboard(); |
| +void ChromeLauncherControllerImpl::OnDisplayConfigurationChanged() { |
| + SetShelfBehaviorsFromPrefs(); |
| } |
| -void ChromeLauncherControllerImpl::AdditionalUserAddedToSession( |
| - Profile* profile) { |
| - // Switch the running applications to the new user. |
| - for (auto& controller : app_window_controllers_) |
| - controller->AdditionalUserAddedToSession(profile); |
| -} |
| +/////////////////////////////////////////////////////////////////////////////// |
| +// LauncherAppUpdater: |
| void ChromeLauncherControllerImpl::OnAppInstalled( |
| content::BrowserContext* browser_context, |
| @@ -1071,9 +1236,8 @@ void ChromeLauncherControllerImpl::OnAppUninstalled( |
| } |
| } |
| -void ChromeLauncherControllerImpl::OnDisplayConfigurationChanged() { |
| - SetShelfBehaviorsFromPrefs(); |
| -} |
| +/////////////////////////////////////////////////////////////////////////////// |
| +// AppSyncUIStateObserver: |
| void ChromeLauncherControllerImpl::OnAppSyncUIStatusChanged() { |
| if (app_sync_ui_state_->status() == AppSyncUIState::STATUS_SYNCING) |
| @@ -1082,101 +1246,33 @@ void ChromeLauncherControllerImpl::OnAppSyncUIStatusChanged() { |
| model_->set_status(ash::ShelfModel::STATUS_NORMAL); |
| } |
| -ChromeLauncherAppMenuItems ChromeLauncherControllerImpl::GetApplicationList( |
| - const ash::ShelfItem& item, |
| - int event_flags) { |
| - // Make sure that there is a controller associated with the id and that the |
| - // extension itself is a valid application and not a panel. |
| - LauncherItemController* controller = GetLauncherItemController(item.id); |
| - if (!controller || !GetShelfIDForAppID(controller->app_id())) |
| - return ChromeLauncherAppMenuItems(); |
| - |
| - return controller->GetApplicationList(event_flags); |
| -} |
| - |
| -std::vector<content::WebContents*> |
| -ChromeLauncherControllerImpl::GetV1ApplicationsFromAppId( |
| - const std::string& app_id) { |
| - ash::ShelfID id = GetShelfIDForAppID(app_id); |
| - |
| - // If there is no such an item pinned to the launcher, no menu gets created. |
| - if (id) { |
| - LauncherItemController* controller = GetLauncherItemController(id); |
| - DCHECK(controller); |
| - if (controller->type() == LauncherItemController::TYPE_SHORTCUT) |
| - return GetV1ApplicationsFromController(controller); |
| - } |
| - return std::vector<content::WebContents*>(); |
| -} |
| - |
| -void ChromeLauncherControllerImpl::ActivateShellApp(const std::string& app_id, |
| - int index) { |
| - ash::ShelfID id = GetShelfIDForAppID(app_id); |
| - if (id) { |
| - LauncherItemController* controller = GetLauncherItemController(id); |
| - if (controller && controller->type() == LauncherItemController::TYPE_APP) { |
| - AppWindowLauncherItemController* app_window_controller = |
| - static_cast<AppWindowLauncherItemController*>(controller); |
| - app_window_controller->ActivateIndexedApp(index); |
| - } |
| - } |
| -} |
| - |
| -bool ChromeLauncherControllerImpl::IsWebContentHandledByApplication( |
| - content::WebContents* web_contents, |
| - const std::string& app_id) { |
| - if ((web_contents_to_app_id_.find(web_contents) != |
| - web_contents_to_app_id_.end()) && |
| - (web_contents_to_app_id_[web_contents] == app_id)) |
| - return true; |
| - return (app_id == kGmailAppId && ContentCanBeHandledByGmailApp(web_contents)); |
| -} |
| +/////////////////////////////////////////////////////////////////////////////// |
| +// AppIconLoaderDelegate: |
| -bool ChromeLauncherControllerImpl::ContentCanBeHandledByGmailApp( |
| - content::WebContents* web_contents) { |
| - ash::ShelfID id = GetShelfIDForAppID(kGmailAppId); |
| - if (id) { |
| - const GURL url = web_contents->GetURL(); |
| - // We need to extend the application matching for the gMail app beyond the |
| - // manifest file's specification. This is required because of the namespace |
| - // overlap with the offline app ("/mail/mu/"). |
| - if (!base::MatchPattern(url.path(), "/mail/mu/*") && |
| - base::MatchPattern(url.path(), "/mail/*") && |
| - GetExtensionForAppID(kGmailAppId) && |
| - GetExtensionForAppID(kGmailAppId)->OverlapsWithOrigin(url)) |
| - return true; |
| +void ChromeLauncherControllerImpl::OnAppImageUpdated( |
| + const std::string& id, |
| + const gfx::ImageSkia& image) { |
| + // TODO: need to get this working for shortcuts. |
| + for (IDToItemControllerMap::const_iterator i = |
| + id_to_item_controller_map_.begin(); |
| + i != id_to_item_controller_map_.end(); ++i) { |
| + LauncherItemController* controller = i->second; |
| + if (controller->app_id() != id) |
| + continue; |
| + if (controller->image_set_by_controller()) |
| + continue; |
| + int index = model_->ItemIndexByID(i->first); |
| + if (index == -1) |
| + continue; |
| + ash::ShelfItem item = model_->items()[index]; |
| + item.image = image; |
| + model_->Set(index, item); |
| + // It's possible we're waiting on more than one item, so don't break. |
| } |
| - return false; |
| -} |
| - |
| -gfx::Image ChromeLauncherControllerImpl::GetAppListIcon( |
| - content::WebContents* web_contents) const { |
| - ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| - if (IsIncognito(web_contents)) |
| - return rb.GetImageNamed(IDR_ASH_SHELF_LIST_INCOGNITO_BROWSER); |
| - favicon::FaviconDriver* favicon_driver = |
| - favicon::ContentFaviconDriver::FromWebContents(web_contents); |
| - gfx::Image result = favicon_driver->GetFavicon(); |
| - if (result.IsEmpty()) |
| - return rb.GetImageNamed(IDR_DEFAULT_FAVICON); |
| - return result; |
| } |
| -base::string16 ChromeLauncherControllerImpl::GetAppListTitle( |
| - content::WebContents* web_contents) const { |
| - base::string16 title = web_contents->GetTitle(); |
| - if (!title.empty()) |
| - return title; |
| - WebContentsToAppIDMap::const_iterator iter = |
| - web_contents_to_app_id_.find(web_contents); |
| - if (iter != web_contents_to_app_id_.end()) { |
| - std::string app_id = iter->second; |
| - const extensions::Extension* extension = GetExtensionForAppID(app_id); |
| - if (extension) |
| - return base::UTF8ToUTF16(extension->name()); |
| - } |
| - return l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE); |
| -} |
| +/////////////////////////////////////////////////////////////////////////////// |
| +// ChromeLauncherControllerImpl protected: |
| ash::ShelfID ChromeLauncherControllerImpl::CreateAppShortcutLauncherItem( |
| const std::string& app_id, |
| @@ -1202,18 +1298,6 @@ const std::string& ChromeLauncherControllerImpl::GetAppIdFromShelfIdForTest( |
| return id_to_item_controller_map_[id]->app_id(); |
| } |
| -bool ChromeLauncherControllerImpl::GetAppIDForShelfIDConst( |
| - ash::ShelfID id, |
| - std::string* app_id) const { |
| - auto app = id_to_item_controller_map_.find(id); |
| - if (app == id_to_item_controller_map_.end()) { |
| - return false; |
| - } else { |
| - *app_id = app->second->app_id(); |
| - return true; |
| - } |
| -} |
| - |
| void ChromeLauncherControllerImpl::SetShelfItemDelegateManagerForTest( |
| ash::ShelfItemDelegateManager* manager) { |
| if (item_delegate_manager_) |
| @@ -1225,6 +1309,9 @@ void ChromeLauncherControllerImpl::SetShelfItemDelegateManagerForTest( |
| item_delegate_manager_->AddObserver(this); |
| } |
| +/////////////////////////////////////////////////////////////////////////////// |
| +// ChromeLauncherControllerImpl private: |
| + |
| void ChromeLauncherControllerImpl::RememberUnpinnedRunningApplicationOrder() { |
| RunningAppListIds list; |
| for (int i = 0; i < model_->item_count(); i++) { |
| @@ -1274,52 +1361,6 @@ ChromeLauncherControllerImpl::CreateAppShortcutLauncherItemWithType( |
| return shelf_id; |
| } |
| -LauncherItemController* ChromeLauncherControllerImpl::GetLauncherItemController( |
| - const ash::ShelfID id) { |
| - if (!HasShelfIDToAppIDMapping(id)) |
| - return NULL; |
| - return id_to_item_controller_map_[id]; |
| -} |
| - |
| -bool ChromeLauncherControllerImpl::IsBrowserFromActiveUser(Browser* browser) { |
| - // If running multi user mode with separate desktops, we have to check if the |
| - // browser is from the active user. |
| - if (chrome::MultiUserWindowManager::GetMultiProfileMode() != |
| - chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED) |
| - return true; |
| - return multi_user_util::IsProfileFromActiveUser(browser->profile()); |
| -} |
| - |
| -bool ChromeLauncherControllerImpl::ShelfBoundsChangesProbablyWithUser( |
| - ash::Shelf* shelf, |
| - const std::string& user_id) const { |
| - Profile* other_profile = multi_user_util::GetProfileFromAccountId( |
| - AccountId::FromUserEmail(user_id)); |
| - if (other_profile == profile_) |
| - return false; |
| - |
| - // Note: The Auto hide state from preferences is not the same as the actual |
| - // visibility of the shelf. Depending on all the various states (full screen, |
| - // no window on desktop, multi user, ..) the shelf could be shown - or not. |
| - PrefService* prefs = profile_->GetPrefs(); |
| - PrefService* other_prefs = other_profile->GetPrefs(); |
| - const int64_t display = GetDisplayIDForShelf(shelf); |
| - bool currently_shown = ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER == |
| - ash::GetShelfAutoHideBehaviorPref(prefs, display); |
| - bool other_shown = ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER == |
| - ash::GetShelfAutoHideBehaviorPref(other_prefs, display); |
| - |
| - return currently_shown != other_shown || |
| - ash::GetShelfAlignmentPref(prefs, display) != |
| - ash::GetShelfAlignmentPref(other_prefs, display); |
| -} |
| - |
| -void ChromeLauncherControllerImpl::OnUserProfileReadyToSwitch( |
| - Profile* profile) { |
| - if (user_switch_observer_.get()) |
| - user_switch_observer_->OnUserProfileReadyToSwitch(profile); |
| -} |
| - |
| void ChromeLauncherControllerImpl::LauncherItemClosed(ash::ShelfID id) { |
| IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); |
| CHECK(iter != id_to_item_controller_map_.end()); |
| @@ -1651,20 +1692,6 @@ ChromeLauncherControllerImpl::GetV1ApplicationsFromController( |
| return app_controller->GetRunningApplications(); |
| } |
| -BrowserShortcutLauncherItemController* |
| -ChromeLauncherControllerImpl::GetBrowserShortcutLauncherItemController() { |
| - for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin(); |
| - i != id_to_item_controller_map_.end(); ++i) { |
| - int index = model_->ItemIndexByID(i->first); |
| - const ash::ShelfItem& item = model_->items()[index]; |
| - if (item.type == ash::TYPE_BROWSER_SHORTCUT) |
| - return static_cast<BrowserShortcutLauncherItemController*>(i->second); |
| - } |
| - NOTREACHED() |
| - << "There should be always be a BrowserShortcutLauncherItemController."; |
| - return nullptr; |
| -} |
| - |
| ash::ShelfID ChromeLauncherControllerImpl::CreateBrowserShortcutLauncherItem() { |
| ash::ShelfItem browser_shortcut; |
| browser_shortcut.type = ash::TYPE_BROWSER_SHORTCUT; |
| @@ -1681,6 +1708,14 @@ ash::ShelfID ChromeLauncherControllerImpl::CreateBrowserShortcutLauncherItem() { |
| return id; |
| } |
| +bool ChromeLauncherControllerImpl::IsIncognito( |
| + const content::WebContents* web_contents) const { |
| + const Profile* profile = |
| + Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| + return profile->IsOffTheRecord() && !profile->IsGuestSession() && |
| + !profile->IsSystemProfile(); |
| +} |
| + |
| void ChromeLauncherControllerImpl::PersistChromeItemIndex(int index) { |
| profile_->GetPrefs()->SetInteger(prefs::kShelfChromeIconIndex, index); |
| } |
| @@ -1745,14 +1780,6 @@ int ChromeLauncherControllerImpl::GetChromeIconIndexForCreation() { |
| return std::min(model_->item_count(), index); |
| } |
| -bool ChromeLauncherControllerImpl::IsIncognito( |
| - const content::WebContents* web_contents) const { |
| - const Profile* profile = |
| - Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| - return profile->IsOffTheRecord() && !profile->IsGuestSession() && |
| - !profile->IsSystemProfile(); |
| -} |
| - |
| void ChromeLauncherControllerImpl::CloseWindowedAppsFromRemovedExtension( |
| const std::string& app_id, |
| const Profile* profile) { |