Chromium Code Reviews| 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 if (command.id.substr(0, COMMAND_CONTEXTMENU_COLUMN_PREFIX.length) |
| 428 == COMMAND_CONTEXTMENU_COLUMN_PREFIX) { | |
|
mazda
2011/11/10 05:32:26
I think it's more common to put operator at the en
yoshiki
2011/11/10 08:15:01
Stop substr()-based implement and change to 1 line
| |
| 408 console.log(command.id.substr(18)); | 429 console.log(command.id.substr(18)); |
|
mazda
2011/11/10 05:32:26
18 -> COMMAND_CONTEXTMENU_COLUMN_PREFIX.length
yoshiki
2011/11/10 08:15:01
ditto
On 2011/11/10 05:32:26, mazda wrote:
| |
| 409 this.onColumnContextMenu_(command.id.substr(18), command); | 430 this.onColumnContextMenu_(command.id.substr(18), command); |
| 410 } else if (command.id == 'tableContextMenu-inspect') { | 431 } else if (command.id.substr(0, COMMAND_CONTEXTMENU_TABLE_PREFIX.length) |
| 411 var contextMenuTarget = this.currentContextMenuTarget_; | 432 == COMMAND_CONTEXTMENU_TABLE_PREFIX) { |
|
mazda
2011/11/10 05:32:26
Operator position.
yoshiki
2011/11/10 08:15:01
ditto
On 2011/11/10 05:32:26, mazda wrote:
| |
| 412 if (contextMenuTarget) { | 433 var target_unique_id = this.currentContextMenuTarget_; |
| 413 this.inspect(contextMenuTarget); | 434 var sub_command = command.id.substr(17); |
|
mazda
2011/11/10 05:32:26
17 -> COMMAND_CONTEXTMENU_TABLE_PREFIX.length
yoshiki
2011/11/10 08:15:01
ditto
On 2011/11/10 05:32:26, mazda wrote:
| |
| 414 this.currentContextMenuTarget_ = undefined; | 435 |
| 415 } | 436 if (!target_unique_id) |
| 437 return; | |
| 438 | |
| 439 if (sub_command == 'inspect') | |
| 440 this.inspect(target_unique_id); | |
| 441 else if (sub_command == 'activate') | |
| 442 this.activatePage(target_unique_id); | |
| 443 | |
| 444 this.currentContextMenuTarget_ = undefined; | |
| 416 } | 445 } |
| 417 }, | 446 }, |
| 418 | 447 |
| 419 onCommandCanExecute_: function(event) { | 448 onCommandCanExecute_: function(event) { |
| 420 event.canExecute = true; | 449 event.canExecute = true; |
| 421 }, | 450 }, |
| 422 | 451 |
| 423 /** | 452 /** |
| 424 * Store resourceIndex of target resource of context menu, because resource | 453 * Store resourceIndex of target resource of context menu, because resource |
| 425 * will be replaced when it is refleshed. | 454 * will be replaced when it is refleshed. |
| 426 */ | 455 */ |
| 427 onTableContextMenuOpened_: function (e) { | 456 onTableContextMenuOpened_: function (e) { |
| 428 var command = this.table_menu_commands_['tableContextMenu-inspect']; | 457 var mc = this.table_menu_commands_; |
| 429 var menuItem = command.menuitem; | 458 var inspect_menuitem |
| 459 = mc[COMMAND_CONTEXTMENU_TABLE_PREFIX + 'inspect'].menuitem; | |
|
mazda
2011/11/10 05:32:26
Operator position.
yoshiki
2011/11/10 08:15:01
Done.
| |
| 460 var activate_menuitem | |
| 461 = mc[COMMAND_CONTEXTMENU_TABLE_PREFIX + 'activate'].menuitem; | |
|
mazda
2011/11/10 05:32:26
Operator position.
yoshiki
2011/11/10 08:15:01
Done.
| |
| 430 | 462 |
| 431 // Disabled by default. | 463 // Disabled by default. |
| 432 menuItem.disabled = true; | 464 inspect_menuitem.disabled = true; |
| 433 this.currentContextMenuTarget_ = undefined; | 465 activate_menuitem.disabled = true; |
| 434 | 466 |
| 435 var target = e.target; | 467 var target = e.target; |
| 436 var classes = target.classList; | 468 var classes = target.classList; |
| 437 while (target && | 469 while (target && |
| 438 Array.prototype.indexOf.call(classes, 'detail-title') == -1) { | 470 Array.prototype.indexOf.call(classes, 'detail-title') == -1) { |
| 439 target = target.parentNode; | 471 target = target.parentNode; |
| 440 classes = target.classList; | 472 classes = target.classList; |
| 441 } | 473 } |
| 442 | 474 |
| 443 if (!target) | 475 if (!target) |
| 444 return; | 476 return; |
| 445 | 477 |
| 446 var index_in_group = target.index_in_group; | 478 var index_in_group = target.index_in_group; |
| 447 | 479 |
| 448 var canInspect = target.data['canInspect'][index_in_group]; | 480 // Sets the uniqueId for current target page under the mouse corsor. |
| 449 if (canInspect) { | 481 this.currentContextMenuTarget_ = target.data['uniqueId'][index_in_group]; |
| 450 menuItem.disabled = false; | 482 |
| 451 this.currentContextMenuTarget_ = | 483 // Enables if the page can be inspected. |
| 452 target.data['uniqueId'][index_in_group]; | 484 if (target.data['canInspect'][index_in_group]) |
| 453 } | 485 inspect_menuitem.disabled = false; |
| 486 | |
| 487 // Enables if the page can be activated. | |
| 488 if (target.data['canActivate'][index_in_group]) | |
| 489 activate_menuitem.disabled = false; | |
| 454 }, | 490 }, |
| 455 | 491 |
| 456 onColumnContextMenu_: function(id, command) { | 492 onColumnContextMenu_: function(id, command) { |
| 457 var menuitem = command.menuitem; | 493 var menuitem = command.menuitem; |
| 458 var checked_item_count = 0; | 494 var checked_item_count = 0; |
| 459 var is_uncheck = 0; | 495 var is_uncheck = 0; |
| 460 | 496 |
| 461 // Leaves a item visible when user tries making invisible but it is the | 497 // Leaves a item visible when user tries making invisible but it is the |
| 462 // last one. | 498 // last one. |
| 463 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) { | 499 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); | 555 taskmanager.onTaskChange(start, length, tasks); |
| 520 } | 556 } |
| 521 | 557 |
| 522 function taskRemoved(start, length) { | 558 function taskRemoved(start, length) { |
| 523 // Sometimes this can get called too early. | 559 // Sometimes this can get called too early. |
| 524 if (!taskmanager) | 560 if (!taskmanager) |
| 525 return; | 561 return; |
| 526 taskmanager.onTaskRemove(start, length); | 562 taskmanager.onTaskRemove(start, length); |
| 527 } | 563 } |
| 528 | 564 |
| OLD | NEW |