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