OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 cr.define('errorCodes', function() { |
| 6 'use strict'; |
| 7 |
| 8 /** |
| 9 * Generate the page content. |
| 10 * @param {Array.<Object>} errorCodes Error codes array consisting of a |
| 11 * numerical error ID and error code string. |
| 12 */ |
| 13 function listErrorCodes(errorCodes) { |
| 14 var errorPageUrl = 'chrome://network-error/'; |
| 15 var errorCodesList = document.createElement('ul'); |
| 16 for (var i = 0; i < errorCodes.length; i++) { |
| 17 var listEl = document.createElement('li'); |
| 18 var errorCodeLinkEl = document.createElement('a'); |
| 19 errorCodeLinkEl.href = errorPageUrl + errorCodes[i].errorId; |
| 20 errorCodeLinkEl.textContent = errorCodes[i].errorCode + ' (' + |
| 21 errorCodes[i].errorId + ')'; |
| 22 listEl.appendChild(errorCodeLinkEl); |
| 23 errorCodesList.appendChild(listEl); |
| 24 } |
| 25 $('pages').appendChild(errorCodesList); |
| 26 } |
| 27 |
| 28 function initialize() { |
| 29 var xhr = new XMLHttpRequest(); |
| 30 xhr.open('GET', 'network-error-data.json'); |
| 31 xhr.addEventListener('load', function(e) { |
| 32 if (xhr.status === 200) { |
| 33 try { |
| 34 var data = JSON.parse(xhr.responseText); |
| 35 listErrorCodes(data['errorCodes']); |
| 36 } catch (e) { |
| 37 $('pages').innerText = 'Could not parse the error codes data. ' + |
| 38 'Try reloading the page.'; |
| 39 } |
| 40 } |
| 41 }); |
| 42 xhr.send(); |
| 43 } |
| 44 |
| 45 return { |
| 46 initialize: initialize |
| 47 }; |
| 48 }); |
| 49 |
| 50 document.addEventListener('DOMContentLoaded', errorCodes.initialize); |
OLD | NEW |