[cros] Process proper notification in SIM dialog.

This eliminates unnecessary dialog refreshes when input is lost and user has to enter it again.
Small JS change, properly disable OK controls in SIM dialogs.

BUG=chrome-os-partner:4661
TEST=Manual. Various operations with SIM dialog.

Review URL: http://codereview.chromium.org/7736014

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98641 0039d316-1c4b-4281-b951-d872f2087c98
parent 576c7cdd
...@@ -2844,6 +2844,10 @@ void NetworkLibraryImplBase::NotifyNetworkDeviceChanged( ...@@ -2844,6 +2844,10 @@ void NetworkLibraryImplBase::NotifyNetworkDeviceChanged(
FOR_EACH_OBSERVER(NetworkDeviceObserver, FOR_EACH_OBSERVER(NetworkDeviceObserver,
*device_observer_list, *device_observer_list,
OnNetworkDeviceFoundNetworks(this, device)); OnNetworkDeviceFoundNetworks(this, device));
} else if (index == PROPERTY_INDEX_SIM_LOCK) {
FOR_EACH_OBSERVER(NetworkDeviceObserver,
*device_observer_list,
OnNetworkDeviceSimLockChanged(this, device));
} }
FOR_EACH_OBSERVER(NetworkDeviceObserver, FOR_EACH_OBSERVER(NetworkDeviceObserver,
*device_observer_list, *device_observer_list,
......
...@@ -1271,14 +1271,17 @@ class NetworkLibrary { ...@@ -1271,14 +1271,17 @@ class NetworkLibrary {
class NetworkDeviceObserver { class NetworkDeviceObserver {
public: public:
// Called when the state of a single device has changed, // Called when the state of a single device has changed.
// for example SIMLock state for cellular.
virtual void OnNetworkDeviceChanged(NetworkLibrary* cros, virtual void OnNetworkDeviceChanged(NetworkLibrary* cros,
const NetworkDevice* device) {} const NetworkDevice* device) {}
// Called when |device| got notification about new networks available. // Called when |device| got notification about new networks available.
virtual void OnNetworkDeviceFoundNetworks(NetworkLibrary* cros, virtual void OnNetworkDeviceFoundNetworks(NetworkLibrary* cros,
const NetworkDevice* device) {} const NetworkDevice* device) {}
// Called when |device| got notification about SIM lock change.
virtual void OnNetworkDeviceSimLockChanged(NetworkLibrary* cros,
const NetworkDevice* device) {}
protected: protected:
~NetworkDeviceObserver() {} ~NetworkDeviceObserver() {}
}; };
......
...@@ -103,8 +103,8 @@ cr.define('mobile', function() { ...@@ -103,8 +103,8 @@ cr.define('mobile', function() {
$('new-pin-input').value = ''; $('new-pin-input').value = '';
$('retype-new-pin-input').value = ''; $('retype-new-pin-input').value = '';
$('choose-pin-overlay').hidden = false; $('choose-pin-overlay').hidden = false;
$('old-pin-input').focus();
SimUnlock.enableChoosePinDialog(true); SimUnlock.enableChoosePinDialog(true);
$('old-pin-input').focus();
break; break;
case SimUnlock.SIM_LOCKED_NO_PIN_TRIES_LEFT: case SimUnlock.SIM_LOCKED_NO_PIN_TRIES_LEFT:
$('locked-pin-no-tries-overlay').hidden = false; $('locked-pin-no-tries-overlay').hidden = false;
...@@ -234,6 +234,7 @@ cr.define('mobile', function() { ...@@ -234,6 +234,7 @@ cr.define('mobile', function() {
}); });
$('pin-input').addEventListener('keyup', function(event) { $('pin-input').addEventListener('keyup', function(event) {
$('enter-pin-confirm').disabled = $('enter-pin-confirm').disabled =
$('enter-pin-dismiss').disabled ||
this.value.length < SimUnlock.PIN_MIN_LENGTH; this.value.length < SimUnlock.PIN_MIN_LENGTH;
}); });
$('enter-pin-confirm').addEventListener('click', function(event) { $('enter-pin-confirm').addEventListener('click', function(event) {
...@@ -264,6 +265,7 @@ cr.define('mobile', function() { ...@@ -264,6 +265,7 @@ cr.define('mobile', function() {
}); });
$('puk-input').addEventListener('keyup', function(event) { $('puk-input').addEventListener('keyup', function(event) {
$('enter-puk-confirm').disabled = $('enter-puk-confirm').disabled =
$('enter-puk-dismiss').disabled ||
this.value.length < SimUnlock.PUK_LENGTH; this.value.length < SimUnlock.PUK_LENGTH;
}); });
$('enter-puk-confirm').addEventListener('click', function(event) { $('enter-puk-confirm').addEventListener('click', function(event) {
...@@ -287,6 +289,7 @@ cr.define('mobile', function() { ...@@ -287,6 +289,7 @@ cr.define('mobile', function() {
}); });
$('old-pin-input').addEventListener('keyup', function(event) { $('old-pin-input').addEventListener('keyup', function(event) {
$('choose-pin-confirm').disabled = $('choose-pin-confirm').disabled =
$('choose-pin-dismiss').disabled ||
this.value.length < SimUnlock.PIN_MIN_LENGTH || this.value.length < SimUnlock.PIN_MIN_LENGTH ||
$('new-pin-input').value.length < SimUnlock.PIN_MIN_LENGTH || $('new-pin-input').value.length < SimUnlock.PIN_MIN_LENGTH ||
$('retype-new-pin-input').value.length < SimUnlock.PIN_MIN_LENGTH; $('retype-new-pin-input').value.length < SimUnlock.PIN_MIN_LENGTH;
...@@ -306,6 +309,7 @@ cr.define('mobile', function() { ...@@ -306,6 +309,7 @@ cr.define('mobile', function() {
var oldPinOk = SimUnlock.state != SimUnlock.SIM_NOT_LOCKED_CHANGE_PIN || var oldPinOk = SimUnlock.state != SimUnlock.SIM_NOT_LOCKED_CHANGE_PIN ||
$('old-pin-input').value.length >= SimUnlock.PIN_MIN_LENGTH; $('old-pin-input').value.length >= SimUnlock.PIN_MIN_LENGTH;
$('choose-pin-confirm').disabled = $('choose-pin-confirm').disabled =
$('choose-pin-dismiss').disabled ||
this.value.length < SimUnlock.PIN_MIN_LENGTH || this.value.length < SimUnlock.PIN_MIN_LENGTH ||
$('retype-new-pin-input').value.length < SimUnlock.PIN_MIN_LENGTH || $('retype-new-pin-input').value.length < SimUnlock.PIN_MIN_LENGTH ||
!oldPinOk; !oldPinOk;
...@@ -314,6 +318,7 @@ cr.define('mobile', function() { ...@@ -314,6 +318,7 @@ cr.define('mobile', function() {
var oldPinOk = SimUnlock.state != SimUnlock.SIM_NOT_LOCKED_CHANGE_PIN || var oldPinOk = SimUnlock.state != SimUnlock.SIM_NOT_LOCKED_CHANGE_PIN ||
$('old-pin-input').value.length >= SimUnlock.PIN_MIN_LENGTH; $('old-pin-input').value.length >= SimUnlock.PIN_MIN_LENGTH;
$('choose-pin-confirm').disabled = $('choose-pin-confirm').disabled =
$('choose-pin-dismiss').disabled ||
this.value.length < SimUnlock.PIN_MIN_LENGTH || this.value.length < SimUnlock.PIN_MIN_LENGTH ||
$('new-pin-input').value.length < SimUnlock.PIN_MIN_LENGTH || $('new-pin-input').value.length < SimUnlock.PIN_MIN_LENGTH ||
!oldPinOk; !oldPinOk;
......
...@@ -97,8 +97,8 @@ class SimUnlockHandler : public WebUIMessageHandler, ...@@ -97,8 +97,8 @@ class SimUnlockHandler : public WebUIMessageHandler,
virtual void RegisterMessages() OVERRIDE; virtual void RegisterMessages() OVERRIDE;
// NetworkLibrary::NetworkDeviceObserver implementation. // NetworkLibrary::NetworkDeviceObserver implementation.
virtual void OnNetworkDeviceChanged(NetworkLibrary* cros, virtual void OnNetworkDeviceSimLockChanged(
const NetworkDevice* device) OVERRIDE; NetworkLibrary* cros, const NetworkDevice* device) OVERRIDE;
// NetworkLibrary::PinOperationObserver implementation. // NetworkLibrary::PinOperationObserver implementation.
virtual void OnPinOperationCompleted(NetworkLibrary* cros, virtual void OnPinOperationCompleted(NetworkLibrary* cros,
...@@ -213,6 +213,8 @@ class SimUnlockHandler : public WebUIMessageHandler, ...@@ -213,6 +213,8 @@ class SimUnlockHandler : public WebUIMessageHandler,
const std::string& error_msg); const std::string& error_msg);
TabContents* tab_contents_; TabContents* tab_contents_;
// Dialog internal state.
SimUnlockState state_; SimUnlockState state_;
// Path of the Cellular device that we monitor property updates from. // Path of the Cellular device that we monitor property updates from.
...@@ -224,6 +226,12 @@ class SimUnlockHandler : public WebUIMessageHandler, ...@@ -224,6 +226,12 @@ class SimUnlockHandler : public WebUIMessageHandler,
// New PIN value for the case when we unblock SIM card or change PIN. // New PIN value for the case when we unblock SIM card or change PIN.
std::string new_pin_; std::string new_pin_;
// True if there's a pending PIN operation.
// That means that SIM lock state change will be received 2 times:
// OnNetworkDeviceSimLockChanged and OnPinOperationCompleted.
// First one should be ignored.
bool pending_pin_operation_;
DISALLOW_COPY_AND_ASSIGN(SimUnlockHandler); DISALLOW_COPY_AND_ASSIGN(SimUnlockHandler);
}; };
...@@ -306,7 +314,8 @@ void SimUnlockUIHTMLSource::StartDataRequest(const std::string& path, ...@@ -306,7 +314,8 @@ void SimUnlockUIHTMLSource::StartDataRequest(const std::string& path,
SimUnlockHandler::SimUnlockHandler() SimUnlockHandler::SimUnlockHandler()
: tab_contents_(NULL), : tab_contents_(NULL),
state_(SIM_UNLOCK_LOADING), state_(SIM_UNLOCK_LOADING),
dialog_mode_(SimDialogDelegate::SIM_DIALOG_UNLOCK) { dialog_mode_(SimDialogDelegate::SIM_DIALOG_UNLOCK),
pending_pin_operation_(false) {
const chromeos::NetworkDevice* cellular = GetCellularDevice(); const chromeos::NetworkDevice* cellular = GetCellularDevice();
// One could just call us directly via chrome://sim-unlock. // One could just call us directly via chrome://sim-unlock.
if (cellular) { if (cellular) {
...@@ -348,17 +357,21 @@ void SimUnlockHandler::RegisterMessages() { ...@@ -348,17 +357,21 @@ void SimUnlockHandler::RegisterMessages() {
NewCallback(this, &SimUnlockHandler::HandleSimStatusInitialize)); NewCallback(this, &SimUnlockHandler::HandleSimStatusInitialize));
} }
void SimUnlockHandler::OnNetworkDeviceChanged(NetworkLibrary* cros, void SimUnlockHandler::OnNetworkDeviceSimLockChanged(
const NetworkDevice* device) { NetworkLibrary* cros, const NetworkDevice* device) {
chromeos::SimLockState lock_state = device->sim_lock_state(); chromeos::SimLockState lock_state = device->sim_lock_state();
int retries_left = device->sim_retries_left(); int retries_left = device->sim_retries_left();
VLOG(1) << "OnNetworkDeviceChanged, lock: " << lock_state VLOG(1) << "OnNetworkDeviceSimLockChanged, lock: " << lock_state
<< ", retries: " << retries_left; << ", retries: " << retries_left;
ProcessSimCardState(GetCellularDevice()); // There's a pending PIN operation.
// Wait for it to finish and refresh state then.
if (!pending_pin_operation_)
ProcessSimCardState(GetCellularDevice());
} }
void SimUnlockHandler::OnPinOperationCompleted(NetworkLibrary* cros, void SimUnlockHandler::OnPinOperationCompleted(NetworkLibrary* cros,
PinOperationError error) { PinOperationError error) {
pending_pin_operation_ = false;
DCHECK(cros); DCHECK(cros);
const NetworkDevice* cellular = cros->FindCellularDevice(); const NetworkDevice* cellular = cros->FindCellularDevice();
DCHECK(cellular); DCHECK(cellular);
...@@ -408,6 +421,7 @@ void SimUnlockHandler::EnterCode(const std::string& code, ...@@ -408,6 +421,7 @@ void SimUnlockHandler::EnterCode(const std::string& code,
const NetworkDevice* cellular = GetCellularDevice(); const NetworkDevice* cellular = GetCellularDevice();
chromeos::SimLockState lock_state = cellular->sim_lock_state(); chromeos::SimLockState lock_state = cellular->sim_lock_state();
pending_pin_operation_ = true;
switch (code_type) { switch (code_type) {
case CODE_PIN: case CODE_PIN:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment