Index: chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controller.cc |
diff --git a/chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controller.cc b/chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controller.cc |
index 2f0020122e542c937fce17ab87b00525769891f5..9f5d8f6699f314218fb02f8b0c84ed0863c94c91 100644 |
--- a/chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controller.cc |
+++ b/chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controller.cc |
@@ -7,6 +7,8 @@ |
#include <vector> |
#include "ash/launcher/launcher.h" |
+#include "ash/launcher/launcher_model.h" |
+#include "ash/launcher/launcher_util.h" |
#include "ash/shell.h" |
#include "ash/wm/window_util.h" |
#include "chrome/browser/profiles/profile.h" |
@@ -19,6 +21,7 @@ |
#include "chrome/browser/ui/browser_list.h" |
#include "chrome/browser/ui/browser_window.h" |
#include "chrome/browser/ui/tabs/tab_strip_model.h" |
+#include "chrome/browser/web_applications/web_app.h" |
#include "chrome/common/extensions/extension_constants.h" |
#include "content/public/browser/web_contents.h" |
#include "grit/ash_resources.h" |
@@ -48,6 +51,54 @@ BrowserShortcutLauncherItemController:: |
~BrowserShortcutLauncherItemController() { |
} |
+void BrowserShortcutLauncherItemController::UpdateBrowserItemStatus() { |
+ // 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.
|
+ // Without this ChromeLauncherControllerTest.BrowserMenuGeneration test will |
+ // fail. |
+ if (!ash::Shell::HasInstance()) |
+ return; |
+ |
+ ash::LauncherModel* model = launcher_controller()->model(); |
+ |
+ // Determine the new browser's active state and change if necessary. |
+ size_t browser_index = ash::launcher::GetBrowserItemIndex(*model); |
+ DCHECK_GE(browser_index, 0u); |
+ ash::LauncherItem browser_item = model->items()[browser_index]; |
+ ash::LauncherItemStatus browser_status = ash::STATUS_CLOSED; |
+ |
+ aura::Window* window = ash::wm::GetActiveWindow(); |
+ if (window) { |
+ // Check if the active browser / tab is a browser which is not an app, |
+ // a windowed app, a popup or any other item which is not a browser of |
+ // interest. |
+ Browser* browser = chrome::FindBrowserWithWindow(window); |
+ if (IsBrowserRepresentedInBrowserList(browser)) { |
+ browser_status = ash::STATUS_ACTIVE; |
+ // If an app is running in active window, browser item status cannot be |
+ // active. |
+ if (launcher_controller()->GetIDByWindow(window) != browser_item.id) |
+ browser_status = ash::STATUS_RUNNING; |
+ } |
+ } |
+ |
+ if (browser_status == ash::STATUS_CLOSED) { |
+ const BrowserList* ash_browser_list = |
+ BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); |
+ for (BrowserList::const_reverse_iterator it = |
+ ash_browser_list->begin_last_active(); |
+ it != ash_browser_list->end_last_active() && |
+ browser_status == ash::STATUS_CLOSED; ++it) { |
+ if (IsBrowserRepresentedInBrowserList(*it)) |
+ browser_status = ash::STATUS_RUNNING; |
+ } |
+ } |
+ |
+ if (browser_status != browser_item.status) { |
+ browser_item.status = browser_status; |
+ model->Set(browser_index, browser_item); |
+ } |
+} |
+ |
string16 BrowserShortcutLauncherItemController::GetTitle() { |
return l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); |
} |
@@ -157,7 +208,7 @@ BrowserShortcutLauncherItemController::GetApplicationList(int event_flags) { |
continue; |
if (browser->is_type_tabbed()) |
found_tabbed_browser = true; |
- else if (!launcher_controller()->IsBrowserRepresentedInBrowserList(browser)) |
+ else if (!IsBrowserRepresentedInBrowserList(browser)) |
continue; |
TabStripModel* tab_strip = browser->tab_strip_model(); |
if (tab_strip->active_index() == -1) |
@@ -223,7 +274,7 @@ void BrowserShortcutLauncherItemController::ActivateOrAdvanceToNextBrowser() { |
for (BrowserList::const_iterator it = |
ash_browser_list->begin(); |
it != ash_browser_list->end(); ++it) { |
- if (launcher_controller()->IsBrowserRepresentedInBrowserList(*it)) |
+ if (IsBrowserRepresentedInBrowserList(*it)) |
items.push_back(*it); |
} |
// If there are no suitable browsers we create a new one. |
@@ -254,7 +305,7 @@ void BrowserShortcutLauncherItemController::ActivateOrAdvanceToNextBrowser() { |
true, |
chrome::HOST_DESKTOP_TYPE_ASH); |
if (!browser || |
- !launcher_controller()->IsBrowserRepresentedInBrowserList(browser)) |
+ !IsBrowserRepresentedInBrowserList(browser)) |
browser = items[0]; |
} |
} |
@@ -262,3 +313,14 @@ void BrowserShortcutLauncherItemController::ActivateOrAdvanceToNextBrowser() { |
browser->window()->Show(); |
browser->window()->Activate(); |
} |
+ |
+bool BrowserShortcutLauncherItemController::IsBrowserRepresentedInBrowserList( |
+ Browser* browser) { |
+ return (browser && |
+ (browser->is_type_tabbed() || |
+ !browser->is_app() || |
+ !browser->is_type_popup() || |
+ launcher_controller()-> |
+ GetLauncherIDForAppID(web_app::GetExtensionIdFromApplicationName( |
+ browser->app_name())) <= 0)); |
+} |