Check-in [2c6a5fb7dd]
Overview
Comment:ChromeOS: Made PIN entry dialog much more robust
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:2c6a5fb7ddeccb1df5d9feb52202588b34134629
User & Date: rkeene on 2016-02-13 10:05:49
Other Links: manifest | tags
Context
2016-02-13
10:08
ChromeOS: Made PIN entry failure code slightly cleaner check-in: 233d1929c2 user: rkeene tags: trunk
10:05
ChromeOS: Made PIN entry dialog much more robust check-in: 2c6a5fb7dd user: rkeene tags: trunk
07:19
ChromeOS: Added start of PIN entry dialog check-in: 32182121df user: rkeene tags: trunk
Changes

Modified build/chrome/Makefile from [d4c1056478] to [1d85794fd7].

    24     24   ifeq (,${NACL_SDK_ROOT})
    25     25   $(error "Please set NACL_SDK_ROOT")
    26     26   endif
    27     27   export NACL_SDK_ROOT
    28     28   
    29     29   all: cackey.crx
    30     30   
    31         -cackey.crx: cackey.pexe cackey.nmf manifest.json cackey.js google-pcsc.js pin.html pin-icon.png
           31  +cackey.crx: cackey.pexe cackey.nmf manifest.json cackey.js google-pcsc.js pin.html pin.js pin-icon.png
    32     32   	rm -f cackey.crx
    33     33   	zip cackey.crx.new $^
    34     34   	mv cackey.crx.new cackey.crx
    35     35   
    36     36   cackey.pexe: cackey-chrome.o cackey-chrome-init.o lib/libcackey.a lib/libpcsc.a lib/libz.a
    37     37   	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o cackey.pexe.new cackey-chrome.o cackey-chrome-init.o $(LIBS)
    38     38   	$(FINALIZE) cackey.pexe.new

