1// Copyright (c) 2011 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5/** 6 * Mock out the chrome.fileBrowserPrivate API for use in the harness. 7 */ 8chrome.fileBrowserPrivate = { 9 10 /** 11 * Return a normal HTML5 filesystem api, rather than the real local 12 * filesystem. 13 * 14 * You must start chrome with --allow-file-access-from-files and 15 * --unlimited-quota-for-files in order for this to work. 16 */ 17 requestLocalFileSystem: function(callback) { 18 window.webkitRequestFileSystem(window.PERSISTENT, 16 * 1024 * 1024, 19 callback, 20 util.ferr('Error requesting filesystem')); 21 }, 22 23 /** 24 * View multiple files. 25 */ 26 viewFiles: function(selectedFiles) { 27 console.log('viewFiles called: ' + selectedFiles.length + 28 ' files selected'); 29 }, 30 31 /** 32 * Select multiple files. 33 */ 34 selectFiles: function(selectedFiles) { 35 console.log('selectFiles called: ' + selectedFiles.length + 36 ' files selected'); 37 }, 38 39 /** 40 * Select a single file. 41 */ 42 selectFile: function(selectedFile, index) { 43 console.log('selectFile called: ' + selectedFile + ', ' + index); 44 }, 45 46 /** 47 * Cancel the dialog without selecting anything. 48 */ 49 cancelDialog: function() { 50 console.log('cancelDialog called'); 51 }, 52 53 /** 54 * Disk mount/unmount notification. 55 */ 56 onDiskChanged: { 57 callbacks: [], 58 addListener: function(cb) { this.callbacks.push(cb) } 59 }, 60 61 getFileTasks: function(urlList, callback) { 62 if (urlList.length == 0) 63 return callback([]); 64 65 if (!callback) 66 throw new Error('Missing callback'); 67 68 var tasks = 69 [ { taskId: 'upload-picasr', 70 title: 'Upload to Picasr', 71 regexp: /\.(jpe?g|gif|png|cr2?|tiff)$/i, 72 iconUrl: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAOCAYAAAAmL5yKAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sEEBcJA0AW6BUAAACdSURBVCjPzZExC4MwEIW/1L2U/gwHf1/3WrqIkz/PWVAoXdolRNLBJNhwiS6FPjguuZf3csnBL2HBLikNtSFmS3yIROUMWhKrHR2XNZiLa9tGkaqtDa4TjBX0yIf8+osLnT3BnKDIvddm/uCRE+fgDc7r4iBPJWAWDADQLh8Tt3neSAYKdAu8gc69L4rAN8v+Fk/3DrxcluD5mr/CB34jRiE3x1kcAAAAAElFTkSuQmCC', 73 }, 74 { taskId: 'upload-orcbook', 75 title: 'Upload to OrcBook', 76 regexp: /\.(jpe?g|png|cr2?|tiff)$/i, 77 iconUrl: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAOCAYAAAAmL5yKAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sEEBcOAw9XftIAAADFSURBVCjPrZKxCsIwEIa/FHFwsvYxROjSQXAoqLiIL+xgBtvZ91A6uOnQc2hT0zRqkR4c3P25+/PfJTCwLU6wEpgBWkDXuInDPSwF5r7mJIeNQFTnIiCeONpVdYlLoK9wEUhNg8+B9FDVaZcgCKAovjTXfvPJFwGZtKW60pt8bOGBzfLouemnFY/MAs8wDeEI4NzaybewBu4AysKVgrK0gfe5iB9vjdAUqQ/S1Y/R3IX9Zc1zxc7zxe2/0Iskt7AsG0hhx14W8XV43FgV4gAAAABJRU5ErkJggg==', 78 }, 79 ]; 80 81 // Copy all tasks, then remove the ones that don't match. 82 var candidateTasks = [].concat(tasks); 83 84 for (var i = 0; i < urlList.length; i++) { 85 if (candidateTasks.length == 0) 86 return callback([]); 87 88 for (var taskIndex = candidateTasks.length - 1; taskIndex >= 0; 89 taskIndex--) { 90 if (candidateTasks[taskIndex].regexp.test(urlList[i])) 91 continue; 92 93 // This task doesn't match this url, remove the task. 94 candidateTasks.splice(taskIndex, 1); 95 } 96 } 97 98 callback(candidateTasks); 99 }, 100 101 executeTask: function(taskId, urlList) { 102 console.log('executing task: ' + taskId + ': ' + urlList.length + ' urls'); 103 }, 104 105 /** 106 * Return localized strings. 107 */ 108 getStrings: function(callback) { 109 // Keep this list in sync with the strings in generated_resources.grd and 110 // extension_file_manager_api.cc! 111 callback({ 112 LOCALE_FMT_DATE_SHORT: '%b %-d, %Y', 113 LOCALE_MONTHS_SHORT: 'Jan^Feb^Mar^Apr^May^Jun^Jul^Aug^Sep^Oct^Nov^Dec', 114 LOCALE_DAYS_SHORT: 'Sun^Mon^Tue^Wed^Thu^Fri^Sat', 115 116 BODY_FONT_FAMILY: 'sans-serif', 117 BODY_FONT_SIZE: '13px', 118 119 FILE_IS_DIRECTORY: 'Folder', 120 PARENT_DIRECTORY: 'Parent Directory', 121 122 ROOT_DIRECTORY_LABEL: 'Files', 123 DOWNLOADS_DIRECTORY_LABEL: 'File Shelf', 124 MEDIA_DIRECTORY_LABEL: 'External Storage', 125 NAME_COLUMN_LABEL: 'Name', 126 SIZE_COLUMN_LABEL: 'Size', 127 DATE_COLUMN_LABEL: 'Date', 128 PREVIEW_COLUMN_LABEL: 'Preview', 129 130 ERROR_CREATING_FOLDER: 'Unable to create folder "$1": $2', 131 ERROR_INVALID_FOLDER_CHARACTER: 'Invalid character in folder name: $1', 132 ERROR_INVALID_FILE_CHARACTER: 'Invalid character in file name: $1', 133 NEW_FOLDER_PROMPT: 'Enter a name for the new folder', 134 NEW_FOLDER_BUTTON_LABEL: 'New Folder', 135 FILENAME_LABEL: 'File Name', 136 137 EJECT_BUTTON: 'Eject', 138 IMAGE_DIMENSIONS: 'Image Dimensions', 139 VOLUME_LABEL: 'Volume Label', 140 READ_ONLY: 'Read Only', 141 142 ERROR_RENAMING: 'Unable to rename "$1": $2', 143 RENAME_PROMPT: 'Enter a new name', 144 RENAME_BUTTON_LABEL: 'Rename', 145 146 ERROR_DELETING: 'Unable to delete "$1": $2', 147 DELETE_BUTTON_LABEL: 'Delete', 148 149 ERROR_MOVING: 'Unable to move "$1": $2', 150 MOVE_BUTTON_LABEL: 'Move', 151 152 ERROR_PASTING: 'Unable to paste "$1": $2', 153 PASTE_BUTTON_LABEL: 'Paste', 154 155 COPY_BUTTON_LABEL: 'Copy', 156 CUT_BUTTON_LABEL: 'Cut', 157 158 DEVICE_TYPE_FLASH: 'Flash Device', 159 DEVICE_TYPE_HDD: 'Hard Disk Device', 160 DEVICE_TYPE_OPTICAL: 'Optical Device', 161 DEVICE_TYPE_UNDEFINED: 'Unknown Device', 162 163 CANCEL_LABEL: 'Cancel', 164 OPEN_LABEL: 'Open', 165 SAVE_LABEL: 'Save', 166 167 SELECT_FOLDER_TITLE: 'Select a folder to open', 168 SELECT_OPEN_FILE_TITLE: 'Select a file to open', 169 SELECT_OPEN_MULTI_FILE_TITLE: 'Select one or more files', 170 SELECT_SAVEAS_FILE_TITLE: 'Select a file to save as', 171 172 COMPUTING_SELECTION: 'Computing selection...', 173 NOTHING_SELECTED: 'No files selected', 174 ONE_FILE_SELECTED: 'One file selected, $1', 175 MANY_FILES_SELECTED: '$1 files selected, $2', 176 177 CONFIRM_DELETE: 'Are you sure?', 178 }); 179 } 180}; 181 182chrome.extension = { 183 getURL: function() { 184 return document.location.href; 185 } 186}; 187