summaryrefslogtreecommitdiffstats
path: root/chromium/chrome/browser/resources/discards/graph_tab.js
blob: c4538c5718f43e28cd9d4bb6922f1e604bba1243 (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
// Copyright 2018 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('graph_tab', function() {
  'use strict';
  /**
   * @implements {performanceManager.mojom.WebUIGraphChangeStreamInterface}
   */
  class WebUIGraphChangeStreamImpl {
    constructor(contentWindow) {
      this.contentWindow_ = contentWindow;
    }

    /**
     * @param {string} type
     * @param {Object|number} data
     */
    postMessage_(type, data) {
      this.contentWindow_.postMessage([type, data], '*');
    }

    /** @override */
    frameCreated(frame) {
      this.postMessage_('frameCreated', frame);
    }

    /** @override */
    pageCreated(page) {
      this.postMessage_('pageCreated', page);
    }

    /** @override */
    processCreated(process) {
      this.postMessage_('processCreated', process);
    }

    /** @override */
    frameChanged(frame) {
      this.postMessage_('frameChanged', frame);
    }

    /** @override */
    pageChanged(page) {
      this.postMessage_('pageChanged', page);
    }

    /** @override */
    processChanged(process) {
      this.postMessage_('processChanged', process);
    }

    /** @override */
    favIconDataAvailable(icon_info) {
      this.postMessage_('favIconDataAvailable', icon_info);
    }

    /** @override */
    nodeDeleted(nodeId) {
      this.postMessage_('nodeDeleted', nodeId);
    }
  }

  return {
    WebUIGraphChangeStreamImpl: WebUIGraphChangeStreamImpl,
  };
});

Polymer({
  is: 'graph-tab',

  /**
   * The Mojo graph data source.
   *
   * @private {performanceManager.mojom.WebUIGraphDumpRemote}
   */
  graphDump_: null,

  /**
   * The graph change listener.
   *
   * @private {performanceManager.mojom.WebUIGraphChangeStreamInterface}
   */
  changeListener_: null,

  /** @override */
  ready: function() {
    this.graphDump_ = performanceManager.mojom.WebUIGraphDump.getRemote();
  },

  /** @override */
  detached: function() {
    // TODO(siggi): Is there a way to tear down the binding explicitly?
    this.graphDump_ = null;
    this.changeListener_ = null;
  },

  /** @private */
  onWebViewReady_: function() {
    this.changeListener_ =
        new graph_tab.WebUIGraphChangeStreamImpl(this.$.webView.contentWindow);
    this.client_ = new performanceManager.mojom.WebUIGraphChangeStreamReceiver(
        this.changeListener_);
    // Save helper to work around closure compiler bug: https://crbug.com/969212
    const helper = this.client_.$;

    // Subscribe for graph updates.
    this.graphDump_.subscribeToChanges(helper.bindNewPipeAndPassRemote());
  },
});