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 * FileManager constructor. | 6 * FileManager constructor. |
7 * | 7 * |
8 * FileManager objects encapsulate the functionality of the file selector | 8 * FileManager objects encapsulate the functionality of the file selector |
9 * dialogs, as well as the full screen file manager application (though the | 9 * dialogs, as well as the full screen file manager application (though the |
10 * latter is not yet implemented). | 10 * latter is not yet implemented). |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 var IMAGE_HOVER_PREVIEW_SIZE = 200; | 114 var IMAGE_HOVER_PREVIEW_SIZE = 200; |
115 | 115 |
116 /** | 116 /** |
117 * The minimum about of time to display the butter bar for, in ms. | 117 * The minimum about of time to display the butter bar for, in ms. |
118 * Justification is 1000ms for minimum display time plus 300ms for transition | 118 * Justification is 1000ms for minimum display time plus 300ms for transition |
119 * duration. | 119 * duration. |
120 */ | 120 */ |
121 var MINIMUM_BUTTER_DISPLAY_TIME_MS = 1300; | 121 var MINIMUM_BUTTER_DISPLAY_TIME_MS = 1300; |
122 | 122 |
123 /** | 123 /** |
124 * Translated strings. | |
125 */ | |
126 var localStrings; | |
127 | |
128 /** | |
129 * Item for the Grid View. | 124 * Item for the Grid View. |
130 * @constructor | 125 * @constructor |
131 */ | 126 */ |
132 function GridItem(fileManager, entry) { | 127 function GridItem(fileManager, entry) { |
133 var li = fileManager.document_.createElement('li'); | 128 var li = fileManager.document_.createElement('li'); |
134 GridItem.decorate(li, fileManager, entry); | 129 GridItem.decorate(li, fileManager, entry); |
135 return li; | 130 return li; |
136 } | 131 } |
137 | 132 |
138 GridItem.prototype = { | 133 GridItem.prototype = { |
(...skipping 10 matching lines...) Expand all Loading... |
149 | 144 |
150 GridItem.decorate = function(li, fileManager, entry) { | 145 GridItem.decorate = function(li, fileManager, entry) { |
151 li.__proto__ = GridItem.prototype; | 146 li.__proto__ = GridItem.prototype; |
152 fileManager.decorateThumbnail_(li, entry); | 147 fileManager.decorateThumbnail_(li, entry); |
153 }; | 148 }; |
154 | 149 |
155 /** | 150 /** |
156 * Return a translated string. | 151 * Return a translated string. |
157 * | 152 * |
158 * Wrapper function to make dealing with translated strings more concise. | 153 * Wrapper function to make dealing with translated strings more concise. |
159 * Equivilant to localStrings.getString(id). | 154 * Equivalent to loadTimeData.getString(id). |
160 * | 155 * |
161 * @param {string} id The id of the string to return. | 156 * @param {string} id The id of the string to return. |
162 * @return {string} The translated string. | 157 * @return {string} The translated string. |
163 */ | 158 */ |
164 function str(id) { | 159 function str(id) { |
165 return localStrings.getString(id) || ('UNLOCALIZED STRING ' + id); | 160 return loadTimeData.getString(id); |
166 } | 161 } |
167 | 162 |
168 /** | 163 /** |
169 * Return a translated string with arguments replaced. | 164 * Return a translated string with arguments replaced. |
170 * | 165 * |
171 * Wrapper function to make dealing with translated strings more concise. | 166 * Wrapper function to make dealing with translated strings more concise. |
172 * Equivilant to localStrings.getStringF(id, ...). | 167 * Equivilant to loadTimeData.getStringF(id, ...). |
173 * | 168 * |
174 * @param {string} id The id of the string to return. | 169 * @param {string} id The id of the string to return. |
175 * @param {...string} The values to replace into the string. | 170 * @param {...string} The values to replace into the string. |
176 * @return {string} The translated string with replaced values. | 171 * @return {string} The translated string with replaced values. |
177 */ | 172 */ |
178 function strf(id, var_args) { | 173 function strf(id, var_args) { |
179 return localStrings.getStringF.apply(localStrings, arguments); | 174 return loadTimeData.getStringF.apply(loadTimeData, arguments); |
180 } | 175 } |
181 | 176 |
182 /** | 177 /** |
183 * @param {number} code File error code (from FileError object). | 178 * @param {number} code File error code (from FileError object). |
184 * @return {string} Translated file error string. | 179 * @return {string} Translated file error string. |
185 */ | 180 */ |
186 function getFileErrorString(code) { | 181 function getFileErrorString(code) { |
187 for (var key in FileError) { | 182 for (var key in FileError) { |
188 var match = /(.*)_ERR$/.exec(key); | 183 var match = /(.*)_ERR$/.exec(key); |
189 if (match && FileError[key] == code) { | 184 if (match && FileError[key] == code) { |
190 // This would convert 1 to 'NOT_FOUND'. | 185 // This would convert 1 to 'NOT_FOUND'. |
191 code = match[1]; | 186 code = match[1]; |
192 break; | 187 break; |
193 } | 188 } |
194 } | 189 } |
195 return localStrings.getString('FILE_ERROR_' + code) || | 190 return loadTimeData.getString('FILE_ERROR_' + code) || |
196 localStrings.getStringF('FILE_ERROR_GENERIC', code); | 191 loadTimeData.getStringF('FILE_ERROR_GENERIC', code); |
197 } | 192 } |
198 | 193 |
199 /** | 194 /** |
200 * Checks if |parent_path| is parent file path of |child_path|. | 195 * Checks if |parent_path| is parent file path of |child_path|. |
201 * | 196 * |
202 * @param {string} parent_path The parent path. | 197 * @param {string} parent_path The parent path. |
203 * @param {string} child_path The child path. | 198 * @param {string} child_path The child path. |
204 */ | 199 */ |
205 function isParentPath(parent_path, child_path) { | 200 function isParentPath(parent_path, child_path) { |
206 if (!parent_path || parent_path.length == 0 || | 201 if (!parent_path || parent_path.length == 0 || |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 FileManager.ListType = { | 262 FileManager.ListType = { |
268 DETAIL: 'detail', | 263 DETAIL: 'detail', |
269 THUMBNAIL: 'thumb' | 264 THUMBNAIL: 'thumb' |
270 }; | 265 }; |
271 | 266 |
272 /** | 267 /** |
273 * Load translated strings. | 268 * Load translated strings. |
274 */ | 269 */ |
275 FileManager.initStrings = function(callback) { | 270 FileManager.initStrings = function(callback) { |
276 chrome.fileBrowserPrivate.getStrings(function(strings) { | 271 chrome.fileBrowserPrivate.getStrings(function(strings) { |
277 localStrings = new LocalStrings(strings); | 272 loadTimeData.data = strings; |
278 if (callback) | 273 if (callback) |
279 callback(); | 274 callback(); |
280 }); | 275 }); |
281 }; | 276 }; |
282 | 277 |
283 // Instance methods. | 278 // Instance methods. |
284 | 279 |
285 /** | 280 /** |
286 * Request local file system, resolve roots and init_ after that. | 281 * Request local file system, resolve roots and init_ after that. |
287 * @private | 282 * @private |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 this.hostedButton.addEventListener('click', this.onGDataPrefClick_.bind( | 599 this.hostedButton.addEventListener('click', this.onGDataPrefClick_.bind( |
605 this, 'hostedFilesDisabled', true /* inverted */)); | 600 this, 'hostedFilesDisabled', true /* inverted */)); |
606 | 601 |
607 cr.ui.ComboButton.decorate(this.taskItems_); | 602 cr.ui.ComboButton.decorate(this.taskItems_); |
608 this.taskItems_.addEventListener('select', | 603 this.taskItems_.addEventListener('select', |
609 this.onTaskItemClicked_.bind(this)); | 604 this.onTaskItemClicked_.bind(this)); |
610 | 605 |
611 this.dialogDom_.ownerDocument.defaultView.addEventListener( | 606 this.dialogDom_.ownerDocument.defaultView.addEventListener( |
612 'resize', this.onResize_.bind(this)); | 607 'resize', this.onResize_.bind(this)); |
613 | 608 |
614 if (str('ASH') == '1') | 609 if (loadTimeData.getBoolean('ASH')) |
615 this.dialogDom_.setAttribute('ash', 'true'); | 610 this.dialogDom_.setAttribute('ash', 'true'); |
616 | 611 |
617 this.filePopup_ = null; | 612 this.filePopup_ = null; |
618 | 613 |
619 this.dialogDom_.querySelector('#search-box').addEventListener( | 614 this.dialogDom_.querySelector('#search-box').addEventListener( |
620 'input', this.onSearchBoxUpdate_.bind(this)); | 615 'input', this.onSearchBoxUpdate_.bind(this)); |
621 | 616 |
622 // Populate the static localized strings. | 617 // Populate the static localized strings. |
623 i18nTemplate.process(this.document_, localStrings.templateData); | 618 i18nTemplate.process(this.document_, loadTimeData); |
624 }; | 619 }; |
625 | 620 |
626 /** | 621 /** |
627 * Constructs table and grid (heavy operation). | 622 * Constructs table and grid (heavy operation). |
628 **/ | 623 **/ |
629 FileManager.prototype.initFileList_ = function() { | 624 FileManager.prototype.initFileList_ = function() { |
630 // Always sharing the data model between the detail/thumb views confuses | 625 // Always sharing the data model between the detail/thumb views confuses |
631 // them. Instead we maintain this bogus data model, and hook it up to the | 626 // them. Instead we maintain this bogus data model, and hook it up to the |
632 // view that is not in use. | 627 // view that is not in use. |
633 this.emptyDataModel_ = new cr.ui.ArrayDataModel([]); | 628 this.emptyDataModel_ = new cr.ui.ArrayDataModel([]); |
(...skipping 1829 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2463 chrome.extension.getURL('images/filetype_generic.png'); | 2458 chrome.extension.getURL('images/filetype_generic.png'); |
2464 } else { | 2459 } else { |
2465 // Use specific icon. | 2460 // Use specific icon. |
2466 var icon = FileType.getIcon(selection.urls[0]); | 2461 var icon = FileType.getIcon(selection.urls[0]); |
2467 task.iconUrl = | 2462 task.iconUrl = |
2468 chrome.extension.getURL('images/filetype_' + icon + '.png'); | 2463 chrome.extension.getURL('images/filetype_' + icon + '.png'); |
2469 } | 2464 } |
2470 task.title = str('ACTION_OPEN'); | 2465 task.title = str('ACTION_OPEN'); |
2471 } else if (task_parts[1] == 'view-pdf') { | 2466 } else if (task_parts[1] == 'view-pdf') { |
2472 // Do not render this task if disabled. | 2467 // Do not render this task if disabled. |
2473 if (str('PDF_VIEW_ENABLED') == 'false') continue; | 2468 if (!loadTimeData.getBoolean('PDF_VIEW_ENABLED')) |
| 2469 continue; |
| 2470 |
2474 task.iconUrl = | 2471 task.iconUrl = |
2475 chrome.extension.getURL('images/filetype_pdf.png'); | 2472 chrome.extension.getURL('images/filetype_pdf.png'); |
2476 task.title = str('ACTION_VIEW'); | 2473 task.title = str('ACTION_VIEW'); |
2477 } else if (task_parts[1] == 'view-in-browser') { | 2474 } else if (task_parts[1] == 'view-in-browser') { |
2478 task.iconUrl = | 2475 task.iconUrl = |
2479 chrome.extension.getURL('images/filetype_generic.png'); | 2476 chrome.extension.getURL('images/filetype_generic.png'); |
2480 task.title = str('ACTION_VIEW'); | 2477 task.title = str('ACTION_VIEW'); |
2481 } else if (task_parts[1] == 'install-crx') { | 2478 } else if (task_parts[1] == 'install-crx') { |
2482 task.iconUrl = | 2479 task.iconUrl = |
2483 chrome.extension.getURL('images/filetype_generic.png'); | 2480 chrome.extension.getURL('images/filetype_generic.png'); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2637 } | 2634 } |
2638 callback(urls); | 2635 callback(urls); |
2639 }.bind(this)); | 2636 }.bind(this)); |
2640 } else { | 2637 } else { |
2641 callback(urls); | 2638 callback(urls); |
2642 } | 2639 } |
2643 }; | 2640 }; |
2644 | 2641 |
2645 FileManager.prototype.getGDataPreferences_ = function() { | 2642 FileManager.prototype.getGDataPreferences_ = function() { |
2646 return this.gdataPreferences_ || | 2643 return this.gdataPreferences_ || |
2647 { driveEnabled: str('ENABLE_GDATA') == '1' }; | 2644 { driveEnabled: loadTimeData.getBoolean('ENABLE_GDATA') }; |
2648 }; | 2645 }; |
2649 | 2646 |
2650 FileManager.prototype.getNetworkConnectionState_ = function() { | 2647 FileManager.prototype.getNetworkConnectionState_ = function() { |
2651 return this.networkConnectionState_ || {}; | 2648 return this.networkConnectionState_ || {}; |
2652 }; | 2649 }; |
2653 | 2650 |
2654 FileManager.prototype.onNetworkConnectionChanged_ = function(state) { | 2651 FileManager.prototype.onNetworkConnectionChanged_ = function(state) { |
2655 console.log(state.online ? 'online' : 'offline', state.type); | 2652 console.log(state.online ? 'online' : 'offline', state.type); |
2656 this.networkConnectionState_ = state; | 2653 this.networkConnectionState_ = state; |
2657 this.directoryModel_.setOffline(!state.online); | 2654 this.directoryModel_.setOffline(!state.online); |
(...skipping 2000 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4658 | 4655 |
4659 function closeBanner() { | 4656 function closeBanner() { |
4660 self.cleanupGDataWelcome_(); | 4657 self.cleanupGDataWelcome_(); |
4661 // Stop showing the welcome banner. | 4658 // Stop showing the welcome banner. |
4662 localStorage[WELCOME_HEADER_COUNTER_KEY] = WELCOME_HEADER_COUNTER_LIMIT; | 4659 localStorage[WELCOME_HEADER_COUNTER_KEY] = WELCOME_HEADER_COUNTER_LIMIT; |
4663 } | 4660 } |
4664 | 4661 |
4665 return maybeShowBanner; | 4662 return maybeShowBanner; |
4666 }; | 4663 }; |
4667 })(); | 4664 })(); |
OLD | NEW |