Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: chrome/browser/chromeos/system/ash_system_tray_delegate.cc

Issue 9664056: ash uber tray: Add the detailed network popup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/system/audio/audio_controller.h" 8 #include "ash/system/audio/audio_controller.h"
9 #include "ash/system/brightness/brightness_controller.h" 9 #include "ash/system/brightness/brightness_controller.h"
10 #include "ash/system/network/network_controller.h" 10 #include "ash/system/network/network_controller.h"
11 #include "ash/system/power/power_status_controller.h" 11 #include "ash/system/power/power_status_controller.h"
12 #include "ash/system/tray/system_tray.h" 12 #include "ash/system/tray/system_tray.h"
13 #include "ash/system/tray/system_tray_delegate.h" 13 #include "ash/system/tray/system_tray_delegate.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/utf_string_conversions.h"
15 #include "chrome/browser/chromeos/audio/audio_handler.h" 16 #include "chrome/browser/chromeos/audio/audio_handler.h"
16 #include "chrome/browser/chromeos/cros/cros_library.h" 17 #include "chrome/browser/chromeos/cros/cros_library.h"
17 #include "chrome/browser/chromeos/cros/network_library.h" 18 #include "chrome/browser/chromeos/cros/network_library.h"
18 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" 19 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h"
19 #include "chrome/browser/chromeos/dbus/power_manager_client.h" 20 #include "chrome/browser/chromeos/dbus/power_manager_client.h"
20 #include "chrome/browser/chromeos/login/user.h" 21 #include "chrome/browser/chromeos/login/user.h"
21 #include "chrome/browser/chromeos/login/user_manager.h" 22 #include "chrome/browser/chromeos/login/user_manager.h"
23 #include "chrome/browser/chromeos/status/network_menu.h"
22 #include "chrome/browser/chromeos/status/network_menu_icon.h" 24 #include "chrome/browser/chromeos/status/network_menu_icon.h"
23 #include "chrome/browser/ui/browser.h" 25 #include "chrome/browser/ui/browser.h"
24 #include "chrome/browser/ui/browser_list.h" 26 #include "chrome/browser/ui/browser_list.h"
25 #include "chrome/common/chrome_notification_types.h" 27 #include "chrome/common/chrome_notification_types.h"
26 #include "content/public/browser/notification_observer.h" 28 #include "content/public/browser/notification_observer.h"
27 #include "content/public/browser/notification_service.h" 29 #include "content/public/browser/notification_service.h"
30 #include "grit/generated_resources.h"
31 #include "ui/base/l10n/l10n_util.h"
28 32
29 namespace chromeos { 33 namespace chromeos {
30 34
31 namespace { 35 namespace {
32 36
37 ash::NetworkIconInfo CreateNetworkIconInfo(const Network* network,
38 NetworkMenuIcon* network_icon) {
39 ash::NetworkIconInfo info;
40 info.name = UTF8ToUTF16(network->name());
41 info.image = network_icon->GetBitmap(network, NetworkMenuIcon::SIZE_SMALL);
42 info.unique_id = network->unique_id();
43 return info;
44 }
45
33 class SystemTrayDelegate : public ash::SystemTrayDelegate, 46 class SystemTrayDelegate : public ash::SystemTrayDelegate,
34 public AudioHandler::VolumeObserver, 47 public AudioHandler::VolumeObserver,
35 public PowerManagerClient::Observer, 48 public PowerManagerClient::Observer,
36 public NetworkMenuIcon::Delegate, 49 public NetworkMenuIcon::Delegate,
50 public NetworkMenu::Delegate,
37 public NetworkLibrary::NetworkManagerObserver, 51 public NetworkLibrary::NetworkManagerObserver,
38 public NetworkLibrary::NetworkObserver, 52 public NetworkLibrary::NetworkObserver,
39 public NetworkLibrary::CellularDataPlanObserver, 53 public NetworkLibrary::CellularDataPlanObserver,
40 public content::NotificationObserver { 54 public content::NotificationObserver {
41 public: 55 public:
42 explicit SystemTrayDelegate(ash::SystemTray* tray) 56 explicit SystemTrayDelegate(ash::SystemTray* tray)
43 : tray_(tray), 57 : tray_(tray),
44 network_icon_(ALLOW_THIS_IN_INITIALIZER_LIST( 58 network_icon_(ALLOW_THIS_IN_INITIALIZER_LIST(
45 new NetworkMenuIcon(this, NetworkMenuIcon::MENU_MODE))) { 59 new NetworkMenuIcon(this, NetworkMenuIcon::MENU_MODE))),
60 network_icon_large_(ALLOW_THIS_IN_INITIALIZER_LIST(
61 new NetworkMenuIcon(this, NetworkMenuIcon::MENU_MODE))),
62 network_menu_(ALLOW_THIS_IN_INITIALIZER_LIST(new NetworkMenu(this))) {
46 AudioHandler::GetInstance()->AddVolumeObserver(this); 63 AudioHandler::GetInstance()->AddVolumeObserver(this);
47 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); 64 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this);
48 DBusThreadManager::Get()->GetPowerManagerClient()->RequestStatusUpdate( 65 DBusThreadManager::Get()->GetPowerManagerClient()->RequestStatusUpdate(
49 PowerManagerClient::UPDATE_USER); 66 PowerManagerClient::UPDATE_USER);
50 67
51 NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary(); 68 NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary();
52 crosnet->AddNetworkManagerObserver(this); 69 crosnet->AddNetworkManagerObserver(this);
53 OnNetworkManagerChanged(crosnet); 70 OnNetworkManagerChanged(crosnet);
54 crosnet->AddCellularDataPlanObserver(this); 71 crosnet->AddCellularDataPlanObserver(this);
55 72
56 registrar_.Add(this, 73 registrar_.Add(this,
57 chrome::NOTIFICATION_LOGIN_USER_CHANGED, 74 chrome::NOTIFICATION_LOGIN_USER_CHANGED,
58 content::NotificationService::AllSources()); 75 content::NotificationService::AllSources());
76
77 network_icon_large_->SetResourceSize(NetworkMenuIcon::SIZE_LARGE);
59 } 78 }
60 79
61 virtual ~SystemTrayDelegate() { 80 virtual ~SystemTrayDelegate() {
62 AudioHandler* audiohandler = AudioHandler::GetInstance(); 81 AudioHandler* audiohandler = AudioHandler::GetInstance();
63 if (audiohandler) 82 if (audiohandler)
64 audiohandler->RemoveVolumeObserver(this); 83 audiohandler->RemoveVolumeObserver(this);
65 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); 84 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this);
66 } 85 }
67 86
68 // Overridden from ash::SystemTrayDelegate: 87 // Overridden from ash::SystemTrayDelegate:
(...skipping 14 matching lines...) Expand all
83 if (!manager->IsUserLoggedIn()) 102 if (!manager->IsUserLoggedIn())
84 return ash::user::LOGGED_IN_NONE; 103 return ash::user::LOGGED_IN_NONE;
85 if (manager->IsCurrentUserOwner()) 104 if (manager->IsCurrentUserOwner())
86 return ash::user::LOGGED_IN_OWNER; 105 return ash::user::LOGGED_IN_OWNER;
87 if (manager->IsLoggedInAsGuest()) 106 if (manager->IsLoggedInAsGuest())
88 return ash::user::LOGGED_IN_GUEST; 107 return ash::user::LOGGED_IN_GUEST;
89 return ash::user::LOGGED_IN_USER; 108 return ash::user::LOGGED_IN_USER;
90 } 109 }
91 110
92 virtual void ShowSettings() OVERRIDE { 111 virtual void ShowSettings() OVERRIDE {
93 BrowserList::GetLastActive()->OpenOptionsDialog(); 112 Browser* browser = BrowserList::GetLastActive();
113 if (browser)
114 browser->OpenOptionsDialog();
94 } 115 }
95 116
96 virtual void ShowDateSettings() OVERRIDE { 117 virtual void ShowDateSettings() OVERRIDE {
97 BrowserList::GetLastActive()->OpenAdvancedOptionsDialog(); 118 Browser* browser = BrowserList::GetLastActive();
119 if (browser)
120 browser->OpenAdvancedOptionsDialog();
121 }
122
123 virtual void ShowNetworkSettings() OVERRIDE {
124 Browser* browser = BrowserList::GetLastActive();
125 if (browser)
126 browser->OpenInternetOptionsDialog();
98 } 127 }
99 128
100 virtual void ShowHelp() OVERRIDE { 129 virtual void ShowHelp() OVERRIDE {
101 BrowserList::GetLastActive()->ShowHelpTab(); 130 Browser* browser = BrowserList::GetLastActive();
131 if (browser)
132 browser->ShowHelpTab();
102 } 133 }
103 134
104 virtual bool IsAudioMuted() const OVERRIDE { 135 virtual bool IsAudioMuted() const OVERRIDE {
105 return AudioHandler::GetInstance()->IsMuted(); 136 return AudioHandler::GetInstance()->IsMuted();
106 } 137 }
107 138
108 virtual void SetAudioMuted(bool muted) OVERRIDE { 139 virtual void SetAudioMuted(bool muted) OVERRIDE {
109 return AudioHandler::GetInstance()->SetMuted(muted); 140 return AudioHandler::GetInstance()->SetMuted(muted);
110 } 141 }
111 142
(...skipping 11 matching lines...) Expand all
123 154
124 virtual void SignOut() OVERRIDE { 155 virtual void SignOut() OVERRIDE {
125 BrowserList::AttemptUserExit(); 156 BrowserList::AttemptUserExit();
126 } 157 }
127 158
128 virtual void RequestLockScreen() OVERRIDE { 159 virtual void RequestLockScreen() OVERRIDE {
129 DBusThreadManager::Get()->GetPowerManagerClient()-> 160 DBusThreadManager::Get()->GetPowerManagerClient()->
130 NotifyScreenLockRequested(); 161 NotifyScreenLockRequested();
131 } 162 }
132 163
133 virtual ash::NetworkIconInfo GetMostRelevantNetworkIcon() OVERRIDE { 164 virtual ash::NetworkIconInfo GetMostRelevantNetworkIcon(bool large) OVERRIDE {
134 ash::NetworkIconInfo info; 165 ash::NetworkIconInfo info;
135 info.image = network_icon_->GetIconAndText(&info.description); 166 info.image = !large ? network_icon_->GetIconAndText(&info.description) :
167 network_icon_large_->GetIconAndText(&info.description);
136 return info; 168 return info;
137 } 169 }
138 170
171 virtual void GetAvailableNetworks(
172 std::vector<ash::NetworkIconInfo>* list) OVERRIDE {
173 NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary();
174 crosnet->RequestNetworkScan();
175
176 // Ethernet.
177 if (crosnet->ethernet_enabled()) {
178 const EthernetNetwork* ethernet_network = crosnet->ethernet_network();
179 if (ethernet_network) {
180 ash::NetworkIconInfo info;
181 info.image = network_icon_->GetBitmap(ethernet_network,
182 NetworkMenuIcon::SIZE_SMALL);
183 if (!ethernet_network->name().empty())
184 info.name = UTF8ToUTF16(ethernet_network->name());
185 else
186 info.name =
187 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET);
188 info.unique_id = ethernet_network->unique_id();
189 list->push_back(info);
190 }
191 }
192
193 // Wifi.
194 if (crosnet->wifi_available() && crosnet->wifi_enabled()) {
195 const WifiNetworkVector& wifi = crosnet->wifi_networks();
196 for (size_t i = 0; i < wifi.size(); ++i)
197 list->push_back(CreateNetworkIconInfo(wifi[i], network_icon_.get()));
198 }
199
200 // Cellular.
201 if (crosnet->cellular_available() && crosnet->cellular_enabled()) {
202 const CellularNetworkVector& cell = crosnet->cellular_networks();
203 for (size_t i = 0; i < cell.size(); ++i)
204 list->push_back(CreateNetworkIconInfo(cell[i], network_icon_.get()));
205 }
206
207 // VPN (only if logged in).
208 if (GetUserLoginStatus() == ash::user::LOGGED_IN_NONE)
209 return;
210 if (crosnet->connected_network() || crosnet->virtual_network_connected()) {
211 const VirtualNetworkVector& vpns = crosnet->virtual_networks();
212 for (size_t i = 0; i < vpns.size(); ++i)
213 list->push_back(CreateNetworkIconInfo(vpns[i], network_icon_.get()));
214 }
215 }
216
217 virtual void ConnectToNetwork(const std::string& network_id) OVERRIDE {
218 NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary();
219 Network* network = crosnet->FindNetworkByUniqueId(network_id);
220 if (network)
221 network_menu_->ConnectToNetwork(network);
222 }
223
224 virtual void ToggleAirplaneMode() OVERRIDE {
225 NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary();
226 crosnet->EnableOfflineMode(!crosnet->offline_mode());
227 }
228
139 private: 229 private:
140 void NotifyRefreshNetwork() { 230 void NotifyRefreshNetwork() {
141 ash::NetworkController* controller = 231 ash::NetworkController* controller =
142 ash::Shell::GetInstance()->network_controller(); 232 ash::Shell::GetInstance()->network_controller();
143 if (controller) { 233 if (controller) {
144 ash::NetworkIconInfo info; 234 ash::NetworkIconInfo info;
145 info.image = network_icon_->GetIconAndText(&info.description); 235 info.image = network_icon_->GetIconAndText(&info.description);
146 controller->OnNetworkRefresh(info); 236 controller->OnNetworkRefresh(info);
147 } 237 }
148 } 238 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 280
191 virtual void UnlockScreen() OVERRIDE { 281 virtual void UnlockScreen() OVERRIDE {
192 } 282 }
193 283
194 virtual void UnlockScreenFailed() OVERRIDE { 284 virtual void UnlockScreenFailed() OVERRIDE {
195 } 285 }
196 286
197 // TODO(sad): Override more from PowerManagerClient::Observer here (e.g. 287 // TODO(sad): Override more from PowerManagerClient::Observer here (e.g.
198 // PowerButtonStateChanged etc.). 288 // PowerButtonStateChanged etc.).
199 289
200 // Overridden from StatusMenuIcon::Delegate. 290 // Overridden from NetworkMenuIcon::Delegate.
201 virtual void NetworkMenuIconChanged() OVERRIDE { 291 virtual void NetworkMenuIconChanged() OVERRIDE {
202 NotifyRefreshNetwork(); 292 NotifyRefreshNetwork();
203 } 293 }
204 294
295 // Overridden from NetworkMenu::Delegate.
296 virtual views::MenuButton* GetMenuButton() OVERRIDE {
297 return NULL;
298 }
299
300 virtual gfx::NativeWindow GetNativeWindow() const OVERRIDE {
301 return NULL;
302 }
303
304 virtual void OpenButtonOptions() OVERRIDE {
305 }
306
307 virtual bool ShouldOpenButtonOptions() const OVERRIDE {
308 return false;
309 }
310
205 // Overridden from NetworkLibrary::NetworkManagerObserver. 311 // Overridden from NetworkLibrary::NetworkManagerObserver.
206 virtual void OnNetworkManagerChanged(NetworkLibrary* crosnet) OVERRIDE { 312 virtual void OnNetworkManagerChanged(NetworkLibrary* crosnet) OVERRIDE {
207 RefreshNetworkObserver(crosnet); 313 RefreshNetworkObserver(crosnet);
208 RefreshNetworkDeviceObserver(crosnet); 314 RefreshNetworkDeviceObserver(crosnet);
209 315
210 // TODO: ShowOptionalMobileDataPromoNotification? 316 // TODO: ShowOptionalMobileDataPromoNotification?
211 317
212 NotifyRefreshNetwork(); 318 NotifyRefreshNetwork();
213 } 319 }
214 320
(...skipping 17 matching lines...) Expand all
232 tray_->UpdateAfterLoginStatusChange(GetUserLoginStatus()); 338 tray_->UpdateAfterLoginStatusChange(GetUserLoginStatus());
233 break; 339 break;
234 } 340 }
235 default: 341 default:
236 NOTREACHED(); 342 NOTREACHED();
237 } 343 }
238 } 344 }
239 345
240 ash::SystemTray* tray_; 346 ash::SystemTray* tray_;
241 scoped_ptr<NetworkMenuIcon> network_icon_; 347 scoped_ptr<NetworkMenuIcon> network_icon_;
348 scoped_ptr<NetworkMenuIcon> network_icon_large_;
349 scoped_ptr<NetworkMenu> network_menu_;
242 content::NotificationRegistrar registrar_; 350 content::NotificationRegistrar registrar_;
243 std::string cellular_device_path_; 351 std::string cellular_device_path_;
244 std::string active_network_path_; 352 std::string active_network_path_;
245 353
246 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegate); 354 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegate);
247 }; 355 };
248 356
249 } // namespace 357 } // namespace
250 358
251 ash::SystemTrayDelegate* CreateSystemTrayDelegate(ash::SystemTray* tray) { 359 ash::SystemTrayDelegate* CreateSystemTrayDelegate(ash::SystemTray* tray) {
252 return new chromeos::SystemTrayDelegate(tray); 360 return new chromeos::SystemTrayDelegate(tray);
253 } 361 }
254 362
255 } // namespace chromeos 363 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698