Modified build/chrome/cackey.js from [097e060f29] to [5dbcaf75a3].

    15     15   
    16     16   /*
    17     17    * Handle and ID for outstanding callbacks
    18     18    */
    19     19   var cackeyOutstandingCallbacks = []
    20     20   var cackeyOutstandingCallbackCounter = -1;
    21     21   
           22  +/*
           23  + * Communication with the PIN entry window
           24  + */
           25  +var pinWindowDidWork = 0;
           26  +
    22     27   /*
    23     28    * Handle a response from the NaCl side regarding certificates available
    24     29    */
    25     30   function cackeyMessageIncomingListCertificates(message, chromeCallback) {
    26     31   	var idx;
    27     32   	var certificates = [];
    28     33   
................................................................................
    84     89   
    85     90   	if (chromeCallback == null) {
    86     91   		console.log("[cackey] Discarding outdated message");
    87     92   
    88     93   		return;
    89     94   	}
    90     95   
    91         -	if (messageEvent.data.status != "success") {
    92         -		console.error("[cackey] Failed to execute command '" + messageEvent.data.command + "': " + messageEvent.data.error);
    93         -
    94         -		chromeCallback();
    95         -	} else {
    96         -		switch (messageEvent.data.command) {
    97         -			case "listcertificates":
    98         -				nextFunction = cackeyMessageIncomingListCertificates;
    99         -
   100         -				break;
   101         -			case "sign":
   102         -				nextFunction = cackeyMessageIncomingSignMessage;
   103         -
   104         -				break;
   105         -		}
           96  +	switch (messageEvent.data.status) {
           97  +		case "error":
           98  +			console.error("[cackey] Failed to execute command '" + messageEvent.data.command + "': " + messageEvent.data.error);
           99  +
          100  +			chromeCallback();
          101  +
          102  +			break;
          103  +		case "retry":
          104  +			pinWindowDidWork = 0;
          105  +
          106  +			chrome.app.window.create("pin.html", {
          107  +				"id": "cackeyPINEntry",
          108  +				"resizable": false,
          109  +				"alwaysOnTop": true,
          110  +				"focused": true,
          111  +				"visibleOnAllWorkspaces": true,
          112  +				"innerBounds": {
          113  +					"width": 350,
          114  +					"minWidth": 350,
          115  +					"height": 135,
          116  +					"minHeight": 135
          117  +				}
          118  +			}, function(pinWindow) {
          119  +				if (!pinWindow) {
          120  +					console.log("[cackey] No window was provided for PIN entry, this will not go well.");
          121  +
          122  +					return;
          123  +				}
          124  +				pinWindow.drawAttention();
          125  +				pinWindow.focus();
          126  +
          127  +				/*
          128  +				 * Register a handler to handle the window being closed without
          129  +				 * having sent anything
          130  +				 */
          131  +				pinWindow.onClosed.addListener(function() {
          132  +					if (pinWindowDidWork != 1) {
          133  +						console.log("[cackey] The PIN dialog was closed without resubmitting the request, treating it as a failure");
          134  +
          135  +						cackeyMessageIncoming(
          136  +							{
          137  +								"data": {
          138  +									"target": "cackey",
          139  +									"command": messageEvent.data.command,
          140  +									"id": messageEvent.data.id,
          141  +									"status": "error",
          142  +									"error": "PIN window closed without a PIN being provided"
          143  +								}
          144  +							}
          145  +						)
          146  +
          147  +					}
          148  +					return;
          149  +				})
          150  +
          151  +				/*
          152  +				 * Pass this message off to the other window so that it may resubmit the request.
          153  +				 */
          154  +				pinWindow.contentWindow.parentWindow = window;
          155  +				pinWindow.contentWindow.messageEvent = messageEvent;
          156  +
          157  +				return;
          158  +			});
          159  +
          160  +			/*
          161  +			 * We return here instead of break to avoid deleting the callback
          162  +			 * entry.
          163  +			 */
          164  +			return;
          165  +		case "success":
          166  +			switch (messageEvent.data.command) {
          167  +				case "listcertificates":
          168  +					nextFunction = cackeyMessageIncomingListCertificates;
          169  +
          170  +					break;
          171  +				case "sign":
          172  +					nextFunction = cackeyMessageIncomingSignMessage;
          173  +
          174  +					break;
          175  +			}
          176  +
          177  +			break;
   106    178   	}
   107    179   
   108    180   	if (nextFunction != null) {
   109    181   		nextFunction(messageEvent.data, chromeCallback);
   110    182   	}
   111    183   
   112    184   	delete cackeyOutstandingCallbacks[messageEvent.data.id];

Modified build/chrome/pin.html from [fee4932709] to [80f230e669].

     1      1   <html>
     2      2   	<head>
     3      3   		<title>CACKey PIN Entry</title>
            4  +		<style>
            5  +			body {
            6  +				margin: 0px;
            7  +			}
            8  +		</style>
            9  +		<script type="text/javascript" src="pin.js"></script>
     4     10   	</head>
     5     11   	<body bgcolor="#e4e4e4" color="#000000">
     6     12   		<form>
     7     13   			<table width="100%" border="0" cellspacing="5" cellpadding="0">
     8     14   				<tr width="100%" align="left" valign="bottom">
     9     15   					<td rowspan="4"><img src="pin-icon.png" alt=""></td>
    10     16   				</tr>
................................................................................
    11     17   				<tr width="100%" align="left" valign="bottom">
    12     18   					<td></td>
    13     19   					<td colspan="2"><div id="prompt" style="font-size: 0.8em;">PIN Entry Required</div></td>
    14     20   				</tr>
    15     21   				<tr width="100%" align="left" valign="center">
    16     22   					<td></td>
    17     23   					<td>PIN:</td>
    18         -					<td><input type="password" name="pin" id="pin" style="width: 100%;"></td>
           24  +					<td><input type="password" name="pin" id="pin" style="width: 100%;" autofocus></td>
    19     25   				</tr>
    20     26   				<tr width="100%" align="right" valign="top">
    21     27   					<td></td>
    22     28   					<td colspan="2">
    23     29   						<input type="button" class="button" name="ok" id="ok" value="OK" style="min-width: 4em;">
    24     30   						<input type="button" class="button" name="cancel" id="cancel" value="Cancel" style="min-width: 4em;">
    25     31   					</td>
    26     32   				</tr>
    27     33   			</table>
    28     34   		</form>
    29     35   	</body>
    30     36   </html>

Added build/chrome/pin.js version [73ed093e1a].

            1  +function clickOk() {
            2  +
            3  +	parentWindow.pinWindowDidWork = 1;
            4  +
            5  +	window.close();
            6  +
            7  +	return;
            8  +}
            9  +
           10  +function clickCancel() {
           11  +	window.close();
           12  +
           13  +	return;
           14  +}
           15  +
           16  +function focusPin() {
           17  +	window.focus();
           18  +
           19  +	document.getElementById('pin').focus();
           20  +
           21  +	return;
           22  +}
           23  +
           24  +setTimeout(function() {
           25  +	var noFocusObjects, idx;
           26  +
           27  +	document.getElementById('ok').onclick = function() {
           28  +		clickOk();
           29  +	};
           30  +
           31  +	document.getElementById('cancel').onclick = function() {
           32  +		clickCancel();
           33  +	};
           34  +
           35  +	window.onfocus = function() {
           36  +		focusPin();
           37  +	}
           38  +
           39  +	document.getElementById('pin').onblur = function() {
           40  +		setTimeout(function() {
           41  +			if (document.activeElement.className != "button") {
           42  +				focusPin();
           43  +			}
           44  +		}, 1);
           45  +	}
           46  +}, 1);