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

Side by Side Diff: ash/system/chromeos/network/tray_network.cc

Issue 12218116: Revert 181806 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 10 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 "ash/system/chromeos/network/tray_network.h" 5 #include "ash/system/chromeos/network/tray_network.h"
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "ash/system/chromeos/network/network_icon_animation.h"
10 #include "ash/system/chromeos/network/network_list_detailed_view.h" 9 #include "ash/system/chromeos/network/network_list_detailed_view.h"
11 #include "ash/system/chromeos/network/network_list_detailed_view_base.h" 10 #include "ash/system/chromeos/network/network_list_detailed_view_base.h"
12 #include "ash/system/chromeos/network/network_state_list_detailed_view.h" 11 #include "ash/system/chromeos/network/network_state_list_detailed_view.h"
13 #include "ash/system/chromeos/network/tray_network_state_observer.h" 12 #include "ash/system/chromeos/network/tray_network_state_observer.h"
14 #include "ash/system/tray/system_tray.h" 13 #include "ash/system/tray/system_tray.h"
15 #include "ash/system/tray/system_tray_delegate.h" 14 #include "ash/system/tray/system_tray_delegate.h"
16 #include "ash/system/tray/system_tray_notifier.h" 15 #include "ash/system/tray/system_tray_notifier.h"
17 #include "ash/system/tray/tray_constants.h" 16 #include "ash/system/tray/tray_constants.h"
18 #include "ash/system/tray/tray_item_more.h" 17 #include "ash/system/tray/tray_item_more.h"
19 #include "ash/system/tray/tray_item_view.h" 18 #include "ash/system/tray/tray_item_view.h"
20 #include "ash/system/tray/tray_notification_view.h" 19 #include "ash/system/tray/tray_notification_view.h"
21 #include "base/command_line.h" 20 #include "base/command_line.h"
22 #include "base/utf_string_conversions.h"
23 #include "chromeos/network/network_configuration_handler.h"
24 #include "chromeos/network/network_state.h"
25 #include "chromeos/network/network_state_handler.h" 21 #include "chromeos/network/network_state_handler.h"
26 #include "grit/ash_resources.h" 22 #include "grit/ash_resources.h"
27 #include "grit/ash_strings.h" 23 #include "grit/ash_strings.h"
28 #include "third_party/cros_system_api/dbus/service_constants.h" 24 #include "third_party/cros_system_api/dbus/service_constants.h"
29 #include "ui/base/accessibility/accessible_view_state.h" 25 #include "ui/base/accessibility/accessible_view_state.h"
30 #include "ui/base/l10n/l10n_util.h" 26 #include "ui/base/l10n/l10n_util.h"
31 #include "ui/base/resource/resource_bundle.h" 27 #include "ui/base/resource/resource_bundle.h"
32 #include "ui/views/controls/link.h" 28 #include "ui/views/controls/link.h"
33 #include "ui/views/controls/link_listener.h" 29 #include "ui/views/controls/link_listener.h"
34 #include "ui/views/layout/box_layout.h" 30 #include "ui/views/layout/box_layout.h"
(...skipping 22 matching lines...) Expand all
57 return 0; 53 return 0;
58 } 54 }
59 55
60 bool UseNewNetworkHandlers() { 56 bool UseNewNetworkHandlers() {
61 return CommandLine::ForCurrentProcess()->HasSwitch( 57 return CommandLine::ForCurrentProcess()->HasSwitch(
62 ash::switches::kAshEnableNewNetworkStatusArea); 58 ash::switches::kAshEnableNewNetworkStatusArea);
63 } 59 }
64 60
65 } // namespace 61 } // namespace
66 62
67 using chromeos::NetworkState;
68 using chromeos::NetworkStateHandler;
69
70 namespace ash { 63 namespace ash {
71 namespace internal { 64 namespace internal {
72 65
73 namespace tray { 66 namespace tray {
74 67
68 enum ColorTheme {
69 LIGHT,
70 DARK,
71 };
72
75 class NetworkMessages { 73 class NetworkMessages {
76 public: 74 public:
77 struct Message { 75 struct Message {
78 Message() : delegate(NULL) {} 76 Message() : delegate(NULL) {}
79 Message(NetworkTrayDelegate* in_delegate, 77 Message(NetworkTrayDelegate* in_delegate,
80 TrayNetwork::NetworkType network_type, 78 TrayNetwork::NetworkType network_type,
81 const string16& in_title, 79 const string16& in_title,
82 const string16& in_message, 80 const string16& in_message,
83 const std::vector<string16>& in_links) : 81 const std::vector<string16>& in_links) :
84 delegate(in_delegate), 82 delegate(in_delegate),
85 network_type_(network_type), 83 network_type_(network_type),
86 title(in_title), 84 title(in_title),
87 message(in_message), 85 message(in_message),
88 links(in_links) {} 86 links(in_links) {}
89 NetworkTrayDelegate* delegate; 87 NetworkTrayDelegate* delegate;
90 TrayNetwork::NetworkType network_type_; 88 TrayNetwork::NetworkType network_type_;
91 string16 title; 89 string16 title;
92 string16 message; 90 string16 message;
93 std::vector<string16> links; 91 std::vector<string16> links;
94 }; 92 };
95 typedef std::map<TrayNetwork::MessageType, Message> MessageMap; 93 typedef std::map<TrayNetwork::MessageType, Message> MessageMap;
96 94
97 MessageMap& messages() { return messages_; } 95 MessageMap& messages() { return messages_; }
98 const MessageMap& messages() const { return messages_; } 96 const MessageMap& messages() const { return messages_; }
99 97
100 private: 98 private:
101 MessageMap messages_; 99 MessageMap messages_;
102 }; 100 };
103 101
104 class NetworkTrayView : public TrayItemView, 102 class NetworkTrayView : public TrayItemView {
105 public network_icon::AnimationObserver {
106 public: 103 public:
107 explicit NetworkTrayView(TrayNetwork* network_tray) 104 NetworkTrayView(SystemTrayItem* owner, ColorTheme size)
108 : TrayItemView(network_tray), 105 : TrayItemView(owner), color_theme_(size) {
109 network_tray_(network_tray) {
110 SetLayoutManager( 106 SetLayoutManager(
111 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); 107 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0));
112 108
113 image_view_ = new views::ImageView; 109 image_view_ = color_theme_ == DARK ?
110 new FixedSizedImageView(0, kTrayPopupItemHeight) :
111 new views::ImageView;
114 AddChildView(image_view_); 112 AddChildView(image_view_);
115 113
116 NetworkIconInfo info; 114 NetworkIconInfo info;
117 if (UseNewNetworkHandlers()) { 115 Shell::GetInstance()->system_tray_delegate()->
118 UpdateNetworkStateHandlerIcon(); 116 GetMostRelevantNetworkIcon(&info, false);
119 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); 117 Update(info);
120 } else {
121 Shell::GetInstance()->system_tray_delegate()->
122 GetMostRelevantNetworkIcon(&info, false);
123 UpdateIcon(info.tray_icon_visible, info.image);
124 }
125 } 118 }
126 119
127 virtual ~NetworkTrayView() { 120 virtual ~NetworkTrayView() {}
128 if (UseNewNetworkHandlers())
129 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
130 }
131 121
132 void Update(const NetworkIconInfo& info) { 122 void Update(const NetworkIconInfo& info) {
133 if (UseNewNetworkHandlers()) 123 image_view_->SetImage(info.image);
134 return; 124 SetVisible(info.tray_icon_visible);
135 UpdateIcon(info.tray_icon_visible, info.image); 125 SchedulePaint();
136 UpdateConnectionStatus(info.name, info.connected); 126 UpdateConnectionStatus(info.name, info.connected);
137 } 127 }
138 128
139 void UpdateNetworkStateHandlerIcon() {
140 DCHECK(UseNewNetworkHandlers());
141 NetworkStateHandler* handler = NetworkStateHandler::Get();
142 gfx::ImageSkia image;
143 string16 name;
144 network_tray_->GetNetworkStateHandlerImageAndLabel(
145 network_icon::ICON_TYPE_TRAY, &image, &name);
146 bool show_in_tray = !image.isNull();
147 UpdateIcon(show_in_tray, image);
148 const NetworkState* connected_network = handler->ConnectedNetworkByType(
149 NetworkStateHandler::kMatchTypeNonVirtual);
150 if (connected_network)
151 UpdateConnectionStatus(UTF8ToUTF16(connected_network->name()), true);
152 else
153 UpdateConnectionStatus(string16(), false);
154 }
155
156 // views::View override. 129 // views::View override.
157 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE { 130 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE {
158 state->name = connection_status_string_; 131 state->name = connection_status_string_;
159 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; 132 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON;
160 } 133 }
161 134
162 // network_icon::AnimationObserver
163 virtual void NetworkIconChanged() OVERRIDE {
164 if (UseNewNetworkHandlers())
165 UpdateNetworkStateHandlerIcon();
166 }
167
168 private: 135 private:
169 // Updates connection status and notifies accessibility event when necessary. 136 // Updates connection status and notifies accessibility event when necessary.
170 void UpdateConnectionStatus(const string16& network_name, bool connected) { 137 void UpdateConnectionStatus(const string16& network_name, bool connected) {
171 string16 new_connection_status_string; 138 string16 new_connection_status_string;
172 if (connected) { 139 if (connected) {
173 new_connection_status_string = l10n_util::GetStringFUTF16( 140 new_connection_status_string = l10n_util::GetStringFUTF16(
174 IDS_ASH_STATUS_TRAY_NETWORK_CONNECTED, network_name); 141 IDS_ASH_STATUS_TRAY_NETWORK_CONNECTED, network_name);
175 } 142 }
176 if (new_connection_status_string != connection_status_string_) { 143 if (new_connection_status_string != connection_status_string_) {
177 connection_status_string_ = new_connection_status_string; 144 connection_status_string_ = new_connection_status_string;
178 if(!connection_status_string_.empty()) { 145 if(!connection_status_string_.empty()) {
179 GetWidget()->NotifyAccessibilityEvent( 146 GetWidget()->NotifyAccessibilityEvent(
180 this, ui::AccessibilityTypes::EVENT_ALERT, true); 147 this, ui::AccessibilityTypes::EVENT_ALERT, true);
181 } 148 }
182 } 149 }
183 } 150 }
184 151
185 void UpdateIcon(bool tray_icon_visible, const gfx::ImageSkia& image) {
186 image_view_->SetImage(image);
187 SetVisible(tray_icon_visible);
188 SchedulePaint();
189 }
190
191 TrayNetwork* network_tray_;
192 views::ImageView* image_view_; 152 views::ImageView* image_view_;
153 ColorTheme color_theme_;
193 string16 connection_status_string_; 154 string16 connection_status_string_;
194 155
195 DISALLOW_COPY_AND_ASSIGN(NetworkTrayView); 156 DISALLOW_COPY_AND_ASSIGN(NetworkTrayView);
196 }; 157 };
197 158
198 class NetworkDefaultView : public TrayItemMore, 159 class NetworkDefaultView : public TrayItemMore {
199 public network_icon::AnimationObserver {
200 public: 160 public:
201 NetworkDefaultView(TrayNetwork* network_tray, bool show_more) 161 NetworkDefaultView(SystemTrayItem* owner, bool show_more)
202 : TrayItemMore(network_tray, show_more), 162 : TrayItemMore(owner, show_more) {
203 network_tray_(network_tray) {
204 Update();
205 if (UseNewNetworkHandlers())
206 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this);
207 }
208
209 virtual ~NetworkDefaultView() {
210 if (UseNewNetworkHandlers())
211 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
212 }
213
214 void Update() {
215 if (UseNewNetworkHandlers()) {
216 gfx::ImageSkia image;
217 string16 label;
218 network_tray_->GetNetworkStateHandlerImageAndLabel(
219 network_icon::ICON_TYPE_DEFAULT_VIEW, &image, &label);
220 SetImage(&image);
221 SetLabel(label);
222 SetAccessibleName(label);
223 } else {
224 NetworkIconInfo info;
225 Shell::GetInstance()->system_tray_delegate()->
226 GetMostRelevantNetworkIcon(&info, true);
227 SetImage(&info.image);
228 SetLabel(info.description);
229 SetAccessibleName(info.description);
230 }
231 }
232
233 // network_icon::AnimationObserver
234 virtual void NetworkIconChanged() OVERRIDE {
235 Update(); 163 Update();
236 } 164 }
237 165
166 virtual ~NetworkDefaultView() {}
167
168 void Update() {
169 NetworkIconInfo info;
170 Shell::GetInstance()->system_tray_delegate()->
171 GetMostRelevantNetworkIcon(&info, true);
172 SetImage(&info.image);
173 SetLabel(info.description);
174 SetAccessibleName(info.description);
175 }
176
238 private: 177 private:
239 TrayNetwork* network_tray_;
240
241 DISALLOW_COPY_AND_ASSIGN(NetworkDefaultView); 178 DISALLOW_COPY_AND_ASSIGN(NetworkDefaultView);
242 }; 179 };
243 180
244 class NetworkWifiDetailedView : public NetworkDetailedView { 181 class NetworkWifiDetailedView : public NetworkDetailedView {
245 public: 182 public:
246 NetworkWifiDetailedView(SystemTrayItem* owner, bool wifi_enabled) 183 NetworkWifiDetailedView(SystemTrayItem* owner, bool wifi_enabled)
247 : NetworkDetailedView(owner) { 184 : NetworkDetailedView(owner) {
248 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, 185 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal,
249 kTrayPopupPaddingHorizontal, 186 kTrayPopupPaddingHorizontal,
250 10, 187 10,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 const chromeos::NetworkState* network) OVERRIDE { 224 const chromeos::NetworkState* network) OVERRIDE {
288 } 225 }
289 226
290 private: 227 private:
291 DISALLOW_COPY_AND_ASSIGN(NetworkWifiDetailedView); 228 DISALLOW_COPY_AND_ASSIGN(NetworkWifiDetailedView);
292 }; 229 };
293 230
294 class NetworkMessageView : public views::View, 231 class NetworkMessageView : public views::View,
295 public views::LinkListener { 232 public views::LinkListener {
296 public: 233 public:
297 NetworkMessageView(TrayNetwork* tray_network, 234 NetworkMessageView(TrayNetwork* owner,
298 TrayNetwork::MessageType message_type, 235 TrayNetwork::MessageType message_type,
299 const NetworkMessages::Message& network_msg) 236 const NetworkMessages::Message& network_msg)
300 : tray_network_(tray_network), 237 : owner_(owner),
301 message_type_(message_type), 238 message_type_(message_type),
302 network_type_(network_msg.network_type_) { 239 network_type_(network_msg.network_type_) {
303 SetLayoutManager( 240 SetLayoutManager(
304 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); 241 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1));
305 242
306 if (!network_msg.title.empty()) { 243 if (!network_msg.title.empty()) {
307 views::Label* title = new views::Label(network_msg.title); 244 views::Label* title = new views::Label(network_msg.title);
308 title->SetHorizontalAlignment(gfx::ALIGN_LEFT); 245 title->SetHorizontalAlignment(gfx::ALIGN_LEFT);
309 title->SetFont(title->font().DeriveFont(0, gfx::Font::BOLD)); 246 title->SetFont(title->font().DeriveFont(0, gfx::Font::BOLD));
310 AddChildView(title); 247 AddChildView(title);
(...skipping 18 matching lines...) Expand all
329 AddChildView(link); 266 AddChildView(link);
330 } 267 }
331 } 268 }
332 } 269 }
333 270
334 virtual ~NetworkMessageView() { 271 virtual ~NetworkMessageView() {
335 } 272 }
336 273
337 // Overridden from views::LinkListener. 274 // Overridden from views::LinkListener.
338 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE { 275 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE {
339 tray_network_->LinkClicked(message_type_, source->id()); 276 owner_->LinkClicked(message_type_, source->id());
340 } 277 }
341 278
342 TrayNetwork::MessageType message_type() const { return message_type_; } 279 TrayNetwork::MessageType message_type() const { return message_type_; }
343 TrayNetwork::NetworkType network_type() const { return network_type_; } 280 TrayNetwork::NetworkType network_type() const { return network_type_; }
344 281
345 private: 282 private:
346 TrayNetwork* tray_network_; 283 TrayNetwork* owner_;
347 TrayNetwork::MessageType message_type_; 284 TrayNetwork::MessageType message_type_;
348 TrayNetwork::NetworkType network_type_; 285 TrayNetwork::NetworkType network_type_;
349 286
350 DISALLOW_COPY_AND_ASSIGN(NetworkMessageView); 287 DISALLOW_COPY_AND_ASSIGN(NetworkMessageView);
351 }; 288 };
352 289
353 class NetworkNotificationView : public TrayNotificationView { 290 class NetworkNotificationView : public TrayNotificationView {
354 public: 291 public:
355 explicit NetworkNotificationView(TrayNetwork* tray_network) 292 explicit NetworkNotificationView(TrayNetwork* owner)
356 : TrayNotificationView(tray_network, 0), 293 : TrayNotificationView(owner, 0) {
357 tray_network_(tray_network) {
358 CreateMessageView(); 294 CreateMessageView();
359 InitView(network_message_view_); 295 InitView(network_message_view_);
360 SetIconImage(*ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 296 SetIconImage(*ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
361 GetMessageIcon(network_message_view_->message_type(), 297 GetMessageIcon(network_message_view_->message_type(),
362 network_message_view_->network_type()))); 298 network_message_view_->network_type())));
363 } 299 }
364 300
365 // Overridden from TrayNotificationView. 301 // Overridden from TrayNotificationView.
366 virtual void OnClose() OVERRIDE { 302 virtual void OnClose() OVERRIDE {
367 tray_network_->ClearNetworkMessage(network_message_view_->message_type()); 303 tray_network()->ClearNetworkMessage(network_message_view_->message_type());
368 } 304 }
369 305
370 virtual void OnClickAction() OVERRIDE { 306 virtual void OnClickAction() OVERRIDE {
371 if (network_message_view_->message_type() != 307 if (network_message_view_->message_type() !=
372 TrayNetwork::MESSAGE_DATA_PROMO) 308 TrayNetwork::MESSAGE_DATA_PROMO)
373 tray_network_->PopupDetailedView(0, true); 309 owner()->PopupDetailedView(0, true);
374 } 310 }
375 311
376 void Update() { 312 void Update() {
377 CreateMessageView(); 313 CreateMessageView();
378 UpdateViewAndImage(network_message_view_, 314 UpdateViewAndImage(network_message_view_,
379 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 315 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
380 GetMessageIcon(network_message_view_->message_type(), 316 GetMessageIcon(network_message_view_->message_type(),
381 network_message_view_->network_type()))); 317 network_message_view_->network_type())));
382 } 318 }
383 319
384 private: 320 private:
321 TrayNetwork* tray_network() {
322 return static_cast<TrayNetwork*>(owner());
323 }
324
385 void CreateMessageView() { 325 void CreateMessageView() {
386 // Display the first (highest priority) message. 326 // Display the first (highest priority) message.
387 CHECK(!tray_network_->messages()->messages().empty()); 327 CHECK(!tray_network()->messages()->messages().empty());
388 NetworkMessages::MessageMap::const_iterator iter = 328 NetworkMessages::MessageMap::const_iterator iter =
389 tray_network_->messages()->messages().begin(); 329 tray_network()->messages()->messages().begin();
390 network_message_view_ = 330 network_message_view_ =
391 new NetworkMessageView(tray_network_, iter->first, iter->second); 331 new NetworkMessageView(tray_network(), iter->first, iter->second);
392 } 332 }
393 333
394 TrayNetwork* tray_network_;
395 tray::NetworkMessageView* network_message_view_; 334 tray::NetworkMessageView* network_message_view_;
396 335
397 DISALLOW_COPY_AND_ASSIGN(NetworkNotificationView); 336 DISALLOW_COPY_AND_ASSIGN(NetworkNotificationView);
398 }; 337 };
399 338
400 } // namespace tray 339 } // namespace tray
401 340
402 TrayNetwork::TrayNetwork(SystemTray* system_tray) 341 TrayNetwork::TrayNetwork(SystemTray* system_tray)
403 : SystemTrayItem(system_tray), 342 : SystemTrayItem(system_tray),
404 tray_(NULL), 343 tray_(NULL),
405 default_(NULL), 344 default_(NULL),
406 detailed_(NULL), 345 detailed_(NULL),
407 notification_(NULL), 346 notification_(NULL),
408 messages_(new tray::NetworkMessages()), 347 messages_(new tray::NetworkMessages()),
409 request_wifi_view_(false), 348 request_wifi_view_(false) {
410 uninitialized_msg_(0) {
411 if (UseNewNetworkHandlers()) 349 if (UseNewNetworkHandlers())
412 network_state_observer_.reset(new TrayNetworkStateObserver(this)); 350 network_state_observer_.reset(new TrayNetworkStateObserver(this));
413 Shell::GetInstance()->system_tray_notifier()->AddNetworkObserver(this); 351 Shell::GetInstance()->system_tray_notifier()->AddNetworkObserver(this);
414 } 352 }
415 353
416 TrayNetwork::~TrayNetwork() { 354 TrayNetwork::~TrayNetwork() {
417 Shell::GetInstance()->system_tray_notifier()->RemoveNetworkObserver(this); 355 Shell::GetInstance()->system_tray_notifier()->RemoveNetworkObserver(this);
418 } 356 }
419 357
420 views::View* TrayNetwork::CreateTrayView(user::LoginStatus status) { 358 views::View* TrayNetwork::CreateTrayView(user::LoginStatus status) {
421 CHECK(tray_ == NULL); 359 CHECK(tray_ == NULL);
422 tray_ = new tray::NetworkTrayView(this); 360 tray_ = new tray::NetworkTrayView(this, tray::LIGHT);
423 return tray_; 361 return tray_;
424 } 362 }
425 363
426 views::View* TrayNetwork::CreateDefaultView(user::LoginStatus status) { 364 views::View* TrayNetwork::CreateDefaultView(user::LoginStatus status) {
427 CHECK(default_ == NULL); 365 CHECK(default_ == NULL);
428 CHECK(tray_ != NULL); 366 default_ =
429 default_ = new tray::NetworkDefaultView( 367 new tray::NetworkDefaultView(this, status != user::LOGGED_IN_LOCKED);
430 this, status != user::LOGGED_IN_LOCKED);
431 return default_; 368 return default_;
432 } 369 }
433 370
434 views::View* TrayNetwork::CreateDetailedView(user::LoginStatus status) { 371 views::View* TrayNetwork::CreateDetailedView(user::LoginStatus status) {
435 CHECK(detailed_ == NULL); 372 CHECK(detailed_ == NULL);
436 // Clear any notifications when showing the detailed view. 373 // Clear any notifications when showing the detailed view.
437 messages_->messages().clear(); 374 messages_->messages().clear();
438 HideNotificationView(); 375 HideNotificationView();
439 if (request_wifi_view_) { 376 if (request_wifi_view_) {
440 SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); 377 SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate();
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 void TrayNetwork::OnWillToggleWifi() { 460 void TrayNetwork::OnWillToggleWifi() {
524 if (UseNewNetworkHandlers()) 461 if (UseNewNetworkHandlers())
525 return; // Handled in TrayNetworkStateObserver::NetworkManagerChanged() 462 return; // Handled in TrayNetworkStateObserver::NetworkManagerChanged()
526 if (!detailed_ || 463 if (!detailed_ ||
527 detailed_->GetViewType() == tray::NetworkDetailedView::WIFI_VIEW) { 464 detailed_->GetViewType() == tray::NetworkDetailedView::WIFI_VIEW) {
528 request_wifi_view_ = true; 465 request_wifi_view_ = true;
529 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false); 466 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false);
530 } 467 }
531 } 468 }
532 469
533 void TrayNetwork::TrayNetworkUpdated() {
534 if (tray_ && UseNewNetworkHandlers())
535 tray_->UpdateNetworkStateHandlerIcon();
536 if (default_)
537 default_->Update();
538 }
539
540 void TrayNetwork::NetworkServiceChanged(const chromeos::NetworkState* network) {
541 if (!network->IsConnectingState())
542 connecting_networks_.erase(network->path());
543 }
544
545 void TrayNetwork::ConnectToNetwork(const std::string& service_path) {
546 DCHECK(UseNewNetworkHandlers());
547 const NetworkState* network =
548 NetworkStateHandler::Get()->GetNetworkState(service_path);
549 if (!network)
550 return;
551 if (!network->IsConnectedState()) {
552 chromeos::NetworkConfigurationHandler::Get()->Connect(
553 service_path,
554 base::Bind(&base::DoNothing),
555 chromeos::network_handler::ErrorCallback());
556 connecting_networks_.insert(service_path);
557 } else {
558 // This will show the settings UI for a connected network.
559 // TODO(stevenjb): Change the API to explicitly show network settings.
560 Shell::GetInstance()->system_tray_delegate()->ConnectToNetwork(
561 service_path);
562 }
563 }
564
565 bool TrayNetwork::HasConnectingNetwork(const std::string& service_path) {
566 return connecting_networks_.count(service_path) > 0;
567 }
568
569 void TrayNetwork::GetNetworkStateHandlerImageAndLabel(
570 network_icon::IconType icon_type,
571 gfx::ImageSkia* image,
572 string16* label) {
573 NetworkStateHandler* handler = NetworkStateHandler::Get();
574 const NetworkState* network = handler->ConnectedNetworkByType(
575 NetworkStateHandler::kMatchTypeNonVirtual);
576 if (network && network->type() == flimflam::kTypeEthernet &&
577 icon_type == network_icon::ICON_TYPE_TRAY) {
578 *image = gfx::ImageSkia(); // Don't show ethernet in the tray.
579 return;
580 }
581 const NetworkState* connecting_network = handler->ConnectingNetworkByType(
582 NetworkStateHandler::kMatchTypeWireless);
583 // If we are connecting to a network, and there is either no connected
584 // network, or the connection was user requested, use the connecting
585 // network.
586 if (connecting_network &&
587 (!network ||
588 HasConnectingNetwork(connecting_network->path()))) {
589 network = connecting_network;
590 }
591 if (!network) {
592 // If no connecting network, check for cellular initializing.
593 int uninitialized_msg = GetUninitializedMsg();
594 if (uninitialized_msg != 0) {
595 *image = network_icon::GetImageForConnectingNetwork(
596 icon_type, flimflam::kTypeCellular);
597 if (label)
598 *label = l10n_util::GetStringUTF16(uninitialized_msg);
599 } else {
600 // Otherwise show the disconnected wifi icon.
601 *image = network_icon::GetImageForDisconnectedNetwork(
602 icon_type, flimflam::kTypeWifi);
603 if (label) {
604 *label = l10n_util::GetStringUTF16(
605 IDS_ASH_STATUS_TRAY_NETWORK_NOT_CONNECTED);
606 }
607 }
608 return;
609 }
610 // Get icon and label for connected or connecting network.
611 *image = network_icon::GetImageForNetwork(network, icon_type);
612 if (label)
613 *label = network_icon::GetLabelForNetwork(network, icon_type);
614 }
615
616 int TrayNetwork::GetUninitializedMsg() {
617 NetworkStateHandler* handler = NetworkStateHandler::Get();
618 if (handler->TechnologyUninitialized(
619 NetworkStateHandler::kMatchTypeMobile)) {
620 uninitialized_msg_ = IDS_ASH_STATUS_TRAY_INITIALIZING_CELLULAR;
621 uninitialized_state_time_ = base::Time::Now();
622 return uninitialized_msg_;
623 } else if (handler->GetScanningByType(
624 NetworkStateHandler::kMatchTypeMobile)) {
625 uninitialized_msg_ = IDS_ASH_STATUS_TRAY_CELLULAR_SCANNING;
626 uninitialized_state_time_ = base::Time::Now();
627 return uninitialized_msg_;
628 }
629 // There can be a delay between leaving the Initializing state and when
630 // a Cellular device shows up, so keep showing the initializing
631 // animation for a bit to avoid flashing the disconnect icon.
632 const int kInitializingDelaySeconds = 1;
633 base::TimeDelta dtime = base::Time::Now() - uninitialized_state_time_;
634 if (dtime.InSeconds() < kInitializingDelaySeconds)
635 return uninitialized_msg_;
636 return 0;
637 }
638
639 void TrayNetwork::LinkClicked(MessageType message_type, int link_id) { 470 void TrayNetwork::LinkClicked(MessageType message_type, int link_id) {
640 tray::NetworkMessages::MessageMap::const_iterator iter = 471 tray::NetworkMessages::MessageMap::const_iterator iter =
641 messages()->messages().find(message_type); 472 messages()->messages().find(message_type);
642 if (iter != messages()->messages().end() && iter->second.delegate) 473 if (iter != messages()->messages().end() && iter->second.delegate)
643 iter->second.delegate->NotificationLinkClicked(link_id); 474 iter->second.delegate->NotificationLinkClicked(link_id);
644 } 475 }
645 476
646 } // namespace internal 477 } // namespace internal
647 } // namespace ash 478 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/chromeos/network/tray_network.h ('k') | ash/system/chromeos/network/tray_network_state_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698