summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorstevenjb <stevenjb@chromium.org>2015-02-19 15:45:30 -0800
committerCommit bot <commit-bot@chromium.org>2015-02-19 23:46:03 +0000
commit971fb92c8e09f93b8e06c5647784d3e4a3c9484f (patch)
treeae867d845a907a14c16d130bf76417aa444883ad
parent517912ca0c66cc495529a9db707fc3d55ef18cb4 (diff)
downloadchromium_src-971fb92c8e09f93b8e06c5647784d3e4a3c9484f.zip
chromium_src-971fb92c8e09f93b8e06c5647784d3e4a3c9484f.tar.gz
chromium_src-971fb92c8e09f93b8e06c5647784d3e4a3c9484f.tar.bz2
Add Source property to networkingPrivate.getState
BUG=454031 Review URL: https://codereview.chromium.org/917053002 Cr-Commit-Position: refs/heads/master@{#317174}
-rw-r--r--chrome/browser/resources/chromeos/network_ui/network_ui.js16
-rw-r--r--chrome/test/data/extensions/api_test/networking_private/chromeos/test.js12
-rw-r--r--chromeos/network/network_configuration_handler.cc72
-rw-r--r--chromeos/network/network_configuration_handler.h19
-rw-r--r--chromeos/network/network_state.cc2
-rw-r--r--chromeos/network/network_util.cc31
6 files changed, 102 insertions, 50 deletions
diff --git a/chrome/browser/resources/chromeos/network_ui/network_ui.js b/chrome/browser/resources/chromeos/network_ui/network_ui.js
index d03b71f..970d6b7 100644
--- a/chrome/browser/resources/chromeos/network_ui/network_ui.js
+++ b/chrome/browser/resources/chromeos/network_ui/network_ui.js
@@ -32,7 +32,7 @@ var NetworkUI = (function() {
'Type',
'profile_path',
'visible',
- 'onc_source'
+ 'Source'
];
/**
@@ -143,6 +143,16 @@ var NetworkUI = (function() {
};
/**
+ * Returns a valid HTMLElement id from |guid|.
+ *
+ * @param {string} guid A GUID which may start with a digit
+ * @return {string} A valid HTMLElement id.
+ */
+ var idFromGuid = function(guid) {
+ return '_' + guid.replace(/[{}]/g, '');
+ };
+
+ /**
* This callback function is triggered when visible networks are received.
*
* @param {Array} states A list of network state information for each
@@ -198,7 +208,7 @@ var NetworkUI = (function() {
emptyCell.style.border = 'none';
expandedRow.appendChild(emptyCell);
var detailCell = document.createElement('td');
- detailCell.id = guid;
+ detailCell.id = idFromGuid(guid);
detailCell.className = 'state-table-expanded-cell';
detailCell.colSpan = baseRow.childNodes.length - 1;
expandedRow.appendChild(detailCell);
@@ -236,7 +246,7 @@ var NetworkUI = (function() {
return;
}
- var detailCell = document.querySelector('td#' + guid);
+ var detailCell = document.querySelector('td#' + idFromGuid(guid));
if (!detailCell) {
console.error('No cell for GUID: ' + guid);
return;
diff --git a/chrome/test/data/extensions/api_test/networking_private/chromeos/test.js b/chrome/test/data/extensions/api_test/networking_private/chromeos/test.js
index 92285fd..d810af0 100644
--- a/chrome/test/data/extensions/api_test/networking_private/chromeos/test.js
+++ b/chrome/test/data/extensions/api_test/networking_private/chromeos/test.js
@@ -137,6 +137,7 @@ var availableTests = [
"GUID": "stub_wifi1_guid",
"Name": "wifi1",
"Type": "WiFi",
+ "Source":"User",
"WiFi": {
"Security": "WEP-PSK",
"SignalStrength": 40
@@ -145,6 +146,7 @@ var availableTests = [
"GUID": "stub_wifi2_guid",
"Name": "wifi2_PSK",
"Type": "WiFi",
+ "Source":"User",
"WiFi": {
"Security": "WPA-PSK",
}
@@ -159,6 +161,7 @@ var availableTests = [
"ConnectionState": "Connected",
"GUID": "stub_wifi1_guid",
"Name": "wifi1",
+ "Source":"User",
"Type": "WiFi",
"WiFi": {
"Security": "WEP-PSK",
@@ -177,6 +180,7 @@ var availableTests = [
},
"GUID": "stub_ethernet_guid",
"Name": "eth0",
+ "Source":"Device",
"Type": "Ethernet"
}], result);
}));
@@ -194,6 +198,7 @@ var availableTests = [
},
"GUID": "stub_ethernet_guid",
"Name": "eth0",
+ "Source":"Device",
"Type": "Ethernet"
},
{
@@ -201,6 +206,7 @@ var availableTests = [
"ConnectionState": "Connected",
"GUID": "stub_wifi1_guid",
"Name": "wifi1",
+ "Source": "User",
"Type": "WiFi",
"WiFi": {
"Security": "WEP-PSK",
@@ -212,6 +218,7 @@ var availableTests = [
"ConnectionState": "Connected",
"GUID": "stub_wimax_guid",
"Name": "wimax",
+ "Source":"User",
"Type": "WiMAX",
"WiMAX": {
"SignalStrength": 40
@@ -221,6 +228,7 @@ var availableTests = [
"ConnectionState": "Connected",
"GUID": "stub_vpn1_guid",
"Name": "vpn1",
+ "Source":"User",
"Type": "VPN"
},
{
@@ -228,6 +236,7 @@ var availableTests = [
"ConnectionState": "NotConnected",
"GUID": "stub_wifi2_guid",
"Name": "wifi2_PSK",
+ "Source": "User",
"Type": "WiFi",
"WiFi": {
"Security": "WPA-PSK",
@@ -245,6 +254,7 @@ var availableTests = [
"ConnectionState": "Connected",
"GUID": "stub_wifi1_guid",
"Name": "wifi1",
+ "Source": "User",
"Type": "WiFi",
"WiFi": {
"Security": "WEP-PSK",
@@ -256,6 +266,7 @@ var availableTests = [
"ConnectionState": "NotConnected",
"GUID": "stub_wifi2_guid",
"Name": "wifi2_PSK",
+ "Source": "User",
"Type": "WiFi",
"WiFi": {
"Security": "WPA-PSK",
@@ -463,6 +474,7 @@ var availableTests = [
"ConnectionState": "NotConnected",
"GUID": "stub_wifi2_guid",
"Name": "wifi2_PSK",
+ "Source": "User",
"Type": "WiFi",
"WiFi": {
"Security": "WPA-PSK",
diff --git a/chromeos/network/network_configuration_handler.cc b/chromeos/network/network_configuration_handler.cc
index 841398c..fb4b4f5 100644
--- a/chromeos/network/network_configuration_handler.cc
+++ b/chromeos/network/network_configuration_handler.cc
@@ -49,33 +49,6 @@ void InvokeErrorCallback(const std::string& service_path,
error_callback, service_path, error_name, error_msg);
}
-void GetPropertiesCallback(
- const network_handler::DictionaryResultCallback& callback,
- const network_handler::ErrorCallback& error_callback,
- const std::string& service_path,
- DBusMethodCallStatus call_status,
- const base::DictionaryValue& properties) {
- if (call_status != DBUS_METHOD_CALL_SUCCESS) {
- // Because network services are added and removed frequently, we will see
- // failures regularly, so don't log these.
- network_handler::RunErrorCallback(error_callback,
- service_path,
- network_handler::kDBusFailedError,
- network_handler::kDBusFailedErrorMessage);
- return;
- }
- if (callback.is_null())
- return;
-
- // Get the correct name from WifiHex if necessary.
- scoped_ptr<base::DictionaryValue> properties_copy(properties.DeepCopy());
- std::string name =
- shill_property_util::GetNameFromProperties(service_path, properties);
- if (!name.empty())
- properties_copy->SetStringWithoutPathExpansion(shill::kNameProperty, name);
- callback.Run(service_path, *properties_copy.get());
-}
-
void SetNetworkProfileErrorCallback(
const std::string& service_path,
const std::string& profile_path,
@@ -229,12 +202,12 @@ void NetworkConfigurationHandler::RemoveObserver(
void NetworkConfigurationHandler::GetProperties(
const std::string& service_path,
const network_handler::DictionaryResultCallback& callback,
- const network_handler::ErrorCallback& error_callback) const {
+ const network_handler::ErrorCallback& error_callback) {
NET_LOG_USER("GetProperties", service_path);
DBusThreadManager::Get()->GetShillServiceClient()->GetProperties(
dbus::ObjectPath(service_path),
- base::Bind(&GetPropertiesCallback,
- callback, error_callback, service_path));
+ base::Bind(&NetworkConfigurationHandler::GetPropertiesCallback,
+ AsWeakPtr(), callback, error_callback, service_path));
}
void NetworkConfigurationHandler::SetProperties(
@@ -432,6 +405,45 @@ void NetworkConfigurationHandler::SetNetworkProfileCompleted(
OnConfigurationProfileChanged(service_path, profile_path, source));
}
+void NetworkConfigurationHandler::GetPropertiesCallback(
+ const network_handler::DictionaryResultCallback& callback,
+ const network_handler::ErrorCallback& error_callback,
+ const std::string& service_path,
+ DBusMethodCallStatus call_status,
+ const base::DictionaryValue& properties) {
+ if (call_status != DBUS_METHOD_CALL_SUCCESS) {
+ // Because network services are added and removed frequently, we will see
+ // failures regularly, so don't log these.
+ network_handler::RunErrorCallback(error_callback, service_path,
+ network_handler::kDBusFailedError,
+ network_handler::kDBusFailedErrorMessage);
+ return;
+ }
+ if (callback.is_null())
+ return;
+
+ // Get the correct name from WifiHex if necessary.
+ scoped_ptr<base::DictionaryValue> properties_copy(properties.DeepCopy());
+ std::string name =
+ shill_property_util::GetNameFromProperties(service_path, properties);
+ if (!name.empty())
+ properties_copy->SetStringWithoutPathExpansion(shill::kNameProperty, name);
+
+ // Get the GUID property from NetworkState if it is not set in Shill.
+ std::string guid;
+ properties.GetStringWithoutPathExpansion(::onc::network_config::kGUID, &guid);
+ if (guid.empty()) {
+ const NetworkState* network_state =
+ network_state_handler_->GetNetworkState(service_path);
+ if (network_state) {
+ properties_copy->SetStringWithoutPathExpansion(
+ ::onc::network_config::kGUID, network_state->guid());
+ }
+ }
+
+ callback.Run(service_path, *properties_copy.get());
+}
+
void NetworkConfigurationHandler::SetPropertiesSuccessCallback(
const std::string& service_path,
scoped_ptr<base::DictionaryValue> set_properties,
diff --git a/chromeos/network/network_configuration_handler.h b/chromeos/network/network_configuration_handler.h
index 4b404d8..aa77ef2 100644
--- a/chromeos/network/network_configuration_handler.h
+++ b/chromeos/network/network_configuration_handler.h
@@ -66,10 +66,9 @@ class CHROMEOS_EXPORT NetworkConfigurationHandler
// Gets the properties of the network with id |service_path|. See note on
// |callback| and |error_callback|, in class description above.
- void GetProperties(
- const std::string& service_path,
- const network_handler::DictionaryResultCallback& callback,
- const network_handler::ErrorCallback& error_callback) const;
+ void GetProperties(const std::string& service_path,
+ const network_handler::DictionaryResultCallback& callback,
+ const network_handler::ErrorCallback& error_callback);
// Sets the properties of the network with id |service_path|. This means the
// given properties will be merged with the existing settings, and it won't
@@ -159,7 +158,15 @@ class CHROMEOS_EXPORT NetworkConfigurationHandler
NetworkConfigurationObserver::Source source,
const base::Closure& callback);
- // Invoke the callback and inform NetworkStateHandler to request an update
+ // Set the Name and GUID properties correctly and Invoke |callback|.
+ void GetPropertiesCallback(
+ const network_handler::DictionaryResultCallback& callback,
+ const network_handler::ErrorCallback& error_callback,
+ const std::string& service_path,
+ DBusMethodCallStatus call_status,
+ const base::DictionaryValue& properties);
+
+ // Invoke |callback| and inform NetworkStateHandler to request an update
// for the service after setting properties.
void SetPropertiesSuccessCallback(
const std::string& service_path,
@@ -172,7 +179,7 @@ class CHROMEOS_EXPORT NetworkConfigurationHandler
const std::string& dbus_error_name,
const std::string& dbus_error_message);
- // Invoke the callback and inform NetworkStateHandler to request an update
+ // Invoke |callback| and inform NetworkStateHandler to request an update
// for the service after clearing properties.
void ClearPropertiesSuccessCallback(
const std::string& service_path,
diff --git a/chromeos/network/network_state.cc b/chromeos/network/network_state.cc
index 8bbb991..1843a69 100644
--- a/chromeos/network/network_state.cc
+++ b/chromeos/network/network_state.cc
@@ -202,6 +202,8 @@ void NetworkState::GetStateProperties(base::DictionaryValue* dictionary) const {
dictionary->SetStringWithoutPathExpansion(shill::kGuidProperty, guid());
dictionary->SetStringWithoutPathExpansion(shill::kSecurityClassProperty,
security_class());
+ dictionary->SetStringWithoutPathExpansion(shill::kProfileProperty,
+ profile_path());
if (visible()) {
if (!error().empty())
diff --git a/chromeos/network/network_util.cc b/chromeos/network/network_util.cc
index 1d84adf..ea6e3e2 100644
--- a/chromeos/network/network_util.cc
+++ b/chromeos/network/network_util.cc
@@ -7,8 +7,11 @@
#include "base/strings/string_tokenizer.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
+#include "chromeos/login/login_state.h"
+#include "chromeos/network/managed_network_configuration_handler.h"
#include "chromeos/network/network_state.h"
#include "chromeos/network/network_state_handler.h"
+#include "chromeos/network/network_ui_data.h"
#include "chromeos/network/onc/onc_signature.h"
#include "chromeos/network/onc/onc_translation_tables.h"
#include "chromeos/network/onc/onc_translator.h"
@@ -146,9 +149,18 @@ scoped_ptr<base::DictionaryValue> TranslateNetworkStateToONC(
base::DictionaryValue shill_dictionary;
network->GetStateProperties(&shill_dictionary);
+ // NetworkState is always associated with the primary user profile, regardless
+ // of what profile is associated with the page that calls this method. We do
+ // not expose any sensitive properties in the resulting dictionary, it is
+ // only used to show connection state and icons.
+ std::string user_id_hash = chromeos::LoginState::Get()->primary_user_hash();
+ ::onc::ONCSource onc_source = ::onc::ONC_SOURCE_NONE;
+ NetworkHandler::Get()
+ ->managed_network_configuration_handler()
+ ->FindPolicyByGUID(user_id_hash, network->guid(), &onc_source);
+
scoped_ptr<base::DictionaryValue> onc_dictionary =
- TranslateShillServiceToONCPart(shill_dictionary,
- ::onc::ONC_SOURCE_UNKNOWN,
+ TranslateShillServiceToONCPart(shill_dictionary, onc_source,
&onc::kNetworkWithStateSignature);
return onc_dictionary.Pass();
}
@@ -164,18 +176,15 @@ scoped_ptr<base::ListValue> TranslateNetworkListToONC(
pattern, configured_only, visible_only, limit, &network_states);
scoped_ptr<base::ListValue> network_properties_list(new base::ListValue);
- for (NetworkStateHandler::NetworkStateList::iterator it =
- network_states.begin();
- it != network_states.end();
- ++it) {
+ for (const NetworkState* state : network_states) {
scoped_ptr<base::DictionaryValue> onc_dictionary =
- TranslateNetworkStateToONC(*it);
+ TranslateNetworkStateToONC(state);
if (debugging_properties) {
- onc_dictionary->SetBoolean("connectable", (*it)->connectable());
- onc_dictionary->SetBoolean("visible", (*it)->visible());
- onc_dictionary->SetString("profile_path", (*it)->profile_path());
- onc_dictionary->SetString("service_path", (*it)->path());
+ onc_dictionary->SetBoolean("connectable", state->connectable());
+ onc_dictionary->SetBoolean("visible", state->visible());
+ onc_dictionary->SetString("profile_path", state->profile_path());
+ onc_dictionary->SetString("service_path", state->path());
}
network_properties_list->Append(onc_dictionary.release());