OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 'use strict'; | 5 'use strict'; |
6 | 6 |
7 // TODO(vadimt): Remove alerts. | 7 // TODO(vadimt): Remove alerts. |
8 | 8 |
9 /** | 9 /** |
10 * @fileoverview Utility objects and functions for Google Now extension. | 10 * @fileoverview Utility objects and functions for Google Now extension. |
(...skipping 14 matching lines...) Expand all Loading... |
25 * false. | 25 * false. |
26 */ | 26 */ |
27 function verify(condition, message) { | 27 function verify(condition, message) { |
28 if (!condition) | 28 if (!condition) |
29 throw new Error('\nASSERT: ' + message); | 29 throw new Error('\nASSERT: ' + message); |
30 } | 30 } |
31 | 31 |
32 /** | 32 /** |
33 * Builds a request to the notification server. | 33 * Builds a request to the notification server. |
34 * @param {string} handlerName Server handler to send the request to. | 34 * @param {string} handlerName Server handler to send the request to. |
| 35 * @param {string} contentType Value for the Content-type header. |
35 * @return {XMLHttpRequest} Server request. | 36 * @return {XMLHttpRequest} Server request. |
36 */ | 37 */ |
37 function buildServerRequest(handlerName) { | 38 function buildServerRequest(handlerName, contentType) { |
38 var request = new XMLHttpRequest(); | 39 var request = new XMLHttpRequest(); |
39 | 40 |
40 request.responseType = 'text'; | 41 request.responseType = 'text'; |
41 request.open('POST', NOTIFICATION_CARDS_URL + '/' + handlerName, true); | 42 request.open('POST', NOTIFICATION_CARDS_URL + '/' + handlerName, true); |
42 request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); | 43 request.setRequestHeader('Content-type', contentType); |
43 | 44 |
44 return request; | 45 return request; |
45 } | 46 } |
46 | 47 |
47 /** | 48 /** |
48 * Builds the object to manage tasks (mutually exclusive chains of events). | 49 * Builds the object to manage tasks (mutually exclusive chains of events). |
49 * @param {function(string, string): boolean} areConflicting Function that | 50 * @param {function(string, string): boolean} areConflicting Function that |
50 * checks if a new task can't be added to a task queue that contains an | 51 * checks if a new task can't be added to a task queue that contains an |
51 * existing task. | 52 * existing task. |
52 * @return {Object} Task manager interface. | 53 * @return {Object} Task manager interface. |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 if (topFrameElements.length >= 3) { | 171 if (topFrameElements.length >= 3) { |
171 file = topFrameElements[0] + ':' + topFrameElements[1]; | 172 file = topFrameElements[0] + ':' + topFrameElements[1]; |
172 line = topFrameElements[2]; | 173 line = topFrameElements[2]; |
173 } | 174 } |
174 } | 175 } |
175 var requestParameters = | 176 var requestParameters = |
176 'error=' + encodeURIComponent(error.name) + | 177 'error=' + encodeURIComponent(error.name) + |
177 '&script=' + encodeURIComponent(file) + | 178 '&script=' + encodeURIComponent(file) + |
178 '&line=' + encodeURIComponent(line) + | 179 '&line=' + encodeURIComponent(line) + |
179 '&trace=' + encodeURIComponent(filteredStack); | 180 '&trace=' + encodeURIComponent(filteredStack); |
180 var request = buildServerRequest('jserror'); | 181 var request = buildServerRequest('jserror', |
| 182 'application/x-www-form-urlencoded'); |
181 request.onloadend = function(event) { | 183 request.onloadend = function(event) { |
182 console.log('sendErrorReport status: ' + request.status); | 184 console.log('sendErrorReport status: ' + request.status); |
183 }; | 185 }; |
184 request.send(requestParameters); | 186 request.send(requestParameters); |
185 } | 187 } |
186 | 188 |
187 /** | 189 /** |
188 * Adds error processing to an API callback. | 190 * Adds error processing to an API callback. |
189 * @param {Function} callback Callback to instrument. | 191 * @param {Function} callback Callback to instrument. |
190 * @return {Function} Instrumented callback. | 192 * @return {Function} Instrumented callback. |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 if (alarm.name == alarmName) | 350 if (alarm.name == alarmName) |
349 attempt(); | 351 attempt(); |
350 }); | 352 }); |
351 | 353 |
352 return { | 354 return { |
353 start: start, | 355 start: start, |
354 planForNext: planForNext, | 356 planForNext: planForNext, |
355 stop: stop | 357 stop: stop |
356 }; | 358 }; |
357 } | 359 } |
OLD | NEW |