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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 var IMAGE_HOVER_PREVIEW_SIZE = 200; | 106 var IMAGE_HOVER_PREVIEW_SIZE = 200; |
107 | 107 |
108 /** | 108 /** |
109 * The minimum about of time to display the butter bar for, in ms. | 109 * The minimum about of time to display the butter bar for, in ms. |
110 * Justification is 1000ms for minimum display time plus 300ms for transition | 110 * Justification is 1000ms for minimum display time plus 300ms for transition |
111 * duration. | 111 * duration. |
112 */ | 112 */ |
113 var MINIMUM_BUTTER_DISPLAY_TIME_MS = 1300; | 113 var MINIMUM_BUTTER_DISPLAY_TIME_MS = 1300; |
114 | 114 |
115 /** | 115 /** |
116 * Translated strings. | |
117 */ | |
118 var localStrings; | |
119 | |
120 /** | |
121 * Item for the Grid View. | 116 * Item for the Grid View. |
122 * @constructor | 117 * @constructor |
123 */ | 118 */ |
124 function GridItem(fileManager, entry) { | 119 function GridItem(fileManager, entry) { |
125 var li = fileManager.document_.createElement('li'); | 120 var li = fileManager.document_.createElement('li'); |
126 GridItem.decorate(li, fileManager, entry); | 121 GridItem.decorate(li, fileManager, entry); |
127 return li; | 122 return li; |
128 } | 123 } |
129 | 124 |
130 GridItem.prototype = { | 125 GridItem.prototype = { |
(...skipping 10 matching lines...) Expand all Loading... |
141 | 136 |
142 GridItem.decorate = function(li, fileManager, entry) { | 137 GridItem.decorate = function(li, fileManager, entry) { |
143 li.__proto__ = GridItem.prototype; | 138 li.__proto__ = GridItem.prototype; |
144 fileManager.decorateThumbnail_(li, entry); | 139 fileManager.decorateThumbnail_(li, entry); |
145 }; | 140 }; |
146 | 141 |
147 /** | 142 /** |
148 * Return a translated string. | 143 * Return a translated string. |
149 * | 144 * |
150 * Wrapper function to make dealing with translated strings more concise. | 145 * Wrapper function to make dealing with translated strings more concise. |
151 * Equivilant to localStrings.getString(id). | 146 * Equivalent to loadTimeData.getString(id). |
152 * | 147 * |
153 * @param {string} id The id of the string to return. | 148 * @param {string} id The id of the string to return. |
154 * @return {string} The translated string. | 149 * @return {string} The translated string. |
155 */ | 150 */ |
156 function str(id) { | 151 function str(id) { |
157 return localStrings.getString(id) || ('UNLOCALIZED STRING ' + id); | 152 return loadTimeData.getString(id); |
158 } | 153 } |
159 | 154 |
160 /** | 155 /** |
161 * Return a translated string with arguments replaced. | 156 * Return a translated string with arguments replaced. |
162 * | 157 * |
163 * Wrapper function to make dealing with translated strings more concise. | 158 * Wrapper function to make dealing with translated strings more concise. |
164 * Equivilant to localStrings.getStringF(id, ...). | 159 * Equivilant to loadTimeData.getStringF(id, ...). |
165 * | 160 * |
166 * @param {string} id The id of the string to return. | 161 * @param {string} id The id of the string to return. |
167 * @param {...string} The values to replace into the string. | 162 * @param {...string} The values to replace into the string. |
168 * @return {string} The translated string with replaced values. | 163 * @return {string} The translated string with replaced values. |
169 */ | 164 */ |
170 function strf(id, var_args) { | 165 function strf(id, var_args) { |
171 return localStrings.getStringF.apply(localStrings, arguments); | 166 return loadTimeData.getStringF.apply(loadTimeData, arguments); |
172 } | 167 } |
173 | 168 |
174 /** | 169 /** |
175 * @param {number} code File error code (from FileError object). | 170 * @param {number} code File error code (from FileError object). |
176 * @return {string} Translated file error string. | 171 * @return {string} Translated file error string. |
177 */ | 172 */ |
178 function getFileErrorString(code) { | 173 function getFileErrorString(code) { |
179 for (var key in FileError) { | 174 for (var key in FileError) { |
180 var match = /(.*)_ERR$/.exec(key); | 175 var match = /(.*)_ERR$/.exec(key); |
181 if (match && FileError[key] == code) { | 176 if (match && FileError[key] == code) { |
182 // This would convert 1 to 'NOT_FOUND'. | 177 // This would convert 1 to 'NOT_FOUND'. |
183 code = match[1]; | 178 code = match[1]; |
184 break; | 179 break; |
185 } | 180 } |
186 } | 181 } |
187 return localStrings.getString('FILE_ERROR_' + code) || | 182 return loadTimeData.getString('FILE_ERROR_' + code) || |
188 localStrings.getStringF('FILE_ERROR_GENERIC', code); | 183 loadTimeData.getStringF('FILE_ERROR_GENERIC', code); |
189 } | 184 } |
190 | 185 |
191 /** | 186 /** |
192 * Checks if |parent_path| is parent file path of |child_path|. | 187 * Checks if |parent_path| is parent file path of |child_path|. |
193 * | 188 * |
194 * @param {string} parent_path The parent path. | 189 * @param {string} parent_path The parent path. |
195 * @param {string} child_path The child path. | 190 * @param {string} child_path The child path. |
196 */ | 191 */ |
197 function isParentPath(parent_path, child_path) { | 192 function isParentPath(parent_path, child_path) { |
198 if (!parent_path || parent_path.length == 0 || | 193 if (!parent_path || parent_path.length == 0 || |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 FileManager.ListType = { | 247 FileManager.ListType = { |
253 DETAIL: 'detail', | 248 DETAIL: 'detail', |
254 THUMBNAIL: 'thumb' | 249 THUMBNAIL: 'thumb' |
255 }; | 250 }; |
256 | 251 |
257 /** | 252 /** |
258 * Load translated strings. | 253 * Load translated strings. |
259 */ | 254 */ |
260 FileManager.initStrings = function(callback) { | 255 FileManager.initStrings = function(callback) { |
261 chrome.fileBrowserPrivate.getStrings(function(strings) { | 256 chrome.fileBrowserPrivate.getStrings(function(strings) { |
262 localStrings = new LocalStrings(strings); | 257 loadTimeData.data = strings; |
263 if (callback) | 258 if (callback) |
264 callback(); | 259 callback(); |
265 }); | 260 }); |
266 }; | 261 }; |
267 | 262 |
268 // Instance methods. | 263 // Instance methods. |
269 | 264 |
270 /** | 265 /** |
271 * Request local file system, resolve roots and init_ after that. | 266 * Request local file system, resolve roots and init_ after that. |
272 * @private | 267 * @private |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 this.hostedButton.addEventListener('click', this.onGDataPrefClick_.bind( | 584 this.hostedButton.addEventListener('click', this.onGDataPrefClick_.bind( |
590 this, 'hostedFilesDisabled', true /* inverted */)); | 585 this, 'hostedFilesDisabled', true /* inverted */)); |
591 | 586 |
592 cr.ui.ComboButton.decorate(this.taskItems_); | 587 cr.ui.ComboButton.decorate(this.taskItems_); |
593 this.taskItems_.addEventListener('select', | 588 this.taskItems_.addEventListener('select', |
594 this.onTaskItemClicked_.bind(this)); | 589 this.onTaskItemClicked_.bind(this)); |
595 | 590 |
596 this.dialogDom_.ownerDocument.defaultView.addEventListener( | 591 this.dialogDom_.ownerDocument.defaultView.addEventListener( |
597 'resize', this.onResize_.bind(this)); | 592 'resize', this.onResize_.bind(this)); |
598 | 593 |
599 if (str('ASH') == '1') | 594 if (loadTimeData.getBoolean('ASH')) |
600 this.dialogDom_.setAttribute('ash', 'true'); | 595 this.dialogDom_.setAttribute('ash', 'true'); |
601 | 596 |
602 this.filePopup_ = null; | 597 this.filePopup_ = null; |
603 | 598 |
604 this.dialogDom_.querySelector('#search-box').addEventListener( | 599 this.dialogDom_.querySelector('#search-box').addEventListener( |
605 'input', this.onSearchBoxUpdate_.bind(this)); | 600 'input', this.onSearchBoxUpdate_.bind(this)); |
606 | 601 |
607 // Populate the static localized strings. | 602 // Populate the static localized strings. |
608 i18nTemplate.process(this.document_, localStrings.templateData); | 603 i18nTemplate.process(this.document_, loadTimeData); |
609 }; | 604 }; |
610 | 605 |
611 /** | 606 /** |
612 * Constructs table and grid (heavy operation). | 607 * Constructs table and grid (heavy operation). |
613 **/ | 608 **/ |
614 FileManager.prototype.initFileList_ = function() { | 609 FileManager.prototype.initFileList_ = function() { |
615 // Always sharing the data model between the detail/thumb views confuses | 610 // Always sharing the data model between the detail/thumb views confuses |
616 // them. Instead we maintain this bogus data model, and hook it up to the | 611 // them. Instead we maintain this bogus data model, and hook it up to the |
617 // view that is not in use. | 612 // view that is not in use. |
618 this.emptyDataModel_ = new cr.ui.ArrayDataModel([]); | 613 this.emptyDataModel_ = new cr.ui.ArrayDataModel([]); |
(...skipping 1810 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2429 chrome.extension.getURL('images/filetype_generic.png'); | 2424 chrome.extension.getURL('images/filetype_generic.png'); |
2430 } else { | 2425 } else { |
2431 // Use specific icon. | 2426 // Use specific icon. |
2432 var icon = FileType.getIcon(selection.urls[0]); | 2427 var icon = FileType.getIcon(selection.urls[0]); |
2433 task.iconUrl = | 2428 task.iconUrl = |
2434 chrome.extension.getURL('images/filetype_' + icon + '.png'); | 2429 chrome.extension.getURL('images/filetype_' + icon + '.png'); |
2435 } | 2430 } |
2436 task.title = str('ACTION_OPEN'); | 2431 task.title = str('ACTION_OPEN'); |
2437 } else if (task_parts[1] == 'view-pdf') { | 2432 } else if (task_parts[1] == 'view-pdf') { |
2438 // Do not render this task if disabled. | 2433 // Do not render this task if disabled. |
2439 if (str('PDF_VIEW_ENABLED') == 'false') continue; | 2434 if (!loadTimeData.getBoolean('PDF_VIEW_ENABLED')) |
| 2435 continue; |
| 2436 |
2440 task.iconUrl = | 2437 task.iconUrl = |
2441 chrome.extension.getURL('images/filetype_pdf.png'); | 2438 chrome.extension.getURL('images/filetype_pdf.png'); |
2442 task.title = str('ACTION_VIEW'); | 2439 task.title = str('ACTION_VIEW'); |
2443 } else if (task_parts[1] == 'view-in-browser') { | 2440 } else if (task_parts[1] == 'view-in-browser') { |
2444 task.iconUrl = | 2441 task.iconUrl = |
2445 chrome.extension.getURL('images/filetype_generic.png'); | 2442 chrome.extension.getURL('images/filetype_generic.png'); |
2446 task.title = str('ACTION_VIEW'); | 2443 task.title = str('ACTION_VIEW'); |
2447 } else if (task_parts[1] == 'install-crx') { | 2444 } else if (task_parts[1] == 'install-crx') { |
2448 task.iconUrl = | 2445 task.iconUrl = |
2449 chrome.extension.getURL('images/filetype_generic.png'); | 2446 chrome.extension.getURL('images/filetype_generic.png'); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2603 } | 2600 } |
2604 callback(urls); | 2601 callback(urls); |
2605 }.bind(this)); | 2602 }.bind(this)); |
2606 } else { | 2603 } else { |
2607 callback(urls); | 2604 callback(urls); |
2608 } | 2605 } |
2609 }; | 2606 }; |
2610 | 2607 |
2611 FileManager.prototype.getGDataPreferences_ = function() { | 2608 FileManager.prototype.getGDataPreferences_ = function() { |
2612 return this.gdataPreferences_ || | 2609 return this.gdataPreferences_ || |
2613 { driveEnabled: str('ENABLE_GDATA') == '1' }; | 2610 { driveEnabled: loadTimeData.getBoolean('ENABLE_GDATA') }; |
2614 }; | 2611 }; |
2615 | 2612 |
2616 FileManager.prototype.getNetworkConnectionState_ = function() { | 2613 FileManager.prototype.getNetworkConnectionState_ = function() { |
2617 return this.networkConnectionState_ || {}; | 2614 return this.networkConnectionState_ || {}; |
2618 }; | 2615 }; |
2619 | 2616 |
2620 FileManager.prototype.onNetworkConnectionChanged_ = function(state) { | 2617 FileManager.prototype.onNetworkConnectionChanged_ = function(state) { |
2621 console.log(state.online ? 'online' : 'offline', state.type); | 2618 console.log(state.online ? 'online' : 'offline', state.type); |
2622 this.networkConnectionState_ = state; | 2619 this.networkConnectionState_ = state; |
2623 this.directoryModel_.setOffline(!state.online); | 2620 this.directoryModel_.setOffline(!state.online); |
(...skipping 1911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4535 | 4532 |
4536 function closeBanner() { | 4533 function closeBanner() { |
4537 self.cleanupGDataWelcome_(); | 4534 self.cleanupGDataWelcome_(); |
4538 // Stop showing the welcome banner. | 4535 // Stop showing the welcome banner. |
4539 localStorage[WELCOME_HEADER_COUNTER_KEY] = WELCOME_HEADER_COUNTER_LIMIT; | 4536 localStorage[WELCOME_HEADER_COUNTER_KEY] = WELCOME_HEADER_COUNTER_LIMIT; |
4540 } | 4537 } |
4541 | 4538 |
4542 return maybeShowBanner; | 4539 return maybeShowBanner; |
4543 }; | 4540 }; |
4544 })(); | 4541 })(); |
OLD | NEW |