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

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: feedback 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 path {string} 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(this.GDATA_SEARCH_ROOT_PATH) != 0)
517 return false;
518
519 var pathComponents = path.split('/');
520
521 // We should not create entries on path if it's either gdata search root,
522 // or its immediate child.
523 var lengthDifference =
524 pathComponents.length - this.GDATA_SEARCH_ROOT_COMPONENTS.length;
525 return lengthDifference == 0 || lengthDifference == 1;
526 },
527
528 /*
529 * Root path used for displaying gdata content search results.
530 * Search results will be shown in directory 'GDATA_SEARCH_ROOT_PATH/query'.
531 *
532 * @const
533 * @type {string}
534 */
535 GDATA_SEARCH_ROOT_PATH: '/gdata/.search/',
536
537 /*
538 * @const
539 * @type {Array.<string>}
540 */
541 GDATA_SEARCH_ROOT_COMPONENTS: ["", "gdata", ".search"],
542
543 /*
544 * Creates directory path in which gdata content search results for |query|
545 * should be displayed.
546 *
547 * @param query {string} Search query.
548 * @return {string} Virtual directory path for search results.
549 */
550 createGDataSearchPath: function(query) {
551 return this.GDATA_SEARCH_ROOT_PATH + '/' + query;
dgozman 2012/05/04 11:39:36 I'm almost sure that presubmit check will warn abo
tbarzic 2012/05/05 00:56:06 Done.
552 },
553
554 /*
555 * Tests if the given path is a gdata search result path, and if it is,
556 * returns file's fileName in virtual search file system, its gdata resourceId
557 * and the display name that should be used when the file is shown in file
558 * browser.
559 *
560 * @param path {string} The potential gdata search result path.
561 * @return {object.<string, stringi, string>} Object that will contain file's
562 * fileName, displayName and resourceId; or null if the path is not gdata
563 * search result path.
564 */
565 getFileAndDisplayNameForGDataSearchResult: function(path) {
566 // Nothing to do if the path is not under gdata search root path.
567 if (path.search(this.GDATA_SEARCH_ROOT_PATH) != 0)
568 return null;
569
570 var pathComponents = path.split('/');
571
572 // Search result should be formatted like:
573 // gdataSearchRoot/query/result
574 if (pathComponents.length != this.GDATA_SEARCH_ROOT_COMPONENTS.length + 2)
575 return null;
576 for (var i = 0; i < this.GDATA_SEARCH_ROOT_COMPONENTS.length; i++) {
577 if (pathComponents[i] != this.GDATA_SEARCH_ROOT_COMPONENTS[i])
578 return null;
579 }
580
581 // Search result file name should be formatted like:
582 // resource_id.referenced_file_name
583 // We should display referenced file name only.
584 var result = {};
585 result.fileName = pathComponents.pop();
586 result.displayName =
587 result.fileName.slice(result.fileName.indexOf('.') + 1);
588 result.resourceId =
589 result.fileName.substr(0, result.fileName.indexOf('.'));
590
591 if (result.fileName.length > 0 && result.displayName.length > 0) {
592 return result;
593 } else {
594 return null;
595 }
502 } 596 }
503 }; 597 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698