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

Side by Side Diff: chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_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
OLDNEW
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::UpdateBrowserItemState() {
55 // The shell will not be available for win7_aura unittests like
56 // ChromeLauncherControllerTest.BrowserMenuGeneration.
57 if (!ash::Shell::HasInstance())
58 return;
59
60 ash::LauncherModel* model = launcher_controller()->model();
61
62 // Determine the new browser's active state and change if necessary.
63 size_t browser_index = ash::launcher::GetBrowserItemIndex(*model);
64 DCHECK_GE(browser_index, 0u);
65 ash::LauncherItem browser_item = model->items()[browser_index];
66 ash::LauncherItemStatus browser_status = ash::STATUS_CLOSED;
67
68 aura::Window* window = ash::wm::GetActiveWindow();
69 if (window) {
70 // Check if the active browser / tab is a browser which is not an app,
71 // a windowed app, a popup or any other item which is not a browser of
72 // interest.
73 Browser* browser = chrome::FindBrowserWithWindow(window);
74 if (IsBrowserRepresentedInBrowserList(browser)) {
75 browser_status = ash::STATUS_ACTIVE;
76 // If an app is running in active window, browser item status cannot be
77 // active.
78 if (launcher_controller()->GetIDByWindow(window) != browser_item.id)
79 browser_status = ash::STATUS_RUNNING;
80 }
81 }
82
83 if (browser_status == ash::STATUS_CLOSED) {
84 const BrowserList* ash_browser_list =
85 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
86 for (BrowserList::const_reverse_iterator it =
87 ash_browser_list->begin_last_active();
88 it != ash_browser_list->end_last_active() &&
89 browser_status == ash::STATUS_CLOSED; ++it) {
90 if (IsBrowserRepresentedInBrowserList(*it))
91 browser_status = ash::STATUS_RUNNING;
92 }
93 }
94
95 if (browser_status != browser_item.status) {
96 browser_item.status = browser_status;
97 model->Set(browser_index, browser_item);
98 }
99 }
100
51 string16 BrowserShortcutLauncherItemController::GetTitle() { 101 string16 BrowserShortcutLauncherItemController::GetTitle() {
52 return l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); 102 return l10n_util::GetStringUTF16(IDS_PRODUCT_NAME);
53 } 103 }
54 104
55 bool BrowserShortcutLauncherItemController::IsCurrentlyShownInWindow( 105 bool BrowserShortcutLauncherItemController::IsCurrentlyShownInWindow(
56 aura::Window* window) const { 106 aura::Window* window) const {
57 const BrowserList* ash_browser_list = 107 const BrowserList* ash_browser_list =
58 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); 108 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
59 for (BrowserList::const_iterator it = ash_browser_list->begin(); 109 for (BrowserList::const_iterator it = ash_browser_list->begin();
60 it != ash_browser_list->end(); ++it) { 110 it != ash_browser_list->end(); ++it) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 it != ash_browser_list->end(); ++it) { 195 it != ash_browser_list->end(); ++it) {
146 Browser* browser = *it; 196 Browser* browser = *it;
147 // Make sure that the browser was already shown and it has a proper window. 197 // Make sure that the browser was already shown and it has a proper window.
148 if (std::find(ash_browser_list->begin_last_active(), 198 if (std::find(ash_browser_list->begin_last_active(),
149 ash_browser_list->end_last_active(), 199 ash_browser_list->end_last_active(),
150 browser) == ash_browser_list->end_last_active() || 200 browser) == ash_browser_list->end_last_active() ||
151 !browser->window()) 201 !browser->window())
152 continue; 202 continue;
153 if (browser->is_type_tabbed()) 203 if (browser->is_type_tabbed())
154 found_tabbed_browser = true; 204 found_tabbed_browser = true;
155 else if (!launcher_controller()->IsBrowserRepresentedInBrowserList(browser)) 205 else if (!IsBrowserRepresentedInBrowserList(browser))
156 continue; 206 continue;
157 TabStripModel* tab_strip = browser->tab_strip_model(); 207 TabStripModel* tab_strip = browser->tab_strip_model();
158 if (tab_strip->active_index() == -1) 208 if (tab_strip->active_index() == -1)
159 continue; 209 continue;
160 if (!(event_flags & ui::EF_SHIFT_DOWN)) { 210 if (!(event_flags & ui::EF_SHIFT_DOWN)) {
161 content::WebContents* web_contents = 211 content::WebContents* web_contents =
162 tab_strip->GetWebContentsAt(tab_strip->active_index()); 212 tab_strip->GetWebContentsAt(tab_strip->active_index());
163 gfx::Image app_icon = GetBrowserListIcon(web_contents); 213 gfx::Image app_icon = GetBrowserListIcon(web_contents);
164 string16 title = GetBrowserListTitle(web_contents); 214 string16 title = GetBrowserListTitle(web_contents);
165 items.push_back(new ChromeLauncherAppMenuItemBrowser( 215 items.push_back(new ChromeLauncherAppMenuItemBrowser(
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 void BrowserShortcutLauncherItemController::ActivateOrAdvanceToNextBrowser() { 261 void BrowserShortcutLauncherItemController::ActivateOrAdvanceToNextBrowser() {
212 // Create a list of all suitable running browsers. 262 // Create a list of all suitable running browsers.
213 std::vector<Browser*> items; 263 std::vector<Browser*> items;
214 // We use the list in the order of how the browsers got created - not the LRU 264 // We use the list in the order of how the browsers got created - not the LRU
215 // order. 265 // order.
216 const BrowserList* ash_browser_list = 266 const BrowserList* ash_browser_list =
217 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); 267 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
218 for (BrowserList::const_iterator it = 268 for (BrowserList::const_iterator it =
219 ash_browser_list->begin(); 269 ash_browser_list->begin();
220 it != ash_browser_list->end(); ++it) { 270 it != ash_browser_list->end(); ++it) {
221 if (launcher_controller()->IsBrowserRepresentedInBrowserList(*it)) 271 if (IsBrowserRepresentedInBrowserList(*it))
222 items.push_back(*it); 272 items.push_back(*it);
223 } 273 }
224 // If there are no suitable browsers we create a new one. 274 // If there are no suitable browsers we create a new one.
225 if (!items.size()) { 275 if (!items.size()) {
226 launcher_controller()->CreateNewWindow(); 276 launcher_controller()->CreateNewWindow();
227 return; 277 return;
228 } 278 }
229 Browser* browser = chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow()); 279 Browser* browser = chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow());
230 if (items.size() == 1) { 280 if (items.size() == 1) {
231 // If there is only one suitable browser, we can either activate it, or 281 // If there is only one suitable browser, we can either activate it, or
(...skipping 10 matching lines...) Expand all
242 // if it can be used. 292 // if it can be used.
243 std::vector<Browser*>::iterator i = 293 std::vector<Browser*>::iterator i =
244 std::find(items.begin(), items.end(), browser); 294 std::find(items.begin(), items.end(), browser);
245 if (i != items.end()) { 295 if (i != items.end()) {
246 browser = (++i == items.end()) ? items[0] : *i; 296 browser = (++i == items.end()) ? items[0] : *i;
247 } else { 297 } else {
248 browser = chrome::FindTabbedBrowser(profile_, 298 browser = chrome::FindTabbedBrowser(profile_,
249 true, 299 true,
250 chrome::HOST_DESKTOP_TYPE_ASH); 300 chrome::HOST_DESKTOP_TYPE_ASH);
251 if (!browser || 301 if (!browser ||
252 !launcher_controller()->IsBrowserRepresentedInBrowserList(browser)) 302 !IsBrowserRepresentedInBrowserList(browser))
253 browser = items[0]; 303 browser = items[0];
254 } 304 }
255 } 305 }
256 DCHECK(browser); 306 DCHECK(browser);
257 browser->window()->Show(); 307 browser->window()->Show();
258 browser->window()->Activate(); 308 browser->window()->Activate();
259 } 309 }
310
311 bool BrowserShortcutLauncherItemController::IsBrowserRepresentedInBrowserList(
312 Browser* browser) {
313 return (browser &&
314 (browser->is_type_tabbed() ||
315 !browser->is_app() ||
316 !browser->is_type_popup() ||
317 launcher_controller()->
318 GetLauncherIDForAppID(web_app::GetExtensionIdFromApplicationName(
319 browser->app_name())) <= 0));
320 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698