Chromium Code Reviews| 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/launcher/launcher.h" | 9 #include "ash/launcher/launcher.h" |
| 10 #include "ash/launcher/launcher_model.h" | |
| 11 #include "ash/launcher/launcher_util.h" | |
| 10 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 11 #include "ash/wm/window_util.h" | 13 #include "ash/wm/window_util.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 13 #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" |
| 14 #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 " |
| 15 #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" |
| 16 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 18 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 17 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
| 18 #include "chrome/browser/ui/browser_finder.h" | 20 #include "chrome/browser/ui/browser_finder.h" |
| 19 #include "chrome/browser/ui/browser_list.h" | 21 #include "chrome/browser/ui/browser_list.h" |
| 20 #include "chrome/browser/ui/browser_window.h" | 22 #include "chrome/browser/ui/browser_window.h" |
| 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 23 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 24 #include "chrome/browser/web_applications/web_app.h" | |
| 22 #include "chrome/common/extensions/extension_constants.h" | 25 #include "chrome/common/extensions/extension_constants.h" |
| 23 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
| 24 #include "grit/ash_resources.h" | 27 #include "grit/ash_resources.h" |
| 25 #include "grit/chromium_strings.h" | 28 #include "grit/chromium_strings.h" |
| 26 #include "grit/generated_resources.h" | 29 #include "grit/generated_resources.h" |
| 27 #include "ui/aura/window.h" | 30 #include "ui/aura/window.h" |
| 28 #include "ui/base/events/event.h" | 31 #include "ui/base/events/event.h" |
| 29 #include "ui/base/l10n/l10n_util.h" | 32 #include "ui/base/l10n/l10n_util.h" |
| 30 #include "ui/base/resource/resource_bundle.h" | 33 #include "ui/base/resource/resource_bundle.h" |
| 31 #include "ui/gfx/image/image.h" | 34 #include "ui/gfx/image/image.h" |
| 32 #include "ui/views/corewm/window_animations.h" | 35 #include "ui/views/corewm/window_animations.h" |
| 33 | 36 |
| 34 #if defined(OS_CHROMEOS) | 37 #if defined(OS_CHROMEOS) |
| 35 #include "chrome/browser/chromeos/login/default_pinned_apps_field_trial.h" | 38 #include "chrome/browser/chromeos/login/default_pinned_apps_field_trial.h" |
| 36 #endif | 39 #endif |
| 37 | 40 |
| 38 BrowserShortcutLauncherItemController::BrowserShortcutLauncherItemController( | 41 BrowserShortcutLauncherItemController::BrowserShortcutLauncherItemController( |
| 39 ChromeLauncherController* launcher_controller, | 42 ChromeLauncherController* launcher_controller, |
| 40 Profile* profile) | 43 Profile* profile) |
| 41 : LauncherItemController(TYPE_SHORTCUT, | 44 : LauncherItemController(TYPE_SHORTCUT, |
| 42 extension_misc::kChromeAppId, | 45 extension_misc::kChromeAppId, |
| 43 launcher_controller), | 46 launcher_controller), |
| 44 profile_(profile) { | 47 profile_(profile) { |
| 45 } | 48 } |
| 46 | 49 |
| 47 BrowserShortcutLauncherItemController:: | 50 BrowserShortcutLauncherItemController:: |
| 48 ~BrowserShortcutLauncherItemController() { | 51 ~BrowserShortcutLauncherItemController() { |
| 49 } | 52 } |
| 50 | 53 |
| 54 void BrowserShortcutLauncherItemController::UpdateBrowserItemStatus() { | |
| 55 // This check needs for win7_aura. UpdateBrowserItemStatus() access Shell. | |
|
Mr4D (OOO till 08-26)
2013/09/04 15:12:33
Maybe something like:
// The shell will not be av
simonhong_
2013/09/04 17:08:31
Done.
| |
| 56 // Without this ChromeLauncherControllerTest.BrowserMenuGeneration test will | |
| 57 // fail. | |
| 58 if (!ash::Shell::HasInstance()) | |
| 59 return; | |
| 60 | |
| 61 ash::LauncherModel* model = launcher_controller()->model(); | |
| 62 | |
| 63 // Determine the new browser's active state and change if necessary. | |
| 64 size_t browser_index = ash::launcher::GetBrowserItemIndex(*model); | |
| 65 DCHECK_GE(browser_index, 0u); | |
| 66 ash::LauncherItem browser_item = model->items()[browser_index]; | |
| 67 ash::LauncherItemStatus browser_status = ash::STATUS_CLOSED; | |
| 68 | |
| 69 aura::Window* window = ash::wm::GetActiveWindow(); | |
| 70 if (window) { | |
| 71 // Check if the active browser / tab is a browser which is not an app, | |
| 72 // a windowed app, a popup or any other item which is not a browser of | |
| 73 // interest. | |
| 74 Browser* browser = chrome::FindBrowserWithWindow(window); | |
| 75 if (IsBrowserRepresentedInBrowserList(browser)) { | |
| 76 browser_status = ash::STATUS_ACTIVE; | |
| 77 // If an app is running in active window, browser item status cannot be | |
| 78 // active. | |
| 79 if (launcher_controller()->GetIDByWindow(window) != browser_item.id) | |
| 80 browser_status = ash::STATUS_RUNNING; | |
| 81 } | |
| 82 } | |
| 83 | |
| 84 if (browser_status == ash::STATUS_CLOSED) { | |
| 85 const BrowserList* ash_browser_list = | |
| 86 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); | |
| 87 for (BrowserList::const_reverse_iterator it = | |
| 88 ash_browser_list->begin_last_active(); | |
| 89 it != ash_browser_list->end_last_active() && | |
| 90 browser_status == ash::STATUS_CLOSED; ++it) { | |
| 91 if (IsBrowserRepresentedInBrowserList(*it)) | |
| 92 browser_status = ash::STATUS_RUNNING; | |
| 93 } | |
| 94 } | |
| 95 | |
| 96 if (browser_status != browser_item.status) { | |
| 97 browser_item.status = browser_status; | |
| 98 model->Set(browser_index, browser_item); | |
| 99 } | |
| 100 } | |
| 101 | |
| 51 string16 BrowserShortcutLauncherItemController::GetTitle() { | 102 string16 BrowserShortcutLauncherItemController::GetTitle() { |
| 52 return l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); | 103 return l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); |
| 53 } | 104 } |
| 54 | 105 |
| 55 bool BrowserShortcutLauncherItemController::IsCurrentlyShownInWindow( | 106 bool BrowserShortcutLauncherItemController::IsCurrentlyShownInWindow( |
| 56 aura::Window* window) const { | 107 aura::Window* window) const { |
| 57 const BrowserList* ash_browser_list = | 108 const BrowserList* ash_browser_list = |
| 58 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); | 109 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); |
| 59 for (BrowserList::const_iterator it = ash_browser_list->begin(); | 110 for (BrowserList::const_iterator it = ash_browser_list->begin(); |
| 60 it != ash_browser_list->end(); ++it) { | 111 it != ash_browser_list->end(); ++it) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 it != ash_browser_list->end(); ++it) { | 201 it != ash_browser_list->end(); ++it) { |
| 151 Browser* browser = *it; | 202 Browser* browser = *it; |
| 152 // Make sure that the browser was already shown and it has a proper window. | 203 // Make sure that the browser was already shown and it has a proper window. |
| 153 if (std::find(ash_browser_list->begin_last_active(), | 204 if (std::find(ash_browser_list->begin_last_active(), |
| 154 ash_browser_list->end_last_active(), | 205 ash_browser_list->end_last_active(), |
| 155 browser) == ash_browser_list->end_last_active() || | 206 browser) == ash_browser_list->end_last_active() || |
| 156 !browser->window()) | 207 !browser->window()) |
| 157 continue; | 208 continue; |
| 158 if (browser->is_type_tabbed()) | 209 if (browser->is_type_tabbed()) |
| 159 found_tabbed_browser = true; | 210 found_tabbed_browser = true; |
| 160 else if (!launcher_controller()->IsBrowserRepresentedInBrowserList(browser)) | 211 else if (!IsBrowserRepresentedInBrowserList(browser)) |
| 161 continue; | 212 continue; |
| 162 TabStripModel* tab_strip = browser->tab_strip_model(); | 213 TabStripModel* tab_strip = browser->tab_strip_model(); |
| 163 if (tab_strip->active_index() == -1) | 214 if (tab_strip->active_index() == -1) |
| 164 continue; | 215 continue; |
| 165 if (!(event_flags & ui::EF_SHIFT_DOWN)) { | 216 if (!(event_flags & ui::EF_SHIFT_DOWN)) { |
| 166 content::WebContents* web_contents = | 217 content::WebContents* web_contents = |
| 167 tab_strip->GetWebContentsAt(tab_strip->active_index()); | 218 tab_strip->GetWebContentsAt(tab_strip->active_index()); |
| 168 gfx::Image app_icon = GetBrowserListIcon(web_contents); | 219 gfx::Image app_icon = GetBrowserListIcon(web_contents); |
| 169 string16 title = GetBrowserListTitle(web_contents); | 220 string16 title = GetBrowserListTitle(web_contents); |
| 170 items.push_back(new ChromeLauncherAppMenuItemBrowser( | 221 items.push_back(new ChromeLauncherAppMenuItemBrowser( |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 void BrowserShortcutLauncherItemController::ActivateOrAdvanceToNextBrowser() { | 267 void BrowserShortcutLauncherItemController::ActivateOrAdvanceToNextBrowser() { |
| 217 // Create a list of all suitable running browsers. | 268 // Create a list of all suitable running browsers. |
| 218 std::vector<Browser*> items; | 269 std::vector<Browser*> items; |
| 219 // We use the list in the order of how the browsers got created - not the LRU | 270 // We use the list in the order of how the browsers got created - not the LRU |
| 220 // order. | 271 // order. |
| 221 const BrowserList* ash_browser_list = | 272 const BrowserList* ash_browser_list = |
| 222 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); | 273 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); |
| 223 for (BrowserList::const_iterator it = | 274 for (BrowserList::const_iterator it = |
| 224 ash_browser_list->begin(); | 275 ash_browser_list->begin(); |
| 225 it != ash_browser_list->end(); ++it) { | 276 it != ash_browser_list->end(); ++it) { |
| 226 if (launcher_controller()->IsBrowserRepresentedInBrowserList(*it)) | 277 if (IsBrowserRepresentedInBrowserList(*it)) |
| 227 items.push_back(*it); | 278 items.push_back(*it); |
| 228 } | 279 } |
| 229 // If there are no suitable browsers we create a new one. | 280 // If there are no suitable browsers we create a new one. |
| 230 if (!items.size()) { | 281 if (!items.size()) { |
| 231 launcher_controller()->CreateNewWindow(); | 282 launcher_controller()->CreateNewWindow(); |
| 232 return; | 283 return; |
| 233 } | 284 } |
| 234 Browser* browser = chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow()); | 285 Browser* browser = chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow()); |
| 235 if (items.size() == 1) { | 286 if (items.size() == 1) { |
| 236 // If there is only one suitable browser, we can either activate it, or | 287 // If there is only one suitable browser, we can either activate it, or |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 247 // if it can be used. | 298 // if it can be used. |
| 248 std::vector<Browser*>::iterator i = | 299 std::vector<Browser*>::iterator i = |
| 249 std::find(items.begin(), items.end(), browser); | 300 std::find(items.begin(), items.end(), browser); |
| 250 if (i != items.end()) { | 301 if (i != items.end()) { |
| 251 browser = (++i == items.end()) ? items[0] : *i; | 302 browser = (++i == items.end()) ? items[0] : *i; |
| 252 } else { | 303 } else { |
| 253 browser = chrome::FindTabbedBrowser(profile_, | 304 browser = chrome::FindTabbedBrowser(profile_, |
| 254 true, | 305 true, |
| 255 chrome::HOST_DESKTOP_TYPE_ASH); | 306 chrome::HOST_DESKTOP_TYPE_ASH); |
| 256 if (!browser || | 307 if (!browser || |
| 257 !launcher_controller()->IsBrowserRepresentedInBrowserList(browser)) | 308 !IsBrowserRepresentedInBrowserList(browser)) |
| 258 browser = items[0]; | 309 browser = items[0]; |
| 259 } | 310 } |
| 260 } | 311 } |
| 261 DCHECK(browser); | 312 DCHECK(browser); |
| 262 browser->window()->Show(); | 313 browser->window()->Show(); |
| 263 browser->window()->Activate(); | 314 browser->window()->Activate(); |
| 264 } | 315 } |
| 316 | |
| 317 bool BrowserShortcutLauncherItemController::IsBrowserRepresentedInBrowserList( | |
| 318 Browser* browser) { | |
| 319 return (browser && | |
| 320 (browser->is_type_tabbed() || | |
| 321 !browser->is_app() || | |
| 322 !browser->is_type_popup() || | |
| 323 launcher_controller()-> | |
| 324 GetLauncherIDForAppID(web_app::GetExtensionIdFromApplicationName( | |
| 325 browser->app_name())) <= 0)); | |
| 326 } | |
| OLD | NEW |