summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/chromeos/cros/mock_network_library.h2
-rw-r--r--chrome/browser/chromeos/cros/network_library.cc78
-rw-r--r--chrome/browser/chromeos/cros/network_library.h9
-rw-r--r--chrome/browser/chromeos/dom_ui/internet_options_handler.cc328
-rw-r--r--chrome/browser/chromeos/dom_ui/internet_options_handler.h59
-rw-r--r--chrome/browser/chromeos/options/internet_page_view.cc4
-rw-r--r--chrome/browser/dom_ui/options_ui.cc4
-rw-r--r--chrome/browser/resources/options.html5
-rw-r--r--chrome/browser/resources/options/chromeos_internet_network_list.js127
-rw-r--r--chrome/browser/resources/options/chromeos_internet_options.html15
-rw-r--r--chrome/browser/resources/options/chromeos_internet_options.js64
-rw-r--r--chrome/browser/resources/options/chromeos_internet_options_page.css17
-rw-r--r--chrome/chrome_browser.gypi2
13 files changed, 707 insertions, 7 deletions
diff --git a/chrome/browser/chromeos/cros/mock_network_library.h b/chrome/browser/chromeos/cros/mock_network_library.h
index 975a0f1..c329bd3 100644
--- a/chrome/browser/chromeos/cros/mock_network_library.h
+++ b/chrome/browser/chromeos/cros/mock_network_library.h
@@ -66,7 +66,7 @@ class MockNetworkLibrary : public NetworkLibrary {
MOCK_METHOD1(DisconnectFromWirelessNetwork, void(const WirelessNetwork&));
MOCK_METHOD1(SaveCellularNetwork, void(const CellularNetwork&));
MOCK_METHOD1(SaveWifiNetwork, void(const WifiNetwork&));
- MOCK_METHOD1(ForgetWirelessNetwork, void(const WirelessNetwork&));
+ MOCK_METHOD1(ForgetWirelessNetwork, void(const std::string&));
MOCK_CONST_METHOD0(ethernet_available, bool(void));
MOCK_CONST_METHOD0(wifi_available, bool(void));
diff --git a/chrome/browser/chromeos/cros/network_library.cc b/chrome/browser/chromeos/cros/network_library.cc
index 09328e91..1651117 100644
--- a/chrome/browser/chromeos/cros/network_library.cc
+++ b/chrome/browser/chromeos/cros/network_library.cc
@@ -215,6 +215,8 @@ NetworkLibraryImpl::NetworkLibraryImpl()
offline_mode_(false) {
if (CrosLibrary::Get()->EnsureLoaded()) {
Init();
+ } else {
+ InitTestData();
}
g_url_request_job_tracker.AddObserver(this);
}
@@ -460,9 +462,10 @@ void NetworkLibraryImpl::SaveWifiNetwork(const WifiNetwork& network) {
}
}
-void NetworkLibraryImpl::ForgetWirelessNetwork(const WirelessNetwork& network) {
+void NetworkLibraryImpl::ForgetWirelessNetwork(
+ const std::string& service_path) {
if (CrosLibrary::Get()->EnsureLoaded()) {
- DeleteRememberedService(network.service_path().c_str());
+ DeleteRememberedService(service_path.c_str());
}
}
@@ -645,6 +648,77 @@ void NetworkLibraryImpl::Init() {
this);
}
+void NetworkLibraryImpl::InitTestData() {
+ ethernet_.Clear();
+ ethernet_.set_connected(true);
+
+ wifi_networks_.clear();
+ WifiNetwork wifi1 = WifiNetwork();
+ wifi1.set_service_path("fw1");
+ wifi1.set_name("Fake Wifi 1");
+ wifi1.set_strength(90);
+ wifi1.set_connected(false);
+ wifi1.set_encryption(SECURITY_NONE);
+ wifi_networks_.push_back(wifi1);
+
+ WifiNetwork wifi2 = WifiNetwork();
+ wifi2.set_service_path("fw2");
+ wifi2.set_name("Fake Wifi 2");
+ wifi2.set_strength(70);
+ wifi2.set_connected(true);
+ wifi2.set_encryption(SECURITY_WEP);
+ wifi_networks_.push_back(wifi2);
+
+ WifiNetwork wifi3 = WifiNetwork();
+ wifi3.set_service_path("fw3");
+ wifi3.set_name("Fake Wifi 3");
+ wifi3.set_strength(50);
+ wifi3.set_connected(false);
+ wifi3.set_encryption(SECURITY_WEP);
+ wifi_networks_.push_back(wifi3);
+
+ wifi_ = wifi2;
+
+ cellular_networks_.clear();
+
+ cellular_networks_.clear();
+ CellularNetwork cellular1 = CellularNetwork();
+ cellular1.set_service_path("fc1");
+ cellular1.set_name("Fake Cellular 1");
+ cellular1.set_strength(90);
+ cellular1.set_connected(false);
+ cellular_networks_.push_back(cellular1);
+
+ CellularNetwork cellular2 = CellularNetwork();
+ cellular2.set_service_path("fc2");
+ cellular2.set_name("Fake Cellular 2");
+ cellular2.set_strength(70);
+ cellular2.set_connected(true);
+ cellular_networks_.push_back(cellular2);
+
+ CellularNetwork cellular3 = CellularNetwork();
+ cellular3.set_service_path("fc3");
+ cellular3.set_name("Fake Cellular 3");
+ cellular3.set_strength(50);
+ cellular3.set_connected(false);
+ cellular_networks_.push_back(cellular3);
+
+ cellular_ = cellular2;
+
+ remembered_wifi_networks_.clear();
+ remembered_wifi_networks_.push_back(wifi2);
+
+ remembered_cellular_networks_.clear();
+ remembered_cellular_networks_.push_back(cellular2);
+
+ int devices = (1 << TYPE_ETHERNET) | (1 << TYPE_WIFI) |
+ (1 << TYPE_CELLULAR);
+ available_devices_ = devices;
+ enabled_devices_ = devices;
+ connected_devices_ = devices;
+ offline_mode_ = false;
+}
+
void NetworkLibraryImpl::UpdateSystemInfo() {
if (CrosLibrary::Get()->EnsureLoaded()) {
UpdateNetworkStatus();
diff --git a/chrome/browser/chromeos/cros/network_library.h b/chrome/browser/chromeos/cros/network_library.h
index 645e6ae..0a7e5a2 100644
--- a/chrome/browser/chromeos/cros/network_library.h
+++ b/chrome/browser/chromeos/cros/network_library.h
@@ -32,6 +32,8 @@ class Network {
bool failed() const { return state_ == STATE_FAILURE; }
ConnectionError error() const { return error_; }
+ void set_service_path(const std::string& service_path) {
+ service_path_ = service_path; }
void set_connecting(bool connecting) { state_ = (connecting ?
STATE_ASSOCIATION : STATE_IDLE); }
void set_connected(bool connected) { state_ = (connected ?
@@ -92,6 +94,7 @@ class WirelessNetwork : public Network {
bool auto_connect() const { return auto_connect_; }
void set_name(const std::string& name) { name_ = name; }
+ void set_strength(int strength) { strength_ = strength; }
void set_auto_connect(bool auto_connect) { auto_connect_ = auto_connect; }
// Network overrides.
@@ -339,7 +342,7 @@ class NetworkLibrary {
virtual void SaveWifiNetwork(const WifiNetwork& network) = 0;
// Forget the passed in wireless (either cellular or wifi) network.
- virtual void ForgetWirelessNetwork(const WirelessNetwork& network) = 0;
+ virtual void ForgetWirelessNetwork(const std::string& service_path) = 0;
virtual bool ethernet_available() const = 0;
virtual bool wifi_available() const = 0;
@@ -450,7 +453,7 @@ class NetworkLibraryImpl : public NetworkLibrary,
virtual void DisconnectFromWirelessNetwork(const WirelessNetwork& network);
virtual void SaveCellularNetwork(const CellularNetwork& network);
virtual void SaveWifiNetwork(const WifiNetwork& network);
- virtual void ForgetWirelessNetwork(const WirelessNetwork& network);
+ virtual void ForgetWirelessNetwork(const std::string& service_path);
virtual bool ethernet_available() const {
return available_devices_ & (1 << TYPE_ETHERNET);
@@ -505,6 +508,8 @@ class NetworkLibraryImpl : public NetworkLibrary,
// This methods loads the initial list of networks on startup and starts the
// monitoring of network changes.
void Init();
+ // Initialize with test data.
+ void InitTestData();
// Returns the preferred wifi network.
WifiNetwork* GetPreferredNetwork();
diff --git a/chrome/browser/chromeos/dom_ui/internet_options_handler.cc b/chrome/browser/chromeos/dom_ui/internet_options_handler.cc
new file mode 100644
index 0000000..4a40d15
--- /dev/null
+++ b/chrome/browser/chromeos/dom_ui/internet_options_handler.cc
@@ -0,0 +1,328 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/dom_ui/internet_options_handler.h"
+
+#include <string>
+#include <vector>
+
+#include "app/l10n_util.h"
+#include "app/resource_bundle.h"
+#include "base/base64.h"
+#include "base/basictypes.h"
+#include "base/callback.h"
+#include "base/values.h"
+#include "chrome/browser/browser.h"
+#include "chrome/browser/browser_list.h"
+#include "chrome/browser/browser_window.h"
+#include "chrome/browser/chromeos/cros/cros_library.h"
+#include "chrome/browser/chromeos/status/network_menu_button.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/browser/tab_contents/tab_contents_view.h"
+#include "chrome/common/notification_service.h"
+#include "gfx/codec/png_codec.h"
+#include "grit/browser_resources.h"
+#include "grit/chromium_strings.h"
+#include "grit/generated_resources.h"
+#include "grit/locale_settings.h"
+#include "grit/theme_resources.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+#include "views/window/window.h"
+
+InternetOptionsHandler::InternetOptionsHandler() {
+ chromeos::CrosLibrary::Get()->GetNetworkLibrary()->AddObserver(this);
+}
+
+InternetOptionsHandler::~InternetOptionsHandler() {
+ chromeos::CrosLibrary::Get()->GetNetworkLibrary()->RemoveObserver(this);
+}
+
+void InternetOptionsHandler::GetLocalizedValues(
+ DictionaryValue* localized_strings) {
+ DCHECK(localized_strings);
+ // Internet page - ChromeOS
+ localized_strings->SetString(L"internetPage",
+ l10n_util::GetString(IDS_OPTIONS_INTERNET_TAB_LABEL));
+
+ localized_strings->SetString(L"wired_title",
+ l10n_util::GetString(IDS_OPTIONS_SETTINGS_SECTION_TITLE_WIRED_NETWORK));
+ localized_strings->SetString(L"wireless_title",
+ l10n_util::GetString(
+ IDS_OPTIONS_SETTINGS_SECTION_TITLE_WIRELESS_NETWORK));
+ localized_strings->SetString(L"remembered_title",
+ l10n_util::GetString(
+ IDS_OPTIONS_SETTINGS_SECTION_TITLE_REMEMBERED_NETWORK));
+
+ localized_strings->SetString(L"connect_button",
+ l10n_util::GetString(
+ IDS_OPTIONS_SETTINGS_CONNECT));
+ localized_strings->SetString(L"disconnect_button",
+ l10n_util::GetString(
+ IDS_OPTIONS_SETTINGS_DISCONNECT));
+ localized_strings->SetString(L"options_button",
+ l10n_util::GetString(
+ IDS_OPTIONS_SETTINGS_OPTIONS));
+ localized_strings->SetString(L"forget_button",
+ l10n_util::GetString(
+ IDS_OPTIONS_SETTINGS_FORGET));
+
+ localized_strings->Set(L"wiredList", GetWiredList());
+ localized_strings->Set(L"wirelessList", GetWirelessList());
+ localized_strings->Set(L"rememberedList", GetRememberedList());
+}
+
+void InternetOptionsHandler::RegisterMessages() {
+ // Setup handlers specific to this panel.
+ DCHECK(dom_ui_);
+ dom_ui_->RegisterMessageCallback("buttonClickCallback",
+ NewCallback(this, &InternetOptionsHandler::ButtonClickCallback));
+}
+
+void InternetOptionsHandler::NetworkChanged(chromeos::NetworkLibrary* cros) {
+ if (dom_ui_) {
+ DictionaryValue dictionary;
+ dictionary.Set(L"wiredList", GetWiredList());
+ dictionary.Set(L"wirelessList", GetWirelessList());
+ dictionary.Set(L"rememberedList", GetRememberedList());
+ dom_ui_->CallJavascriptFunction(L"refreshNetworkData", dictionary);
+ }
+}
+
+void InternetOptionsHandler::CreateModalPopup(views::WindowDelegate* view) {
+ Browser* browser = NULL;
+ TabContentsDelegate* delegate = dom_ui_->tab_contents()->delegate();
+ if (delegate)
+ browser = delegate->GetBrowser();
+ DCHECK(browser);
+ views::Window* window = views::Window::CreateChromeWindow(
+ browser->window()->GetNativeHandle(), gfx::Rect(), view);
+ window->SetIsAlwaysOnTop(true);
+ window->Show();
+}
+
+void InternetOptionsHandler::ButtonClickCallback(const Value* value) {
+ if (!value || !value->IsType(Value::TYPE_LIST)) {
+ NOTREACHED();
+ return;
+ }
+ const ListValue* list_value = static_cast<const ListValue*>(value);
+ std::string str_type;
+ std::string service_path;
+ std::string command;
+ if (list_value->GetSize() != 3 ||
+ !list_value->GetString(0, &str_type) ||
+ !list_value->GetString(1, &service_path) ||
+ !list_value->GetString(2, &command)) {
+ NOTREACHED();
+ return;
+ }
+
+ int type = atoi(str_type.c_str());
+ chromeos::NetworkLibrary* cros =
+ chromeos::CrosLibrary::Get()->GetNetworkLibrary();
+ if (type == chromeos::TYPE_ETHERNET) {
+ CreateModalPopup(new chromeos::NetworkConfigView(cros->ethernet_network()));
+ } else if (type == chromeos::TYPE_WIFI) {
+ chromeos::WifiNetwork network;
+ if (command == "forget") {
+ cros->ForgetWirelessNetwork(service_path);
+ } else if (cros->FindWifiNetworkByPath(service_path, &network)) {
+ if (command == "connect") {
+ // Connect to wifi here. Open password page if appropriate.
+ if (network.encrypted()) {
+ chromeos::NetworkConfigView* view =
+ new chromeos::NetworkConfigView(network, true);
+ CreateModalPopup(view);
+ view->SetLoginTextfieldFocus();
+ } else {
+ cros->ConnectToWifiNetwork(
+ network, std::string(), std::string(), std::string());
+ }
+ } else if (command == "disconnect") {
+ cros->DisconnectFromWirelessNetwork(network);
+ } else if (command == "options") {
+ CreateModalPopup(new chromeos::NetworkConfigView(network, false));
+ }
+ }
+ } else if (type == chromeos::TYPE_CELLULAR) {
+ chromeos::CellularNetwork network;
+ if (command == "forget") {
+ cros->ForgetWirelessNetwork(service_path);
+ } else if (cros->FindCellularNetworkByPath(service_path, &network)) {
+ if (command == "connect") {
+ cros->ConnectToCellularNetwork(network);
+ } else if (command == "disconnect") {
+ cros->DisconnectFromWirelessNetwork(network);
+ } else if (command == "options") {
+ CreateModalPopup(new chromeos::NetworkConfigView(network));
+ }
+ }
+ } else {
+ NOTREACHED();
+ }
+}
+
+// Helper function to convert an icon to a data: URL
+// with the icon encoded as a PNG.
+static std::string ConvertSkBitmapToDataURL(const SkBitmap& icon) {
+ DCHECK(!icon.isNull());
+
+ // Get the icon data.
+ std::vector<unsigned char> icon_data;
+ gfx::PNGCodec::EncodeBGRASkBitmap(icon, false, &icon_data);
+
+ // Base64-encode it (to make it a data URL).
+ std::string icon_data_str(reinterpret_cast<char*>(&icon_data[0]),
+ icon_data.size());
+ std::string icon_base64_encoded;
+ base::Base64Encode(icon_data_str, &icon_base64_encoded);
+ return std::string("data:image/png;base64," + icon_base64_encoded);
+}
+
+ListValue* InternetOptionsHandler::GetNetwork(const std::string& service_path,
+ const SkBitmap& icon, const std::string& name, bool connecting,
+ bool connected, int connection_type, bool remembered) {
+
+ ListValue* network = new ListValue();
+
+ int s = IDS_STATUSBAR_NETWORK_DEVICE_DISCONNECTED;
+ if (connecting)
+ s = IDS_STATUSBAR_NETWORK_DEVICE_CONNECTING;
+ else if (connected)
+ s = IDS_STATUSBAR_NETWORK_DEVICE_CONNECTED;
+ std::wstring status = l10n_util::GetString(s);
+
+ // service path
+ network->Append(Value::CreateStringValue(service_path));
+ // name
+ network->Append(Value::CreateStringValue(name));
+ // status
+ network->Append(Value::CreateStringValue(l10n_util::GetString(s)));
+ // type
+ network->Append(Value::CreateIntegerValue(connection_type));
+ // connected
+ network->Append(Value::CreateBooleanValue(connected));
+ // connecting
+ network->Append(Value::CreateBooleanValue(connecting));
+ // icon data url
+ network->Append(Value::CreateStringValue(ConvertSkBitmapToDataURL(icon)));
+ // remembered
+ network->Append(Value::CreateBooleanValue(remembered));
+ return network;
+}
+
+ListValue* InternetOptionsHandler::GetWiredList() {
+ chromeos::NetworkLibrary* cros =
+ chromeos::CrosLibrary::Get()->GetNetworkLibrary();
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ ListValue* list = new ListValue();
+
+ const chromeos::EthernetNetwork& ethernet_network = cros->ethernet_network();
+ SkBitmap icon = *rb.GetBitmapNamed(IDR_STATUSBAR_WIRED_BLACK);
+ if (!ethernet_network.connecting() &&
+ !ethernet_network.connected()) {
+ icon = chromeos::NetworkMenuButton::IconForDisplay(icon,
+ *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_DISCONNECTED));
+ }
+ list->Append(GetNetwork(
+ ethernet_network.service_path(),
+ icon,
+ WideToASCII(l10n_util::GetString(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET)),
+ ethernet_network.connecting(),
+ ethernet_network.connected(),
+ chromeos::TYPE_ETHERNET,
+ false));
+ return list;
+}
+
+ListValue* InternetOptionsHandler::GetWirelessList() {
+ chromeos::NetworkLibrary* cros =
+ chromeos::CrosLibrary::Get()->GetNetworkLibrary();
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ ListValue* list = new ListValue();
+
+ const chromeos::WifiNetworkVector& wifi_networks = cros->wifi_networks();
+ for (chromeos::WifiNetworkVector::const_iterator it =
+ wifi_networks.begin(); it != wifi_networks.end(); ++it) {
+ SkBitmap icon = chromeos::NetworkMenuButton::IconForNetworkStrength(
+ it->strength(), true);
+ if (it->encrypted()) {
+ icon = chromeos::NetworkMenuButton::IconForDisplay(icon,
+ *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_SECURE));
+ }
+ list->Append(GetNetwork(
+ it->service_path(),
+ icon,
+ it->name(),
+ it->connecting(),
+ it->connected(),
+ chromeos::TYPE_WIFI,
+ false));
+ }
+
+ const chromeos::CellularNetworkVector& cellular_networks =
+ cros->cellular_networks();
+ for (chromeos::CellularNetworkVector::const_iterator it =
+ cellular_networks.begin(); it != cellular_networks.end(); ++it) {
+ SkBitmap icon = chromeos::NetworkMenuButton::IconForNetworkStrength(
+ it->strength(), true);
+ SkBitmap badge = *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_3G);
+ icon = chromeos::NetworkMenuButton::IconForDisplay(icon, badge);
+ list->Append(GetNetwork(
+ it->service_path(),
+ icon,
+ it->name(),
+ it->connecting(),
+ it->connected(),
+ chromeos::TYPE_CELLULAR,
+ false));
+ }
+
+ return list;
+}
+
+ListValue* InternetOptionsHandler::GetRememberedList() {
+ chromeos::NetworkLibrary* cros =
+ chromeos::CrosLibrary::Get()->GetNetworkLibrary();
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ ListValue* list = new ListValue();
+
+ const chromeos::WifiNetworkVector& wifi_networks =
+ cros->remembered_wifi_networks();
+ for (chromeos::WifiNetworkVector::const_iterator it =
+ wifi_networks.begin(); it != wifi_networks.end(); ++it) {
+ SkBitmap icon = *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0);
+ if (it->encrypted()) {
+ icon = chromeos::NetworkMenuButton::IconForDisplay(icon,
+ *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_SECURE));
+ }
+ list->Append(GetNetwork(
+ it->service_path(),
+ icon,
+ it->name(),
+ it->connecting(),
+ it->connected(),
+ chromeos::TYPE_WIFI,
+ true));
+ }
+
+ const chromeos::CellularNetworkVector& cellular_networks =
+ cros->remembered_cellular_networks();
+ for (chromeos::CellularNetworkVector::const_iterator it =
+ cellular_networks.begin(); it != cellular_networks.end(); ++it) {
+ SkBitmap icon = *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0);
+ SkBitmap badge = *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_3G);
+ icon = chromeos::NetworkMenuButton::IconForDisplay(icon, badge);
+ list->Append(GetNetwork(
+ it->service_path(),
+ icon,
+ it->name(),
+ it->connecting(),
+ it->connected(),
+ chromeos::TYPE_CELLULAR,
+ true));
+ }
+
+ return list;
+}
diff --git a/chrome/browser/chromeos/dom_ui/internet_options_handler.h b/chrome/browser/chromeos/dom_ui/internet_options_handler.h
new file mode 100644
index 0000000..31ebf43d
--- /dev/null
+++ b/chrome/browser/chromeos/dom_ui/internet_options_handler.h
@@ -0,0 +1,59 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROMEOS_DOM_UI_INTERNET_OPTIONS_HANDLER_H_
+#define CHROME_BROWSER_CHROMEOS_DOM_UI_INTERNET_OPTIONS_HANDLER_H_
+
+#include <string>
+
+#include "chrome/browser/chromeos/cros/network_library.h"
+#include "chrome/browser/dom_ui/options_ui.h"
+
+class SkBitmap;
+namespace views {
+class WindowDelegate;
+}
+
+// ChromeOS internet options page UI handler.
+class InternetOptionsHandler : public OptionsPageUIHandler,
+ public chromeos::NetworkLibrary::Observer {
+ public:
+ InternetOptionsHandler();
+ virtual ~InternetOptionsHandler();
+
+ // OptionsUIHandler implementation.
+ virtual void GetLocalizedValues(DictionaryValue* localized_strings);
+
+ // DOMMessageHandler implementation.
+ virtual void RegisterMessages();
+
+ // NetworkLibrary::Observer implementation.
+ virtual void NetworkChanged(chromeos::NetworkLibrary* obj);
+ virtual void NetworkTraffic(chromeos::NetworkLibrary* cros,
+ int traffic_type) {}
+
+ private:
+ // Open a modal popup dialog.
+ void CreateModalPopup(views::WindowDelegate* view);
+ // Open options dialog for network.
+ // |value| will be [ network_type, service_path, command ]
+ // And command is one of 'options', 'connect', disconnect', or 'forget'
+ void ButtonClickCallback(const Value* value);
+
+ // Creates the map of a network
+ ListValue* GetNetwork(const std::string& service_path, const SkBitmap& icon,
+ const std::string& name, bool connecting, bool connected,
+ int connection_type, bool remembered);
+
+ // Creates the map of wired networks
+ ListValue* GetWiredList();
+ // Creates the map of wireless networks
+ ListValue* GetWirelessList();
+ // Creates the map of remembered networks
+ ListValue* GetRememberedList();
+
+ DISALLOW_COPY_AND_ASSIGN(InternetOptionsHandler);
+};
+
+#endif // CHROME_BROWSER_CHROMEOS_DOM_UI_INTERNET_OPTIONS_HANDLER_H_
diff --git a/chrome/browser/chromeos/options/internet_page_view.cc b/chrome/browser/chromeos/options/internet_page_view.cc
index 71f3e55..437f70f 100644
--- a/chrome/browser/chromeos/options/internet_page_view.cc
+++ b/chrome/browser/chromeos/options/internet_page_view.cc
@@ -474,12 +474,12 @@ void RememberedSection::ButtonClicked(int button, int connection_type, int id) {
if (connection_type == TYPE_CELLULAR) {
if (static_cast<int>(celluar_networks_.size()) > id) {
CrosLibrary::Get()->GetNetworkLibrary()->ForgetWirelessNetwork(
- celluar_networks_[id]);
+ celluar_networks_[id].service_path());
}
} else if (connection_type == TYPE_WIFI) {
if (static_cast<int>(wifi_networks_.size()) > id) {
CrosLibrary::Get()->GetNetworkLibrary()->ForgetWirelessNetwork(
- wifi_networks_[id]);
+ wifi_networks_[id].service_path());
}
} else {
NOTREACHED();
diff --git a/chrome/browser/dom_ui/options_ui.cc b/chrome/browser/dom_ui/options_ui.cc
index 003702c..9fe4a7c 100644
--- a/chrome/browser/dom_ui/options_ui.cc
+++ b/chrome/browser/dom_ui/options_ui.cc
@@ -4,6 +4,8 @@
#include "chrome/browser/dom_ui/options_ui.h"
+#include <algorithm>
+
#include "app/l10n_util.h"
#include "app/resource_bundle.h"
#include "base/callback.h"
@@ -47,6 +49,7 @@
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/dom_ui/accounts_options_handler.h"
#include "chrome/browser/chromeos/dom_ui/core_chromeos_options_handler.h"
+#include "chrome/browser/chromeos/dom_ui/internet_options_handler.h"
#include "chrome/browser/chromeos/dom_ui/labs_handler.h"
#include "chrome/browser/chromeos/dom_ui/language_chewing_options_handler.h"
#include "chrome/browser/chromeos/dom_ui/language_hangul_options_handler.h"
@@ -133,6 +136,7 @@ OptionsUI::OptionsUI(TabContents* contents) : DOMUI(contents) {
#if defined(OS_CHROMEOS)
AddOptionsPageUIHandler(localized_strings,
new chromeos::AccountsOptionsHandler());
+ AddOptionsPageUIHandler(localized_strings, new InternetOptionsHandler());
AddOptionsPageUIHandler(localized_strings, new LabsHandler());
AddOptionsPageUIHandler(localized_strings,
new LanguageChewingOptionsHandler());
diff --git a/chrome/browser/resources/options.html b/chrome/browser/resources/options.html
index f239394..a1856b4 100644
--- a/chrome/browser/resources/options.html
+++ b/chrome/browser/resources/options.html
@@ -21,6 +21,8 @@
<script src="options/pref_ui.js"></script>
<script src="options/options_page.js"></script>
<if expr="pp_ifdef('chromeos')">
+ <script src="options/chromeos_internet_network_list.js"></script>
+ <script src="options/chromeos_internet_options.js"></script>
<script src="options/chromeos_language_list.js"></script>
<script src="options/chromeos_language_options.js"></script>
<script src="options/chromeos_system_options.js"></script>
@@ -50,6 +52,7 @@ function load() {
if (cr.isChromeOS) {
OptionsPage.register(SystemOptions.getInstance());
+ OptionsPage.register(InternetOptions.getInstance());
OptionsPage.register(AccountsOptions.getInstance());
// TODO(mazda): uncomment this once the language options is ready
// OptionsPage.register(new OptionsPage(
@@ -118,6 +121,7 @@ window.onpopstate = function(e) {
<link rel="stylesheet" href="options/clear_browser_data_overlay.css">
<if expr="pp_ifdef('chromeos')">
<link rel="stylesheet" href="options/chromeos_accounts_options_page.css">
+ <link rel="stylesheet" href="options/chromeos_internet_options_page.css">
<link rel="stylesheet" href="options/chromeos_language_options.css">
</if>
<link rel="stylesheet" href="options/personal_options.css">
@@ -147,6 +151,7 @@ window.onpopstate = function(e) {
<div id="mainview">
<if expr="pp_ifdef('chromeos')">
<include src="options/chromeos_system_options.html">
+ <include src="options/chromeos_internet_options.html">
<include src="options/chromeos_language_options.html">
<include src="options/chromeos_labs.html">
<include src="options/chromeos_accounts_options.html">
diff --git a/chrome/browser/resources/options/chromeos_internet_network_list.js b/chrome/browser/resources/options/chromeos_internet_network_list.js
new file mode 100644
index 0000000..3536c37
--- /dev/null
+++ b/chrome/browser/resources/options/chromeos_internet_network_list.js
@@ -0,0 +1,127 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+cr.define('options.internet', function() {
+ const List = cr.ui.List;
+ const ListItem = cr.ui.ListItem;
+ const ArrayDataModel = cr.ui.ArrayDataModel;
+
+ /**
+ * Creates a new network list.
+ * @param {Object=} opt_propertyBag Optional properties.
+ * @constructor
+ * @extends {cr.ui.List}
+ */
+ var NetworkList = cr.ui.define('list');
+
+ NetworkList.prototype = {
+ __proto__: List.prototype,
+
+ createItem: function(network) {
+ return new NetworkListItem(network);
+ },
+
+ /**
+ * Loads given network list.
+ * @param {Array} users An array of user object.
+ */
+ load: function(networks) {
+ this.dataModel = new ArrayDataModel(networks);
+ },
+
+ };
+
+ /**
+ * Creates a new network list item.
+ * @param {!ListValue} network The network this represents.
+ * @constructor
+ * @extends {cr.ui.ListItem}
+ */
+ function NetworkListItem(network) {
+ var el = cr.doc.createElement('div');
+ el.servicePath = network[0];
+ el.networkName = network[1];
+ el.networkStatus = network[2];
+ el.networkType = network[3];
+ el.connected = network[4];
+ el.connecting = network[5];
+ el.iconURL = network[6];
+ el.remembered = network[7];
+ NetworkListItem.decorate(el);
+ return el;
+ }
+
+ /**
+ * Decorates an element as a network list item.
+ * @param {!HTMLElement} el The element to decorate.
+ */
+ NetworkListItem.decorate = function(el) {
+ el.__proto__ = NetworkListItem.prototype;
+ el.decorate();
+ };
+
+ NetworkListItem.prototype = {
+ __proto__: ListItem.prototype,
+
+ /** @inheritDoc */
+ decorate: function() {
+ ListItem.prototype.decorate.call(this);
+
+ // icon and name
+ var nameEl = this.ownerDocument.createElement('span');
+ nameEl.className = 'label';
+ // TODO(xiyuan): Use css for this.
+ if (this.connected)
+ nameEl.style.fontWeight = 'bold';
+ nameEl.textContent = this.networkName;
+ nameEl.style.backgroundImage = url(this.iconURL);
+ this.appendChild(nameEl);
+
+ // status
+ var statusEl = this.ownerDocument.createElement('span');
+ statusEl.className = 'label';
+ statusEl.textContent = this.networkStatus;
+ this.appendChild(statusEl);
+
+ if (!this.remembered) {
+ if (this.connected) {
+ // disconnect button (if not ethernet)
+ if (this.networkType != 1)
+ this.appendChild(this.createButton_('disconnect_button',
+ 'disconnect'));
+
+ // options button
+ this.appendChild(this.createButton_('options_button', 'options'));
+ } else if (!this.connecting) {
+ // connect button
+ this.appendChild(this.createButton_('connect_button', 'connect'));
+ }
+ } else {
+ // forget button
+ this.appendChild(this.createButton_('forget_button', 'forget'));
+ }
+ },
+
+ /**
+ * Creates a button for interacting with a network.
+ * @param {Object} name The name of the localStrings to use for the text.
+ * @param {Object} type The type of button.
+ */
+ createButton_: function(name, type) {
+ var buttonEl = this.ownerDocument.createElement('button');
+ buttonEl.textContent = localStrings.getString(name);
+ var networkType = this.networkType;
+ var servicePath = this.servicePath;
+ buttonEl.onclick = function(event) {
+ chrome.send('buttonClickCallback',
+ [String(networkType), String(servicePath), String(type)]);
+ };
+ return buttonEl;
+ }
+ };
+
+ return {
+ NetworkList: NetworkList
+ };
+});
diff --git a/chrome/browser/resources/options/chromeos_internet_options.html b/chrome/browser/resources/options/chromeos_internet_options.html
new file mode 100644
index 0000000..ffbecea
--- /dev/null
+++ b/chrome/browser/resources/options/chromeos_internet_options.html
@@ -0,0 +1,15 @@
+<div class="page hidden" id="internetPage">
+ <h1 i18n-content="internetPage"></h1>
+ <section>
+ <h3 i18n-content="wired_title"></h3>
+ <list class="network-list" id="wiredList"></list>
+ </section>
+ <section>
+ <h3 i18n-content="wireless_title"></h3>
+ <list class="network-list" id="wirelessList"></list>
+ </section>
+ <section>
+ <h3 i18n-content="remembered_title"></h3>
+ <list class="network-list" id="rememberedList"></list>
+ </section>
+</div>
diff --git a/chrome/browser/resources/options/chromeos_internet_options.js b/chrome/browser/resources/options/chromeos_internet_options.js
new file mode 100644
index 0000000..60eca9a
--- /dev/null
+++ b/chrome/browser/resources/options/chromeos_internet_options.js
@@ -0,0 +1,64 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+///////////////////////////////////////////////////////////////////////////////
+// InternetOptions class:
+
+/**
+ * Encapsulated handling of ChromeOS internet options page.
+ * @constructor
+ */
+function InternetOptions() {
+ OptionsPage.call(this, 'internet', localStrings.getString('internetPage'),
+ 'internetPage');
+}
+
+cr.addSingletonGetter(InternetOptions);
+
+// Inherit InternetOptions from OptionsPage.
+InternetOptions.prototype = {
+ __proto__: OptionsPage.prototype,
+
+ /**
+ * Initializes InternetOptions page.
+ * Calls base class implementation to starts preference initialization.
+ */
+ initializePage: function() {
+ // Call base class implementation to starts preference initialization.
+ OptionsPage.prototype.initializePage.call(this);
+
+ options.internet.NetworkList.decorate($('wiredList'));
+ $('wiredList').load(templateData.wiredList);
+ options.internet.NetworkList.decorate($('wirelessList'));
+ $('wirelessList').load(templateData.wirelessList);
+ options.internet.NetworkList.decorate($('rememberedList'));
+ $('rememberedList').load(templateData.rememberedList);
+
+ this.addEventListener('visibleChange', this.handleVisibleChange_);
+ },
+
+ networkListInitalized_: false,
+
+ /**
+ * Handler for OptionsPage's visible property change event.
+ * @param {Event} e Property change event.
+ */
+ handleVisibleChange_ : function(e) {
+ if (!this.networkListInitalized_ && this.visible) {
+ this.networkListInitalized_ = true;
+ $('wiredList').redraw();
+ $('wirelessList').redraw();
+ $('rememberedList').redraw();
+ }
+ }
+};
+
+//
+//Chrome callbacks
+//
+function refreshNetworkData(data) {
+ $('wiredList').load(data.wiredList);
+ $('wirelessList').load(data.wirelessList);
+ $('rememberedList').load(data.rememberedList);
+}
diff --git a/chrome/browser/resources/options/chromeos_internet_options_page.css b/chrome/browser/resources/options/chromeos_internet_options_page.css
new file mode 100644
index 0000000..9e42189
--- /dev/null
+++ b/chrome/browser/resources/options/chromeos_internet_options_page.css
@@ -0,0 +1,17 @@
+.network-list {
+ border: 1px solid lightgrey;
+ padding: 2px;
+ width: 600px;
+ height: 200px;
+}
+
+.network-list > * > .label {
+ -webkit-padding-start: 30px;
+ background: 0 50% no-repeat;
+}
+
+.network-list > * > button {
+ border: 1px solid hsl(214, 91%, 85%);
+ border-radius: 3px;
+ width: 150px;
+}
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 5374e50..cc0cbf5 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -400,6 +400,8 @@
'browser/chromeos/dom_ui/accounts_options_handler.h',
'browser/chromeos/dom_ui/core_chromeos_options_handler.cc',
'browser/chromeos/dom_ui/core_chromeos_options_handler.h',
+ 'browser/chromeos/dom_ui/internet_options_handler.cc',
+ 'browser/chromeos/dom_ui/internet_options_handler.h',
'browser/chromeos/dom_ui/labs_handler.cc',
'browser/chromeos/dom_ui/labs_handler.h',
'browser/chromeos/dom_ui/language_chewing_options_handler.cc',