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 9bd33e0ba8871b605a28f6aa57529e6cf66f4763..160e7580fe53ce0ab886f89125b5f422cb5de86b 100644 |
--- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.cc |
+++ b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.cc |
@@ -355,7 +355,14 @@ void ChromeLauncherControllerImpl::CloseLauncherItem(ash::ShelfID id) { |
CHECK(iter != id_to_item_controller_map_.end()); |
SetItemStatus(id, ash::STATUS_CLOSED); |
std::string app_id = iter->second->app_id(); |
- iter->second = AppShortcutLauncherItemController::Create(app_id, this); |
+ std::string app_shelf_id = iter->second->app_id(); |
+ if (iter->second->type() == LauncherItemController::TYPE_APP) { |
+ AppWindowLauncherItemController* app_window_controller = |
+ static_cast<AppWindowLauncherItemController*>(iter->second); |
+ app_shelf_id = app_window_controller->app_shelf_id(); |
+ } |
+ iter->second = |
+ AppShortcutLauncherItemController::Create(app_id, app_shelf_id, this); |
iter->second->set_shelf_id(id); |
// Existing controller is destroyed and replaced by registering again. |
SetShelfItemDelegate(id, iter->second); |
@@ -428,11 +435,11 @@ bool ChromeLauncherControllerImpl::IsPinnable(ash::ShelfID id) const { |
} |
void ChromeLauncherControllerImpl::LockV1AppWithID(const std::string& app_id) { |
- ash::ShelfID id = GetShelfIDForAppID(app_id); |
+ ash::ShelfID id = GetShelfIDForAppID(app_id, app_id); |
if (!IsPinned(id) && !IsWindowedAppInLauncher(app_id)) { |
CreateAppShortcutLauncherItemWithType(app_id, model_->item_count(), |
ash::TYPE_WINDOWED_APP); |
- id = GetShelfIDForAppID(app_id); |
+ id = GetShelfIDForAppID(app_id, app_id); |
} |
CHECK(id); |
id_to_item_controller_map_[id]->lock(); |
@@ -440,7 +447,7 @@ void ChromeLauncherControllerImpl::LockV1AppWithID(const std::string& app_id) { |
void ChromeLauncherControllerImpl::UnlockV1AppWithID( |
const std::string& app_id) { |
- ash::ShelfID id = GetShelfIDForAppID(app_id); |
+ ash::ShelfID id = GetShelfIDForAppID(app_id, app_id); |
CHECK(id); |
CHECK(IsPinned(id) || IsWindowedAppInLauncher(app_id)); |
LauncherItemController* controller = id_to_item_controller_map_[id]; |
@@ -491,7 +498,7 @@ void ChromeLauncherControllerImpl::ActivateApp(const std::string& app_id, |
ash::LaunchSource source, |
int event_flags) { |
// If there is an existing non-shortcut controller for this app, open it. |
- ash::ShelfID id = GetShelfIDForAppID(app_id); |
+ ash::ShelfID id = GetShelfIDForAppID(app_id, app_id); |
if (id) { |
LauncherItemController* controller = GetLauncherItemController(id); |
controller->Activate(source); |
@@ -501,7 +508,7 @@ void ChromeLauncherControllerImpl::ActivateApp(const std::string& app_id, |
// Create a temporary application launcher item and use it to see if there are |
// running instances. |
std::unique_ptr<AppShortcutLauncherItemController> app_controller( |
- AppShortcutLauncherItemController::Create(app_id, this)); |
+ AppShortcutLauncherItemController::Create(app_id, app_id, this)); |
if (!app_controller->GetRunningApplications().empty()) |
app_controller->Activate(source); |
else |
@@ -534,7 +541,7 @@ void ChromeLauncherControllerImpl::SetLauncherItemImage( |
bool ChromeLauncherControllerImpl::IsWindowedAppInLauncher( |
const std::string& app_id) { |
- int index = model_->ItemIndexByID(GetShelfIDForAppID(app_id)); |
+ int index = model_->ItemIndexByID(GetShelfIDForAppID(app_id, app_id)); |
if (index < 0) |
return false; |
@@ -571,7 +578,7 @@ void ChromeLauncherControllerImpl::UpdateAppState( |
if (web_contents_to_app_id_.find(contents) != web_contents_to_app_id_.end()) { |
std::string last_app_id = web_contents_to_app_id_[contents]; |
if (last_app_id != app_id) { |
- ash::ShelfID id = GetShelfIDForAppID(last_app_id); |
+ ash::ShelfID id = GetShelfIDForAppID(last_app_id, last_app_id); |
if (id) { |
// Since GetAppState() will use |web_contents_to_app_id_| we remove |
// the connection before calling it. |
@@ -586,7 +593,7 @@ void ChromeLauncherControllerImpl::UpdateAppState( |
else |
web_contents_to_app_id_[contents] = app_id; |
- ash::ShelfID id = GetShelfIDForAppID(app_id); |
+ ash::ShelfID id = GetShelfIDForAppID(app_id, app_id); |
if (id) { |
SetItemStatus(id, (app_state == APP_STATE_WINDOW_ACTIVE || |
app_state == APP_STATE_ACTIVE) |
@@ -604,7 +611,7 @@ ash::ShelfID ChromeLauncherControllerImpl::GetShelfIDForWebContents( |
if (app_id.empty() && ContentCanBeHandledByGmailApp(contents)) |
app_id = kGmailAppId; |
- ash::ShelfID id = GetShelfIDForAppID(app_id); |
+ ash::ShelfID id = GetShelfIDForAppID(app_id, app_id); |
if (app_id.empty() || !id) { |
int browser_index = model_->GetItemIndexForType(ash::TYPE_BROWSER_SHORTCUT); |
@@ -711,7 +718,8 @@ ChromeLauncherAppMenuItems ChromeLauncherControllerImpl::GetApplicationList( |
// 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())) |
+ if (!controller || |
+ !GetShelfIDForAppID(controller->app_id(), controller->app_id())) |
return ChromeLauncherAppMenuItems(); |
return controller->GetApplicationList(event_flags); |
@@ -720,7 +728,7 @@ ChromeLauncherAppMenuItems ChromeLauncherControllerImpl::GetApplicationList( |
std::vector<content::WebContents*> |
ChromeLauncherControllerImpl::GetV1ApplicationsFromAppId( |
const std::string& app_id) { |
- ash::ShelfID id = GetShelfIDForAppID(app_id); |
+ ash::ShelfID id = GetShelfIDForAppID(app_id, app_id); |
// If there is no such an item pinned to the launcher, no menu gets created. |
if (id) { |
@@ -734,7 +742,7 @@ ChromeLauncherControllerImpl::GetV1ApplicationsFromAppId( |
void ChromeLauncherControllerImpl::ActivateShellApp(const std::string& app_id, |
int index) { |
- ash::ShelfID id = GetShelfIDForAppID(app_id); |
+ ash::ShelfID id = GetShelfIDForAppID(app_id, app_id); |
if (id) { |
LauncherItemController* controller = GetLauncherItemController(id); |
if (controller && controller->type() == LauncherItemController::TYPE_APP) { |
@@ -757,7 +765,7 @@ bool ChromeLauncherControllerImpl::IsWebContentHandledByApplication( |
bool ChromeLauncherControllerImpl::ContentCanBeHandledByGmailApp( |
content::WebContents* web_contents) { |
- ash::ShelfID id = GetShelfIDForAppID(kGmailAppId); |
+ ash::ShelfID id = GetShelfIDForAppID(kGmailAppId, kGmailAppId); |
if (id) { |
const GURL url = web_contents->GetURL(); |
// We need to extend the application matching for the gMail app beyond the |
@@ -894,14 +902,33 @@ void ChromeLauncherControllerImpl::OnShelfVisibilityStateChanged( |
ash::Shelf* shelf) {} |
ash::ShelfID ChromeLauncherControllerImpl::GetShelfIDForAppID( |
- const std::string& app_id) { |
+ const std::string& app_id, |
+ const std::string& app_shelf_id) { |
for (IDToItemControllerMap::const_iterator i = |
id_to_item_controller_map_.begin(); |
i != id_to_item_controller_map_.end(); ++i) { |
stevenjb
2016/08/29 15:56:30
Convert this to a C++11 style iterator
Andra Paraschiv
2016/08/30 09:58:24
Done.
|
if (i->second->type() == LauncherItemController::TYPE_APP_PANEL) |
continue; // Don't include panels |
- if (i->second->app_id() == app_id) |
+ // If app window controller, check app_id and app_shelf_id. |
+ if (i->second->type() == LauncherItemController::TYPE_APP) { |
+ AppWindowLauncherItemController* app_window_controller = |
+ static_cast<AppWindowLauncherItemController*>(i->second); |
+ if ((app_window_controller->app_id() == app_id) && |
+ (app_window_controller->app_shelf_id() == app_shelf_id)) { |
+ return i->first; |
+ } |
+ // If not browser shortcut controller, check app_id and app_shelf_id. |
+ } else if ((i->second->type() == LauncherItemController::TYPE_SHORTCUT) && |
+ (i->second->app_id() != extension_misc::kChromeAppId)) { |
+ AppShortcutLauncherItemController* app_shortcut_controller = |
+ static_cast<AppShortcutLauncherItemController*>(i->second); |
+ if ((app_shortcut_controller->app_id() == app_id) && |
+ (app_shortcut_controller->app_shelf_id() == app_shelf_id)) { |
+ return i->first; |
+ } |
+ } else if (i->second->app_id() == app_id) { |
return i->first; |
+ } |
} |
return 0; |
} |
@@ -976,7 +1003,7 @@ void ChromeLauncherControllerImpl::OnAppUninstalledPrepared( |
// Since we might have windowed apps of this type which might have |
// outstanding locks which needs to be removed. |
const Profile* profile = Profile::FromBrowserContext(browser_context); |
- if (GetShelfIDForAppID(app_id)) |
+ if (GetShelfIDForAppID(app_id, app_id)) |
CloseWindowedAppsFromRemovedExtension(app_id, profile); |
if (IsAppPinned(app_id)) { |
@@ -1041,7 +1068,7 @@ void ChromeLauncherControllerImpl::RestoreUnpinnedRunningApplicationOrder( |
int running_index = model_->FirstRunningAppIndex(); |
for (RunningAppListIds::iterator app_id = app_id_list->second.begin(); |
app_id != app_id_list->second.end(); ++app_id) { |
- ash::ShelfID shelf_id = GetShelfIDForAppID(*app_id); |
+ ash::ShelfID shelf_id = GetShelfIDForAppID(*app_id, *app_id); |
if (shelf_id) { |
int app_index = model_->ItemIndexByID(shelf_id); |
DCHECK_GE(app_index, 0); |
@@ -1061,7 +1088,7 @@ ChromeLauncherControllerImpl::CreateAppShortcutLauncherItemWithType( |
int index, |
ash::ShelfItemType shelf_item_type) { |
AppShortcutLauncherItemController* controller = |
- AppShortcutLauncherItemController::Create(app_id, this); |
+ AppShortcutLauncherItemController::Create(app_id, app_id, this); |
ash::ShelfID shelf_id = InsertAppLauncherItem( |
controller, app_id, ash::STATUS_CLOSED, index, shelf_item_type); |
return shelf_id; |
@@ -1088,7 +1115,7 @@ void ChromeLauncherControllerImpl::DoPinAppWithID(const std::string& app_id) { |
if (IsAppPinned(app_id)) |
return; |
- ash::ShelfID shelf_id = GetShelfIDForAppID(app_id); |
+ ash::ShelfID shelf_id = GetShelfIDForAppID(app_id, app_id); |
if (shelf_id) { |
// App item exists, pin it |
Pin(shelf_id); |
@@ -1100,7 +1127,7 @@ void ChromeLauncherControllerImpl::DoPinAppWithID(const std::string& app_id) { |
} |
void ChromeLauncherControllerImpl::DoUnpinAppWithID(const std::string& app_id) { |
- ash::ShelfID shelf_id = GetShelfIDForAppID(app_id); |
+ ash::ShelfID shelf_id = GetShelfIDForAppID(app_id, app_id); |
if (shelf_id && IsPinned(shelf_id)) |
Unpin(shelf_id); |
} |
@@ -1258,7 +1285,7 @@ void ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref() { |
DCHECK(index <= max_index); |
} else { |
// Check if the item was already running but not yet pinned. |
- ash::ShelfID shelf_id = GetShelfIDForAppID(*pref_app_id); |
+ ash::ShelfID shelf_id = GetShelfIDForAppID(*pref_app_id, *pref_app_id); |
if (shelf_id) { |
// This app is running but not yet pinned. So pin and move it. |
index = PinRunningAppInternal(index, shelf_id); |
@@ -1301,7 +1328,7 @@ void ChromeLauncherControllerImpl::UpdateAppLaunchersFromPref() { |
} else { |
DoPinAppWithID(*pref_app_id); |
int target_index = FindInsertionPoint(); |
- ash::ShelfID id = GetShelfIDForAppID(*pref_app_id); |
+ ash::ShelfID id = GetShelfIDForAppID(*pref_app_id, *pref_app_id); |
int source_index = model_->ItemIndexByID(id); |
if (source_index != target_index) |
model_->Move(source_index, target_index); |