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

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

Issue 23534022: Handling browser item status in BrowserShortcutLauncherItemController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 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.h" 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "ash/ash_switches.h" 9 #include "ash/ash_switches.h"
10 #include "ash/launcher/launcher.h" 10 #include "ash/launcher/launcher.h"
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 void ChromeLauncherController::SetItemStatus( 341 void ChromeLauncherController::SetItemStatus(
342 ash::LauncherID id, 342 ash::LauncherID id,
343 ash::LauncherItemStatus status) { 343 ash::LauncherItemStatus status) {
344 int index = model_->ItemIndexByID(id); 344 int index = model_->ItemIndexByID(id);
345 // Since ordinary browser windows are not registered, we might get a negative 345 // Since ordinary browser windows are not registered, we might get a negative
346 // index here. 346 // index here.
347 if (index >= 0) { 347 if (index >= 0) {
348 ash::LauncherItem item = model_->items()[index]; 348 ash::LauncherItem item = model_->items()[index];
349 item.status = status; 349 item.status = status;
350 model_->Set(index, item); 350 model_->Set(index, item);
351
352 if (model_->items()[index].type == ash::TYPE_BROWSER_SHORTCUT)
353 return;
354 } 351 }
355 UpdateBrowserItemStatus();
356 } 352 }
357 353
358 void ChromeLauncherController::SetItemController( 354 void ChromeLauncherController::SetItemController(
359 ash::LauncherID id, 355 ash::LauncherID id,
360 LauncherItemController* controller) { 356 LauncherItemController* controller) {
361 CHECK(controller); 357 CHECK(controller);
362 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); 358 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id);
363 CHECK(iter != id_to_item_controller_map_.end()); 359 CHECK(iter != id_to_item_controller_map_.end());
364 iter->second->OnRemoved(); 360 iter->second->OnRemoved();
365 iter->second = controller; 361 iter->second = controller;
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 app_id = kGmailAppId; 808 app_id = kGmailAppId;
813 809
814 // Check the old |app_id| for a tab. If the contents has changed we need to 810 // Check the old |app_id| for a tab. If the contents has changed we need to
815 // remove it from the previous app. 811 // remove it from the previous app.
816 if (web_contents_to_app_id_.find(contents) != web_contents_to_app_id_.end()) { 812 if (web_contents_to_app_id_.find(contents) != web_contents_to_app_id_.end()) {
817 std::string last_app_id = web_contents_to_app_id_[contents]; 813 std::string last_app_id = web_contents_to_app_id_[contents];
818 if (last_app_id != app_id) 814 if (last_app_id != app_id)
819 RemoveTabFromRunningApp(contents, last_app_id); 815 RemoveTabFromRunningApp(contents, last_app_id);
820 } 816 }
821 817
822 if (app_id.empty()) {
823 // Even if there is no application running, we should update the activation
824 // state of the associated browser.
825 UpdateBrowserItemStatus();
826 return;
827 }
828
829 web_contents_to_app_id_[contents] = app_id; 818 web_contents_to_app_id_[contents] = app_id;
830 819
831 if (app_state == APP_STATE_REMOVED) { 820 if (app_state == APP_STATE_REMOVED) {
832 // The tab has gone away. 821 // The tab has gone away.
833 RemoveTabFromRunningApp(contents, app_id); 822 RemoveTabFromRunningApp(contents, app_id);
834 } else { 823 } else {
835 WebContentsList& tab_list(app_id_to_web_contents_list_[app_id]); 824 WebContentsList& tab_list(app_id_to_web_contents_list_[app_id]);
836 825
837 if (app_state == APP_STATE_INACTIVE) { 826 if (app_state == APP_STATE_INACTIVE) {
838 WebContentsList::const_iterator i_tab = 827 WebContentsList::const_iterator i_tab =
839 std::find(tab_list.begin(), tab_list.end(), contents); 828 std::find(tab_list.begin(), tab_list.end(), contents);
840 if (i_tab == tab_list.end()) 829 if (i_tab == tab_list.end())
841 tab_list.push_back(contents); 830 tab_list.push_back(contents);
842 if (i_tab != tab_list.begin()) { 831 if (i_tab != tab_list.begin()) {
843 // Going inactive, but wasn't the front tab, indicating that a new 832 // Going inactive, but wasn't the front tab, indicating that a new
844 // tab has already become active. 833 // tab has already become active.
845 return; 834 return;
846 } 835 }
847 } else { 836 } else {
848 tab_list.remove(contents); 837 tab_list.remove(contents);
849 tab_list.push_front(contents); 838 tab_list.push_front(contents);
850 } 839 }
851 ash::LauncherID id = GetLauncherIDForAppID(app_id); 840 ash::LauncherID id = GetLauncherIDForAppID(app_id);
852 if (id) { 841 if (id) {
853 // If the window is active, mark the app as active. 842 // If the window is active, mark the app as active.
854 SetItemStatus(id, app_state == APP_STATE_WINDOW_ACTIVE ? 843 SetItemStatus(id, app_state == APP_STATE_WINDOW_ACTIVE ?
855 ash::STATUS_ACTIVE : ash::STATUS_RUNNING); 844 ash::STATUS_ACTIVE : ash::STATUS_RUNNING);
856 } 845 }
857 } 846 }
858 UpdateBrowserItemStatus();
859 } 847 }
860 848
861 void ChromeLauncherController::SetRefocusURLPatternForTest(ash::LauncherID id, 849 void ChromeLauncherController::SetRefocusURLPatternForTest(ash::LauncherID id,
862 const GURL& url) { 850 const GURL& url) {
863 DCHECK(HasItemController(id)); 851 DCHECK(HasItemController(id));
864 LauncherItemController* controller = id_to_item_controller_map_[id]; 852 LauncherItemController* controller = id_to_item_controller_map_[id];
865 853
866 int index = model_->ItemIndexByID(id); 854 int index = model_->ItemIndexByID(id);
867 if (index == -1) { 855 if (index == -1) {
868 NOTREACHED() << "Invalid launcher id"; 856 NOTREACHED() << "Invalid launcher id";
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
1229 const std::string& app_id, 1217 const std::string& app_id,
1230 int index, 1218 int index,
1231 ash::LauncherItemType launcher_item_type) { 1219 ash::LauncherItemType launcher_item_type) {
1232 AppShortcutLauncherItemController* controller = 1220 AppShortcutLauncherItemController* controller =
1233 new AppShortcutLauncherItemController(app_id, this); 1221 new AppShortcutLauncherItemController(app_id, this);
1234 ash::LauncherID launcher_id = InsertAppLauncherItem( 1222 ash::LauncherID launcher_id = InsertAppLauncherItem(
1235 controller, app_id, ash::STATUS_CLOSED, index, launcher_item_type); 1223 controller, app_id, ash::STATUS_CLOSED, index, launcher_item_type);
1236 return launcher_id; 1224 return launcher_id;
1237 } 1225 }
1238 1226
1239 void ChromeLauncherController::UpdateBrowserItemStatus() {
1240 // This check needs for win7_aura. UpdateBrowserItemStatus() access Shell.
1241 // Without this ChromeLauncherControllerTest.BrowserMenuGeneration test will
1242 // fail.
1243 if (!ash::Shell::HasInstance())
1244 return;
1245
1246 // Determine the new browser's active state and change if necessary.
1247 size_t browser_index = ash::launcher::GetBrowserItemIndex(*model_);
1248 DCHECK_GE(browser_index, 0u);
1249 ash::LauncherItem browser_item = model_->items()[browser_index];
1250 ash::LauncherItemStatus browser_status = ash::STATUS_CLOSED;
1251
1252 aura::Window* window = ash::wm::GetActiveWindow();
1253 if (window) {
1254 // Check if the active browser / tab is a browser which is not an app,
1255 // a windowed app, a popup or any other item which is not a browser of
1256 // interest.
1257 Browser* browser = chrome::FindBrowserWithWindow(window);
1258 if (IsBrowserRepresentedInBrowserList(browser)) {
1259 browser_status = ash::STATUS_ACTIVE;
1260 const ash::LauncherItems& items = model_->items();
1261 // If another launcher item has claimed to be active, we don't.
1262 for (size_t i = 0;
1263 i < items.size() && browser_status == ash::STATUS_ACTIVE; ++i) {
1264 if (i != browser_index && items[i].status == ash::STATUS_ACTIVE)
1265 browser_status = ash::STATUS_RUNNING;
1266 }
1267 }
1268 }
1269
1270 if (browser_status == ash::STATUS_CLOSED) {
1271 const BrowserList* ash_browser_list =
1272 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
1273 for (BrowserList::const_reverse_iterator it =
1274 ash_browser_list->begin_last_active();
1275 it != ash_browser_list->end_last_active() &&
1276 browser_status == ash::STATUS_CLOSED; ++it) {
1277 if (IsBrowserRepresentedInBrowserList(*it))
1278 browser_status = ash::STATUS_RUNNING;
1279 }
1280 }
1281
1282 if (browser_status != browser_item.status) {
1283 browser_item.status = browser_status;
1284 model_->Set(browser_index, browser_item);
1285 }
1286 }
1287
1288 Profile* ChromeLauncherController::GetProfileForNewWindows() { 1227 Profile* ChromeLauncherController::GetProfileForNewWindows() {
1289 return ProfileManager::GetDefaultProfileOrOffTheRecord(); 1228 return ProfileManager::GetDefaultProfileOrOffTheRecord();
1290 } 1229 }
1291 1230
1292 void ChromeLauncherController::LauncherItemClosed(ash::LauncherID id) { 1231 void ChromeLauncherController::LauncherItemClosed(ash::LauncherID id) {
1293 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); 1232 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id);
1294 CHECK(iter != id_to_item_controller_map_.end()); 1233 CHECK(iter != id_to_item_controller_map_.end());
1295 CHECK(iter->second); 1234 CHECK(iter->second);
1296 app_icon_loader_->ClearImage(iter->second->app_id()); 1235 app_icon_loader_->ClearImage(iter->second->app_id());
1297 iter->second->OnRemoved(); 1236 iter->second->OnRemoved();
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
1549 1488
1550 std::vector<content::WebContents*> 1489 std::vector<content::WebContents*>
1551 ChromeLauncherController::GetV1ApplicationsFromController( 1490 ChromeLauncherController::GetV1ApplicationsFromController(
1552 LauncherItemController* controller) { 1491 LauncherItemController* controller) {
1553 DCHECK(controller->type() == LauncherItemController::TYPE_SHORTCUT); 1492 DCHECK(controller->type() == LauncherItemController::TYPE_SHORTCUT);
1554 AppShortcutLauncherItemController* app_controller = 1493 AppShortcutLauncherItemController* app_controller =
1555 static_cast<AppShortcutLauncherItemController*>(controller); 1494 static_cast<AppShortcutLauncherItemController*>(controller);
1556 return app_controller->GetRunningApplications(); 1495 return app_controller->GetRunningApplications();
1557 } 1496 }
1558 1497
1559 bool ChromeLauncherController::IsBrowserRepresentedInBrowserList( 1498 BrowserShortcutLauncherItemController*
1560 Browser* browser) {
1561 return (browser &&
1562 (browser->is_type_tabbed() ||
1563 !browser->is_app() ||
1564 !browser->is_type_popup() ||
1565 GetLauncherIDForAppID(web_app::GetExtensionIdFromApplicationName(
1566 browser->app_name())) <= 0));
1567 }
1568
1569 LauncherItemController*
1570 ChromeLauncherController::GetBrowserShortcutLauncherItemController() { 1499 ChromeLauncherController::GetBrowserShortcutLauncherItemController() {
1571 for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin(); 1500 for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin();
1572 i != id_to_item_controller_map_.end(); ++i) { 1501 i != id_to_item_controller_map_.end(); ++i) {
1573 int index = model_->ItemIndexByID(i->first); 1502 int index = model_->ItemIndexByID(i->first);
1574 const ash::LauncherItem& item = model_->items()[index]; 1503 const ash::LauncherItem& item = model_->items()[index];
1575 if (item.type == ash::TYPE_BROWSER_SHORTCUT) 1504 if (item.type == ash::TYPE_BROWSER_SHORTCUT)
1576 return i->second; 1505 return static_cast<BrowserShortcutLauncherItemController*>(i->second);
1577 } 1506 }
1578 // LauncerItemController For Browser Shortcut must be existed. If it does not 1507 // LauncerItemController For Browser Shortcut must be existed. If it does not
1579 // existe create it. 1508 // exist, create it.
Mr4D (OOO till 08-26) 2013/09/04 15:12:33 What about: // Create a LauncherItemController fo
simonhong_ 2013/09/04 17:08:31 Done.
1580 ash::LauncherID id = CreateBrowserShortcutLauncherItem(); 1509 ash::LauncherID id = CreateBrowserShortcutLauncherItem();
1581 DCHECK(id_to_item_controller_map_[id]); 1510 DCHECK(id_to_item_controller_map_[id]);
1582 return id_to_item_controller_map_[id]; 1511 return static_cast<BrowserShortcutLauncherItemController*>(
1512 id_to_item_controller_map_[id]);
1583 } 1513 }
1584 1514
1585 ash::LauncherID ChromeLauncherController::CreateBrowserShortcutLauncherItem() { 1515 ash::LauncherID ChromeLauncherController::CreateBrowserShortcutLauncherItem() {
1586 ash::LauncherItem browser_shortcut; 1516 ash::LauncherItem browser_shortcut;
1587 browser_shortcut.type = ash::TYPE_BROWSER_SHORTCUT; 1517 browser_shortcut.type = ash::TYPE_BROWSER_SHORTCUT;
1588 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 1518 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
1589 browser_shortcut.image = *rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_32); 1519 browser_shortcut.image = *rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_32);
1590 ash::LauncherID id = model_->next_id(); 1520 ash::LauncherID id = model_->next_id();
1591 size_t index = GetChromeIconIndexFromPref(); 1521 size_t index = GetChromeIconIndexFromPref();
1592 model_->AddAt(index, browser_shortcut); 1522 model_->AddAt(index, browser_shortcut);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1656 // TODO(simon.hong81): Register LauncherItemDelegate when LauncherItemDelegate 1586 // TODO(simon.hong81): Register LauncherItemDelegate when LauncherItemDelegate
1657 // is created. 1587 // is created.
1658 ash::LauncherItemDelegateManager* manager = 1588 ash::LauncherItemDelegateManager* manager =
1659 ash::Shell::GetInstance()->launcher_item_delegate_manager(); 1589 ash::Shell::GetInstance()->launcher_item_delegate_manager();
1660 manager->RegisterLauncherItemDelegate(ash::TYPE_APP_PANEL, this); 1590 manager->RegisterLauncherItemDelegate(ash::TYPE_APP_PANEL, this);
1661 manager->RegisterLauncherItemDelegate(ash::TYPE_APP_SHORTCUT, this); 1591 manager->RegisterLauncherItemDelegate(ash::TYPE_APP_SHORTCUT, this);
1662 manager->RegisterLauncherItemDelegate(ash::TYPE_BROWSER_SHORTCUT, this); 1592 manager->RegisterLauncherItemDelegate(ash::TYPE_BROWSER_SHORTCUT, this);
1663 manager->RegisterLauncherItemDelegate(ash::TYPE_PLATFORM_APP, this); 1593 manager->RegisterLauncherItemDelegate(ash::TYPE_PLATFORM_APP, this);
1664 manager->RegisterLauncherItemDelegate(ash::TYPE_WINDOWED_APP, this); 1594 manager->RegisterLauncherItemDelegate(ash::TYPE_WINDOWED_APP, this);
1665 } 1595 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698