| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/browser_shortcut_launcher_item_controll
er.h" | 5 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll
er.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "ash/common/shelf/shelf_model.h" | 9 #include "ash/common/shelf/shelf_model.h" |
| 10 #include "ash/shelf/shelf_delegate.h" | 10 #include "ash/shelf/shelf_delegate.h" |
| 11 #include "ash/shelf/shelf_util.h" | 11 #include "ash/shelf/shelf_util.h" |
| 12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 13 #include "ash/wm/window_util.h" | 13 #include "ash/wm/window_util.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" | 15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" |
| 16 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_browser.h
" | 16 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_browser.h
" |
| 17 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_tab.h" | 17 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_tab.h" |
| 18 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 18 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 19 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h" |
| 19 #include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h" | 20 #include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h" |
| 20 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" | 21 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" |
| 21 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
| 22 #include "chrome/browser/ui/browser_commands.h" | 23 #include "chrome/browser/ui/browser_commands.h" |
| 23 #include "chrome/browser/ui/browser_finder.h" | 24 #include "chrome/browser/ui/browser_finder.h" |
| 24 #include "chrome/browser/ui/browser_window.h" | 25 #include "chrome/browser/ui/browser_window.h" |
| 25 #include "chrome/browser/ui/chrome_pages.h" | 26 #include "chrome/browser/ui/chrome_pages.h" |
| 26 #include "chrome/browser/ui/settings_window_manager.h" | 27 #include "chrome/browser/ui/settings_window_manager.h" |
| 27 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 28 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 28 #include "chrome/browser/web_applications/web_app.h" | 29 #include "chrome/browser/web_applications/web_app.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 browser_item.status = browser_status; | 116 browser_item.status = browser_status; |
| 116 shelf_model_->Set(browser_index, browser_item); | 117 shelf_model_->Set(browser_index, browser_item); |
| 117 } | 118 } |
| 118 } | 119 } |
| 119 | 120 |
| 120 void BrowserShortcutLauncherItemController::SetShelfIDForBrowserWindowContents( | 121 void BrowserShortcutLauncherItemController::SetShelfIDForBrowserWindowContents( |
| 121 Browser* browser, | 122 Browser* browser, |
| 122 content::WebContents* web_contents) { | 123 content::WebContents* web_contents) { |
| 123 // We need to call SetShelfIDForWindow for V1 applications since they are | 124 // We need to call SetShelfIDForWindow for V1 applications since they are |
| 124 // content which might change and as such change the application type. | 125 // content which might change and as such change the application type. |
| 125 if (!browser || !launcher_controller()->IsBrowserFromActiveUser(browser) || | 126 if (!browser || !IsBrowserFromActiveUser(browser) || |
| 126 IsSettingsBrowser(browser)) | 127 IsSettingsBrowser(browser)) |
| 127 return; | 128 return; |
| 128 | 129 |
| 129 ash::SetShelfIDForWindow( | 130 ash::SetShelfIDForWindow( |
| 130 launcher_controller()->GetShelfIDForWebContents(web_contents), | 131 launcher_controller()->GetShelfIDForWebContents(web_contents), |
| 131 browser->window()->GetNativeWindow()); | 132 browser->window()->GetNativeWindow()); |
| 132 } | 133 } |
| 133 | 134 |
| 134 bool BrowserShortcutLauncherItemController::IsOpen() const { | 135 bool BrowserShortcutLauncherItemController::IsOpen() const { |
| 135 const BrowserList* browser_list = BrowserList::GetInstance(); | 136 const BrowserList* browser_list = BrowserList::GetInstance(); |
| 136 for (BrowserList::const_iterator it = browser_list->begin(); | 137 for (BrowserList::const_iterator it = browser_list->begin(); |
| 137 it != browser_list->end(); ++it) { | 138 it != browser_list->end(); ++it) { |
| 138 if (launcher_controller()->IsBrowserFromActiveUser(*it)) | 139 if (IsBrowserFromActiveUser(*it)) |
| 139 return true; | 140 return true; |
| 140 } | 141 } |
| 141 return false; | 142 return false; |
| 142 } | 143 } |
| 143 | 144 |
| 144 bool BrowserShortcutLauncherItemController::IsVisible() const { | 145 bool BrowserShortcutLauncherItemController::IsVisible() const { |
| 145 Browser* last_browser = | 146 Browser* last_browser = |
| 146 chrome::FindTabbedBrowser(launcher_controller()->GetProfile(), true); | 147 chrome::FindTabbedBrowser(launcher_controller()->GetProfile(), true); |
| 147 | 148 |
| 148 if (!last_browser) { | 149 if (!last_browser) { |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 } | 327 } |
| 327 DCHECK(browser); | 328 DCHECK(browser); |
| 328 browser->window()->Show(); | 329 browser->window()->Show(); |
| 329 browser->window()->Activate(); | 330 browser->window()->Activate(); |
| 330 return kExistingWindowActivated; | 331 return kExistingWindowActivated; |
| 331 } | 332 } |
| 332 | 333 |
| 333 bool BrowserShortcutLauncherItemController::IsBrowserRepresentedInBrowserList( | 334 bool BrowserShortcutLauncherItemController::IsBrowserRepresentedInBrowserList( |
| 334 Browser* browser) { | 335 Browser* browser) { |
| 335 // Only Ash desktop browser windows for the active user are represented. | 336 // Only Ash desktop browser windows for the active user are represented. |
| 336 if (!browser || !launcher_controller()->IsBrowserFromActiveUser(browser)) | 337 if (!browser || !IsBrowserFromActiveUser(browser)) |
| 337 return false; | 338 return false; |
| 338 | 339 |
| 339 // v1 App popup windows with a valid app id have their own icon. | 340 // v1 App popup windows with a valid app id have their own icon. |
| 340 if (browser->is_app() && | 341 if (browser->is_app() && |
| 341 browser->is_type_popup() && | 342 browser->is_type_popup() && |
| 342 ash::Shell::GetInstance()->GetShelfDelegate()->GetShelfIDForAppID( | 343 ash::Shell::GetInstance()->GetShelfDelegate()->GetShelfIDForAppID( |
| 343 web_app::GetExtensionIdFromApplicationName(browser->app_name())) > 0) | 344 web_app::GetExtensionIdFromApplicationName(browser->app_name())) > 0) |
| 344 return false; | 345 return false; |
| 345 | 346 |
| 346 // Settings browsers have their own icon. | 347 // Settings browsers have their own icon. |
| 347 if (IsSettingsBrowser(browser)) | 348 if (IsSettingsBrowser(browser)) |
| 348 return false; | 349 return false; |
| 349 | 350 |
| 350 // Tabbed browser and other popup windows are all represented. | 351 // Tabbed browser and other popup windows are all represented. |
| 351 return true; | 352 return true; |
| 352 } | 353 } |
| 353 | 354 |
| 354 BrowserList::BrowserVector | 355 BrowserList::BrowserVector |
| 355 BrowserShortcutLauncherItemController::GetListOfActiveBrowsers() { | 356 BrowserShortcutLauncherItemController::GetListOfActiveBrowsers() { |
| 356 BrowserList::BrowserVector active_browsers; | 357 BrowserList::BrowserVector active_browsers; |
| 357 for (auto* browser : *BrowserList::GetInstance()) { | 358 for (auto* browser : *BrowserList::GetInstance()) { |
| 358 // Make sure that the browser is from the current user, has a proper window, | 359 // Make sure that the browser is from the current user, has a proper window, |
| 359 // and the window was already shown. | 360 // and the window was already shown. |
| 360 if (!launcher_controller()->IsBrowserFromActiveUser(browser)) | 361 if (!IsBrowserFromActiveUser(browser)) |
| 361 continue; | 362 continue; |
| 362 if (!browser->window()->GetNativeWindow()->IsVisible() && | 363 if (!browser->window()->GetNativeWindow()->IsVisible() && |
| 363 !browser->window()->IsMinimized()) { | 364 !browser->window()->IsMinimized()) { |
| 364 continue; | 365 continue; |
| 365 } | 366 } |
| 366 if (!IsBrowserRepresentedInBrowserList(browser) && | 367 if (!IsBrowserRepresentedInBrowserList(browser) && |
| 367 !browser->is_type_tabbed()) | 368 !browser->is_type_tabbed()) |
| 368 continue; | 369 continue; |
| 369 active_browsers.push_back(browser); | 370 active_browsers.push_back(browser); |
| 370 } | 371 } |
| 371 return active_browsers; | 372 return active_browsers; |
| 372 } | 373 } |
| OLD | NEW |