OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 11 matching lines...) Expand all Loading... |
22 ['processId', 'PROCESS_ID_COLUMN', 100, false], | 22 ['processId', 'PROCESS_ID_COLUMN', 100, false], |
23 ['webCoreImageCacheSize', 'WEBCORE_IMAGE_CACHE_COLUMN', 120, false], | 23 ['webCoreImageCacheSize', 'WEBCORE_IMAGE_CACHE_COLUMN', 120, false], |
24 ['webCoreScriptsCacheSize', 'WEBCORE_SCRIPTS_CACHE_COLUMN', 120, false], | 24 ['webCoreScriptsCacheSize', 'WEBCORE_SCRIPTS_CACHE_COLUMN', 120, false], |
25 ['webCoreCSSCacheSize', 'WEBCORE_CSS_CACHE_COLUMN', 120, false], | 25 ['webCoreCSSCacheSize', 'WEBCORE_CSS_CACHE_COLUMN', 120, false], |
26 ['fps', 'FPS_COLUMN', 50, true], | 26 ['fps', 'FPS_COLUMN', 50, true], |
27 ['sqliteMemoryUsed', 'SQLITE_MEMORY_USED_COLUMN', 80, false], | 27 ['sqliteMemoryUsed', 'SQLITE_MEMORY_USED_COLUMN', 80, false], |
28 ['goatsTeleported', 'GOATS_TELEPORTED_COLUMN', 80, false], | 28 ['goatsTeleported', 'GOATS_TELEPORTED_COLUMN', 80, false], |
29 ['v8MemoryAllocatedSize', 'JAVASCRIPT_MEMORY_ALLOCATED_COLUMN', 120, false], | 29 ['v8MemoryAllocatedSize', 'JAVASCRIPT_MEMORY_ALLOCATED_COLUMN', 120, false], |
30 ]; | 30 ]; |
31 | 31 |
| 32 var COMMAND_CONTEXTMENU_COLUMN_PREFIX = 'columnContextMenu'; |
| 33 var COMMAND_CONTEXTMENU_TABLE_PREFIX = 'tableContextMenu'; |
| 34 |
32 var localStrings = new LocalStrings(); | 35 var localStrings = new LocalStrings(); |
33 | 36 |
34 TaskManager.prototype = { | 37 TaskManager.prototype = { |
35 /** | 38 /** |
36 * Handle window close. | 39 * Handle window close. |
37 * @public | 40 * @public |
38 */ | 41 */ |
39 onClose: function () { | 42 onClose: function () { |
40 if (!this.disabled_) { | 43 if (!this.disabled_) { |
41 this.disabled_ = true; | 44 this.disabled_ = true; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 | 119 |
117 /** | 120 /** |
118 * Sends command to enable taskmanager model. | 121 * Sends command to enable taskmanager model. |
119 * @public | 122 * @public |
120 */ | 123 */ |
121 enableTaskManager: function () { | 124 enableTaskManager: function () { |
122 chrome.send('enableTaskManager'); | 125 chrome.send('enableTaskManager'); |
123 }, | 126 }, |
124 | 127 |
125 /** | 128 /** |
| 129 * Sends command to activate a page. |
| 130 * @public |
| 131 */ |
| 132 activatePage: function (uniqueId) { |
| 133 chrome.send('activatePage', [uniqueId]); |
| 134 }, |
| 135 |
| 136 /** |
126 * Initializes taskmanager. | 137 * Initializes taskmanager. |
127 * @public | 138 * @public |
128 */ | 139 */ |
129 initialize: function (dialogDom, opt) { | 140 initialize: function (dialogDom, opt) { |
130 if (!dialogDom) { | 141 if (!dialogDom) { |
131 console.log('ERROR: dialogDom is not defined.'); | 142 console.log('ERROR: dialogDom is not defined.'); |
132 return; | 143 return; |
133 } | 144 } |
134 | 145 |
135 this.opt_ = opt; | 146 this.opt_ = opt; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 | 237 |
227 this.commandsElement_ = this.document_.createElement('commands'); | 238 this.commandsElement_ = this.document_.createElement('commands'); |
228 this.document_.body.appendChild(this.commandsElement_); | 239 this.document_.body.appendChild(this.commandsElement_); |
229 | 240 |
230 this.columnSelectContextMenu_ = this.document_.createElement('menu'); | 241 this.columnSelectContextMenu_ = this.document_.createElement('menu'); |
231 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) { | 242 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) { |
232 var column = DEFAULT_COLUMNS[i]; | 243 var column = DEFAULT_COLUMNS[i]; |
233 | 244 |
234 // Creates command element to receive event. | 245 // Creates command element to receive event. |
235 var command = this.document_.createElement('command'); | 246 var command = this.document_.createElement('command'); |
236 command.id = 'columnContextMenu-' + column[0]; | 247 command.id = COMMAND_CONTEXTMENU_COLUMN_PREFIX + '-' + column[0]; |
237 cr.ui.Command.decorate(command); | 248 cr.ui.Command.decorate(command); |
238 this.column_menu_commands_[command.id] = command; | 249 this.column_menu_commands_[command.id] = command; |
239 this.commandsElement_.appendChild(command); | 250 this.commandsElement_.appendChild(command); |
240 | 251 |
241 // Creates menuitem element. | 252 // Creates menuitem element. |
242 var item = this.document_.createElement('menuitem'); | 253 var item = this.document_.createElement('menuitem'); |
243 item.command = command; | 254 item.command = command; |
244 command.menuitem = item; | 255 command.menuitem = item; |
245 item.textContent = this.localized_column_[i]; | 256 item.textContent = this.localized_column_[i]; |
246 if (this.is_column_shown_[i]) | 257 if (this.is_column_shown_[i]) |
(...skipping 10 matching lines...) Expand all Loading... |
257 this.document_.addEventListener('command', this.onCommand_.bind(this)); | 268 this.document_.addEventListener('command', this.onCommand_.bind(this)); |
258 this.document_.addEventListener('canExecute', | 269 this.document_.addEventListener('canExecute', |
259 this.onCommandCanExecute_.bind(this)); | 270 this.onCommandCanExecute_.bind(this)); |
260 | 271 |
261 }, | 272 }, |
262 | 273 |
263 initTableMenu_: function () { | 274 initTableMenu_: function () { |
264 this.table_menu_commands_ = []; | 275 this.table_menu_commands_ = []; |
265 this.tableContextMenu_ = this.document_.createElement('menu'); | 276 this.tableContextMenu_ = this.document_.createElement('menu'); |
266 | 277 |
267 // Creates command element to receive event. | 278 var addMenuItem = function (tm, command_id, string_id, default_label) { |
268 var command = this.document_.createElement('command'); | 279 // Creates command element to receive event. |
269 command.id = 'tableContextMenu-inspect'; | 280 var command = tm.document_.createElement('command'); |
270 cr.ui.Command.decorate(command); | 281 command.id = COMMAND_CONTEXTMENU_TABLE_PREFIX + '-' + command_id; |
271 this.table_menu_commands_[command.id] = command; | 282 cr.ui.Command.decorate(command); |
272 this.commandsElement_.appendChild(command); | 283 tm.table_menu_commands_[command.id] = command; |
| 284 tm.commandsElement_.appendChild(command); |
273 | 285 |
274 // Creates menuitem element. | 286 // Creates menuitem element. |
275 var item = this.document_.createElement('menuitem'); | 287 var item = tm.document_.createElement('menuitem'); |
276 item.command = command; | 288 item.command = command; |
277 command.menuitem = item; | 289 command.menuitem = item; |
278 var localized_label = localStrings.getString('INSPECT'); | 290 var localized_label = localStrings.getString(string_id); |
279 item.textContent = (localized_label != "") ? localized_label : "Inspect"; | 291 item.textContent = localized_label || default_label; |
280 this.tableContextMenu_.appendChild(item); | 292 tm.tableContextMenu_.appendChild(item); |
| 293 }; |
| 294 |
| 295 addMenuItem(this, 'inspect', 'INSPECT', "Inspect"); |
| 296 addMenuItem(this, 'activate', 'ACTIVATE', "Activate"); |
281 | 297 |
282 this.document_.body.appendChild(this.tableContextMenu_); | 298 this.document_.body.appendChild(this.tableContextMenu_); |
283 cr.ui.Menu.decorate(this.tableContextMenu_); | 299 cr.ui.Menu.decorate(this.tableContextMenu_); |
284 }, | 300 }, |
285 | 301 |
286 initTable_: function () { | 302 initTable_: function () { |
287 if (!this.dataModel_ || !this.selectionModel_ || !this.columnModel_) { | 303 if (!this.dataModel_ || !this.selectionModel_ || !this.columnModel_) { |
288 console.log('ERROR: some models are not defined.'); | 304 console.log('ERROR: some models are not defined.'); |
289 return; | 305 return; |
290 } | 306 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 image.src = entry['icon'][i]; | 359 image.src = entry['icon'][i]; |
344 label.appendChild(image); | 360 label.appendChild(image); |
345 var text = this.document_.createElement('div'); | 361 var text = this.document_.createElement('div'); |
346 text.className = 'detail-title-text'; | 362 text.className = 'detail-title-text'; |
347 text.textContent = entry['title'][i]; | 363 text.textContent = entry['title'][i]; |
348 label.appendChild(text); | 364 label.appendChild(text); |
349 | 365 |
350 cr.ui.contextMenuHandler.addContextMenuProperty(label); | 366 cr.ui.contextMenuHandler.addContextMenuProperty(label); |
351 label.contextMenu = this.tableContextMenu_; | 367 label.contextMenu = this.tableContextMenu_; |
352 | 368 |
| 369 label.addEventListener('dblclick', (function(uniqueId) { |
| 370 this.activatePage(uniqueId); |
| 371 }).bind(this, entry['uniqueId'][i])); |
| 372 |
353 label.data = entry; | 373 label.data = entry; |
354 label.index_in_group = i; | 374 label.index_in_group = i; |
355 } else { | 375 } else { |
356 label.textContent = entry[columnId][i]; | 376 label.textContent = entry[columnId][i]; |
357 } | 377 } |
358 label.id = 'detail-' + columnId + '-pid' + entry.processId + '-' + i; | 378 label.id = 'detail-' + columnId + '-pid' + entry.processId + '-' + i; |
359 label.className = 'detail-' + columnId + ' pid' + entry.processId; | 379 label.className = 'detail-' + columnId + ' pid' + entry.processId; |
360 container.appendChild(label); | 380 container.appendChild(label); |
361 } | 381 } |
362 } | 382 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 if (!dm) | 417 if (!dm) |
398 return; | 418 return; |
399 dm.splice(start, length); | 419 dm.splice(start, length); |
400 }, | 420 }, |
401 | 421 |
402 /** | 422 /** |
403 * Respond to a command being executed. | 423 * Respond to a command being executed. |
404 */ | 424 */ |
405 onCommand_: function(event) { | 425 onCommand_: function(event) { |
406 var command = event.command; | 426 var command = event.command; |
407 if (command.id.substr(0, 18) == 'columnContextMenu-') { | 427 var command_id = command.id.split('-', 2); |
408 console.log(command.id.substr(18)); | 428 |
409 this.onColumnContextMenu_(command.id.substr(18), command); | 429 var main_command = command_id[0]; |
410 } else if (command.id == 'tableContextMenu-inspect') { | 430 var sub_command = command_id[1]; |
411 var contextMenuTarget = this.currentContextMenuTarget_; | 431 |
412 if (contextMenuTarget) { | 432 if (main_command == COMMAND_CONTEXTMENU_COLUMN_PREFIX) { |
413 this.inspect(contextMenuTarget); | 433 this.onColumnContextMenu_(sub_command, command); |
414 this.currentContextMenuTarget_ = undefined; | 434 } else if (main_command == COMMAND_CONTEXTMENU_TABLE_PREFIX) { |
415 } | 435 var target_unique_id = this.currentContextMenuTarget_; |
| 436 |
| 437 if (!target_unique_id) |
| 438 return; |
| 439 |
| 440 if (sub_command == 'inspect') |
| 441 this.inspect(target_unique_id); |
| 442 else if (sub_command == 'activate') |
| 443 this.activatePage(target_unique_id); |
| 444 |
| 445 this.currentContextMenuTarget_ = undefined; |
416 } | 446 } |
417 }, | 447 }, |
418 | 448 |
419 onCommandCanExecute_: function(event) { | 449 onCommandCanExecute_: function(event) { |
420 event.canExecute = true; | 450 event.canExecute = true; |
421 }, | 451 }, |
422 | 452 |
423 /** | 453 /** |
424 * Store resourceIndex of target resource of context menu, because resource | 454 * Store resourceIndex of target resource of context menu, because resource |
425 * will be replaced when it is refleshed. | 455 * will be replaced when it is refleshed. |
426 */ | 456 */ |
427 onTableContextMenuOpened_: function (e) { | 457 onTableContextMenuOpened_: function (e) { |
428 var command = this.table_menu_commands_['tableContextMenu-inspect']; | 458 var mc = this.table_menu_commands_; |
429 var menuItem = command.menuitem; | 459 var inspect_menuitem = |
| 460 mc[COMMAND_CONTEXTMENU_TABLE_PREFIX + '-inspect'].menuitem; |
| 461 var activate_menuitem = |
| 462 mc[COMMAND_CONTEXTMENU_TABLE_PREFIX + '-activate'].menuitem; |
430 | 463 |
431 // Disabled by default. | 464 // Disabled by default. |
432 menuItem.disabled = true; | 465 inspect_menuitem.disabled = true; |
433 this.currentContextMenuTarget_ = undefined; | 466 activate_menuitem.disabled = true; |
434 | 467 |
435 var target = e.target; | 468 var target = e.target; |
436 var classes = target.classList; | 469 var classes = target.classList; |
437 while (target && | 470 while (target && |
438 Array.prototype.indexOf.call(classes, 'detail-title') == -1) { | 471 Array.prototype.indexOf.call(classes, 'detail-title') == -1) { |
439 target = target.parentNode; | 472 target = target.parentNode; |
440 classes = target.classList; | 473 classes = target.classList; |
441 } | 474 } |
442 | 475 |
443 if (!target) | 476 if (!target) |
444 return; | 477 return; |
445 | 478 |
446 var index_in_group = target.index_in_group; | 479 var index_in_group = target.index_in_group; |
447 | 480 |
448 var canInspect = target.data['canInspect'][index_in_group]; | 481 // Sets the uniqueId for current target page under the mouse corsor. |
449 if (canInspect) { | 482 this.currentContextMenuTarget_ = target.data['uniqueId'][index_in_group]; |
450 menuItem.disabled = false; | 483 |
451 this.currentContextMenuTarget_ = | 484 // Enables if the page can be inspected. |
452 target.data['uniqueId'][index_in_group]; | 485 if (target.data['canInspect'][index_in_group]) |
453 } | 486 inspect_menuitem.disabled = false; |
| 487 |
| 488 // Enables if the page can be activated. |
| 489 if (target.data['canActivate'][index_in_group]) |
| 490 activate_menuitem.disabled = false; |
454 }, | 491 }, |
455 | 492 |
456 onColumnContextMenu_: function(id, command) { | 493 onColumnContextMenu_: function(id, command) { |
457 var menuitem = command.menuitem; | 494 var menuitem = command.menuitem; |
458 var checked_item_count = 0; | 495 var checked_item_count = 0; |
459 var is_uncheck = 0; | 496 var is_uncheck = 0; |
460 | 497 |
461 // Leaves a item visible when user tries making invisible but it is the | 498 // Leaves a item visible when user tries making invisible but it is the |
462 // last one. | 499 // last one. |
463 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) { | 500 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 taskmanager.onTaskChange(start, length, tasks); | 556 taskmanager.onTaskChange(start, length, tasks); |
520 } | 557 } |
521 | 558 |
522 function taskRemoved(start, length) { | 559 function taskRemoved(start, length) { |
523 // Sometimes this can get called too early. | 560 // Sometimes this can get called too early. |
524 if (!taskmanager) | 561 if (!taskmanager) |
525 return; | 562 return; |
526 taskmanager.onTaskRemove(start, length); | 563 taskmanager.onTaskRemove(start, length); |
527 } | 564 } |
528 | 565 |
OLD | NEW |