Chromium Code Reviews| 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 // HSTS is HTTPS Strict Transport Security: a way for sites to elect to always | |
|
eroman
2011/02/17 00:48:28
Thanks for adding this.
nit: Can you use the /***
agl
2011/02/17 17:21:30
Done.
| |
| 6 // use HTTPS. See http://dev.chromium.org/sts | |
| 7 // | |
| 8 // This UI allows a user to query and update the browser's list of HSTS domains. | |
| 9 | |
| 10 function HSTSView(mainBoxId, queryInputId, formId, queryOutputDivId, | |
| 11 addInputId, addFormId, addCheckId, | |
| 12 deleteInputId, deleteFormId) { | |
| 13 DivView.call(this, mainBoxId); | |
| 14 | |
| 15 this.queryInput_ = document.getElementById(queryInputId); | |
| 16 this.addCheck_ = document.getElementById(addCheckId); | |
| 17 this.addInput_ = document.getElementById(addInputId); | |
| 18 this.deleteInput_ = document.getElementById(deleteInputId); | |
| 19 this.queryOutputDiv_ = document.getElementById(queryOutputDivId); | |
| 20 | |
| 21 var form = document.getElementById(formId); | |
| 22 form.addEventListener('submit', this.onSubmitQuery_.bind(this), false); | |
| 23 form = document.getElementById(addFormId); | |
| 24 form.addEventListener('submit', this.onSubmitAdd_.bind(this), false); | |
| 25 form = document.getElementById(deleteFormId); | |
| 26 form.addEventListener('submit', this.onSubmitDelete_.bind(this), false); | |
| 27 | |
| 28 g_browser.addHSTSObserver(this); | |
| 29 } | |
| 30 | |
| 31 inherits(HSTSView, DivView); | |
| 32 | |
| 33 HSTSView.prototype.onSubmitQuery_ = function(event) { | |
| 34 g_browser.sendHSTSQuery(this.queryInput_.value); | |
| 35 event.preventDefault(); | |
| 36 }; | |
| 37 | |
| 38 HSTSView.prototype.onSubmitAdd_ = function(event) { | |
| 39 g_browser.sendHSTSAdd(this.addInput_.value, this.addCheck_.checked); | |
| 40 g_browser.sendHSTSQuery(this.addInput_.value); | |
| 41 this.queryInput_.value = this.addInput_.value; | |
| 42 this.addCheck_.checked = false; | |
| 43 this.addInput_.value = ''; | |
| 44 event.preventDefault(); | |
| 45 }; | |
| 46 | |
| 47 HSTSView.prototype.onSubmitDelete_ = function(event) { | |
| 48 g_browser.sendHSTSDelete(this.deleteInput_.value); | |
| 49 this.deleteInput_.value = ''; | |
| 50 event.preventDefault(); | |
| 51 }; | |
| 52 | |
| 53 function hstsModeToString(m) { | |
| 54 if (m == 0) { | |
| 55 return 'STRICT'; | |
| 56 } else if (m == 1) { | |
| 57 return 'OPPORTUNISTIC'; | |
| 58 } else if (m == 2) { | |
| 59 return 'SPDY'; | |
| 60 } else { | |
| 61 return 'UNKNOWN'; | |
| 62 } | |
| 63 } | |
| 64 | |
| 65 function yellowFade(element) { | |
| 66 element.style.webkitTransitionProperty = 'background-color'; | |
| 67 element.style.webkitTransitionDuration = '0'; | |
| 68 element.style.backgroundColor = '#fffccf'; | |
| 69 setTimeout(function() { | |
| 70 element.style.webkitTransitionDuration = '1000ms'; | |
| 71 element.style.backgroundColor = '#fff'; | |
| 72 }, 0); | |
| 73 } | |
| 74 | |
| 75 HSTSView.prototype.onHSTSQueryResult = function(result) { | |
| 76 if (result.error != undefined) { | |
| 77 this.queryOutputDiv_.innerHTML = ''; | |
| 78 s = addNode(this.queryOutputDiv_, 'span'); | |
| 79 s.innerText = result.error; | |
| 80 s.style.color = 'red'; | |
| 81 yellowFade(this.queryOutputDiv_); | |
| 82 return; | |
| 83 } | |
| 84 | |
| 85 if (result.result == false) { | |
| 86 this.queryOutputDiv_.innerHTML = '<b>Not found</b>'; | |
| 87 yellowFade(this.queryOutputDiv_); | |
| 88 return; | |
| 89 } | |
| 90 | |
| 91 this.queryOutputDiv_.innerHTML = ''; | |
| 92 | |
| 93 s = addNode(this.queryOutputDiv_, 'span'); | |
| 94 s.innerHTML = '<b>Found</b>: mode: '; | |
| 95 | |
| 96 t = document.createElement('tt'); | |
| 97 t.innerText = hstsModeToString(result.mode); | |
| 98 this.queryOutputDiv_.appendChild(t); | |
| 99 | |
| 100 addTextNode(this.queryOutputDiv_, ' include_subdomains:'); | |
| 101 | |
| 102 t = document.createElement('tt'); | |
|
eroman
2011/02/17 00:48:28
You can use addNode() for all these places that ar
agl
2011/02/17 17:21:30
Done.
| |
| 103 t.innerText = result.subdomains; | |
| 104 this.queryOutputDiv_.appendChild(t); | |
| 105 | |
| 106 addTextNode(this.queryOutputDiv_, ' domain:'); | |
| 107 | |
| 108 t = document.createElement('tt'); | |
| 109 t.innerText = result.domain; | |
| 110 this.queryOutputDiv_.appendChild(t); | |
| 111 | |
| 112 addTextNode(this.queryOutputDiv_, ' is_preloaded:'); | |
| 113 | |
| 114 t = document.createElement('tt'); | |
| 115 t.innerText = result.preloaded; | |
| 116 this.queryOutputDiv_.appendChild(t); | |
| 117 yellowFade(this.queryOutputDiv_); | |
| 118 } | |
| OLD | NEW |