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

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: CreateAppAndBrowserState() 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
« no previous file with comments | « chrome/browser/ui/ash/launcher/chrome_launcher_controller.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
1226 const std::string& app_id, 1214 const std::string& app_id,
1227 int index, 1215 int index,
1228 ash::LauncherItemType launcher_item_type) { 1216 ash::LauncherItemType launcher_item_type) {
1229 AppShortcutLauncherItemController* controller = 1217 AppShortcutLauncherItemController* controller =
1230 new AppShortcutLauncherItemController(app_id, this); 1218 new AppShortcutLauncherItemController(app_id, this);
1231 ash::LauncherID launcher_id = InsertAppLauncherItem( 1219 ash::LauncherID launcher_id = InsertAppLauncherItem(
1232 controller, app_id, ash::STATUS_CLOSED, index, launcher_item_type); 1220 controller, app_id, ash::STATUS_CLOSED, index, launcher_item_type);
1233 return launcher_id; 1221 return launcher_id;
1234 } 1222 }
1235 1223
1236 void ChromeLauncherController::UpdateBrowserItemStatus() {
1237 // This check needs for win7_aura. UpdateBrowserItemStatus() access Shell.
1238 // Without this ChromeLauncherControllerTest.BrowserMenuGeneration test will
1239 // fail.
1240 if (!ash::Shell::HasInstance())
1241 return;
1242
1243 // Determine the new browser's active state and change if necessary.
1244 size_t browser_index = ash::launcher::GetBrowserItemIndex(*model_);
1245 DCHECK_GE(browser_index, 0u);
1246 ash::LauncherItem browser_item = model_->items()[browser_index];
1247 ash::LauncherItemStatus browser_status = ash::STATUS_CLOSED;
1248
1249 aura::Window* window = ash::wm::GetActiveWindow();
1250 if (window) {
1251 // Check if the active browser / tab is a browser which is not an app,
1252 // a windowed app, a popup or any other item which is not a browser of
1253 // interest.
1254 Browser* browser = chrome::FindBrowserWithWindow(window);
1255 if (IsBrowserRepresentedInBrowserList(browser)) {
1256 browser_status = ash::STATUS_ACTIVE;
1257 const ash::LauncherItems& items = model_->items();
1258 // If another launcher item has claimed to be active, we don't.
1259 for (size_t i = 0;
1260 i < items.size() && browser_status == ash::STATUS_ACTIVE; ++i) {
1261 if (i != browser_index && items[i].status == ash::STATUS_ACTIVE)
1262 browser_status = ash::STATUS_RUNNING;
1263 }
1264 }
1265 }
1266
1267 if (browser_status == ash::STATUS_CLOSED) {
1268 const BrowserList* ash_browser_list =
1269 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
1270 for (BrowserList::const_reverse_iterator it =
1271 ash_browser_list->begin_last_active();
1272 it != ash_browser_list->end_last_active() &&
1273 browser_status == ash::STATUS_CLOSED; ++it) {
1274 if (IsBrowserRepresentedInBrowserList(*it))
1275 browser_status = ash::STATUS_RUNNING;
1276 }
1277 }
1278
1279 if (browser_status != browser_item.status) {
1280 browser_item.status = browser_status;
1281 model_->Set(browser_index, browser_item);
1282 }
1283 }
1284
1285 Profile* ChromeLauncherController::GetProfileForNewWindows() { 1224 Profile* ChromeLauncherController::GetProfileForNewWindows() {
1286 return ProfileManager::GetDefaultProfileOrOffTheRecord(); 1225 return ProfileManager::GetDefaultProfileOrOffTheRecord();
1287 } 1226 }
1288 1227
1289 void ChromeLauncherController::LauncherItemClosed(ash::LauncherID id) { 1228 void ChromeLauncherController::LauncherItemClosed(ash::LauncherID id) {
1290 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id); 1229 IDToItemControllerMap::iterator iter = id_to_item_controller_map_.find(id);
1291 CHECK(iter != id_to_item_controller_map_.end()); 1230 CHECK(iter != id_to_item_controller_map_.end());
1292 CHECK(iter->second); 1231 CHECK(iter->second);
1293 app_icon_loader_->ClearImage(iter->second->app_id()); 1232 app_icon_loader_->ClearImage(iter->second->app_id());
1294 iter->second->OnRemoved(); 1233 iter->second->OnRemoved();
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
1546 1485
1547 std::vector<content::WebContents*> 1486 std::vector<content::WebContents*>
1548 ChromeLauncherController::GetV1ApplicationsFromController( 1487 ChromeLauncherController::GetV1ApplicationsFromController(
1549 LauncherItemController* controller) { 1488 LauncherItemController* controller) {
1550 DCHECK(controller->type() == LauncherItemController::TYPE_SHORTCUT); 1489 DCHECK(controller->type() == LauncherItemController::TYPE_SHORTCUT);
1551 AppShortcutLauncherItemController* app_controller = 1490 AppShortcutLauncherItemController* app_controller =
1552 static_cast<AppShortcutLauncherItemController*>(controller); 1491 static_cast<AppShortcutLauncherItemController*>(controller);
1553 return app_controller->GetRunningApplications(); 1492 return app_controller->GetRunningApplications();
1554 } 1493 }
1555 1494
1556 bool ChromeLauncherController::IsBrowserRepresentedInBrowserList( 1495 BrowserShortcutLauncherItemController*
1557 Browser* browser) {
1558 return (browser &&
1559 (browser->is_type_tabbed() ||
1560 !browser->is_app() ||
1561 !browser->is_type_popup() ||
1562 GetLauncherIDForAppID(web_app::GetExtensionIdFromApplicationName(
1563 browser->app_name())) <= 0));
1564 }
1565
1566 LauncherItemController*
1567 ChromeLauncherController::GetBrowserShortcutLauncherItemController() { 1496 ChromeLauncherController::GetBrowserShortcutLauncherItemController() {
1568 for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin(); 1497 for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin();
1569 i != id_to_item_controller_map_.end(); ++i) { 1498 i != id_to_item_controller_map_.end(); ++i) {
1570 int index = model_->ItemIndexByID(i->first); 1499 int index = model_->ItemIndexByID(i->first);
1571 const ash::LauncherItem& item = model_->items()[index]; 1500 const ash::LauncherItem& item = model_->items()[index];
1572 if (item.type == ash::TYPE_BROWSER_SHORTCUT) 1501 if (item.type == ash::TYPE_BROWSER_SHORTCUT)
1573 return i->second; 1502 return static_cast<BrowserShortcutLauncherItemController*>(i->second);
1574 } 1503 }
1575 // LauncerItemController For Browser Shortcut must be existed. If it does not 1504 // Create a LauncherItemController for the Browser shortcut if it does not
1576 // existe create it. 1505 // exist yet.
1577 ash::LauncherID id = CreateBrowserShortcutLauncherItem(); 1506 ash::LauncherID id = CreateBrowserShortcutLauncherItem();
1578 DCHECK(id_to_item_controller_map_[id]); 1507 DCHECK(id_to_item_controller_map_[id]);
1579 return id_to_item_controller_map_[id]; 1508 return static_cast<BrowserShortcutLauncherItemController*>(
1509 id_to_item_controller_map_[id]);
1580 } 1510 }
1581 1511
1582 ash::LauncherID ChromeLauncherController::CreateBrowserShortcutLauncherItem() { 1512 ash::LauncherID ChromeLauncherController::CreateBrowserShortcutLauncherItem() {
1583 ash::LauncherItem browser_shortcut; 1513 ash::LauncherItem browser_shortcut;
1584 browser_shortcut.type = ash::TYPE_BROWSER_SHORTCUT; 1514 browser_shortcut.type = ash::TYPE_BROWSER_SHORTCUT;
1585 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 1515 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
1586 browser_shortcut.image = *rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_32); 1516 browser_shortcut.image = *rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_32);
1587 ash::LauncherID id = model_->next_id(); 1517 ash::LauncherID id = model_->next_id();
1588 size_t index = GetChromeIconIndexFromPref(); 1518 size_t index = GetChromeIconIndexFromPref();
1589 model_->AddAt(index, browser_shortcut); 1519 model_->AddAt(index, browser_shortcut);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1653 // TODO(simon.hong81): Register LauncherItemDelegate when LauncherItemDelegate 1583 // TODO(simon.hong81): Register LauncherItemDelegate when LauncherItemDelegate
1654 // is created. 1584 // is created.
1655 ash::LauncherItemDelegateManager* manager = 1585 ash::LauncherItemDelegateManager* manager =
1656 ash::Shell::GetInstance()->launcher_item_delegate_manager(); 1586 ash::Shell::GetInstance()->launcher_item_delegate_manager();
1657 manager->RegisterLauncherItemDelegate(ash::TYPE_APP_PANEL, this); 1587 manager->RegisterLauncherItemDelegate(ash::TYPE_APP_PANEL, this);
1658 manager->RegisterLauncherItemDelegate(ash::TYPE_APP_SHORTCUT, this); 1588 manager->RegisterLauncherItemDelegate(ash::TYPE_APP_SHORTCUT, this);
1659 manager->RegisterLauncherItemDelegate(ash::TYPE_BROWSER_SHORTCUT, this); 1589 manager->RegisterLauncherItemDelegate(ash::TYPE_BROWSER_SHORTCUT, this);
1660 manager->RegisterLauncherItemDelegate(ash::TYPE_PLATFORM_APP, this); 1590 manager->RegisterLauncherItemDelegate(ash::TYPE_PLATFORM_APP, this);
1661 manager->RegisterLauncherItemDelegate(ash::TYPE_WINDOWED_APP, this); 1591 manager->RegisterLauncherItemDelegate(ash::TYPE_WINDOWED_APP, this);
1662 } 1592 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/launcher/chrome_launcher_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698