OLD | NEW |
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 // Setting the src of an img to an empty string can crash the browser, so we | 5 // Setting the src of an img to an empty string can crash the browser, so we |
6 // use an empty 1x1 gif instead. | 6 // use an empty 1x1 gif instead. |
7 | 7 |
8 /** | 8 /** |
9 * FileManager constructor. | 9 * FileManager constructor. |
10 * | 10 * |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 this.showCheckboxes_ = | 483 this.showCheckboxes_ = |
484 (this.dialogType_ == FileManager.DialogType.FULL_PAGE || | 484 (this.dialogType_ == FileManager.DialogType.FULL_PAGE || |
485 this.dialogType_ == FileManager.DialogType.SELECT_OPEN_MULTI_FILE); | 485 this.dialogType_ == FileManager.DialogType.SELECT_OPEN_MULTI_FILE); |
486 | 486 |
487 this.table_.startBatchUpdates(); | 487 this.table_.startBatchUpdates(); |
488 this.grid_.startBatchUpdates(); | 488 this.grid_.startBatchUpdates(); |
489 | 489 |
490 this.initFileList_(); | 490 this.initFileList_(); |
491 this.initDialogs_(); | 491 this.initDialogs_(); |
492 | 492 |
493 this.copyManager_ = new FileCopyManager(this.filesystem_.root); | |
494 this.copyManager_.addEventListener('copy-progress', | |
495 this.onCopyProgress_.bind(this)); | |
496 this.copyManager_.addEventListener('copy-operation-complete', | |
497 this.onCopyManagerOperationComplete_.bind(this)); | |
498 | |
499 window.addEventListener('popstate', this.onPopState_.bind(this)); | 493 window.addEventListener('popstate', this.onPopState_.bind(this)); |
500 window.addEventListener('unload', this.onUnload_.bind(this)); | 494 window.addEventListener('unload', this.onUnload_.bind(this)); |
501 | 495 |
502 var offlineHandler = this.onOnlineOffline_.bind(this); | 496 var offlineHandler = this.onOnlineOffline_.bind(this); |
503 window.addEventListener('online', offlineHandler); | 497 window.addEventListener('online', offlineHandler); |
504 window.addEventListener('offline', offlineHandler); | 498 window.addEventListener('offline', offlineHandler); |
505 offlineHandler(); // Sync with the current state. | 499 offlineHandler(); // Sync with the current state. |
506 | 500 |
507 this.directoryModel_.addEventListener('directory-changed', | 501 this.directoryModel_.addEventListener('directory-changed', |
508 this.onDirectoryChanged_.bind(this)); | 502 this.onDirectoryChanged_.bind(this)); |
(...skipping 15 matching lines...) Expand all Loading... |
524 // The list of archives requested to mount. We will show contents once | 518 // The list of archives requested to mount. We will show contents once |
525 // archive is mounted, but only for mounts from within this filebrowser tab. | 519 // archive is mounted, but only for mounts from within this filebrowser tab. |
526 this.mountRequests_ = []; | 520 this.mountRequests_ = []; |
527 this.unmountRequests_ = []; | 521 this.unmountRequests_ = []; |
528 chrome.fileBrowserPrivate.onMountCompleted.addListener( | 522 chrome.fileBrowserPrivate.onMountCompleted.addListener( |
529 this.onMountCompleted_.bind(this)); | 523 this.onMountCompleted_.bind(this)); |
530 | 524 |
531 chrome.fileBrowserPrivate.onFileChanged.addListener( | 525 chrome.fileBrowserPrivate.onFileChanged.addListener( |
532 this.onFileChanged_.bind(this)); | 526 this.onFileChanged_.bind(this)); |
533 | 527 |
534 // The list of callbacks to be invoked during the directory rescan after | |
535 // all paste tasks are complete. | |
536 this.pasteSuccessCallbacks_ = []; | |
537 | |
538 var path = this.getPathFromUrlOrParams_(); | 528 var path = this.getPathFromUrlOrParams_(); |
539 if (path && | 529 if (path && |
540 DirectoryModel.getRootType(path) == DirectoryModel.RootType.GDATA) { | 530 DirectoryModel.getRootType(path) == DirectoryModel.RootType.GDATA) { |
541 // We are opening on a GData path. Mount GData and show | 531 // We are opening on a GData path. Mount GData and show |
542 // "Loading Google Docs" message until the directory content loads. | 532 // "Loading Google Docs" message until the directory content loads. |
543 this.dialogContainer_.setAttribute('unmounted', true); | 533 this.dialogContainer_.setAttribute('unmounted', true); |
544 this.initGData_(true /* dirChanged */); | 534 this.initGData_(true /* dirChanged */); |
545 // This is a one-time handler (will be nulled out on the first call). | 535 // This is a one-time handler (will be nulled out on the first call). |
546 this.setupCurrentDirectoryPostponed_ = function(event) { | 536 this.setupCurrentDirectoryPostponed_ = function(event) { |
547 this.directoryModel_.removeEventListener('directory-changed', | 537 this.directoryModel_.removeEventListener('directory-changed', |
(...skipping 22 matching lines...) Expand all Loading... |
570 this.metadataProvider_ = | 560 this.metadataProvider_ = |
571 new MetadataProvider(this.filesystem_.root.toURL()); | 561 new MetadataProvider(this.filesystem_.root.toURL()); |
572 | 562 |
573 // PyAuto tests monitor this state by polling this variable | 563 // PyAuto tests monitor this state by polling this variable |
574 this.__defineGetter__('workerInitialized_', function() { | 564 this.__defineGetter__('workerInitialized_', function() { |
575 return self.getMetadataProvider().isInitialized(); | 565 return self.getMetadataProvider().isInitialized(); |
576 }); | 566 }); |
577 | 567 |
578 this.directoryModel_.offline = this.isOffline(); | 568 this.directoryModel_.offline = this.isOffline(); |
579 | 569 |
| 570 if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) |
| 571 this.initDataTransferOperations_(); |
| 572 |
| 573 this.table_.endBatchUpdates(); |
| 574 this.grid_.endBatchUpdates(); |
| 575 |
| 576 metrics.recordInterval('Load.DOM'); |
| 577 metrics.recordInterval('Load.Total'); |
| 578 }; |
| 579 |
| 580 FileManager.prototype.initDataTransferOperations_ = function() { |
| 581 this.copyManager_ = new FileCopyManager(this.filesystem_.root); |
| 582 this.copyManager_.addEventListener('copy-progress', |
| 583 this.onCopyProgress_.bind(this)); |
| 584 this.copyManager_.addEventListener('copy-operation-complete', |
| 585 this.onCopyManagerOperationComplete_.bind(this)); |
| 586 |
580 var controller = this.fileTransferController_ = new FileTransferController( | 587 var controller = this.fileTransferController_ = new FileTransferController( |
581 this.directoryModel_.fileList, | 588 this.directoryModel_.fileList, |
582 this.directoryModel_.fileListSelection, | 589 this.directoryModel_.fileListSelection, |
583 GridItem.bind(null, this), | 590 GridItem.bind(null, this), |
584 this.copyManager_, | 591 this.copyManager_, |
585 this.directoryModel_); | 592 this.directoryModel_); |
586 controller.attachDragSource(this.table_.list); | 593 controller.attachDragSource(this.table_.list); |
587 controller.attachDropTarget(this.table_.list); | 594 controller.attachDropTarget(this.table_.list); |
588 controller.attachDragSource(this.grid_); | 595 controller.attachDragSource(this.grid_); |
589 controller.attachDropTarget(this.grid_); | 596 controller.attachDropTarget(this.grid_); |
590 controller.attachCopyPasteHandlers(this.document_); | 597 controller.attachCopyPasteHandlers(this.document_); |
591 controller.addEventListener('selection-copied', | 598 controller.addEventListener('selection-copied', |
592 this.blinkSelection.bind(this)); | 599 this.blinkSelection.bind(this)); |
593 controller.addEventListener('selection-cut', | 600 controller.addEventListener('selection-cut', |
594 this.blinkSelection.bind(this)); | 601 this.blinkSelection.bind(this)); |
595 | |
596 this.table_.endBatchUpdates(); | |
597 this.grid_.endBatchUpdates(); | |
598 | |
599 metrics.recordInterval('Load.DOM'); | |
600 metrics.recordInterval('Load.Total'); | |
601 }; | 602 }; |
602 | 603 |
603 /** | 604 /** |
604 * One-time initialization of commands. | 605 * One-time initialization of commands. |
605 */ | 606 */ |
606 FileManager.prototype.initCommands_ = function() { | 607 FileManager.prototype.initCommands_ = function() { |
607 var commands = this.dialogDom_.querySelectorAll('command'); | 608 var commands = this.dialogDom_.querySelectorAll('command'); |
608 for (var i = 0; i < commands.length; i++) { | 609 for (var i = 0; i < commands.length; i++) { |
609 var command = commands[i]; | 610 var command = commands[i]; |
610 cr.ui.Command.decorate(command); | 611 cr.ui.Command.decorate(command); |
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1206 * selection. | 1207 * selection. |
1207 */ | 1208 */ |
1208 FileManager.prototype.canExecute_ = function(commandId) { | 1209 FileManager.prototype.canExecute_ = function(commandId) { |
1209 var readonly = this.isOnReadonlyDirectory(); | 1210 var readonly = this.isOnReadonlyDirectory(); |
1210 switch (commandId) { | 1211 switch (commandId) { |
1211 case 'copy': | 1212 case 'copy': |
1212 case 'cut': | 1213 case 'cut': |
1213 return this.document_.queryCommandEnabled(commandId); | 1214 return this.document_.queryCommandEnabled(commandId); |
1214 | 1215 |
1215 case 'paste': | 1216 case 'paste': |
1216 return this.fileTransferController_.queryPasteCommandEnabled(); | 1217 return !!this.fileTransferController_ && |
| 1218 this.fileTransferController_.queryPasteCommandEnabled(); |
1217 | 1219 |
1218 case 'rename': | 1220 case 'rename': |
1219 return (// Initialized to the point where we have a current directory | 1221 return (// Initialized to the point where we have a current directory |
1220 !readonly && | 1222 !readonly && |
1221 // Rename not in progress. | 1223 // Rename not in progress. |
1222 !this.isRenamingInProgress() && | 1224 !this.isRenamingInProgress() && |
1223 // Only one file selected. | 1225 // Only one file selected. |
1224 this.selection && | 1226 this.selection && |
1225 this.selection.totalCount == 1); | 1227 this.selection.totalCount == 1); |
1226 | 1228 |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1430 var options = {progress: progress.percentage, timeout: 0}; | 1432 var options = {progress: progress.percentage, timeout: 0}; |
1431 this.updateButter(strf('PASTE_ITEMS_REMAINING', progress.pendingItems), | 1433 this.updateButter(strf('PASTE_ITEMS_REMAINING', progress.pendingItems), |
1432 options); | 1434 options); |
1433 } | 1435 } |
1434 return; | 1436 return; |
1435 } | 1437 } |
1436 if (event.reason == 'SUCCESS') { | 1438 if (event.reason == 'SUCCESS') { |
1437 clearTimeout(this.butterTimeout_); | 1439 clearTimeout(this.butterTimeout_); |
1438 if (this.currentButter_) | 1440 if (this.currentButter_) |
1439 this.hideButter(); | 1441 this.hideButter(); |
1440 | |
1441 self = this; | |
1442 var callback; | |
1443 while (callback = self.pasteSuccessCallbacks_.shift()) { | |
1444 try { | |
1445 callback(); | |
1446 } catch (ex) { | |
1447 console.error('Caught exception while inovking callback: ' + | |
1448 callback, ex); | |
1449 } | |
1450 } | |
1451 } else if (event.reason == 'ERROR') { | 1442 } else if (event.reason == 'ERROR') { |
1452 clearTimeout(this.butterTimeout_); | 1443 clearTimeout(this.butterTimeout_); |
1453 switch (event.error.reason) { | 1444 switch (event.error.reason) { |
1454 case 'TARGET_EXISTS': | 1445 case 'TARGET_EXISTS': |
1455 var name = event.error.data.name; | 1446 var name = event.error.data.name; |
1456 if (event.error.data.isDirectory) | 1447 if (event.error.data.isDirectory) |
1457 name += '/'; | 1448 name += '/'; |
1458 this.showButterError(strf('PASTE_TARGET_EXISTS_ERROR', name)); | 1449 this.showButterError(strf('PASTE_TARGET_EXISTS_ERROR', name)); |
1459 break; | 1450 break; |
1460 | 1451 |
(...skipping 2952 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4413 | 4404 |
4414 chrome.fileBrowserPrivate.setGDataPreferences(changeInfo); | 4405 chrome.fileBrowserPrivate.setGDataPreferences(changeInfo); |
4415 | 4406 |
4416 if (oldValue) { | 4407 if (oldValue) { |
4417 event.target.removeAttribute('checked'); | 4408 event.target.removeAttribute('checked'); |
4418 } else { | 4409 } else { |
4419 event.target.setAttribute('checked', 'checked'); | 4410 event.target.setAttribute('checked', 'checked'); |
4420 } | 4411 } |
4421 }; | 4412 }; |
4422 })(); | 4413 })(); |
OLD | NEW |