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

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: fix indent 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
« no previous file with comments | « chrome/browser/resources/file_manager/js/file_transfer_controller.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 /** 10 /**
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 * @param {Object} transform Transform object, 534 * @param {Object} transform Transform object,
535 * contains scaleX, scaleY and rotate90 properties. 535 * contains scaleX, scaleY and rotate90 properties.
536 */ 536 */
537 util.applyTransform = function(element, transform) { 537 util.applyTransform = function(element, transform) {
538 element.style.webkitTransform = 538 element.style.webkitTransform =
539 transform ? 'scaleX(' + transform.scaleX + ') ' + 539 transform ? 'scaleX(' + transform.scaleX + ') ' +
540 'scaleY(' + transform.scaleY + ') ' + 540 'scaleY(' + transform.scaleY + ') ' +
541 'rotate(' + transform.rotate90 * 90 + 'deg)' : 541 'rotate(' + transform.rotate90 * 90 + 'deg)' :
542 ''; 542 '';
543 }; 543 };
544
545 /**
546 * Given a list of gdata search result urls, generates a list of urls which
547 * gdata search result urls reference.
548 *
549 * @param {Array.<string>} urls List of gdata search result urls.
550 * @param {string} rootUrl Root url for resolved urls. Should be gdata root
551 * url.
552 * @param {function(Array.<string>)} callback Callback that will be invoked
553 * when the method finishes. It will be passed list of resolved urls.
554 */
555 util.resolveGDataSearchUrls = function(urls, rootUrl, callback) {
556 var resolvedUrls = [];
557 // If the list of urls is empty, there's nothing to do.
558 if (urls.length == 0) {
559 callback([]);
560 return;
561 }
562
563 // Given relative file path, it will generate escaped file path that will
564 // be appended to rootUrl to form the resolved url.
565 function getURIEncodedPath(filePath) {
566 var components = filePath.split('/');
567 // Root url should already contain path's root dir, so clear it.
568 components[0] = '';
569 for (var i = 0; i < components.length; i++)
570 components[i] = encodeURIComponent(components[i]);
571 return components.join('/');
572 }
573
574 // Resolves single url at |urls[index]| and calls |onResolved| with |index|.
575 function resolveUrl(index, onResolved) {
576 chrome.fileBrowserPrivate.getPathForDriveSearchResult(urls[index],
577 function(filePath) {
578 if (filePath) {
579 resolvedUrls.push(rootUrl + getURIEncodedPath(filePath));
580 } else {
581 // If we weren't able to resolve the url, fallback to using
582 // original url.
583 resolvedUrls.push(urls[index]);
584 }
585 onResolved(index);
586 });
587 }
588
589 // If not all urls are resolved, starts resolving next one, else calls
590 // callback
591 function resolveNextOrFinish(lastIndex) {
592 var nextIndex = lastIndex + 1;
593 if (nextIndex == urls.length) {
594 callback(resolvedUrls);
595 return;
596 }
597 resolveUrl(nextIndex, resolveNextOrFinish);
598 }
599
600 // Start resolving first url.
601 resolveUrl(0, resolveNextOrFinish);
602 };
603
604 /**
605 * Tests if the given path is a gdata search result path, and if it is,
606 * returns file's fileName in virtual search file system, its gdata resourceId
607 * and the display name that should be used when the file is shown in file
608 * browser.
609 *
610 * @param {string} path The potential gdata search result path.
611 * @return {object.<string, stringi, string>} Object that will contain file's
612 * fileName, displayName and resourceId; or null if the path is not gdata
613 * search result path.
614 */
615 util.getFileAndDisplayNameForGDataSearchResult = function(path) {
616 // Nothing to do if the path is not under gdata search root path.
617 if (path.indexOf(DirectoryModel.GDATA_SEARCH_ROOT_PATH) != 0)
618 return null;
619
620 var pathComponents = path.split('/');
621
622 // Search result should be formatted like:
623 // gdataSearchRoot/query/result
624 if (pathComponents.length !=
625 DirectoryModel.GDATA_SEARCH_ROOT_COMPONENTS.length + 2)
626 return null;
627 for (var i = 0;
628 i < DirectoryModel.GDATA_SEARCH_ROOT_COMPONENTS.length;
629 i++) {
630 if (pathComponents[i] != DirectoryModel.GDATA_SEARCH_ROOT_COMPONENTS[i])
631 return null;
632 }
633
634 // Search result file name should be formatted like:
635 // resource_id.referenced_file_name
636 // We should display referenced file name only.
637 var result = {};
638 result.fileName = pathComponents.pop();
639 result.displayName =
640 result.fileName.slice(result.fileName.indexOf('.') + 1);
641 result.resourceId =
642 result.fileName.substr(0, result.fileName.indexOf('.'));
643
644 if (result.fileName.length > 0 && result.displayName.length > 0) {
645 return result;
646 } else {
647 return null;
648 }
649 };
OLDNEW
« no previous file with comments | « chrome/browser/resources/file_manager/js/file_transfer_controller.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698