diff options
author | mnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-17 06:47:22 +0000 |
---|---|---|
committer | mnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-17 06:47:22 +0000 |
commit | 5d30093dfcb030d02b5e3873ae77b30fe660d9de (patch) | |
tree | 8ebfe24cfeb1d5a24458c0e3a8506ac592769856 | |
parent | 6a712e7c5c5a892abb46140946fca1c0c02c6454 (diff) | |
download | chromium_src-5d30093dfcb030d02b5e3873ae77b30fe660d9de.zip chromium_src-5d30093dfcb030d02b5e3873ae77b30fe660d9de.tar.gz chromium_src-5d30093dfcb030d02b5e3873ae77b30fe660d9de.tar.bz2 |
Parse UI meta data for policy-configured networks directly from ONC dictionary.
BUG=chromium-os:19411
TEST=Confrigure a network through policy. Check whether recommended settings show up properly in the UI.
Review URL: http://codereview.chromium.org/8918025
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114915 0039d316-1c4b-4281-b951-d872f2087c98
17 files changed, 681 insertions, 405 deletions
diff --git a/chrome/browser/chromeos/cros/mock_network_library.h b/chrome/browser/chromeos/cros/mock_network_library.h index ff959d8..92b6905 100644 --- a/chrome/browser/chromeos/cros/mock_network_library.h +++ b/chrome/browser/chromeos/cros/mock_network_library.h @@ -82,6 +82,9 @@ class MockNetworkLibrary : public NetworkLibrary { MOCK_CONST_METHOD1(FindRememberedNetworkByPath, Network*(const std::string&)); MOCK_CONST_METHOD1(FindRememberedNetworkByUniqueId, Network*(const std::string&)); + MOCK_CONST_METHOD1(FindOncForNetwork, + const base::DictionaryValue*( + const std::string& unique_id)); MOCK_CONST_METHOD1(GetDataPlans, CellularDataPlanVector*(const std::string&)); MOCK_CONST_METHOD1(GetSignificantDataPlan, diff --git a/chrome/browser/chromeos/cros/network_library.cc b/chrome/browser/chromeos/cros/network_library.cc index 59936a9..f69b7e4 100644 --- a/chrome/browser/chromeos/cros/network_library.cc +++ b/chrome/browser/chromeos/cros/network_library.cc @@ -1705,6 +1705,9 @@ class NetworkLibraryImplBase : public NetworkLibrary { virtual Network* FindRememberedNetworkByUniqueId( const std::string& unique_id) const OVERRIDE; + virtual const base::DictionaryValue* FindOncForNetwork( + const std::string& unique_id) const OVERRIDE; + virtual const CellularDataPlanVector* GetDataPlans( const std::string& path) const OVERRIDE; virtual const CellularDataPlan* GetSignificantDataPlan( @@ -1779,6 +1782,7 @@ class NetworkLibraryImplBase : public NetworkLibrary { typedef std::map<std::string, int> PriorityMap; typedef std::map<std::string, NetworkDevice*> NetworkDeviceMap; typedef std::map<std::string, CellularDataPlanVector*> CellularDataPlanMap; + typedef std::map<std::string, const base::DictionaryValue*> NetworkOncMap; struct NetworkProfile { NetworkProfile(const std::string& p, NetworkProfileType t) @@ -1997,6 +2001,9 @@ class NetworkLibraryImplBase : public NetworkLibrary { // Temporary connection data for async connect calls. ConnectData connect_data_; + // Holds unique id to ONC mapping. + NetworkOncMap network_onc_map_; + DISALLOW_COPY_AND_ASSIGN(NetworkLibraryImplBase); }; @@ -2028,6 +2035,7 @@ NetworkLibraryImplBase::~NetworkLibraryImplBase() { STLDeleteValues(&device_map_); STLDeleteValues(&network_device_observers_); STLDeleteValues(&network_observers_); + STLDeleteValues(&network_onc_map_); } ////////////////////////////////////////////////////////////////////////////// @@ -2372,6 +2380,12 @@ Network* NetworkLibraryImplBase::FindRememberedNetworkByUniqueId( return NULL; } +const base::DictionaryValue* NetworkLibraryImplBase::FindOncForNetwork( + const std::string& unique_id) const { + NetworkOncMap::const_iterator iter = network_onc_map_.find(unique_id); + return iter != network_onc_map_.end() ? iter->second : NULL; +} + //////////////////////////////////////////////////////////////////////////// // Data Plans. @@ -2875,6 +2889,7 @@ bool NetworkLibraryImplBase::LoadOncNetworks(const std::string& onc_blob, } // Parse all networks. Bail out if that fails. + NetworkOncMap added_onc_map; ScopedVector<Network> networks; for (int i = 0; i < parser.GetNetworkConfigsSize(); i++) { // Parse Open Network Configuration blob into a temporary Network object. @@ -2886,6 +2901,15 @@ bool NetworkLibraryImplBase::LoadOncNetworks(const std::string& onc_blob, return false; } networks.push_back(network); + added_onc_map[network->unique_id()] = parser.GetNetworkConfig(i); + } + + // Update the ONC map. + for (NetworkOncMap::iterator iter(added_onc_map.begin()); + iter != added_onc_map.end(); ++iter) { + const base::DictionaryValue*& entry = network_onc_map_[iter->first]; + delete entry; + entry = iter->second->DeepCopy(); } // Configure the networks. While doing so, collect unique identifiers of the @@ -2926,7 +2950,7 @@ bool NetworkLibraryImplBase::LoadOncNetworks(const std::string& onc_blob, for (WifiNetworkVector::iterator i(remembered_wifi_networks_.begin()); i != remembered_wifi_networks_.end(); ++i) { WifiNetwork* network = *i; - if (NetworkUIData::GetONCSource(network) == source && + if (NetworkUIData::GetONCSource(network->ui_data()) == source && network_ids.find(network->unique_id()) == network_ids.end()) to_be_deleted.push_back(network->service_path()); } @@ -2934,7 +2958,7 @@ bool NetworkLibraryImplBase::LoadOncNetworks(const std::string& onc_blob, for (VirtualNetworkVector::iterator i(remembered_virtual_networks_.begin()); i != remembered_virtual_networks_.end(); ++i) { VirtualNetwork* network = *i; - if (NetworkUIData::GetONCSource(network) == source && + if (NetworkUIData::GetONCSource(network->ui_data()) == source && network_ids.find(network->unique_id()) == network_ids.end()) to_be_deleted.push_back(network->service_path()); } @@ -3179,6 +3203,14 @@ void NetworkLibraryImplBase::DeleteRememberedNetwork( } } + // Remove the ONC blob for the network, if present. + NetworkOncMap::iterator onc_map_entry = + network_onc_map_.find(network->unique_id()); + if (onc_map_entry != network_onc_map_.end()) { + delete onc_map_entry->second; + network_onc_map_.erase(onc_map_entry); + } + delete remembered_network; } diff --git a/chrome/browser/chromeos/cros/network_library.h b/chrome/browser/chromeos/cros/network_library.h index 7f22d19..ed24f95 100644 --- a/chrome/browser/chromeos/cros/network_library.h +++ b/chrome/browser/chromeos/cros/network_library.h @@ -1620,6 +1620,13 @@ class NetworkLibrary { virtual Network* FindRememberedNetworkByUniqueId( const std::string& unique_id) const = 0; + // Return a pointer to the ONC dictionary for a network identified by unique + // ID. Returns NULL if there is no ONC dictionary available for that network. + // The ONC dictionary is usually only present for policy-configure networks + // which get reconfigured at startup. + virtual const base::DictionaryValue* FindOncForNetwork( + const std::string& unique_id) const = 0; + // Retrieves the data plans associated with |path|, NULL if there are no // associated plans. virtual const CellularDataPlanVector* GetDataPlans( diff --git a/chrome/browser/chromeos/cros/network_ui_data.cc b/chrome/browser/chromeos/cros/network_ui_data.cc index b546b48..386bd22 100644 --- a/chrome/browser/chromeos/cros/network_ui_data.cc +++ b/chrome/browser/chromeos/cros/network_ui_data.cc @@ -11,33 +11,8 @@ namespace chromeos { // Top-level UI data dictionary keys. const char NetworkUIData::kKeyONCSource[] = "onc_source"; -const char NetworkUIData::kKeyProperties[] = "properties"; // Property names for per-property data stored under |kKeyProperties|. -const char NetworkUIData::kPropertyAutoConnect[] = "auto_connect"; -const char NetworkUIData::kPropertyPreferred[] = "preferred"; -const char NetworkUIData::kPropertyPassphrase[] = "passphrase"; -const char NetworkUIData::kPropertySaveCredentials[] = "save_credentials"; - -const char NetworkUIData::kPropertyVPNCaCertNss[] = "VPN.ca_cert_nss"; -const char NetworkUIData::kPropertyVPNPskPassphrase[] = "VPN.psk_passphrase"; -const char NetworkUIData::kPropertyVPNClientCertId[] = "VPN.client_cert_id"; -const char NetworkUIData::kPropertyVPNUsername[] = "VPN.username"; -const char NetworkUIData::kPropertyVPNUserPassphrase[] = "VPN.user_passphrase"; -const char NetworkUIData::kPropertyVPNGroupName[] = "VPN.group_name"; - -const char NetworkUIData::kPropertyEAPMethod[] = "EAP.method"; -const char NetworkUIData::kPropertyEAPPhase2Auth[] = "EAP.phase_2_auth"; -const char NetworkUIData::kPropertyEAPServerCaCertNssNickname[] = - "EAP.server_ca_cert_nss_nickname"; -const char NetworkUIData::kPropertyEAPClientCertPkcs11Id[] = - "EAP.client_cert_pkcs11_id"; -const char NetworkUIData::kPropertyEAPUseSystemCAs[] = "EAP.use_system_cas"; -const char NetworkUIData::kPropertyEAPIdentity[] = "EAP.identity"; -const char NetworkUIData::kPropertyEAPAnonymousIdentity[] = - "EAP.anonymous_identity"; -const char NetworkUIData::kPropertyEAPPassphrase[] = "EAP.passphrase"; - const EnumMapper<NetworkUIData::ONCSource>::Pair NetworkUIData::kONCSourceTable[] = { { "user_import", NetworkUIData::ONC_SOURCE_USER_IMPORT }, @@ -49,12 +24,6 @@ const EnumMapper<NetworkUIData::ONCSource>::Pair const char NetworkPropertyUIData::kKeyController[] = "controller"; const char NetworkPropertyUIData::kKeyDefaultValue[] = "default_value"; -const EnumMapper<NetworkPropertyUIData::Controller>::Pair - NetworkPropertyUIData::kControllerTable[] = { - { "user", NetworkPropertyUIData::CONTROLLER_USER }, - { "policy", NetworkPropertyUIData::CONTROLLER_POLICY }, -}; - NetworkUIData::NetworkUIData() : onc_source_(ONC_SOURCE_NONE) { } @@ -62,31 +31,26 @@ NetworkUIData::NetworkUIData() NetworkUIData::~NetworkUIData() { } -void NetworkUIData::SetProperty(const char* property_key, - const NetworkPropertyUIData& ui_data) { - properties_.Set(property_key, ui_data.BuildDictionary()); -} - void NetworkUIData::FillDictionary(base::DictionaryValue* dict) const { dict->Clear(); std::string source_string(GetONCSourceMapper().GetKey(onc_source_)); if (!source_string.empty()) dict->SetString(kKeyONCSource, source_string); - dict->Set(kKeyProperties, properties_.DeepCopy()); } // static -NetworkUIData::ONCSource NetworkUIData::GetONCSource(const Network* network) { +NetworkUIData::ONCSource NetworkUIData::GetONCSource( + const base::DictionaryValue* ui_data) { std::string source; - if (network->ui_data()->GetString(kKeyONCSource, &source)) + if (ui_data && ui_data->GetString(kKeyONCSource, &source)) return GetONCSourceMapper().Get(source); return ONC_SOURCE_NONE; } // static -bool NetworkUIData::IsManaged(const Network* network) { - ONCSource source = GetONCSource(network); +bool NetworkUIData::IsManaged(const base::DictionaryValue* ui_data) { + ONCSource source = GetONCSource(ui_data); return source == ONC_SOURCE_DEVICE_POLICY || source == ONC_SOURCE_USER_POLICY; } @@ -111,60 +75,44 @@ NetworkPropertyUIData::NetworkPropertyUIData(Controller controller, default_value_(default_value) { } -NetworkPropertyUIData::NetworkPropertyUIData(const Network* network, - const char* property_key) { - UpdateFromNetwork(network, property_key); +NetworkPropertyUIData::NetworkPropertyUIData( + const base::DictionaryValue* ui_data) { + Reset(ui_data); } -void NetworkPropertyUIData::UpdateFromNetwork(const Network* network, - const char* property_key) { - // If there is no per-property information available, the property inherits - // the controlled state of the network. - controller_ = - NetworkUIData::IsManaged(network) ? CONTROLLER_POLICY : CONTROLLER_USER; +void NetworkPropertyUIData::Reset(const base::DictionaryValue* ui_data) { default_value_.reset(); - - if (!property_key) - return; - - const base::DictionaryValue* ui_data = network->ui_data(); - if (!ui_data) - return; - - base::DictionaryValue* property_map = NULL; - if (!ui_data->GetDictionary(NetworkUIData::kKeyProperties, &property_map)) - return; - - base::DictionaryValue* property = NULL; - if (!property_map->GetDictionary(property_key, &property)) - return; - - std::string controller; - if (property->GetString(kKeyController, &controller)) - controller_ = GetControllerMapper().Get(controller); - - base::Value* default_value = NULL; - if (property->Get(kKeyDefaultValue, &default_value) && default_value) - default_value_.reset(default_value->DeepCopy()); + controller_ = NetworkUIData::IsManaged(ui_data) ? CONTROLLER_POLICY + : CONTROLLER_USER; } -base::DictionaryValue* NetworkPropertyUIData::BuildDictionary() const { - base::DictionaryValue* dict = new base::DictionaryValue(); - std::string controller_string(GetControllerMapper().GetKey(controller_)); - if (!controller_string.empty()) - dict->SetString(kKeyController, controller_string); - if (default_value_.get()) - dict->Set(kKeyDefaultValue, default_value_->DeepCopy()); - return dict; -} +void NetworkPropertyUIData::ParseOncProperty( + const base::DictionaryValue* ui_data, + const base::DictionaryValue* onc, + const std::string& property_key) { + Reset(ui_data); + if (!onc || controller_ == CONTROLLER_USER) + return; -// static -EnumMapper<NetworkPropertyUIData::Controller>& - NetworkPropertyUIData::GetControllerMapper() { - CR_DEFINE_STATIC_LOCAL(EnumMapper<Controller>, mapper, - (kControllerTable, arraysize(kControllerTable), - CONTROLLER_USER)); - return mapper; + size_t pos = property_key.find_last_of('.'); + std::string recommended_property_key; + std::string property_basename(property_key); + if (pos != std::string::npos) { + recommended_property_key = property_key.substr(0, pos + 1); + property_basename = property_key.substr(pos + 1); + } + recommended_property_key += "Recommended"; + + base::ListValue* recommended_keys = NULL; + if (onc->GetList(recommended_property_key, &recommended_keys)) { + base::StringValue basename_value(property_basename); + if (recommended_keys->Find(basename_value) != recommended_keys->end()) { + controller_ = CONTROLLER_USER; + base::Value* default_value = NULL; + if (onc->Get(property_key, &default_value)) + default_value_.reset(default_value->DeepCopy()); + } + } } } // namespace chromeos diff --git a/chrome/browser/chromeos/cros/network_ui_data.h b/chrome/browser/chromeos/cros/network_ui_data.h index 7d07744..3817f7c 100644 --- a/chrome/browser/chromeos/cros/network_ui_data.h +++ b/chrome/browser/chromeos/cros/network_ui_data.h @@ -15,7 +15,6 @@ namespace chromeos { -class Network; class NetworkPropertyUIData; // Helper for accessing and setting values in the network's UI data dictionary. @@ -26,11 +25,6 @@ class NetworkPropertyUIData; // // NetworkUIData ui_data; // ui_data.set_onc_source(NetworkUIData::ONC_SOURCE_USER_IMPORT); -// NetworkPropertyUIData auto_connect_property( -// NetworkPropertyUIData::CONTROLLER_USER, -// base::Value::CreateBooleanValue(true)); -// ui_data.SetProperty(NetworkUIData::kPropertyAutoConnect, -// auto_connect_property); // ui_data.FillDictionary(network->ui_data()); class NetworkUIData { public: @@ -49,53 +43,23 @@ class NetworkUIData { // Sets the ONC source. void set_onc_source(ONCSource onc_source) { onc_source_ = onc_source; } - // Fills in metadata for a property. - void SetProperty(const char* property_key, - const NetworkPropertyUIData& ui_data); - // Fills in |dict| with the currently configured values. This will write the // keys appropriate for Network::ui_data() as defined below (kKeyXXX). - void FillDictionary(DictionaryValue* dict) const; + void FillDictionary(base::DictionaryValue* dict) const; // Get the ONC source for a network. - static ONCSource GetONCSource(const Network* network); + static ONCSource GetONCSource(const base::DictionaryValue* ui_data); // Check whether a network is managed by policy. - static bool IsManaged(const Network* network); + static bool IsManaged(const base::DictionaryValue* ui_data); // Source of the ONC network. This is an integer according to enum ONCSource. static const char kKeyONCSource[]; - // Per-property meta data. This is handled by NetworkPropertyUIData. - static const char kKeyProperties[]; - - // Property names for per-property dat - static const char kPropertyAutoConnect[]; - static const char kPropertyPreferred[]; - static const char kPropertyPassphrase[]; - static const char kPropertySaveCredentials[]; - - static const char kPropertyVPNCaCertNss[]; - static const char kPropertyVPNPskPassphrase[]; - static const char kPropertyVPNClientCertId[]; - static const char kPropertyVPNUsername[]; - static const char kPropertyVPNUserPassphrase[]; - static const char kPropertyVPNGroupName[]; - - static const char kPropertyEAPMethod[]; - static const char kPropertyEAPPhase2Auth[]; - static const char kPropertyEAPServerCaCertNssNickname[]; - static const char kPropertyEAPClientCertPkcs11Id[]; - static const char kPropertyEAPUseSystemCAs[]; - static const char kPropertyEAPIdentity[]; - static const char kPropertyEAPAnonymousIdentity[]; - static const char kPropertyEAPPassphrase[]; - private: static EnumMapper<ONCSource>& GetONCSourceMapper(); ONCSource onc_source_; - DictionaryValue properties_; static const EnumMapper<NetworkUIData::ONCSource>::Pair kONCSourceTable[]; @@ -119,21 +83,22 @@ class NetworkPropertyUIData { NetworkPropertyUIData(); ~NetworkPropertyUIData(); + // Initializes the object by calling Reset() with the provided ui_data. + explicit NetworkPropertyUIData(const base::DictionaryValue* ui_data); + // Initializes the object with the given values. |default_value| may be NULL // to specify no default value is present. Takes ownership of |default_value|. NetworkPropertyUIData(Controller controller, base::Value* default_value); - // Initializes the object and calls UpdateFromNetwork. - NetworkPropertyUIData(const Network* network, const char* property_key); + // Resets the property to the controller specified by the given |ui_data| and + // clears the default value. + void Reset(const base::DictionaryValue* ui_data); - // Updates the object from the network-level UI data dictionary. - // |property_key| may be null, in which case the there'll be no default value - // and |controller| will be set to CONTROLLER_POLICY iff the network is - // managed. - void UpdateFromNetwork(const Network* network, const char* property_key); - // Builds a dictionary for storing in the network-level UI data dictionary. - // Ownership is transferred to the caller. - DictionaryValue* BuildDictionary() const; + // Update the property object from dictionary, reading the key given by + // |property_key|. + void ParseOncProperty(const base::DictionaryValue* ui_data, + const base::DictionaryValue* onc, + const std::string& property_key); const base::Value* default_value() const { return default_value_.get(); } bool managed() const { return controller_ == CONTROLLER_POLICY; } @@ -143,17 +108,12 @@ class NetworkPropertyUIData { bool editable() const { return controller_ == CONTROLLER_USER; } private: - static EnumMapper<Controller>& GetControllerMapper(); - Controller controller_; scoped_ptr<base::Value> default_value_; static const char kKeyController[]; static const char kKeyDefaultValue[]; - static const EnumMapper<NetworkPropertyUIData::Controller>::Pair - kControllerTable[]; - // So it can access the kKeyXYZ constants. friend class NetworkUIDataTest; diff --git a/chrome/browser/chromeos/cros/network_ui_data_unittest.cc b/chrome/browser/chromeos/cros/network_ui_data_unittest.cc index 36cddb3..10ff44f 100644 --- a/chrome/browser/chromeos/cros/network_ui_data_unittest.cc +++ b/chrome/browser/chromeos/cros/network_ui_data_unittest.cc @@ -2,164 +2,133 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/memory/scoped_ptr.h" -#include "base/stringprintf.h" -#include "chrome/browser/chromeos/cros/network_library.h" #include "chrome/browser/chromeos/cros/network_ui_data.h" #include "testing/gtest/include/gtest/gtest.h" namespace chromeos { -namespace { - -// A mock network for testing. We really only need the ui_data() member. -class TestNetwork : public Network { - public: - TestNetwork() - : Network("wifi-network", TYPE_WIFI) {} -}; - -} // namespace - class NetworkUIDataTest : public testing::Test { protected: NetworkUIDataTest() {} - - static void SetProperty(DictionaryValue* dict, - const char* property_key, - const char* controller, - base::Value* default_value) { - DictionaryValue* property_dict = new DictionaryValue(); - if (controller) { - property_dict->SetString(NetworkPropertyUIData::kKeyController, - controller); - } - if (default_value) { - property_dict->Set(NetworkPropertyUIData::kKeyDefaultValue, - default_value); - } - dict->Set(base::StringPrintf("%s.%s", - NetworkUIData::kKeyProperties, - property_key), - property_dict); - } - - static void CheckProperty(const DictionaryValue* dict, - const char* property_key, - const char* controller, - base::Value* default_value) { - scoped_ptr<base::Value> scoped_default_value(default_value); - DictionaryValue* property_dict; - std::string key = base::StringPrintf("%s.%s", - NetworkUIData::kKeyProperties, - property_key); - EXPECT_TRUE(dict->GetDictionary(key, &property_dict)); - ASSERT_TRUE(property_dict); - std::string actual_controller; - EXPECT_TRUE(property_dict->GetString(NetworkPropertyUIData::kKeyController, - &actual_controller)); - EXPECT_EQ(controller, actual_controller); - if (default_value) { - base::Value* actual_value = NULL; - EXPECT_TRUE(property_dict->Get(NetworkPropertyUIData::kKeyDefaultValue, - &actual_value)); - EXPECT_TRUE(base::Value::Equals(default_value, actual_value)); + virtual ~NetworkUIDataTest() {} + + void CheckProperty(const NetworkPropertyUIData& property, + const base::Value* expected_default_value, + bool expected_managed, + bool expected_recommended, + bool expected_editable) { + if (expected_default_value) { + EXPECT_TRUE(base::Value::Equals(expected_default_value, + property.default_value())); + } else { + EXPECT_FALSE(property.default_value()); } + EXPECT_EQ(expected_managed, property.managed()); + EXPECT_EQ(expected_recommended, property.recommended()); + EXPECT_EQ(expected_editable, property.editable()); } - - TestNetwork network_; - - DISALLOW_COPY_AND_ASSIGN(NetworkUIDataTest); }; TEST_F(NetworkUIDataTest, ONCSource) { - network_.ui_data()->SetString(NetworkUIData::kKeyONCSource, "user_import"); + base::DictionaryValue ui_data; + + ui_data.SetString(NetworkUIData::kKeyONCSource, "user_import"); EXPECT_EQ(NetworkUIData::ONC_SOURCE_USER_IMPORT, - NetworkUIData::GetONCSource(&network_)); - EXPECT_FALSE(NetworkUIData::IsManaged(&network_)); + NetworkUIData::GetONCSource(&ui_data)); + EXPECT_FALSE(NetworkUIData::IsManaged(&ui_data)); - network_.ui_data()->SetString(NetworkUIData::kKeyONCSource, "device_policy"); + ui_data.SetString(NetworkUIData::kKeyONCSource, "device_policy"); EXPECT_EQ(NetworkUIData::ONC_SOURCE_DEVICE_POLICY, - NetworkUIData::GetONCSource(&network_)); - EXPECT_TRUE(NetworkUIData::IsManaged(&network_)); + NetworkUIData::GetONCSource(&ui_data)); + EXPECT_TRUE(NetworkUIData::IsManaged(&ui_data)); - network_.ui_data()->SetString(NetworkUIData::kKeyONCSource, "user_policy"); + ui_data.SetString(NetworkUIData::kKeyONCSource, "user_policy"); EXPECT_EQ(NetworkUIData::ONC_SOURCE_USER_POLICY, - NetworkUIData::GetONCSource(&network_)); - EXPECT_TRUE(NetworkUIData::IsManaged(&network_)); + NetworkUIData::GetONCSource(&ui_data)); + EXPECT_TRUE(NetworkUIData::IsManaged(&ui_data)); } -TEST_F(NetworkUIDataTest, ReadProperties) { - SetProperty(network_.ui_data(), NetworkUIData::kPropertyAutoConnect, - "policy", NULL); - SetProperty(network_.ui_data(), NetworkUIData::kPropertyPreferred, - "user", Value::CreateBooleanValue(true)); - SetProperty(network_.ui_data(), NetworkUIData::kPropertyPassphrase, - NULL, Value::CreateIntegerValue(42)); - - NetworkPropertyUIData property_ui_data(&network_, - NetworkUIData::kPropertyAutoConnect); - EXPECT_TRUE(property_ui_data.managed()); - EXPECT_FALSE(property_ui_data.recommended()); - EXPECT_FALSE(property_ui_data.editable()); - EXPECT_FALSE(property_ui_data.default_value()); - - property_ui_data.UpdateFromNetwork(&network_, - NetworkUIData::kPropertyPreferred); - EXPECT_FALSE(property_ui_data.managed()); - EXPECT_TRUE(property_ui_data.recommended()); - EXPECT_TRUE(property_ui_data.editable()); - base::FundamentalValue expected_preferred(true); - EXPECT_TRUE(base::Value::Equals(&expected_preferred, - property_ui_data.default_value())); - - property_ui_data.UpdateFromNetwork(&network_, - NetworkUIData::kPropertyPassphrase); - EXPECT_FALSE(property_ui_data.managed()); - EXPECT_TRUE(property_ui_data.recommended()); - EXPECT_TRUE(property_ui_data.editable()); - base::FundamentalValue expected_passphrase(42); - EXPECT_TRUE(base::Value::Equals(&expected_passphrase, - property_ui_data.default_value())); - - property_ui_data.UpdateFromNetwork(&network_, - NetworkUIData::kPropertySaveCredentials); - EXPECT_FALSE(property_ui_data.managed()); - EXPECT_FALSE(property_ui_data.recommended()); - EXPECT_TRUE(property_ui_data.editable()); - EXPECT_FALSE(property_ui_data.default_value()); +TEST_F(NetworkUIDataTest, PropertyInit) { + NetworkPropertyUIData empty_prop; + CheckProperty(empty_prop, NULL, false, false, true); + + NetworkPropertyUIData null_prop(NULL); + CheckProperty(null_prop, NULL, false, false, true); + + base::DictionaryValue empty_dict; + NetworkPropertyUIData empty_dict_prop(&empty_dict); + CheckProperty(empty_dict_prop, NULL, false, false, true); + } -TEST_F(NetworkUIDataTest, WriteProperties) { +TEST_F(NetworkUIDataTest, ParseOncProperty) { + base::DictionaryValue ui_data; NetworkUIData ui_data_builder; + + base::DictionaryValue onc; + + base::StringValue val_a("a"); + base::StringValue val_b("b"); + base::StringValue val_a_a("a_a"); + base::StringValue val_a_b("a_b"); + + onc.Set("a", val_a.DeepCopy()); + onc.Set("b", val_b.DeepCopy()); + onc.Set("a.a", val_a_a.DeepCopy()); + onc.Set("a.b", val_a_b.DeepCopy()); + base::ListValue recommended; + recommended.Append(base::Value::CreateStringValue("b")); + recommended.Append(base::Value::CreateStringValue("c")); + recommended.Append(base::Value::CreateStringValue("a.a")); + onc.Set("Recommended", recommended.DeepCopy()); + onc.Set("a.Recommended", recommended.DeepCopy()); + + NetworkPropertyUIData prop; + + ui_data_builder.set_onc_source(NetworkUIData::ONC_SOURCE_USER_IMPORT); + ui_data_builder.FillDictionary(&ui_data); + + prop.ParseOncProperty(NULL, &onc, "a"); + CheckProperty(prop, NULL, false, false, true); + + prop.ParseOncProperty(&ui_data, &onc, "a"); + CheckProperty(prop, NULL, false, false, true); + + prop.ParseOncProperty(&ui_data, &onc, "a.b"); + CheckProperty(prop, NULL, false, false, true); + + prop.ParseOncProperty(&ui_data, &onc, "c"); + CheckProperty(prop, NULL, false, false, true); + ui_data_builder.set_onc_source(NetworkUIData::ONC_SOURCE_USER_POLICY); - NetworkPropertyUIData auto_connect_ui_data( - NetworkPropertyUIData::CONTROLLER_USER, - base::Value::CreateBooleanValue(true)); - ui_data_builder.SetProperty(NetworkUIData::kPropertyAutoConnect, - auto_connect_ui_data); - NetworkPropertyUIData preferred_ui_data( - NetworkPropertyUIData::CONTROLLER_POLICY, - base::Value::CreateBooleanValue(42)); - ui_data_builder.SetProperty(NetworkUIData::kPropertyPreferred, - preferred_ui_data); - NetworkPropertyUIData passphrase_ui_data( - NetworkPropertyUIData::CONTROLLER_USER, NULL); - ui_data_builder.SetProperty(NetworkUIData::kPropertyPassphrase, - passphrase_ui_data); - - DictionaryValue dict; - ui_data_builder.FillDictionary(&dict); - - std::string onc_source; - EXPECT_TRUE(dict.GetString(NetworkUIData::kKeyONCSource, &onc_source)); - EXPECT_EQ("user_policy", onc_source); - CheckProperty(&dict, NetworkUIData::kPropertyAutoConnect, - "user", base::Value::CreateBooleanValue(true)); - CheckProperty(&dict, NetworkUIData::kPropertyPreferred, - "policy", base::Value::CreateBooleanValue(42)); - CheckProperty(&dict, NetworkUIData::kPropertyPassphrase, - "user", NULL); + ui_data_builder.FillDictionary(&ui_data); + + prop.ParseOncProperty(&ui_data, &onc, "a"); + CheckProperty(prop, NULL, true, false, false); + + prop.ParseOncProperty(&ui_data, &onc, "b"); + CheckProperty(prop, &val_b, false, true, true); + + prop.ParseOncProperty(&ui_data, &onc, "c"); + CheckProperty(prop, NULL, false, false, true); + + prop.ParseOncProperty(&ui_data, &onc, "d"); + CheckProperty(prop, NULL, true, false, false); + + prop.ParseOncProperty(&ui_data, &onc, "a.a"); + CheckProperty(prop, NULL, true, false, false); + + prop.ParseOncProperty(&ui_data, &onc, "a.b"); + CheckProperty(prop, &val_a_b, false, true, true); + + prop.ParseOncProperty(&ui_data, &onc, "a.c"); + CheckProperty(prop, NULL, false, false, true); + + prop.ParseOncProperty(&ui_data, &onc, "a.d"); + CheckProperty(prop, NULL, true, false, false); + + prop.ParseOncProperty(&ui_data, NULL, "a.e"); + CheckProperty(prop, NULL, true, false, false); } } // namespace chromeos diff --git a/chrome/browser/chromeos/cros/onc_constants.cc b/chrome/browser/chromeos/cros/onc_constants.cc new file mode 100644 index 0000000..27eb527 --- /dev/null +++ b/chrome/browser/chromeos/cros/onc_constants.cc @@ -0,0 +1,85 @@ +// Copyright (c) 2011 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/cros/onc_constants.h" + +namespace chromeos { + +// Constants for ONC properties. +namespace onc { + +const char kGUID[] = "GUID"; +const char kName[] = "Name"; +const char kRemove[] = "Remove"; +const char kType[] = "Type"; +const char kVPN[] = "VPN"; +const char kWiFi[] = "WiFi"; + +namespace wifi { +const char kAutoConnect[] = "AutoConnect"; +const char kEAP[] = "EAP"; +const char kHiddenSSID[] = "HiddenSSID"; +const char kPassphrase[] = "Passphrase"; +const char kProxyURL[] = "ProxyURL"; +const char kSSID[] = "SSID"; +const char kSecurity[] = "Security"; +} // namespace wifi + +namespace eap { +const char kAnonymousIdentity[] = "AnonymousIdentity"; +const char kClientCertPattern[] = "ClientCertPattern"; +const char kClientCertRef[] = "ClientCertRef"; +const char kClientCertType[] = "ClientCertType"; +const char kIdentity[] = "Identity"; +const char kInner[] = "Inner"; +const char kOuter[] = "Outer"; +const char kPassword[] = "Password"; +const char kSaveCredentials[] = "SaveCredentials"; +const char kServerCARef[] = "ServerCARef"; +const char kUseSystemCAs[] = "UseSystemCAs"; +} // namespace eap + +namespace vpn { +const char kAuthNoCache[] = "AuthNoCache"; +const char kAuthRetry[] = "AuthRetry"; +const char kAuth[] = "Auth"; +const char kAuthenticationType[] = "AuthenticationType"; +const char kCipher[] = "Cipher"; +const char kClientCertPattern[] = "ClientCertPattern"; +const char kClientCertRef[] = "ClientCertRef"; +const char kClientCertType[] = "ClientCertType"; +const char kCompLZO[] = "CompLZO"; +const char kCompNoAdapt[] = "CompNoAdapt"; +const char kGroup[] = "Group"; +const char kHost[] = "Host"; +const char kIKEVersion[] = "IKEVersion"; +const char kIPsec[] = "IPsec"; +const char kKeyDirection[] = "KeyDirection"; +const char kL2TP[] = "L2TP"; +const char kNsCertType[] = "NsCertType"; +const char kOpenVPN[] = "OpenVPN"; +const char kPSK[] = "PSK"; +const char kPassword[] = "Password"; +const char kPort[] = "Port"; +const char kProto[] = "Proto"; +const char kPushPeerInfo[] = "PushPeerInfo"; +const char kRemoteCertEKU[] = "RemoteCertEKU"; +const char kRemoteCertKU[] = "RemoteCertKU"; +const char kRemoteCertTLS[] = "RemoteCertTLS"; +const char kRenegSec[] = "RenegSec"; +const char kSaveCredentials[] = "SaveCredentials"; +const char kServerCARef[] = "ServerCARef"; +const char kServerCertRef[] = "ServerCertRef"; +const char kServerPollTimeout[] = "ServerPollTimeout"; +const char kShaper[] = "Shaper"; +const char kStaticChallenge[] = "StaticChallenge"; +const char kTLSAuthContents[] = "TLSAuthContents"; +const char kTLSRemote[] = "TLSRemote"; +const char kType[] = "Type"; +const char kUsername[] = "Username"; +} // namespace vpn + +} // namespace onc + +} // namespace chromeos diff --git a/chrome/browser/chromeos/cros/onc_constants.h b/chrome/browser/chromeos/cros/onc_constants.h new file mode 100644 index 0000000..c9fb2cb --- /dev/null +++ b/chrome/browser/chromeos/cros/onc_constants.h @@ -0,0 +1,178 @@ +// Copyright (c) 2011 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_CROS_ONC_CONSTANTS_H_ +#define CHROME_BROWSER_CHROMEOS_CROS_ONC_CONSTANTS_H_ +#pragma once + +namespace chromeos { + +// Constants for ONC properties. +namespace onc { + +extern const char kGUID[]; +extern const char kName[]; +extern const char kRemove[]; +extern const char kType[]; +extern const char kVPN[]; +extern const char kWiFi[]; + +namespace wifi { +extern const char kAutoConnect[]; +extern const char kEAP[]; +extern const char kHiddenSSID[]; +extern const char kPassphrase[]; +extern const char kProxyURL[]; +extern const char kSSID[]; +extern const char kSecurity[]; +} // namespace wifi + +namespace eap { +extern const char kAnonymousIdentity[]; +extern const char kClientCertPattern[]; +extern const char kClientCertRef[]; +extern const char kClientCertType[]; +extern const char kIdentity[]; +extern const char kInner[]; +extern const char kOuter[]; +extern const char kPassword[]; +extern const char kSaveCredentials[]; +extern const char kServerCARef[]; +extern const char kUseSystemCAs[]; +} // namespace eap + +namespace vpn { +extern const char kAuthNoCache[]; +extern const char kAuthRetry[]; +extern const char kAuth[]; +extern const char kAuthenticationType[]; +extern const char kCipher[]; +extern const char kClientCertPattern[]; +extern const char kClientCertRef[]; +extern const char kClientCertType[]; +extern const char kCompLZO[]; +extern const char kCompNoAdapt[]; +extern const char kGroup[]; +extern const char kHost[]; +extern const char kIKEVersion[]; +extern const char kIPsec[]; +extern const char kKeyDirection[]; +extern const char kL2TP[]; +extern const char kNsCertType[]; +extern const char kOpenVPN[]; +extern const char kPSK[]; +extern const char kPassword[]; +extern const char kPort[]; +extern const char kProto[]; +extern const char kPushPeerInfo[]; +extern const char kRemoteCertEKU[]; +extern const char kRemoteCertKU[]; +extern const char kRemoteCertTLS[]; +extern const char kRenegSec[]; +extern const char kSaveCredentials[]; +extern const char kServerCARef[]; +extern const char kServerCertRef[]; +extern const char kServerPollTimeout[]; +extern const char kShaper[]; +extern const char kStaticChallenge[]; +extern const char kTLSAuthContents[]; +extern const char kTLSRemote[]; +extern const char kType[]; +extern const char kUsername[]; +} // namespace vpn + +} // namespace onc + +} // namespace chromeos + +#endif // CHROME_BROWSER_CHROMEOS_CROS_ONC_CONSTANTS_H_ +// Copyright (c) 2011 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_CROS_ONC_CONSTANTS_H_ +#define CHROME_BROWSER_CHROMEOS_CROS_ONC_CONSTANTS_H_ +#pragma once + +namespace chromeos { + +// Constants for ONC properties. +namespace onc { + +extern const char kGUID[]; +extern const char kName[]; +extern const char kRemove[]; +extern const char kType[]; +extern const char kVPN[]; +extern const char kWiFi[]; + +namespace wifi { +extern const char kAutoConnect[]; +extern const char kEAP[]; +extern const char kHiddenSSID[]; +extern const char kPassphrase[]; +extern const char kProxyURL[]; +extern const char kSSID[]; +extern const char kSecurity[]; +} // namespace wifi + +namespace eap { +extern const char kAnonymousIdentity[]; +extern const char kClientCertPattern[]; +extern const char kClientCertRef[]; +extern const char kClientCertType[]; +extern const char kIdentity[]; +extern const char kInner[]; +extern const char kOuter[]; +extern const char kPassword[]; +extern const char kSaveCredentials[]; +extern const char kServerCARef[]; +extern const char kUseSystemCAs[]; +} // namespace eap + +namespace vpn { +extern const char kAuthNoCache[]; +extern const char kAuthRetry[]; +extern const char kAuth[]; +extern const char kAuthenticationType[]; +extern const char kCipher[]; +extern const char kClientCertPattern[]; +extern const char kClientCertRef[]; +extern const char kClientCertType[]; +extern const char kCompLZO[]; +extern const char kCompNoAdapt[]; +extern const char kGroup[]; +extern const char kHost[]; +extern const char kIKEVersion[]; +extern const char kIPsec[]; +extern const char kKeyDirection[]; +extern const char kL2TP[]; +extern const char kNsCertType[]; +extern const char kOpenVPN[]; +extern const char kPSK[]; +extern const char kPassword[]; +extern const char kPort[]; +extern const char kProto[]; +extern const char kPushPeerInfo[]; +extern const char kRemoteCertEKU[]; +extern const char kRemoteCertKU[]; +extern const char kRemoteCertTLS[]; +extern const char kRenegSec[]; +extern const char kSaveCredentials[]; +extern const char kServerCARef[]; +extern const char kServerCertRef[]; +extern const char kServerPollTimeout[]; +extern const char kShaper[]; +extern const char kStaticChallenge[]; +extern const char kTLSAuthContents[]; +extern const char kTLSRemote[]; +extern const char kType[]; +extern const char kUsername[]; +} // namespace vpn + +} // namespace onc + +} // namespace chromeos + +#endif // CHROME_BROWSER_CHROMEOS_CROS_ONC_CONSTANTS_H_ diff --git a/chrome/browser/chromeos/cros/onc_network_parser.cc b/chrome/browser/chromeos/cros/onc_network_parser.cc index b50dbed..69ba0da 100644 --- a/chrome/browser/chromeos/cros/onc_network_parser.cc +++ b/chrome/browser/chromeos/cros/onc_network_parser.cc @@ -15,6 +15,7 @@ #include "chrome/browser/chromeos/cros/native_network_constants.h" #include "chrome/browser/chromeos/cros/native_network_parser.h" #include "chrome/browser/chromeos/cros/network_library.h" +#include "chrome/browser/chromeos/cros/onc_constants.h" #include "chrome/common/net/x509_certificate_model.h" #include "grit/generated_resources.h" #include "net/base/cert_database.h" @@ -42,106 +43,117 @@ EnumMapper<PropertyIndex>::Pair network_configuration_table[] = { OncValueSignature network_configuration_signature[] = { // TODO(crosbug.com/23673): Support Ethernet settings. - { "GUID", PROPERTY_INDEX_GUID, TYPE_STRING }, - { "Name", PROPERTY_INDEX_NAME, TYPE_STRING }, + { onc::kGUID, PROPERTY_INDEX_GUID, TYPE_STRING }, + { onc::kName, PROPERTY_INDEX_NAME, TYPE_STRING }, // TODO(crosbug.com/23674): Support ProxySettings. // TODO(crosbug.com/23604): Handle removing networks. - { "Remove", PROPERTY_INDEX_ONC_REMOVE, TYPE_BOOLEAN }, - { "Type", PROPERTY_INDEX_TYPE, TYPE_STRING }, - { "WiFi", PROPERTY_INDEX_ONC_WIFI, TYPE_DICTIONARY }, - { "VPN", PROPERTY_INDEX_ONC_VPN, TYPE_DICTIONARY }, + { onc::kRemove, PROPERTY_INDEX_ONC_REMOVE, TYPE_BOOLEAN }, + { onc::kType, PROPERTY_INDEX_TYPE, TYPE_STRING }, + { onc::kWiFi, PROPERTY_INDEX_ONC_WIFI, TYPE_DICTIONARY }, + { onc::kVPN, PROPERTY_INDEX_ONC_VPN, TYPE_DICTIONARY }, { NULL } }; OncValueSignature wifi_signature[] = { - { "AutoConnect", PROPERTY_INDEX_AUTO_CONNECT, TYPE_BOOLEAN }, - { "EAP", PROPERTY_INDEX_EAP, TYPE_DICTIONARY }, - { "HiddenSSID", PROPERTY_INDEX_HIDDEN_SSID, TYPE_BOOLEAN }, - { "Passphrase", PROPERTY_INDEX_PASSPHRASE, TYPE_STRING }, - { "ProxyURL", PROPERTY_INDEX_PROXY_CONFIG, TYPE_STRING }, - { "Security", PROPERTY_INDEX_SECURITY, TYPE_STRING }, - { "SSID", PROPERTY_INDEX_SSID, TYPE_STRING }, + { onc::wifi::kAutoConnect, PROPERTY_INDEX_AUTO_CONNECT, TYPE_BOOLEAN }, + { onc::wifi::kEAP, PROPERTY_INDEX_EAP, TYPE_DICTIONARY }, + { onc::wifi::kHiddenSSID, PROPERTY_INDEX_HIDDEN_SSID, TYPE_BOOLEAN }, + { onc::wifi::kPassphrase, PROPERTY_INDEX_PASSPHRASE, TYPE_STRING }, + { onc::wifi::kProxyURL, PROPERTY_INDEX_PROXY_CONFIG, TYPE_STRING }, + { onc::wifi::kSecurity, PROPERTY_INDEX_SECURITY, TYPE_STRING }, + { onc::wifi::kSSID, PROPERTY_INDEX_SSID, TYPE_STRING }, { NULL } }; OncValueSignature eap_signature[] = { - { "AnonymousIdentity", PROPERTY_INDEX_EAP_ANONYMOUS_IDENTITY, TYPE_STRING }, - { "ClientCertPattern", PROPERTY_INDEX_ONC_CLIENT_CERT_PATTERN, + { onc::eap::kAnonymousIdentity, PROPERTY_INDEX_EAP_ANONYMOUS_IDENTITY, + TYPE_STRING }, + { onc::eap::kClientCertPattern, PROPERTY_INDEX_ONC_CLIENT_CERT_PATTERN, TYPE_DICTIONARY }, - { "ClientCertRef", PROPERTY_INDEX_ONC_CLIENT_CERT_REF, TYPE_STRING }, - { "ClientCertType", PROPERTY_INDEX_ONC_CLIENT_CERT_TYPE, TYPE_STRING }, - { "Identity", PROPERTY_INDEX_EAP_IDENTITY, TYPE_STRING }, - { "Inner", PROPERTY_INDEX_EAP_PHASE_2_AUTH, TYPE_STRING }, - { "Outer", PROPERTY_INDEX_EAP_METHOD, TYPE_STRING }, - { "Password", PROPERTY_INDEX_EAP_PASSWORD, TYPE_STRING }, - { "ServerCARef", PROPERTY_INDEX_EAP_CA_CERT, TYPE_STRING }, - { "UseSystemCAs", PROPERTY_INDEX_EAP_USE_SYSTEM_CAS, TYPE_BOOLEAN }, + { onc::eap::kClientCertRef, PROPERTY_INDEX_ONC_CLIENT_CERT_REF, TYPE_STRING }, + { onc::eap::kClientCertType, PROPERTY_INDEX_ONC_CLIENT_CERT_TYPE, + TYPE_STRING }, + { onc::eap::kIdentity, PROPERTY_INDEX_EAP_IDENTITY, TYPE_STRING }, + { onc::eap::kInner, PROPERTY_INDEX_EAP_PHASE_2_AUTH, TYPE_STRING }, + { onc::eap::kOuter, PROPERTY_INDEX_EAP_METHOD, TYPE_STRING }, + { onc::eap::kPassword, PROPERTY_INDEX_EAP_PASSWORD, TYPE_STRING }, + { onc::eap::kServerCARef, PROPERTY_INDEX_EAP_CA_CERT, TYPE_STRING }, + { onc::eap::kUseSystemCAs, PROPERTY_INDEX_EAP_USE_SYSTEM_CAS, TYPE_BOOLEAN }, + { onc::eap::kSaveCredentials, PROPERTY_INDEX_SAVE_CREDENTIALS, TYPE_BOOLEAN }, { NULL } }; OncValueSignature vpn_signature[] = { - { "Host", PROPERTY_INDEX_PROVIDER_HOST, TYPE_STRING }, - { "IPsec", PROPERTY_INDEX_ONC_IPSEC, TYPE_DICTIONARY }, - { "L2TP", PROPERTY_INDEX_ONC_L2TP, TYPE_DICTIONARY }, - { "OpenVPN", PROPERTY_INDEX_ONC_OPENVPN, TYPE_DICTIONARY }, - { "Type", PROPERTY_INDEX_PROVIDER_TYPE, TYPE_STRING }, + { onc::vpn::kHost, PROPERTY_INDEX_PROVIDER_HOST, TYPE_STRING }, + { onc::vpn::kIPsec, PROPERTY_INDEX_ONC_IPSEC, TYPE_DICTIONARY }, + { onc::vpn::kL2TP, PROPERTY_INDEX_ONC_L2TP, TYPE_DICTIONARY }, + { onc::vpn::kOpenVPN, PROPERTY_INDEX_ONC_OPENVPN, TYPE_DICTIONARY }, + { onc::vpn::kType, PROPERTY_INDEX_PROVIDER_TYPE, TYPE_STRING }, { NULL } }; OncValueSignature ipsec_signature[] = { - { "AuthenticationType", PROPERTY_INDEX_IPSEC_AUTHENTICATIONTYPE, + { onc::vpn::kAuthenticationType, PROPERTY_INDEX_IPSEC_AUTHENTICATIONTYPE, TYPE_STRING }, - { "Group", PROPERTY_INDEX_L2TPIPSEC_GROUP_NAME, TYPE_STRING }, - { "IKEVersion", PROPERTY_INDEX_IPSEC_IKEVERSION, TYPE_INTEGER }, - { "ClientCertPattern", PROPERTY_INDEX_ONC_CLIENT_CERT_PATTERN, + { onc::vpn::kGroup, PROPERTY_INDEX_L2TPIPSEC_GROUP_NAME, TYPE_STRING }, + { onc::vpn::kIKEVersion, PROPERTY_INDEX_IPSEC_IKEVERSION, TYPE_INTEGER }, + { onc::vpn::kClientCertPattern, PROPERTY_INDEX_ONC_CLIENT_CERT_PATTERN, TYPE_DICTIONARY }, - { "ClientCertRef", PROPERTY_INDEX_ONC_CLIENT_CERT_REF, TYPE_STRING }, - { "ClientCertType", PROPERTY_INDEX_ONC_CLIENT_CERT_TYPE, TYPE_STRING }, + { onc::vpn::kClientCertRef, PROPERTY_INDEX_ONC_CLIENT_CERT_REF, TYPE_STRING }, + { onc::vpn::kClientCertType, PROPERTY_INDEX_ONC_CLIENT_CERT_TYPE, + TYPE_STRING }, // Note: EAP and XAUTH not yet supported. - { "PSK", PROPERTY_INDEX_L2TPIPSEC_PSK, TYPE_STRING }, - { "SaveCredentials", PROPERTY_INDEX_SAVE_CREDENTIALS, TYPE_BOOLEAN }, - { "ServerCARef", PROPERTY_INDEX_L2TPIPSEC_CA_CERT_NSS, TYPE_STRING }, + { onc::vpn::kPSK, PROPERTY_INDEX_L2TPIPSEC_PSK, TYPE_STRING }, + { onc::vpn::kSaveCredentials, PROPERTY_INDEX_SAVE_CREDENTIALS, TYPE_BOOLEAN }, + { onc::vpn::kServerCARef, PROPERTY_INDEX_L2TPIPSEC_CA_CERT_NSS, TYPE_STRING }, { NULL } }; OncValueSignature l2tp_signature[] = { - { "Password", PROPERTY_INDEX_L2TPIPSEC_PASSWORD, TYPE_STRING }, - { "SaveCredentials", PROPERTY_INDEX_SAVE_CREDENTIALS, TYPE_BOOLEAN }, - { "Username", PROPERTY_INDEX_L2TPIPSEC_USER, TYPE_STRING }, + { onc::vpn::kPassword, PROPERTY_INDEX_L2TPIPSEC_PASSWORD, TYPE_STRING }, + { onc::vpn::kSaveCredentials, PROPERTY_INDEX_SAVE_CREDENTIALS, TYPE_BOOLEAN }, + { onc::vpn::kUsername, PROPERTY_INDEX_L2TPIPSEC_USER, TYPE_STRING }, { NULL } }; OncValueSignature openvpn_signature[] = { - { "Auth", PROPERTY_INDEX_OPEN_VPN_AUTH, TYPE_STRING }, - { "AuthRetry", PROPERTY_INDEX_OPEN_VPN_AUTHRETRY, TYPE_STRING }, - { "AuthNoCache", PROPERTY_INDEX_OPEN_VPN_AUTHNOCACHE, TYPE_BOOLEAN }, - { "Cipher", PROPERTY_INDEX_OPEN_VPN_CIPHER, TYPE_STRING }, - { "ClientCertPattern", PROPERTY_INDEX_ONC_CLIENT_CERT_PATTERN, + { onc::vpn::kAuth, PROPERTY_INDEX_OPEN_VPN_AUTH, TYPE_STRING }, + { onc::vpn::kAuthRetry, PROPERTY_INDEX_OPEN_VPN_AUTHRETRY, TYPE_STRING }, + { onc::vpn::kAuthNoCache, PROPERTY_INDEX_OPEN_VPN_AUTHNOCACHE, TYPE_BOOLEAN }, + { onc::vpn::kCipher, PROPERTY_INDEX_OPEN_VPN_CIPHER, TYPE_STRING }, + { onc::vpn::kClientCertPattern, PROPERTY_INDEX_ONC_CLIENT_CERT_PATTERN, TYPE_DICTIONARY }, - { "ClientCertRef", PROPERTY_INDEX_ONC_CLIENT_CERT_REF, TYPE_STRING }, - { "ClientCertType", PROPERTY_INDEX_ONC_CLIENT_CERT_TYPE, TYPE_STRING }, - { "CompLZO", PROPERTY_INDEX_OPEN_VPN_COMPLZO, TYPE_STRING }, - { "CompNoAdapt", PROPERTY_INDEX_OPEN_VPN_COMPNOADAPT, TYPE_BOOLEAN }, - { "KeyDirection", PROPERTY_INDEX_OPEN_VPN_KEYDIRECTION, TYPE_STRING }, - { "NsCertType", PROPERTY_INDEX_OPEN_VPN_NSCERTTYPE, TYPE_STRING }, - { "Password", PROPERTY_INDEX_OPEN_VPN_PASSWORD, TYPE_STRING }, - { "Port", PROPERTY_INDEX_OPEN_VPN_PORT, TYPE_INTEGER }, - { "Proto", PROPERTY_INDEX_OPEN_VPN_PROTO, TYPE_STRING }, - { "PushPeerInfo", PROPERTY_INDEX_OPEN_VPN_PUSHPEERINFO, TYPE_BOOLEAN }, - { "RemoteCertEKU", PROPERTY_INDEX_OPEN_VPN_REMOTECERTEKU, TYPE_STRING }, - { "RemoteCertKU", PROPERTY_INDEX_OPEN_VPN_REMOTECERTKU, TYPE_LIST }, - { "RemoteCertTLS", PROPERTY_INDEX_OPEN_VPN_REMOTECERTTLS, TYPE_STRING }, - { "RenegSec", PROPERTY_INDEX_OPEN_VPN_RENEGSEC, TYPE_INTEGER }, - { "SaveCredentials", PROPERTY_INDEX_SAVE_CREDENTIALS, TYPE_BOOLEAN }, - { "ServerCARef", PROPERTY_INDEX_OPEN_VPN_CACERT, TYPE_STRING }, - { "ServerCertRef", PROPERTY_INDEX_OPEN_VPN_CERT, TYPE_STRING }, - { "ServerPollTimeout", PROPERTY_INDEX_OPEN_VPN_SERVERPOLLTIMEOUT, + { onc::vpn::kClientCertRef, PROPERTY_INDEX_ONC_CLIENT_CERT_REF, TYPE_STRING }, + { onc::vpn::kClientCertType, PROPERTY_INDEX_ONC_CLIENT_CERT_TYPE, + TYPE_STRING }, + { onc::vpn::kCompLZO, PROPERTY_INDEX_OPEN_VPN_COMPLZO, TYPE_STRING }, + { onc::vpn::kCompNoAdapt, PROPERTY_INDEX_OPEN_VPN_COMPNOADAPT, TYPE_BOOLEAN }, + { onc::vpn::kKeyDirection, PROPERTY_INDEX_OPEN_VPN_KEYDIRECTION, + TYPE_STRING }, + { onc::vpn::kNsCertType, PROPERTY_INDEX_OPEN_VPN_NSCERTTYPE, TYPE_STRING }, + { onc::vpn::kPassword, PROPERTY_INDEX_OPEN_VPN_PASSWORD, TYPE_STRING }, + { onc::vpn::kPort, PROPERTY_INDEX_OPEN_VPN_PORT, TYPE_INTEGER }, + { onc::vpn::kProto, PROPERTY_INDEX_OPEN_VPN_PROTO, TYPE_STRING }, + { onc::vpn::kPushPeerInfo, PROPERTY_INDEX_OPEN_VPN_PUSHPEERINFO, + TYPE_BOOLEAN }, + { onc::vpn::kRemoteCertEKU, PROPERTY_INDEX_OPEN_VPN_REMOTECERTEKU, + TYPE_STRING }, + { onc::vpn::kRemoteCertKU, PROPERTY_INDEX_OPEN_VPN_REMOTECERTKU, TYPE_LIST }, + { onc::vpn::kRemoteCertTLS, PROPERTY_INDEX_OPEN_VPN_REMOTECERTTLS, + TYPE_STRING }, + { onc::vpn::kRenegSec, PROPERTY_INDEX_OPEN_VPN_RENEGSEC, TYPE_INTEGER }, + { onc::vpn::kSaveCredentials, PROPERTY_INDEX_SAVE_CREDENTIALS, TYPE_BOOLEAN }, + { onc::vpn::kServerCARef, PROPERTY_INDEX_OPEN_VPN_CACERT, TYPE_STRING }, + { onc::vpn::kServerCertRef, PROPERTY_INDEX_OPEN_VPN_CERT, TYPE_STRING }, + { onc::vpn::kServerPollTimeout, PROPERTY_INDEX_OPEN_VPN_SERVERPOLLTIMEOUT, TYPE_INTEGER }, - { "Shaper", PROPERTY_INDEX_OPEN_VPN_SHAPER, TYPE_INTEGER }, - { "StaticChallenge", PROPERTY_INDEX_OPEN_VPN_STATICCHALLENGE, TYPE_STRING }, - { "TLSAuthContents", PROPERTY_INDEX_OPEN_VPN_TLSAUTHCONTENTS, TYPE_STRING }, - { "TLSRemote", PROPERTY_INDEX_OPEN_VPN_TLSREMOTE, TYPE_STRING }, - { "Username", PROPERTY_INDEX_OPEN_VPN_USER, TYPE_STRING }, + { onc::vpn::kShaper, PROPERTY_INDEX_OPEN_VPN_SHAPER, TYPE_INTEGER }, + { onc::vpn::kStaticChallenge, PROPERTY_INDEX_OPEN_VPN_STATICCHALLENGE, + TYPE_STRING }, + { onc::vpn::kTLSAuthContents, PROPERTY_INDEX_OPEN_VPN_TLSAUTHCONTENTS, + TYPE_STRING }, + { onc::vpn::kTLSRemote, PROPERTY_INDEX_OPEN_VPN_TLSREMOTE, TYPE_STRING }, + { onc::vpn::kUsername, PROPERTY_INDEX_OPEN_VPN_USER, TYPE_STRING }, { NULL } }; @@ -231,20 +243,28 @@ int OncNetworkParser::GetNetworkConfigsSize() const { return network_configs_ ? network_configs_->GetSize() : 0; } -Network* OncNetworkParser::ParseNetwork(int n) { +const base::DictionaryValue* OncNetworkParser::GetNetworkConfig(int n) { CHECK(network_configs_); CHECK(static_cast<size_t>(n) < network_configs_->GetSize()); CHECK_GE(n, 0); - DictionaryValue* info = NULL; + base::DictionaryValue* info = NULL; if (!network_configs_->GetDictionary(n, &info)) { parse_error_ = l10n_util::GetStringUTF8( IDS_NETWORK_CONFIG_ERROR_NETWORK_PROP_DICT_MALFORMED); return NULL; } + return info; +} + +Network* OncNetworkParser::ParseNetwork(int n) { + const base::DictionaryValue* info = GetNetworkConfig(n); + if (!info) + return NULL; + if (VLOG_IS_ON(2)) { std::string network_json; - base::JSONWriter::Write(static_cast<base::Value*>(info), + base::JSONWriter::Write(static_cast<const base::Value*>(info), true, &network_json); VLOG(2) << "Parsing network at index " << n << ": " << network_json; diff --git a/chrome/browser/chromeos/cros/onc_network_parser.h b/chrome/browser/chromeos/cros/onc_network_parser.h index 56eb0c5..7134c14 100644 --- a/chrome/browser/chromeos/cros/onc_network_parser.h +++ b/chrome/browser/chromeos/cros/onc_network_parser.h @@ -60,8 +60,12 @@ class OncNetworkParser : public NetworkParser { // Returns the number of networks in the "NetworkConfigs" list. int GetNetworkConfigsSize() const; + // Returns the network configuration dictionary for the nth network. CHECKs if + // |n| is out of range and returns NULL on parse errors. + const base::DictionaryValue* GetNetworkConfig(int n); + // Call to create the network by parsing network config in the nth position. - // (0-based). Returns NULL if there's a parse error or if n is out of range. + // (0-based). CHECKs if |n| is out of range and returns NULL on parse errors. Network* ParseNetwork(int n); // Returns the number of certificates in the "Certificates" list. diff --git a/chrome/browser/chromeos/options/vpn_config_view.cc b/chrome/browser/chromeos/options/vpn_config_view.cc index 653f861..2cd19c1 100644 --- a/chrome/browser/chromeos/options/vpn_config_view.cc +++ b/chrome/browser/chromeos/options/vpn_config_view.cc @@ -5,8 +5,10 @@ #include "chrome/browser/chromeos/options/vpn_config_view.h" #include "base/string_util.h" +#include "base/stringprintf.h" #include "base/utf_string_conversions.h" #include "chrome/browser/chromeos/cros/cros_library.h" +#include "chrome/browser/chromeos/cros/onc_constants.h" #include "chrome/common/net/x509_certificate_model.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" @@ -370,18 +372,12 @@ const std::string VPNConfigView::GetUserCertID() const { void VPNConfigView::Init(VirtualNetwork* vpn) { if (vpn) { - ca_cert_ui_data_.UpdateFromNetwork( - vpn, NetworkUIData::kPropertyVPNCaCertNss); - psk_passphrase_ui_data_.UpdateFromNetwork( - vpn, NetworkUIData::kPropertyVPNPskPassphrase); - user_cert_ui_data_.UpdateFromNetwork( - vpn, NetworkUIData::kPropertyVPNClientCertId); - username_ui_data_.UpdateFromNetwork( - vpn, NetworkUIData::kPropertyVPNUsername); - user_passphrase_ui_data_.UpdateFromNetwork( - vpn, NetworkUIData::kPropertyVPNUserPassphrase); - group_name_ui_data_.UpdateFromNetwork( - vpn, NetworkUIData::kPropertyVPNGroupName); + ParseVPNUIProperty(&ca_cert_ui_data_, vpn, onc::vpn::kServerCARef); + ParseVPNUIProperty(&psk_passphrase_ui_data_, vpn, onc::vpn::kPSK); + ParseVPNUIProperty(&user_cert_ui_data_, vpn, onc::vpn::kClientCertRef); + ParseVPNUIProperty(&username_ui_data_, vpn, onc::vpn::kUsername); + ParseVPNUIProperty(&user_passphrase_ui_data_, vpn, onc::vpn::kPassword); + ParseVPNUIProperty(&group_name_ui_data_, vpn, onc::vpn::kGroup); } views::GridLayout* layout = views::GridLayout::CreatePanel(this); @@ -788,4 +784,24 @@ const std::string VPNConfigView::GetTextFromField( return result; } +void VPNConfigView::ParseVPNUIProperty(NetworkPropertyUIData* property_ui_data, + Network* network, + const std::string& key) { + NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary(); + const base::DictionaryValue* onc = + network_library->FindOncForNetwork(network->unique_id()); + + base::DictionaryValue* vpn_dict = NULL; + if (!onc || !onc->GetDictionary(onc::kVPN, &vpn_dict)) + return; + + std::string vpn_type; + if (!vpn_dict || !vpn_dict->GetString(onc::kType, &vpn_type)) + return; + + property_ui_data->ParseOncProperty( + network->ui_data(), onc, + base::StringPrintf("%s.%s.%s", onc::kVPN, vpn_type.c_str(), key.c_str())); +} + } // namespace chromeos diff --git a/chrome/browser/chromeos/options/vpn_config_view.h b/chrome/browser/chromeos/options/vpn_config_view.h index d94bade..152b140 100644 --- a/chrome/browser/chromeos/options/vpn_config_view.h +++ b/chrome/browser/chromeos/options/vpn_config_view.h @@ -98,6 +98,12 @@ class VPNConfigView : public ChildNetworkConfigView, const std::string GetServerCACertNssNickname() const; const std::string GetUserCertID() const; + // Parses a VPN UI |property| from the given |network|. |key| is the property + // name within the type-specific VPN subdictionary. + void ParseVPNUIProperty(NetworkPropertyUIData* property_ui_data, + Network* network, + const std::string& key); + CertLibrary* cert_library_; std::string server_hostname_; diff --git a/chrome/browser/chromeos/options/wifi_config_view.cc b/chrome/browser/chromeos/options/wifi_config_view.cc index 4702fdf..988c681 100644 --- a/chrome/browser/chromeos/options/wifi_config_view.cc +++ b/chrome/browser/chromeos/options/wifi_config_view.cc @@ -5,9 +5,11 @@ #include "chrome/browser/chromeos/options/wifi_config_view.h" #include "base/string_util.h" +#include "base/stringprintf.h" #include "base/utf_string_conversions.h" #include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/cros/network_library.h" +#include "chrome/browser/chromeos/cros/onc_constants.h" #include "chrome/browser/chromeos/login/user_manager.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" @@ -749,31 +751,24 @@ void WifiConfigView::Cancel() { // the 802.1x fields. void WifiConfigView::Init(WifiNetwork* wifi, bool show_8021x) { if (wifi) { - eap_method_ui_data_.UpdateFromNetwork( - wifi, NetworkUIData::kPropertyEAPMethod); - phase_2_auth_ui_data_.UpdateFromNetwork( - wifi, NetworkUIData::kPropertyEAPPhase2Auth); - user_cert_ui_data_.UpdateFromNetwork( - wifi, NetworkUIData::kPropertyEAPClientCertPkcs11Id); - server_ca_cert_ui_data_.UpdateFromNetwork( - wifi, NetworkUIData::kPropertyEAPServerCaCertNssNickname); + ParseWiFiEAPUIProperty(&eap_method_ui_data_, wifi, onc::eap::kOuter); + ParseWiFiEAPUIProperty(&phase_2_auth_ui_data_, wifi, onc::eap::kInner); + ParseWiFiEAPUIProperty(&user_cert_ui_data_, wifi, onc::eap::kClientCertRef); + ParseWiFiEAPUIProperty(&server_ca_cert_ui_data_, wifi, + onc::eap::kServerCARef); if (server_ca_cert_ui_data_.managed()) { - server_ca_cert_ui_data_.UpdateFromNetwork( - wifi, NetworkUIData::kPropertyEAPUseSystemCAs); - } - identity_ui_data_.UpdateFromNetwork( - wifi, NetworkUIData::kPropertyEAPIdentity); - identity_anonymous_ui_data_.UpdateFromNetwork( - wifi, NetworkUIData::kPropertyEAPAnonymousIdentity); - save_credentials_ui_data_.UpdateFromNetwork( - wifi, NetworkUIData::kPropertySaveCredentials); - if (show_8021x) { - passphrase_ui_data_.UpdateFromNetwork( - wifi, NetworkUIData::kPropertyEAPPassphrase); - } else { - passphrase_ui_data_.UpdateFromNetwork( - wifi, NetworkUIData::kPropertyPassphrase); + ParseWiFiEAPUIProperty(&server_ca_cert_ui_data_, wifi, + onc::eap::kUseSystemCAs); } + ParseWiFiEAPUIProperty(&identity_ui_data_, wifi, onc::eap::kIdentity); + ParseWiFiEAPUIProperty(&identity_anonymous_ui_data_, wifi, + onc::eap::kAnonymousIdentity); + ParseWiFiEAPUIProperty(&save_credentials_ui_data_, wifi, + onc::eap::kSaveCredentials); + if (show_8021x) + ParseWiFiEAPUIProperty(&passphrase_ui_data_, wifi, onc::eap::kPassword); + else + ParseWiFiUIProperty(&passphrase_ui_data_, wifi, onc::wifi::kPassphrase); } views::GridLayout* layout = views::GridLayout::CreatePanel(this); @@ -1135,4 +1130,24 @@ void WifiConfigView::InitFocus() { passphrase_textfield_->RequestFocus(); } +void WifiConfigView::ParseWiFiUIProperty( + NetworkPropertyUIData* property_ui_data, + Network* network, + const std::string& key) { + NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary(); + property_ui_data->ParseOncProperty( + network->ui_data(), + network_library->FindOncForNetwork(network->unique_id()), + base::StringPrintf("%s.%s", onc::kWiFi, key.c_str())); +} + +void WifiConfigView::ParseWiFiEAPUIProperty( + NetworkPropertyUIData* property_ui_data, + Network* network, + const std::string& key) { + ParseWiFiUIProperty( + property_ui_data, network, + base::StringPrintf("%s.%s", onc::wifi::kEAP, key.c_str())); +} + } // namespace chromeos diff --git a/chrome/browser/chromeos/options/wifi_config_view.h b/chrome/browser/chromeos/options/wifi_config_view.h index 3fcc961..cff3a13 100644 --- a/chrome/browser/chromeos/options/wifi_config_view.h +++ b/chrome/browser/chromeos/options/wifi_config_view.h @@ -107,6 +107,18 @@ class WifiConfigView : public ChildNetworkConfigView, // Updates the error text label. void UpdateErrorLabel(); + // Parses a WiFi UI |property| from the ONC associated with |network|. |key| + // is the property name within the ONC WiFi dictionary. + void ParseWiFiUIProperty(NetworkPropertyUIData* property_ui_data, + Network* network, + const std::string& key); + + // Parses a WiFi EAP UI |property| from the ONC associated with |network|. + // |key| is the property name within the ONC WiFi.EAP dictionary. + void ParseWiFiEAPUIProperty(NetworkPropertyUIData* property_ui_data, + Network* network, + const std::string& key); + CertLibrary* cert_library_; NetworkPropertyUIData eap_method_ui_data_; diff --git a/chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc b/chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc index 949ece1..198eda1 100644 --- a/chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc +++ b/chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc @@ -26,6 +26,7 @@ #include "chrome/browser/chromeos/choose_mobile_network_dialog.h" #include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/cros/network_library.h" +#include "chrome/browser/chromeos/cros/onc_constants.h" #include "chrome/browser/chromeos/cros_settings.h" #include "chrome/browser/chromeos/mobile_config.h" #include "chrome/browser/chromeos/options/network_config_view.h" @@ -172,7 +173,7 @@ NetworkInfoDictionary::NetworkInfoDictionary(const chromeos::Network* network) { set_remembered(false); set_shared(false); set_needs_new_plan(false); - set_policy_managed(chromeos::NetworkUIData::IsManaged(network)); + set_policy_managed(chromeos::NetworkUIData::IsManaged(network->ui_data())); } NetworkInfoDictionary::NetworkInfoDictionary( @@ -189,7 +190,7 @@ NetworkInfoDictionary::NetworkInfoDictionary( set_remembered(true); set_shared(remembered->profile_type() == chromeos::PROFILE_SHARED); set_needs_new_plan(false); - set_policy_managed(chromeos::NetworkUIData::IsManaged(remembered)); + set_policy_managed(chromeos::NetworkUIData::IsManaged(remembered->ui_data())); } DictionaryValue* NetworkInfoDictionary::BuildDictionary() { @@ -866,6 +867,10 @@ void InternetOptionsHandler::PopulateDictionaryDetails( network->service_path()); } + const base::DictionaryValue* ui_data = network->ui_data(); + const base::DictionaryValue* onc = + cros_->FindOncForNetwork(network->unique_id()); + DictionaryValue dictionary; std::string hardware_address; chromeos::NetworkIPConfigVector ipconfigs = cros_->GetIPConfigs( @@ -890,10 +895,10 @@ void InternetOptionsHandler::PopulateDictionaryDetails( ipconfig_static.reset(ipconfig_dict.release()); } - chromeos::NetworkPropertyUIData ipconfig_dhcp_ui_data(network, NULL); + chromeos::NetworkPropertyUIData ipconfig_dhcp_ui_data(ui_data); SetValueDictionary(&dictionary, "ipconfigDHCP", ipconfig_dhcp.release(), ipconfig_dhcp_ui_data); - chromeos::NetworkPropertyUIData ipconfig_static_ui_data(network, NULL); + chromeos::NetworkPropertyUIData ipconfig_static_ui_data(ui_data); SetValueDictionary(&dictionary, "ipconfigStatic", ipconfig_static.release(), ipconfig_static_ui_data); @@ -914,8 +919,7 @@ void InternetOptionsHandler::PopulateDictionaryDetails( dictionary.SetBoolean("showStaticIPConfig", staticIPConfig && (type == chromeos::TYPE_WIFI || type == chromeos::TYPE_ETHERNET)); - chromeos::NetworkPropertyUIData preferred_ui_data( - network, chromeos::NetworkUIData::kPropertyPreferred); + chromeos::NetworkPropertyUIData preferred_ui_data(ui_data); if (network_profile == chromeos::PROFILE_USER) { dictionary.SetBoolean("showPreferred", true); SetValueDictionary(&dictionary, "preferred", @@ -927,8 +931,13 @@ void InternetOptionsHandler::PopulateDictionaryDetails( Value::CreateBooleanValue(network->preferred()), preferred_ui_data); } - chromeos::NetworkPropertyUIData auto_connect_ui_data( - network, chromeos::NetworkUIData::kPropertyAutoConnect); + chromeos::NetworkPropertyUIData auto_connect_ui_data(ui_data); + if (type == chromeos::TYPE_WIFI) + auto_connect_ui_data.ParseOncProperty( + ui_data, onc, + base::StringPrintf("%s.%s", + chromeos::onc::kWiFi, + chromeos::onc::wifi::kAutoConnect)); SetValueDictionary(&dictionary, "autoConnect", Value::CreateBooleanValue(network->auto_connect()), auto_connect_ui_data); @@ -1024,7 +1033,8 @@ void InternetOptionsHandler::PopulateCellularDetails( const chromeos::NetworkDevice* device = cros_->FindNetworkDeviceByPath(cellular->device_path()); if (device) { - chromeos::NetworkPropertyUIData cellular_propety_ui_data(cellular, NULL); + chromeos::NetworkPropertyUIData cellular_propety_ui_data( + cellular->ui_data()); dictionary->SetString("manufacturer", device->manufacturer()); dictionary->SetString("modelId", device->model_id()); dictionary->SetString("firmwareRevision", device->firmware_revision()); diff --git a/chrome/browser/ui/webui/options2/chromeos/internet_options_handler.cc b/chrome/browser/ui/webui/options2/chromeos/internet_options_handler.cc index 7af2d1b..6d47870 100644 --- a/chrome/browser/ui/webui/options2/chromeos/internet_options_handler.cc +++ b/chrome/browser/ui/webui/options2/chromeos/internet_options_handler.cc @@ -26,6 +26,7 @@ #include "chrome/browser/chromeos/choose_mobile_network_dialog.h" #include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/cros/network_library.h" +#include "chrome/browser/chromeos/cros/onc_constants.h" #include "chrome/browser/chromeos/cros_settings.h" #include "chrome/browser/chromeos/mobile_config.h" #include "chrome/browser/chromeos/options/network_config_view.h" @@ -172,7 +173,7 @@ NetworkInfoDictionary::NetworkInfoDictionary(const chromeos::Network* network) { set_remembered(false); set_shared(false); set_needs_new_plan(false); - set_policy_managed(chromeos::NetworkUIData::IsManaged(network)); + set_policy_managed(chromeos::NetworkUIData::IsManaged(network->ui_data())); } NetworkInfoDictionary::NetworkInfoDictionary( @@ -189,8 +190,7 @@ NetworkInfoDictionary::NetworkInfoDictionary( set_remembered(true); set_shared(remembered->profile_type() == chromeos::PROFILE_SHARED); set_needs_new_plan(false); - set_policy_managed( - network ? chromeos::NetworkUIData::IsManaged(network) : false); + set_policy_managed(chromeos::NetworkUIData::IsManaged(remembered->ui_data())); } DictionaryValue* NetworkInfoDictionary::BuildDictionary() { @@ -867,6 +867,10 @@ void InternetOptionsHandler::PopulateDictionaryDetails( network->service_path()); } + const base::DictionaryValue* ui_data = network->ui_data(); + const base::DictionaryValue* onc = + cros_->FindOncForNetwork(network->unique_id()); + DictionaryValue dictionary; std::string hardware_address; chromeos::NetworkIPConfigVector ipconfigs = cros_->GetIPConfigs( @@ -891,10 +895,10 @@ void InternetOptionsHandler::PopulateDictionaryDetails( ipconfig_static.reset(ipconfig_dict.release()); } - chromeos::NetworkPropertyUIData ipconfig_dhcp_ui_data(network, NULL); + chromeos::NetworkPropertyUIData ipconfig_dhcp_ui_data(ui_data); SetValueDictionary(&dictionary, "ipconfigDHCP", ipconfig_dhcp.release(), ipconfig_dhcp_ui_data); - chromeos::NetworkPropertyUIData ipconfig_static_ui_data(network, NULL); + chromeos::NetworkPropertyUIData ipconfig_static_ui_data(ui_data); SetValueDictionary(&dictionary, "ipconfigStatic", ipconfig_static.release(), ipconfig_static_ui_data); @@ -915,8 +919,7 @@ void InternetOptionsHandler::PopulateDictionaryDetails( dictionary.SetBoolean("showStaticIPConfig", staticIPConfig && (type == chromeos::TYPE_WIFI || type == chromeos::TYPE_ETHERNET)); - chromeos::NetworkPropertyUIData preferred_ui_data( - network, chromeos::NetworkUIData::kPropertyPreferred); + chromeos::NetworkPropertyUIData preferred_ui_data(ui_data); if (network_profile == chromeos::PROFILE_USER) { dictionary.SetBoolean("showPreferred", true); SetValueDictionary(&dictionary, "preferred", @@ -928,8 +931,13 @@ void InternetOptionsHandler::PopulateDictionaryDetails( Value::CreateBooleanValue(network->preferred()), preferred_ui_data); } - chromeos::NetworkPropertyUIData auto_connect_ui_data( - network, chromeos::NetworkUIData::kPropertyAutoConnect); + chromeos::NetworkPropertyUIData auto_connect_ui_data(ui_data); + if (type == chromeos::TYPE_WIFI) + auto_connect_ui_data.ParseOncProperty( + ui_data, onc, + base::StringPrintf("%s.%s", + chromeos::onc::kWiFi, + chromeos::onc::wifi::kAutoConnect)); SetValueDictionary(&dictionary, "autoConnect", Value::CreateBooleanValue(network->auto_connect()), auto_connect_ui_data); @@ -1025,7 +1033,8 @@ void InternetOptionsHandler::PopulateCellularDetails( const chromeos::NetworkDevice* device = cros_->FindNetworkDeviceByPath(cellular->device_path()); if (device) { - chromeos::NetworkPropertyUIData cellular_propety_ui_data(cellular, NULL); + chromeos::NetworkPropertyUIData cellular_propety_ui_data( + cellular->ui_data()); dictionary->SetString("manufacturer", device->manufacturer()); dictionary->SetString("modelId", device->model_id()); dictionary->SetString("firmwareRevision", device->firmware_revision()); diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 7e46c902..e12393a 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -433,6 +433,8 @@ 'browser/chromeos/cros/network_parser.h', 'browser/chromeos/cros/network_ui_data.cc', 'browser/chromeos/cros/network_ui_data.h', + 'browser/chromeos/cros/onc_constants.cc', + 'browser/chromeos/cros/onc_constants.h', 'browser/chromeos/cros/onc_network_parser.cc', 'browser/chromeos/cros/onc_network_parser.h', 'browser/chromeos/cros_settings.cc', |