| Index: chrome/browser/chromeos/options/network_connect.cc
|
| diff --git a/chrome/browser/chromeos/options/network_connect.cc b/chrome/browser/chromeos/options/network_connect.cc
|
| index c44822b4950bfb05479b48ef41bf4d84930058bb..25ec368c2274842a688f05db2dd36cb2bc98519f 100644
|
| --- a/chrome/browser/chromeos/options/network_connect.cc
|
| +++ b/chrome/browser/chromeos/options/network_connect.cc
|
| @@ -12,8 +12,8 @@
|
| #include "base/command_line.h"
|
| #include "base/strings/stringprintf.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| -#include "chrome/browser/chromeos/cros/network_library.h"
|
| #include "chrome/browser/chromeos/enrollment_dialog_view.h"
|
| +#include "chrome/browser/chromeos/login/user_manager.h"
|
| #include "chrome/browser/chromeos/options/network_config_view.h"
|
| #include "chrome/browser/profiles/profile_manager.h"
|
| #include "chrome/browser/ui/browser_finder.h"
|
| @@ -21,6 +21,13 @@
|
| #include "chrome/browser/ui/webui/chromeos/mobile_setup_dialog.h"
|
| #include "chrome/common/url_constants.h"
|
| #include "chromeos/chromeos_switches.h"
|
| +#include "chromeos/network/certificate_pattern.h"
|
| +#include "chromeos/network/certificate_pattern_matcher.h"
|
| +#include "chromeos/network/managed_network_configuration_handler.h"
|
| +#include "chromeos/network/network_event_log.h"
|
| +#include "chromeos/network/network_handler.h"
|
| +#include "chromeos/network/network_state.h"
|
| +#include "chromeos/network/network_state_handler.h"
|
| #include "content/public/browser/user_metrics.h"
|
| #include "grit/generated_resources.h"
|
| #include "net/base/escape.h"
|
| @@ -28,84 +35,29 @@
|
| #include "ui/base/l10n/l10n_util.h"
|
|
|
| namespace chromeos {
|
| -namespace network_connect {
|
|
|
| namespace {
|
|
|
| -void DoConnect(Network* network, gfx::NativeWindow parent_window) {
|
| - NetworkLibrary* cros = NetworkLibrary::Get();
|
| - if (network->type() == TYPE_VPN) {
|
| - VirtualNetwork* vpn = static_cast<VirtualNetwork*>(network);
|
| - if (vpn->NeedMoreInfoToConnect()) {
|
| - // Show the connection UI if info for a field is missing.
|
| - NetworkConfigView::Show(vpn, parent_window);
|
| - } else {
|
| - cros->ConnectToVirtualNetwork(vpn);
|
| - // Connection failures are responsible for updating the UI, including
|
| - // reopening dialogs.
|
| - }
|
| - } else if (network->type() == TYPE_WIFI) {
|
| - WifiNetwork* wifi = static_cast<WifiNetwork*>(network);
|
| - if (wifi->IsPassphraseRequired()) {
|
| - // Show the connection UI if we require a passphrase.
|
| - NetworkConfigView::Show(wifi, parent_window);
|
| - } else {
|
| - cros->ConnectToWifiNetwork(wifi);
|
| - // Connection failures are responsible for updating the UI, including
|
| - // reopening dialogs.
|
| - }
|
| - } else if (network->type() == TYPE_WIMAX) {
|
| - WimaxNetwork* wimax = static_cast<WimaxNetwork*>(network);
|
| - if (wimax->passphrase_required()) {
|
| - // Show the connection UI if we require a passphrase.
|
| - NetworkConfigView::Show(wimax, parent_window);
|
| - } else {
|
| - cros->ConnectToWimaxNetwork(wimax);
|
| - // Connection failures are responsible for updating the UI, including
|
| - // reopening dialogs.
|
| - }
|
| - } else if (network->type() == TYPE_CELLULAR) {
|
| - CellularNetwork* cellular = static_cast<CellularNetwork*>(network);
|
| - if (cellular->activation_state() != ACTIVATION_STATE_ACTIVATED ||
|
| - cellular->out_of_credits()) {
|
| - ActivateCellular(cellular->service_path());
|
| - } else {
|
| - cros->ConnectToCellularNetwork(cellular);
|
| - }
|
| - }
|
| +void EnrollmentComplete(const std::string& service_path) {
|
| + NET_LOG_USER("Enrollment Complete", service_path);
|
| }
|
|
|
| -} // namespace
|
| -
|
| -void ActivateCellular(const std::string& service_path) {
|
| - chromeos::NetworkLibrary* cros =
|
| - chromeos::NetworkLibrary::Get();
|
| - if (!cros->CellularDeviceUsesDirectActivation()) {
|
| - // For non direct activation, show the mobile setup dialog which can be
|
| - // used to activate the network.
|
| - ShowMobileSetup(service_path);
|
| - return;
|
| - }
|
| - chromeos::CellularNetwork* cellular =
|
| - cros->FindCellularNetworkByPath(service_path);
|
| - if (!cellular)
|
| - return;
|
| - if (cellular->activation_state() != chromeos::ACTIVATION_STATE_ACTIVATED)
|
| - cellular->StartActivation();
|
| - return;
|
| }
|
|
|
| +namespace network_connect {
|
| +
|
| void ShowMobileSetup(const std::string& service_path) {
|
| - NetworkLibrary* cros = NetworkLibrary::Get();
|
| - const CellularNetwork* cellular =
|
| - cros->FindCellularNetworkByPath(service_path);
|
| - if (cellular && !cellular->activated() &&
|
| - cellular->activate_over_non_cellular_network() &&
|
| - (!cros->connected_network() || !cros->connected_network()->online())) {
|
| - NetworkTechnology technology = cellular->network_technology();
|
| + NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
|
| + const NetworkState* cellular =
|
| + handler->FirstNetworkByType(flimflam::kTypeCellular);
|
| + if (cellular &&
|
| + cellular->activation_state() != flimflam::kActivationStateActivated &&
|
| + cellular->activate_over_non_cellular_networks() &&
|
| + !handler->DefaultNetwork()) {
|
| + std::string technology = cellular->network_technology();
|
| ash::NetworkObserver::NetworkType network_type =
|
| - (technology == chromeos::NETWORK_TECHNOLOGY_LTE ||
|
| - technology == chromeos::NETWORK_TECHNOLOGY_LTE_ADVANCED)
|
| + (technology == flimflam::kNetworkTechnologyLte ||
|
| + technology == flimflam::kNetworkTechnologyLteAdvanced)
|
| ? ash::NetworkObserver::NETWORK_CELLULAR_LTE
|
| : ash::NetworkObserver::NETWORK_CELLULAR;
|
| ash::Shell::GetInstance()->system_tray_notifier()->NotifySetNetworkMessage(
|
| @@ -121,106 +73,93 @@ void ShowMobileSetup(const std::string& service_path) {
|
| MobileSetupDialog::Show(service_path);
|
| }
|
|
|
| -ConnectResult ConnectToNetwork(const std::string& service_path,
|
| - gfx::NativeWindow parent_window) {
|
| - if (CommandLine::ForCurrentProcess()->HasSwitch(
|
| - chromeos::switches::kUseNewNetworkConnectionHandler)) {
|
| - ash::network_connect::ConnectToNetwork(service_path);
|
| - return CONNECT_STARTED;
|
| - }
|
| -
|
| - NetworkLibrary* cros = NetworkLibrary::Get();
|
| - Network* network = cros->FindNetworkByPath(service_path);
|
| - if (!network)
|
| - return NETWORK_NOT_FOUND;
|
| -
|
| - if (network->connecting_or_connected())
|
| - return CONNECT_NOT_STARTED;
|
| -
|
| - if (network->type() == TYPE_ETHERNET)
|
| - return CONNECT_NOT_STARTED; // Normally this shouldn't happen
|
| -
|
| - if (network->type() == TYPE_WIFI || network->type() == TYPE_VPN) {
|
| - network->SetEnrollmentDelegate(chromeos::CreateEnrollmentDelegate(
|
| - parent_window, network->name(), ProfileManager::GetLastUsedProfile()));
|
| - network->AttemptConnection(base::Bind(&DoConnect, network, parent_window));
|
| - return CONNECT_STARTED;
|
| - }
|
| -
|
| - if (network->type() == TYPE_WIMAX) {
|
| - WimaxNetwork* wimax = static_cast<WimaxNetwork*>(network);
|
| - wimax->AttemptConnection(base::Bind(&DoConnect, wimax, parent_window));
|
| - return CONNECT_STARTED;
|
| - }
|
| -
|
| - if (network->type() == TYPE_CELLULAR) {
|
| - CellularNetwork* cellular = static_cast<CellularNetwork*>(network);
|
| - if (cellular->NeedsActivation() || cellular->out_of_credits()) {
|
| - ActivateCellular(service_path);
|
| - return CONNECT_STARTED;
|
| - }
|
| - if (cellular->activation_state() == ACTIVATION_STATE_ACTIVATING)
|
| - return CONNECT_NOT_STARTED;
|
| - cros->ConnectToCellularNetwork(cellular);
|
| - return CONNECT_STARTED;
|
| +void ShowNetworkSettings(const std::string& service_path) {
|
| + std::string page = chrome::kInternetOptionsSubPage;
|
| + const NetworkState* network = service_path.empty() ? NULL :
|
| + NetworkHandler::Get()->network_state_handler()->GetNetworkState(
|
| + service_path);
|
| + if (network) {
|
| + std::string name(network->name());
|
| + if (name.empty() && network->type() == flimflam::kTypeEthernet)
|
| + name = l10n_util::GetStringUTF8(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET);
|
| + page += base::StringPrintf(
|
| + "?servicePath=%s&networkType=%s&networkName=%s",
|
| + net::EscapeUrlEncodedData(service_path, true).c_str(),
|
| + net::EscapeUrlEncodedData(network->type(), true).c_str(),
|
| + net::EscapeUrlEncodedData(name, false).c_str());
|
| }
|
| -
|
| - NOTREACHED();
|
| - return CONNECT_NOT_STARTED;
|
| + content::RecordAction(
|
| + content::UserMetricsAction("OpenInternetOptionsDialog"));
|
| + Browser* browser = chrome::FindOrCreateTabbedBrowser(
|
| + ProfileManager::GetDefaultProfileOrOffTheRecord(),
|
| + chrome::HOST_DESKTOP_TYPE_ASH);
|
| + chrome::ShowSettingsSubPage(browser, page);
|
| }
|
|
|
| void HandleUnconfiguredNetwork(const std::string& service_path,
|
| gfx::NativeWindow parent_window) {
|
| - NetworkLibrary* cros = NetworkLibrary::Get();
|
| - Network* network = cros->FindNetworkByPath(service_path);
|
| + const NetworkState* network = NetworkHandler::Get()->network_state_handler()->
|
| + GetNetworkState(service_path);
|
| if (!network) {
|
| - LOG(WARNING) << "Unknown network: " << service_path;
|
| + NET_LOG_ERROR("Configuring Unknown network", service_path);
|
| return;
|
| }
|
|
|
| - if (network->type() == TYPE_WIFI || network->type() == TYPE_VPN) {
|
| - network->SetEnrollmentDelegate(chromeos::CreateEnrollmentDelegate(
|
| - parent_window, network->name(), ProfileManager::GetLastUsedProfile()));
|
| - // This will connect to the network only if the network just needs to have
|
| - // its certificate configured. Otherwise it will show an enrollment dialog
|
| - // if available, or call NetworkConfigView::Show().
|
| - network->AttemptConnection(
|
| - base::Bind(&NetworkConfigView::Show, network, parent_window));
|
| + if (network->type() == flimflam::kTypeWifi ||
|
| + network->type() == flimflam::kTypeWimax ||
|
| + network->type() == flimflam::kTypeVPN) {
|
| + NetworkConfigView::Show(service_path, parent_window);
|
| return;
|
| }
|
|
|
| - if (network->type() == TYPE_WIMAX) {
|
| - NetworkConfigView::Show(network, parent_window);
|
| - return;
|
| - }
|
| -
|
| - if (network->type() == TYPE_CELLULAR) {
|
| - CellularNetwork* cellular = static_cast<CellularNetwork*>(network);
|
| - if (cellular->NeedsActivation()) {
|
| - ActivateCellular(service_path);
|
| + if (network->type() == flimflam::kTypeCellular) {
|
| + if (network->activation_state() != flimflam::kActivationStateActivated) {
|
| + ash::network_connect::ActivateCellular(service_path);
|
| return;
|
| - } else if (cellular->out_of_credits()) {
|
| + }
|
| + if (network->cellular_out_of_credits()) {
|
| ShowMobileSetup(service_path);
|
| return;
|
| }
|
| }
|
| -
|
| // No special configure or setup for |service_path|, show the settings UI.
|
| - std::string page = chrome::kInternetOptionsSubPage;
|
| - std::string name = network->name();
|
| - if (name.empty() && network->type() == TYPE_ETHERNET)
|
| - name = l10n_util::GetStringUTF8(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET);
|
| - page += base::StringPrintf(
|
| - "?servicePath=%s&networkType=%d&networkName=%s",
|
| - net::EscapeUrlEncodedData(service_path, true).c_str(),
|
| - network->type(),
|
| - net::EscapeUrlEncodedData(name, false).c_str());
|
| - content::RecordAction(
|
| - content::UserMetricsAction("OpenInternetOptionsDialog"));
|
| - Browser* browser = chrome::FindOrCreateTabbedBrowser(
|
| - ProfileManager::GetDefaultProfileOrOffTheRecord(),
|
| - chrome::HOST_DESKTOP_TYPE_ASH);
|
| - chrome::ShowSettingsSubPage(browser, page);
|
| + ShowNetworkSettings(service_path);
|
| +}
|
| +
|
| +bool EnrollNetwork(const std::string& service_path,
|
| + gfx::NativeWindow parent_window) {
|
| + const NetworkState* network = NetworkHandler::Get()->network_state_handler()->
|
| + GetNetworkState(service_path);
|
| + if (!network) {
|
| + NET_LOG_ERROR("Enrolling Unknown network", service_path);
|
| + return false;
|
| + }
|
| + // We skip certificate patterns for device policy ONC so that an unmanaged
|
| + // user can't get to the place where a cert is presented for them
|
| + // involuntarily.
|
| + if (network->ui_data().onc_source() == onc::ONC_SOURCE_DEVICE_POLICY)
|
| + return false;
|
| +
|
| + const CertificatePattern& certificate_pattern =
|
| + network->ui_data().certificate_pattern();
|
| + if (certificate_pattern.Empty())
|
| + return false;
|
| +
|
| + NET_LOG_USER("Enrolling", service_path);
|
| +
|
| + EnrollmentDelegate* enrollment = CreateEnrollmentDelegate(
|
| + parent_window, network->name(), ProfileManager::GetDefaultProfile());
|
| + return enrollment->Enroll(certificate_pattern.enrollment_uri_list(),
|
| + base::Bind(&EnrollmentComplete, service_path));
|
| +}
|
| +
|
| +const base::DictionaryValue* FindPolicyForActiveUser(
|
| + const NetworkState* network,
|
| + onc::ONCSource* onc_source) {
|
| + const User* user = UserManager::Get()->GetActiveUser();
|
| + std::string username_hash = user ? user->username_hash() : std::string();
|
| + return NetworkHandler::Get()->managed_network_configuration_handler()->
|
| + FindPolicyByGUID(username_hash, network->guid(), onc_source);
|
| }
|
|
|
| } // namespace network_connect
|
|
|