1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/ash/system_tray_delegate_win.h"
#include <string>
#include "ash/shell.h"
#include "ash/shell_delegate.h"
#include "ash/system/tray/system_tray.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/tray/system_tray_notifier.h"
#include "ash/volume_control_delegate.h"
#include "base/logging.h"
#include "base/time/time.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/host_desktop.h"
#include "chrome/browser/upgrade_detector.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_service.h"
#include "grit/locale_settings.h"
#include "ui/base/l10n/l10n_util.h"
namespace {
class SystemTrayDelegateWin : public ash::SystemTrayDelegate,
public content::NotificationObserver {
public:
SystemTrayDelegateWin()
: clock_type_(base::GetHourClockType()) {
// Register notifications on construction so that events such as
// PROFILE_CREATED do not get missed if they happen before Initialize().
registrar_.reset(new content::NotificationRegistrar);
registrar_->Add(this,
chrome::NOTIFICATION_UPGRADE_RECOMMENDED,
content::NotificationService::AllSources());
}
virtual ~SystemTrayDelegateWin() {
registrar_.reset();
}
// Overridden from ash::SystemTrayDelegate:
virtual void Initialize() OVERRIDE {
UpdateClockType();
}
virtual void Shutdown() OVERRIDE {
}
virtual bool GetTrayVisibilityOnStartup() OVERRIDE {
return true;
}
virtual ash::user::LoginStatus GetUserLoginStatus() const OVERRIDE {
return ash::user::LOGGED_IN_OWNER;
}
virtual void ChangeProfilePicture() OVERRIDE {
}
virtual const std::string GetEnterpriseDomain() const OVERRIDE {
return std::string();
}
virtual const base::string16 GetEnterpriseMessage() const OVERRIDE {
return base::string16();
}
virtual const std::string GetLocallyManagedUserManager() const OVERRIDE {
return std::string();
}
virtual const base::string16 GetLocallyManagedUserManagerName() const
OVERRIDE {
return base::string16();
}
virtual const base::string16 GetLocallyManagedUserMessage() const OVERRIDE {
return base::string16();
}
virtual bool SystemShouldUpgrade() const OVERRIDE {
return UpgradeDetector::GetInstance()->notify_upgrade();
}
virtual base::HourClockType GetHourClockType() const OVERRIDE {
return clock_type_;
}
virtual void ShowSettings() OVERRIDE {
}
virtual bool ShouldShowSettings() OVERRIDE {
return true;
}
virtual void ShowDateSettings() OVERRIDE {
}
virtual void ShowSetTimeDialog() OVERRIDE {
}
virtual void ShowNetworkSettings(const std::string& service_path) OVERRIDE {
}
virtual void ShowBluetoothSettings() OVERRIDE {
}
virtual void ShowDisplaySettings() OVERRIDE {
}
virtual void ShowChromeSlow() OVERRIDE {
}
virtual bool ShouldShowDisplayNotification() OVERRIDE {
return false;
}
virtual void ShowDriveSettings() OVERRIDE {
}
virtual void ShowIMESettings() OVERRIDE {
}
virtual void ShowHelp() OVERRIDE {
chrome::ShowHelpForProfile(
ProfileManager::GetLastUsedProfile(),
chrome::HOST_DESKTOP_TYPE_ASH,
chrome::HELP_SOURCE_MENU);
}
virtual void ShowAccessibilityHelp() OVERRIDE {
}
virtual void ShowAccessibilitySettings() OVERRIDE {
}
virtual void ShowPublicAccountInfo() OVERRIDE {
}
virtual void ShowLocallyManagedUserInfo() OVERRIDE {
}
virtual void ShowEnterpriseInfo() OVERRIDE {
}
virtual void ShowUserLogin() OVERRIDE {
}
virtual bool ShowSpringChargerReplacementDialog() OVERRIDE {
return false;
}
virtual bool IsSpringChargerReplacementDialogVisible() OVERRIDE {
return false;
}
virtual bool HasUserConfirmedSafeSpringCharger() OVERRIDE {
return false;
}
virtual void ShutDown() OVERRIDE {
}
virtual void SignOut() OVERRIDE {
}
virtual void RequestLockScreen() OVERRIDE {
}
virtual void RequestRestartForUpdate() OVERRIDE {
chrome::AttemptRestart();
}
virtual void GetAvailableBluetoothDevices(
ash::BluetoothDeviceList* list) OVERRIDE {
}
virtual void BluetoothStartDiscovering() OVERRIDE {
}
virtual void BluetoothStopDiscovering() OVERRIDE {
}
virtual void ConnectToBluetoothDevice(const std::string& address) OVERRIDE {
}
virtual bool IsBluetoothDiscovering() OVERRIDE {
return false;
}
virtual void GetCurrentIME(ash::IMEInfo* info) OVERRIDE {
}
virtual void GetAvailableIMEList(ash::IMEInfoList* list) OVERRIDE {
}
virtual void GetCurrentIMEProperties(
ash::IMEPropertyInfoList* list) OVERRIDE {
}
virtual void SwitchIME(const std::string& ime_id) OVERRIDE {
}
virtual void ActivateIMEProperty(const std::string& key) OVERRIDE {
}
virtual void CancelDriveOperation(int32 operation_id) OVERRIDE {
}
virtual void GetDriveOperationStatusList(
ash::DriveOperationStatusList* list) OVERRIDE {
}
virtual void ShowNetworkConfigure(const std::string& network_id,
gfx::NativeWindow parent_window) OVERRIDE {
}
virtual bool EnrollNetwork(const std::string& network_id,
gfx::NativeWindow parent_window) OVERRIDE {
return true;
}
virtual void ManageBluetoothDevices() OVERRIDE {
}
virtual void ToggleBluetooth() OVERRIDE {
}
virtual void ShowMobileSimDialog() OVERRIDE {
}
virtual void ShowMobileSetupDialog(const std::string& service_path) OVERRIDE {
}
virtual void ShowOtherNetworkDialog(const std::string& type) OVERRIDE {
}
virtual bool GetBluetoothAvailable() OVERRIDE {
return false;
}
virtual bool GetBluetoothEnabled() OVERRIDE {
return false;
}
virtual bool GetBluetoothDiscovering() OVERRIDE {
return false;
}
virtual void ChangeProxySettings() OVERRIDE {
}
virtual ash::VolumeControlDelegate*
GetVolumeControlDelegate() const OVERRIDE {
return NULL;
}
virtual void SetVolumeControlDelegate(
scoped_ptr<ash::VolumeControlDelegate> delegate) OVERRIDE {
}
virtual bool GetSessionStartTime(
base::TimeTicks* session_start_time) OVERRIDE {
return false;
}
virtual bool GetSessionLengthLimit(
base::TimeDelta* session_length_limit) OVERRIDE {
return false;
}
virtual int GetSystemTrayMenuWidth() OVERRIDE {
return l10n_util::GetLocalizedContentsWidthInPixels(
IDS_SYSTEM_TRAY_MENU_BUBBLE_WIDTH_PIXELS);
}
virtual void ActiveUserWasChanged() OVERRIDE {
}
virtual bool IsNetworkBehindCaptivePortal(
const std::string& service_path) const OVERRIDE {
return false;
}
virtual bool IsSearchKeyMappedToCapsLock() OVERRIDE {
return false;
}
virtual ash::tray::UserAccountsDelegate* GetUserAccountsDelegate(
const std::string& user_id) OVERRIDE {
return NULL;
}
private:
ash::SystemTrayNotifier* GetSystemTrayNotifier() {
return ash::Shell::GetInstance()->system_tray_notifier();
}
void UpdateClockType() {
clock_type_ = (base::GetHourClockType() == base::k24HourClock) ?
base::k24HourClock : base::k12HourClock;
GetSystemTrayNotifier()->NotifyDateFormatChanged();
}
// content::NotificationObserver implementation.
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE {
if (type == chrome::NOTIFICATION_UPGRADE_RECOMMENDED) {
UpgradeDetector* detector =
content::Source<UpgradeDetector>(source).ptr();
ash::UpdateObserver::UpdateSeverity severity =
ash::UpdateObserver::UPDATE_NORMAL;
switch (detector->upgrade_notification_stage()) {
case UpgradeDetector::UPGRADE_ANNOYANCE_CRITICAL:
case UpgradeDetector::UPGRADE_ANNOYANCE_SEVERE:
severity = ash::UpdateObserver::UPDATE_SEVERE_RED;
break;
case UpgradeDetector::UPGRADE_ANNOYANCE_HIGH:
severity = ash::UpdateObserver::UPDATE_HIGH_ORANGE;
break;
case UpgradeDetector::UPGRADE_ANNOYANCE_ELEVATED:
severity = ash::UpdateObserver::UPDATE_LOW_GREEN;
break;
case UpgradeDetector::UPGRADE_ANNOYANCE_LOW:
case UpgradeDetector::UPGRADE_ANNOYANCE_NONE:
severity = ash::UpdateObserver::UPDATE_NORMAL;
break;
}
GetSystemTrayNotifier()->NotifyUpdateRecommended(severity);
} else {
NOTREACHED();
}
}
scoped_ptr<content::NotificationRegistrar> registrar_;
base::HourClockType clock_type_;
DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegateWin);
};
} // namespace
ash::SystemTrayDelegate* CreateWindowsSystemTrayDelegate() {
return new SystemTrayDelegateWin();
}
|