summaryrefslogtreecommitdiffstats
path: root/chromium/chrome/browser/resources/extensions/load_error.js
blob: be8d902255409e09470b6afe9ee9fc195e9f2bd6 (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
// Copyright 2017 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('extensions', function() {
  'use strict';

  /** @interface */
  class LoadErrorDelegate {
    /**
     * Attempts to load the previously-attempted unpacked extension.
     * @param {string} retryId
     * @return {!Promise}
     */
    retryLoadUnpacked(retryId) {}
  }

  const LoadError = Polymer({
    is: 'extensions-load-error',
    properties: {
      /** @type {extensions.LoadErrorDelegate} */
      delegate: Object,

      /** @type {chrome.developerPrivate.LoadError} */
      loadError: Object,

      /** @private */
      retrying_: Boolean,
    },

    observers: [
      'observeLoadErrorChanges_(loadError)',
    ],

    show: function() {
      /** @type {!CrDialogElement} */ (this.$.dialog).showModal();
    },

    close: function() {
      /** @type {!CrDialogElement} */ (this.$.dialog).close();
    },

    /** @private */
    onRetryTap_: function() {
      this.retrying_ = true;
      this.delegate.retryLoadUnpacked(this.loadError.retryGuid)
          .then(
              () => {
                this.close();
              },
              loadError => {
                this.loadError =
                    /** @type {chrome.developerPrivate.LoadError} */ (
                        loadError);
                this.retrying_ = false;
              });
    },

    /** @private */
    observeLoadErrorChanges_: function() {
      assert(this.loadError);
      const source = this.loadError.source;
      // CodeSection expects a RequestFileSourceResponse, rather than an
      // ErrorFileSource. Massage into place.
      // TODO(devlin): Make RequestFileSourceResponse use ErrorFileSource.
      /** @type {!chrome.developerPrivate.RequestFileSourceResponse} */
      const codeSectionProperties = {
        beforeHighlight: source ? source.beforeHighlight : '',
        highlight: source ? source.highlight : '',
        afterHighlight: source ? source.afterHighlight : '',
        title: '',
        message: this.loadError.error,
      };

      this.$.code.code = codeSectionProperties;
    },
  });

  return {LoadError: LoadError, LoadErrorDelegate: LoadErrorDelegate};
});