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