| 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_icon_animation.h" |
| 10 #include "ash/system/chromeos/network/network_list_detailed_view.h" | 10 #include "ash/system/chromeos/network/network_list_detailed_view.h" |
| 11 #include "ash/system/chromeos/network/network_list_detailed_view_base.h" | 11 #include "ash/system/chromeos/network/network_list_detailed_view_base.h" |
| 12 #include "ash/system/chromeos/network/network_state_list_detailed_view.h" | 12 #include "ash/system/chromeos/network/network_state_list_detailed_view.h" |
| 13 #include "ash/system/chromeos/network/network_state_notifier.h" | 13 #include "ash/system/chromeos/network/network_state_notifier.h" |
| 14 #include "ash/system/chromeos/network/network_tray_delegate.h" |
| 14 #include "ash/system/tray/system_tray.h" | 15 #include "ash/system/tray/system_tray.h" |
| 15 #include "ash/system/tray/system_tray_delegate.h" | 16 #include "ash/system/tray/system_tray_delegate.h" |
| 16 #include "ash/system/tray/system_tray_notifier.h" | 17 #include "ash/system/tray/system_tray_notifier.h" |
| 17 #include "ash/system/tray/tray_constants.h" | 18 #include "ash/system/tray/tray_constants.h" |
| 18 #include "ash/system/tray/tray_item_more.h" | 19 #include "ash/system/tray/tray_item_more.h" |
| 19 #include "ash/system/tray/tray_item_view.h" | 20 #include "ash/system/tray/tray_item_view.h" |
| 20 #include "ash/system/tray/tray_notification_view.h" | 21 #include "ash/system/tray/tray_notification_view.h" |
| 21 #include "base/command_line.h" | 22 #include "base/command_line.h" |
| 22 #include "base/utf_string_conversions.h" | 23 #include "base/utf_string_conversions.h" |
| 23 #include "chromeos/network/network_state.h" | 24 #include "chromeos/network/network_state.h" |
| 24 #include "chromeos/network/network_state_handler.h" | 25 #include "chromeos/network/network_state_handler.h" |
| 25 #include "grit/ash_resources.h" | 26 #include "grit/ash_resources.h" |
| 26 #include "grit/ash_strings.h" | 27 #include "grit/ash_strings.h" |
| 27 #include "third_party/cros_system_api/dbus/service_constants.h" | 28 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 28 #include "ui/base/accessibility/accessible_view_state.h" | 29 #include "ui/base/accessibility/accessible_view_state.h" |
| 29 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
| 30 #include "ui/base/resource/resource_bundle.h" | 31 #include "ui/base/resource/resource_bundle.h" |
| 31 #include "ui/views/controls/link.h" | 32 #include "ui/views/controls/link.h" |
| 32 #include "ui/views/controls/link_listener.h" | 33 #include "ui/views/controls/link_listener.h" |
| 33 #include "ui/views/layout/box_layout.h" | 34 #include "ui/views/layout/box_layout.h" |
| 34 #include "ui/views/widget/widget.h" | 35 #include "ui/views/widget/widget.h" |
| 35 | 36 |
| 37 using ash::internal::TrayNetwork; |
| 38 using ash::NetworkObserver; |
| 36 using chromeos::NetworkState; | 39 using chromeos::NetworkState; |
| 37 using chromeos::NetworkStateHandler; | 40 using chromeos::NetworkStateHandler; |
| 38 | 41 |
| 39 namespace { | 42 namespace { |
| 40 | 43 |
| 41 using ash::internal::TrayNetwork; | 44 int GetMessageIcon(NetworkObserver::MessageType message_type, |
| 42 | 45 NetworkObserver::NetworkType network_type) { |
| 43 int GetMessageIcon( | |
| 44 TrayNetwork::MessageType message_type, | |
| 45 TrayNetwork::NetworkType network_type) { | |
| 46 switch(message_type) { | 46 switch(message_type) { |
| 47 case TrayNetwork::ERROR_CONNECT_FAILED: | 47 case NetworkObserver::ERROR_CONNECT_FAILED: |
| 48 if (TrayNetwork::NETWORK_CELLULAR == network_type) | 48 if (NetworkObserver::NETWORK_CELLULAR == network_type) |
| 49 return IDR_AURA_UBER_TRAY_CELLULAR_NETWORK_FAILED; | 49 return IDR_AURA_UBER_TRAY_CELLULAR_NETWORK_FAILED; |
| 50 else | 50 else |
| 51 return IDR_AURA_UBER_TRAY_NETWORK_FAILED; | 51 return IDR_AURA_UBER_TRAY_NETWORK_FAILED; |
| 52 case TrayNetwork::MESSAGE_DATA_PROMO: | 52 case NetworkObserver::ERROR_OUT_OF_CREDITS: |
| 53 case NetworkObserver::MESSAGE_DATA_PROMO: |
| 53 if (network_type == TrayNetwork::NETWORK_CELLULAR_LTE) | 54 if (network_type == TrayNetwork::NETWORK_CELLULAR_LTE) |
| 54 return IDR_AURA_UBER_TRAY_NOTIFICATION_LTE; | 55 return IDR_AURA_UBER_TRAY_NOTIFICATION_LTE; |
| 55 else | 56 else |
| 56 return IDR_AURA_UBER_TRAY_NOTIFICATION_3G; | 57 return IDR_AURA_UBER_TRAY_NOTIFICATION_3G; |
| 57 } | 58 } |
| 58 NOTREACHED(); | 59 NOTREACHED(); |
| 59 return 0; | 60 return 0; |
| 60 } | 61 } |
| 61 | 62 |
| 62 bool UseNewNetworkHandlers() { | 63 bool UseNewNetworkHandlers() { |
| 63 return !CommandLine::ForCurrentProcess()->HasSwitch( | 64 return !CommandLine::ForCurrentProcess()->HasSwitch( |
| 64 ash::switches::kAshDisableNewNetworkStatusArea) && | 65 ash::switches::kAshDisableNewNetworkStatusArea) && |
| 65 NetworkStateHandler::IsInitialized(); | 66 NetworkStateHandler::IsInitialized(); |
| 66 } | 67 } |
| 67 | 68 |
| 68 } // namespace | 69 } // namespace |
| 69 | 70 |
| 70 namespace ash { | 71 namespace ash { |
| 71 namespace internal { | 72 namespace internal { |
| 72 | 73 |
| 73 namespace tray { | 74 namespace tray { |
| 74 | 75 |
| 75 class NetworkMessages { | 76 class NetworkMessages { |
| 76 public: | 77 public: |
| 77 struct Message { | 78 struct Message { |
| 78 Message() : delegate(NULL) {} | 79 Message() : delegate(NULL) {} |
| 79 Message(NetworkTrayDelegate* in_delegate, | 80 Message(NetworkTrayDelegate* in_delegate, |
| 80 TrayNetwork::NetworkType network_type, | 81 NetworkObserver::NetworkType network_type, |
| 81 const string16& in_title, | 82 const string16& in_title, |
| 82 const string16& in_message, | 83 const string16& in_message, |
| 83 const std::vector<string16>& in_links) : | 84 const std::vector<string16>& in_links) : |
| 84 delegate(in_delegate), | 85 delegate(in_delegate), |
| 85 network_type_(network_type), | 86 network_type_(network_type), |
| 86 title(in_title), | 87 title(in_title), |
| 87 message(in_message), | 88 message(in_message), |
| 88 links(in_links) {} | 89 links(in_links) {} |
| 89 NetworkTrayDelegate* delegate; | 90 NetworkTrayDelegate* delegate; |
| 90 TrayNetwork::NetworkType network_type_; | 91 NetworkObserver::NetworkType network_type_; |
| 91 string16 title; | 92 string16 title; |
| 92 string16 message; | 93 string16 message; |
| 93 std::vector<string16> links; | 94 std::vector<string16> links; |
| 94 }; | 95 }; |
| 95 typedef std::map<TrayNetwork::MessageType, Message> MessageMap; | 96 typedef std::map<NetworkObserver::MessageType, Message> MessageMap; |
| 96 | 97 |
| 97 MessageMap& messages() { return messages_; } | 98 MessageMap& messages() { return messages_; } |
| 98 const MessageMap& messages() const { return messages_; } | 99 const MessageMap& messages() const { return messages_; } |
| 99 | 100 |
| 100 private: | 101 private: |
| 101 MessageMap messages_; | 102 MessageMap messages_; |
| 102 }; | 103 }; |
| 103 | 104 |
| 104 class NetworkTrayView : public TrayItemView, | 105 class NetworkTrayView : public TrayItemView, |
| 105 public network_icon::AnimationObserver { | 106 public network_icon::AnimationObserver { |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 } | 289 } |
| 289 | 290 |
| 290 private: | 291 private: |
| 291 DISALLOW_COPY_AND_ASSIGN(NetworkWifiDetailedView); | 292 DISALLOW_COPY_AND_ASSIGN(NetworkWifiDetailedView); |
| 292 }; | 293 }; |
| 293 | 294 |
| 294 class NetworkMessageView : public views::View, | 295 class NetworkMessageView : public views::View, |
| 295 public views::LinkListener { | 296 public views::LinkListener { |
| 296 public: | 297 public: |
| 297 NetworkMessageView(TrayNetwork* tray_network, | 298 NetworkMessageView(TrayNetwork* tray_network, |
| 298 TrayNetwork::MessageType message_type, | 299 NetworkObserver::MessageType message_type, |
| 299 const NetworkMessages::Message& network_msg) | 300 const NetworkMessages::Message& network_msg) |
| 300 : tray_network_(tray_network), | 301 : tray_network_(tray_network), |
| 301 message_type_(message_type), | 302 message_type_(message_type), |
| 302 network_type_(network_msg.network_type_) { | 303 network_type_(network_msg.network_type_) { |
| 303 SetLayoutManager( | 304 SetLayoutManager( |
| 304 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); | 305 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); |
| 305 | 306 |
| 306 if (!network_msg.title.empty()) { | 307 if (!network_msg.title.empty()) { |
| 307 views::Label* title = new views::Label(network_msg.title); | 308 views::Label* title = new views::Label(network_msg.title); |
| 308 title->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 309 title->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 332 } | 333 } |
| 333 | 334 |
| 334 virtual ~NetworkMessageView() { | 335 virtual ~NetworkMessageView() { |
| 335 } | 336 } |
| 336 | 337 |
| 337 // Overridden from views::LinkListener. | 338 // Overridden from views::LinkListener. |
| 338 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE { | 339 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE { |
| 339 tray_network_->LinkClicked(message_type_, source->id()); | 340 tray_network_->LinkClicked(message_type_, source->id()); |
| 340 } | 341 } |
| 341 | 342 |
| 342 TrayNetwork::MessageType message_type() const { return message_type_; } | 343 NetworkObserver::MessageType message_type() const { return message_type_; } |
| 343 TrayNetwork::NetworkType network_type() const { return network_type_; } | 344 NetworkObserver::NetworkType network_type() const { return network_type_; } |
| 344 | 345 |
| 345 private: | 346 private: |
| 346 TrayNetwork* tray_network_; | 347 TrayNetwork* tray_network_; |
| 347 TrayNetwork::MessageType message_type_; | 348 NetworkObserver::MessageType message_type_; |
| 348 TrayNetwork::NetworkType network_type_; | 349 NetworkObserver::NetworkType network_type_; |
| 349 | 350 |
| 350 DISALLOW_COPY_AND_ASSIGN(NetworkMessageView); | 351 DISALLOW_COPY_AND_ASSIGN(NetworkMessageView); |
| 351 }; | 352 }; |
| 352 | 353 |
| 353 class NetworkNotificationView : public TrayNotificationView { | 354 class NetworkNotificationView : public TrayNotificationView { |
| 354 public: | 355 public: |
| 355 explicit NetworkNotificationView(TrayNetwork* tray_network) | 356 explicit NetworkNotificationView(TrayNetwork* tray_network) |
| 356 : TrayNotificationView(tray_network, 0), | 357 : TrayNotificationView(tray_network, 0), |
| 357 tray_network_(tray_network) { | 358 tray_network_(tray_network) { |
| 358 CreateMessageView(); | 359 CreateMessageView(); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 void TrayNetwork::OnNetworkRefresh(const NetworkIconInfo& info) { | 492 void TrayNetwork::OnNetworkRefresh(const NetworkIconInfo& info) { |
| 492 if (tray_) | 493 if (tray_) |
| 493 tray_->Update(info); | 494 tray_->Update(info); |
| 494 if (default_) | 495 if (default_) |
| 495 default_->Update(); | 496 default_->Update(); |
| 496 if (detailed_) | 497 if (detailed_) |
| 497 detailed_->ManagerChanged(); | 498 detailed_->ManagerChanged(); |
| 498 } | 499 } |
| 499 | 500 |
| 500 void TrayNetwork::SetNetworkMessage(NetworkTrayDelegate* delegate, | 501 void TrayNetwork::SetNetworkMessage(NetworkTrayDelegate* delegate, |
| 501 MessageType message_type, | 502 MessageType message_type, |
| 502 NetworkType network_type, | 503 NetworkType network_type, |
| 503 const string16& title, | 504 const string16& title, |
| 504 const string16& message, | 505 const string16& message, |
| 505 const std::vector<string16>& links) { | 506 const std::vector<string16>& links) { |
| 506 messages_->messages()[message_type] = tray::NetworkMessages::Message( | 507 messages_->messages()[message_type] = tray::NetworkMessages::Message( |
| 507 delegate, network_type, title, message, links); | 508 delegate, network_type, title, message, links); |
| 508 if (notification_) | 509 if (notification_) |
| 509 notification_->Update(); | 510 notification_->Update(); |
| 510 else | 511 else |
| 511 ShowNotificationView(); | 512 ShowNotificationView(); |
| 512 } | 513 } |
| 513 | 514 |
| 514 void TrayNetwork::ClearNetworkMessage(MessageType message_type) { | 515 void TrayNetwork::ClearNetworkMessage(MessageType message_type) { |
| 515 messages_->messages().erase(message_type); | 516 messages_->messages().erase(message_type); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 // Get icon and label for connected or connecting network. | 613 // Get icon and label for connected or connecting network. |
| 613 *image = network_icon::GetImageForNetwork(network, icon_type); | 614 *image = network_icon::GetImageForNetwork(network, icon_type); |
| 614 if (label) | 615 if (label) |
| 615 *label = network_icon::GetLabelForNetwork(network, icon_type); | 616 *label = network_icon::GetLabelForNetwork(network, icon_type); |
| 616 } | 617 } |
| 617 | 618 |
| 618 void TrayNetwork::LinkClicked(MessageType message_type, int link_id) { | 619 void TrayNetwork::LinkClicked(MessageType message_type, int link_id) { |
| 619 tray::NetworkMessages::MessageMap::const_iterator iter = | 620 tray::NetworkMessages::MessageMap::const_iterator iter = |
| 620 messages()->messages().find(message_type); | 621 messages()->messages().find(message_type); |
| 621 if (iter != messages()->messages().end() && iter->second.delegate) | 622 if (iter != messages()->messages().end() && iter->second.delegate) |
| 622 iter->second.delegate->NotificationLinkClicked(link_id); | 623 iter->second.delegate->NotificationLinkClicked(message_type, link_id); |
| 623 } | 624 } |
| 624 | 625 |
| 625 } // namespace internal | 626 } // namespace internal |
| 626 } // namespace ash | 627 } // namespace ash |
| OLD | NEW |