Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Side by Side Diff: chrome/browser/resources/file_manager/js/util.js

Issue 10342010: Add gdata content search to file_manager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: style nits Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 (event.shiftKey ? 'Shift-' : '') + 492 (event.shiftKey ? 'Shift-' : '') +
493 (event.metaKey ? 'Meta-' : ''); 493 (event.metaKey ? 'Meta-' : '');
494 }, 494 },
495 495
496 /** 496 /**
497 * A wrapper for navigator.onLine that allows for easy debug override. 497 * A wrapper for navigator.onLine that allows for easy debug override.
498 * @return {boolean} True if offline. 498 * @return {boolean} True if offline.
499 */ 499 */
500 isOffline: function() { 500 isOffline: function() {
501 return !navigator.onLine; 501 return !navigator.onLine;
502 },
503
504 /*
505 * Tests if |path| references special, internaly used directory in which
506 * creating new entries is not allowed.
507 * Currently, only paths used for gdata content search match this description
508 * (gdata content search root directory and directories that contain gdata
509 * content search results).
510 *
511 * @param {string} path Path which is being tested.
512 * @return {boolean} Test result.
513 */
514 isSpecialReadonlyDirectory: function(path) {
515 // If the path is not search root or it's child, we're fine.
516 if (path.search(util.GDATA_SEARCH_ROOT_PATH) != 0 &&
517 path + '/' != util.GDATA_SEARCH_ROOT_PATH) {
518 return false;
519 }
520
521 var pathComponents = path.split('/');
522
523 // We should not create entries on path if it's either gdata search root,
524 // or its immediate child.
525 var lengthDifference =
526 pathComponents.length - util.GDATA_SEARCH_ROOT_COMPONENTS.length;
527 return lengthDifference == 0 || lengthDifference == 1;
528 },
529
530 /*
531 * Root path used for displaying gdata content search results.
532 * Search results will be shown in directory 'GDATA_SEARCH_ROOT_PATH/query'.
533 *
534 * @const
535 * @type {string}
536 */
537 GDATA_SEARCH_ROOT_PATH: '/gdata/.search',
538
539 /*
540 * @const
541 * @type {Array.<string>}
542 */
543 GDATA_SEARCH_ROOT_COMPONENTS: ['', 'gdata', '.search'],
544
545 /*
546 * Creates directory path in which gdata content search results for |query|
547 * should be displayed.
548 *
549 * @param {string} query Search query.
550 * @return {string} Virtual directory path for search results.
551 */
552 createGDataSearchPath: function(query) {
553 return util.GDATA_SEARCH_ROOT_PATH + '/' + query;
554 },
555
556 /*
557 * Tests if the given path is a gdata search result path, and if it is,
558 * returns file's fileName in virtual search file system, its gdata resourceId
559 * and the display name that should be used when the file is shown in file
560 * browser.
561 *
562 * @param {string} path The potential gdata search result path.
563 * @return {object.<string, stringi, string>} Object that will contain file's
564 * fileName, displayName and resourceId; or null if the path is not gdata
565 * search result path.
566 */
567 getFileAndDisplayNameForGDataSearchResult: function(path) {
568 // Nothing to do if the path is not under gdata search root path.
569 if (path.search(util.GDATA_SEARCH_ROOT_PATH) != 0)
570 return null;
571
572 var pathComponents = path.split('/');
573
574 // Search result should be formatted like:
575 // gdataSearchRoot/query/result
576 if (pathComponents.length != util.GDATA_SEARCH_ROOT_COMPONENTS.length + 2)
577 return null;
578 for (var i = 0; i < util.GDATA_SEARCH_ROOT_COMPONENTS.length; i++) {
579 if (pathComponents[i] != util.GDATA_SEARCH_ROOT_COMPONENTS[i])
580 return null;
581 }
582
583 // Search result file name should be formatted like:
584 // resource_id.referenced_file_name
585 // We should display referenced file name only.
586 var result = {};
587 result.fileName = pathComponents.pop();
588 result.displayName =
589 result.fileName.slice(result.fileName.indexOf('.') + 1);
590 result.resourceId =
591 result.fileName.substr(0, result.fileName.indexOf('.'));
592
593 if (result.fileName.length > 0 && result.displayName.length > 0) {
594 return result;
595 } else {
596 return null;
597 }
502 } 598 }
503 }; 599 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698