[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(
FOR_EACH_OBSERVER(NetworkDeviceObserver,
*device_observer_list,
OnNetworkDeviceFoundNetworks(this, device));
} else if (index == PROPERTY_INDEX_SIM_LOCK) {
FOR_EACH_OBSERVER(NetworkDeviceObserver,
*device_observer_list,
OnNetworkDeviceSimLockChanged(this, device));
}
FOR_EACH_OBSERVER(NetworkDeviceObserver,
*device_observer_list,
......
......@@ -1271,14 +1271,17 @@ class NetworkLibrary {
class NetworkDeviceObserver {
public:
// Called when the state of a single device has changed,
// for example SIMLock state for cellular.
// Called when the state of a single device has changed.
virtual void OnNetworkDeviceChanged(NetworkLibrary* cros,
const NetworkDevice* device) {}
// Called when |device| got notification about new networks available.
virtual void OnNetworkDeviceFoundNetworks(NetworkLibrary* cros,
const NetworkDevice* device) {}
// Called when |device| got notification about SIM lock change.
virtual void OnNetworkDeviceSimLockChanged(NetworkLibrary* cros,
const NetworkDevice* device) {}
protected:
~NetworkDeviceObserver() {}
};
......
......@@ -103,8 +103,8 @@ cr.define('mobile', function() {
$('new-pin-input').value = '';
$('retype-new-pin-input').value = '';
$('choose-pin-overlay').hidden = false;
$('old-pin-input').focus();
SimUnlock.enableChoosePinDialog(true);
$('old-pin-input').focus();
break;
case SimUnlock.SIM_LOCKED_NO_PIN_TRIES_LEFT:
$('locked-pin-no-tries-overlay').hidden = false;
......@@ -234,6 +234,7 @@ cr.define('mobile', function() {
});
$('pin-input').addEventListener('keyup', function(event) {
$('enter-pin-confirm').disabled =
$('enter-pin-dismiss').disabled ||
this.value.length < SimUnlock.PIN_MIN_LENGTH;
});
$('enter-pin-confirm').addEventListener('click', function(event) {
......@@ -264,6 +265,7 @@ cr.define('mobile', function() {
});
$('puk-input').addEventListener('keyup', function(event) {
$('enter-puk-confirm').disabled =
$('enter-puk-dismiss').disabled ||
this.value.length < SimUnlock.PUK_LENGTH;
});
$('enter-puk-confirm').addEventListener('click', function(event) {
......@@ -287,6 +289,7 @@ cr.define('mobile', function() {
});
$('old-pin-input').addEventListener('keyup', function(event) {
$('choose-pin-confirm').disabled =
$('choose-pin-dismiss').disabled ||
this.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;
......@@ -306,6 +309,7 @@ cr.define('mobile', function() {
var oldPinOk = SimUnlock.state != SimUnlock.SIM_NOT_LOCKED_CHANGE_PIN ||
$('old-pin-input').value.length >= SimUnlock.PIN_MIN_LENGTH;
$('choose-pin-confirm').disabled =
$('choose-pin-dismiss').disabled ||
this.value.length < SimUnlock.PIN_MIN_LENGTH ||
$('retype-new-pin-input').value.length < SimUnlock.PIN_MIN_LENGTH ||
!oldPinOk;
......@@ -314,6 +318,7 @@ cr.define('mobile', function() {
var oldPinOk = SimUnlock.state != SimUnlock.SIM_NOT_LOCKED_CHANGE_PIN ||
$('old-pin-input').value.length >= SimUnlock.PIN_MIN_LENGTH;
$('choose-pin-confirm').disabled =
$('choose-pin-dismiss').disabled ||
this.value.length < SimUnlock.PIN_MIN_LENGTH ||
$('new-pin-input').value.length < SimUnlock.PIN_MIN_LENGTH ||
!oldPinOk;
......
......@@ -97,8 +97,8 @@ class SimUnlockHandler : public WebUIMessageHandler,
virtual void RegisterMessages() OVERRIDE;
// NetworkLibrary::NetworkDeviceObserver implementation.
virtual void OnNetworkDeviceChanged(NetworkLibrary* cros,
const NetworkDevice* device) OVERRIDE;
virtual void OnNetworkDeviceSimLockChanged(
NetworkLibrary* cros, const NetworkDevice* device) OVERRIDE;
// NetworkLibrary::PinOperationObserver implementation.
virtual void OnPinOperationCompleted(NetworkLibrary* cros,
......@@ -213,6 +213,8 @@ class SimUnlockHandler : public WebUIMessageHandler,
const std::string& error_msg);
TabContents* tab_contents_;
// Dialog internal state.
SimUnlockState state_;
// Path of the Cellular device that we monitor property updates from.
......@@ -224,6 +226,12 @@ class SimUnlockHandler : public WebUIMessageHandler,
// New PIN value for the case when we unblock SIM card or change 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);
};
......@@ -306,7 +314,8 @@ void SimUnlockUIHTMLSource::StartDataRequest(const std::string& path,
SimUnlockHandler::SimUnlockHandler()
: tab_contents_(NULL),
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();
// One could just call us directly via chrome://sim-unlock.
if (cellular) {
......@@ -348,17 +357,21 @@ void SimUnlockHandler::RegisterMessages() {
NewCallback(this, &SimUnlockHandler::HandleSimStatusInitialize));
}
void SimUnlockHandler::OnNetworkDeviceChanged(NetworkLibrary* cros,
const NetworkDevice* device) {
void SimUnlockHandler::OnNetworkDeviceSimLockChanged(
NetworkLibrary* cros, const NetworkDevice* device) {
chromeos::SimLockState lock_state = device->sim_lock_state();
int retries_left = device->sim_retries_left();
VLOG(1) << "OnNetworkDeviceChanged, lock: " << lock_state
VLOG(1) << "OnNetworkDeviceSimLockChanged, lock: " << lock_state
<< ", retries: " << retries_left;
// 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,
PinOperationError error) {
pending_pin_operation_ = false;
DCHECK(cros);
const NetworkDevice* cellular = cros->FindCellularDevice();
DCHECK(cellular);
......@@ -408,6 +421,7 @@ void SimUnlockHandler::EnterCode(const std::string& code,
const NetworkDevice* cellular = GetCellularDevice();
chromeos::SimLockState lock_state = cellular->sim_lock_state();
pending_pin_operation_ = true;
switch (code_type) {
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