summaryrefslogtreecommitdiff
path: root/chromium/chrome/browser/resources/apps_debugger/js/items.js
blob: 5ff959eaed03d15152227f16aeeb1d0d5a8132b0 (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
// Copyright (c) 2012 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.

cr.define('apps_dev_tool', function() {
  'use strict';

  /**
   * AppsDevTool constructor.
   * @constructor
   * @extends {HTMLDivElement}
   */
  function AppsDevTool() {}

  AppsDevTool.prototype = {
    __proto__: HTMLDivElement.prototype,

    /**
     * Perform initial setup.
     */
    initialize: function() {
      cr.ui.decorate('tabbox', cr.ui.TabBox);

      // Set up the three buttons (load unpacked, pack and update).
      document.querySelector('#apps-tab .load-unpacked').
          addEventListener('click', this.handleLoadUnpackedItem_.bind(this));
      document.querySelector('#extensions-tab .load-unpacked').
          addEventListener('click', this.handleLoadUnpackedItem_.bind(this));
      document.querySelector('#apps-tab .update-items-now').
          addEventListener('click', this.handleUpdateItemNow_.bind(this,
          document.querySelector('#apps-tab .update-items-progress')));
      document.querySelector('#extensions-tab .update-items-now').
          addEventListener('click', this.handleUpdateItemNow_.bind(this,
          document.querySelector('#extensions-tab .update-items-progress')));
      var packItemOverlay =
          apps_dev_tool.PackItemOverlay.getInstance().initializePage();

      preventDefaultOnPoundLinkClicks();  // From webui/js/util.js
    },

    /**
     * Handles the Load Unpacked Extension button.
     * @param {!Event} e Click event.
     * @private
     */
    handleLoadUnpackedItem_: function(e) {
      chrome.developerPrivate.loadUnpacked();
    },

    /**
     * Handles the Update Extension Now Button.
     * @param {!Element} tabNode Element containing the progress label.
     * @param {!Event} e Click event.
     * @private
     */
    handleUpdateItemNow_: function(progressLabelNode, e) {
      progressLabelNode.classList.add('updating');
      chrome.developerPrivate.autoUpdate(function(response) {
        // autoUpdate() will run too fast. We wait for 2 sec
        // before hiding the label so that the user can see it.
        setTimeout(function() {
          progressLabelNode.classList.remove('updating');
        }, 2000);
      });
    },
  };

  /**
   * Returns the current overlay or null if one does not exist.
   * @return {Element} The overlay element.
   */
  AppsDevTool.getCurrentOverlay = function() {
    return document.querySelector('#overlay .page.showing');
  };

  /**
   * Shows |el|. If there's another overlay showing, hide it.
   * @param {HTMLElement} el The overlay page to show. If falsey, all overlays
   *     are hidden.
   */
  AppsDevTool.showOverlay = function(el) {
    var currentlyShowingOverlay = AppsDevTool.getCurrentOverlay();
    if (currentlyShowingOverlay)
      currentlyShowingOverlay.classList.remove('showing');
    if (el)
      el.classList.add('showing');
    overlay.hidden = !el;
    uber.invokeMethodOnParent(el ? 'beginInterceptingEvents' :
                                   'stopInterceptingEvents');
  };

  /**
   * Loads translated strings.
   */
  AppsDevTool.initStrings = function() {
    chrome.developerPrivate.getStrings(function(strings) {
      loadTimeData.data = strings;
      i18nTemplate.process(document, loadTimeData);

      // Check managed profiles.
      chrome.developerPrivate.isProfileManaged(function(isManaged) {
        if (!isManaged)
          return;
        alertOverlay.setValues(
            loadTimeData.getString('managedProfileDialogTitle'),
            loadTimeData.getString('managedProfileDialogDescription'),
            loadTimeData.getString('managedProfileDialogCloseButton'),
            null,
            function() {
              AppsDevTool.showOverlay(null);
              window.close();
            },
            null);
        AppsDevTool.showOverlay($('alertOverlay'));
      });
    });
  };

  return {
    AppsDevTool: AppsDevTool,
  };
});