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 "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" |
9 #include "ash/system/chromeos/network/network_list_detailed_view.h" | 10 #include "ash/system/chromeos/network/network_list_detailed_view.h" |
10 #include "ash/system/chromeos/network/network_list_detailed_view_base.h" | 11 #include "ash/system/chromeos/network/network_list_detailed_view_base.h" |
11 #include "ash/system/chromeos/network/network_state_list_detailed_view.h" | 12 #include "ash/system/chromeos/network/network_state_list_detailed_view.h" |
12 #include "ash/system/chromeos/network/tray_network_state_observer.h" | 13 #include "ash/system/chromeos/network/tray_network_state_observer.h" |
13 #include "ash/system/tray/system_tray.h" | 14 #include "ash/system/tray/system_tray.h" |
14 #include "ash/system/tray/system_tray_delegate.h" | 15 #include "ash/system/tray/system_tray_delegate.h" |
15 #include "ash/system/tray/system_tray_notifier.h" | 16 #include "ash/system/tray/system_tray_notifier.h" |
16 #include "ash/system/tray/tray_constants.h" | 17 #include "ash/system/tray/tray_constants.h" |
17 #include "ash/system/tray/tray_item_more.h" | 18 #include "ash/system/tray/tray_item_more.h" |
18 #include "ash/system/tray/tray_item_view.h" | 19 #include "ash/system/tray/tray_item_view.h" |
19 #include "ash/system/tray/tray_notification_view.h" | 20 #include "ash/system/tray/tray_notification_view.h" |
20 #include "base/command_line.h" | 21 #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" |
21 #include "chromeos/network/network_state_handler.h" | 25 #include "chromeos/network/network_state_handler.h" |
22 #include "grit/ash_resources.h" | 26 #include "grit/ash_resources.h" |
23 #include "grit/ash_strings.h" | 27 #include "grit/ash_strings.h" |
24 #include "third_party/cros_system_api/dbus/service_constants.h" | 28 #include "third_party/cros_system_api/dbus/service_constants.h" |
25 #include "ui/base/accessibility/accessible_view_state.h" | 29 #include "ui/base/accessibility/accessible_view_state.h" |
26 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
27 #include "ui/base/resource/resource_bundle.h" | 31 #include "ui/base/resource/resource_bundle.h" |
28 #include "ui/views/controls/link.h" | 32 #include "ui/views/controls/link.h" |
29 #include "ui/views/controls/link_listener.h" | 33 #include "ui/views/controls/link_listener.h" |
30 #include "ui/views/layout/box_layout.h" | 34 #include "ui/views/layout/box_layout.h" |
(...skipping 22 matching lines...) Expand all Loading... |
53 return 0; | 57 return 0; |
54 } | 58 } |
55 | 59 |
56 bool UseNewNetworkHandlers() { | 60 bool UseNewNetworkHandlers() { |
57 return CommandLine::ForCurrentProcess()->HasSwitch( | 61 return CommandLine::ForCurrentProcess()->HasSwitch( |
58 ash::switches::kAshEnableNewNetworkStatusArea); | 62 ash::switches::kAshEnableNewNetworkStatusArea); |
59 } | 63 } |
60 | 64 |
61 } // namespace | 65 } // namespace |
62 | 66 |
| 67 using chromeos::NetworkState; |
| 68 using chromeos::NetworkStateHandler; |
| 69 |
63 namespace ash { | 70 namespace ash { |
64 namespace internal { | 71 namespace internal { |
65 | 72 |
66 namespace tray { | 73 namespace tray { |
67 | 74 |
68 enum ColorTheme { | |
69 LIGHT, | |
70 DARK, | |
71 }; | |
72 | |
73 class NetworkMessages { | 75 class NetworkMessages { |
74 public: | 76 public: |
75 struct Message { | 77 struct Message { |
76 Message() : delegate(NULL) {} | 78 Message() : delegate(NULL) {} |
77 Message(NetworkTrayDelegate* in_delegate, | 79 Message(NetworkTrayDelegate* in_delegate, |
78 TrayNetwork::NetworkType network_type, | 80 TrayNetwork::NetworkType network_type, |
79 const string16& in_title, | 81 const string16& in_title, |
80 const string16& in_message, | 82 const string16& in_message, |
81 const std::vector<string16>& in_links) : | 83 const std::vector<string16>& in_links) : |
82 delegate(in_delegate), | 84 delegate(in_delegate), |
83 network_type_(network_type), | 85 network_type_(network_type), |
84 title(in_title), | 86 title(in_title), |
85 message(in_message), | 87 message(in_message), |
86 links(in_links) {} | 88 links(in_links) {} |
87 NetworkTrayDelegate* delegate; | 89 NetworkTrayDelegate* delegate; |
88 TrayNetwork::NetworkType network_type_; | 90 TrayNetwork::NetworkType network_type_; |
89 string16 title; | 91 string16 title; |
90 string16 message; | 92 string16 message; |
91 std::vector<string16> links; | 93 std::vector<string16> links; |
92 }; | 94 }; |
93 typedef std::map<TrayNetwork::MessageType, Message> MessageMap; | 95 typedef std::map<TrayNetwork::MessageType, Message> MessageMap; |
94 | 96 |
95 MessageMap& messages() { return messages_; } | 97 MessageMap& messages() { return messages_; } |
96 const MessageMap& messages() const { return messages_; } | 98 const MessageMap& messages() const { return messages_; } |
97 | 99 |
98 private: | 100 private: |
99 MessageMap messages_; | 101 MessageMap messages_; |
100 }; | 102 }; |
101 | 103 |
102 class NetworkTrayView : public TrayItemView { | 104 class NetworkTrayView : public TrayItemView, |
| 105 public network_icon::AnimationObserver { |
103 public: | 106 public: |
104 NetworkTrayView(SystemTrayItem* owner, ColorTheme size) | 107 explicit NetworkTrayView(TrayNetwork* network_tray) |
105 : TrayItemView(owner), color_theme_(size) { | 108 : TrayItemView(network_tray), |
| 109 network_tray_(network_tray) { |
106 SetLayoutManager( | 110 SetLayoutManager( |
107 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); | 111 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); |
108 | 112 |
109 image_view_ = color_theme_ == DARK ? | 113 image_view_ = new views::ImageView; |
110 new FixedSizedImageView(0, kTrayPopupItemHeight) : | |
111 new views::ImageView; | |
112 AddChildView(image_view_); | 114 AddChildView(image_view_); |
113 | 115 |
114 NetworkIconInfo info; | 116 NetworkIconInfo info; |
115 Shell::GetInstance()->system_tray_delegate()-> | 117 if (UseNewNetworkHandlers()) { |
116 GetMostRelevantNetworkIcon(&info, false); | 118 UpdateNetworkStateHandlerIcon(); |
117 Update(info); | 119 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); |
| 120 } else { |
| 121 Shell::GetInstance()->system_tray_delegate()-> |
| 122 GetMostRelevantNetworkIcon(&info, false); |
| 123 UpdateIcon(info.tray_icon_visible, info.image); |
| 124 } |
118 } | 125 } |
119 | 126 |
120 virtual ~NetworkTrayView() {} | 127 virtual ~NetworkTrayView() { |
| 128 if (UseNewNetworkHandlers()) |
| 129 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); |
| 130 } |
121 | 131 |
122 void Update(const NetworkIconInfo& info) { | 132 void Update(const NetworkIconInfo& info) { |
123 image_view_->SetImage(info.image); | 133 if (UseNewNetworkHandlers()) |
124 SetVisible(info.tray_icon_visible); | 134 return; |
125 SchedulePaint(); | 135 UpdateIcon(info.tray_icon_visible, info.image); |
126 UpdateConnectionStatus(info.name, info.connected); | 136 UpdateConnectionStatus(info.name, info.connected); |
127 } | 137 } |
128 | 138 |
| 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 |
129 // views::View override. | 156 // views::View override. |
130 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE { | 157 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE { |
131 state->name = connection_status_string_; | 158 state->name = connection_status_string_; |
132 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; | 159 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; |
133 } | 160 } |
134 | 161 |
| 162 // network_icon::AnimationObserver |
| 163 virtual void NetworkIconChanged() OVERRIDE { |
| 164 if (UseNewNetworkHandlers()) |
| 165 UpdateNetworkStateHandlerIcon(); |
| 166 } |
| 167 |
135 private: | 168 private: |
136 // Updates connection status and notifies accessibility event when necessary. | 169 // Updates connection status and notifies accessibility event when necessary. |
137 void UpdateConnectionStatus(const string16& network_name, bool connected) { | 170 void UpdateConnectionStatus(const string16& network_name, bool connected) { |
138 string16 new_connection_status_string; | 171 string16 new_connection_status_string; |
139 if (connected) { | 172 if (connected) { |
140 new_connection_status_string = l10n_util::GetStringFUTF16( | 173 new_connection_status_string = l10n_util::GetStringFUTF16( |
141 IDS_ASH_STATUS_TRAY_NETWORK_CONNECTED, network_name); | 174 IDS_ASH_STATUS_TRAY_NETWORK_CONNECTED, network_name); |
142 } | 175 } |
143 if (new_connection_status_string != connection_status_string_) { | 176 if (new_connection_status_string != connection_status_string_) { |
144 connection_status_string_ = new_connection_status_string; | 177 connection_status_string_ = new_connection_status_string; |
145 if(!connection_status_string_.empty()) { | 178 if(!connection_status_string_.empty()) { |
146 GetWidget()->NotifyAccessibilityEvent( | 179 GetWidget()->NotifyAccessibilityEvent( |
147 this, ui::AccessibilityTypes::EVENT_ALERT, true); | 180 this, ui::AccessibilityTypes::EVENT_ALERT, true); |
148 } | 181 } |
149 } | 182 } |
150 } | 183 } |
151 | 184 |
| 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_; |
152 views::ImageView* image_view_; | 192 views::ImageView* image_view_; |
153 ColorTheme color_theme_; | |
154 string16 connection_status_string_; | 193 string16 connection_status_string_; |
155 | 194 |
156 DISALLOW_COPY_AND_ASSIGN(NetworkTrayView); | 195 DISALLOW_COPY_AND_ASSIGN(NetworkTrayView); |
157 }; | 196 }; |
158 | 197 |
159 class NetworkDefaultView : public TrayItemMore { | 198 class NetworkDefaultView : public TrayItemMore, |
| 199 public network_icon::AnimationObserver { |
160 public: | 200 public: |
161 NetworkDefaultView(SystemTrayItem* owner, bool show_more) | 201 NetworkDefaultView(TrayNetwork* network_tray, bool show_more) |
162 : TrayItemMore(owner, show_more) { | 202 : TrayItemMore(network_tray, 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 { |
163 Update(); | 235 Update(); |
164 } | 236 } |
165 | 237 |
166 virtual ~NetworkDefaultView() {} | 238 private: |
| 239 TrayNetwork* network_tray_; |
167 | 240 |
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 | |
177 private: | |
178 DISALLOW_COPY_AND_ASSIGN(NetworkDefaultView); | 241 DISALLOW_COPY_AND_ASSIGN(NetworkDefaultView); |
179 }; | 242 }; |
180 | 243 |
181 class NetworkWifiDetailedView : public NetworkDetailedView { | 244 class NetworkWifiDetailedView : public NetworkDetailedView { |
182 public: | 245 public: |
183 NetworkWifiDetailedView(SystemTrayItem* owner, bool wifi_enabled) | 246 NetworkWifiDetailedView(SystemTrayItem* owner, bool wifi_enabled) |
184 : NetworkDetailedView(owner) { | 247 : NetworkDetailedView(owner) { |
185 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, | 248 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, |
186 kTrayPopupPaddingHorizontal, | 249 kTrayPopupPaddingHorizontal, |
187 10, | 250 10, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 const chromeos::NetworkState* network) OVERRIDE { | 287 const chromeos::NetworkState* network) OVERRIDE { |
225 } | 288 } |
226 | 289 |
227 private: | 290 private: |
228 DISALLOW_COPY_AND_ASSIGN(NetworkWifiDetailedView); | 291 DISALLOW_COPY_AND_ASSIGN(NetworkWifiDetailedView); |
229 }; | 292 }; |
230 | 293 |
231 class NetworkMessageView : public views::View, | 294 class NetworkMessageView : public views::View, |
232 public views::LinkListener { | 295 public views::LinkListener { |
233 public: | 296 public: |
234 NetworkMessageView(TrayNetwork* owner, | 297 NetworkMessageView(TrayNetwork* tray_network, |
235 TrayNetwork::MessageType message_type, | 298 TrayNetwork::MessageType message_type, |
236 const NetworkMessages::Message& network_msg) | 299 const NetworkMessages::Message& network_msg) |
237 : owner_(owner), | 300 : tray_network_(tray_network), |
238 message_type_(message_type), | 301 message_type_(message_type), |
239 network_type_(network_msg.network_type_) { | 302 network_type_(network_msg.network_type_) { |
240 SetLayoutManager( | 303 SetLayoutManager( |
241 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); | 304 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); |
242 | 305 |
243 if (!network_msg.title.empty()) { | 306 if (!network_msg.title.empty()) { |
244 views::Label* title = new views::Label(network_msg.title); | 307 views::Label* title = new views::Label(network_msg.title); |
245 title->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 308 title->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
246 title->SetFont(title->font().DeriveFont(0, gfx::Font::BOLD)); | 309 title->SetFont(title->font().DeriveFont(0, gfx::Font::BOLD)); |
247 AddChildView(title); | 310 AddChildView(title); |
(...skipping 18 matching lines...) Expand all Loading... |
266 AddChildView(link); | 329 AddChildView(link); |
267 } | 330 } |
268 } | 331 } |
269 } | 332 } |
270 | 333 |
271 virtual ~NetworkMessageView() { | 334 virtual ~NetworkMessageView() { |
272 } | 335 } |
273 | 336 |
274 // Overridden from views::LinkListener. | 337 // Overridden from views::LinkListener. |
275 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE { | 338 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE { |
276 owner_->LinkClicked(message_type_, source->id()); | 339 tray_network_->LinkClicked(message_type_, source->id()); |
277 } | 340 } |
278 | 341 |
279 TrayNetwork::MessageType message_type() const { return message_type_; } | 342 TrayNetwork::MessageType message_type() const { return message_type_; } |
280 TrayNetwork::NetworkType network_type() const { return network_type_; } | 343 TrayNetwork::NetworkType network_type() const { return network_type_; } |
281 | 344 |
282 private: | 345 private: |
283 TrayNetwork* owner_; | 346 TrayNetwork* tray_network_; |
284 TrayNetwork::MessageType message_type_; | 347 TrayNetwork::MessageType message_type_; |
285 TrayNetwork::NetworkType network_type_; | 348 TrayNetwork::NetworkType network_type_; |
286 | 349 |
287 DISALLOW_COPY_AND_ASSIGN(NetworkMessageView); | 350 DISALLOW_COPY_AND_ASSIGN(NetworkMessageView); |
288 }; | 351 }; |
289 | 352 |
290 class NetworkNotificationView : public TrayNotificationView { | 353 class NetworkNotificationView : public TrayNotificationView { |
291 public: | 354 public: |
292 explicit NetworkNotificationView(TrayNetwork* owner) | 355 explicit NetworkNotificationView(TrayNetwork* tray_network) |
293 : TrayNotificationView(owner, 0) { | 356 : TrayNotificationView(tray_network, 0), |
| 357 tray_network_(tray_network) { |
294 CreateMessageView(); | 358 CreateMessageView(); |
295 InitView(network_message_view_); | 359 InitView(network_message_view_); |
296 SetIconImage(*ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 360 SetIconImage(*ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
297 GetMessageIcon(network_message_view_->message_type(), | 361 GetMessageIcon(network_message_view_->message_type(), |
298 network_message_view_->network_type()))); | 362 network_message_view_->network_type()))); |
299 } | 363 } |
300 | 364 |
301 // Overridden from TrayNotificationView. | 365 // Overridden from TrayNotificationView. |
302 virtual void OnClose() OVERRIDE { | 366 virtual void OnClose() OVERRIDE { |
303 tray_network()->ClearNetworkMessage(network_message_view_->message_type()); | 367 tray_network_->ClearNetworkMessage(network_message_view_->message_type()); |
304 } | 368 } |
305 | 369 |
306 virtual void OnClickAction() OVERRIDE { | 370 virtual void OnClickAction() OVERRIDE { |
307 if (network_message_view_->message_type() != | 371 if (network_message_view_->message_type() != |
308 TrayNetwork::MESSAGE_DATA_PROMO) | 372 TrayNetwork::MESSAGE_DATA_PROMO) |
309 owner()->PopupDetailedView(0, true); | 373 tray_network_->PopupDetailedView(0, true); |
310 } | 374 } |
311 | 375 |
312 void Update() { | 376 void Update() { |
313 CreateMessageView(); | 377 CreateMessageView(); |
314 UpdateViewAndImage(network_message_view_, | 378 UpdateViewAndImage(network_message_view_, |
315 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 379 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
316 GetMessageIcon(network_message_view_->message_type(), | 380 GetMessageIcon(network_message_view_->message_type(), |
317 network_message_view_->network_type()))); | 381 network_message_view_->network_type()))); |
318 } | 382 } |
319 | 383 |
320 private: | 384 private: |
321 TrayNetwork* tray_network() { | 385 void CreateMessageView() { |
322 return static_cast<TrayNetwork*>(owner()); | 386 // Display the first (highest priority) message. |
| 387 CHECK(!tray_network_->messages()->messages().empty()); |
| 388 NetworkMessages::MessageMap::const_iterator iter = |
| 389 tray_network_->messages()->messages().begin(); |
| 390 network_message_view_ = |
| 391 new NetworkMessageView(tray_network_, iter->first, iter->second); |
323 } | 392 } |
324 | 393 |
325 void CreateMessageView() { | 394 TrayNetwork* tray_network_; |
326 // Display the first (highest priority) message. | |
327 CHECK(!tray_network()->messages()->messages().empty()); | |
328 NetworkMessages::MessageMap::const_iterator iter = | |
329 tray_network()->messages()->messages().begin(); | |
330 network_message_view_ = | |
331 new NetworkMessageView(tray_network(), iter->first, iter->second); | |
332 } | |
333 | |
334 tray::NetworkMessageView* network_message_view_; | 395 tray::NetworkMessageView* network_message_view_; |
335 | 396 |
336 DISALLOW_COPY_AND_ASSIGN(NetworkNotificationView); | 397 DISALLOW_COPY_AND_ASSIGN(NetworkNotificationView); |
337 }; | 398 }; |
338 | 399 |
339 } // namespace tray | 400 } // namespace tray |
340 | 401 |
341 TrayNetwork::TrayNetwork(SystemTray* system_tray) | 402 TrayNetwork::TrayNetwork(SystemTray* system_tray) |
342 : SystemTrayItem(system_tray), | 403 : SystemTrayItem(system_tray), |
343 tray_(NULL), | 404 tray_(NULL), |
344 default_(NULL), | 405 default_(NULL), |
345 detailed_(NULL), | 406 detailed_(NULL), |
346 notification_(NULL), | 407 notification_(NULL), |
347 messages_(new tray::NetworkMessages()), | 408 messages_(new tray::NetworkMessages()), |
348 request_wifi_view_(false) { | 409 request_wifi_view_(false), |
| 410 uninitialized_msg_(0) { |
349 if (UseNewNetworkHandlers()) | 411 if (UseNewNetworkHandlers()) |
350 network_state_observer_.reset(new TrayNetworkStateObserver(this)); | 412 network_state_observer_.reset(new TrayNetworkStateObserver(this)); |
351 Shell::GetInstance()->system_tray_notifier()->AddNetworkObserver(this); | 413 Shell::GetInstance()->system_tray_notifier()->AddNetworkObserver(this); |
352 } | 414 } |
353 | 415 |
354 TrayNetwork::~TrayNetwork() { | 416 TrayNetwork::~TrayNetwork() { |
355 Shell::GetInstance()->system_tray_notifier()->RemoveNetworkObserver(this); | 417 Shell::GetInstance()->system_tray_notifier()->RemoveNetworkObserver(this); |
356 } | 418 } |
357 | 419 |
358 views::View* TrayNetwork::CreateTrayView(user::LoginStatus status) { | 420 views::View* TrayNetwork::CreateTrayView(user::LoginStatus status) { |
359 CHECK(tray_ == NULL); | 421 CHECK(tray_ == NULL); |
360 tray_ = new tray::NetworkTrayView(this, tray::LIGHT); | 422 tray_ = new tray::NetworkTrayView(this); |
361 return tray_; | 423 return tray_; |
362 } | 424 } |
363 | 425 |
364 views::View* TrayNetwork::CreateDefaultView(user::LoginStatus status) { | 426 views::View* TrayNetwork::CreateDefaultView(user::LoginStatus status) { |
365 CHECK(default_ == NULL); | 427 CHECK(default_ == NULL); |
366 default_ = | 428 CHECK(tray_ != NULL); |
367 new tray::NetworkDefaultView(this, status != user::LOGGED_IN_LOCKED); | 429 default_ = new tray::NetworkDefaultView( |
| 430 this, status != user::LOGGED_IN_LOCKED); |
368 return default_; | 431 return default_; |
369 } | 432 } |
370 | 433 |
371 views::View* TrayNetwork::CreateDetailedView(user::LoginStatus status) { | 434 views::View* TrayNetwork::CreateDetailedView(user::LoginStatus status) { |
372 CHECK(detailed_ == NULL); | 435 CHECK(detailed_ == NULL); |
373 // Clear any notifications when showing the detailed view. | 436 // Clear any notifications when showing the detailed view. |
374 messages_->messages().clear(); | 437 messages_->messages().clear(); |
375 HideNotificationView(); | 438 HideNotificationView(); |
376 if (request_wifi_view_) { | 439 if (request_wifi_view_) { |
377 SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); | 440 SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 void TrayNetwork::OnWillToggleWifi() { | 523 void TrayNetwork::OnWillToggleWifi() { |
461 if (UseNewNetworkHandlers()) | 524 if (UseNewNetworkHandlers()) |
462 return; // Handled in TrayNetworkStateObserver::NetworkManagerChanged() | 525 return; // Handled in TrayNetworkStateObserver::NetworkManagerChanged() |
463 if (!detailed_ || | 526 if (!detailed_ || |
464 detailed_->GetViewType() == tray::NetworkDetailedView::WIFI_VIEW) { | 527 detailed_->GetViewType() == tray::NetworkDetailedView::WIFI_VIEW) { |
465 request_wifi_view_ = true; | 528 request_wifi_view_ = true; |
466 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false); | 529 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false); |
467 } | 530 } |
468 } | 531 } |
469 | 532 |
| 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 |
470 void TrayNetwork::LinkClicked(MessageType message_type, int link_id) { | 639 void TrayNetwork::LinkClicked(MessageType message_type, int link_id) { |
471 tray::NetworkMessages::MessageMap::const_iterator iter = | 640 tray::NetworkMessages::MessageMap::const_iterator iter = |
472 messages()->messages().find(message_type); | 641 messages()->messages().find(message_type); |
473 if (iter != messages()->messages().end() && iter->second.delegate) | 642 if (iter != messages()->messages().end() && iter->second.delegate) |
474 iter->second.delegate->NotificationLinkClicked(link_id); | 643 iter->second.delegate->NotificationLinkClicked(link_id); |
475 } | 644 } |
476 | 645 |
477 } // namespace internal | 646 } // namespace internal |
478 } // namespace ash | 647 } // namespace ash |
OLD | NEW |