Chromium Code Reviews| 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 const EMPTY_IMAGE_URI = 'data:image/gif;base64,' | 7 const EMPTY_IMAGE_URI = 'data:image/gif;base64,' |
| 8 + 'R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw%3D%3D'; | 8 + 'R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw%3D%3D'; |
| 9 | 9 |
| 10 /** | 10 /** |
| (...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 475 }; | 475 }; |
| 476 } | 476 } |
| 477 | 477 |
| 478 // Optional list of file types. | 478 // Optional list of file types. |
| 479 this.fileTypes_ = this.params_.typeList; | 479 this.fileTypes_ = this.params_.typeList; |
| 480 | 480 |
| 481 this.showCheckboxes_ = | 481 this.showCheckboxes_ = |
| 482 (this.dialogType_ == FileManager.DialogType.FULL_PAGE || | 482 (this.dialogType_ == FileManager.DialogType.FULL_PAGE || |
| 483 this.dialogType_ == FileManager.DialogType.SELECT_OPEN_MULTI_FILE); | 483 this.dialogType_ == FileManager.DialogType.SELECT_OPEN_MULTI_FILE); |
| 484 | 484 |
| 485 this.table_.list.startBatchUpdates(); | 485 this.table_.startBatchUpdates(); |
| 486 this.grid_.startBatchUpdates(); | 486 this.grid_.startBatchUpdates(); |
| 487 | 487 |
| 488 this.initFileList_(); | 488 this.initFileList_(); |
| 489 this.initDialogs_(); | 489 this.initDialogs_(); |
| 490 | 490 |
| 491 this.copyManager_ = new FileCopyManager(); | 491 this.copyManager_ = new FileCopyManager(); |
| 492 this.copyManager_.addEventListener('copy-progress', | 492 this.copyManager_.addEventListener('copy-progress', |
| 493 this.onCopyProgress_.bind(this)); | 493 this.onCopyProgress_.bind(this)); |
| 494 | 494 |
| 495 window.addEventListener('popstate', this.onPopState_.bind(this)); | 495 window.addEventListener('popstate', this.onPopState_.bind(this)); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 543 sortDirection = | 543 sortDirection = |
| 544 window.localStorage['sort-direction-' + this.dialogType_] || | 544 window.localStorage['sort-direction-' + this.dialogType_] || |
| 545 sortDirection; | 545 sortDirection; |
| 546 } | 546 } |
| 547 this.directoryModel_.fileList.sort(sortField, sortDirection); | 547 this.directoryModel_.fileList.sort(sortField, sortDirection); |
| 548 | 548 |
| 549 this.refocus(); | 549 this.refocus(); |
| 550 | 550 |
| 551 this.createMetadataProvider_(); | 551 this.createMetadataProvider_(); |
| 552 | 552 |
| 553 this.table_.list.endBatchUpdates(); | 553 this.table_.endBatchUpdates(); |
| 554 this.grid_.endBatchUpdates(); | 554 this.grid_.endBatchUpdates(); |
| 555 | 555 |
| 556 metrics.recordInterval('Load.DOM'); | 556 metrics.recordInterval('Load.DOM'); |
| 557 metrics.recordInterval('Load.Total'); | 557 metrics.recordInterval('Load.Total'); |
| 558 }; | 558 }; |
| 559 | 559 |
| 560 /** | 560 /** |
| 561 * One-time initialization of commands. | 561 * One-time initialization of commands. |
| 562 */ | 562 */ |
| 563 FileManager.prototype.initCommands_ = function() { | 563 FileManager.prototype.initCommands_ = function() { |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 754 | 754 |
| 755 var self = this; | 755 var self = this; |
| 756 this.rootsList_.itemConstructor = function(entry) { | 756 this.rootsList_.itemConstructor = function(entry) { |
| 757 return self.renderRoot_(entry); | 757 return self.renderRoot_(entry); |
| 758 }; | 758 }; |
| 759 | 759 |
| 760 this.rootsList_.selectionModel = this.directoryModel_.rootsListSelection; | 760 this.rootsList_.selectionModel = this.directoryModel_.rootsListSelection; |
| 761 | 761 |
| 762 // TODO(dgozman): add "Add a drive" item. | 762 // TODO(dgozman): add "Add a drive" item. |
| 763 this.rootsList_.dataModel = this.directoryModel_.rootsList; | 763 this.rootsList_.dataModel = this.directoryModel_.rootsList; |
| 764 this.directoryModel_.updateRoots(); | 764 this.directoryModel_.updateRoots(function() { |
| 765 self.rootsList_.endBatchUpdates(); | |
| 766 }); | |
| 765 }; | 767 }; |
| 766 | 768 |
| 767 FileManager.prototype.initGData_ = function() { | 769 FileManager.prototype.initGData_ = function() { |
| 768 metrics.startInterval('Load.GData'); | 770 metrics.startInterval('Load.GData'); |
| 769 // TODO(zelidrag): We should do this first time user selects this provider. | 771 // TODO(zelidrag): We should do this first time user selects this provider. |
| 770 chrome.fileBrowserPrivate.addMount('', 'gdata', {}); | 772 chrome.fileBrowserPrivate.addMount('', 'gdata', {}); |
| 771 }; | 773 }; |
| 772 | 774 |
| 773 /** | 775 /** |
| 774 * Get the icon type for a given Entry. | 776 * Get the icon type for a given Entry. |
| (...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1390 | 1392 |
| 1391 /** | 1393 /** |
| 1392 * Restores current directory and may be a selected item after page load (or | 1394 * Restores current directory and may be a selected item after page load (or |
| 1393 * reload) or popping a state (after click on back/forward). If location.hash | 1395 * reload) or popping a state (after click on back/forward). If location.hash |
| 1394 * is present it means that the user has navigated somewhere and that place | 1396 * is present it means that the user has navigated somewhere and that place |
| 1395 * will be restored. defaultPath primarily is used with save/open dialogs. | 1397 * will be restored. defaultPath primarily is used with save/open dialogs. |
| 1396 * Default path may also contain a file name. Freshly opened file manager | 1398 * Default path may also contain a file name. Freshly opened file manager |
| 1397 * window has neither. | 1399 * window has neither. |
| 1398 */ | 1400 */ |
| 1399 FileManager.prototype.setupCurrentDirectory_ = function() { | 1401 FileManager.prototype.setupCurrentDirectory_ = function() { |
| 1402 // Avoid a bunch of intermediate list redraws while the data model is | |
| 1403 // cleared and updated. | |
| 1404 this.table_.startBatchUpdates(); | |
| 1405 var onLoaded = this.table_.endBatchUpdates.bind(this.table_); | |
| 1406 | |
| 1400 if (location.hash) { | 1407 if (location.hash) { |
| 1401 // Location hash has the highest priority. | 1408 // Location hash has the highest priority. |
| 1402 var path = decodeURI(location.hash.substr(1)); | 1409 var path = decodeURI(location.hash.substr(1)); |
| 1403 | 1410 |
| 1404 // In the FULL_PAGE mode if the path points to a file we should invoke | 1411 // In the FULL_PAGE mode if the path points to a file we should invoke |
| 1405 // the default action after selecting it. | 1412 // the default action after selecting it. |
| 1406 if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) { | 1413 if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) { |
| 1407 // To prevent the file list flickering for a moment before the action | 1414 // To prevent the file list flickering for a moment before the action |
| 1408 // is executed we hide it under a white div. | 1415 // is executed we hide it under a white div. |
| 1409 var shade = this.document_.createElement('div'); | 1416 var shade = this.document_.createElement('div'); |
| 1410 shade.className = 'overlay-pane'; | 1417 shade.className = 'overlay-pane'; |
| 1411 shade.style.backgroundColor = 'white'; | 1418 shade.style.backgroundColor = 'white'; |
| 1412 this.document_.body.appendChild(shade); | 1419 this.document_.body.appendChild(shade); |
| 1413 function removeShade() { shade.parentNode.removeChild(shade) } | 1420 function removeShade() { shade.parentNode.removeChild(shade) } |
| 1414 | 1421 |
| 1415 function onResolve(baseName, leafName, exists) { | 1422 function onResolve(baseName, leafName, exists) { |
| 1416 if (!exists || leafName == '') { | 1423 if (!exists || leafName == '') { |
| 1417 // Non-existent file or a directory. Remove the shade immediately. | 1424 // Non-existent file or a directory. Remove the shade immediately. |
| 1418 removeShade(); | 1425 removeShade(); |
|
Vladislav Kaznacheev
2012/02/29 21:04:48
onLoaded() needs to be called from there as well.
Rick Byers
2012/03/02 00:19:46
I don't think so, we're not necessarily done yet a
| |
| 1419 } | 1426 } |
| 1420 } | 1427 } |
| 1421 | 1428 |
| 1422 // TODO(kaznacheev): refactor dispatchDefaultTask to accept an array | 1429 // TODO(kaznacheev): refactor dispatchDefaultTask to accept an array |
| 1423 // of urls instead of a selection. This will remove the need to wait | 1430 // of urls instead of a selection. This will remove the need to wait |
| 1424 // until the selection is done. | 1431 // until the selection is done. |
| 1425 var self = this; | 1432 var self = this; |
| 1426 function onFileSelected() { | 1433 function onFileSelected() { |
| 1434 onLoaded(); | |
| 1427 self.dispatchDefaultTask_(); | 1435 self.dispatchDefaultTask_(); |
| 1428 setTimeout(removeShade, 1000); | 1436 setTimeout(removeShade, 1000); |
| 1429 } | 1437 } |
| 1430 this.directoryModel_.setupPath(path, onResolve, onFileSelected); | 1438 this.directoryModel_.setupPath(path, onFileSelected, onResolve); |
| 1431 return; | 1439 return; |
| 1432 } | 1440 } |
| 1433 | 1441 |
| 1434 this.directoryModel_.setupPath(path); | 1442 this.directoryModel_.setupPath(path, onLoaded); |
| 1435 return; | 1443 return; |
| 1436 } | 1444 } |
| 1437 | 1445 |
| 1438 if (this.params_.defaultPath) { | 1446 if (this.params_.defaultPath) { |
| 1439 var path = this.params_.defaultPath; | 1447 var path = this.params_.defaultPath; |
| 1440 if (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) { | 1448 if (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) { |
| 1441 this.directoryModel_.setupPath(path, function(basePath, leafName) { | 1449 this.directoryModel_.setupPath(path, onLoaded, |
| 1442 this.filenameInput_.value = leafName; | 1450 function(basePath, leafName) { |
| 1443 this.selectDefaultPathInFilenameInput_(); | 1451 this.filenameInput_.value = leafName; |
| 1444 }.bind(this)); | 1452 this.selectDefaultPathInFilenameInput_(); |
| 1453 }.bind(this)); | |
| 1445 return; | 1454 return; |
| 1446 } | 1455 } |
| 1447 | 1456 |
| 1448 this.directoryModel_.setupPath(path); | 1457 this.directoryModel_.setupPath(path, onLoaded); |
| 1449 return; | 1458 return; |
| 1450 } | 1459 } |
| 1451 | 1460 |
| 1452 this.directoryModel_.setupDefaultPath(); | 1461 this.directoryModel_.setupDefaultPath(onLoaded); |
| 1453 }; | 1462 }; |
| 1454 | 1463 |
| 1455 /** | 1464 /** |
| 1456 * Tweak the UI to become a particular kind of dialog, as determined by the | 1465 * Tweak the UI to become a particular kind of dialog, as determined by the |
| 1457 * dialog type parameter passed to the constructor. | 1466 * dialog type parameter passed to the constructor. |
| 1458 */ | 1467 */ |
| 1459 FileManager.prototype.initDialogType_ = function() { | 1468 FileManager.prototype.initDialogType_ = function() { |
| 1460 var defaultTitle; | 1469 var defaultTitle; |
| 1461 var okLabel = str('OPEN_LABEL'); | 1470 var okLabel = str('OPEN_LABEL'); |
| 1462 | 1471 |
| (...skipping 878 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2341 }; | 2350 }; |
| 2342 } else { | 2351 } else { |
| 2343 self.gdataMounted_ = false; | 2352 self.gdataMounted_ = false; |
| 2344 self.gdataAuthToken_ = null; | 2353 self.gdataAuthToken_ = null; |
| 2345 self.gdataMountInfo_ = null; | 2354 self.gdataMountInfo_ = null; |
| 2346 } | 2355 } |
| 2347 } | 2356 } |
| 2348 | 2357 |
| 2349 chrome.fileBrowserPrivate.getMountPoints(function(mountPoints) { | 2358 chrome.fileBrowserPrivate.getMountPoints(function(mountPoints) { |
| 2350 self.setMountPoints_(mountPoints); | 2359 self.setMountPoints_(mountPoints); |
| 2351 var changeDirectoryTo = null; | 2360 var changeDirectoryCallback = null; |
| 2352 | 2361 |
| 2353 if (event.eventType == 'mount') { | 2362 if (event.eventType == 'mount') { |
| 2354 // Mount request finished - remove it. | 2363 // Mount request finished - remove it. |
| 2355 var index = self.mountRequests_.indexOf(event.sourceUrl); | 2364 var index = self.mountRequests_.indexOf(event.sourceUrl); |
| 2356 if (index != -1) { | 2365 if (index != -1) { |
| 2357 self.mountRequests_.splice(index, 1); | 2366 self.mountRequests_.splice(index, 1); |
| 2358 // Go to mounted directory, if request was initiated from this tab. | 2367 // Go to mounted directory, if request was initiated from this tab. |
| 2359 if (event.status == 'success') | 2368 if (event.status == 'success') |
| 2360 changeDirectoryTo = event.mountPath; | 2369 changeDirectoryTo = event.mountPath; |
|
Vladislav Kaznacheev
2012/02/29 21:04:48
This is now an undeclared and unused variable. I d
Rick Byers
2012/03/02 00:19:46
Yes thank you - I missed that case! How's this in
| |
| 2361 } | 2370 } |
| 2362 } | 2371 } |
| 2363 | 2372 |
| 2364 if (event.eventType == 'unmount') { | 2373 if (event.eventType == 'unmount') { |
| 2365 // Unmount request finished - remove it. | 2374 // Unmount request finished - remove it. |
| 2366 var index = self.unmountRequests_.indexOf(event.sourceUrl); | 2375 var index = self.unmountRequests_.indexOf(event.sourceUrl); |
| 2367 if (index != -1) | 2376 if (index != -1) |
| 2368 self.unmountRequests_.splice(index, 1); | 2377 self.unmountRequests_.splice(index, 1); |
| 2369 } | 2378 } |
| 2370 | 2379 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 2385 if (event.eventType == 'unmount' && event.status == 'success' && | 2394 if (event.eventType == 'unmount' && event.status == 'success' && |
| 2386 event.mountPath == self.directoryModel_.rootPath) { | 2395 event.mountPath == self.directoryModel_.rootPath) { |
| 2387 if (self.params_.mountTriggered) { | 2396 if (self.params_.mountTriggered) { |
| 2388 // window.close() sometimes doesn't work. | 2397 // window.close() sometimes doesn't work. |
| 2389 chrome.tabs.getCurrent(function(tab){ | 2398 chrome.tabs.getCurrent(function(tab){ |
| 2390 chrome.tabs.remove(tab.id); | 2399 chrome.tabs.remove(tab.id); |
| 2391 }); | 2400 }); |
| 2392 return; | 2401 return; |
| 2393 } | 2402 } |
| 2394 // Current durectory just unmounted. Move to the 'Downloads'. | 2403 // Current durectory just unmounted. Move to the 'Downloads'. |
| 2395 changeDirectoryTo = '/' + DirectoryModel.DOWNLOADS_DIRECTORY; | 2404 changeDirectoryCallback = function() { |
| 2405 self.directoryModel_.changeDirectory( | |
| 2406 '/' + DirectoryModel.DOWNLOADS_DIRECTORY); | |
| 2407 }; | |
| 2396 } | 2408 } |
| 2397 | 2409 |
| 2398 // Even if something failed root list should be rescanned. | 2410 // Even if something failed root list should be rescanned. |
| 2399 // Failed mounts can "give" us new devices which might be formatted, | 2411 // Failed mounts can "give" us new devices which might be formatted, |
| 2400 // so we have to refresh root list then. | 2412 // so we have to refresh root list then. |
| 2401 self.directoryModel_.updateRoots(changeDirectoryTo); | 2413 self.directoryModel_.updateRoots(changeDirectoryCallback); |
| 2402 }); | 2414 }); |
| 2403 }; | 2415 }; |
| 2404 | 2416 |
| 2405 /** | 2417 /** |
| 2406 * Event handler called when some internal task should be executed. | 2418 * Event handler called when some internal task should be executed. |
| 2407 */ | 2419 */ |
| 2408 FileManager.prototype.onFileTaskExecute_ = function(id, details) { | 2420 FileManager.prototype.onFileTaskExecute_ = function(id, details) { |
| 2409 var urls = details.urls; | 2421 var urls = details.urls; |
| 2410 if (id == 'play') { | 2422 if (id == 'play') { |
| 2411 var position = 0; | 2423 var position = 0; |
| (...skipping 1520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3932 }); | 3944 }); |
| 3933 }, onError); | 3945 }, onError); |
| 3934 | 3946 |
| 3935 function onError(err) { | 3947 function onError(err) { |
| 3936 console.log('Error while checking free space: ' + err); | 3948 console.log('Error while checking free space: ' + err); |
| 3937 setTimeout(doCheck, 1000 * 60); | 3949 setTimeout(doCheck, 1000 * 60); |
| 3938 } | 3950 } |
| 3939 } | 3951 } |
| 3940 } | 3952 } |
| 3941 })(); | 3953 })(); |
| OLD | NEW |