| 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 |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 | 291 |
| 292 prefs_observer_ = | 292 prefs_observer_ = |
| 293 ash::launcher::ChromeLauncherPrefsObserver::CreateIfNecessary(profile()); | 293 ash::launcher::ChromeLauncherPrefsObserver::CreateIfNecessary(profile()); |
| 294 } | 294 } |
| 295 | 295 |
| 296 ash::ShelfID ChromeLauncherControllerImpl::CreateAppLauncherItem( | 296 ash::ShelfID ChromeLauncherControllerImpl::CreateAppLauncherItem( |
| 297 LauncherItemController* controller, | 297 LauncherItemController* controller, |
| 298 const std::string& app_id, | 298 const std::string& app_id, |
| 299 ash::ShelfItemStatus status) { | 299 ash::ShelfItemStatus status) { |
| 300 return InsertAppLauncherItem(controller, app_id, status, model_->item_count(), | 300 return InsertAppLauncherItem(controller, app_id, status, model_->item_count(), |
| 301 controller->GetShelfItemType()); | 301 ash::TYPE_APP); |
| 302 } |
| 303 |
| 304 const ash::ShelfItem& ChromeLauncherControllerImpl::GetItem( |
| 305 ash::ShelfID id) const { |
| 306 const int index = model_->ItemIndexByID(id); |
| 307 DCHECK_GE(index, 0); |
| 308 return model_->items()[index]; |
| 309 } |
| 310 |
| 311 void ChromeLauncherControllerImpl::SetItemType(ash::ShelfID id, |
| 312 ash::ShelfItemType type) { |
| 313 const int index = model_->ItemIndexByID(id); |
| 314 DCHECK_GE(index, 0); |
| 315 ash::ShelfItem item = model_->items()[index]; |
| 316 if (item.type != type) { |
| 317 item.type = type; |
| 318 model_->Set(index, item); |
| 319 } |
| 302 } | 320 } |
| 303 | 321 |
| 304 void ChromeLauncherControllerImpl::SetItemStatus(ash::ShelfID id, | 322 void ChromeLauncherControllerImpl::SetItemStatus(ash::ShelfID id, |
| 305 ash::ShelfItemStatus status) { | 323 ash::ShelfItemStatus status) { |
| 306 int index = model_->ItemIndexByID(id); | 324 const int index = model_->ItemIndexByID(id); |
| 307 ash::ShelfItemStatus old_status = model_->items()[index].status; | 325 DCHECK_GE(index, 0); |
| 308 // Since ordinary browser windows are not registered, we might get a negative | 326 ash::ShelfItem item = model_->items()[index]; |
| 309 // index here. | 327 if (item.status != status) { |
| 310 if (index >= 0 && old_status != status) { | |
| 311 ash::ShelfItem item = model_->items()[index]; | |
| 312 item.status = status; | 328 item.status = status; |
| 313 model_->Set(index, item); | 329 model_->Set(index, item); |
| 314 } | 330 } |
| 315 } | 331 } |
| 316 | 332 |
| 317 void ChromeLauncherControllerImpl::SetItemController( | 333 void ChromeLauncherControllerImpl::SetItemController( |
| 318 ash::ShelfID id, | 334 ash::ShelfID id, |
| 319 LauncherItemController* controller) { | 335 LauncherItemController* controller) { |
| 320 CHECK(controller); | 336 CHECK(controller); |
| 321 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); | 337 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 bool update_prefs) { | 387 bool update_prefs) { |
| 372 LauncherItemController* controller = GetLauncherItemController(id); | 388 LauncherItemController* controller = GetLauncherItemController(id); |
| 373 CHECK(controller); | 389 CHECK(controller); |
| 374 | 390 |
| 375 if (update_prefs) { | 391 if (update_prefs) { |
| 376 ash::launcher::RemovePinPosition( | 392 ash::launcher::RemovePinPosition( |
| 377 profile(), ash::launcher::AppLauncherId(GetAppIDForShelfID(id), | 393 profile(), ash::launcher::AppLauncherId(GetAppIDForShelfID(id), |
| 378 GetLaunchIDForShelfID(id))); | 394 GetLaunchIDForShelfID(id))); |
| 379 } | 395 } |
| 380 | 396 |
| 381 if (controller->type() == LauncherItemController::TYPE_APP || | 397 if (GetItem(id).status != ash::STATUS_CLOSED || controller->locked()) |
| 382 controller->locked()) { | |
| 383 UnpinRunningAppInternal(model_->ItemIndexByID(id)); | 398 UnpinRunningAppInternal(model_->ItemIndexByID(id)); |
| 384 } else { | 399 else |
| 385 LauncherItemClosed(id); | 400 LauncherItemClosed(id); |
| 386 } | |
| 387 } | 401 } |
| 388 | 402 |
| 389 bool ChromeLauncherControllerImpl::IsPinned(ash::ShelfID id) { | 403 bool ChromeLauncherControllerImpl::IsPinned(ash::ShelfID id) { |
| 390 int index = model_->ItemIndexByID(id); | 404 int index = model_->ItemIndexByID(id); |
| 391 if (index < 0) | 405 if (index < 0) |
| 392 return false; | 406 return false; |
| 393 ash::ShelfItemType type = model_->items()[index].type; | 407 ash::ShelfItemType type = model_->items()[index].type; |
| 394 return (type == ash::TYPE_APP_SHORTCUT || type == ash::TYPE_BROWSER_SHORTCUT); | 408 return (type == ash::TYPE_APP_SHORTCUT || type == ash::TYPE_BROWSER_SHORTCUT); |
| 395 } | 409 } |
| 396 | 410 |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 if (!controller || !GetShelfIDForAppID(controller->app_id())) | 693 if (!controller || !GetShelfIDForAppID(controller->app_id())) |
| 680 return ChromeLauncherAppMenuItems(); | 694 return ChromeLauncherAppMenuItems(); |
| 681 | 695 |
| 682 return controller->GetApplicationList(event_flags); | 696 return controller->GetApplicationList(event_flags); |
| 683 } | 697 } |
| 684 | 698 |
| 685 std::vector<content::WebContents*> | 699 std::vector<content::WebContents*> |
| 686 ChromeLauncherControllerImpl::GetV1ApplicationsFromAppId( | 700 ChromeLauncherControllerImpl::GetV1ApplicationsFromAppId( |
| 687 const std::string& app_id) { | 701 const std::string& app_id) { |
| 688 ash::ShelfID id = GetShelfIDForAppID(app_id); | 702 ash::ShelfID id = GetShelfIDForAppID(app_id); |
| 689 | 703 // If there is no such item pinned to the launcher, no menu gets created. |
| 690 // If there is no such an item pinned to the launcher, no menu gets created. | 704 if (id != ash::kInvalidShelfID && |
| 691 if (id) { | 705 GetItem(id).type == ash::TYPE_APP_SHORTCUT) { |
| 692 LauncherItemController* controller = GetLauncherItemController(id); | 706 LauncherItemController* controller = GetLauncherItemController(id); |
| 693 DCHECK(controller); | 707 AppShortcutLauncherItemController* app_controller = |
| 694 if (controller->type() == LauncherItemController::TYPE_SHORTCUT) | 708 static_cast<AppShortcutLauncherItemController*>(controller); |
| 695 return GetV1ApplicationsFromController(controller); | 709 return app_controller->GetRunningApplications(); |
| 696 } | 710 } |
| 697 return std::vector<content::WebContents*>(); | 711 return std::vector<content::WebContents*>(); |
| 698 } | 712 } |
| 699 | 713 |
| 700 void ChromeLauncherControllerImpl::ActivateShellApp(const std::string& app_id, | 714 void ChromeLauncherControllerImpl::ActivateShellApp(const std::string& app_id, |
| 701 int index) { | 715 int window_index) { |
| 702 ash::ShelfID id = GetShelfIDForAppID(app_id); | 716 ash::ShelfID id = GetShelfIDForAppID(app_id); |
| 703 if (id) { | 717 if (id != ash::kInvalidShelfID && GetItem(id).type == ash::TYPE_APP) { |
| 704 LauncherItemController* controller = GetLauncherItemController(id); | 718 LauncherItemController* controller = GetLauncherItemController(id); |
| 705 if (controller && controller->type() == LauncherItemController::TYPE_APP) { | 719 AppWindowLauncherItemController* app_window_controller = |
| 706 AppWindowLauncherItemController* app_window_controller = | 720 static_cast<AppWindowLauncherItemController*>(controller); |
| 707 static_cast<AppWindowLauncherItemController*>(controller); | 721 app_window_controller->ActivateIndexedApp(window_index); |
| 708 app_window_controller->ActivateIndexedApp(index); | |
| 709 } | |
| 710 } | 722 } |
| 711 } | 723 } |
| 712 | 724 |
| 713 bool ChromeLauncherControllerImpl::IsWebContentHandledByApplication( | 725 bool ChromeLauncherControllerImpl::IsWebContentHandledByApplication( |
| 714 content::WebContents* web_contents, | 726 content::WebContents* web_contents, |
| 715 const std::string& app_id) { | 727 const std::string& app_id) { |
| 716 if ((web_contents_to_app_id_.find(web_contents) != | 728 if ((web_contents_to_app_id_.find(web_contents) != |
| 717 web_contents_to_app_id_.end()) && | 729 web_contents_to_app_id_.end()) && |
| 718 (web_contents_to_app_id_[web_contents] == app_id)) | 730 (web_contents_to_app_id_[web_contents] == app_id)) |
| 719 return true; | 731 return true; |
| (...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1255 if (item.type != ash::TYPE_APP_SHORTCUT) { | 1267 if (item.type != ash::TYPE_APP_SHORTCUT) { |
| 1256 ++index; | 1268 ++index; |
| 1257 continue; | 1269 continue; |
| 1258 } | 1270 } |
| 1259 | 1271 |
| 1260 const LauncherItemController* controller = | 1272 const LauncherItemController* controller = |
| 1261 GetLauncherItemController(item.id); | 1273 GetLauncherItemController(item.id); |
| 1262 DCHECK(controller); | 1274 DCHECK(controller); |
| 1263 DCHECK_NE(controller->app_id(), extension_misc::kChromeAppId); | 1275 DCHECK_NE(controller->app_id(), extension_misc::kChromeAppId); |
| 1264 | 1276 |
| 1265 if (controller->locked() || | 1277 if (item.status != ash::STATUS_CLOSED || controller->locked()) { |
| 1266 controller->type() == LauncherItemController::TYPE_APP) { | |
| 1267 UnpinRunningAppInternal(index); | 1278 UnpinRunningAppInternal(index); |
| 1268 // Note, item can be moved to the right due weighting in shelf model. | 1279 // Note, item can be moved to the right due weighting in shelf model. |
| 1269 DCHECK_GE(model_->ItemIndexByID(item.id), index); | 1280 DCHECK_GE(model_->ItemIndexByID(item.id), index); |
| 1270 } else { | 1281 } else { |
| 1271 LauncherItemClosed(item.id); | 1282 LauncherItemClosed(item.id); |
| 1272 } | 1283 } |
| 1273 } | 1284 } |
| 1274 } | 1285 } |
| 1275 | 1286 |
| 1276 void ChromeLauncherControllerImpl::SetVirtualKeyboardBehaviorFromPrefs() { | 1287 void ChromeLauncherControllerImpl::SetVirtualKeyboardBehaviorFromPrefs() { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1319 ash::ShelfID ChromeLauncherControllerImpl::InsertAppLauncherItem( | 1330 ash::ShelfID ChromeLauncherControllerImpl::InsertAppLauncherItem( |
| 1320 LauncherItemController* controller, | 1331 LauncherItemController* controller, |
| 1321 const std::string& app_id, | 1332 const std::string& app_id, |
| 1322 ash::ShelfItemStatus status, | 1333 ash::ShelfItemStatus status, |
| 1323 int index, | 1334 int index, |
| 1324 ash::ShelfItemType shelf_item_type) { | 1335 ash::ShelfItemType shelf_item_type) { |
| 1325 ash::ShelfID id = model_->next_id(); | 1336 ash::ShelfID id = model_->next_id(); |
| 1326 CHECK(!HasShelfIDToAppIDMapping(id)); | 1337 CHECK(!HasShelfIDToAppIDMapping(id)); |
| 1327 CHECK(controller); | 1338 CHECK(controller); |
| 1328 // Ash's ShelfWindowWatcher handles app panel windows separately. | 1339 // Ash's ShelfWindowWatcher handles app panel windows separately. |
| 1329 DCHECK_NE(ash::TYPE_APP_PANEL, controller->GetShelfItemType()); | 1340 DCHECK_NE(ash::TYPE_APP_PANEL, shelf_item_type); |
| 1330 id_to_item_controller_map_[id] = controller; | 1341 id_to_item_controller_map_[id] = controller; |
| 1331 controller->set_shelf_id(id); | 1342 controller->set_shelf_id(id); |
| 1332 | 1343 |
| 1333 ash::ShelfItem item; | 1344 ash::ShelfItem item; |
| 1334 item.type = shelf_item_type; | 1345 item.type = shelf_item_type; |
| 1335 item.image = extensions::util::GetDefaultAppIcon(); | 1346 item.image = extensions::util::GetDefaultAppIcon(); |
| 1336 | 1347 |
| 1337 ash::ShelfItemStatus new_state = GetAppState(app_id); | 1348 ash::ShelfItemStatus new_state = GetAppState(app_id); |
| 1338 if (new_state != ash::STATUS_CLOSED) | 1349 if (new_state != ash::STATUS_CLOSED) |
| 1339 status = new_state; | 1350 status = new_state; |
| 1340 | 1351 |
| 1341 item.status = status; | 1352 item.status = status; |
| 1342 model_->AddAt(index, item); | 1353 model_->AddAt(index, item); |
| 1343 | 1354 |
| 1344 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id); | 1355 AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app_id); |
| 1345 if (app_icon_loader) { | 1356 if (app_icon_loader) { |
| 1346 app_icon_loader->FetchImage(app_id); | 1357 app_icon_loader->FetchImage(app_id); |
| 1347 app_icon_loader->UpdateImage(app_id); | 1358 app_icon_loader->UpdateImage(app_id); |
| 1348 } | 1359 } |
| 1349 | 1360 |
| 1350 SetShelfItemDelegate(id, controller); | 1361 SetShelfItemDelegate(id, controller); |
| 1351 | 1362 |
| 1352 return id; | 1363 return id; |
| 1353 } | 1364 } |
| 1354 | 1365 |
| 1355 std::vector<content::WebContents*> | |
| 1356 ChromeLauncherControllerImpl::GetV1ApplicationsFromController( | |
| 1357 LauncherItemController* controller) { | |
| 1358 DCHECK(controller->type() == LauncherItemController::TYPE_SHORTCUT); | |
| 1359 AppShortcutLauncherItemController* app_controller = | |
| 1360 static_cast<AppShortcutLauncherItemController*>(controller); | |
| 1361 return app_controller->GetRunningApplications(); | |
| 1362 } | |
| 1363 | |
| 1364 void ChromeLauncherControllerImpl::CreateBrowserShortcutLauncherItem() { | 1366 void ChromeLauncherControllerImpl::CreateBrowserShortcutLauncherItem() { |
| 1365 ash::ShelfItem browser_shortcut; | 1367 ash::ShelfItem browser_shortcut; |
| 1366 browser_shortcut.type = ash::TYPE_BROWSER_SHORTCUT; | 1368 browser_shortcut.type = ash::TYPE_BROWSER_SHORTCUT; |
| 1367 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 1369 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 1368 browser_shortcut.image = *rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_32); | 1370 browser_shortcut.image = *rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_32); |
| 1369 ash::ShelfID id = model_->next_id(); | 1371 ash::ShelfID id = model_->next_id(); |
| 1370 model_->AddAt(0, browser_shortcut); | 1372 model_->AddAt(0, browser_shortcut); |
| 1371 id_to_item_controller_map_[id] = | 1373 id_to_item_controller_map_[id] = |
| 1372 new BrowserShortcutLauncherItemController(this, model_); | 1374 new BrowserShortcutLauncherItemController(this, model_); |
| 1373 id_to_item_controller_map_[id]->set_shelf_id(id); | 1375 id_to_item_controller_map_[id]->set_shelf_id(id); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1528 LauncherItemController* controller = GetLauncherItemController(item.id); | 1530 LauncherItemController* controller = GetLauncherItemController(item.id); |
| 1529 if (!controller || controller->image_set_by_controller()) | 1531 if (!controller || controller->image_set_by_controller()) |
| 1530 continue; | 1532 continue; |
| 1531 item.image = image; | 1533 item.image = image; |
| 1532 if (arc_deferred_launcher_) | 1534 if (arc_deferred_launcher_) |
| 1533 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image); | 1535 arc_deferred_launcher_->MaybeApplySpinningEffect(id, &item.image); |
| 1534 model_->Set(index, item); | 1536 model_->Set(index, item); |
| 1535 // It's possible we're waiting on more than one item, so don't break. | 1537 // It's possible we're waiting on more than one item, so don't break. |
| 1536 } | 1538 } |
| 1537 } | 1539 } |
| OLD | NEW |