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 <limits> | 7 #include <limits> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/resources/grit/ash_resources.h" | 10 #include "ash/resources/grit/ash_resources.h" |
11 #include "ash/shelf/shelf_model.h" | 11 #include "ash/shelf/shelf_model.h" |
12 #include "ash/shell.h" | |
13 #include "ash/wm/window_properties.h" | 12 #include "ash/wm/window_properties.h" |
14 #include "ash/wm/window_util.h" | |
15 #include "ash/wm_window.h" | 13 #include "ash/wm_window.h" |
16 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
17 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
18 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 17 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
20 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h" | 18 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h" |
21 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" | 19 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" |
22 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | 20 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
23 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
24 #include "chrome/browser/ui/browser_commands.h" | 22 #include "chrome/browser/ui/browser_commands.h" |
25 #include "chrome/browser/ui/browser_finder.h" | 23 #include "chrome/browser/ui/browser_finder.h" |
| 24 #include "chrome/browser/ui/browser_list.h" |
26 #include "chrome/browser/ui/browser_window.h" | 25 #include "chrome/browser/ui/browser_window.h" |
27 #include "chrome/browser/ui/chrome_pages.h" | 26 #include "chrome/browser/ui/chrome_pages.h" |
28 #include "chrome/browser/ui/settings_window_manager.h" | 27 #include "chrome/browser/ui/settings_window_manager.h" |
29 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 28 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
30 #include "chrome/browser/web_applications/web_app.h" | 29 #include "chrome/browser/web_applications/web_app.h" |
31 #include "chrome/common/extensions/extension_constants.h" | 30 #include "chrome/common/extensions/extension_constants.h" |
32 #include "chrome/grit/chromium_strings.h" | 31 #include "chrome/grit/chromium_strings.h" |
33 #include "chrome/grit/generated_resources.h" | 32 #include "chrome/grit/generated_resources.h" |
34 #include "components/strings/grit/components_strings.h" | 33 #include "components/strings/grit/components_strings.h" |
35 #include "content/public/browser/notification_service.h" | 34 #include "content/public/browser/notification_service.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 ~BrowserShortcutLauncherItemController() {} | 122 ~BrowserShortcutLauncherItemController() {} |
124 | 123 |
125 void BrowserShortcutLauncherItemController::UpdateBrowserItemState() { | 124 void BrowserShortcutLauncherItemController::UpdateBrowserItemState() { |
126 // Determine the new browser's active state and change if necessary. | 125 // Determine the new browser's active state and change if necessary. |
127 int browser_index = | 126 int browser_index = |
128 shelf_model_->GetItemIndexForType(ash::TYPE_BROWSER_SHORTCUT); | 127 shelf_model_->GetItemIndexForType(ash::TYPE_BROWSER_SHORTCUT); |
129 DCHECK_GE(browser_index, 0); | 128 DCHECK_GE(browser_index, 0); |
130 ash::ShelfItem browser_item = shelf_model_->items()[browser_index]; | 129 ash::ShelfItem browser_item = shelf_model_->items()[browser_index]; |
131 ash::ShelfItemStatus browser_status = ash::STATUS_CLOSED; | 130 ash::ShelfItemStatus browser_status = ash::STATUS_CLOSED; |
132 | 131 |
133 aura::Window* window = ash::wm::GetActiveWindow(); | 132 Browser* browser = BrowserList::GetInstance()->GetLastActive(); |
134 if (window) { | 133 if (browser && browser->window()->IsActive() && |
| 134 IsBrowserRepresentedInBrowserList(browser)) { |
135 // Check if the active browser / tab is a browser which is not an app, | 135 // Check if the active browser / tab is a browser which is not an app, |
136 // a windowed app, a popup or any other item which is not a browser of | 136 // a windowed app, a popup or any other item which is not a browser of |
137 // interest. | 137 // interest. |
138 Browser* browser = chrome::FindBrowserWithWindow(window); | 138 browser_status = ash::STATUS_ACTIVE; |
139 if (IsBrowserRepresentedInBrowserList(browser)) { | 139 // If an app that has item is running in active WebContents, browser item |
140 browser_status = ash::STATUS_ACTIVE; | 140 // status cannot be active. |
141 // If an app that has item is running in active WebContents, browser item | 141 content::WebContents* contents = |
142 // status cannot be active. | 142 browser->tab_strip_model()->GetActiveWebContents(); |
143 content::WebContents* contents = | 143 if (contents && |
144 browser->tab_strip_model()->GetActiveWebContents(); | 144 (ChromeLauncherController::instance()->GetShelfIDForWebContents( |
145 if (contents && | 145 contents) != browser_item.id)) |
146 (ChromeLauncherController::instance()->GetShelfIDForWebContents( | 146 browser_status = ash::STATUS_RUNNING; |
147 contents) != browser_item.id)) | |
148 browser_status = ash::STATUS_RUNNING; | |
149 } | |
150 } | 147 } |
151 | 148 |
152 if (browser_status == ash::STATUS_CLOSED) { | 149 if (browser_status == ash::STATUS_CLOSED) { |
153 for (auto* browser : *BrowserList::GetInstance()) { | 150 for (auto* browser : *BrowserList::GetInstance()) { |
154 if (IsBrowserRepresentedInBrowserList(browser)) { | 151 if (IsBrowserRepresentedInBrowserList(browser)) { |
155 browser_status = ash::STATUS_RUNNING; | 152 browser_status = ash::STATUS_RUNNING; |
156 break; | 153 break; |
157 } | 154 } |
158 } | 155 } |
159 } | 156 } |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 for (BrowserList::const_iterator it = browser_list->begin(); | 312 for (BrowserList::const_iterator it = browser_list->begin(); |
316 it != browser_list->end(); ++it) { | 313 it != browser_list->end(); ++it) { |
317 if (IsBrowserRepresentedInBrowserList(*it)) | 314 if (IsBrowserRepresentedInBrowserList(*it)) |
318 items.push_back(*it); | 315 items.push_back(*it); |
319 } | 316 } |
320 // If there are no suitable browsers we create a new one. | 317 // If there are no suitable browsers we create a new one. |
321 if (items.empty()) { | 318 if (items.empty()) { |
322 chrome::NewEmptyWindow(ChromeLauncherController::instance()->profile()); | 319 chrome::NewEmptyWindow(ChromeLauncherController::instance()->profile()); |
323 return ash::SHELF_ACTION_NEW_WINDOW_CREATED; | 320 return ash::SHELF_ACTION_NEW_WINDOW_CREATED; |
324 } | 321 } |
325 Browser* browser = chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow()); | 322 Browser* browser = BrowserList::GetInstance()->GetLastActive(); |
326 if (items.size() == 1) { | 323 if (items.size() == 1) { |
327 // If there is only one suitable browser, we can either activate it, or | 324 // If there is only one suitable browser, we can either activate it, or |
328 // bounce it (if it is already active). | 325 // bounce it (if it is already active). |
329 if (browser == items[0]) { | 326 if (items[0]->window()->IsActive()) { |
330 AnimateWindow(browser->window()->GetNativeWindow(), | 327 AnimateWindow(items[0]->window()->GetNativeWindow(), |
331 wm::WINDOW_ANIMATION_TYPE_BOUNCE); | 328 wm::WINDOW_ANIMATION_TYPE_BOUNCE); |
332 return ash::SHELF_ACTION_NONE; | 329 return ash::SHELF_ACTION_NONE; |
333 } | 330 } |
334 browser = items[0]; | 331 browser = items[0]; |
335 } else { | 332 } else { |
336 // If there is more than one suitable browser, we advance to the next if | 333 // If there is more than one suitable browser, we advance to the next if |
337 // |browser| is already active - or - check the last used browser if it can | 334 // |browser| is already active - or - check the last used browser if it can |
338 // be used. | 335 // be used. |
339 std::vector<Browser*>::iterator i = | 336 std::vector<Browser*>::iterator i = |
340 std::find(items.begin(), items.end(), browser); | 337 std::find(items.begin(), items.end(), browser); |
341 if (i != items.end()) { | 338 if (i != items.end()) { |
342 browser = (++i == items.end()) ? items[0] : *i; | 339 if (browser->window()->IsActive()) |
| 340 browser = (++i == items.end()) ? items[0] : *i; |
343 } else { | 341 } else { |
344 browser = chrome::FindTabbedBrowser( | 342 browser = chrome::FindTabbedBrowser( |
345 ChromeLauncherController::instance()->profile(), true); | 343 ChromeLauncherController::instance()->profile(), true); |
346 if (!browser || !IsBrowserRepresentedInBrowserList(browser)) | 344 if (!browser || !IsBrowserRepresentedInBrowserList(browser)) |
347 browser = items[0]; | 345 browser = items[0]; |
348 } | 346 } |
349 } | 347 } |
350 DCHECK(browser); | 348 DCHECK(browser); |
351 browser->window()->Show(); | 349 browser->window()->Show(); |
352 browser->window()->Activate(); | 350 browser->window()->Activate(); |
353 return ash::SHELF_ACTION_WINDOW_ACTIVATED; | 351 return ash::SHELF_ACTION_WINDOW_ACTIVATED; |
354 } | 352 } |
355 | 353 |
356 bool BrowserShortcutLauncherItemController::IsBrowserRepresentedInBrowserList( | 354 bool BrowserShortcutLauncherItemController::IsBrowserRepresentedInBrowserList( |
357 Browser* browser) { | 355 Browser* browser) { |
358 // Only Ash desktop browser windows for the active user are represented. | 356 // Only Ash desktop browser windows for the active user are represented. |
359 if (!browser || !IsBrowserFromActiveUser(browser)) | 357 if (!browser || !IsBrowserFromActiveUser(browser)) |
360 return false; | 358 return false; |
361 | 359 |
362 // v1 App popup windows with a valid app id have their own icon. | 360 // v1 App popup windows with a valid app id have their own icon. |
363 ash::ShelfModel* model = ash::Shell::Get()->shelf_model(); | |
364 if (browser->is_app() && browser->is_type_popup() && | 361 if (browser->is_app() && browser->is_type_popup() && |
365 model->GetShelfIDForAppID(web_app::GetExtensionIdFromApplicationName( | 362 shelf_model_->GetShelfIDForAppID( |
366 browser->app_name())) > 0) { | 363 web_app::GetExtensionIdFromApplicationName(browser->app_name())) != |
| 364 ash::kInvalidShelfID) { |
367 return false; | 365 return false; |
368 } | 366 } |
369 | 367 |
370 // Settings browsers have their own icon. | 368 // Settings browsers have their own icon. |
371 if (IsSettingsBrowser(browser)) | 369 if (IsSettingsBrowser(browser)) |
372 return false; | 370 return false; |
373 | 371 |
374 // Tabbed browser and other popup windows are all represented. | 372 // Tabbed browser and other popup windows are all represented. |
375 return true; | 373 return true; |
376 } | 374 } |
(...skipping 26 matching lines...) Expand all Loading... |
403 Browser* browser = content::Source<Browser>(source).ptr(); | 401 Browser* browser = content::Source<Browser>(source).ptr(); |
404 DCHECK(browser); | 402 DCHECK(browser); |
405 BrowserList::BrowserVector::iterator item = std::find( | 403 BrowserList::BrowserVector::iterator item = std::find( |
406 browser_menu_items_.begin(), browser_menu_items_.end(), browser); | 404 browser_menu_items_.begin(), browser_menu_items_.end(), browser); |
407 DCHECK(item != browser_menu_items_.end()); | 405 DCHECK(item != browser_menu_items_.end()); |
408 // Clear the entry for the closed browser and leave other indices intact. | 406 // Clear the entry for the closed browser and leave other indices intact. |
409 *item = nullptr; | 407 *item = nullptr; |
410 registrar_.Remove(this, chrome::NOTIFICATION_BROWSER_CLOSING, | 408 registrar_.Remove(this, chrome::NOTIFICATION_BROWSER_CLOSING, |
411 content::Source<Browser>(browser)); | 409 content::Source<Browser>(browser)); |
412 } | 410 } |
OLD | NEW |