summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorstevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-14 18:37:22 +0000
committerstevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-14 18:37:22 +0000
commitc1ee006d1b62afc15e5a9343d51684864e02ee7c (patch)
tree0b4f122945ff6e9ec0b6ef11aa5659680c7cdec3
parentb736e5057cbfaf261c36d61cbc3b8018d202c0a5 (diff)
downloadchromium_src-c1ee006d1b62afc15e5a9343d51684864e02ee7c.zip
chromium_src-c1ee006d1b62afc15e5a9343d51684864e02ee7c.tar.gz
chromium_src-c1ee006d1b62afc15e5a9343d51684864e02ee7c.tar.bz2
Implement action interface in network_menu.js for 'connect'.
* Added NetworkMenu::UpdateMenu() * Added NetworkMenu::ConnectToNetworkAt() BUG=http://code.google.com/p/chromium-os/issues/detail?id=7343 TEST=Test the network menu (it still looks ugly). Specifically, selecting a non secure network, or one with a certificate installed should connect to it. Also, temporarily, using 'space' or 'return' to select a network should connect to it without closing the menu. Review URL: http://codereview.chromium.org/3678006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62598 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/cros/cros_mock.cc43
-rw-r--r--chrome/browser/chromeos/cros/cros_mock.h5
-rw-r--r--chrome/browser/chromeos/cros/network_library.cc21
-rw-r--r--chrome/browser/chromeos/cros/network_library.h3
-rw-r--r--chrome/browser/chromeos/dom_ui/network_menu_ui.cc30
-rw-r--r--chrome/browser/chromeos/login/login_browsertest.cc74
-rw-r--r--chrome/browser/chromeos/options/wifi_config_view.cc29
-rw-r--r--chrome/browser/chromeos/status/network_dropdown_button.cc3
-rw-r--r--chrome/browser/chromeos/status/network_menu.cc163
-rw-r--r--chrome/browser/chromeos/status/network_menu.h11
-rw-r--r--chrome/browser/chromeos/status/network_menu_button.cc1
-rw-r--r--chrome/browser/resources/network_menu.js20
12 files changed, 266 insertions, 137 deletions
diff --git a/chrome/browser/chromeos/cros/cros_mock.cc b/chrome/browser/chromeos/cros/cros_mock.cc
index fcca7a7..9761d9b 100644
--- a/chrome/browser/chromeos/cros/cros_mock.cc
+++ b/chrome/browser/chromeos/cros/cros_mock.cc
@@ -271,15 +271,17 @@ void CrosMock::SetNetworkLibraryStatusAreaExpectations() {
EXPECT_CALL(*mock_network_library_, AddObserver(_))
.Times(1)
.RetiresOnSaturation();
- EXPECT_CALL(*mock_network_library_, wifi_connecting())
- .Times(1)
+
+ // NetworkDropdownButton::NetworkChanged() calls:
+ EXPECT_CALL(*mock_network_library_, ethernet_connected())
+ .Times(2) // also called by NetworkMenu::InitMenuItems()
.WillRepeatedly((Return(false)))
.RetiresOnSaturation();
EXPECT_CALL(*mock_network_library_, wifi_connected())
.Times(1)
.WillRepeatedly((Return(false)))
.RetiresOnSaturation();
- EXPECT_CALL(*mock_network_library_, cellular_connecting())
+ EXPECT_CALL(*mock_network_library_, wifi_connecting())
.Times(1)
.WillRepeatedly((Return(false)))
.RetiresOnSaturation();
@@ -287,18 +289,49 @@ void CrosMock::SetNetworkLibraryStatusAreaExpectations() {
.Times(1)
.WillRepeatedly((Return(false)))
.RetiresOnSaturation();
- EXPECT_CALL(*mock_network_library_, ethernet_connected())
+ EXPECT_CALL(*mock_network_library_, cellular_connecting())
.Times(1)
.WillRepeatedly((Return(false)))
.RetiresOnSaturation();
EXPECT_CALL(*mock_network_library_, Connected())
- .Times(1)
+ .Times(2) // also called by NetworkMenu::InitMenuItems()
.WillRepeatedly((Return(false)))
.RetiresOnSaturation();
EXPECT_CALL(*mock_network_library_, Connecting())
.Times(1)
.WillRepeatedly((Return(false)))
.RetiresOnSaturation();
+
+ // NetworkMenu::InitMenuItems() calls:
+ EXPECT_CALL(*mock_network_library_, ethernet_connecting())
+ .Times(1)
+ .WillRepeatedly((Return(false)))
+ .RetiresOnSaturation();
+ EXPECT_CALL(*mock_network_library_, wifi_networks())
+ .Times(1)
+ .WillRepeatedly((ReturnRef(wifi_networks_)))
+ .RetiresOnSaturation();
+ EXPECT_CALL(*mock_network_library_, wifi_available())
+ .Times(1)
+ .WillRepeatedly((Return(false)))
+ .RetiresOnSaturation();
+ EXPECT_CALL(*mock_network_library_, wifi_name())
+ .Times(1)
+ .WillRepeatedly((ReturnRef(empty_string_)))
+ .RetiresOnSaturation();
+ EXPECT_CALL(*mock_network_library_, cellular_networks())
+ .Times(1)
+ .WillRepeatedly((ReturnRef(cellular_networks_)))
+ .RetiresOnSaturation();
+ EXPECT_CALL(*mock_network_library_, cellular_name())
+ .Times(1)
+ .WillRepeatedly((ReturnRef(empty_string_)))
+ .RetiresOnSaturation();
+ EXPECT_CALL(*mock_network_library_, cellular_available())
+ .Times(1)
+ .WillRepeatedly((Return(false)))
+ .RetiresOnSaturation();
+
EXPECT_CALL(*mock_network_library_, RemoveObserver(_))
.Times(1)
.RetiresOnSaturation();
diff --git a/chrome/browser/chromeos/cros/cros_mock.h b/chrome/browser/chromeos/cros/cros_mock.h
index d0818a0..f38081d 100644
--- a/chrome/browser/chromeos/cros/cros_mock.h
+++ b/chrome/browser/chromeos/cros/cros_mock.h
@@ -6,6 +6,7 @@
#define CHROME_BROWSER_CHROMEOS_CROS_CROS_MOCK_H_
#include "chrome/browser/chromeos/cros/cros_library.h"
+#include "chrome/browser/chromeos/cros/network_library.h"
#include "chrome/test/in_process_browser_test.h"
#include "cros/chromeos_input_method.h"
@@ -102,6 +103,10 @@ class CrosMock {
MockTouchpadLibrary* mock_touchpad_library_;
ImePropertyList ime_properties_;
+ WifiNetworkVector wifi_networks_;
+ CellularNetworkVector cellular_networks_;
+ std::string empty_string_;
+
DISALLOW_COPY_AND_ASSIGN(CrosMock);
};
diff --git a/chrome/browser/chromeos/cros/network_library.cc b/chrome/browser/chromeos/cros/network_library.cc
index 7bc256b..099ed89 100644
--- a/chrome/browser/chromeos/cros/network_library.cc
+++ b/chrome/browser/chromeos/cros/network_library.cc
@@ -389,7 +389,26 @@ std::string WifiNetwork::GetEncryptionString() {
case SECURITY_8021X:
return "8021X";
}
- return "Unknown";}
+ return "Unknown";
+}
+
+// Parse 'path' to determine if the certificate is stored in a pkcs#11 device.
+// flimflam recognizes the string "SETTINGS:" to specify authentication
+// parameters. 'key_id=' indicates that the certificate is stored in a pkcs#11
+// device. See src/third_party/flimflam/files/doc/service-api.txt.
+bool WifiNetwork::IsCertificateLoaded() const {
+ static const std::string settings_string("SETTINGS:");
+ static const std::string pkcs11_key("key_id");
+ if (cert_path_.find(settings_string) == 0) {
+ std::string::size_type idx = cert_path_.find(pkcs11_key);
+ if (idx != std::string::npos)
+ idx = cert_path_.find_first_not_of(kWhitespaceASCII,
+ idx + pkcs11_key.length());
+ if (idx != std::string::npos && cert_path_[idx] == '=')
+ return true;
+ }
+ return false;
+}
////////////////////////////////////////////////////////////////////////////////
// NetworkLibrary
diff --git a/chrome/browser/chromeos/cros/network_library.h b/chrome/browser/chromeos/cros/network_library.h
index 795a0df..668783c 100644
--- a/chrome/browser/chromeos/cros/network_library.h
+++ b/chrome/browser/chromeos/cros/network_library.h
@@ -227,6 +227,9 @@ class WifiNetwork : public WirelessNetwork {
// This not translated and should be only used for debugging purposes.
std::string GetEncryptionString();
+ // Return true if cert_path_ indicates that we have loaded the certificate.
+ bool IsCertificateLoaded() const;
+
protected:
ConnectionSecurity encryption_;
std::string passphrase_;
diff --git a/chrome/browser/chromeos/dom_ui/network_menu_ui.cc b/chrome/browser/chromeos/dom_ui/network_menu_ui.cc
index b7905fa..cb267a1 100644
--- a/chrome/browser/chromeos/dom_ui/network_menu_ui.cc
+++ b/chrome/browser/chromeos/dom_ui/network_menu_ui.cc
@@ -5,6 +5,7 @@
#include "chrome/browser/chromeos/dom_ui/network_menu_ui.h"
#include "base/values.h"
+#include "base/string_number_conversions.h"
#include "base/string_util.h"
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/chromeos/status/network_menu.h"
@@ -85,8 +86,33 @@ void NetworkMenuUI::AddCustomConfigValues(DictionaryValue* config) const {
void NetworkMenuUI::ModelAction(const menus::MenuModel* model,
const ListValue* values) {
- //const NetworkMenu* network_menu = static_cast<const NetworkMenu*>(model);
- // Invoke model methods here.
+ const NetworkMenu* network_menu = static_cast<const NetworkMenu*>(model);
+ std::string action;
+ bool success = values->GetString(0, &action);
+ if (!success) {
+ LOG(WARNING) << "ModelAction called with no arguments from: "
+ << chrome::kChromeUINetworkMenu;
+ return;
+ }
+ int index;
+ std::string index_str;
+ success = values->GetString(1, &index_str);
+ success = success && base::StringToInt(index_str, &index);
+ if (!success) {
+ LOG(WARNING) << "ModelAction called with no index from: "
+ << chrome::kChromeUINetworkMenu;
+ return;
+ }
+ std::string passphrase;
+ values->GetString(2, &passphrase); // Optional
+ std::string identity;
+ values->GetString(3, &identity); // Optional
+ if (action == "connect" || action == "reconnect") {
+ network_menu->ConnectToNetworkAt(index, passphrase, identity);
+ } else {
+ LOG(WARNING) << "Unrecognized action: " << action
+ << " from: " << chrome::kChromeUINetworkMenu;
+ }
}
DictionaryValue* NetworkMenuUI::CreateMenuItem(const menus::MenuModel* model,
diff --git a/chrome/browser/chromeos/login/login_browsertest.cc b/chrome/browser/chromeos/login/login_browsertest.cc
index 3dacb09..f307f27 100644
--- a/chrome/browser/chromeos/login/login_browsertest.cc
+++ b/chrome/browser/chromeos/login/login_browsertest.cc
@@ -24,59 +24,42 @@
namespace chromeos {
using ::testing::_;
+using ::testing::AnyNumber;
using ::testing::InvokeWithoutArgs;
+using ::testing::NiceMock;
using ::testing::Return;
using ::testing::ReturnRef;
-using ::testing::NiceMock;
-class LoginTestBase : public InProcessBrowserTest {
+class LoginTestBase : public CrosInProcessBrowserTest {
public:
- LoginTestBase() {
- testApi_ = chromeos::CrosLibrary::Get()->GetTestApi();
- testApi_->SetLibraryLoader(&loader_, false);
- EXPECT_CALL(loader_, Load(_))
- .WillRepeatedly(Return(true));
-
- testApi_->SetKeyboardLibrary(&mock_keyboard_library_, false);
- testApi_->SetInputMethodLibrary(&mock_input_method_library_, false);
- EXPECT_CALL(mock_input_method_library_, GetActiveInputMethods())
- .WillRepeatedly(
- InvokeWithoutArgs(CreateFallbackInputMethodDescriptors));
-
- testApi_->SetNetworkLibrary(&mock_network_library_, false);
-
- testApi_->SetPowerLibrary(&mock_power_library_, false);
- EXPECT_CALL(mock_power_library_, battery_time_to_empty())
- .WillRepeatedly((Return(base::TimeDelta::FromMinutes(42))));
- EXPECT_CALL(mock_power_library_, battery_time_to_full())
- .WillRepeatedly((Return(base::TimeDelta::FromMinutes(24))));
-
- testApi_->SetTouchpadLibrary(&mock_touchpad_library_, false);
- testApi_->SetCryptohomeLibrary(&mock_cryptohome_library_, false);
- testApi_->SetScreenLockLibrary(&mock_screen_lock_library_, false);
- testApi_->SetSystemLibrary(&mock_system_library_, false);
+ LoginTestBase() : mock_cryptohome_library_(NULL),
+ mock_screen_lock_library_(NULL) {
}
protected:
- NiceMock<MockLibraryLoader> loader_;
- NiceMock<MockCryptohomeLibrary> mock_cryptohome_library_;
- NiceMock<MockKeyboardLibrary> mock_keyboard_library_;
- NiceMock<MockInputMethodLibrary> mock_input_method_library_;
- NiceMock<MockNetworkLibrary> mock_network_library_;
- NiceMock<MockPowerLibrary> mock_power_library_;
- NiceMock<MockScreenLockLibrary> mock_screen_lock_library_;
- NiceMock<MockTouchpadLibrary> mock_touchpad_library_;
- NiceMock<MockSystemLibrary> mock_system_library_;
- ImePropertyList ime_properties_;
- chromeos::CrosLibrary::TestApi* testApi_;
+ virtual void SetUpInProcessBrowserTestFixture() {
+ cros_mock_->InitStatusAreaMocks();
+ cros_mock_->SetStatusAreaMocksExpectations();
+ cros_mock_->InitMockCryptohomeLibrary();
+ cros_mock_->InitMockScreenLockLibrary();
+ mock_cryptohome_library_ = cros_mock_->mock_cryptohome_library();
+ mock_screen_lock_library_ = cros_mock_->mock_screen_lock_library();
+ EXPECT_CALL(*mock_cryptohome_library_, IsMounted())
+ .WillRepeatedly(Return(true));
+ }
+
+ MockCryptohomeLibrary* mock_cryptohome_library_;
+ MockScreenLockLibrary* mock_screen_lock_library_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(LoginTestBase);
};
class LoginUserTest : public LoginTestBase {
- public:
- LoginUserTest() {
- EXPECT_CALL(mock_cryptohome_library_, IsMounted())
- .WillRepeatedly(Return(true));
- EXPECT_CALL(mock_screen_lock_library_, AddObserver(_))
+ protected:
+ virtual void SetUpInProcessBrowserTestFixture() {
+ LoginTestBase::SetUpInProcessBrowserTestFixture();
+ EXPECT_CALL(*mock_screen_lock_library_, AddObserver(_))
.WillOnce(Return());
}
@@ -88,12 +71,7 @@ class LoginUserTest : public LoginTestBase {
};
class LoginProfileTest : public LoginTestBase {
- public:
- LoginProfileTest() {
- EXPECT_CALL(mock_cryptohome_library_, IsMounted())
- .WillRepeatedly(Return(true));
- }
-
+ protected:
virtual void SetUpCommandLine(CommandLine* command_line) {
command_line->AppendSwitchASCII(switches::kLoginProfile, "user");
command_line->AppendSwitch(switches::kNoFirstRun);
diff --git a/chrome/browser/chromeos/options/wifi_config_view.cc b/chrome/browser/chromeos/options/wifi_config_view.cc
index 21c22eb..05d024a 100644
--- a/chrome/browser/chromeos/options/wifi_config_view.cc
+++ b/chrome/browser/chromeos/options/wifi_config_view.cc
@@ -205,23 +205,6 @@ void WifiConfigView::FocusFirstField() {
passphrase_textfield_->RequestFocus();
}
-// Parse 'path' to determine if the certificate is stored in a pkcs#11 device.
-// flimflam recognizes the string "SETTINGS:" to specify authentication
-// parameters. 'key_id=' indicates that the certificate is stored in a pkcs#11
-// device. See src/third_party/flimflam/files/doc/service-api.txt.
-static bool is_certificate_in_pkcs11(const std::string& path) {
- static const std::string settings_string("SETTINGS:");
- static const std::string pkcs11_key("key_id");
- if (path.find(settings_string) == 0) {
- std::string::size_type idx = path.find(pkcs11_key);
- if (idx != std::string::npos)
- idx = path.find_first_not_of(kWhitespaceASCII, idx + pkcs11_key.length());
- if (idx != std::string::npos && path[idx] == '=')
- return true;
- }
- return false;
-}
-
void WifiConfigView::Init() {
views::GridLayout* layout = CreatePanelGridLayout(this);
SetLayoutManager(layout);
@@ -252,9 +235,9 @@ void WifiConfigView::Init() {
}
layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
- // Certificates stored in a pkcs11 device can not be browsed
- // and do not require a passphrase.
- bool certificate_in_pkcs11 = false;
+ // Loaded certificates (i.e. stored in a pkcs11 device) do not require
+ // a passphrase.
+ bool certificate_loaded = false;
// Add ID and cert password if we're using 802.1x
// XXX we're cheating and assuming 802.1x means EAP-TLS - not true
@@ -277,9 +260,9 @@ void WifiConfigView::Init() {
IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT)));
if (!wifi_.cert_path().empty()) {
certificate_path_ = wifi_.cert_path();
- certificate_in_pkcs11 = is_certificate_in_pkcs11(certificate_path_);
+ certificate_loaded = wifi_.IsCertificateLoaded();
}
- if (certificate_in_pkcs11) {
+ if (certificate_loaded) {
std::wstring label = l10n_util::GetString(
IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CERT_INSTALLED);
views::Label* cert_text = new views::Label(label);
@@ -299,7 +282,7 @@ void WifiConfigView::Init() {
}
// Add passphrase if other_network or wifi is encrypted.
- if (other_network_ || (wifi_.encrypted() && !certificate_in_pkcs11)) {
+ if (other_network_ || (wifi_.encrypted() && !certificate_loaded)) {
layout->StartRow(0, column_view_set_id);
int label_text_id;
if (wifi_.encryption() == SECURITY_8021X)
diff --git a/chrome/browser/chromeos/status/network_dropdown_button.cc b/chrome/browser/chromeos/status/network_dropdown_button.cc
index 159a703..2f83d6e 100644
--- a/chrome/browser/chromeos/status/network_dropdown_button.cc
+++ b/chrome/browser/chromeos/status/network_dropdown_button.cc
@@ -73,6 +73,9 @@ void NetworkDropdownButton::NetworkChanged(NetworkLibrary* cros) {
// user selected. For example user selected WiFi network but we have Ethernet
// connection and Chrome OS device will actually use Ethernet.
+ // This gets called on initialization, so any changes should be reflected
+ // in CrosMock::SetNetworkLibraryStatusAreaExpectations().
+
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
if (CrosLibrary::Get()->EnsureLoaded()) {
// Always show the higher priority connection first. Ethernet then wifi.
diff --git a/chrome/browser/chromeos/status/network_menu.cc b/chrome/browser/chromeos/status/network_menu.cc
index 7e269e9..e738909 100644
--- a/chrome/browser/chromeos/status/network_menu.cc
+++ b/chrome/browser/chromeos/status/network_menu.cc
@@ -91,6 +91,10 @@ bool NetworkMenu::GetNetworkAt(int index, NetworkInfo* info) const {
info->message = l10n_util::GetStringUTF8(
IDS_STATUSBAR_NETWORK_DEVICE_DISCONNECTED);
}
+ } else {
+ info->status = kNetworkStatusDisconnected;
+ info->message = l10n_util::GetStringUTF8(
+ IDS_STATUSBAR_NETWORK_DEVICE_DISCONNECTED);
}
info->ip_address = wifi.ip_address();
info->need_passphrase = wifi.encrypted();
@@ -123,6 +127,10 @@ bool NetworkMenu::GetNetworkAt(int index, NetworkInfo* info) const {
info->message = l10n_util::GetStringUTF8(
IDS_STATUSBAR_NETWORK_DEVICE_DISCONNECTED);
}
+ } else {
+ info->status = kNetworkStatusDisconnected;
+ info->message = l10n_util::GetStringUTF8(
+ IDS_STATUSBAR_NETWORK_DEVICE_DISCONNECTED);
}
info->ip_address = cellular.ip_address();
info->need_passphrase = false;
@@ -131,6 +139,9 @@ bool NetworkMenu::GetNetworkAt(int index, NetworkInfo* info) const {
res = false; // Network not found, hide entry.
}
} else if (flags & FLAG_OTHER_NETWORK) {
+ info->status = kNetworkStatusDisconnected;
+ info->message = l10n_util::GetStringUTF8(
+ IDS_STATUSBAR_NETWORK_DEVICE_DISCONNECTED);
info->network_type = kNetworkTypeOther;
info->need_passphrase = true;
info->remembered = true;
@@ -140,6 +151,47 @@ bool NetworkMenu::GetNetworkAt(int index, NetworkInfo* info) const {
return res;
}
+void NetworkMenu::ConnectToNetworkAt(int index,
+ const std::string& passphrase,
+ const std::string& identity) const {
+ int flags = menu_items_[index].flags;
+ NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary();
+ if (flags & FLAG_WIFI) {
+ WifiNetwork wifi;
+ bool found = cros->FindWifiNetworkByPath(
+ menu_items_[index].wireless_path, &wifi);
+ if (found) {
+ // Connect or reconnect.
+ if (wifi.encrypted()) {
+ if (wifi.IsCertificateLoaded()) {
+ cros->ConnectToWifiNetwork(wifi, std::string(),
+ std::string(), wifi.cert_path());
+ } else {
+ // TODO(stevenjb): use passphrase/identity once provided.
+ // cros->ConnectToWifiNetwork(wifi, passphrase,
+ // identity, menu_items[index].path);
+ const bool kFocusLogin = true;
+ ShowNetworkConfigView(new NetworkConfigView(wifi, true), kFocusLogin);
+ }
+ } else {
+ cros->ConnectToWifiNetwork(wifi, std::string(),
+ std::string(), std::string());
+ }
+ }
+ } else if (flags & FLAG_CELLULAR) {
+ CellularNetwork cellular;
+ bool found = cros->FindCellularNetworkByPath(
+ menu_items_[index].wireless_path, &cellular);
+ if (found) {
+ // Connect or reconnect.
+ cros->ConnectToCellularNetwork(cellular);
+ }
+ } else if (flags & FLAG_OTHER_NETWORK) {
+ const bool kFocusLogin = true;
+ ShowNetworkConfigView(new NetworkConfigView(), kFocusLogin);
+ }
+}
+
////////////////////////////////////////////////////////////////////////////////
// NetworkMenu, menus::MenuModel implementation:
@@ -178,17 +230,6 @@ bool NetworkMenu::IsEnabledAt(int index) const {
return !(menu_items_[index].flags & FLAG_DISABLED);
}
-void NetworkMenu::ShowTabbedNetworkSettings(const Network& network) {
- Browser* browser = BrowserList::GetLastActive();
- if (!browser)
- return;
- std::string page = StringPrintf("%s?servicePath=%s&networkType=%d",
- chrome::kInternetOptionsSubPage,
- EscapeUrlEncodedData(network.service_path()).c_str(),
- network.type());
- browser->ShowOptionsTab(page);
-}
-
void NetworkMenu::ActivatedAt(int index) {
// When we are refreshing the menu, ignore menu item activation.
if (refreshing_menu_)
@@ -207,27 +248,16 @@ void NetworkMenu::ActivatedAt(int index) {
} else if (flags & FLAG_TOGGLE_OFFLINE) {
cros->EnableOfflineMode(!cros->offline_mode());
} else if (flags & FLAG_OTHER_NETWORK) {
- NetworkConfigView* view = new NetworkConfigView();
- view->set_browser_mode(IsBrowserMode());
- views::Window* window = browser::CreateViewsWindow(GetNativeWindow(),
- gfx::Rect(),
- view);
- window->SetIsAlwaysOnTop(true);
- window->Show();
- view->SetLoginTextfieldFocus();
+ const bool kFocusLogin = true;
+ ShowNetworkConfigView(new NetworkConfigView(), kFocusLogin);
} else if (flags & FLAG_ETHERNET) {
if (cros->ethernet_connected()) {
if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableTabbedOptions)) {
ShowTabbedNetworkSettings(cros->ethernet_network());
} else {
- NetworkConfigView* view =
- new NetworkConfigView(cros->ethernet_network());
- view->set_browser_mode(IsBrowserMode());
- views::Window* window = browser::CreateViewsWindow(
- GetNativeWindow(), gfx::Rect(), view);
- window->SetIsAlwaysOnTop(true);
- window->Show();
+ ShowNetworkConfigView(
+ new NetworkConfigView(cros->ethernet_network()), false);
}
}
} else if (flags & FLAG_WIFI) {
@@ -240,35 +270,25 @@ void NetworkMenu::ActivatedAt(int index) {
// TODO(stevenjb): Show notification.
} else if (wifi.name() == cros->wifi_name()) {
if (cros->wifi_connected()) {
+ // If we are already connected, show the config settings.
if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableTabbedOptions)) {
ShowTabbedNetworkSettings(wifi);
} else {
- // If we are already connected, open the config dialog.
- NetworkConfigView* view = new NetworkConfigView(wifi, false);
- view->set_browser_mode(IsBrowserMode());
- views::Window* window = browser::CreateViewsWindow(
- GetNativeWindow(), gfx::Rect(), view);
- window->SetIsAlwaysOnTop(true);
- window->Show();
+ ShowNetworkConfigView(new NetworkConfigView(wifi, false), false);
}
} else {
// TODO(stevenjb): Connection in progress. Show dialog?
}
} else {
// If wifi network is not encrypted, then directly connect.
- // Otherwise, we open password dialog window.
+ // Otherwise, open the password dialog window.
if (!wifi.encrypted()) {
cros->ConnectToWifiNetwork(wifi, std::string(),
std::string(), std::string());
} else {
- NetworkConfigView* view = new NetworkConfigView(wifi, true);
- view->set_browser_mode(IsBrowserMode());
- views::Window* window = browser::CreateViewsWindow(
- GetNativeWindow(), gfx::Rect(), view);
- window->SetIsAlwaysOnTop(true);
- window->Show();
- view->SetLoginTextfieldFocus();
+ const bool kFocusLogin = true;
+ ShowNetworkConfigView(new NetworkConfigView(wifi, true), kFocusLogin);
}
}
} else if (flags & FLAG_CELLULAR) {
@@ -288,12 +308,7 @@ void NetworkMenu::ActivatedAt(int index) {
switches::kEnableTabbedOptions)) {
ShowTabbedNetworkSettings(cellular);
} else {
- NetworkConfigView* view = new NetworkConfigView(cellular);
- view->set_browser_mode(IsBrowserMode());
- views::Window* window = browser::CreateViewsWindow(
- GetNativeWindow(), gfx::Rect(), view);
- window->SetIsAlwaysOnTop(true);
- window->Show();
+ ShowNetworkConfigView(new NetworkConfigView(cellular), false);
}
} else {
// TODO(stevenjb): Connection in progress. Show dialog?
@@ -314,6 +329,13 @@ void NetworkMenu::CancelMenu() {
network_menu_->CancelMenu();
}
+void NetworkMenu::UpdateMenu() {
+ refreshing_menu_ = true;
+ InitMenuItems();
+ network_menu_->Rebuild();
+ refreshing_menu_ = false;
+}
+
// static
SkBitmap NetworkMenu::IconForNetworkStrength(int strength, bool black) {
// Compose wifi icon by superimposing various icons.
@@ -378,7 +400,6 @@ void NetworkMenu::RunMenu(views::View* source, const gfx::Point& pt) {
cros->UpdateSystemInfo();
InitMenuItems();
network_menu_->Rebuild();
- network_menu_->UpdateStates();
// Restore menu width, if it was set up.
// NOTE: width isn't checked for correctness here since all width-related
// logic implemented inside |network_menu_|.
@@ -389,31 +410,37 @@ void NetworkMenu::RunMenu(views::View* source, const gfx::Point& pt) {
}
void NetworkMenu::InitMenuItems() {
+ // This gets called on initialization, so any changes should be reflected
+ // in CrosMock::SetNetworkLibraryStatusAreaExpectations().
+
menu_items_.clear();
// Populate our MenuItems with the current list of wifi networks.
NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary();
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
// Ethernet
+ bool ethernet_connected = cros->ethernet_connected();
+ bool ethernet_connecting = cros->ethernet_connecting();
string16 label = l10n_util::GetStringUTF16(
IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET);
SkBitmap icon = *rb.GetBitmapNamed(IDR_STATUSBAR_WIRED_BLACK);
- SkBitmap badge = cros->ethernet_connecting() || cros->ethernet_connected() ?
+ SkBitmap badge = ethernet_connecting || ethernet_connected ?
SkBitmap() : *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_DISCONNECTED);
- int flag = (cros->ethernet_connecting() || cros->ethernet_connected()) ?
+ int flag = (ethernet_connecting || ethernet_connected) ?
FLAG_ETHERNET | FLAG_ASSOCIATED : FLAG_ETHERNET;
menu_items_.push_back(MenuItem(menus::MenuModel::TYPE_COMMAND, label,
IconForDisplay(icon, badge), std::string(), flag));
// Wifi
const WifiNetworkVector& wifi_networks = cros->wifi_networks();
+ const std::string& active_wifi_name = cros->wifi_name();
// Wifi networks ssids.
for (size_t i = 0; i < wifi_networks.size(); ++i) {
label = ASCIIToUTF16(wifi_networks[i].name());
SkBitmap icon = IconForNetworkStrength(wifi_networks[i].strength(), true);
SkBitmap badge = wifi_networks[i].encrypted() ?
*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_SECURE) : SkBitmap();
- flag = (wifi_networks[i].name() == cros->wifi_name()) ?
+ flag = (wifi_networks[i].name() == active_wifi_name) ?
FLAG_WIFI | FLAG_ASSOCIATED : FLAG_WIFI;
menu_items_.push_back(MenuItem(menus::MenuModel::TYPE_COMMAND, label,
IconForDisplay(icon, badge), wifi_networks[i].service_path(), flag));
@@ -421,6 +448,7 @@ void NetworkMenu::InitMenuItems() {
// Cellular
const CellularNetworkVector& cell_networks = cros->cellular_networks();
+ const std::string& active_cellular_name = cros->cellular_name();
// Cellular networks ssids.
for (size_t i = 0; i < cell_networks.size(); ++i) {
label = ASCIIToUTF16(cell_networks[i].name());
@@ -428,7 +456,7 @@ void NetworkMenu::InitMenuItems() {
// TODO(chocobo): Check cellular network 3g/edge.
SkBitmap badge = *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_3G);
// SkBitmap badge = *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_EDGE);
- flag = (cell_networks[i].name() == cros->cellular_name()) ?
+ flag = (cell_networks[i].name() == active_cellular_name) ?
FLAG_CELLULAR | FLAG_ASSOCIATED : FLAG_CELLULAR;
menu_items_.push_back(MenuItem(menus::MenuModel::TYPE_COMMAND, label,
IconForDisplay(icon, badge), cell_networks[i].service_path(), flag));
@@ -449,12 +477,14 @@ void NetworkMenu::InitMenuItems() {
SkBitmap()),
std::string(), FLAG_OTHER_NETWORK));
- if (cros->wifi_available() || cros->cellular_available()) {
+ bool wifi_available = cros->wifi_available();
+ bool cellular_available = cros->cellular_available();
+ if (wifi_available || cellular_available) {
// Separator.
menu_items_.push_back(MenuItem());
// Turn Wifi Off. (only if wifi available)
- if (cros->wifi_available()) {
+ if (wifi_available) {
int id = cros->wifi_enabled() ? IDS_STATUSBAR_NETWORK_DEVICE_DISABLE :
IDS_STATUSBAR_NETWORK_DEVICE_ENABLE;
label = l10n_util::GetStringFUTF16(id,
@@ -464,7 +494,7 @@ void NetworkMenu::InitMenuItems() {
}
// Turn Cellular Off. (only if cellular available)
- if (cros->cellular_available()) {
+ if (cellular_available) {
int id = cros->cellular_enabled() ? IDS_STATUSBAR_NETWORK_DEVICE_DISABLE :
IDS_STATUSBAR_NETWORK_DEVICE_ENABLE;
label = l10n_util::GetStringFUTF16(id,
@@ -495,4 +525,27 @@ void NetworkMenu::InitMenuItems() {
}
}
+void NetworkMenu::ShowTabbedNetworkSettings(const Network& network) {
+ Browser* browser = BrowserList::GetLastActive();
+ if (!browser)
+ return;
+ std::string page = StringPrintf("%s?servicePath=%s&networkType=%d",
+ chrome::kInternetOptionsSubPage,
+ EscapeUrlEncodedData(network.service_path()).c_str(),
+ network.type());
+ browser->ShowOptionsTab(page);
+}
+
+// TODO(stevenjb): deprecate this once all of the UI is embedded in the menu.
+void NetworkMenu::ShowNetworkConfigView(NetworkConfigView* view,
+ bool focus_login) const {
+ view->set_browser_mode(IsBrowserMode());
+ views::Window* window = browser::CreateViewsWindow(
+ GetNativeWindow(), gfx::Rect(), view);
+ window->SetIsAlwaysOnTop(true);
+ window->Show();
+ if (focus_login)
+ view->SetLoginTextfieldFocus();
+}
+
} // namespace chromeos
diff --git a/chrome/browser/chromeos/status/network_menu.h b/chrome/browser/chromeos/status/network_menu.h
index acd9acc..240a573 100644
--- a/chrome/browser/chromeos/status/network_menu.h
+++ b/chrome/browser/chromeos/status/network_menu.h
@@ -74,6 +74,11 @@ class NetworkMenu : public views::ViewMenuDelegate,
// |index| is the index in menu_items_, set when the menu is built.
bool GetNetworkAt(int index, NetworkInfo* info) const;
+ // Connect or reconnect to the network at |index|.
+ void ConnectToNetworkAt(int index,
+ const std::string& passphrase,
+ const std::string& identity) const;
+
// menus::MenuModel implementation.
virtual bool HasIcons() const { return true; }
virtual int GetItemCount() const;
@@ -119,6 +124,8 @@ class NetworkMenu : public views::ViewMenuDelegate,
// Notify subclasses that connection to |network| was initiated.
virtual void OnConnectNetwork(const Network& network,
SkBitmap selected_icon_) {}
+ // Update the menu (e.g. when the network list or status has changed).
+ void UpdateMenu();
private:
enum MenuItemFlags {
@@ -164,6 +171,10 @@ class NetworkMenu : public views::ViewMenuDelegate,
// Shows network details in DOM UI options window.
void ShowTabbedNetworkSettings(const Network& network);
+ // Show a NetworkConfigView modal dialog instance.
+ // TODO(stevenjb): deprecate this once all of the UI is embedded in the menu.
+ void ShowNetworkConfigView(NetworkConfigView* view, bool focus_login) const;
+
// Set to true if we are currently refreshing the menu.
bool refreshing_menu_;
diff --git a/chrome/browser/chromeos/status/network_menu_button.cc b/chrome/browser/chromeos/status/network_menu_button.cc
index 9ed0854..f4ff11c 100644
--- a/chrome/browser/chromeos/status/network_menu_button.cc
+++ b/chrome/browser/chromeos/status/network_menu_button.cc
@@ -148,6 +148,7 @@ void NetworkMenuButton::NetworkChanged(NetworkLibrary* cros) {
}
SchedulePaint();
+ UpdateMenu();
}
void NetworkMenuButton::SetBadge(const SkBitmap& badge) {
diff --git a/chrome/browser/resources/network_menu.js b/chrome/browser/resources/network_menu.js
index d07e152..2f0e767 100644
--- a/chrome/browser/resources/network_menu.js
+++ b/chrome/browser/resources/network_menu.js
@@ -3,10 +3,10 @@
// found in the LICENSE file.
/**
- * Sends 'activate' DOMUI message.
+ * Sends "connect" using the 'action' DOMUI message.
*/
-function sendAction(values) {
- chrome.send('action', values);
+function sendConnect(index, passphrase, identity) {
+ chrome.send('action', [ 'connect', String(index), passphrase, identity ]);
}
var NetworkMenuItem = cr.ui.define('div');
@@ -74,4 +74,18 @@ NetworkMenu.prototype = {
return new MenuItem();
}
},
+
+ onKeydown_: function(event) {
+ switch (event.keyIdentifier) {
+ case 'Enter':
+ case 'U+0020': // space
+ // Temporary, for testing sendConnect()
+ sendConnect(this.getMenuItemIndexOf(this.current_),
+ "passphrase", "identity");
+ break;
+ default:
+ Menu.prototype.onKeydown_.call(this, event);
+ break;
+ }
+ }
};