OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/l10n_util.h" | 5 #include "app/l10n_util.h" |
6 #include "app/resource_bundle.h" | 6 #include "app/resource_bundle.h" |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "chrome/app/chrome_dll_resource.h" |
8 #include "chrome/browser/background_mode_manager.h" | 9 #include "chrome/browser/background_mode_manager.h" |
9 #include "chrome/browser/browser_list.h" | 10 #include "chrome/browser/browser_list.h" |
10 #include "chrome/browser/metrics/user_metrics.h" | 11 #include "chrome/browser/metrics/user_metrics.h" |
11 #include "chrome/browser/pref_service.h" | 12 #include "chrome/browser/pref_service.h" |
12 #include "chrome/browser/profile.h" | 13 #include "chrome/browser/profile.h" |
13 #include "chrome/browser/status_icons/status_icon.h" | 14 #include "chrome/browser/status_icons/status_icon.h" |
14 #include "chrome/browser/status_icons/status_tray.h" | 15 #include "chrome/browser/status_icons/status_tray.h" |
15 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
16 #include "chrome/common/extensions/extension.h" | 17 #include "chrome/common/extensions/extension.h" |
17 #include "chrome/common/notification_service.h" | 18 #include "chrome/common/notification_service.h" |
18 #include "chrome/common/notification_type.h" | 19 #include "chrome/common/notification_type.h" |
19 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
20 #include "grit/browser_resources.h" | 21 #include "grit/browser_resources.h" |
21 #include "grit/chromium_strings.h" | 22 #include "grit/chromium_strings.h" |
| 23 #include "grit/generated_resources.h" |
22 #include "grit/theme_resources.h" | 24 #include "grit/theme_resources.h" |
23 | 25 |
24 BackgroundModeManager::BackgroundModeManager(Profile* profile) | 26 BackgroundModeManager::BackgroundModeManager(Profile* profile) |
25 : profile_(profile), | 27 : profile_(profile), |
26 background_app_count_(0), | 28 background_app_count_(0), |
27 status_tray_(NULL) { | 29 status_tray_(NULL) { |
28 // If background mode is disabled for unittests, just exit - don't listen for | 30 // If background mode is disabled for unittests, just exit - don't listen for |
29 // any notifications. | 31 // any notifications. |
30 if (CommandLine::ForCurrentProcess()->HasSwitch( | 32 if (CommandLine::ForCurrentProcess()->HasSwitch( |
31 switches::kDisableBackgroundMode)) | 33 switches::kDisableBackgroundMode)) |
(...skipping 30 matching lines...) Expand all Loading... |
62 | 64 |
63 // Check for the presence of background apps after all extensions have been | 65 // Check for the presence of background apps after all extensions have been |
64 // loaded, to handle the case where an extension has been manually removed | 66 // loaded, to handle the case where an extension has been manually removed |
65 // while Chrome was not running. | 67 // while Chrome was not running. |
66 registrar_.Add(this, NotificationType::EXTENSIONS_READY, | 68 registrar_.Add(this, NotificationType::EXTENSIONS_READY, |
67 Source<Profile>(profile)); | 69 Source<Profile>(profile)); |
68 | 70 |
69 } | 71 } |
70 | 72 |
71 BackgroundModeManager::~BackgroundModeManager() { | 73 BackgroundModeManager::~BackgroundModeManager() { |
| 74 // If we're going away, remove our status tray icon so we don't get any events |
| 75 // from it. |
| 76 RemoveStatusTrayIcon(); |
72 } | 77 } |
73 | 78 |
74 bool BackgroundModeManager::IsBackgroundModeEnabled() { | 79 bool BackgroundModeManager::IsBackgroundModeEnabled() { |
75 return profile_->GetPrefs()->GetBoolean(prefs::kBackgroundModeEnabled); | 80 return profile_->GetPrefs()->GetBoolean(prefs::kBackgroundModeEnabled); |
76 } | 81 } |
77 | 82 |
78 void BackgroundModeManager::Observe(NotificationType type, | 83 void BackgroundModeManager::Observe(NotificationType type, |
79 const NotificationSource& source, | 84 const NotificationSource& source, |
80 const NotificationDetails& details) { | 85 const NotificationDetails& details) { |
81 switch (type.value) { | 86 switch (type.value) { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 return; | 179 return; |
175 status_icon_ = status_tray_->CreateStatusIcon(); | 180 status_icon_ = status_tray_->CreateStatusIcon(); |
176 if (!status_icon_) | 181 if (!status_icon_) |
177 return; | 182 return; |
178 | 183 |
179 // Set the image and add ourselves as a click observer on it | 184 // Set the image and add ourselves as a click observer on it |
180 SkBitmap* bitmap = ResourceBundle::GetSharedInstance().GetBitmapNamed( | 185 SkBitmap* bitmap = ResourceBundle::GetSharedInstance().GetBitmapNamed( |
181 IDR_STATUS_TRAY_ICON); | 186 IDR_STATUS_TRAY_ICON); |
182 status_icon_->SetImage(*bitmap); | 187 status_icon_->SetImage(*bitmap); |
183 status_icon_->SetToolTip(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); | 188 status_icon_->SetToolTip(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); |
184 status_icon_->AddObserver(this); | 189 |
| 190 // Create a context menu item for Chrome. |
| 191 menus::SimpleMenuModel* menu = new menus::SimpleMenuModel(this); |
| 192 menu->AddItem(IDC_ABOUT, l10n_util::GetStringFUTF16(IDS_ABOUT, |
| 193 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); |
| 194 menu->AddSeparator(); |
| 195 menu->AddItemWithStringId(IDC_EXIT, IDS_EXIT); |
| 196 status_icon_->SetContextMenu(menu); |
| 197 } |
| 198 |
| 199 bool BackgroundModeManager::IsCommandIdChecked(int command_id) const { |
| 200 return false; |
| 201 } |
| 202 |
| 203 bool BackgroundModeManager::IsCommandIdEnabled(int command_id) const { |
| 204 // For now, we do not support disabled items. |
| 205 return true; |
| 206 } |
| 207 |
| 208 bool BackgroundModeManager::GetAcceleratorForCommandId( |
| 209 int command_id, |
| 210 menus::Accelerator* accelerator) { |
| 211 // No accelerators for status icon context menus. |
| 212 return false; |
185 } | 213 } |
186 | 214 |
187 void BackgroundModeManager::RemoveStatusTrayIcon() { | 215 void BackgroundModeManager::RemoveStatusTrayIcon() { |
188 if (status_icon_) | 216 if (status_icon_) |
189 status_tray_->RemoveStatusIcon(status_icon_); | 217 status_tray_->RemoveStatusIcon(status_icon_); |
190 status_icon_ = NULL; | 218 status_icon_ = NULL; |
191 } | 219 } |
192 | 220 |
193 void BackgroundModeManager::OnClicked() { | 221 |
194 UserMetrics::RecordAction(UserMetricsAction("Exit"), profile_); | 222 void BackgroundModeManager::ExecuteCommand(int item) { |
195 BrowserList::CloseAllBrowsersAndExit(); | 223 switch (item) { |
| 224 case IDC_EXIT: |
| 225 UserMetrics::RecordAction(UserMetricsAction("Exit"), profile_); |
| 226 BrowserList::CloseAllBrowsersAndExit(); |
| 227 break; |
| 228 case IDC_ABOUT: { |
| 229 // Need to display a browser window to put up the about dialog. |
| 230 Browser* browser = BrowserList::GetLastActive(); |
| 231 if (!browser) { |
| 232 Browser::OpenEmptyWindow(profile_); |
| 233 browser = BrowserList::GetLastActive(); |
| 234 } |
| 235 browser->OpenAboutChromeDialog(); |
| 236 break; |
| 237 } |
| 238 default: |
| 239 NOTREACHED(); |
| 240 break; |
| 241 } |
196 } | 242 } |
197 | 243 |
198 // static | 244 // static |
199 void BackgroundModeManager::RegisterUserPrefs(PrefService* prefs) { | 245 void BackgroundModeManager::RegisterUserPrefs(PrefService* prefs) { |
200 prefs->RegisterBooleanPref(prefs::kBackgroundModeEnabled, true); | 246 prefs->RegisterBooleanPref(prefs::kBackgroundModeEnabled, true); |
201 } | 247 } |
OLD | NEW |