OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/chromeos/system/ash_system_tray_delegate.h" | 5 #include "chrome/browser/chromeos/system/ash_system_tray_delegate.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/shell_window_ids.h" | |
8 #include "ash/system/audio/audio_controller.h" | 9 #include "ash/system/audio/audio_controller.h" |
9 #include "ash/system/brightness/brightness_controller.h" | 10 #include "ash/system/brightness/brightness_controller.h" |
10 #include "ash/system/network/network_controller.h" | 11 #include "ash/system/network/network_controller.h" |
11 #include "ash/system/power/power_status_controller.h" | 12 #include "ash/system/power/power_status_controller.h" |
12 #include "ash/system/tray/system_tray.h" | 13 #include "ash/system/tray/system_tray.h" |
13 #include "ash/system/tray/system_tray_delegate.h" | 14 #include "ash/system/tray/system_tray_delegate.h" |
14 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/utf_string_conversions.h" | |
15 #include "chrome/browser/chromeos/audio/audio_handler.h" | 17 #include "chrome/browser/chromeos/audio/audio_handler.h" |
16 #include "chrome/browser/chromeos/cros/cros_library.h" | 18 #include "chrome/browser/chromeos/cros/cros_library.h" |
17 #include "chrome/browser/chromeos/cros/network_library.h" | 19 #include "chrome/browser/chromeos/cros/network_library.h" |
18 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" | 20 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" |
19 #include "chrome/browser/chromeos/dbus/power_manager_client.h" | 21 #include "chrome/browser/chromeos/dbus/power_manager_client.h" |
22 #include "chrome/browser/chromeos/login/login_html_dialog.h" | |
23 #include "chrome/browser/chromeos/login/proxy_settings_dialog.h" | |
20 #include "chrome/browser/chromeos/login/user.h" | 24 #include "chrome/browser/chromeos/login/user.h" |
21 #include "chrome/browser/chromeos/login/user_manager.h" | 25 #include "chrome/browser/chromeos/login/user_manager.h" |
26 #include "chrome/browser/chromeos/status/network_menu.h" | |
22 #include "chrome/browser/chromeos/status/network_menu_icon.h" | 27 #include "chrome/browser/chromeos/status/network_menu_icon.h" |
23 #include "chrome/browser/ui/browser.h" | 28 #include "chrome/browser/ui/browser.h" |
24 #include "chrome/browser/ui/browser_list.h" | 29 #include "chrome/browser/ui/browser_list.h" |
25 #include "chrome/common/chrome_notification_types.h" | 30 #include "chrome/common/chrome_notification_types.h" |
26 #include "content/public/browser/notification_observer.h" | 31 #include "content/public/browser/notification_observer.h" |
27 #include "content/public/browser/notification_service.h" | 32 #include "content/public/browser/notification_service.h" |
33 #include "grit/generated_resources.h" | |
34 #include "ui/base/l10n/l10n_util.h" | |
28 | 35 |
29 namespace chromeos { | 36 namespace chromeos { |
30 | 37 |
31 namespace { | 38 namespace { |
32 | 39 |
40 ash::NetworkIconInfo CreateNetworkIconInfo(const Network* network, | |
41 NetworkMenuIcon* network_icon) { | |
42 ash::NetworkIconInfo info; | |
43 info.name = UTF8ToUTF16(network->name()); | |
44 info.image = network_icon->GetBitmap(network, NetworkMenuIcon::SIZE_SMALL); | |
45 info.unique_id = network->unique_id(); | |
46 return info; | |
47 } | |
48 | |
33 class SystemTrayDelegate : public ash::SystemTrayDelegate, | 49 class SystemTrayDelegate : public ash::SystemTrayDelegate, |
34 public AudioHandler::VolumeObserver, | 50 public AudioHandler::VolumeObserver, |
35 public PowerManagerClient::Observer, | 51 public PowerManagerClient::Observer, |
36 public NetworkMenuIcon::Delegate, | 52 public NetworkMenuIcon::Delegate, |
53 public NetworkMenu::Delegate, | |
37 public NetworkLibrary::NetworkManagerObserver, | 54 public NetworkLibrary::NetworkManagerObserver, |
38 public NetworkLibrary::NetworkObserver, | 55 public NetworkLibrary::NetworkObserver, |
39 public NetworkLibrary::CellularDataPlanObserver, | 56 public NetworkLibrary::CellularDataPlanObserver, |
40 public content::NotificationObserver { | 57 public content::NotificationObserver { |
41 public: | 58 public: |
42 explicit SystemTrayDelegate(ash::SystemTray* tray) | 59 explicit SystemTrayDelegate(ash::SystemTray* tray) |
43 : tray_(tray), | 60 : tray_(tray), |
44 network_icon_(ALLOW_THIS_IN_INITIALIZER_LIST( | 61 network_icon_(ALLOW_THIS_IN_INITIALIZER_LIST( |
45 new NetworkMenuIcon(this, NetworkMenuIcon::MENU_MODE))) { | 62 new NetworkMenuIcon(this, NetworkMenuIcon::MENU_MODE))), |
63 network_icon_large_(ALLOW_THIS_IN_INITIALIZER_LIST( | |
64 new NetworkMenuIcon(this, NetworkMenuIcon::MENU_MODE))), | |
65 network_menu_(ALLOW_THIS_IN_INITIALIZER_LIST(new NetworkMenu(this))) { | |
46 AudioHandler::GetInstance()->AddVolumeObserver(this); | 66 AudioHandler::GetInstance()->AddVolumeObserver(this); |
47 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); | 67 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); |
48 DBusThreadManager::Get()->GetPowerManagerClient()->RequestStatusUpdate( | 68 DBusThreadManager::Get()->GetPowerManagerClient()->RequestStatusUpdate( |
49 PowerManagerClient::UPDATE_USER); | 69 PowerManagerClient::UPDATE_USER); |
50 | 70 |
51 NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary(); | 71 NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary(); |
52 crosnet->AddNetworkManagerObserver(this); | 72 crosnet->AddNetworkManagerObserver(this); |
53 OnNetworkManagerChanged(crosnet); | 73 OnNetworkManagerChanged(crosnet); |
54 crosnet->AddCellularDataPlanObserver(this); | 74 crosnet->AddCellularDataPlanObserver(this); |
55 | 75 |
56 registrar_.Add(this, | 76 registrar_.Add(this, |
57 chrome::NOTIFICATION_LOGIN_USER_CHANGED, | 77 chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
58 content::NotificationService::AllSources()); | 78 content::NotificationService::AllSources()); |
79 | |
80 network_icon_large_->SetResourceSize(NetworkMenuIcon::SIZE_LARGE); | |
59 } | 81 } |
60 | 82 |
61 virtual ~SystemTrayDelegate() { | 83 virtual ~SystemTrayDelegate() { |
62 AudioHandler* audiohandler = AudioHandler::GetInstance(); | 84 AudioHandler* audiohandler = AudioHandler::GetInstance(); |
63 if (audiohandler) | 85 if (audiohandler) |
64 audiohandler->RemoveVolumeObserver(this); | 86 audiohandler->RemoveVolumeObserver(this); |
65 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); | 87 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); |
66 } | 88 } |
67 | 89 |
68 // Overridden from ash::SystemTrayDelegate: | 90 // Overridden from ash::SystemTrayDelegate: |
(...skipping 14 matching lines...) Expand all Loading... | |
83 if (!manager->IsUserLoggedIn()) | 105 if (!manager->IsUserLoggedIn()) |
84 return ash::user::LOGGED_IN_NONE; | 106 return ash::user::LOGGED_IN_NONE; |
85 if (manager->IsCurrentUserOwner()) | 107 if (manager->IsCurrentUserOwner()) |
86 return ash::user::LOGGED_IN_OWNER; | 108 return ash::user::LOGGED_IN_OWNER; |
87 if (manager->IsLoggedInAsGuest()) | 109 if (manager->IsLoggedInAsGuest()) |
88 return ash::user::LOGGED_IN_GUEST; | 110 return ash::user::LOGGED_IN_GUEST; |
89 return ash::user::LOGGED_IN_USER; | 111 return ash::user::LOGGED_IN_USER; |
90 } | 112 } |
91 | 113 |
92 virtual void ShowSettings() OVERRIDE { | 114 virtual void ShowSettings() OVERRIDE { |
93 BrowserList::GetLastActive()->OpenOptionsDialog(); | 115 Browser* browser = BrowserList::GetLastActive(); |
116 if (browser) | |
117 browser->OpenOptionsDialog(); | |
94 } | 118 } |
95 | 119 |
96 virtual void ShowDateSettings() OVERRIDE { | 120 virtual void ShowDateSettings() OVERRIDE { |
97 BrowserList::GetLastActive()->OpenAdvancedOptionsDialog(); | 121 Browser* browser = BrowserList::GetLastActive(); |
122 if (browser) | |
123 browser->OpenAdvancedOptionsDialog(); | |
124 } | |
125 | |
126 virtual void ShowNetworkSettings() OVERRIDE { | |
127 Browser* browser = BrowserList::GetLastActive(); | |
128 if (browser) | |
129 browser->OpenInternetOptionsDialog(); | |
98 } | 130 } |
99 | 131 |
100 virtual void ShowHelp() OVERRIDE { | 132 virtual void ShowHelp() OVERRIDE { |
101 BrowserList::GetLastActive()->ShowHelpTab(); | 133 Browser* browser = BrowserList::GetLastActive(); |
134 if (browser) | |
135 browser->ShowHelpTab(); | |
102 } | 136 } |
103 | 137 |
104 virtual bool IsAudioMuted() const OVERRIDE { | 138 virtual bool IsAudioMuted() const OVERRIDE { |
105 return AudioHandler::GetInstance()->IsMuted(); | 139 return AudioHandler::GetInstance()->IsMuted(); |
106 } | 140 } |
107 | 141 |
108 virtual void SetAudioMuted(bool muted) OVERRIDE { | 142 virtual void SetAudioMuted(bool muted) OVERRIDE { |
109 return AudioHandler::GetInstance()->SetMuted(muted); | 143 return AudioHandler::GetInstance()->SetMuted(muted); |
110 } | 144 } |
111 | 145 |
(...skipping 11 matching lines...) Expand all Loading... | |
123 | 157 |
124 virtual void SignOut() OVERRIDE { | 158 virtual void SignOut() OVERRIDE { |
125 BrowserList::AttemptUserExit(); | 159 BrowserList::AttemptUserExit(); |
126 } | 160 } |
127 | 161 |
128 virtual void RequestLockScreen() OVERRIDE { | 162 virtual void RequestLockScreen() OVERRIDE { |
129 DBusThreadManager::Get()->GetPowerManagerClient()-> | 163 DBusThreadManager::Get()->GetPowerManagerClient()-> |
130 NotifyScreenLockRequested(); | 164 NotifyScreenLockRequested(); |
131 } | 165 } |
132 | 166 |
133 virtual ash::NetworkIconInfo GetMostRelevantNetworkIcon() OVERRIDE { | 167 virtual ash::NetworkIconInfo GetMostRelevantNetworkIcon(bool large) OVERRIDE { |
134 ash::NetworkIconInfo info; | 168 ash::NetworkIconInfo info; |
135 info.image = network_icon_->GetIconAndText(&info.description); | 169 info.image = !large ? network_icon_->GetIconAndText(&info.description) : |
170 network_icon_large_->GetIconAndText(&info.description); | |
136 return info; | 171 return info; |
137 } | 172 } |
138 | 173 |
174 virtual void GetAvailableNetworks( | |
175 std::vector<ash::NetworkIconInfo>* list) OVERRIDE { | |
176 NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary(); | |
177 crosnet->RequestNetworkScan(); | |
178 | |
179 // Ethernet. | |
180 if (crosnet->ethernet_enabled()) { | |
181 const EthernetNetwork* ethernet_network = crosnet->ethernet_network(); | |
182 if (ethernet_network) { | |
183 ash::NetworkIconInfo info; | |
184 info.image = network_icon_->GetBitmap(ethernet_network, | |
185 NetworkMenuIcon::SIZE_SMALL); | |
186 if (!ethernet_network->name().empty()) | |
187 info.name = UTF8ToUTF16(ethernet_network->name()); | |
188 else | |
189 info.name = | |
190 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET); | |
191 info.unique_id = ethernet_network->unique_id(); | |
192 list->push_back(info); | |
193 } | |
194 } | |
195 | |
196 // Wifi. | |
197 if (crosnet->wifi_available() && crosnet->wifi_enabled()) { | |
198 const WifiNetworkVector& wifi = crosnet->wifi_networks(); | |
199 for (size_t i = 0; i < wifi.size(); ++i) | |
200 list->push_back(CreateNetworkIconInfo(wifi[i], network_icon_.get())); | |
201 } | |
202 | |
203 // Cellular. | |
204 if (crosnet->cellular_available() && crosnet->cellular_enabled()) { | |
205 const CellularNetworkVector& cell = crosnet->cellular_networks(); | |
206 for (size_t i = 0; i < cell.size(); ++i) | |
207 list->push_back(CreateNetworkIconInfo(cell[i], network_icon_.get())); | |
208 } | |
209 | |
210 // VPN (only if logged in). | |
211 if (GetUserLoginStatus() == ash::user::LOGGED_IN_NONE) | |
212 return; | |
213 if (crosnet->connected_network() || crosnet->virtual_network_connected()) { | |
214 const VirtualNetworkVector& vpns = crosnet->virtual_networks(); | |
215 for (size_t i = 0; i < vpns.size(); ++i) | |
216 list->push_back(CreateNetworkIconInfo(vpns[i], network_icon_.get())); | |
217 } | |
218 } | |
219 | |
220 virtual void ConnectToNetwork(const std::string& network_id) OVERRIDE { | |
221 NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary(); | |
222 Network* network = crosnet->FindNetworkByUniqueId(network_id); | |
223 if (network) | |
224 network_menu_->ConnectToNetwork(network); | |
225 } | |
226 | |
227 virtual void ToggleAirplaneMode() OVERRIDE { | |
228 NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary(); | |
229 crosnet->EnableOfflineMode(!crosnet->offline_mode()); | |
230 } | |
231 | |
232 virtual void ChangeProxySettings() OVERRIDE { | |
233 CHECK(GetUserLoginStatus() == ash::user::LOGGED_IN_NONE); | |
234 if (!proxy_settings_dialog_.get()) { | |
235 ash::Shell* shell = ash::Shell::GetInstance(); | |
236 proxy_settings_dialog_.reset(new ProxySettingsDialog(NULL, shell-> | |
237 GetContainer(ash::internal::kShellWindowId_SettingBubbleContainer))); | |
238 } | |
239 proxy_settings_dialog_->Show(); | |
240 } | |
241 | |
139 private: | 242 private: |
140 void NotifyRefreshNetwork() { | 243 void NotifyRefreshNetwork() { |
141 ash::NetworkController* controller = | 244 ash::NetworkController* controller = |
142 ash::Shell::GetInstance()->network_controller(); | 245 ash::Shell::GetInstance()->network_controller(); |
143 if (controller) { | 246 if (controller) { |
144 ash::NetworkIconInfo info; | 247 ash::NetworkIconInfo info; |
145 info.image = network_icon_->GetIconAndText(&info.description); | 248 info.image = network_icon_->GetIconAndText(&info.description); |
146 controller->OnNetworkRefresh(info); | 249 controller->OnNetworkRefresh(info); |
147 } | 250 } |
148 } | 251 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
190 | 293 |
191 virtual void UnlockScreen() OVERRIDE { | 294 virtual void UnlockScreen() OVERRIDE { |
192 } | 295 } |
193 | 296 |
194 virtual void UnlockScreenFailed() OVERRIDE { | 297 virtual void UnlockScreenFailed() OVERRIDE { |
195 } | 298 } |
196 | 299 |
197 // TODO(sad): Override more from PowerManagerClient::Observer here (e.g. | 300 // TODO(sad): Override more from PowerManagerClient::Observer here (e.g. |
198 // PowerButtonStateChanged etc.). | 301 // PowerButtonStateChanged etc.). |
199 | 302 |
200 // Overridden from StatusMenuIcon::Delegate. | 303 // Overridden from NetworkMenuIcon::Delegate. |
201 virtual void NetworkMenuIconChanged() OVERRIDE { | 304 virtual void NetworkMenuIconChanged() OVERRIDE { |
202 NotifyRefreshNetwork(); | 305 NotifyRefreshNetwork(); |
203 } | 306 } |
204 | 307 |
308 // Overridden from NetworkMenu::Delegate. | |
309 virtual views::MenuButton* GetMenuButton() OVERRIDE { | |
310 return NULL; | |
311 } | |
312 | |
313 virtual gfx::NativeWindow GetNativeWindow() const OVERRIDE { | |
314 return NULL; | |
Nikita (slow)
2012/03/13 15:36:33
This method is not called when NetworkMenu opens i
Nikita (slow)
2012/03/13 15:37:04
This was a question.
sadrul
2012/03/13 15:48:39
I have changed this to return the ash container in
| |
315 } | |
316 | |
317 virtual void OpenButtonOptions() OVERRIDE { | |
318 } | |
319 | |
320 virtual bool ShouldOpenButtonOptions() const OVERRIDE { | |
321 return false; | |
322 } | |
323 | |
205 // Overridden from NetworkLibrary::NetworkManagerObserver. | 324 // Overridden from NetworkLibrary::NetworkManagerObserver. |
206 virtual void OnNetworkManagerChanged(NetworkLibrary* crosnet) OVERRIDE { | 325 virtual void OnNetworkManagerChanged(NetworkLibrary* crosnet) OVERRIDE { |
207 RefreshNetworkObserver(crosnet); | 326 RefreshNetworkObserver(crosnet); |
208 RefreshNetworkDeviceObserver(crosnet); | 327 RefreshNetworkDeviceObserver(crosnet); |
209 | 328 |
210 // TODO: ShowOptionalMobileDataPromoNotification? | 329 // TODO: ShowOptionalMobileDataPromoNotification? |
211 | 330 |
212 NotifyRefreshNetwork(); | 331 NotifyRefreshNetwork(); |
213 } | 332 } |
214 | 333 |
(...skipping 17 matching lines...) Expand all Loading... | |
232 tray_->UpdateAfterLoginStatusChange(GetUserLoginStatus()); | 351 tray_->UpdateAfterLoginStatusChange(GetUserLoginStatus()); |
233 break; | 352 break; |
234 } | 353 } |
235 default: | 354 default: |
236 NOTREACHED(); | 355 NOTREACHED(); |
237 } | 356 } |
238 } | 357 } |
239 | 358 |
240 ash::SystemTray* tray_; | 359 ash::SystemTray* tray_; |
241 scoped_ptr<NetworkMenuIcon> network_icon_; | 360 scoped_ptr<NetworkMenuIcon> network_icon_; |
361 scoped_ptr<NetworkMenuIcon> network_icon_large_; | |
362 scoped_ptr<NetworkMenu> network_menu_; | |
242 content::NotificationRegistrar registrar_; | 363 content::NotificationRegistrar registrar_; |
243 std::string cellular_device_path_; | 364 std::string cellular_device_path_; |
244 std::string active_network_path_; | 365 std::string active_network_path_; |
366 scoped_ptr<LoginHtmlDialog> proxy_settings_dialog_; | |
Nikita (slow)
2012/03/13 15:36:33
Should be removed.
sadrul
2012/03/13 15:48:39
Done.
| |
245 | 367 |
246 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegate); | 368 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegate); |
247 }; | 369 }; |
248 | 370 |
249 } // namespace | 371 } // namespace |
250 | 372 |
251 ash::SystemTrayDelegate* CreateSystemTrayDelegate(ash::SystemTray* tray) { | 373 ash::SystemTrayDelegate* CreateSystemTrayDelegate(ash::SystemTray* tray) { |
252 return new chromeos::SystemTrayDelegate(tray); | 374 return new chromeos::SystemTrayDelegate(tray); |
253 } | 375 } |
254 | 376 |
255 } // namespace chromeos | 377 } // namespace chromeos |
OLD | NEW |