1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_CHROMEOS_STATUS_NETWORK_MENU_BUTTON_H_ 6 #define CHROME_BROWSER_CHROMEOS_STATUS_NETWORK_MENU_BUTTON_H_ 7 #pragma once 8 9 #include <string> 10 11 #include "base/task.h" 12 #include "base/timer.h" 13 #include "chrome/browser/chromeos/cros/network_library.h" 14 #include "chrome/browser/chromeos/customization_document.h" 15 #include "chrome/browser/chromeos/login/message_bubble.h" 16 #include "chrome/browser/chromeos/status/network_menu.h" 17 #include "chrome/browser/chromeos/status/status_area_button.h" 18 #include "ui/base/animation/throb_animation.h" 19 20 namespace gfx { 21 class Canvas; 22 } 23 24 namespace chromeos { 25 26 class StatusAreaHost; 27 28 // The network menu button in the status area. 29 // This class will handle getting the wifi networks and populating the menu. 30 // It will also handle the status icon changing and connecting to another 31 // wifi/cellular network. 32 // 33 // The network menu looks like this: 34 // 35 // <icon> Ethernet 36 // <icon> Wifi Network A 37 // <icon> Wifi Network B 38 // <icon> Wifi Network C 39 // <icon> Cellular Network A 40 // <icon> Cellular Network B 41 // <icon> Cellular Network C 42 // <icon> Other... 43 // -------------------------------- 44 // Disable Wifi 45 // Disable Celluar 46 // -------------------------------- 47 // <IP Address> 48 // Network settings... 49 // 50 // <icon> will show the strength of the wifi/cellular networks. 51 // The label will be BOLD if the network is currently connected. 52 class NetworkMenuButton : public StatusAreaButton, 53 public NetworkMenu, 54 public NetworkLibrary::NetworkDeviceObserver, 55 public NetworkLibrary::NetworkManagerObserver, 56 public NetworkLibrary::NetworkObserver, 57 public NetworkLibrary::CellularDataPlanObserver, 58 public MessageBubbleDelegate { 59 public: 60 explicit NetworkMenuButton(StatusAreaHost* host); 61 virtual ~NetworkMenuButton(); 62 63 // ui::AnimationDelegate implementation. 64 virtual void AnimationProgressed(const ui::Animation* animation); 65 66 // NetworkLibrary::NetworkDeviceObserver implementation. 67 virtual void OnNetworkDeviceChanged(NetworkLibrary* cros, 68 const NetworkDevice* device); 69 // NetworkLibrary::NetworkManagerObserver implementation. 70 virtual void OnNetworkManagerChanged(NetworkLibrary* cros); 71 // NetworkLibrary::NetworkObserver implementation. 72 virtual void OnNetworkChanged(NetworkLibrary* cros, const Network* network); 73 // NetworkLibrary::CellularDataPlanObserver implementation. 74 virtual void OnCellularDataPlanChanged(NetworkLibrary* cros); 75 76 // NetworkMenu implementation: 77 virtual bool IsBrowserMode() const; 78 79 protected: 80 // NetworkMenu implementation: 81 virtual gfx::NativeWindow GetNativeWindow() const; 82 virtual void OpenButtonOptions(); 83 virtual bool ShouldOpenButtonOptions() const; 84 85 // views::View 86 virtual void OnLocaleChanged() OVERRIDE; 87 88 // MessageBubbleDelegate implementation: BubbleClosing(Bubble * bubble,bool closed_by_escape)89 virtual void BubbleClosing(Bubble* bubble, bool closed_by_escape) { 90 mobile_data_bubble_ = NULL; 91 } CloseOnEscape()92 virtual bool CloseOnEscape() { return true; } FadeInOnShow()93 virtual bool FadeInOnShow() { return false; } 94 virtual void OnHelpLinkActivated(); 95 96 private: 97 // Returns carrier deal if it's specified and should be shown, 98 // otherwise returns NULL. 99 const ServicesCustomizationDocument::CarrierDeal* GetCarrierDeal( 100 NetworkLibrary* cros); 101 102 // Sets the icon and the badges (badges are at the bottom of the icon). 103 void SetIconAndBadges(const SkBitmap* icon, 104 const SkBitmap* right_badge, 105 const SkBitmap* left_badge); 106 // Sets the icon only. Keep the previous badge. 107 void SetIconOnly(const SkBitmap* icon); 108 // Sets the badges only. Keep the previous icon. 109 void SetBadgesOnly(const SkBitmap* right_badge, const SkBitmap* left_badge); 110 // Set the network icon based on the status of the |network| 111 void SetNetworkIcon(NetworkLibrary* cros, const Network* network); 112 113 // Called when the list of devices has possibly changed. This will remove 114 // old network device observers and add a network observers 115 // for the new devices. 116 void RefreshNetworkDeviceObserver(NetworkLibrary* cros); 117 118 // Called when the active network has possibly changed. This will remove 119 // old network observer and add a network observer for the active network. 120 void RefreshNetworkObserver(NetworkLibrary* cros); 121 122 // Shows 3G promo notification if needed. 123 void ShowOptionalMobileDataPromoNotification(NetworkLibrary* cros); 124 125 // Path of the Cellular device that we monitor property updates from. 126 std::string cellular_device_path_; 127 128 // The icon showing the network strength. 129 const SkBitmap* icon_; 130 // A badge icon displayed on top of icon, in bottom-right corner. 131 const SkBitmap* right_badge_; 132 // A badge icon displayed on top of icon, in bottom-left corner. 133 const SkBitmap* left_badge_; 134 135 // Notification bubble for 3G promo. 136 MessageBubble* mobile_data_bubble_; 137 138 // True if check for promo needs to be done, 139 // otherwise just ignore it for current session. 140 bool check_for_promo_; 141 142 // Cellular device SIM was locked when we last checked 143 bool was_sim_locked_; 144 145 // The throb animation that does the wifi connecting animation. 146 ui::ThrobAnimation animation_connecting_; 147 148 // The duration of the icon throbbing in milliseconds. 149 static const int kThrobDuration; 150 151 // If any network is currently active, this is the service path of the one 152 // whose status is displayed in the network menu button. 153 std::string active_network_; 154 155 // Current carrier deal URL. 156 std::string deal_url_; 157 158 // Factory for delaying showing promo notification. 159 ScopedRunnableMethodFactory<NetworkMenuButton> method_factory_; 160 161 DISALLOW_COPY_AND_ASSIGN(NetworkMenuButton); 162 }; 163 164 } // namespace chromeos 165 166 #endif // CHROME_BROWSER_CHROMEOS_STATUS_NETWORK_MENU_BUTTON_H_ 167