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

Side by Side Diff: chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controller.cc

Issue 2719233002: Fix browser window shelf id init; re-enable browser test. (Closed)
Patch Set: Add shelf_delegate null check. Created 3 years, 9 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
« no previous file with comments | « no previous file | chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/common/shelf/shelf_delegate.h" 9 #include "ash/common/shelf/shelf_delegate.h"
10 #include "ash/common/shelf/shelf_model.h" 10 #include "ash/common/shelf/shelf_model.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 } 59 }
60 60
61 } // namespace 61 } // namespace
62 62
63 BrowserShortcutLauncherItemController::BrowserShortcutLauncherItemController( 63 BrowserShortcutLauncherItemController::BrowserShortcutLauncherItemController(
64 ChromeLauncherController* launcher_controller, 64 ChromeLauncherController* launcher_controller,
65 ash::ShelfModel* shelf_model) 65 ash::ShelfModel* shelf_model)
66 : LauncherItemController(extension_misc::kChromeAppId, 66 : LauncherItemController(extension_misc::kChromeAppId,
67 std::string(), 67 std::string(),
68 launcher_controller), 68 launcher_controller),
69 shelf_model_(shelf_model) {} 69 shelf_model_(shelf_model) {
70 // Tag all open browser windows with the appropriate shelf id property. This
71 // associates each window with the shelf item for the active web contents.
72 for (auto* browser : *BrowserList::GetInstance()) {
73 if (IsBrowserRepresentedInBrowserList(browser) &&
74 browser->tab_strip_model()->GetActiveWebContents()) {
75 SetShelfIDForBrowserWindowContents(
76 browser, browser->tab_strip_model()->GetActiveWebContents());
77 }
78 }
79 }
70 80
71 BrowserShortcutLauncherItemController:: 81 BrowserShortcutLauncherItemController::
72 ~BrowserShortcutLauncherItemController() {} 82 ~BrowserShortcutLauncherItemController() {}
73 83
74 void BrowserShortcutLauncherItemController::UpdateBrowserItemState() { 84 void BrowserShortcutLauncherItemController::UpdateBrowserItemState() {
75 // Determine the new browser's active state and change if necessary. 85 // Determine the new browser's active state and change if necessary.
76 int browser_index = 86 int browser_index =
77 shelf_model_->GetItemIndexForType(ash::TYPE_BROWSER_SHORTCUT); 87 shelf_model_->GetItemIndexForType(ash::TYPE_BROWSER_SHORTCUT);
78 DCHECK_GE(browser_index, 0); 88 DCHECK_GE(browser_index, 0);
79 ash::ShelfItem browser_item = shelf_model_->items()[browser_index]; 89 ash::ShelfItem browser_item = shelf_model_->items()[browser_index];
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 return ash::SHELF_ACTION_WINDOW_ACTIVATED; 282 return ash::SHELF_ACTION_WINDOW_ACTIVATED;
273 } 283 }
274 284
275 bool BrowserShortcutLauncherItemController::IsBrowserRepresentedInBrowserList( 285 bool BrowserShortcutLauncherItemController::IsBrowserRepresentedInBrowserList(
276 Browser* browser) { 286 Browser* browser) {
277 // Only Ash desktop browser windows for the active user are represented. 287 // Only Ash desktop browser windows for the active user are represented.
278 if (!browser || !IsBrowserFromActiveUser(browser)) 288 if (!browser || !IsBrowserFromActiveUser(browser))
279 return false; 289 return false;
280 290
281 // v1 App popup windows with a valid app id have their own icon. 291 // v1 App popup windows with a valid app id have their own icon.
282 if (browser->is_app() && browser->is_type_popup() && 292 ash::ShelfDelegate* delegate = ash::WmShell::Get()->shelf_delegate();
283 ash::WmShell::Get()->shelf_delegate()->GetShelfIDForAppID( 293 if (browser->is_app() && browser->is_type_popup() && delegate &&
284 web_app::GetExtensionIdFromApplicationName(browser->app_name())) > 0) 294 delegate->GetShelfIDForAppID(web_app::GetExtensionIdFromApplicationName(
295 browser->app_name())) > 0) {
285 return false; 296 return false;
297 }
286 298
287 // Settings browsers have their own icon. 299 // Settings browsers have their own icon.
288 if (IsSettingsBrowser(browser)) 300 if (IsSettingsBrowser(browser))
289 return false; 301 return false;
290 302
291 // Tabbed browser and other popup windows are all represented. 303 // Tabbed browser and other popup windows are all represented.
292 return true; 304 return true;
293 } 305 }
294 306
295 BrowserList::BrowserVector 307 BrowserList::BrowserVector
296 BrowserShortcutLauncherItemController::GetListOfActiveBrowsers() { 308 BrowserShortcutLauncherItemController::GetListOfActiveBrowsers() {
297 BrowserList::BrowserVector active_browsers; 309 BrowserList::BrowserVector active_browsers;
298 for (auto* browser : *BrowserList::GetInstance()) { 310 for (auto* browser : *BrowserList::GetInstance()) {
299 // Make sure that the browser is from the current user, has a proper window, 311 // Make sure that the browser is from the current user, has a proper window,
300 // and the window was already shown. 312 // and the window was already shown.
301 if (!IsBrowserFromActiveUser(browser)) 313 if (!IsBrowserFromActiveUser(browser))
302 continue; 314 continue;
303 if (!browser->window()->GetNativeWindow()->IsVisible() && 315 if (!browser->window()->GetNativeWindow()->IsVisible() &&
304 !browser->window()->IsMinimized()) { 316 !browser->window()->IsMinimized()) {
305 continue; 317 continue;
306 } 318 }
307 if (!IsBrowserRepresentedInBrowserList(browser) && 319 if (!IsBrowserRepresentedInBrowserList(browser) &&
308 !browser->is_type_tabbed()) 320 !browser->is_type_tabbed())
309 continue; 321 continue;
310 active_browsers.push_back(browser); 322 active_browsers.push_back(browser);
311 } 323 }
312 return active_browsers; 324 return active_browsers;
313 } 325 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698