| 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 /** | 5 /** |
| 6 * Namespace for utility functions. | 6 * Namespace for utility functions. |
| 7 */ | 7 */ |
| 8 var util = {}; | 8 var util = {}; |
| 9 | 9 |
| 10 /** | 10 /** |
| (...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 * @const | 582 * @const |
| 583 */ | 583 */ |
| 584 util.EntryChangedKind = { | 584 util.EntryChangedKind = { |
| 585 CREATED: 0, | 585 CREATED: 0, |
| 586 DELETED: 1, | 586 DELETED: 1, |
| 587 }; | 587 }; |
| 588 Object.freeze(util.EntryChangedKind); | 588 Object.freeze(util.EntryChangedKind); |
| 589 | 589 |
| 590 /** | 590 /** |
| 591 * Obtains whether an entry is fake or not. | 591 * Obtains whether an entry is fake or not. |
| 592 * @param {(!Entry|!Object)} entry Entry or a fake entry. | 592 * @param {(!Entry|!FakeEntry)} entry Entry or a fake entry. |
| 593 * @return {boolean} True if the given entry is fake. | 593 * @return {boolean} True if the given entry is fake. |
| 594 */ | 594 */ |
| 595 util.isFakeEntry = function(entry) { | 595 util.isFakeEntry = function(entry) { |
| 596 return !('getParent' in entry); | 596 return !('getParent' in entry); |
| 597 }; | 597 }; |
| 598 | 598 |
| 599 /** | 599 /** |
| 600 * Creates an instance of UserDOMError with given error name that looks like a | 600 * Creates an instance of UserDOMError with given error name that looks like a |
| 601 * FileError except that it does not have the deprecated FileError.code member. | 601 * FileError except that it does not have the deprecated FileError.code member. |
| 602 * | 602 * |
| (...skipping 23 matching lines...) Expand all Loading... |
| 626 util.UserDOMError.prototype = { | 626 util.UserDOMError.prototype = { |
| 627 /** | 627 /** |
| 628 * @return {string} File error name. | 628 * @return {string} File error name. |
| 629 */ | 629 */ |
| 630 get name() { return this.name_; | 630 get name() { return this.name_; |
| 631 } | 631 } |
| 632 }; | 632 }; |
| 633 | 633 |
| 634 /** | 634 /** |
| 635 * Compares two entries. | 635 * Compares two entries. |
| 636 * @param {Entry|Object} entry1 The entry to be compared. Can be a fake. | 636 * @param {Entry|FakeEntry} entry1 The entry to be compared. Can be a fake. |
| 637 * @param {Entry|Object} entry2 The entry to be compared. Can be a fake. | 637 * @param {Entry|FakeEntry} entry2 The entry to be compared. Can be a fake. |
| 638 * @return {boolean} True if the both entry represents a same file or | 638 * @return {boolean} True if the both entry represents a same file or |
| 639 * directory. Returns true if both entries are null. | 639 * directory. Returns true if both entries are null. |
| 640 */ | 640 */ |
| 641 util.isSameEntry = function(entry1, entry2) { | 641 util.isSameEntry = function(entry1, entry2) { |
| 642 if (!entry1 && !entry2) | 642 if (!entry1 && !entry2) |
| 643 return true; | 643 return true; |
| 644 if (!entry1 || !entry2) | 644 if (!entry1 || !entry2) |
| 645 return false; | 645 return false; |
| 646 return entry1.toURL() === entry2.toURL(); | 646 return entry1.toURL() === entry2.toURL(); |
| 647 }; | 647 }; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 * @return {number} Compare result. | 685 * @return {number} Compare result. |
| 686 */ | 686 */ |
| 687 util.comparePath = function(entry1, entry2) { | 687 util.comparePath = function(entry1, entry2) { |
| 688 return util.collator.compare(entry1.fullPath, entry2.fullPath); | 688 return util.collator.compare(entry1.fullPath, entry2.fullPath); |
| 689 }; | 689 }; |
| 690 | 690 |
| 691 /** | 691 /** |
| 692 * Checks if {@code entry} is an immediate child of {@code directory}. | 692 * Checks if {@code entry} is an immediate child of {@code directory}. |
| 693 * | 693 * |
| 694 * @param {Entry} entry The presumptive child. | 694 * @param {Entry} entry The presumptive child. |
| 695 * @param {DirectoryEntry} directory The presumptive parent. | 695 * @param {DirectoryEntry|FakeEntry} directory The presumptive parent. |
| 696 * @return {!Promise.<boolean>} Resolves with true if {@code directory} is | 696 * @return {!Promise.<boolean>} Resolves with true if {@code directory} is |
| 697 * parent of {@code entry}. | 697 * parent of {@code entry}. |
| 698 */ | 698 */ |
| 699 util.isChildEntry = function(entry, directory) { | 699 util.isChildEntry = function(entry, directory) { |
| 700 return new Promise( | 700 return new Promise( |
| 701 function(resolve, reject) { | 701 function(resolve, reject) { |
| 702 if (!entry || !directory) { | 702 if (!entry || !directory) { |
| 703 resolve(false); | 703 resolve(false); |
| 704 } | 704 } |
| 705 | 705 |
| 706 entry.getParent( | 706 entry.getParent( |
| 707 function(parent) { | 707 function(parent) { |
| 708 resolve(util.isSameEntry(parent, directory)); | 708 resolve(util.isSameEntry(parent, directory)); |
| 709 }, | 709 }, |
| 710 reject); | 710 reject); |
| 711 }); | 711 }); |
| 712 }; | 712 }; |
| 713 | 713 |
| 714 /** | 714 /** |
| 715 * Checks if the child entry is a descendant of another entry. If the entries | 715 * Checks if the child entry is a descendant of another entry. If the entries |
| 716 * point to the same file or directory, then returns false. | 716 * point to the same file or directory, then returns false. |
| 717 * | 717 * |
| 718 * @param {!DirectoryEntry|!Object} ancestorEntry The ancestor directory entry. | 718 * @param {!DirectoryEntry|!FakeEntry} ancestorEntry The ancestor directory |
| 719 * Can be a fake. | 719 * entry. Can be a fake. |
| 720 * @param {!Entry|!Object} childEntry The child entry. Can be a fake. | 720 * @param {!Entry|!FakeEntry} childEntry The child entry. Can be a fake. |
| 721 * @return {boolean} True if the child entry is contained in the ancestor path. | 721 * @return {boolean} True if the child entry is contained in the ancestor path. |
| 722 */ | 722 */ |
| 723 util.isDescendantEntry = function(ancestorEntry, childEntry) { | 723 util.isDescendantEntry = function(ancestorEntry, childEntry) { |
| 724 if (!ancestorEntry.isDirectory) | 724 if (!ancestorEntry.isDirectory) |
| 725 return false; | 725 return false; |
| 726 if (!util.isSameFileSystem(ancestorEntry.filesystem, childEntry.filesystem)) | 726 if (!util.isSameFileSystem(ancestorEntry.filesystem, childEntry.filesystem)) |
| 727 return false; | 727 return false; |
| 728 if (util.isSameEntry(ancestorEntry, childEntry)) | 728 if (util.isSameEntry(ancestorEntry, childEntry)) |
| 729 return false; | 729 return false; |
| 730 if (util.isFakeEntry(ancestorEntry) || util.isFakeEntry(childEntry)) | 730 if (util.isFakeEntry(ancestorEntry) || util.isFakeEntry(childEntry)) |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1033 * @param {!cr.EventTarget} target | 1033 * @param {!cr.EventTarget} target |
| 1034 * @param {string} type | 1034 * @param {string} type |
| 1035 * @param {Function} handler | 1035 * @param {Function} handler |
| 1036 */ | 1036 */ |
| 1037 util.addEventListenerToBackgroundComponent = function(target, type, handler) { | 1037 util.addEventListenerToBackgroundComponent = function(target, type, handler) { |
| 1038 target.addEventListener(type, handler); | 1038 target.addEventListener(type, handler); |
| 1039 window.addEventListener('pagehide', function() { | 1039 window.addEventListener('pagehide', function() { |
| 1040 target.removeEventListener(type, handler); | 1040 target.removeEventListener(type, handler); |
| 1041 }); | 1041 }); |
| 1042 }; | 1042 }; |
| OLD | NEW |