Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/status/network_menu.h" | 5 #include "chrome/browser/chromeos/status/network_menu.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/browser/chromeos/choose_mobile_network_dialog.h" | 13 #include "chrome/browser/chromeos/choose_mobile_network_dialog.h" |
| 14 #include "chrome/browser/chromeos/cros/cros_library.h" | 14 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 15 #include "chrome/browser/chromeos/customization_document.h" | 15 #include "chrome/browser/chromeos/customization_document.h" |
| 16 #include "chrome/browser/chromeos/sim_dialog_delegate.h" | 16 #include "chrome/browser/chromeos/sim_dialog_delegate.h" |
| 17 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
| 18 #include "chrome/browser/ui/browser_list.h" | 18 #include "chrome/browser/ui/browser_list.h" |
| 19 #include "chrome/browser/ui/views/window.h" | 19 #include "chrome/browser/ui/views/window.h" |
| 20 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
| 21 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
| 22 #include "content/browser/browser_thread.h" | |
| 22 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
| 23 #include "grit/theme_resources.h" | 24 #include "grit/theme_resources.h" |
| 24 #include "net/base/escape.h" | 25 #include "net/base/escape.h" |
| 25 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
| 26 #include "ui/base/resource/resource_bundle.h" | 27 #include "ui/base/resource/resource_bundle.h" |
| 27 #include "ui/gfx/canvas_skia.h" | 28 #include "ui/gfx/canvas_skia.h" |
| 28 #include "ui/gfx/skbitmap_operations.h" | 29 #include "ui/gfx/skbitmap_operations.h" |
| 29 #include "views/controls/menu/menu_2.h" | 30 #include "views/controls/menu/menu_item_view.h" |
| 31 #include "views/controls/menu/submenu_view.h" | |
| 30 #include "views/window/window.h" | 32 #include "views/window/window.h" |
| 31 | 33 |
| 32 namespace { | 34 namespace { |
| 33 | 35 |
| 34 // Replace '&' in a string with "&&" to allow it to be a menu item label. | 36 // Replace '&' in a string with "&&" to allow it to be a menu item label. |
| 35 std::string EscapeAmpersands(const std::string& input) { | 37 std::string EscapeAmpersands(const std::string& input) { |
| 36 std::string str = input; | 38 std::string str = input; |
| 37 size_t found = str.find('&'); | 39 size_t found = str.find('&'); |
| 38 while (found != std::string::npos) { | 40 while (found != std::string::npos) { |
| 39 str.replace(found, 1, "&&"); | 41 str.replace(found, 1, "&&"); |
| 40 found = str.find('&', found + 2); | 42 found = str.find('&', found + 2); |
| 41 } | 43 } |
| 42 return str; | 44 return str; |
| 43 } | 45 } |
| 44 | 46 |
| 47 // Offsets for views menu ids (main menu and submenu ids use the same | |
| 48 // namespace). | |
| 49 const int kMainIndexOffset = 1000; | |
| 50 const int kVPNIndexOffset = 2000; | |
| 51 const int kMoreIndexOffset = 3000; | |
| 52 | |
| 53 // Default minimum width in pixels of the menu to prevent unnecessary | |
| 54 // resizing as networks are updated. | |
| 55 const int kDefaultMinimumWidth = 280; | |
| 56 | |
| 45 } // namespace | 57 } // namespace |
| 46 | 58 |
| 47 namespace chromeos { | 59 namespace chromeos { |
| 48 | 60 |
| 61 class NetworkMenuModel : public views::MenuDelegate { | |
| 62 public: | |
| 63 struct NetworkInfo { | |
| 64 NetworkInfo(); | |
| 65 ~NetworkInfo(); | |
| 66 | |
| 67 // "ethernet" | "wifi" | "cellular" | "other". | |
| 68 std::string network_type; | |
| 69 // "connected" | "connecting" | "disconnected" | "error". | |
| 70 std::string status; | |
| 71 // status message or error message, empty if unknown status. | |
| 72 std::string message; | |
| 73 // IP address (if network is active, empty otherwise) | |
| 74 std::string ip_address; | |
| 75 // Remembered passphrase. | |
| 76 std::string passphrase; | |
| 77 // true if the network requires a passphrase. | |
| 78 bool need_passphrase; | |
| 79 // true if the network is currently remembered. | |
| 80 bool remembered; | |
| 81 // true if the network is auto connect (meaningful for Wifi only). | |
| 82 bool auto_connect; | |
| 83 }; | |
| 84 | |
| 85 explicit NetworkMenuModel(NetworkMenu* owner); | |
| 86 virtual ~NetworkMenuModel(); | |
| 87 | |
| 88 // Connect or reconnect to the network at |index|. | |
| 89 // If remember >= 0, set the favorite state of the network. | |
| 90 void ConnectToNetworkAt(int index, | |
| 91 const std::string& passphrase, | |
| 92 const std::string& ssid, | |
| 93 int remember) const; | |
| 94 | |
| 95 // Called by NetworkMenu::RunMenu to initialize list of menu items. | |
| 96 virtual void InitMenuItems(bool is_browser_mode, | |
| 97 bool should_open_button_options) = 0; | |
| 98 | |
| 99 // PopulateMenu() clears and reinstalls the menu items defined in this | |
| 100 // instance by calling PopulateMenuItem() on each one. Subclasses override | |
| 101 // PopulateMenuItem(), transform command_id into the correct range for | |
| 102 // the menu, and call the base class PopulateMenuItem(). | |
| 103 virtual void PopulateMenu(views::MenuItemView* menu); | |
| 104 virtual void PopulateMenuItem(views::MenuItemView* menu, | |
| 105 int index, | |
| 106 int command_id); | |
| 107 | |
| 108 // Menu item field accessors. | |
| 109 int GetItemCount() const; | |
| 110 ui::MenuModel::ItemType GetTypeAt(int index) const; | |
| 111 string16 GetLabelAt(int index) const; | |
| 112 const gfx::Font* GetLabelFontAt(int index) const; | |
| 113 bool IsItemCheckedAt(int index) const; | |
| 114 bool GetIconAt(int index, SkBitmap* icon); | |
| 115 bool IsEnabledAt(int index) const; | |
| 116 NetworkMenuModel* GetSubmenuModelAt(int index) const; | |
| 117 void ActivatedAt(int index); | |
| 118 | |
| 119 protected: | |
| 120 enum MenuItemFlags { | |
| 121 FLAG_NONE = 0, | |
| 122 FLAG_DISABLED = 1 << 0, | |
| 123 FLAG_TOGGLE_ETHERNET = 1 << 1, | |
| 124 FLAG_TOGGLE_WIFI = 1 << 2, | |
| 125 FLAG_TOGGLE_CELLULAR = 1 << 3, | |
| 126 FLAG_TOGGLE_OFFLINE = 1 << 4, | |
| 127 FLAG_ASSOCIATED = 1 << 5, | |
| 128 FLAG_ETHERNET = 1 << 6, | |
| 129 FLAG_WIFI = 1 << 7, | |
| 130 FLAG_CELLULAR = 1 << 8, | |
| 131 FLAG_OPTIONS = 1 << 9, | |
| 132 FLAG_ADD_WIFI = 1 << 10, | |
| 133 FLAG_ADD_CELLULAR = 1 << 11, | |
| 134 FLAG_VPN = 1 << 12, | |
| 135 FLAG_ADD_VPN = 1 << 13, | |
| 136 FLAG_DISCONNECT_VPN = 1 << 14, | |
| 137 FLAG_VIEW_ACCOUNT = 1 << 15, | |
| 138 }; | |
| 139 | |
| 140 struct MenuItem { | |
| 141 MenuItem() | |
| 142 : type(ui::MenuModel::TYPE_SEPARATOR), | |
| 143 sub_menu_model(NULL), | |
| 144 flags(0) {} | |
| 145 MenuItem(ui::MenuModel::ItemType type, string16 label, SkBitmap icon, | |
| 146 const std::string& service_path, int flags) | |
| 147 : type(type), | |
| 148 label(label), | |
| 149 icon(icon), | |
| 150 service_path(service_path), | |
| 151 sub_menu_model(NULL), | |
| 152 flags(flags) {} | |
| 153 MenuItem(ui::MenuModel::ItemType type, string16 label, SkBitmap icon, | |
| 154 NetworkMenuModel* sub_menu_model, int flags) | |
| 155 : type(type), | |
| 156 label(label), | |
| 157 icon(icon), | |
| 158 sub_menu_model(sub_menu_model), | |
| 159 flags(flags) {} | |
| 160 | |
| 161 ui::MenuModel::ItemType type; | |
| 162 string16 label; | |
| 163 SkBitmap icon; | |
| 164 std::string service_path; | |
| 165 NetworkMenuModel* sub_menu_model; // Weak. | |
| 166 int flags; | |
| 167 }; | |
| 168 typedef std::vector<MenuItem> MenuItemVector; | |
| 169 | |
| 170 // Our menu items. | |
| 171 MenuItemVector menu_items_; | |
| 172 | |
| 173 NetworkMenu* owner_; // Weak pointer to NetworkMenu that owns this MenuModel. | |
| 174 | |
| 175 // Top up URL of the current carrier on empty string if there's none. | |
| 176 std::string top_up_url_; | |
| 177 | |
| 178 // Carrier ID which top up URL is initialized for. | |
| 179 // Used to update top up URL only when cellular carrier has changed. | |
| 180 std::string carrier_id_; | |
| 181 | |
| 182 private: | |
| 183 // Show a NetworkConfigView modal dialog instance. | |
| 184 void ShowNetworkConfigView(NetworkConfigView* view) const; | |
| 185 | |
| 186 void ActivateCellular(const CellularNetwork* cellular) const; | |
| 187 void ShowOther(ConnectionType type) const; | |
| 188 void ShowOtherCellular() const; | |
| 189 | |
| 190 DISALLOW_COPY_AND_ASSIGN(NetworkMenuModel); | |
| 191 }; | |
| 192 | |
| 49 class MoreMenuModel : public NetworkMenuModel { | 193 class MoreMenuModel : public NetworkMenuModel { |
| 50 public: | 194 public: |
| 51 explicit MoreMenuModel(NetworkMenu* owner); | 195 explicit MoreMenuModel(NetworkMenu* owner); |
| 52 virtual ~MoreMenuModel() {} | 196 virtual ~MoreMenuModel() {} |
| 53 | 197 |
| 54 // NetworkMenuModel implementation. | 198 // NetworkMenuModel implementation. |
| 55 virtual void InitMenuItems(bool is_browser_mode, | 199 virtual void InitMenuItems(bool is_browser_mode, |
| 56 bool should_open_button_options); | 200 bool should_open_button_options) OVERRIDE; |
| 201 virtual void PopulateMenuItem(views::MenuItemView* menu, | |
| 202 int index, | |
| 203 int command_id) OVERRIDE; | |
| 57 | 204 |
| 58 private: | 205 private: |
| 59 friend class MainMenuModel; | 206 friend class MainMenuModel; |
| 60 DISALLOW_COPY_AND_ASSIGN(MoreMenuModel); | 207 DISALLOW_COPY_AND_ASSIGN(MoreMenuModel); |
| 61 }; | 208 }; |
| 62 | 209 |
| 63 class VPNMenuModel : public NetworkMenuModel { | 210 class VPNMenuModel : public NetworkMenuModel { |
| 64 public: | 211 public: |
| 65 explicit VPNMenuModel(NetworkMenu* owner); | 212 explicit VPNMenuModel(NetworkMenu* owner); |
| 66 virtual ~VPNMenuModel() {} | 213 virtual ~VPNMenuModel() {} |
| 67 | 214 |
| 68 // NetworkMenuModel implementation. | 215 // NetworkMenuModel implementation. |
| 69 virtual void InitMenuItems(bool is_browser_mode, | 216 virtual void InitMenuItems(bool is_browser_mode, |
| 70 bool should_open_button_options); | 217 bool should_open_button_options) OVERRIDE; |
| 218 virtual void PopulateMenuItem(views::MenuItemView* menu, | |
| 219 int index, | |
| 220 int command_id) OVERRIDE; | |
| 71 | 221 |
| 72 static SkBitmap IconForDisplay(const Network* network); | 222 static SkBitmap IconForDisplay(const Network* network); |
| 73 | 223 |
| 74 private: | 224 private: |
| 75 DISALLOW_COPY_AND_ASSIGN(VPNMenuModel); | 225 DISALLOW_COPY_AND_ASSIGN(VPNMenuModel); |
| 76 }; | 226 }; |
| 77 | 227 |
| 78 class MainMenuModel : public NetworkMenuModel { | 228 class MainMenuModel : public NetworkMenuModel { |
| 79 public: | 229 public: |
| 80 explicit MainMenuModel(NetworkMenu* owner); | 230 explicit MainMenuModel(NetworkMenu* owner); |
| 81 virtual ~MainMenuModel() {} | 231 virtual ~MainMenuModel() {} |
| 82 | 232 |
| 83 // NetworkMenuModel implementation. | 233 // NetworkMenuModel implementation. |
| 84 virtual void InitMenuItems(bool is_browser_mode, | 234 virtual void InitMenuItems(bool is_browser_mode, |
| 85 bool should_open_button_options); | 235 bool should_open_button_options) OVERRIDE; |
| 236 virtual void PopulateMenuItem(views::MenuItemView* menu, | |
| 237 int index, | |
| 238 int command_id) OVERRIDE; | |
| 239 | |
| 240 // views::MenuDelegate implementation. | |
| 241 virtual const gfx::Font& GetLabelFont(int id) const OVERRIDE; | |
| 242 virtual bool IsItemChecked(int id) const OVERRIDE; | |
| 243 virtual bool IsCommandEnabled(int id) const OVERRIDE; | |
| 244 virtual void ExecuteCommand(int id) OVERRIDE; | |
| 86 | 245 |
| 87 private: | 246 private: |
| 88 scoped_ptr<NetworkMenuModel> vpn_menu_model_; | 247 scoped_ptr<NetworkMenuModel> vpn_menu_model_; |
| 89 scoped_ptr<MoreMenuModel> more_menu_model_; | 248 scoped_ptr<MoreMenuModel> more_menu_model_; |
| 90 | 249 |
| 91 DISALLOW_COPY_AND_ASSIGN(MainMenuModel); | 250 DISALLOW_COPY_AND_ASSIGN(MainMenuModel); |
| 92 }; | 251 }; |
| 93 | 252 |
| 253 // Forwarding proxy for NetworkMenu. This class is needed when UpdateMenu() | |
| 254 // is not called from the UI thread. A task is created with this reference | |
| 255 // counted class to update the menu in the proper thread. | |
| 256 class NetworkMenuTaskProxy | |
| 257 : public base::RefCountedThreadSafe<NetworkMenuTaskProxy> { | |
| 258 public: | |
| 259 explicit NetworkMenuTaskProxy(NetworkMenu* network_menu) | |
| 260 : network_menu_(network_menu) { | |
| 261 } | |
| 262 | |
| 263 // Forwarding function to run as a UI thread task. | |
| 264 void UpdateMenu() { | |
| 265 if (network_menu_) | |
| 266 network_menu_->UpdateMenuImpl(); | |
| 267 } | |
| 268 | |
| 269 // Call to avoid any future dereferencing of the wrapped NetworkMenu. | |
| 270 void Invalidate() { | |
| 271 network_menu_ = NULL; | |
| 272 } | |
| 273 | |
| 274 private: | |
| 275 NetworkMenu* network_menu_; | |
| 276 | |
| 277 DISALLOW_COPY_AND_ASSIGN(NetworkMenuTaskProxy); | |
| 278 }; | |
| 279 | |
| 94 //////////////////////////////////////////////////////////////////////////////// | 280 //////////////////////////////////////////////////////////////////////////////// |
| 95 // NetworkMenuModel::NetworkInfo | 281 // NetworkMenuModel::NetworkInfo |
| 96 | 282 |
| 97 NetworkMenuModel::NetworkInfo::NetworkInfo() | 283 NetworkMenuModel::NetworkInfo::NetworkInfo() |
| 98 : need_passphrase(false), remembered(true), auto_connect(true) { | 284 : need_passphrase(false), remembered(true), auto_connect(true) { |
| 99 } | 285 } |
| 100 | 286 |
| 101 NetworkMenuModel::NetworkInfo::~NetworkInfo() {} | 287 NetworkMenuModel::NetworkInfo::~NetworkInfo() {} |
| 102 | 288 |
| 103 //////////////////////////////////////////////////////////////////////////////// | 289 //////////////////////////////////////////////////////////////////////////////// |
| 104 // NetworkMenuModel, public methods: | 290 // NetworkMenuModel, public methods: |
| 105 | 291 |
| 106 NetworkMenuModel::NetworkMenuModel(NetworkMenu* owner) : owner_(owner) {} | 292 NetworkMenuModel::NetworkMenuModel(NetworkMenu* owner) : owner_(owner) {} |
| 107 | 293 |
| 108 NetworkMenuModel::~NetworkMenuModel() {} | 294 NetworkMenuModel::~NetworkMenuModel() {} |
| 109 | 295 |
| 110 bool NetworkMenuModel::ConnectToNetworkAt(int index, | 296 void NetworkMenuModel::PopulateMenu(views::MenuItemView* menu) { |
| 297 if (menu->HasSubmenu()) { | |
| 298 const int old_count = menu->GetSubmenu()->child_count(); | |
| 299 for (int i = 0; i < old_count; ++i) | |
| 300 menu->RemoveMenuItemAt(0); | |
| 301 } | |
| 302 | |
| 303 const int menu_items_count = GetItemCount(); | |
| 304 for (int i = 0; i < menu_items_count; ++i) | |
| 305 PopulateMenuItem(menu, i, i); | |
| 306 } | |
| 307 | |
| 308 void NetworkMenuModel::PopulateMenuItem( | |
| 309 views::MenuItemView* menu, | |
| 310 int index, | |
| 311 int command_id) { | |
| 312 DCHECK_GT(GetItemCount(), index); | |
| 313 switch (GetTypeAt(index)) { | |
| 314 case ui::MenuModel::TYPE_SEPARATOR: | |
| 315 menu->AppendSeparator(); | |
| 316 break; | |
| 317 case ui::MenuModel::TYPE_COMMAND: { | |
| 318 SkBitmap icon; | |
| 319 if (GetIconAt(index, &icon)) { | |
| 320 menu->AppendMenuItemWithIcon(command_id, | |
| 321 UTF16ToWide(GetLabelAt(index)), | |
| 322 icon); | |
| 323 } else { | |
| 324 menu->AppendMenuItemWithLabel(command_id, | |
| 325 UTF16ToWide(GetLabelAt(index))); | |
| 326 } | |
| 327 break; | |
| 328 } | |
| 329 case ui::MenuModel::TYPE_SUBMENU: { | |
| 330 views::MenuItemView* submenu = NULL; | |
| 331 SkBitmap icon; | |
| 332 if (GetIconAt(index, &icon)) { | |
| 333 submenu = menu->AppendSubMenuWithIcon(command_id, | |
| 334 UTF16ToWide(GetLabelAt(index)), | |
| 335 icon); | |
| 336 } else { | |
| 337 submenu = menu->AppendSubMenu(command_id, | |
| 338 UTF16ToWide(GetLabelAt(index))); | |
| 339 } | |
| 340 GetSubmenuModelAt(index)->PopulateMenu(submenu); | |
| 341 break; | |
| 342 } | |
| 343 default: | |
| 344 NOTREACHED(); | |
| 345 } | |
| 346 } | |
| 347 | |
| 348 void NetworkMenuModel::ConnectToNetworkAt(int index, | |
| 111 const std::string& passphrase, | 349 const std::string& passphrase, |
| 112 const std::string& ssid, | 350 const std::string& ssid, |
| 113 int auto_connect) const { | 351 int auto_connect) const { |
| 114 int flags = menu_items_[index].flags; | 352 int flags = menu_items_[index].flags; |
| 115 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); | 353 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); |
| 116 const std::string& service_path = menu_items_[index].service_path; | 354 const std::string& service_path = menu_items_[index].service_path; |
| 117 if (flags & FLAG_WIFI) { | 355 if (flags & FLAG_WIFI) { |
| 118 WifiNetwork* wifi = cros->FindWifiNetworkByPath(service_path); | 356 WifiNetwork* wifi = cros->FindWifiNetworkByPath(service_path); |
| 119 if (wifi) { | 357 if (wifi) { |
| 120 // Connect or reconnect. | 358 // Connect or reconnect. |
| 121 if (auto_connect >= 0) | 359 if (auto_connect >= 0) |
| 122 wifi->SetAutoConnect(auto_connect ? true : false); | 360 wifi->SetAutoConnect(auto_connect ? true : false); |
| 123 if (wifi->connecting_or_connected()) { | 361 if (wifi->connecting_or_connected()) { |
| 124 // Show the config settings for the active network. | 362 // Show the config settings for the active network. |
| 125 owner_->ShowTabbedNetworkSettings(wifi); | 363 owner_->ShowTabbedNetworkSettings(wifi); |
| 126 return true; | |
| 127 } | 364 } |
| 128 if (wifi->IsPassphraseRequired()) { | 365 if (wifi->IsPassphraseRequired()) { |
|
stevenjb
2011/05/18 18:43:36
else if
rhashimoto
2011/05/19 00:36:54
Yikes, thanks for catching these. Done.
| |
| 129 // Show the connection UI if we require a passphrase. | 366 // Show the connection UI if we require a passphrase. |
| 130 ShowNetworkConfigView(new NetworkConfigView(wifi)); | 367 ShowNetworkConfigView(new NetworkConfigView(wifi)); |
| 131 return true; | |
| 132 } else { | 368 } else { |
| 133 cros->ConnectToWifiNetwork(wifi); | 369 cros->ConnectToWifiNetwork(wifi); |
| 134 // Connection failures are responsible for updating the UI, including | 370 // Connection failures are responsible for updating the UI, including |
| 135 // reopening dialogs. | 371 // reopening dialogs. |
| 136 return true; | |
| 137 } | 372 } |
| 138 } else { | 373 } else { |
| 139 // If we are attempting to connect to a network that no longer exists, | 374 // If we are attempting to connect to a network that no longer exists, |
| 140 // display a notification. | 375 // display a notification. |
| 141 LOG(WARNING) << "Wi-fi network does not exist to connect to: " | 376 LOG(WARNING) << "Wi-fi network does not exist to connect to: " |
| 142 << service_path; | 377 << service_path; |
| 143 // TODO(stevenjb): Show notification. | 378 // TODO(stevenjb): Show notification. |
| 144 } | 379 } |
| 145 } else if (flags & FLAG_CELLULAR) { | 380 } else if (flags & FLAG_CELLULAR) { |
| 146 CellularNetwork* cellular = cros->FindCellularNetworkByPath( | 381 CellularNetwork* cellular = cros->FindCellularNetworkByPath( |
| 147 service_path); | 382 service_path); |
| 148 if (cellular) { | 383 if (cellular) { |
| 149 if ((cellular->activation_state() != ACTIVATION_STATE_ACTIVATED && | 384 if ((cellular->activation_state() != ACTIVATION_STATE_ACTIVATED && |
| 150 cellular->activation_state() != ACTIVATION_STATE_UNKNOWN) || | 385 cellular->activation_state() != ACTIVATION_STATE_UNKNOWN) || |
| 151 cellular->needs_new_plan()) { | 386 cellular->needs_new_plan()) { |
| 152 ActivateCellular(cellular); | 387 ActivateCellular(cellular); |
| 153 return true; | |
| 154 } else if (cellular->connecting_or_connected()) { | 388 } else if (cellular->connecting_or_connected()) { |
| 155 // Cellular network is connecting or connected, | 389 // Cellular network is connecting or connected, |
| 156 // so we show the config settings for the cellular network. | 390 // so we show the config settings for the cellular network. |
| 157 owner_->ShowTabbedNetworkSettings(cellular); | 391 owner_->ShowTabbedNetworkSettings(cellular); |
| 158 return true; | |
| 159 } | 392 } |
| 160 // Clicked on a disconnected cellular network, so connect to it. | 393 // Clicked on a disconnected cellular network, so connect to it. |
| 161 cros->ConnectToCellularNetwork(cellular); | 394 cros->ConnectToCellularNetwork(cellular); |
|
stevenjb
2011/05/18 18:43:36
else { }
rhashimoto
2011/05/19 00:36:54
Done.
| |
| 162 } else { | 395 } else { |
| 163 // If we are attempting to connect to a network that no longer exists, | 396 // If we are attempting to connect to a network that no longer exists, |
| 164 // display a notification. | 397 // display a notification. |
| 165 LOG(WARNING) << "Cellular network does not exist to connect to: " | 398 LOG(WARNING) << "Cellular network does not exist to connect to: " |
| 166 << service_path; | 399 << service_path; |
| 167 // TODO(stevenjb): Show notification. | 400 // TODO(stevenjb): Show notification. |
| 168 } | 401 } |
| 169 } else if (flags & FLAG_ADD_WIFI) { | 402 } else if (flags & FLAG_ADD_WIFI) { |
| 170 ShowOther(TYPE_WIFI); | 403 ShowOther(TYPE_WIFI); |
| 171 } else if (flags & FLAG_ADD_CELLULAR) { | 404 } else if (flags & FLAG_ADD_CELLULAR) { |
| 172 ShowOtherCellular(); | 405 ShowOtherCellular(); |
| 173 } else if (flags & FLAG_ADD_VPN) { | 406 } else if (flags & FLAG_ADD_VPN) { |
| 174 ShowOther(TYPE_VPN); | 407 ShowOther(TYPE_VPN); |
| 175 } else if (flags & FLAG_VPN) { | 408 } else if (flags & FLAG_VPN) { |
| 176 VirtualNetwork* vpn = cros->FindVirtualNetworkByPath(service_path); | 409 VirtualNetwork* vpn = cros->FindVirtualNetworkByPath(service_path); |
| 177 if (vpn) { | 410 if (vpn) { |
| 178 // Connect or reconnect. | 411 // Connect or reconnect. |
| 179 if (vpn->connecting_or_connected()) { | 412 if (vpn->connecting_or_connected()) { |
| 180 // Show the config settings for the connected network. | 413 // Show the config settings for the connected network. |
| 181 if (cros->connected_network()) | 414 if (cros->connected_network()) |
| 182 owner_->ShowTabbedNetworkSettings(cros->connected_network()); | 415 owner_->ShowTabbedNetworkSettings(cros->connected_network()); |
| 183 return true; | |
| 184 } | 416 } |
| 185 // Show the connection UI if info for a field is missing. | 417 // Show the connection UI if info for a field is missing. |
| 186 if (vpn->NeedMoreInfoToConnect()) { | 418 if (vpn->NeedMoreInfoToConnect()) { |
|
stevenjb
2011/05/18 18:43:36
else if
rhashimoto
2011/05/19 00:36:54
Done.
| |
| 187 ShowNetworkConfigView(new NetworkConfigView(vpn)); | 419 ShowNetworkConfigView(new NetworkConfigView(vpn)); |
| 188 return true; | |
| 189 } | 420 } |
| 190 cros->ConnectToVirtualNetwork(vpn); | 421 cros->ConnectToVirtualNetwork(vpn); |
|
stevenjb
2011/05/18 18:43:36
else { }
rhashimoto
2011/05/19 00:36:54
Done.
| |
| 191 // Connection failures are responsible for updating the UI, including | 422 // Connection failures are responsible for updating the UI, including |
| 192 // reopening dialogs. | 423 // reopening dialogs. |
| 193 return true; | |
| 194 } else { | 424 } else { |
| 195 // If we are attempting to connect to a network that no longer exists, | 425 // If we are attempting to connect to a network that no longer exists, |
| 196 // display a notification. | 426 // display a notification. |
| 197 LOG(WARNING) << "VPN does not exist to connect to: " << service_path; | 427 LOG(WARNING) << "VPN does not exist to connect to: " << service_path; |
| 198 // TODO(stevenjb): Show notification. | 428 // TODO(stevenjb): Show notification. |
| 199 } | 429 } |
| 200 } | 430 } |
| 201 return true; | |
| 202 } | 431 } |
| 203 | 432 |
| 204 //////////////////////////////////////////////////////////////////////////////// | 433 //////////////////////////////////////////////////////////////////////////////// |
| 205 // NetworkMenuModel, ui::MenuModel implementation: | 434 // NetworkMenuModel, ui::MenuModel implementation: |
| 206 | 435 |
| 207 bool NetworkMenuModel::HasIcons() const { | |
| 208 return true; | |
| 209 } | |
| 210 | |
| 211 int NetworkMenuModel::GetItemCount() const { | 436 int NetworkMenuModel::GetItemCount() const { |
| 212 return static_cast<int>(menu_items_.size()); | 437 return static_cast<int>(menu_items_.size()); |
| 213 } | 438 } |
| 214 | 439 |
| 215 ui::MenuModel::ItemType NetworkMenuModel::GetTypeAt(int index) const { | 440 ui::MenuModel::ItemType NetworkMenuModel::GetTypeAt(int index) const { |
| 216 return menu_items_[index].type; | 441 return menu_items_[index].type; |
| 217 } | 442 } |
| 218 | 443 |
| 219 int NetworkMenuModel::GetCommandIdAt(int index) const { | |
| 220 return index; | |
| 221 } | |
| 222 | |
| 223 string16 NetworkMenuModel::GetLabelAt(int index) const { | 444 string16 NetworkMenuModel::GetLabelAt(int index) const { |
| 224 return menu_items_[index].label; | 445 return menu_items_[index].label; |
| 225 } | 446 } |
| 226 | 447 |
| 227 bool NetworkMenuModel::IsItemDynamicAt(int index) const { | |
| 228 return true; | |
| 229 } | |
| 230 | |
| 231 const gfx::Font* NetworkMenuModel::GetLabelFontAt(int index) const { | 448 const gfx::Font* NetworkMenuModel::GetLabelFontAt(int index) const { |
| 232 return (menu_items_[index].flags & FLAG_ASSOCIATED) ? | 449 return (menu_items_[index].flags & FLAG_ASSOCIATED) ? |
| 233 &ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BoldFont) : | 450 &ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BoldFont) : |
| 234 NULL; | 451 NULL; |
| 235 } | 452 } |
| 236 | 453 |
| 237 bool NetworkMenuModel::GetAcceleratorAt( | |
| 238 int index, ui::Accelerator* accelerator) const { | |
| 239 return false; | |
| 240 } | |
| 241 | |
| 242 bool NetworkMenuModel::IsItemCheckedAt(int index) const { | 454 bool NetworkMenuModel::IsItemCheckedAt(int index) const { |
| 243 // All ui::MenuModel::TYPE_CHECK menu items are checked. | 455 // All ui::MenuModel::TYPE_CHECK menu items are checked. |
| 244 return true; | 456 return true; |
| 245 } | 457 } |
| 246 | 458 |
| 247 int NetworkMenuModel::GetGroupIdAt(int index) const { | |
| 248 return 0; | |
| 249 } | |
| 250 | |
| 251 bool NetworkMenuModel::GetIconAt(int index, SkBitmap* icon) { | 459 bool NetworkMenuModel::GetIconAt(int index, SkBitmap* icon) { |
| 252 if (!menu_items_[index].icon.empty()) { | 460 if (!menu_items_[index].icon.empty()) { |
| 253 *icon = menu_items_[index].icon; | 461 *icon = menu_items_[index].icon; |
| 254 return true; | 462 return true; |
| 255 } | 463 } |
| 256 return false; | 464 return false; |
| 257 } | 465 } |
| 258 | 466 |
| 259 ui::ButtonMenuItemModel* NetworkMenuModel::GetButtonMenuItemAt( | |
| 260 int index) const { | |
| 261 return NULL; | |
| 262 } | |
| 263 | |
| 264 bool NetworkMenuModel::IsEnabledAt(int index) const { | 467 bool NetworkMenuModel::IsEnabledAt(int index) const { |
| 265 return !(menu_items_[index].flags & FLAG_DISABLED); | 468 return !(menu_items_[index].flags & FLAG_DISABLED); |
| 266 } | 469 } |
| 267 | 470 |
| 268 ui::MenuModel* NetworkMenuModel::GetSubmenuModelAt(int index) const { | 471 NetworkMenuModel* NetworkMenuModel::GetSubmenuModelAt(int index) const { |
| 269 return menu_items_[index].sub_menu_model; | 472 return menu_items_[index].sub_menu_model; |
| 270 } | 473 } |
| 271 | 474 |
| 272 void NetworkMenuModel::HighlightChangedTo(int index) {} | |
| 273 | |
| 274 void NetworkMenuModel::ActivatedAt(int index) { | 475 void NetworkMenuModel::ActivatedAt(int index) { |
| 275 // When we are refreshing the menu, ignore menu item activation. | 476 // When we are refreshing the menu, ignore menu item activation. |
| 276 if (owner_->refreshing_menu_) | 477 if (owner_->refreshing_menu_) |
| 277 return; | 478 return; |
| 278 | 479 |
| 279 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); | 480 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); |
| 280 int flags = menu_items_[index].flags; | 481 int flags = menu_items_[index].flags; |
| 281 if (flags & FLAG_OPTIONS) { | 482 if (flags & FLAG_OPTIONS) { |
| 282 owner_->OpenButtonOptions(); | 483 owner_->OpenButtonOptions(); |
| 283 } else if (flags & FLAG_TOGGLE_ETHERNET) { | 484 } else if (flags & FLAG_TOGGLE_ETHERNET) { |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 312 const VirtualNetwork* active_vpn = cros->virtual_network(); | 513 const VirtualNetwork* active_vpn = cros->virtual_network(); |
| 313 if (active_vpn) | 514 if (active_vpn) |
| 314 cros->DisconnectFromNetwork(active_vpn); | 515 cros->DisconnectFromNetwork(active_vpn); |
| 315 } else if (flags & FLAG_VIEW_ACCOUNT) { | 516 } else if (flags & FLAG_VIEW_ACCOUNT) { |
| 316 Browser* browser = BrowserList::GetLastActive(); | 517 Browser* browser = BrowserList::GetLastActive(); |
| 317 if (browser) | 518 if (browser) |
| 318 browser->ShowSingletonTab(GURL(top_up_url_)); | 519 browser->ShowSingletonTab(GURL(top_up_url_)); |
| 319 } | 520 } |
| 320 } | 521 } |
| 321 | 522 |
| 322 void NetworkMenuModel::MenuWillShow() {} | |
| 323 | |
| 324 void NetworkMenuModel::SetMenuModelDelegate(ui::MenuModelDelegate* delegate) {} | |
| 325 | |
| 326 //////////////////////////////////////////////////////////////////////////////// | 523 //////////////////////////////////////////////////////////////////////////////// |
| 327 // NetworkMenuModel, private methods: | 524 // NetworkMenuModel, private methods: |
| 328 | 525 |
| 329 // TODO(stevenjb): deprecate this once we've committed to tabbed settings | 526 // TODO(stevenjb): deprecate this once we've committed to tabbed settings |
| 330 // and the embedded menu UI (and fully deprecated NetworkConfigView). | 527 // and the embedded menu UI (and fully deprecated NetworkConfigView). |
| 331 // Meanwhile, if MenuUI::IsEnabled() is true, always show the settings UI, | 528 // Meanwhile, if MenuUI::IsEnabled() is true, always show the settings UI, |
| 332 // otherwise show NetworkConfigView only to get passwords when not connected. | 529 // otherwise show NetworkConfigView only to get passwords when not connected. |
| 333 void NetworkMenuModel::ShowNetworkConfigView(NetworkConfigView* view) const { | 530 void NetworkMenuModel::ShowNetworkConfigView(NetworkConfigView* view) const { |
| 334 views::Window* window = browser::CreateViewsWindow( | 531 views::Window* window = browser::CreateViewsWindow( |
| 335 owner_->GetNativeWindow(), gfx::Rect(), view); | 532 owner_->GetNativeWindow(), gfx::Rect(), view); |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 683 } else { | 880 } else { |
| 684 if (!more_menu_model_->menu_items_.empty()) { | 881 if (!more_menu_model_->menu_items_.empty()) { |
| 685 menu_items_.push_back(MenuItem( | 882 menu_items_.push_back(MenuItem( |
| 686 ui::MenuModel::TYPE_SUBMENU, | 883 ui::MenuModel::TYPE_SUBMENU, |
| 687 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_MORE), | 884 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_MORE), |
| 688 SkBitmap(), more_menu_model_.get(), FLAG_NONE)); | 885 SkBitmap(), more_menu_model_.get(), FLAG_NONE)); |
| 689 } | 886 } |
| 690 } | 887 } |
| 691 } | 888 } |
| 692 | 889 |
| 890 void MainMenuModel::PopulateMenuItem( | |
| 891 views::MenuItemView* menu, | |
| 892 int index, | |
| 893 int command_id) { | |
| 894 NetworkMenuModel::PopulateMenuItem(menu, index, | |
| 895 command_id + kMainIndexOffset); | |
| 896 } | |
| 897 | |
| 898 // views::MenuDelegate implementation. | |
| 899 | |
| 900 const gfx::Font& MainMenuModel::GetLabelFont(int id) const { | |
| 901 DCHECK_GT(kMoreIndexOffset, kVPNIndexOffset); | |
| 902 DCHECK_GT(kVPNIndexOffset, kMainIndexOffset); | |
| 903 const gfx::Font* font = NULL; | |
| 904 if (id >= kMoreIndexOffset) | |
| 905 font = more_menu_model_->GetLabelFontAt(id - kMoreIndexOffset); | |
| 906 else if (id >= kVPNIndexOffset) | |
| 907 font = vpn_menu_model_->GetLabelFontAt(id - kVPNIndexOffset); | |
| 908 else if (id >= kMainIndexOffset) | |
| 909 font = GetLabelFontAt(id - kMainIndexOffset); | |
| 910 | |
| 911 return font ? *font : views::MenuDelegate::GetLabelFont(id); | |
| 912 } | |
| 913 | |
| 914 | |
| 915 bool MainMenuModel::IsItemChecked(int id) const { | |
| 916 DCHECK_GT(kMoreIndexOffset, kVPNIndexOffset); | |
| 917 DCHECK_GT(kVPNIndexOffset, kMainIndexOffset); | |
| 918 if (id >= kMoreIndexOffset) | |
| 919 return more_menu_model_->IsItemCheckedAt(id - kMoreIndexOffset); | |
| 920 else if (id >= kVPNIndexOffset) | |
| 921 return vpn_menu_model_->IsItemCheckedAt(id - kVPNIndexOffset); | |
| 922 else if (id >= kMainIndexOffset) | |
| 923 return IsItemCheckedAt(id - kMainIndexOffset); | |
| 924 | |
| 925 return views::MenuDelegate::IsItemChecked(id); | |
| 926 } | |
| 927 | |
| 928 bool MainMenuModel::IsCommandEnabled(int id) const { | |
| 929 DCHECK_GT(kMoreIndexOffset, kVPNIndexOffset); | |
| 930 DCHECK_GT(kVPNIndexOffset, kMainIndexOffset); | |
| 931 if (id >= kMoreIndexOffset) | |
| 932 return more_menu_model_->IsEnabledAt(id - kMoreIndexOffset); | |
| 933 else if (id >= kVPNIndexOffset) | |
| 934 return vpn_menu_model_->IsEnabledAt(id - kVPNIndexOffset); | |
| 935 else if (id >= kMainIndexOffset) | |
| 936 return IsEnabledAt(id - kMainIndexOffset); | |
| 937 | |
| 938 return views::MenuDelegate::IsCommandEnabled(id); | |
| 939 } | |
| 940 | |
| 941 void MainMenuModel::ExecuteCommand(int id) { | |
| 942 DCHECK_GT(kMoreIndexOffset, kVPNIndexOffset); | |
| 943 DCHECK_GT(kVPNIndexOffset, kMainIndexOffset); | |
| 944 if (id >= kMoreIndexOffset) | |
| 945 more_menu_model_->ActivatedAt(id - kMoreIndexOffset); | |
| 946 else if (id >= kVPNIndexOffset) | |
| 947 vpn_menu_model_->ActivatedAt(id - kVPNIndexOffset); | |
| 948 else if (id >= kMainIndexOffset) | |
| 949 ActivatedAt(id - kMainIndexOffset); | |
| 950 } | |
| 951 | |
| 693 //////////////////////////////////////////////////////////////////////////////// | 952 //////////////////////////////////////////////////////////////////////////////// |
| 694 // VPNMenuModel | 953 // VPNMenuModel |
| 695 | 954 |
| 696 VPNMenuModel::VPNMenuModel(NetworkMenu* owner) | 955 VPNMenuModel::VPNMenuModel(NetworkMenu* owner) |
| 697 : NetworkMenuModel(owner) { | 956 : NetworkMenuModel(owner) { |
| 698 } | 957 } |
| 699 | 958 |
| 700 void VPNMenuModel::InitMenuItems(bool is_browser_mode, | 959 void VPNMenuModel::InitMenuItems(bool is_browser_mode, |
| 701 bool should_open_button_options) { | 960 bool should_open_button_options) { |
| 702 // This gets called on initialization, so any changes should be reflected | 961 // This gets called on initialization, so any changes should be reflected |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 755 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_ADD_VPN), | 1014 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_ADD_VPN), |
| 756 SkBitmap(), std::string(), FLAG_ADD_VPN)); | 1015 SkBitmap(), std::string(), FLAG_ADD_VPN)); |
| 757 if (active_vpn) { | 1016 if (active_vpn) { |
| 758 menu_items_.push_back(MenuItem( | 1017 menu_items_.push_back(MenuItem( |
| 759 ui::MenuModel::TYPE_COMMAND, | 1018 ui::MenuModel::TYPE_COMMAND, |
| 760 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DISCONNECT_VPN), | 1019 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DISCONNECT_VPN), |
| 761 SkBitmap(), std::string(), FLAG_DISCONNECT_VPN)); | 1020 SkBitmap(), std::string(), FLAG_DISCONNECT_VPN)); |
| 762 } | 1021 } |
| 763 } | 1022 } |
| 764 | 1023 |
| 1024 void VPNMenuModel::PopulateMenuItem( | |
| 1025 views::MenuItemView* menu, | |
| 1026 int index, | |
| 1027 int command_id) { | |
| 1028 NetworkMenuModel::PopulateMenuItem(menu, index, | |
| 1029 command_id + kVPNIndexOffset); | |
| 1030 } | |
| 1031 | |
| 765 // static | 1032 // static |
| 766 SkBitmap VPNMenuModel::IconForDisplay(const Network* network) { | 1033 SkBitmap VPNMenuModel::IconForDisplay(const Network* network) { |
| 767 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 1034 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 768 const SkBitmap* icon = NULL; | 1035 const SkBitmap* icon = NULL; |
| 769 const SkBitmap* bottom_right_badge = NULL; | 1036 const SkBitmap* bottom_right_badge = NULL; |
| 770 const SkBitmap* top_left_badge = NULL; | 1037 const SkBitmap* top_left_badge = NULL; |
| 771 // We know for sure |network| is the active network, so no more checking | 1038 // We know for sure |network| is the active network, so no more checking |
| 772 // is needed by BadgeForPrivateNetworkStatus, hence pass in NULL. | 1039 // is needed by BadgeForPrivateNetworkStatus, hence pass in NULL. |
| 773 const SkBitmap* bottom_left_badge = | 1040 const SkBitmap* bottom_left_badge = |
| 774 NetworkMenu::BadgeForPrivateNetworkStatus(NULL); | 1041 NetworkMenu::BadgeForPrivateNetworkStatus(NULL); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 864 } | 1131 } |
| 865 } | 1132 } |
| 866 | 1133 |
| 867 menu_items_ = link_items; | 1134 menu_items_ = link_items; |
| 868 if (!menu_items_.empty() && address_items.size() > 1) | 1135 if (!menu_items_.empty() && address_items.size() > 1) |
| 869 menu_items_.push_back(MenuItem()); // Separator | 1136 menu_items_.push_back(MenuItem()); // Separator |
| 870 menu_items_.insert(menu_items_.end(), | 1137 menu_items_.insert(menu_items_.end(), |
| 871 address_items.begin(), address_items.end()); | 1138 address_items.begin(), address_items.end()); |
| 872 } | 1139 } |
| 873 | 1140 |
| 1141 void MoreMenuModel::PopulateMenuItem( | |
| 1142 views::MenuItemView* menu, | |
| 1143 int index, | |
| 1144 int command_id) { | |
| 1145 NetworkMenuModel::PopulateMenuItem(menu, index, | |
| 1146 command_id + kMoreIndexOffset); | |
| 1147 } | |
| 1148 | |
| 874 //////////////////////////////////////////////////////////////////////////////// | 1149 //////////////////////////////////////////////////////////////////////////////// |
| 875 // NetworkMenu | 1150 // NetworkMenu |
| 876 | 1151 |
| 877 // static | 1152 // static |
| 878 const int NetworkMenu::kNumBarsImages = 4; | 1153 const int NetworkMenu::kNumBarsImages = 4; |
| 879 | 1154 |
| 880 // NOTE: Use an array rather than just calculating a resource number to avoid | 1155 // NOTE: Use an array rather than just calculating a resource number to avoid |
| 881 // creating implicit ordering dependencies on the resource values. | 1156 // creating implicit ordering dependencies on the resource values. |
| 882 // static | 1157 // static |
| 883 const int NetworkMenu::kBarsImages[kNumBarsImages] = { | 1158 const int NetworkMenu::kBarsImages[kNumBarsImages] = { |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 913 | 1188 |
| 914 // static | 1189 // static |
| 915 const int NetworkMenu::kNumAnimatingImages = 10; | 1190 const int NetworkMenu::kNumAnimatingImages = 10; |
| 916 | 1191 |
| 917 // static | 1192 // static |
| 918 SkBitmap NetworkMenu::kAnimatingImages[kNumAnimatingImages]; | 1193 SkBitmap NetworkMenu::kAnimatingImages[kNumAnimatingImages]; |
| 919 | 1194 |
| 920 // static | 1195 // static |
| 921 SkBitmap NetworkMenu::kAnimatingImagesBlack[kNumAnimatingImages]; | 1196 SkBitmap NetworkMenu::kAnimatingImagesBlack[kNumAnimatingImages]; |
| 922 | 1197 |
| 923 NetworkMenu::NetworkMenu() : min_width_(-1) { | 1198 NetworkMenu::NetworkMenu() : min_width_(kDefaultMinimumWidth) { |
| 924 main_menu_model_.reset(new MainMenuModel(this)); | 1199 main_menu_model_.reset(new MainMenuModel(this)); |
| 925 network_menu_.reset(new views::Menu2(main_menu_model_.get())); | 1200 network_menu_.reset(new views::MenuItemView(main_menu_model_.get())); |
| 1201 network_menu_->set_has_icons(true); | |
| 1202 | |
| 1203 network_menu_task_proxy_ = new NetworkMenuTaskProxy(this); | |
| 926 } | 1204 } |
| 927 | 1205 |
| 928 NetworkMenu::~NetworkMenu() { | 1206 NetworkMenu::~NetworkMenu() { |
| 1207 // Ensure that any lingering UpdateMenu() tasks don't dereference | |
| 1208 // this instance. | |
| 1209 network_menu_task_proxy_->Invalidate(); | |
| 929 } | 1210 } |
| 930 | 1211 |
| 931 void NetworkMenu::SetFirstLevelMenuWidth(int width) { | 1212 void NetworkMenu::SetFirstLevelMenuWidth(int width) { |
| 932 min_width_ = width; | 1213 min_width_ = width; |
| 933 // This actually has no effect since menu is rebuilt before showing. | |
| 934 network_menu_->SetMinimumWidth(width); | |
| 935 } | 1214 } |
| 936 | 1215 |
| 937 void NetworkMenu::CancelMenu() { | 1216 void NetworkMenu::CancelMenu() { |
| 938 network_menu_->CancelMenu(); | 1217 network_menu_->Cancel(); |
| 939 } | 1218 } |
| 940 | 1219 |
| 941 void NetworkMenu::UpdateMenu() { | 1220 void NetworkMenu::UpdateMenu() { |
| 1221 // Invoke UpdateMenuImpl() on the UI thread. | |
| 1222 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | |
| 1223 BrowserThread::PostTask( | |
| 1224 BrowserThread::UI, FROM_HERE, | |
| 1225 NewRunnableMethod( | |
| 1226 network_menu_task_proxy_.get(), &NetworkMenuTaskProxy::UpdateMenu)); | |
| 1227 } else { | |
| 1228 UpdateMenuImpl(); | |
| 1229 } | |
| 1230 } | |
| 1231 | |
| 1232 void NetworkMenu::UpdateMenuImpl() { | |
| 942 refreshing_menu_ = true; | 1233 refreshing_menu_ = true; |
| 943 main_menu_model_->InitMenuItems(IsBrowserMode(), ShouldOpenButtonOptions()); | 1234 main_menu_model_->InitMenuItems(IsBrowserMode(), ShouldOpenButtonOptions()); |
| 944 network_menu_->Rebuild(); | 1235 main_menu_model_->PopulateMenu(network_menu_.get()); |
| 1236 network_menu_->ChildrenChanged(); | |
| 945 refreshing_menu_ = false; | 1237 refreshing_menu_ = false; |
| 946 } | 1238 } |
| 947 | 1239 |
| 948 // static | 1240 // static |
| 949 const SkBitmap* NetworkMenu::IconForNetworkStrength(const WifiNetwork* wifi, | 1241 const SkBitmap* NetworkMenu::IconForNetworkStrength(const WifiNetwork* wifi, |
| 950 bool black) { | 1242 bool black) { |
| 951 DCHECK(wifi); | 1243 DCHECK(wifi); |
| 952 if (wifi->strength() == 0) { | 1244 if (wifi->strength() == 0) { |
| 953 return ResourceBundle::GetSharedInstance().GetBitmapNamed( | 1245 return ResourceBundle::GetSharedInstance().GetBitmapNamed( |
| 954 black ? IDR_STATUSBAR_NETWORK_BARS0_BLACK : | 1246 black ? IDR_STATUSBAR_NETWORK_BARS0_BLACK : |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1149 chrome::kInternetOptionsSubPage, | 1441 chrome::kInternetOptionsSubPage, |
| 1150 EscapeUrlEncodedData(network->service_path()).c_str(), | 1442 EscapeUrlEncodedData(network->service_path()).c_str(), |
| 1151 network->type()); | 1443 network->type()); |
| 1152 browser->ShowOptionsTab(page); | 1444 browser->ShowOptionsTab(page); |
| 1153 } | 1445 } |
| 1154 | 1446 |
| 1155 //////////////////////////////////////////////////////////////////////////////// | 1447 //////////////////////////////////////////////////////////////////////////////// |
| 1156 // NetworkMenu, views::ViewMenuDelegate implementation: | 1448 // NetworkMenu, views::ViewMenuDelegate implementation: |
| 1157 | 1449 |
| 1158 void NetworkMenu::RunMenu(views::View* source, const gfx::Point& pt) { | 1450 void NetworkMenu::RunMenu(views::View* source, const gfx::Point& pt) { |
| 1159 refreshing_menu_ = true; | |
| 1160 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); | 1451 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); |
| 1161 cros->RequestNetworkScan(); | 1452 cros->RequestNetworkScan(); |
| 1162 | 1453 |
| 1163 // Build initial menu items. They will be updated when UpdateMenu is | 1454 UpdateMenu(); |
| 1164 // called from NetworkChanged. | |
| 1165 main_menu_model_->InitMenuItems(IsBrowserMode(), ShouldOpenButtonOptions()); | |
| 1166 network_menu_->Rebuild(); | |
| 1167 | 1455 |
| 1168 // Restore menu width, if it was set up. | 1456 // TODO(rhashimoto): Remove this workaround when WebUI provides a |
| 1169 // NOTE: width isn't checked for correctness here since all width-related | 1457 // top-level widget on the ChromeOS login screen that is a window. |
| 1170 // logic implemented inside |network_menu_|. | 1458 // The current BackgroundView class for the ChromeOS login screen |
| 1171 if (min_width_ != -1) | 1459 // creates a owning Widget that has a native GtkWindow but is not a |
| 1172 network_menu_->SetMinimumWidth(min_width_); | 1460 // Window. This makes it impossible to get the NativeWindow via |
| 1173 refreshing_menu_ = false; | 1461 // the views API. This workaround casts the top-level NativeWidget |
| 1174 network_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); | 1462 // to a NativeWindow that we can pass to MenuItemView::RunMenuAt(). |
| 1463 gfx::NativeWindow window = GTK_WINDOW(source->GetWidget()->GetNativeView()); | |
| 1464 | |
| 1465 gfx::Point screen_loc; | |
| 1466 views::View::ConvertPointToScreen(source, &screen_loc); | |
| 1467 gfx::Rect bounds(screen_loc, source->size()); | |
| 1468 network_menu_->GetSubmenu()->set_minimum_preferred_width(min_width_); | |
| 1469 network_menu_->RunMenuAt(window, GetMenuButton(), bounds, | |
| 1470 views::MenuItemView::TOPRIGHT, true); | |
| 1175 } | 1471 } |
| 1176 | 1472 |
| 1177 } // namespace chromeos | 1473 } // namespace chromeos |
| 1178 | |
| 1179 | |
| OLD | NEW |