| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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 /** | |
| 6 * HSTS is HTTPS Strict Transport Security: a way for sites to elect to always | |
| 7 * use HTTPS. See http://dev.chromium.org/sts | |
| 8 * | |
| 9 * This UI allows a user to query and update the browser's list of HSTS domains. | |
| 10 | |
| 11 * @constructor | |
| 12 */ | |
| 13 function HSTSView() { | |
| 14 const mainBoxId = 'hstsTabContent'; | |
| 15 const queryInputId = 'hstsQueryInput'; | |
| 16 const formId = 'hstsQueryForm'; | |
| 17 const queryOutputDivId = 'hstsQueryOutput'; | |
| 18 const addInputId = 'hstsAddInput'; | |
| 19 const addFormId = 'hstsAddForm'; | |
| 20 const addCheckId = 'hstsCheckInput'; | |
| 21 const addPinsId = 'hstsAddPins'; | |
| 22 const deleteInputId = 'hstsDeleteInput'; | |
| 23 const deleteFormId = 'hstsDeleteForm'; | |
| 24 | |
| 25 DivView.call(this, mainBoxId); | |
| 26 | |
| 27 this.queryInput_ = $(queryInputId); | |
| 28 this.addCheck_ = $(addCheckId); | |
| 29 this.addInput_ = $(addInputId); | |
| 30 this.addPins_ = $(addPinsId); | |
| 31 this.deleteInput_ = $(deleteInputId); | |
| 32 this.queryOutputDiv_ = $(queryOutputDivId); | |
| 33 | |
| 34 var form = $(formId); | |
| 35 form.addEventListener('submit', this.onSubmitQuery_.bind(this), false); | |
| 36 form = $(addFormId); | |
| 37 form.addEventListener('submit', this.onSubmitAdd_.bind(this), false); | |
| 38 form = $(deleteFormId); | |
| 39 form.addEventListener('submit', this.onSubmitDelete_.bind(this), false); | |
| 40 | |
| 41 g_browser.addHSTSObserver(this); | |
| 42 } | |
| 43 | |
| 44 inherits(HSTSView, DivView); | |
| 45 | |
| 46 HSTSView.prototype.onSubmitQuery_ = function(event) { | |
| 47 g_browser.sendHSTSQuery(this.queryInput_.value); | |
| 48 event.preventDefault(); | |
| 49 }; | |
| 50 | |
| 51 HSTSView.prototype.onSubmitAdd_ = function(event) { | |
| 52 g_browser.sendHSTSAdd(this.addInput_.value, | |
| 53 this.addCheck_.checked, | |
| 54 this.addPins_.value); | |
| 55 g_browser.sendHSTSQuery(this.addInput_.value); | |
| 56 this.queryInput_.value = this.addInput_.value; | |
| 57 this.addCheck_.checked = false; | |
| 58 this.addInput_.value = ''; | |
| 59 this.addPins_.value = ''; | |
| 60 event.preventDefault(); | |
| 61 }; | |
| 62 | |
| 63 HSTSView.prototype.onSubmitDelete_ = function(event) { | |
| 64 g_browser.sendHSTSDelete(this.deleteInput_.value); | |
| 65 this.deleteInput_.value = ''; | |
| 66 event.preventDefault(); | |
| 67 }; | |
| 68 | |
| 69 function hstsModeToString(m) { | |
| 70 if (m == 0) { | |
| 71 return 'STRICT'; | |
| 72 } else if (m == 1) { | |
| 73 return 'OPPORTUNISTIC'; | |
| 74 } else if (m == 2) { | |
| 75 return 'SPDY'; | |
| 76 } else if (m == 3) { | |
| 77 return 'NONE'; | |
| 78 } else { | |
| 79 return 'UNKNOWN'; | |
| 80 } | |
| 81 } | |
| 82 | |
| 83 function yellowFade(element) { | |
| 84 element.style.webkitTransitionProperty = 'background-color'; | |
| 85 element.style.webkitTransitionDuration = '0'; | |
| 86 element.style.backgroundColor = '#fffccf'; | |
| 87 setTimeout(function() { | |
| 88 element.style.webkitTransitionDuration = '1000ms'; | |
| 89 element.style.backgroundColor = '#fff'; | |
| 90 }, 0); | |
| 91 } | |
| 92 | |
| 93 HSTSView.prototype.onHSTSQueryResult = function(result) { | |
| 94 if (result.error != undefined) { | |
| 95 this.queryOutputDiv_.innerHTML = ''; | |
| 96 s = addNode(this.queryOutputDiv_, 'span'); | |
| 97 s.textContent = result.error; | |
| 98 s.style.color = 'red'; | |
| 99 yellowFade(this.queryOutputDiv_); | |
| 100 return; | |
| 101 } | |
| 102 | |
| 103 if (result.result == false) { | |
| 104 this.queryOutputDiv_.innerHTML = '<b>Not found</b>'; | |
| 105 yellowFade(this.queryOutputDiv_); | |
| 106 return; | |
| 107 } | |
| 108 | |
| 109 this.queryOutputDiv_.innerHTML = ''; | |
| 110 | |
| 111 s = addNode(this.queryOutputDiv_, 'span'); | |
| 112 s.innerHTML = '<b>Found</b>: mode: '; | |
| 113 | |
| 114 t = addNode(this.queryOutputDiv_, 'tt'); | |
| 115 t.textContent = hstsModeToString(result.mode); | |
| 116 | |
| 117 addTextNode(this.queryOutputDiv_, ' include_subdomains:'); | |
| 118 | |
| 119 t = addNode(this.queryOutputDiv_, 'tt'); | |
| 120 t.textContent = result.subdomains; | |
| 121 | |
| 122 addTextNode(this.queryOutputDiv_, ' domain:'); | |
| 123 | |
| 124 t = addNode(this.queryOutputDiv_, 'tt'); | |
| 125 t.textContent = result.domain; | |
| 126 | |
| 127 addTextNode(this.queryOutputDiv_, ' is_preloaded:'); | |
| 128 | |
| 129 t = addNode(this.queryOutputDiv_, 'tt'); | |
| 130 t.textContent = result.preloaded; | |
| 131 | |
| 132 addTextNode(this.queryOutputDiv_, ' pubkey_hashes:'); | |
| 133 | |
| 134 t = addNode(this.queryOutputDiv_, 'tt'); | |
| 135 t.textContent = result.public_key_hashes; | |
| 136 | |
| 137 yellowFade(this.queryOutputDiv_); | |
| 138 } | |
| OLD | NEW |