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 function HSTSView(mainBoxId, queryInputId, formId, queryOutputDivId, |
| 6 addInputId, addFormId, addCheckId, deleteInputId, deleteFormId
) { |
| 7 DivView.call(this, mainBoxId); |
| 8 |
| 9 this.queryInput_ = document.getElementById(queryInputId); |
| 10 this.addCheck_ = document.getElementById(addCheckId); |
| 11 this.addInput_ = document.getElementById(addInputId); |
| 12 this.deleteInput_ = document.getElementById(deleteInputId); |
| 13 this.queryOutputDiv_ = document.getElementById(queryOutputDivId); |
| 14 |
| 15 var form = document.getElementById(formId); |
| 16 form.addEventListener('submit', this.onSubmitQuery_.bind(this), false); |
| 17 form = document.getElementById(addFormId); |
| 18 form.addEventListener('submit', this.onSubmitAdd_.bind(this), false); |
| 19 form = document.getElementById(deleteFormId); |
| 20 form.addEventListener('submit', this.onSubmitDelete_.bind(this), false); |
| 21 |
| 22 g_browser.hstsQueryCallback = this.onQueryCallback_.bind(this); |
| 23 } |
| 24 |
| 25 inherits(HSTSView, DivView); |
| 26 |
| 27 HSTSView.prototype.onSubmitQuery_ = function(event) { |
| 28 g_browser.sendHSTSQuery(this.queryInput_.value); |
| 29 event.preventDefault(); |
| 30 }; |
| 31 |
| 32 HSTSView.prototype.onSubmitAdd_ = function(event) { |
| 33 g_browser.sendHSTSAdd(this.addInput_.value, this.addCheck_.checked); |
| 34 g_browser.sendHSTSQuery(this.addInput_.value); |
| 35 this.queryInput_.value = this.addInput_.value; |
| 36 this.addCheck_.checked = false; |
| 37 this.addInput_.value = ""; |
| 38 event.preventDefault(); |
| 39 }; |
| 40 |
| 41 HSTSView.prototype.onSubmitDelete_ = function(event) { |
| 42 g_browser.sendHSTSDelete(this.deleteInput_.value); |
| 43 this.deleteInput_.value = ""; |
| 44 event.preventDefault(); |
| 45 }; |
| 46 |
| 47 function hstsModeToString(m) { |
| 48 if (m == 0) { |
| 49 return "STRICT"; |
| 50 } else if (m == 1) { |
| 51 return "OPPORTUNISTIC"; |
| 52 } else if (m == 2) { |
| 53 return "SPDY"; |
| 54 } else { |
| 55 return "UNKNOWN"; |
| 56 } |
| 57 } |
| 58 |
| 59 function yellowFade(element) { |
| 60 element.style.webkitTransitionProperty = "background-color"; |
| 61 element.style.webkitTransitionDuration = "0"; |
| 62 element.style.backgroundColor = "#fffccf"; |
| 63 setTimeout(function() { |
| 64 element.style.webkitTransitionDuration = "1000ms"; |
| 65 element.style.backgroundColor = "#fff"; |
| 66 }, 0); |
| 67 } |
| 68 |
| 69 HSTSView.prototype.onQueryCallback_ = function(result) { |
| 70 if (result.result == false) { |
| 71 this.queryOutputDiv_.innerHTML = "<b>Not found</b>"; |
| 72 } else { |
| 73 this.queryOutputDiv_.innerHTML = "<b>Found</b>: mode: <tt>" + |
| 74 hstsModeToString(result.mode) + |
| 75 "</tt> include_subdomains: <tt>" + |
| 76 result.subdomains + |
| 77 "</tt> domain: <tt>" + |
| 78 result.domain + |
| 79 "</tt> is_preloaded: <tt>" + |
| 80 result.preloaded + |
| 81 "</tt>"; |
| 82 } |
| 83 yellowFade(this.queryOutputDiv_); |
| 84 } |
OLD | NEW |