summaryrefslogtreecommitdiffstats
path: root/chrome/browser/resources/net_internals/hstsview.js
blob: 10cfab6bf829c1510c1e3fe3c8697619f8350f66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/**
 * HSTS is HTTPS Strict Transport Security: a way for sites to elect to always
 * use HTTPS. See http://dev.chromium.org/sts
 *
 * This UI allows a user to query and update the browser's list of HSTS domains.

 *  @constructor
 */
function HSTSView(mainBoxId, queryInputId, formId, queryOutputDivId,
                  addInputId, addFormId, addCheckId, addPinsId,
                  deleteInputId, deleteFormId) {
  DivView.call(this, mainBoxId);

  this.queryInput_ = document.getElementById(queryInputId);
  this.addCheck_ = document.getElementById(addCheckId);
  this.addInput_ = document.getElementById(addInputId);
  this.addPins_ = document.getElementById(addPinsId);
  this.deleteInput_ = document.getElementById(deleteInputId);
  this.queryOutputDiv_ = document.getElementById(queryOutputDivId);

  var form = document.getElementById(formId);
  form.addEventListener('submit', this.onSubmitQuery_.bind(this), false);
  form = document.getElementById(addFormId);
  form.addEventListener('submit', this.onSubmitAdd_.bind(this), false);
  form = document.getElementById(deleteFormId);
  form.addEventListener('submit', this.onSubmitDelete_.bind(this), false);

  g_browser.addHSTSObserver(this);
}

inherits(HSTSView, DivView);

HSTSView.prototype.onSubmitQuery_ = function(event) {
  g_browser.sendHSTSQuery(this.queryInput_.value);
  event.preventDefault();
};

HSTSView.prototype.onSubmitAdd_ = function(event) {
  g_browser.sendHSTSAdd(this.addInput_.value,
                        this.addCheck_.checked,
                        this.addPins_.value);
  g_browser.sendHSTSQuery(this.addInput_.value);
  this.queryInput_.value = this.addInput_.value;
  this.addCheck_.checked = false;
  this.addInput_.value = '';
  this.addPins_.value = '';
  event.preventDefault();
};

HSTSView.prototype.onSubmitDelete_ = function(event) {
  g_browser.sendHSTSDelete(this.deleteInput_.value);
  this.deleteInput_.value = '';
  event.preventDefault();
};

function hstsModeToString(m) {
  if (m == 0) {
    return 'STRICT';
  } else if (m == 1) {
    return 'OPPORTUNISTIC';
  } else if (m == 2) {
    return 'SPDY';
  } else if (m == 3) {
    return 'NONE';
  } else {
    return 'UNKNOWN';
  }
}

function yellowFade(element) {
  element.style.webkitTransitionProperty = 'background-color';
  element.style.webkitTransitionDuration = '0';
  element.style.backgroundColor = '#fffccf';
  setTimeout(function() {
    element.style.webkitTransitionDuration = '1000ms';
    element.style.backgroundColor = '#fff';
  }, 0);
}

HSTSView.prototype.onHSTSQueryResult = function(result) {
  if (result.error != undefined) {
    this.queryOutputDiv_.innerHTML = '';
    s = addNode(this.queryOutputDiv_, 'span');
    s.textContent = result.error;
    s.style.color = 'red';
    yellowFade(this.queryOutputDiv_);
    return;
  }

  if (result.result == false) {
    this.queryOutputDiv_.innerHTML = '<b>Not found</b>';
    yellowFade(this.queryOutputDiv_);
    return;
  }

  this.queryOutputDiv_.innerHTML = '';

  s = addNode(this.queryOutputDiv_, 'span');
  s.innerHTML = '<b>Found</b>: mode: ';

  t = addNode(this.queryOutputDiv_, 'tt');
  t.textContent = hstsModeToString(result.mode);

  addTextNode(this.queryOutputDiv_, ' include_subdomains:');

  t = addNode(this.queryOutputDiv_, 'tt');
  t.textContent = result.subdomains;

  addTextNode(this.queryOutputDiv_, ' domain:');

  t = addNode(this.queryOutputDiv_, 'tt');
  t.textContent = result.domain;

  addTextNode(this.queryOutputDiv_, ' is_preloaded:');

  t = addNode(this.queryOutputDiv_, 'tt');
  t.textContent = result.preloaded;

  addTextNode(this.queryOutputDiv_, ' pubkey_hashes:');

  t = addNode(this.queryOutputDiv_, 'tt');
  t.textContent = result.public_key_hashes;

  yellowFade(this.queryOutputDiv_);
}