Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: chrome/browser/resources/task_manager/main.js

Issue 8993007: WebUI TaskManager: Delay scripts loading. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: marge with master Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** @constructor */ 5 /** @constructor */
6 function TaskManager() { } 6 function TaskManager() { }
7 7
8 cr.addSingletonGetter(TaskManager); 8 cr.addSingletonGetter(TaskManager);
9 9
10 /* 10 /*
(...skipping 19 matching lines...) Expand all
30 ]; 30 ];
31 31
32 var COMMAND_CONTEXTMENU_COLUMN_PREFIX = 'columnContextMenu'; 32 var COMMAND_CONTEXTMENU_COLUMN_PREFIX = 'columnContextMenu';
33 var COMMAND_CONTEXTMENU_TABLE_PREFIX = 'tableContextMenu'; 33 var COMMAND_CONTEXTMENU_TABLE_PREFIX = 'tableContextMenu';
34 34
35 var localStrings = new LocalStrings(); 35 var localStrings = new LocalStrings();
36 36
37 TaskManager.prototype = { 37 TaskManager.prototype = {
38 /** 38 /**
39 * Handle window close. 39 * Handle window close.
40 * @public
41 */ 40 */
42 onClose: function () { 41 onClose: function () {
43 if (!this.disabled_) { 42 if (!this.disabled_) {
44 this.disabled_ = true; 43 this.disabled_ = true;
45 this.disableTaskManager(); 44 this.disableTaskManager();
46 } 45 }
47 }, 46 },
48 47
49 /** 48 /**
50 * Handle selection change. 49 * Handle selection change.
51 * This is also called when data of tasks are refleshed, even if selection 50 * This is also called when data of tasks are refleshed, even if selection
52 * has not been changed. 51 * has not been changed.
53 * @public
54 */ 52 */
55 onSelectionChange: function () { 53 onSelectionChange: function () {
56 var sm = this.selectionModel_; 54 var sm = this.selectionModel_;
57 var dm = this.dataModel_; 55 var dm = this.dataModel_;
58 var selectedIndexes = sm.selectedIndexes; 56 var selectedIndexes = sm.selectedIndexes;
59 var is_end_process_enabled = true; 57 var is_end_process_enabled = true;
60 if (selectedIndexes.length == 0) 58 if (selectedIndexes.length == 0)
61 is_end_process_enabled = false; 59 is_end_process_enabled = false;
62 for (var i = 0; i < selectedIndexes.length; i++) { 60 for (var i = 0; i < selectedIndexes.length; i++) {
63 var index = selectedIndexes[i]; 61 var index = selectedIndexes[i];
64 var task = dm.item(index); 62 var task = dm.item(index);
65 if (task['type'] == 'BROWSER') 63 if (task['type'] == 'BROWSER')
66 is_end_process_enabled = false; 64 is_end_process_enabled = false;
67 } 65 }
68 if (this.is_end_process_enabled_ != is_end_process_enabled) { 66 if (this.is_end_process_enabled_ != is_end_process_enabled) {
69 if (is_end_process_enabled) 67 if (is_end_process_enabled)
70 $('kill-process').removeAttribute("disabled"); 68 $('kill-process').removeAttribute("disabled");
71 else 69 else
72 $('kill-process').setAttribute("disabled", "true"); 70 $('kill-process').setAttribute("disabled", "true");
73 71
74 this.is_end_process_enabled_ = is_end_process_enabled; 72 this.is_end_process_enabled_ = is_end_process_enabled;
75 } 73 }
76 }, 74 },
77 75
78 /** 76 /**
79 * Closes taskmanager dialog. 77 * Closes taskmanager dialog.
80 * After this function is called, onClose() will be called. 78 * After this function is called, onClose() will be called.
81 * @public
82 */ 79 */
83 close: function () { 80 close: function () {
84 window.close(); 81 window.close();
85 }, 82 },
86 83
87 /** 84 /**
88 * Sends commands to kill selected processes. 85 * Sends commands to kill selected processes.
89 * @public
90 */ 86 */
91 killSelectedProcesses: function () { 87 killSelectedProcesses: function () {
92 var selectedIndexes = this.selectionModel_.selectedIndexes; 88 var selectedIndexes = this.selectionModel_.selectedIndexes;
93 var dm = this.dataModel_; 89 var dm = this.dataModel_;
94 var uniqueIds = []; 90 var uniqueIds = [];
95 for (var i = 0; i < selectedIndexes.length; i++) { 91 for (var i = 0; i < selectedIndexes.length; i++) {
96 var index = selectedIndexes[i]; 92 var index = selectedIndexes[i];
97 var task = dm.item(index); 93 var task = dm.item(index);
98 uniqueIds.push(task['uniqueId'][0]); 94 uniqueIds.push(task['uniqueId'][0]);
99 } 95 }
100 96
101 chrome.send('killProcesses', uniqueIds); 97 chrome.send('killProcesses', uniqueIds);
102 }, 98 },
103 99
104 /** 100 /**
105 * Sends command to initiate resource inspection. 101 * Sends command to initiate resource inspection.
106 * @public
107 */ 102 */
108 inspect: function (uniqueId) { 103 inspect: function (uniqueId) {
109 chrome.send('inspect', [uniqueId]); 104 chrome.send('inspect', [uniqueId]);
110 }, 105 },
111 106
112 /** 107 /**
113 * Sends command to kill a process. 108 * Sends command to kill a process.
114 * @public
115 */ 109 */
116 openAboutMemory: function () { 110 openAboutMemory: function () {
117 chrome.send('openAboutMemory'); 111 chrome.send('openAboutMemory');
118 }, 112 },
119 113
120 /** 114 /**
121 * Sends command to disable taskmanager model. 115 * Sends command to disable taskmanager model.
122 * @public
123 */ 116 */
124 disableTaskManager: function () { 117 disableTaskManager: function () {
125 chrome.send('disableTaskManager'); 118 chrome.send('disableTaskManager');
126 }, 119 },
127 120
128 /** 121 /**
129 * Sends command to enable taskmanager model. 122 * Sends command to enable taskmanager model.
130 * @public
131 */ 123 */
132 enableTaskManager: function () { 124 enableTaskManager: function () {
133 chrome.send('enableTaskManager'); 125 chrome.send('enableTaskManager');
134 }, 126 },
135 127
136 /** 128 /**
137 * Sends command to activate a page. 129 * Sends command to activate a page.
138 * @public
139 */ 130 */
140 activatePage: function (uniqueId) { 131 activatePage: function (uniqueId) {
141 chrome.send('activatePage', [uniqueId]); 132 chrome.send('activatePage', [uniqueId]);
142 }, 133 },
143 134
144 /** 135 /**
145 * Initializes taskmanager. 136 * Initializes taskmanager.
146 * @public
147 */ 137 */
148 initialize: function (dialogDom, opt) { 138 initialize: function (dialogDom, opt) {
149 if (!dialogDom) { 139 if (!dialogDom) {
150 console.log('ERROR: dialogDom is not defined.'); 140 console.log('ERROR: dialogDom is not defined.');
151 return; 141 return;
152 } 142 }
153 143
144 measureTime.startInterval('Load.DOM');
145
154 this.opt_ = opt; 146 this.opt_ = opt;
155 147
156 this.initialized_ = true; 148 this.initialized_ = true;
157 this.enableTaskManager(); 149 this.enableTaskManager();
158 150
159 this.dialogDom_ = dialogDom; 151 this.dialogDom_ = dialogDom;
160 this.document_ = dialogDom.ownerDocument; 152 this.document_ = dialogDom.ownerDocument;
161 153
162 $('close-window').addEventListener('click', this.close.bind(this));
163 $('kill-process').addEventListener('click',
164 this.killSelectedProcesses.bind(this));
165 $('about-memory-link').addEventListener('click',
166 this.openAboutMemory.bind(this));
167
168 this.pendingTaskUpdates_ = []; 154 this.pendingTaskUpdates_ = [];
169 this.is_column_shown_ = []; 155 this.is_column_shown_ = [];
170 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) { 156 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) {
171 this.is_column_shown_[i] = DEFAULT_COLUMNS[i][3]; 157 this.is_column_shown_[i] = DEFAULT_COLUMNS[i][3];
172 } 158 }
173 159
174 this.localized_column_ = []; 160 this.localized_column_ = [];
175 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) { 161 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) {
176 var column_label_id = DEFAULT_COLUMNS[i][1]; 162 var column_label_id = DEFAULT_COLUMNS[i][1];
177 var localized_label = localStrings.getString(column_label_id); 163 var localized_label = localStrings.getString(column_label_id);
178 // Falls back to raw column_label_id if localized string is not defined. 164 // Falls back to raw column_label_id if localized string is not defined.
179 if (localized_label == "") 165 if (localized_label == "")
180 localized_label = column_label_id; 166 localized_label = column_label_id;
181 167
182 this.localized_column_[i] = localized_label; 168 this.localized_column_[i] = localized_label;
183 } 169 }
184 170
171 this.initElements_();
185 this.initColumnModel_(); 172 this.initColumnModel_();
186 this.selectionModel_ = new cr.ui.ListSelectionModel(); 173 this.selectionModel_ = new cr.ui.ListSelectionModel();
187 this.dataModel_ = new cr.ui.ArrayDataModel([]); 174 this.dataModel_ = new cr.ui.ArrayDataModel([]);
188 175
189 this.selectionModel_.addEventListener('change', 176 this.selectionModel_.addEventListener('change',
190 this.onSelectionChange.bind(this)); 177 this.onSelectionChange.bind(this));
191 178
192 // Initializes compare functions for column sort. 179 // Initializes compare functions for column sort.
193 var dm = this.dataModel_; 180 var dm = this.dataModel_;
194 // Columns to sort by value instead of itself. 181 // Columns to sort by value instead of itself.
(...skipping 11 matching lines...) Expand all
206 var aValues = a[value_id]; 193 var aValues = a[value_id];
207 var bValues = b[value_id]; 194 var bValues = b[value_id];
208 var aValue = aValues && aValues[0] || 0; 195 var aValue = aValues && aValues[0] || 0;
209 var bvalue = bValues && bValues[0] || 0; 196 var bvalue = bValues && bValues[0] || 0;
210 return dm.defaultValuesCompareFunction(aValue, bvalue); 197 return dm.defaultValuesCompareFunction(aValue, bvalue);
211 }; 198 };
212 }(); 199 }();
213 dm.setCompareFunction(column_id, compare_func); 200 dm.setCompareFunction(column_id, compare_func);
214 } 201 }
215 202
216 var ary = this.dialogDom_.querySelectorAll('[visibleif]'); 203 this.initTable_();
217 for (var i = 0; i < ary.length; i++) { 204
218 var expr = ary[i].getAttribute('visibleif'); 205 // Populate the static localized strings.
219 if (!eval(expr)) 206 i18nTemplate.process(this.document_, templateData);
220 ary[i].hidden = true; 207
208 measureTime.recordInterval('Load.DOM');
209 measureTime.recordInterval('Load.Total');
210
211 loadDelayedIncludes(this);
212 },
213
214 /**
215 * Initializes the visibilities and handlers of the elements.
216 * This method is called by initialize().
217 * @private
218 */
219 initElements_: function() {
220 // <if expr="pp_ifdef('chromeos')">
221 // The elements 'dialog-title' and 'close-window' exist only on ChromeOS.
222 // This <if ... /if> section is removed while flattening HTML if chrome is
223 // built as Desktop Chrome.
224 if (!this.opt_['isShowTitle'])
225 $('dialog-title').style.display = 'none';
226 if (!this.opt_['isShowCloseButton'])
227 $('close-window').style.display = 'none';
228 $('close-window').addEventListener('click', this.close.bind(this));
229 // </if>
230
231 $('kill-process').addEventListener('click',
232 this.killSelectedProcesses.bind(this));
233 $('about-memory-link').addEventListener('click',
234 this.openAboutMemory.bind(this));
235 },
236
237 /**
238 * Additional initialization of taskmanager. This function is called when
239 * the loading of delayed scripts finished.
240 */
241 delayedInitialize: function() {
242 this.initColumnMenu_();
243 this.initTableMenu_();
244
245 var dm = this.dataModel_;
246 for (var i = 0; i < dm.length; i++) {
247 for (var j = 0; j < DEFAULT_COLUMNS.length; j++) {
248 var columnId = DEFAULT_COLUMNS[j][0];
249 var row = dm.item(i)[columnId];
250 for (var k = 0; k < row.length; k++) {
251 var processId = dm.item(i)['processId'][0];
252 var labelId = 'detail-' + columnId + '-pid' + processId + '-' + k;
253 var label = $(labelId);
254
255 // Initialize a context-menu, if the label exists and its context-
256 // menu is not initialized yet.
257 if (label && !label.contextMenu)
258 cr.ui.contextMenuHandler.setContextMenu(label,
259 this.tableContextMenu_);
260 }
261 }
221 } 262 }
222 263
223 this.initTable_(); 264 this.isFinishedInitDelayed_ = true;
224 this.initColumnMenu_();
225 this.initTableMenu_();
226 this.table_.redraw(); 265 this.table_.redraw();
227 }, 266 },
228 267
229 initColumnModel_: function () { 268 initColumnModel_: function () {
230 var table_columns = new Array(); 269 var table_columns = new Array();
231 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) { 270 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) {
232 if (!this.is_column_shown_[i]) 271 if (!this.is_column_shown_[i])
233 continue; 272 continue;
234 273
235 var column = DEFAULT_COLUMNS[i]; 274 var column = DEFAULT_COLUMNS[i];
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 command.menuitem = item; 307 command.menuitem = item;
269 item.textContent = this.localized_column_[i]; 308 item.textContent = this.localized_column_[i];
270 if (this.is_column_shown_[i]) 309 if (this.is_column_shown_[i])
271 item.setAttributeNode(this.document_.createAttribute("checked")); 310 item.setAttributeNode(this.document_.createAttribute("checked"));
272 this.columnSelectContextMenu_.appendChild(item); 311 this.columnSelectContextMenu_.appendChild(item);
273 } 312 }
274 313
275 this.document_.body.appendChild(this.columnSelectContextMenu_); 314 this.document_.body.appendChild(this.columnSelectContextMenu_);
276 cr.ui.Menu.decorate(this.columnSelectContextMenu_); 315 cr.ui.Menu.decorate(this.columnSelectContextMenu_);
277 316
278 cr.ui.contextMenuHandler.addContextMenuProperty(this.table_.header); 317 cr.ui.contextMenuHandler.setContextMenu(this.table_.header,
279 this.table_.header.contextMenu = this.columnSelectContextMenu_; 318 this.columnSelectContextMenu_);
280 319 cr.ui.contextMenuHandler.setContextMenu(this.table_.list,
281 cr.ui.contextMenuHandler.addContextMenuProperty(this.table_.list); 320 this.columnSelectContextMenu_);
282 this.table_.list.contextMenu = this.columnSelectContextMenu_;
283 321
284 this.document_.addEventListener('command', this.onCommand_.bind(this)); 322 this.document_.addEventListener('command', this.onCommand_.bind(this));
285 this.document_.addEventListener('canExecute', 323 this.document_.addEventListener('canExecute',
286 this.onCommandCanExecute_.bind(this)); 324 this.onCommandCanExecute_.bind(this));
287
288 }, 325 },
289 326
290 initTableMenu_: function () { 327 initTableMenu_: function () {
291 this.table_menu_commands_ = []; 328 this.table_menu_commands_ = [];
292 this.tableContextMenu_ = this.document_.createElement('menu'); 329 this.tableContextMenu_ = this.document_.createElement('menu');
293 330
294 var addMenuItem = function (tm, command_id, string_id, default_label) { 331 var addMenuItem = function (tm, command_id, string_id, default_label) {
295 // Creates command element to receive event. 332 // Creates command element to receive event.
296 var command = tm.document_.createElement('command'); 333 var command = tm.document_.createElement('command');
297 command.id = COMMAND_CONTEXTMENU_TABLE_PREFIX + '-' + command_id; 334 command.id = COMMAND_CONTEXTMENU_TABLE_PREFIX + '-' + command_id;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 cell.appendChild( 391 cell.appendChild(
355 cm.getRenderFunction(i).call(null, dataItem, cm.getId(i), table)); 392 cm.getRenderFunction(i).call(null, dataItem, cm.getId(i), table));
356 393
357 listItem.appendChild(cell); 394 listItem.appendChild(cell);
358 } 395 }
359 listItem.data = dataItem; 396 listItem.data = dataItem;
360 397
361 return listItem; 398 return listItem;
362 }, 399 },
363 400
401
364 renderColumn_: function(entry, columnId, table) { 402 renderColumn_: function(entry, columnId, table) {
365 var container = this.document_.createElement('div'); 403 var container = this.document_.createElement('div');
366 container.className = 'detail-container-' + columnId; 404 container.className = 'detail-container-' + columnId;
367 405
368 if (entry && entry[columnId]) { 406 if (entry && entry[columnId]) {
369 container.id = 'detail-container-' + columnId + '-pid' + entry.processId; 407 container.id = 'detail-container-' + columnId + '-pid' + entry.processId;
370 408
371 for (var i = 0; i < entry[columnId].length; i++) { 409 for (var i = 0; i < entry[columnId].length; i++) {
372 var label = document.createElement('div'); 410 var label = document.createElement('div');
373 if (columnId == 'title') { 411 if (columnId == 'title') {
374 var image = this.document_.createElement('img'); 412 var image = this.document_.createElement('img');
375 image.className = 'detail-title-image'; 413 image.className = 'detail-title-image';
376 image.src = entry['icon'][i]; 414 image.src = entry['icon'][i];
377 label.appendChild(image); 415 label.appendChild(image);
378 var text = this.document_.createElement('div'); 416 var text = this.document_.createElement('div');
379 text.className = 'detail-title-text'; 417 text.className = 'detail-title-text';
380 text.textContent = entry['title'][i]; 418 text.textContent = entry['title'][i];
381 label.appendChild(text); 419 label.appendChild(text);
382 420
383 cr.ui.contextMenuHandler.addContextMenuProperty(label); 421 // Chech if the delayed scripts (included in includes.js) have been
384 label.contextMenu = this.tableContextMenu_; 422 // loaded or not. If the delayed scripts ware not loaded yet, a
423 // context menu could not be initialized. In such case, it will be
424 // initialized at delayedInitialize() just after loading of delayed
425 // scripts instead of here.
426 if (this.isFinishedInitDelayed_)
427 cr.ui.contextMenuHandler.setContextMenu(label,
428 this.tableContextMenu_);
385 429
386 label.addEventListener('dblclick', (function(uniqueId) { 430 label.addEventListener('dblclick', (function(uniqueId) {
387 this.activatePage(uniqueId); 431 this.activatePage(uniqueId);
388 }).bind(this, entry['uniqueId'][i])); 432 }).bind(this, entry['uniqueId'][i]));
389 433
390 label.data = entry; 434 label.data = entry;
391 label.index_in_group = i; 435 label.index_in_group = i;
392 } else { 436 } else {
393 label.textContent = entry[columnId][i]; 437 label.textContent = entry[columnId][i];
394 } 438 }
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 547
504 onCommandCanExecute_: function(event) { 548 onCommandCanExecute_: function(event) {
505 event.canExecute = true; 549 event.canExecute = true;
506 }, 550 },
507 551
508 /** 552 /**
509 * Store resourceIndex of target resource of context menu, because resource 553 * Store resourceIndex of target resource of context menu, because resource
510 * will be replaced when it is refleshed. 554 * will be replaced when it is refleshed.
511 */ 555 */
512 onTableContextMenuOpened_: function (e) { 556 onTableContextMenuOpened_: function (e) {
557 if (!this.isFinishedInitDelayed_)
558 return;
559
513 var mc = this.table_menu_commands_; 560 var mc = this.table_menu_commands_;
514 var inspect_menuitem = 561 var inspect_menuitem =
515 mc[COMMAND_CONTEXTMENU_TABLE_PREFIX + '-inspect'].menuitem; 562 mc[COMMAND_CONTEXTMENU_TABLE_PREFIX + '-inspect'].menuitem;
516 var activate_menuitem = 563 var activate_menuitem =
517 mc[COMMAND_CONTEXTMENU_TABLE_PREFIX + '-activate'].menuitem; 564 mc[COMMAND_CONTEXTMENU_TABLE_PREFIX + '-activate'].menuitem;
518 565
519 // Disabled by default. 566 // Disabled by default.
520 inspect_menuitem.disabled = true; 567 inspect_menuitem.disabled = true;
521 activate_menuitem.disabled = true; 568 activate_menuitem.disabled = true;
522 569
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 return; 657 return;
611 taskmanager.onTaskChange(start, length, tasks); 658 taskmanager.onTaskChange(start, length, tasks);
612 } 659 }
613 660
614 function taskRemoved(start, length) { 661 function taskRemoved(start, length) {
615 // Sometimes this can get called too early. 662 // Sometimes this can get called too early.
616 if (!taskmanager) 663 if (!taskmanager)
617 return; 664 return;
618 taskmanager.onTaskRemove(start, length); 665 taskmanager.onTaskRemove(start, length);
619 } 666 }
620
OLDNEW
« no previous file with comments | « chrome/browser/resources/task_manager/main.html ('k') | chrome/browser/resources/task_manager/measure_time.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698