Diff

Differences From Artifact [097e060f29]:

To Artifact [5dbcaf75a3]:


15
16
17
18
19
20
21





22
23
24
25
26
27
28
..
84
85
86
87
88
89
90
91

92
93
94
95

































































96
97
98
99
100
101
102
103
104
105


106
107
108
109
110
111
112

/*
 * Handle and ID for outstanding callbacks
 */
var cackeyOutstandingCallbacks = []
var cackeyOutstandingCallbackCounter = -1;






/*
 * Handle a response from the NaCl side regarding certificates available
 */
function cackeyMessageIncomingListCertificates(message, chromeCallback) {
	var idx;
	var certificates = [];

................................................................................

	if (chromeCallback == null) {
		console.log("[cackey] Discarding outdated message");

		return;
	}

	if (messageEvent.data.status != "success") {

		console.error("[cackey] Failed to execute command '" + messageEvent.data.command + "': " + messageEvent.data.error);

		chromeCallback();
	} else {

































































		switch (messageEvent.data.command) {
			case "listcertificates":
				nextFunction = cackeyMessageIncomingListCertificates;

				break;
			case "sign":
				nextFunction = cackeyMessageIncomingSignMessage;

				break;
		}


	}

	if (nextFunction != null) {
		nextFunction(messageEvent.data, chromeCallback);
	}

	delete cackeyOutstandingCallbacks[messageEvent.data.id];







>
>
>
>
>







 







|
>
|

|
<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|

|
|
|

|
|
>
>







15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
..
89
90
91
92
93
94
95
96
97
98
99
100

101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184

/*
 * Handle and ID for outstanding callbacks
 */
var cackeyOutstandingCallbacks = []
var cackeyOutstandingCallbackCounter = -1;

/*
 * Communication with the PIN entry window
 */
var pinWindowDidWork = 0;

/*
 * Handle a response from the NaCl side regarding certificates available
 */
function cackeyMessageIncomingListCertificates(message, chromeCallback) {
	var idx;
	var certificates = [];

................................................................................

	if (chromeCallback == null) {
		console.log("[cackey] Discarding outdated message");

		return;
	}

	switch (messageEvent.data.status) {
		case "error":
			console.error("[cackey] Failed to execute command '" + messageEvent.data.command + "': " + messageEvent.data.error);

			chromeCallback();


			break;
		case "retry":
			pinWindowDidWork = 0;

			chrome.app.window.create("pin.html", {
				"id": "cackeyPINEntry",
				"resizable": false,
				"alwaysOnTop": true,
				"focused": true,
				"visibleOnAllWorkspaces": true,
				"innerBounds": {
					"width": 350,
					"minWidth": 350,
					"height": 135,
					"minHeight": 135
				}
			}, function(pinWindow) {
				if (!pinWindow) {
					console.log("[cackey] No window was provided for PIN entry, this will not go well.");

					return;
				}
				pinWindow.drawAttention();
				pinWindow.focus();

				/*
				 * Register a handler to handle the window being closed without
				 * having sent anything
				 */
				pinWindow.onClosed.addListener(function() {
					if (pinWindowDidWork != 1) {
						console.log("[cackey] The PIN dialog was closed without resubmitting the request, treating it as a failure");

						cackeyMessageIncoming(
							{
								"data": {
									"target": "cackey",
									"command": messageEvent.data.command,
									"id": messageEvent.data.id,
									"status": "error",
									"error": "PIN window closed without a PIN being provided"
								}
							}
						)

					}
					return;
				})

				/*
				 * Pass this message off to the other window so that it may resubmit the request.
				 */
				pinWindow.contentWindow.parentWindow = window;
				pinWindow.contentWindow.messageEvent = messageEvent;

				return;
			});

			/*
			 * We return here instead of break to avoid deleting the callback
			 * entry.
			 */
			return;
		case "success":
			switch (messageEvent.data.command) {
				case "listcertificates":
					nextFunction = cackeyMessageIncomingListCertificates;

					break;
				case "sign":
					nextFunction = cackeyMessageIncomingSignMessage;

					break;
			}

			break;
	}

	if (nextFunction != null) {
		nextFunction(messageEvent.data, chromeCallback);
	}

	delete cackeyOutstandingCallbacks[messageEvent.data.id];