Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / ash / launcher / chrome_launcher_app_menu_item_browser.cc
blobbe2cbe0df6f36e646ddf3f293870823f04407864
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_browser.h"
7 #include "ash/wm/window_util.h"
8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_finder.h"
12 #include "chrome/browser/ui/browser_window.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model.h"
14 #include "content/public/browser/notification_service.h"
15 #include "ui/events/event_constants.h"
17 ChromeLauncherAppMenuItemBrowser::ChromeLauncherAppMenuItemBrowser(
18 const base::string16 title,
19 const gfx::Image* icon,
20 Browser* browser,
21 bool has_leading_separator)
22 : ChromeLauncherAppMenuItem(title, icon, has_leading_separator),
23 browser_(browser) {
24 DCHECK(browser);
25 registrar_.Add(this,
26 chrome::NOTIFICATION_BROWSER_CLOSING,
27 content::Source<Browser>(browser));
29 ChromeLauncherAppMenuItemBrowser::~ChromeLauncherAppMenuItemBrowser() {
32 bool ChromeLauncherAppMenuItemBrowser::IsActive() const {
33 return browser_ == chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow());
36 bool ChromeLauncherAppMenuItemBrowser::IsEnabled() const {
37 return true;
40 void ChromeLauncherAppMenuItemBrowser::Execute(int event_flags) {
41 if (browser_) {
42 if (event_flags & (ui::EF_SHIFT_DOWN | ui::EF_MIDDLE_MOUSE_BUTTON)) {
43 TabStripModel* tab_strip = browser_->tab_strip_model();
44 tab_strip->CloseAllTabs();
45 } else {
46 // In ChromeOS multiprofile scenario we might need to teleport the window
47 // back to the current user desktop.
48 multi_user_util::MoveWindowToCurrentDesktop(
49 browser_->window()->GetNativeWindow());
50 browser_->window()->Show();
51 ash::wm::ActivateWindow(browser_->window()->GetNativeWindow());
56 void ChromeLauncherAppMenuItemBrowser::Observe(
57 int type,
58 const content::NotificationSource& source,
59 const content::NotificationDetails& details) {
60 switch (type) {
61 case chrome::NOTIFICATION_BROWSER_CLOSING:
62 DCHECK_EQ(browser_, content::Source<Browser>(source).ptr());
63 browser_ = NULL;
64 break;
66 default:
67 NOTREACHED();