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

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

Powered by Google App Engine
This is Rietveld 408576698