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 * Returns a function that console.log's its arguments, prefixed by |msg|. | 10 * Returns a function that console.log's its arguments, prefixed by |msg|. |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 (event.shiftKey ? 'Shift-' : '') + | 507 (event.shiftKey ? 'Shift-' : '') + |
508 (event.metaKey ? 'Meta-' : ''); | 508 (event.metaKey ? 'Meta-' : ''); |
509 }, | 509 }, |
510 | 510 |
511 /** | 511 /** |
512 * A wrapper for navigator.onLine that allows for easy debug override. | 512 * A wrapper for navigator.onLine that allows for easy debug override. |
513 * @return {boolean} True if offline. | 513 * @return {boolean} True if offline. |
514 */ | 514 */ |
515 isOffline: function() { | 515 isOffline: function() { |
516 return !navigator.onLine; | 516 return !navigator.onLine; |
| 517 }, |
| 518 |
| 519 /** |
| 520 * Tests if the given path is a gdata search result path, and if it is, |
| 521 * returns file's fileName in virtual search file system, its gdata resourceId |
| 522 * and the display name that should be used when the file is shown in file |
| 523 * browser. |
| 524 * |
| 525 * @param {string} path The potential gdata search result path. |
| 526 * @return {object.<string, stringi, string>} Object that will contain file's |
| 527 * fileName, displayName and resourceId; or null if the path is not gdata |
| 528 * search result path. |
| 529 */ |
| 530 getFileAndDisplayNameForGDataSearchResult: function(path) { |
| 531 // Nothing to do if the path is not under gdata search root path. |
| 532 if (path.search(DirectoryModel.GDATA_SEARCH_ROOT_PATH) != 0) |
| 533 return null; |
| 534 |
| 535 var pathComponents = path.split('/'); |
| 536 |
| 537 // Search result should be formatted like: |
| 538 // gdataSearchRoot/query/result |
| 539 if (pathComponents.length != |
| 540 DirectoryModel.GDATA_SEARCH_ROOT_COMPONENTS.length + 2) |
| 541 return null; |
| 542 for (var i = 0; |
| 543 i < DirectoryModel.GDATA_SEARCH_ROOT_COMPONENTS.length; |
| 544 i++) { |
| 545 if (pathComponents[i] != DirectoryModel.GDATA_SEARCH_ROOT_COMPONENTS[i]) |
| 546 return null; |
| 547 } |
| 548 |
| 549 // Search result file name should be formatted like: |
| 550 // resource_id.referenced_file_name |
| 551 // We should display referenced file name only. |
| 552 var result = {}; |
| 553 result.fileName = pathComponents.pop(); |
| 554 result.displayName = |
| 555 result.fileName.slice(result.fileName.indexOf('.') + 1); |
| 556 result.resourceId = |
| 557 result.fileName.substr(0, result.fileName.indexOf('.')); |
| 558 |
| 559 if (result.fileName.length > 0 && result.displayName.length > 0) { |
| 560 return result; |
| 561 } else { |
| 562 return null; |
| 563 } |
517 } | 564 } |
518 }; | 565 }; |
OLD | NEW |