Diff

Differences From Artifact [25cd0bb896]:

To Artifact [dece8c3884]:


    21     21   
    22     22   /*
    23     23    * Communication with the PIN entry window
    24     24    */
    25     25   var pinWindowPINValue = "";
    26     26   var pinWindowPreviousHandle = null;
    27     27   
           28  +/*
           29  + * Messages that may need to be retried after getting a PIN
           30  + */
           31  +var cackeyMessagesToRetry = [];
           32  +
    28     33   /*
    29     34    * Handle a response from the NaCl side regarding certificates available
    30     35    */
    31     36   function cackeyMessageIncomingListCertificates(message, chromeCallback) {
    32     37   	var idx;
    33     38   	var certificates = [];
    34     39   
................................................................................
    98    103   		case "error":
    99    104   			console.error("[cackey] Failed to execute command '" + messageEvent.data.command + "': " + messageEvent.data.error);
   100    105   
   101    106   			chromeCallback();
   102    107   
   103    108   			break;
   104    109   		case "retry":
   105         -			pinWindowPINValue = "";
          110  +			/*
          111  +			 * Add the new request to the queue of events to process when the PIN
          112  +			 * prompt is terminated.
          113  +			 */
          114  +			cackeyMessagesToRetry.push(messageEvent);
   106    115   
   107    116   			if (pinWindowPreviousHandle) {
   108    117   				/*
   109    118   				 * An existing PIN entry is in progress
   110         -				 * Wait for it to complete and tie this request to that one.
          119  +				 * Just add the request to the queue (above) and wait
   111    120   				 */
   112    121   
   113         -				/* XXX:TODO */
          122  +				return;
   114    123   			}
   115    124   
          125  +			/*
          126  +			 * Set the handle to an invalid (but non-null) value until the window
          127  +			 * is created in case we are invoked again soon.
          128  +			 */
          129  +			pinWindowPreviousHandle = "invalid";
          130  +
   116    131   			chrome.app.window.create("pin.html", {
   117    132   				"id": "cackeyPINEntry",
   118    133   				"resizable": false,
   119    134   				"alwaysOnTop": true,
   120    135   				"focused": true,
   121    136   				"visibleOnAllWorkspaces": true,
   122    137   				"innerBounds": {
   123    138   					"width": 350,
   124    139   					"minWidth": 350,
   125    140   					"height": 135,
   126    141   					"minHeight": 135
   127    142   				}
   128    143   			}, function(pinWindow) {
          144  +				/*
          145  +				 * Set the PIN value to blank
          146  +				 */
          147  +				pinWindowPINValue = "";
          148  +
   129    149   				if (!pinWindow) {
   130    150   					console.log("[cackey] No window was provided for PIN entry, this will not go well.");
   131    151   
   132    152   					return;
   133    153   				}
   134    154   
   135    155   				pinWindowPreviousHandle = pinWindow;
................................................................................
   138    158   				pinWindow.focus();
   139    159   
   140    160   				/*
   141    161   				 * Register a handler to handle the window being closed without
   142    162   				 * having sent anything
   143    163   				 */
   144    164   				pinWindow.onClosed.addListener(function() {
          165  +					var messageIdx;
          166  +
   145    167   					pinWindowPreviousHandle = null;
   146    168   
   147         -					if (pinWindowPINValue == "") {
   148         -						console.log("[cackey] The PIN dialog was closed without resubmitting the request, treating it as a failure");
          169  +					for (messageIdx = 0; messageIdx < cackeyMessagesToRetry.length; messageIdx++) {
          170  +						var tmpMessageEvent;
   149    171   
   150         -						messageEvent.data.status = "error";
   151         -						messageEvent.data.error = "PIN window closed without a PIN being provided";
          172  +						tmpMessageEvent = cackeyMessagesToRetry[messageIdx];
   152    173   
   153         -						cackeyMessageIncoming(messageEvent);
          174  +						if (pinWindowPINValue == "") {
          175  +							console.log("[cackey] The PIN dialog was closed without gathering a PIN, treating it as a failure.");
          176  +
          177  +							tmpMessageEvent.data.status = "error";
          178  +							tmpMessageEvent.data.error = "PIN window closed without a PIN being provided";
          179  +
          180  +							cackeyMessageIncoming(tmpMessageEvent);
          181  +						} else {
          182  +							cackeyHandle.postMessage(tmpMessageEvent.data.originalrequest);
          183  +						}
          184  +
          185  +						delete cackeyMessagesToRetry[messageIdx];
   154    186   					}
   155    187   
   156    188   					return;
   157    189   				})
   158    190   
   159    191   				/*
   160    192   				 * Pass this message off to the other window so that it may resubmit the request.