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 // 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 var g_slideshow_data = null; | 10 var g_slideshow_data = null; |
| (...skipping 1393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1404 return; | 1404 return; |
| 1405 } | 1405 } |
| 1406 | 1406 |
| 1407 function onLeafFound(leafEntry) { | 1407 function onLeafFound(leafEntry) { |
| 1408 if (leafEntry.isDirectory) { | 1408 if (leafEntry.isDirectory) { |
| 1409 self.changeDirectoryEntry(leafEntry, CD_NO_HISTORY); | 1409 self.changeDirectoryEntry(leafEntry, CD_NO_HISTORY); |
| 1410 return; | 1410 return; |
| 1411 } | 1411 } |
| 1412 | 1412 |
| 1413 // Leaf is an existing file, cd to its parent directory and select it. | 1413 // Leaf is an existing file, cd to its parent directory and select it. |
| 1414 self.changeDirectoryEntry(baseDirEntry, CD_NO_HISTORY, leafEntry.name); | 1414 self.changeDirectoryEntry(baseDirEntry, CD_NO_HISTORY, function() { |
| 1415 self.selectEntry(leafEntry.name); | |
| 1416 }); | |
| 1415 } | 1417 } |
| 1416 | 1418 |
| 1417 function onLeafError(err) { | 1419 function onLeafError(err) { |
| 1418 // Set filename first so OK button will update in changeDirectoryEntry. | 1420 // Set filename first so OK button will update in changeDirectoryEntry. |
| 1419 self.filenameInput_.value = leafName; | 1421 self.filenameInput_.value = leafName; |
| 1420 if (err = FileError.NOT_FOUND_ERR) { | 1422 if (err = FileError.NOT_FOUND_ERR) { |
| 1421 // Leaf does not exist, it's just a suggested file name. | 1423 // Leaf does not exist, it's just a suggested file name. |
| 1422 self.changeDirectoryEntry(baseDirEntry, CD_NO_HISTORY); | 1424 self.changeDirectoryEntry(baseDirEntry, CD_NO_HISTORY); |
| 1423 } else { | 1425 } else { |
| 1424 console.log('Unexpected error resolving default leaf: ' + err); | 1426 console.log('Unexpected error resolving default leaf: ' + err); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1506 cacheFunction = cacheEntrySize; | 1508 cacheFunction = cacheEntrySize; |
| 1507 } else if (field == 'type') { | 1509 } else if (field == 'type') { |
| 1508 cacheFunction = this.cacheEntryFileType.bind(this); | 1510 cacheFunction = this.cacheEntryFileType.bind(this); |
| 1509 } else if (field == 'cachedIconType_') { | 1511 } else if (field == 'cachedIconType_') { |
| 1510 cacheFunction = this.cacheEntryIconType.bind(this); | 1512 cacheFunction = this.cacheEntryIconType.bind(this); |
| 1511 } else { | 1513 } else { |
| 1512 setTimeout(callback, 0); | 1514 setTimeout(callback, 0); |
| 1513 return; | 1515 return; |
| 1514 } | 1516 } |
| 1515 | 1517 |
| 1516 function checkCount() { | 1518 // Start one fake wait to prevent calling the callback twice. |
| 1517 if (uncachedCount == 0) { | 1519 var waitCount = 1; |
| 1518 // Callback via a setTimeout so the sync/async semantics don't change | 1520 for (var i = 0; i < entries.length ; i++) { |
| 1519 // based on whether or not the value is cached. | 1521 var entry = entries[i]; |
| 1520 setTimeout(callback, 0); | 1522 if (!(field in entry)) { |
| 1523 waitCount++; | |
| 1524 cacheFunction(entry, onCacheDone) | |
| 1521 } | 1525 } |
| 1522 } | 1526 } |
| 1527 onCacheDone(); // Finish the fake callback. | |
| 1523 | 1528 |
| 1524 var uncachedCount = entries.length; | 1529 function onCacheDone() { |
| 1525 | 1530 waitCount--; |
| 1526 for (var i = uncachedCount - 1; i >= 0 ; i--) { | 1531 // If all caching functions finished synchronously or entries.length = 0 |
| 1527 var entry = entries[i]; | 1532 // call the callback synchronously. |
| 1528 if (field in entry) { | 1533 if (waitCount == 0) |
| 1529 uncachedCount--; | 1534 setTimeout(callback, 0); |
| 1530 } else { | |
| 1531 cacheFunction(entry, function() { | |
| 1532 uncachedCount--; | |
| 1533 checkCount(); | |
| 1534 }); | |
| 1535 } | |
| 1536 } | 1535 } |
| 1537 | |
| 1538 checkCount(); | |
| 1539 } | 1536 } |
| 1540 | 1537 |
| 1541 /** | 1538 /** |
| 1542 * Render (and wire up) a checkbox to be used in either a detail or a | 1539 * Render (and wire up) a checkbox to be used in either a detail or a |
| 1543 * thumbnail list item. | 1540 * thumbnail list item. |
| 1544 */ | 1541 */ |
| 1545 FileManager.prototype.renderCheckbox_ = function(entry) { | 1542 FileManager.prototype.renderCheckbox_ = function(entry) { |
| 1546 var input = this.document_.createElement('input'); | 1543 var input = this.document_.createElement('input'); |
| 1547 input.setAttribute('type', 'checkbox'); | 1544 input.setAttribute('type', 'checkbox'); |
| 1548 input.setAttribute('tabindex', -1); | 1545 input.setAttribute('tabindex', -1); |
| (...skipping 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2626 /** | 2623 /** |
| 2627 * Change the current directory to the directory represented by a | 2624 * Change the current directory to the directory represented by a |
| 2628 * DirectoryEntry. | 2625 * DirectoryEntry. |
| 2629 * | 2626 * |
| 2630 * Dispatches the 'directory-changed' event when the directory is successfully | 2627 * Dispatches the 'directory-changed' event when the directory is successfully |
| 2631 * changed. | 2628 * changed. |
| 2632 * | 2629 * |
| 2633 * @param {string} path The absolute path to the new directory. | 2630 * @param {string} path The absolute path to the new directory. |
| 2634 * @param {bool} opt_saveHistory Save this in the history stack (defaults | 2631 * @param {bool} opt_saveHistory Save this in the history stack (defaults |
| 2635 * to true). | 2632 * to true). |
| 2636 * @param {string} opt_selectedEntry The name of the file to select after | 2633 * @param {function} opt_action Action executed when the directory loaded. |
| 2637 * changing directories. | 2634 * By default selects the first item |
| 2635 * (unless it's a save dialog). | |
| 2638 */ | 2636 */ |
| 2639 FileManager.prototype.changeDirectoryEntry = function(dirEntry, | 2637 FileManager.prototype.changeDirectoryEntry = function(dirEntry, |
| 2640 opt_saveHistory, | 2638 opt_saveHistory, |
| 2641 opt_selectedEntry, | 2639 opt_action) { |
| 2642 opt_callback) { | |
| 2643 if (typeof opt_saveHistory == 'undefined') { | 2640 if (typeof opt_saveHistory == 'undefined') { |
| 2644 opt_saveHistory = true; | 2641 opt_saveHistory = true; |
| 2645 } else { | 2642 } else { |
| 2646 opt_saveHistory = !!opt_saveHistory; | 2643 opt_saveHistory = !!opt_saveHistory; |
| 2647 } | 2644 } |
| 2648 | 2645 |
| 2646 var action = opt_action || | |
| 2647 (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE ? | |
| 2648 undefined : this.selectIndex.bind(this, 0)); | |
| 2649 | |
| 2649 var location = document.location.origin + document.location.pathname + '#' + | 2650 var location = document.location.origin + document.location.pathname + '#' + |
| 2650 encodeURI(dirEntry.fullPath); | 2651 encodeURI(dirEntry.fullPath); |
| 2651 if (opt_saveHistory) { | 2652 if (opt_saveHistory) { |
| 2652 history.pushState(undefined, dirEntry.fullPath, location); | 2653 history.pushState(undefined, dirEntry.fullPath, location); |
| 2653 } else if (window.location.hash != location) { | 2654 } else if (window.location.hash != location) { |
| 2654 // If the user typed URL manually that is not canonical it would be fixed | 2655 // If the user typed URL manually that is not canonical it would be fixed |
| 2655 // here. However it seems history.replaceState doesn't work properly | 2656 // here. However it seems history.replaceState doesn't work properly |
| 2656 // with rewritable URLs (while does with history.pushState). It changes | 2657 // with rewritable URLs (while does with history.pushState). It changes |
| 2657 // window.location but doesn't change content of the ombibox. | 2658 // window.location but doesn't change content of the ombibox. |
| 2658 history.replaceState(undefined, dirEntry.fullPath, location); | 2659 history.replaceState(undefined, dirEntry.fullPath, location); |
| 2659 } | 2660 } |
| 2660 | 2661 |
| 2661 if (this.currentDirEntry_ && | 2662 if (this.currentDirEntry_ && |
| 2662 this.currentDirEntry_.fullPath == dirEntry.fullPath) { | 2663 this.currentDirEntry_.fullPath == dirEntry.fullPath) { |
| 2663 // Directory didn't actually change. | 2664 // Directory didn't actually change. |
| 2664 if (opt_selectedEntry) | 2665 if (opt_callback) |
|
Vladislav Kaznacheev
2011/12/06 13:46:28
Did you mean opt_action?
SeRya
2011/12/06 15:02:10
Fixed.
| |
| 2665 this.selectEntry(opt_selectedEntry); | 2666 opt_callback(); |
| 2666 else | |
| 2667 this.selectIndex(0); | |
| 2668 return; | 2667 return; |
| 2669 } | 2668 } |
| 2670 | 2669 |
| 2671 var e = new cr.Event('directory-changed'); | 2670 var e = new cr.Event('directory-changed'); |
| 2672 e.previousDirEntry = this.currentDirEntry_; | 2671 e.previousDirEntry = this.currentDirEntry_; |
| 2673 e.newDirEntry = dirEntry; | 2672 e.newDirEntry = dirEntry; |
| 2674 e.saveHistory = opt_saveHistory; | 2673 e.saveHistory = opt_saveHistory; |
| 2675 e.selectedEntry = opt_selectedEntry; | 2674 e.opt_callback = action; |
| 2676 e.opt_callback = opt_callback; | |
| 2677 this.currentDirEntry_ = dirEntry; | 2675 this.currentDirEntry_ = dirEntry; |
| 2678 this.dispatchEvent(e); | 2676 this.dispatchEvent(e); |
| 2679 } | 2677 } |
| 2680 | 2678 |
| 2681 /** | 2679 /** |
| 2682 * Change the current directory to the directory represented by a string | 2680 * Change the current directory to the directory represented by a string |
| 2683 * path. | 2681 * path. |
| 2684 * | 2682 * |
| 2685 * Dispatches the 'directory-changed' event when the directory is successfully | 2683 * Dispatches the 'directory-changed' event when the directory is successfully |
| 2686 * changed. | 2684 * changed. |
| 2687 * | 2685 * |
| 2688 * @param {string} path The absolute path to the new directory. | 2686 * @param {string} path The absolute path to the new directory. |
| 2689 * @param {bool} opt_saveHistory Save this in the history stack (defaults | 2687 * @param {bool} opt_saveHistory Save this in the history stack (defaults |
| 2690 * to true). | 2688 * to true). |
| 2691 * @param {string} opt_selectedEntry The name of the file to select after | 2689 * @param {string} opt_selectedEntry The name of the file to select after |
| 2692 * changing directories. | 2690 * changing directories. |
| 2693 */ | 2691 */ |
| 2694 FileManager.prototype.changeDirectory = function(path, | 2692 FileManager.prototype.changeDirectory = function(path, |
| 2695 opt_saveHistory, | 2693 opt_saveHistory) { |
| 2696 opt_selectedEntry, | |
| 2697 opt_callback) { | |
| 2698 if (path == '/') | 2694 if (path == '/') |
| 2699 return this.changeDirectoryEntry(this.filesystem_.root, | 2695 return this.changeDirectoryEntry(this.filesystem_.root, |
| 2700 opt_saveHistory, | 2696 opt_saveHistory); |
| 2701 opt_selectedEntry, | |
| 2702 opt_callback); | |
| 2703 | 2697 |
| 2704 var self = this; | 2698 var self = this; |
| 2705 | |
| 2706 this.filesystem_.root.getDirectory( | 2699 this.filesystem_.root.getDirectory( |
| 2707 path, {create: false}, | 2700 path, {create: false}, |
| 2708 function(dirEntry) { | 2701 function(dirEntry) { |
| 2709 self.changeDirectoryEntry( | 2702 self.changeDirectoryEntry(dirEntry, opt_saveHistory); |
| 2710 dirEntry, opt_saveHistory, opt_selectedEntry, opt_callback); | |
| 2711 }, | 2703 }, |
| 2712 function(err) { | 2704 function(err) { |
| 2713 console.error('Error changing directory to: ' + path + ', ' + err); | 2705 console.error('Error changing directory to: ' + path + ', ' + err); |
| 2714 if (self.currentDirEntry_) { | 2706 if (self.currentDirEntry_) { |
| 2715 var location = '#' + encodeURI(self.currentDirEntry_.fullPath); | 2707 var location = '#' + encodeURI(self.currentDirEntry_.fullPath); |
| 2716 history.replaceState(undefined, | 2708 history.replaceState(undefined, |
| 2717 self.currentDirEntry_.fullPath, | 2709 self.currentDirEntry_.fullPath, |
| 2718 location); | 2710 location); |
| 2719 } else { | 2711 } else { |
| 2720 // If we've never successfully changed to a directory, force them | 2712 // If we've never successfully changed to a directory, force them |
| 2721 // to the root. | 2713 // to the root. |
| 2722 self.changeDirectory('/', false); | 2714 self.changeDirectory('/', CD_NO_HISTORY); |
| 2723 } | 2715 } |
| 2724 }); | 2716 }); |
| 2725 }; | 2717 }; |
| 2726 | 2718 |
| 2727 FileManager.prototype.deleteEntries = function(entries, force, opt_callback) { | 2719 FileManager.prototype.deleteEntries = function(entries, force, opt_callback) { |
| 2728 if (!force) { | 2720 if (!force) { |
| 2729 var self = this; | 2721 var self = this; |
| 2730 var msg; | 2722 var msg; |
| 2731 if (entries.length == 1) { | 2723 if (entries.length == 1) { |
| 2732 msg = strf('CONFIRM_DELETE_ONE', entries[0].name); | 2724 msg = strf('CONFIRM_DELETE_ONE', entries[0].name); |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3073 this.subscribedOnDirectoryChanges_ = true; | 3065 this.subscribedOnDirectoryChanges_ = true; |
| 3074 chrome.fileBrowserPrivate.addFileWatch(event.newDirEntry.toURL(), | 3066 chrome.fileBrowserPrivate.addFileWatch(event.newDirEntry.toURL(), |
| 3075 function(result) { | 3067 function(result) { |
| 3076 if (!result) { | 3068 if (!result) { |
| 3077 console.log('Failed to add file watch'); | 3069 console.log('Failed to add file watch'); |
| 3078 } | 3070 } |
| 3079 }); | 3071 }); |
| 3080 } | 3072 } |
| 3081 | 3073 |
| 3082 this.rescanDirectory_(function() { | 3074 this.rescanDirectory_(function() { |
| 3083 if (event.selectedEntry) | |
| 3084 self.selectEntry(event.selectedEntry); | |
| 3085 else | |
| 3086 self.selectIndex(0); | |
| 3087 if (event.opt_callback) { | 3075 if (event.opt_callback) { |
| 3088 try { | 3076 try { |
| 3089 event.opt_callback(); | 3077 event.opt_callback(); |
| 3090 } catch (ex) { | 3078 } catch (ex) { |
| 3091 console.error('Caught exception while inovking callback: ', ex); | 3079 console.error('Caught exception while inovking callback: ', ex); |
| 3092 } | 3080 } |
| 3093 } | 3081 } |
| 3094 // For tests that open the dialog to empty directories, everything | 3082 // For tests that open the dialog to empty directories, everything |
| 3095 // is loaded at this point. | 3083 // is loaded at this point. |
| 3096 chrome.test.sendMessage('directory-change-complete'); | 3084 chrome.test.sendMessage('directory-change-complete'); |
| (...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3990 }); | 3978 }); |
| 3991 }, onError); | 3979 }, onError); |
| 3992 | 3980 |
| 3993 function onError(err) { | 3981 function onError(err) { |
| 3994 console.log('Error while checking free space: ' + err); | 3982 console.log('Error while checking free space: ' + err); |
| 3995 setTimeout(doCheck, 1000 * 60); | 3983 setTimeout(doCheck, 1000 * 60); |
| 3996 } | 3984 } |
| 3997 } | 3985 } |
| 3998 } | 3986 } |
| 3999 })(); | 3987 })(); |
| OLD | NEW |