1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_tab.h"
7 #include "ash/wm/window_util.h"
8 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_finder.h"
11 #include "chrome/browser/ui/browser_window.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
13 #include "ui/events/event_constants.h"
15 ChromeLauncherAppMenuItemTab::ChromeLauncherAppMenuItemTab(
16 const base::string16 title
,
17 const gfx::Image
* icon
,
18 content::WebContents
* content
,
19 bool has_leading_separator
)
20 : ChromeLauncherAppMenuItem(title
, icon
, has_leading_separator
),
21 content::WebContentsObserver(content
) {
24 bool ChromeLauncherAppMenuItemTab::IsActive() const {
25 Browser
* browser
= chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow());
28 return web_contents() == browser
->tab_strip_model()->GetActiveWebContents();
31 bool ChromeLauncherAppMenuItemTab::IsEnabled() const {
35 void ChromeLauncherAppMenuItemTab::Execute(int event_flags
) {
38 Browser
* browser
= chrome::FindBrowserWithWebContents(web_contents());
41 TabStripModel
* tab_strip
= browser
->tab_strip_model();
42 int index
= tab_strip
->GetIndexOfWebContents(web_contents());
43 DCHECK_NE(index
, TabStripModel::kNoTab
);
44 if (event_flags
& (ui::EF_SHIFT_DOWN
| ui::EF_MIDDLE_MOUSE_BUTTON
)) {
45 tab_strip
->CloseWebContentsAt(index
, TabStripModel::CLOSE_USER_GESTURE
);
47 // In ChromeOS multiprofile scenario we might need to teleport the window
48 // back to the current user desktop.
49 multi_user_util::MoveWindowToCurrentDesktop(
50 browser
->window()->GetNativeWindow());
51 tab_strip
->ActivateTabAt(index
, false);
52 browser
->window()->Show();
53 // Need this check to prevent unit tests from crashing.
54 if (browser
->window()->GetNativeWindow())
55 ash::wm::ActivateWindow(browser
->window()->GetNativeWindow());