forked from catapult-project/catapult
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prerender_view.js
96 lines (76 loc) · 2.93 KB
/
prerender_view.js
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
// 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.
/**
* This view displays information related to Prerendering.
*/
var PrerenderView = (function() {
'use strict';
// We inherit from DivView.
var superClass = DivView;
/**
* @constructor
*/
function PrerenderView() {
assertFirstConstructorCall(PrerenderView);
// Call superclass's constructor.
superClass.call(this, PrerenderView.MAIN_BOX_ID);
g_browser.addPrerenderInfoObserver(this, true);
}
PrerenderView.TAB_ID = 'tab-handle-prerender';
PrerenderView.TAB_NAME = 'Prerender';
PrerenderView.TAB_HASH = '#prerender';
// IDs for special HTML elements in prerender_view.html
PrerenderView.MAIN_BOX_ID = 'prerender-view-tab-content';
PrerenderView.PRERENDER_VIEW_ENABLED_ID =
'prerender-view-enabled';
PrerenderView.PRERENDER_VIEW_ENABLED_NOTE_ID =
'prerender-view-enabled-note';
PrerenderView.PRERENDER_VIEW_OMNIBOX_ENABLED_ID =
'prerender-view-omnibox-enabled';
PrerenderView.HISTORY_TABLE_ID = 'prerender-view-history-table';
PrerenderView.ACTIVE_TABLE_ID = 'prerender-view-active-table';
cr.addSingletonGetter(PrerenderView);
PrerenderView.prototype = {
// Inherit the superclass's methods.
__proto__: superClass.prototype,
onLoadLogFinish: function(data) {
return this.onPrerenderInfoChanged(data.prerenderInfo);
},
onPrerenderInfoChanged: function(prerenderInfo) {
if (!prerenderInfo)
return false;
$(PrerenderView.PRERENDER_VIEW_ENABLED_ID).textContent =
prerenderInfo.enabled;
$(PrerenderView.PRERENDER_VIEW_ENABLED_NOTE_ID).textContent =
prerenderInfo.enabled_note;
$(PrerenderView.PRERENDER_VIEW_OMNIBOX_ENABLED_ID).textContent =
prerenderInfo.omnibox_enabled;
var tbodyActive = $(PrerenderView.ACTIVE_TABLE_ID);
tbodyActive.innerHTML = '';
// Fill in Active Prerender Pages table
for (var i = 0; i < prerenderInfo.active.length; ++i) {
var a = prerenderInfo.active[i];
var tr = addNode(tbodyActive, 'tr');
addNodeWithText(tr, 'td', a.url);
addNodeWithText(tr, 'td', a.duration);
addNodeWithText(tr, 'td', a.is_loaded);
}
var tbodyHistory = $(PrerenderView.HISTORY_TABLE_ID);
tbodyHistory.innerHTML = '';
// Fill in Prerender History table
for (var i = 0; i < prerenderInfo.history.length; ++i) {
var h = prerenderInfo.history[i];
var tr = addNode(tbodyHistory, 'tr');
tr.className = h.final_status.toLowerCase();
addNodeWithText(tr, 'td', h.origin);
addNodeWithText(tr, 'td', h.url);
addNodeWithText(tr, 'td', h.final_status);
addNodeWithText(tr, 'td',
timeutil.dateToString(new Date(parseInt(h.end_time))));
}
return true;
}
};
return PrerenderView;
})();