• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (c) 2012 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
5function highlightIfChanged(node, oldVal, newVal) {
6  function clearHighlight() {
7    this.removeAttribute('highlighted');
8  }
9
10  var oldStr = oldVal.toString();
11  var newStr = newVal.toString();
12  if (oldStr != '' && oldStr != newStr) {
13    // Note the addListener function does not end up creating duplicate
14    // listeners.  There can be only one listener per event at a time.
15    // Reference: https://developer.mozilla.org/en/DOM/element.addEventListener
16    node.addEventListener('webkitAnimationEnd', clearHighlight, false);
17    node.setAttribute('highlighted', '');
18  }
19}
20
21(function() {
22// Contains the latest snapshot of sync about info.
23chrome.sync.aboutInfo = {};
24
25// TODO(akalin): Make aboutInfo have key names likeThis and not
26// like_this.
27function refreshAboutInfo(aboutInfo) {
28  chrome.sync.aboutInfo = aboutInfo;
29  var aboutInfoDiv = $('aboutInfo');
30  jstProcess(new JsEvalContext(aboutInfo), aboutInfoDiv);
31}
32
33function onLoad() {
34  $('status-data').hidden = true;
35  chrome.sync.getAboutInfo(refreshAboutInfo);
36
37  chrome.sync.onServiceStateChanged.addListener(function() {
38    chrome.sync.getAboutInfo(refreshAboutInfo);
39  });
40
41  var dumpStatusButton = $('dump-status');
42  dumpStatusButton.addEventListener('click', function(event) {
43    var aboutInfo = chrome.sync.aboutInfo;
44    if (!$('include-ids').checked) {
45      aboutInfo.details = chrome.sync.aboutInfo.details.filter(function(el) {
46        return !el.is_sensitive;
47      });
48    }
49    var data = '';
50    data += new Date().toString() + '\n';
51    data += '======\n';
52    data += 'Status\n';
53    data += '======\n';
54    data += JSON.stringify(aboutInfo, null, 2) + '\n';
55
56    $('status-text').value = data;
57    $('status-data').hidden = false;
58  });
59
60  var importStatusButton = $('import-status');
61  importStatusButton.addEventListener('click', function(event) {
62    $('status-data').hidden = false;
63    if ($('status-text').value.length == 0) {
64      $('status-text').value = 'Paste sync status dump here then click import.';
65      return;
66    }
67
68    // First remove any characters before the '{'.
69    var data = $('status-text').value;
70    var firstBrace = data.indexOf('{');
71    if (firstBrace < 0) {
72      $('status-text').value = 'Invalid sync status dump.';
73      return;
74    }
75    data = data.substr(firstBrace);
76
77    // Remove listeners to prevent sync events from overwriting imported data.
78    chrome.sync.onServiceStateChanged.removeListeners();
79
80    var aboutInfo = JSON.parse(data);
81    refreshAboutInfo(aboutInfo);
82  });
83}
84
85document.addEventListener('DOMContentLoaded', onLoad, false);
86})();
87