| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/dom_ui/mobile_setup_ui.h" | 5 #include "chrome/browser/chromeos/dom_ui/mobile_setup_ui.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
| 11 #include "app/resource_bundle.h" | 11 #include "app/resource_bundle.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
| 14 #include "base/json/json_reader.h" | 14 #include "base/json/json_reader.h" |
| 15 #include "base/json/json_writer.h" | 15 #include "base/json/json_writer.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/string_piece.h" | 17 #include "base/string_piece.h" |
| 18 #include "base/string_util.h" | 18 #include "base/string_util.h" |
| 19 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
| 20 #include "base/values.h" | 20 #include "base/values.h" |
| 21 #include "base/weak_ptr.h" | 21 #include "base/weak_ptr.h" |
| 22 #include "chrome/browser/browser.h" | 22 #include "chrome/browser/browser.h" |
| 23 #include "chrome/browser/browser_list.h" | 23 #include "chrome/browser/browser_list.h" |
| 24 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
| 25 #include "chrome/browser/browser_thread.h" | 25 #include "chrome/browser/browser_thread.h" |
| 26 #include "chrome/browser/chromeos/cros/cros_library.h" | 26 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 27 #include "chrome/browser/chromeos/cros/network_library.h" | 27 #include "chrome/browser/chromeos/cros/network_library.h" |
| 28 #include "chrome/browser/chromeos/cros/system_library.h" | 28 #include "chrome/browser/chromeos/cros/system_library.h" |
| 29 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" | 29 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" |
| 30 #include "chrome/browser/prefs/pref_service.h" |
| 31 #include "chrome/browser/profile.h" |
| 30 #include "chrome/browser/tab_contents/tab_contents.h" | 32 #include "chrome/browser/tab_contents/tab_contents.h" |
| 31 #include "chrome/common/jstemplate_builder.h" | 33 #include "chrome/common/jstemplate_builder.h" |
| 34 #include "chrome/common/pref_names.h" |
| 32 #include "chrome/common/url_constants.h" | 35 #include "chrome/common/url_constants.h" |
| 33 #include "googleurl/src/gurl.h" | 36 #include "googleurl/src/gurl.h" |
| 34 #include "grit/browser_resources.h" | 37 #include "grit/browser_resources.h" |
| 35 #include "grit/chromium_strings.h" | 38 #include "grit/chromium_strings.h" |
| 36 #include "grit/generated_resources.h" | 39 #include "grit/generated_resources.h" |
| 37 #include "grit/locale_settings.h" | 40 #include "grit/locale_settings.h" |
| 38 #include "net/base/ssl_config_service.h" | |
| 39 | 41 |
| 40 namespace { | 42 namespace { |
| 41 | 43 |
| 42 // Host page JS API function names. | 44 // Host page JS API function names. |
| 43 const char kJsApiStartActivation[] = "startActivation"; | 45 const char kJsApiStartActivation[] = "startActivation"; |
| 44 const char kJsApiCloseTab[] = "closeTab"; | 46 const char kJsApiCloseTab[] = "closeTab"; |
| 45 const char kJsApiSetTransactionStatus[] = "setTransactionStatus"; | 47 const char kJsApiSetTransactionStatus[] = "setTransactionStatus"; |
| 46 | 48 |
| 47 const wchar_t kJsDeviceStatusChangedHandler[] = | 49 const wchar_t kJsDeviceStatusChangedHandler[] = |
| 48 L"mobile.MobileSetup.deviceStateChanged"; | 50 L"mobile.MobileSetup.deviceStateChanged"; |
| 49 | 51 |
| 50 // Collular device states that are reported to DOM UI layer. | |
| 51 const char kStateUnknown[] = "unknown"; | |
| 52 const char kStateConnecting[] = "connecting"; | |
| 53 const char kStateError[] = "error"; | |
| 54 const char kStateNeedsPayment[] = "payment"; | |
| 55 const char kStateActivating[] = "activating"; | |
| 56 const char kStateDisconnected[] = "disconnected"; | |
| 57 const char kStateConnected[] = "connected"; | |
| 58 const char kFailedPayment[] = "failed_payment"; | |
| 59 | |
| 60 // Error codes matching codes defined in the cellular config file. | 52 // Error codes matching codes defined in the cellular config file. |
| 61 const char kErrorDefault[] = "default"; | 53 const char kErrorDefault[] = "default"; |
| 62 const char kErrorBadConnectionPartial[] = "bad_connection_partial"; | 54 const char kErrorBadConnectionPartial[] = "bad_connection_partial"; |
| 63 const char kErrorBadConnectionActivated[] = "bad_connection_activated"; | 55 const char kErrorBadConnectionActivated[] = "bad_connection_activated"; |
| 64 const char kErrorRoamingOnConnection[] = "roaming_connection"; | 56 const char kErrorRoamingOnConnection[] = "roaming_connection"; |
| 65 const char kErrorNoEVDO[] = "no_evdo"; | 57 const char kErrorNoEVDO[] = "no_evdo"; |
| 66 const char kErrorRoamingActivation[] = "roaming_activation"; | 58 const char kErrorRoamingActivation[] = "roaming_activation"; |
| 67 const char kErrorRoamingPartiallyActivated[] = "roaming_partially_activated"; | 59 const char kErrorRoamingPartiallyActivated[] = "roaming_partially_activated"; |
| 68 const char kErrorNoService[] = "no_service"; | 60 const char kErrorNoService[] = "no_service"; |
| 69 const char kFailedPaymentError[] = "failed_payment"; | 61 const char kFailedPaymentError[] = "failed_payment"; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 // NetworkLibrary::PropertyObserver implementation. | 144 // NetworkLibrary::PropertyObserver implementation. |
| 153 virtual void PropertyChanged(const char* service_path, | 145 virtual void PropertyChanged(const char* service_path, |
| 154 const char* key, | 146 const char* key, |
| 155 const Value* value); | 147 const Value* value); |
| 156 | 148 |
| 157 private: | 149 private: |
| 158 typedef enum PlanActivationState { | 150 typedef enum PlanActivationState { |
| 159 PLAN_ACTIVATION_PAGE_LOADING = -1, | 151 PLAN_ACTIVATION_PAGE_LOADING = -1, |
| 160 PLAN_ACTIVATION_START = 0, | 152 PLAN_ACTIVATION_START = 0, |
| 161 PLAN_ACTIVATION_INITIATING_ACTIVATION = 1, | 153 PLAN_ACTIVATION_INITIATING_ACTIVATION = 1, |
| 162 PLAN_ACTIVATION_ACTIVATING = 2, | 154 PLAN_ACTIVATION_RECONNECTING = 2, |
| 163 PLAN_ACTIVATION_SHOWING_PAYMENT = 3, | 155 PLAN_ACTIVATION_SHOWING_PAYMENT = 3, |
| 164 PLAN_ACTIVATION_DONE = 4, | 156 PLAN_ACTIVATION_DONE = 4, |
| 165 PLAN_ACTIVATION_ERROR = 5, | 157 PLAN_ACTIVATION_ERROR = 5, |
| 166 } PlanActivationState; | 158 } PlanActivationState; |
| 167 | 159 |
| 168 // Handlers for JS DOMUI messages. | 160 // Handlers for JS DOMUI messages. |
| 169 void HandleStartActivation(const ListValue* args); | 161 void HandleStartActivation(const ListValue* args); |
| 170 void HandleCloseTab(const ListValue* args); | 162 void HandleCloseTab(const ListValue* args); |
| 171 void HandleSetTransactionStatus(const ListValue* args); | 163 void HandleSetTransactionStatus(const ListValue* args); |
| 172 | 164 |
| 173 // Sends message to host registration page with system/user info data. | 165 // Sends message to host registration page with system/user info data. |
| 174 void SendDeviceInfo(); | 166 void SendDeviceInfo(); |
| 175 | 167 |
| 176 // Verify the state of cellular network and modify internal state. | 168 // Verify the state of cellular network and modify internal state. |
| 177 void EvaluateCellularNetwork(const chromeos::CellularNetwork* network); | 169 void EvaluateCellularNetwork(chromeos::CellularNetwork* network); |
| 178 // Check the current cellular network for error conditions. | 170 // Check the current cellular network for error conditions. |
| 179 bool GotActivationError(const chromeos::CellularNetwork* network, | 171 bool GotActivationError(const chromeos::CellularNetwork* network, |
| 180 std::string* error); | 172 std::string* error); |
| 181 void ChangeState(const chromeos::CellularNetwork* network, | 173 void ChangeState(chromeos::CellularNetwork* network, |
| 182 PlanActivationState new_state, | 174 PlanActivationState new_state, |
| 183 const std::string& error_description); | 175 const std::string& error_description); |
| 184 | 176 // Prepares network devices for cellular activation process. |
| 177 void SetupActivationProcess(chromeos::CellularNetwork* network); |
| 178 // Resets network devices after cellular activation process. |
| 179 // |network| should be NULL if the activation process failed. |
| 180 void CompleteActivation(chromeos::CellularNetwork* network); |
| 185 // Control routines for handling other types of connections during | 181 // Control routines for handling other types of connections during |
| 186 // cellular activation. | 182 // cellular activation. |
| 187 void ReEnableOtherConnections(); | 183 void ReEnableOtherConnections(); |
| 188 void DisableOtherConnections(); | |
| 189 | 184 |
| 190 // Converts the currently active CellularNetwork device into a JS object. | 185 // Converts the currently active CellularNetwork device into a JS object. |
| 191 static void GetDeviceInfo(const chromeos::CellularNetwork* network, | 186 static void GetDeviceInfo(const chromeos::CellularNetwork* network, |
| 192 DictionaryValue* value); | 187 DictionaryValue* value); |
| 193 static bool ShouldReportDeviceState(std::string* state, std::string* error); | 188 static bool ShouldReportDeviceState(std::string* state, std::string* error); |
| 194 | 189 |
| 195 // Performs activation state cellular device evaluation. | 190 // Performs activation state cellular device evaluation. |
| 196 // Returns false if device activation failed. In this case |error| | 191 // Returns false if device activation failed. In this case |error| |
| 197 // will contain error message to be reported to DOM UI. | 192 // will contain error message to be reported to DOM UI. |
| 198 static bool EvaluateCellularDeviceState(bool* report_status, | 193 static bool EvaluateCellularDeviceState(bool* report_status, |
| 199 std::string* state, | 194 std::string* state, |
| 200 std::string* error); | 195 std::string* error); |
| 201 | 196 |
| 202 // Return error message for a given code. | 197 // Return error message for a given code. |
| 203 static std::string GetErrorMessage(const std::string& code); | 198 static std::string GetErrorMessage(const std::string& code); |
| 204 static void LoadCellularConfig(); | 199 static void LoadCellularConfig(); |
| 205 | 200 |
| 206 static const char* GetStateDescription(PlanActivationState state); | 201 static const char* GetStateDescription(PlanActivationState state); |
| 207 | 202 |
| 208 static scoped_ptr<CellularConfigDocument> cellular_config_; | 203 static scoped_ptr<CellularConfigDocument> cellular_config_; |
| 209 | 204 |
| 210 TabContents* tab_contents_; | 205 TabContents* tab_contents_; |
| 211 // Internal handler state. | 206 // Internal handler state. |
| 212 PlanActivationState state_; | 207 PlanActivationState state_; |
| 213 std::string service_path_; | 208 std::string service_path_; |
| 214 // Flags that control if wifi and ethernet connection needs to be restored | 209 // Flags that control if wifi and ethernet connection needs to be restored |
| 215 // after the activation of cellular network. | 210 // after the activation of cellular network. |
| 216 bool reenable_wifi_; | 211 bool reenable_wifi_; |
| 217 bool reenable_ethernet_; | 212 bool reenable_ethernet_; |
| 213 bool reenable_cert_check_; |
| 218 DISALLOW_COPY_AND_ASSIGN(MobileSetupHandler); | 214 DISALLOW_COPY_AND_ASSIGN(MobileSetupHandler); |
| 219 }; | 215 }; |
| 220 | 216 |
| 221 scoped_ptr<CellularConfigDocument> MobileSetupHandler::cellular_config_; | 217 scoped_ptr<CellularConfigDocument> MobileSetupHandler::cellular_config_; |
| 222 | 218 |
| 223 //////////////////////////////////////////////////////////////////////////////// | 219 //////////////////////////////////////////////////////////////////////////////// |
| 224 // | 220 // |
| 225 // CellularConfigDocument | 221 // CellularConfigDocument |
| 226 // | 222 // |
| 227 //////////////////////////////////////////////////////////////////////////////// | 223 //////////////////////////////////////////////////////////////////////////////// |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 //////////////////////////////////////////////////////////////////////////////// | 314 //////////////////////////////////////////////////////////////////////////////// |
| 319 // | 315 // |
| 320 // MobileSetupHandler | 316 // MobileSetupHandler |
| 321 // | 317 // |
| 322 //////////////////////////////////////////////////////////////////////////////// | 318 //////////////////////////////////////////////////////////////////////////////// |
| 323 MobileSetupHandler::MobileSetupHandler(const std::string& service_path) | 319 MobileSetupHandler::MobileSetupHandler(const std::string& service_path) |
| 324 : tab_contents_(NULL), | 320 : tab_contents_(NULL), |
| 325 state_(PLAN_ACTIVATION_PAGE_LOADING), | 321 state_(PLAN_ACTIVATION_PAGE_LOADING), |
| 326 service_path_(service_path), | 322 service_path_(service_path), |
| 327 reenable_wifi_(false), | 323 reenable_wifi_(false), |
| 328 reenable_ethernet_(false) { | 324 reenable_ethernet_(false), |
| 325 reenable_cert_check_(false) { |
| 329 } | 326 } |
| 330 | 327 |
| 331 MobileSetupHandler::~MobileSetupHandler() { | 328 MobileSetupHandler::~MobileSetupHandler() { |
| 332 chromeos::NetworkLibrary* lib = | 329 chromeos::NetworkLibrary* lib = |
| 333 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | 330 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); |
| 334 lib->RemoveObserver(this); | 331 lib->RemoveObserver(this); |
| 335 lib->RemoveProperyObserver(this); | 332 lib->RemoveProperyObserver(this); |
| 336 // net::SSLConfigService::AllowRevChecking(); | |
| 337 ReEnableOtherConnections(); | 333 ReEnableOtherConnections(); |
| 338 } | 334 } |
| 339 | 335 |
| 340 DOMMessageHandler* MobileSetupHandler::Attach(DOMUI* dom_ui) { | 336 DOMMessageHandler* MobileSetupHandler::Attach(DOMUI* dom_ui) { |
| 341 return DOMMessageHandler::Attach(dom_ui); | 337 return DOMMessageHandler::Attach(dom_ui); |
| 342 } | 338 } |
| 343 | 339 |
| 344 void MobileSetupHandler::Init(TabContents* contents) { | 340 void MobileSetupHandler::Init(TabContents* contents) { |
| 345 tab_contents_ = contents; | 341 tab_contents_ = contents; |
| 346 LoadCellularConfig(); | 342 LoadCellularConfig(); |
| 343 SetupActivationProcess(GetCellularNetwork(service_path_)); |
| 347 } | 344 } |
| 348 | 345 |
| 349 void MobileSetupHandler::RegisterMessages() { | 346 void MobileSetupHandler::RegisterMessages() { |
| 350 dom_ui_->RegisterMessageCallback(kJsApiStartActivation, | 347 dom_ui_->RegisterMessageCallback(kJsApiStartActivation, |
| 351 NewCallback(this, &MobileSetupHandler::HandleStartActivation)); | 348 NewCallback(this, &MobileSetupHandler::HandleStartActivation)); |
| 352 dom_ui_->RegisterMessageCallback(kJsApiCloseTab, | 349 dom_ui_->RegisterMessageCallback(kJsApiCloseTab, |
| 353 NewCallback(this, &MobileSetupHandler::HandleCloseTab)); | 350 NewCallback(this, &MobileSetupHandler::HandleCloseTab)); |
| 354 dom_ui_->RegisterMessageCallback(kJsApiSetTransactionStatus, | 351 dom_ui_->RegisterMessageCallback(kJsApiSetTransactionStatus, |
| 355 NewCallback(this, &MobileSetupHandler::HandleSetTransactionStatus)); | 352 NewCallback(this, &MobileSetupHandler::HandleSetTransactionStatus)); |
| 356 } | 353 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 return; | 398 return; |
| 402 } | 399 } |
| 403 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> | 400 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> |
| 404 GetNetworkLibrary(); | 401 GetNetworkLibrary(); |
| 405 lib->RemoveObserver(this); | 402 lib->RemoveObserver(this); |
| 406 lib->RemoveProperyObserver(this); | 403 lib->RemoveProperyObserver(this); |
| 407 // Start monitoring network and service property changes. | 404 // Start monitoring network and service property changes. |
| 408 lib->AddObserver(this); | 405 lib->AddObserver(this); |
| 409 lib->AddProperyObserver(network->service_path().c_str(), | 406 lib->AddProperyObserver(network->service_path().c_str(), |
| 410 this); | 407 this); |
| 411 state_ = PLAN_ACTIVATION_START; | 408 ChangeState(network, PLAN_ACTIVATION_START, std::string()); |
| 412 EvaluateCellularNetwork(network); | 409 EvaluateCellularNetwork(network); |
| 413 } | 410 } |
| 414 | 411 |
| 415 void MobileSetupHandler::HandleSetTransactionStatus(const ListValue* args) { | 412 void MobileSetupHandler::HandleSetTransactionStatus(const ListValue* args) { |
| 416 const size_t kSetTransactionStatusParamCount = 1; | 413 const size_t kSetTransactionStatusParamCount = 1; |
| 417 if (args->GetSize() != kSetTransactionStatusParamCount) | 414 if (args->GetSize() != kSetTransactionStatusParamCount) |
| 418 return; | 415 return; |
| 419 | 416 |
| 420 // Get change callback function name. | 417 // Get change callback function name. |
| 421 std::string status; | 418 std::string status; |
| 422 if (!args->GetString(0, &status)) | 419 if (!args->GetString(0, &status)) |
| 423 return; | 420 return; |
| 424 | 421 |
| 425 // The payment is received, try to reconnect and check the status all over | 422 // The payment is received, try to reconnect and check the status all over |
| 426 // again. | 423 // again. |
| 427 if (LowerCaseEqualsASCII(status, "OK")) { | 424 if (LowerCaseEqualsASCII(status, "ok")) { |
| 428 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> | 425 ChangeState(GetCellularNetwork(), PLAN_ACTIVATION_START, std::string()); |
| 429 GetNetworkLibrary(); | 426 EvaluateCellularNetwork(GetCellularNetwork()); |
| 430 ChangeState( | |
| 431 lib->cellular_network(), | |
| 432 PLAN_ACTIVATION_START, std::string()); | |
| 433 } | 427 } |
| 434 } | 428 } |
| 435 | 429 |
| 436 | 430 |
| 437 void MobileSetupHandler::EvaluateCellularNetwork( | 431 void MobileSetupHandler::EvaluateCellularNetwork( |
| 438 const chromeos::CellularNetwork* network) { | 432 chromeos::CellularNetwork* network) { |
| 439 if (!dom_ui_) | 433 if (!dom_ui_) |
| 440 return; | 434 return; |
| 441 | 435 |
| 442 PlanActivationState new_state = state_; | 436 PlanActivationState new_state = state_; |
| 443 if (network) { | 437 if (network) { |
| 444 LOG(INFO) << "Cellular:\n service=" << network->GetStateString().c_str() | 438 LOG(INFO) << "Cellular:\n service=" << network->GetStateString().c_str() |
| 445 << "\n ui=" << GetStateDescription(state_) | 439 << "\n ui=" << GetStateDescription(state_) |
| 446 << "\n activation=" << network->GetActivationStateString().c_str() | 440 << "\n activation=" << network->GetActivationStateString().c_str() |
| 447 << "\n restricted=" << (network->restricted_pool() ? "yes" : "no") | 441 << "\n restricted=" << (network->restricted_pool() ? "yes" : "no") |
| 448 << "\n error=" << network->GetErrorString().c_str() | 442 << "\n error=" << network->GetErrorString().c_str() |
| 449 << "\n setvice_path=" << network->service_path().c_str(); | 443 << "\n setvice_path=" << network->service_path().c_str(); |
| 450 } else { | 444 } else { |
| 451 LOG(WARNING) << "Cellular service lost"; | 445 LOG(WARNING) << "Cellular service lost"; |
| 452 } | 446 } |
| 453 switch (state_) { | 447 switch (state_) { |
| 454 case PLAN_ACTIVATION_START: | 448 case PLAN_ACTIVATION_START: |
| 455 if (network) { | 449 if (network) { |
| 456 switch (network->activation_state()) { | 450 switch (network->activation_state()) { |
| 457 case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED: | |
| 458 case chromeos::ACTIVATION_STATE_ACTIVATED: | 451 case chromeos::ACTIVATION_STATE_ACTIVATED: |
| 459 if (network->failed_or_disconnected()) { | 452 if (network->failed_or_disconnected()) { |
| 460 new_state = PLAN_ACTIVATION_ACTIVATING; | 453 new_state = PLAN_ACTIVATION_RECONNECTING; |
| 461 } else if (network->connection_state() == chromeos::STATE_READY) { | 454 } else if (network->connection_state() == chromeos::STATE_READY) { |
| 462 new_state = network->restricted_pool() ? | 455 if (network->restricted_pool()) { |
| 463 PLAN_ACTIVATION_SHOWING_PAYMENT : PLAN_ACTIVATION_DONE; | 456 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT; |
| 457 } else { |
| 458 new_state = PLAN_ACTIVATION_DONE; |
| 459 } |
| 464 } | 460 } |
| 465 break; | 461 break; |
| 466 case chromeos::ACTIVATION_STATE_UNKNOWN: | 462 case chromeos::ACTIVATION_STATE_UNKNOWN: |
| 467 case chromeos::ACTIVATION_STATE_NOT_ACTIVATED: | 463 case chromeos::ACTIVATION_STATE_NOT_ACTIVATED: |
| 464 case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED: |
| 468 if (network->failed_or_disconnected()) { | 465 if (network->failed_or_disconnected()) { |
| 469 new_state = PLAN_ACTIVATION_INITIATING_ACTIVATION; | 466 new_state = PLAN_ACTIVATION_INITIATING_ACTIVATION; |
| 470 } else if (network->connected()) { | 467 } else if (network->connected()) { |
| 471 LOG(INFO) << "Disconnecting from " << | 468 LOG(INFO) << "Disconnecting from " << |
| 472 network->service_path().c_str(); | 469 network->service_path().c_str(); |
| 473 chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> | 470 chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> |
| 474 DisconnectFromWirelessNetwork(network); | 471 DisconnectFromWirelessNetwork(network); |
| 475 } | 472 } |
| 476 break; | 473 break; |
| 477 default: | 474 default: |
| 478 new_state = PLAN_ACTIVATION_INITIATING_ACTIVATION; | 475 new_state = PLAN_ACTIVATION_INITIATING_ACTIVATION; |
| 479 break; | 476 break; |
| 480 } | 477 } |
| 481 } | 478 } |
| 482 break; | 479 break; |
| 483 case PLAN_ACTIVATION_INITIATING_ACTIVATION: | 480 case PLAN_ACTIVATION_INITIATING_ACTIVATION: |
| 484 if (network) { | 481 if (network) { |
| 485 switch (network->activation_state()) { | 482 switch (network->activation_state()) { |
| 486 case chromeos::ACTIVATION_STATE_ACTIVATED: | 483 case chromeos::ACTIVATION_STATE_ACTIVATED: |
| 487 if (network->failed_or_disconnected()) { | 484 if (network->failed_or_disconnected()) { |
| 488 new_state = PLAN_ACTIVATION_ACTIVATING; | 485 new_state = PLAN_ACTIVATION_RECONNECTING; |
| 489 } else if (network->connection_state() == chromeos::STATE_READY) { | 486 } else if (network->connection_state() == chromeos::STATE_READY) { |
| 490 if (network->restricted_pool()) { | 487 if (network->restricted_pool()) { |
| 491 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT; | 488 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT; |
| 492 } else { | 489 } else { |
| 493 new_state = PLAN_ACTIVATION_DONE; | 490 new_state = PLAN_ACTIVATION_DONE; |
| 494 } | 491 } |
| 495 } | 492 } |
| 496 break; | 493 break; |
| 497 case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED: | 494 case chromeos::ACTIVATION_STATE_PARTIALLY_ACTIVATED: |
| 498 if (network->connected()) | 495 if (network->connected()) |
| 499 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT; | 496 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT; |
| 500 else | 497 else |
| 501 new_state = PLAN_ACTIVATION_ACTIVATING; | 498 new_state = PLAN_ACTIVATION_RECONNECTING; |
| 502 break; | 499 break; |
| 503 case chromeos::ACTIVATION_STATE_NOT_ACTIVATED: | 500 case chromeos::ACTIVATION_STATE_NOT_ACTIVATED: |
| 504 // Wait in this state until activation state changes. | 501 // Wait in this state until activation state changes. |
| 505 break; | 502 break; |
| 506 case chromeos::ACTIVATION_STATE_ACTIVATING: | 503 case chromeos::ACTIVATION_STATE_ACTIVATING: |
| 507 break; | 504 break; |
| 508 default: | 505 default: |
| 509 break; | 506 break; |
| 510 } | 507 } |
| 511 } | 508 } |
| 512 break; | 509 break; |
| 513 case PLAN_ACTIVATION_ACTIVATING: | 510 case PLAN_ACTIVATION_RECONNECTING: |
| 514 // Wait until the service shows up and gets activated. | 511 // Wait until the service shows up and gets activated. |
| 515 if (network) { | 512 if (network) { |
| 516 switch (network->activation_state()) { | 513 switch (network->activation_state()) { |
| 517 case chromeos::ACTIVATION_STATE_ACTIVATED: | 514 case chromeos::ACTIVATION_STATE_ACTIVATED: |
| 518 if (network->connection_state() == chromeos::STATE_READY) { | 515 if (network->connection_state() == chromeos::STATE_READY) { |
| 519 if (network->restricted_pool()) { | 516 if (network->restricted_pool()) { |
| 520 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT; | 517 new_state = PLAN_ACTIVATION_SHOWING_PAYMENT; |
| 521 } else { | 518 } else { |
| 522 new_state = PLAN_ACTIVATION_DONE; | 519 new_state = PLAN_ACTIVATION_DONE; |
| 523 } | 520 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 554 // Debugging helper function, will take it out at the end. | 551 // Debugging helper function, will take it out at the end. |
| 555 const char* MobileSetupHandler::GetStateDescription( | 552 const char* MobileSetupHandler::GetStateDescription( |
| 556 PlanActivationState state) { | 553 PlanActivationState state) { |
| 557 switch (state) { | 554 switch (state) { |
| 558 case PLAN_ACTIVATION_PAGE_LOADING: | 555 case PLAN_ACTIVATION_PAGE_LOADING: |
| 559 return "PAGE_LOADING"; | 556 return "PAGE_LOADING"; |
| 560 case PLAN_ACTIVATION_START: | 557 case PLAN_ACTIVATION_START: |
| 561 return "ACTIVATION_START"; | 558 return "ACTIVATION_START"; |
| 562 case PLAN_ACTIVATION_INITIATING_ACTIVATION: | 559 case PLAN_ACTIVATION_INITIATING_ACTIVATION: |
| 563 return "INITIATING_ACTIVATION"; | 560 return "INITIATING_ACTIVATION"; |
| 564 case PLAN_ACTIVATION_ACTIVATING : | 561 case PLAN_ACTIVATION_RECONNECTING: |
| 565 return "ACTIVATING"; | 562 return "RECONNECTING"; |
| 566 case PLAN_ACTIVATION_SHOWING_PAYMENT: | 563 case PLAN_ACTIVATION_SHOWING_PAYMENT: |
| 567 return "SHOWING_PAYMENT"; | 564 return "SHOWING_PAYMENT"; |
| 568 case PLAN_ACTIVATION_DONE: | 565 case PLAN_ACTIVATION_DONE: |
| 569 return "DONE"; | 566 return "DONE"; |
| 570 case PLAN_ACTIVATION_ERROR: | 567 case PLAN_ACTIVATION_ERROR: |
| 571 return "ERROR"; | 568 return "ERROR"; |
| 572 } | 569 } |
| 573 return "UNKNOWN"; | 570 return "UNKNOWN"; |
| 574 } | 571 } |
| 575 | 572 |
| 576 void MobileSetupHandler::ChangeState(const chromeos::CellularNetwork* network, | 573 |
| 574 void MobileSetupHandler::CompleteActivation( |
| 575 chromeos::CellularNetwork* network) { |
| 576 // Remove observers, we are done with this page. |
| 577 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> |
| 578 GetNetworkLibrary(); |
| 579 // If we have successfully activated the connection, set autoconnect flag. |
| 580 if (network) { |
| 581 network->set_auto_connect(true); |
| 582 lib->SaveCellularNetwork(network); |
| 583 } |
| 584 lib->RemoveObserver(this); |
| 585 lib->RemoveProperyObserver(this); |
| 586 // Reactivate other types of connections if we have |
| 587 // shut them down previously. |
| 588 ReEnableOtherConnections(); |
| 589 } |
| 590 |
| 591 |
| 592 void MobileSetupHandler::ChangeState(chromeos::CellularNetwork* network, |
| 577 PlanActivationState new_state, | 593 PlanActivationState new_state, |
| 578 const std::string& error_description) { | 594 const std::string& error_description) { |
| 579 static bool first_time = true; | 595 static bool first_time = true; |
| 580 if (state_ == new_state && !first_time) | 596 if (state_ == new_state && !first_time) |
| 581 return; | 597 return; |
| 582 LOG(INFO) << "Activation state flip old = " << | 598 LOG(INFO) << "Activation state flip old = " << |
| 583 GetStateDescription(state_) << ", new = " << | 599 GetStateDescription(state_) << ", new = " << |
| 584 GetStateDescription(new_state); | 600 GetStateDescription(new_state); |
| 585 first_time = false; | 601 first_time = false; |
| 586 state_ = new_state; | 602 state_ = new_state; |
| 587 switch (new_state) { | 603 switch (new_state) { |
| 588 case PLAN_ACTIVATION_START: | 604 case PLAN_ACTIVATION_START: |
| 589 DisableOtherConnections(); | |
| 590 break; | 605 break; |
| 591 case PLAN_ACTIVATION_INITIATING_ACTIVATION: | 606 case PLAN_ACTIVATION_INITIATING_ACTIVATION: |
| 592 DCHECK(network); | 607 DCHECK(network); |
| 593 LOG(INFO) << "Activating service " << network->service_path().c_str(); | 608 LOG(INFO) << "Activating service " << network->service_path().c_str(); |
| 594 if (!network->StartActivation()) | 609 if (!network->StartActivation()) |
| 595 new_state = PLAN_ACTIVATION_ERROR; | 610 new_state = PLAN_ACTIVATION_ERROR; |
| 596 break; | 611 break; |
| 597 case PLAN_ACTIVATION_ACTIVATING: { | 612 case PLAN_ACTIVATION_RECONNECTING: { |
| 598 DCHECK(network); | 613 DCHECK(network); |
| 599 if (network) { | 614 if (network) { |
| 600 chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> | 615 chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> |
| 601 ConnectToCellularNetwork(network); | 616 ConnectToCellularNetwork(network); |
| 602 } | 617 } |
| 603 break; | 618 break; |
| 604 } | 619 } |
| 605 case PLAN_ACTIVATION_PAGE_LOADING: | 620 case PLAN_ACTIVATION_PAGE_LOADING: |
| 606 return; | 621 return; |
| 607 case PLAN_ACTIVATION_SHOWING_PAYMENT: | 622 case PLAN_ACTIVATION_SHOWING_PAYMENT: |
| 608 // Fix for fix SSL for the walled gardens where cert chain verification | 623 // Fix for fix SSL for the walled gardens where cert chain verification |
| 609 // might not work. | 624 // might not work. |
| 610 // net::SSLConfigService::DisallowRevChecking(); | |
| 611 break; | 625 break; |
| 612 case PLAN_ACTIVATION_DONE: | 626 case PLAN_ACTIVATION_DONE: |
| 627 DCHECK(network); |
| 628 CompleteActivation(network); |
| 629 break; |
| 613 case PLAN_ACTIVATION_ERROR: { | 630 case PLAN_ACTIVATION_ERROR: { |
| 614 // net::SSLConfigService::AllowRevChecking(); | 631 CompleteActivation(NULL); |
| 615 // Remove observers, we are done with this page. | |
| 616 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> | |
| 617 GetNetworkLibrary(); | |
| 618 lib->RemoveObserver(this); | |
| 619 lib->RemoveProperyObserver(this); | |
| 620 // Reactivate other types of connections if we have | |
| 621 // shut them down previously. | |
| 622 ReEnableOtherConnections(); | |
| 623 break; | 632 break; |
| 624 } | 633 } |
| 625 default: | 634 default: |
| 626 break; | 635 break; |
| 627 } | 636 } |
| 628 DictionaryValue device_dict; | 637 DictionaryValue device_dict; |
| 629 if (network) | 638 if (network) |
| 630 GetDeviceInfo(network, &device_dict); | 639 GetDeviceInfo(network, &device_dict); |
| 631 device_dict.SetInteger("state", new_state); | 640 device_dict.SetInteger("state", new_state); |
| 632 if (error_description.length()) | 641 if (error_description.length()) |
| 633 device_dict.SetString("error", error_description); | 642 device_dict.SetString("error", error_description); |
| 634 dom_ui_->CallJavascriptFunction( | 643 dom_ui_->CallJavascriptFunction( |
| 635 kJsDeviceStatusChangedHandler, device_dict); | 644 kJsDeviceStatusChangedHandler, device_dict); |
| 636 } | 645 } |
| 637 | 646 |
| 638 void MobileSetupHandler::ReEnableOtherConnections() { | 647 void MobileSetupHandler::ReEnableOtherConnections() { |
| 639 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> | 648 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> |
| 640 GetNetworkLibrary(); | 649 GetNetworkLibrary(); |
| 641 if (reenable_ethernet_) { | 650 if (reenable_ethernet_) { |
| 642 reenable_ethernet_ = false; | 651 reenable_ethernet_ = false; |
| 643 lib->EnableEthernetNetworkDevice(true); | 652 lib->EnableEthernetNetworkDevice(true); |
| 644 } | 653 } |
| 645 if (reenable_wifi_) { | 654 if (reenable_wifi_) { |
| 646 reenable_wifi_ = false; | 655 reenable_wifi_ = false; |
| 647 lib->EnableCellularNetworkDevice(true); | 656 lib->EnableCellularNetworkDevice(true); |
| 648 } | 657 } |
| 658 |
| 659 PrefService* prefs = dom_ui_->GetProfile()->GetPrefs(); |
| 660 if (reenable_cert_check_) { |
| 661 reenable_cert_check_ = false; |
| 662 prefs->SetBoolean(prefs::kCertRevocationCheckingEnabled, |
| 663 reenable_cert_check_); |
| 664 } |
| 649 } | 665 } |
| 650 | 666 |
| 651 void MobileSetupHandler::DisableOtherConnections() { | 667 |
| 668 void MobileSetupHandler::SetupActivationProcess( |
| 669 chromeos::CellularNetwork* network) { |
| 670 if (!network) |
| 671 return; |
| 672 |
| 673 // Disable SSL cert checks since we will be doing this in |
| 674 // restricted pool. |
| 675 PrefService* prefs = dom_ui_->GetProfile()->GetPrefs(); |
| 676 if (!reenable_cert_check_ && |
| 677 prefs->GetBoolean( |
| 678 prefs::kCertRevocationCheckingEnabled)) { |
| 679 reenable_cert_check_ = true; |
| 680 prefs->SetBoolean(prefs::kCertRevocationCheckingEnabled, false); |
| 681 } |
| 682 |
| 652 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> | 683 chromeos::NetworkLibrary* lib = chromeos::CrosLibrary::Get()-> |
| 653 GetNetworkLibrary(); | 684 GetNetworkLibrary(); |
| 685 // Disable autoconnect to cellular network. |
| 686 network->set_auto_connect(false); |
| 687 lib->SaveCellularNetwork(network); |
| 688 |
| 689 // Disable ethernet and wifi. |
| 654 if (!reenable_ethernet_ && lib->ethernet_enabled()) { | 690 if (!reenable_ethernet_ && lib->ethernet_enabled()) { |
| 655 reenable_ethernet_ = true; | 691 reenable_ethernet_ = true; |
| 656 lib->EnableEthernetNetworkDevice(false); | 692 lib->EnableEthernetNetworkDevice(false); |
| 657 } | 693 } |
| 658 if (!reenable_wifi_ && lib->wifi_enabled()) { | 694 if (!reenable_wifi_ && lib->wifi_enabled()) { |
| 659 reenable_wifi_ = true; | 695 reenable_wifi_ = true; |
| 660 lib->EnableCellularNetworkDevice(false); | 696 lib->EnableCellularNetworkDevice(false); |
| 661 } | 697 } |
| 662 } | 698 } |
| 663 | 699 |
| 700 |
| 664 bool MobileSetupHandler::GotActivationError( | 701 bool MobileSetupHandler::GotActivationError( |
| 665 const chromeos::CellularNetwork* network, std::string* error) { | 702 const chromeos::CellularNetwork* network, std::string* error) { |
| 666 if (!network) | 703 if (!network) |
| 667 return false; | 704 return false; |
| 668 bool got_error = false; | 705 bool got_error = false; |
| 669 const char* error_code = kErrorDefault; | 706 const char* error_code = kErrorDefault; |
| 670 | 707 |
| 671 // This is the magic for detection of errors in during activation process. | 708 // This is the magic for detection of errors in during activation process. |
| 672 if (network->connection_state() == chromeos::STATE_FAILURE && | 709 if (network->connection_state() == chromeos::STATE_FAILURE && |
| 673 network->error() == chromeos::ERROR_AAA_FAILED ) { | 710 network->error() == chromeos::ERROR_AAA_FAILED ) { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 760 new MobileSetupUIHTMLSource(service_path); | 797 new MobileSetupUIHTMLSource(service_path); |
| 761 | 798 |
| 762 // Set up the chrome://mobilesetup/ source. | 799 // Set up the chrome://mobilesetup/ source. |
| 763 BrowserThread::PostTask( | 800 BrowserThread::PostTask( |
| 764 BrowserThread::IO, FROM_HERE, | 801 BrowserThread::IO, FROM_HERE, |
| 765 NewRunnableMethod( | 802 NewRunnableMethod( |
| 766 Singleton<ChromeURLDataManager>::get(), | 803 Singleton<ChromeURLDataManager>::get(), |
| 767 &ChromeURLDataManager::AddDataSource, | 804 &ChromeURLDataManager::AddDataSource, |
| 768 make_scoped_refptr(html_source))); | 805 make_scoped_refptr(html_source))); |
| 769 } | 806 } |
| OLD | NEW |