OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 * @param {DialogType} dialogType | 6 * @param {DialogType} dialogType |
7 * @param {!FileManagerUI} ui | 7 * @param {!FileManagerUI} ui |
8 * @param {!MetadataCache} metadataCache | 8 * @param {!MetadataCache} metadataCache |
9 * @param {!FileSelectionHandler} selectionHandler | 9 * @param {!FileSelectionHandler} selectionHandler |
10 * @param {!MetadataUpdateController} metadataUpdateController | 10 * @param {!MetadataUpdateController} metadataUpdateController |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
205 * Opens the suggest file dialog. | 205 * Opens the suggest file dialog. |
206 * | 206 * |
207 * @param {Entry} entry Entry of the file. | 207 * @param {Entry} entry Entry of the file. |
208 * @param {function()} onSuccess Success callback. | 208 * @param {function()} onSuccess Success callback. |
209 * @param {function()} onCancelled User-cancelled callback. | 209 * @param {function()} onCancelled User-cancelled callback. |
210 * @param {function()} onFailure Failure callback. | 210 * @param {function()} onFailure Failure callback. |
211 * @private | 211 * @private |
212 */ | 212 */ |
213 TaskController.prototype.openSuggestAppsDialog = | 213 TaskController.prototype.openSuggestAppsDialog = |
214 function(entry, onSuccess, onCancelled, onFailure) { | 214 function(entry, onSuccess, onCancelled, onFailure) { |
215 if (!url) { | 215 if (!entry) { |
216 onFailure(); | 216 onFailure(); |
217 return; | 217 return; |
218 } | 218 } |
219 | 219 |
220 this.metadataCache_.getOne(entry, 'external', function(prop) { | 220 this.getMimeType_(entry).then(function(mimeType) { |
221 if (!prop || !prop.contentMimeType) { | 221 var basename = entry.name; |
222 var splitted = util.splitExtension(basename); | |
223 var extension = splitted[1]; | |
224 | |
225 // Returns with failure if the file has neither extension nor MIME type. | |
226 if (!extension || !mimeType) { | |
222 onFailure(); | 227 onFailure(); |
223 return; | 228 return; |
224 } | 229 } |
225 | |
226 var basename = entry.name; | |
227 var splitted = util.splitExtension(basename); | |
228 var filename = splitted[0]; | |
229 var extension = splitted[1]; | |
230 var mime = prop.contentMimeType; | |
231 | |
232 // Returns with failure if the file has neither extension nor mime. | |
233 if (!extension || !mime) { | |
234 onFailure(); | |
235 return; | |
236 } | |
237 | 230 |
238 var onDialogClosed = function(result) { | 231 var onDialogClosed = function(result) { |
239 switch (result) { | 232 switch (result) { |
240 case SuggestAppsDialog.Result.INSTALL_SUCCESSFUL: | 233 case SuggestAppsDialog.Result.INSTALL_SUCCESSFUL: |
241 onSuccess(); | 234 onSuccess(); |
242 break; | 235 break; |
243 case SuggestAppsDialog.Result.FAILED: | 236 case SuggestAppsDialog.Result.FAILED: |
244 onFailure(); | 237 onFailure(); |
245 break; | 238 break; |
246 default: | 239 default: |
247 onCancelled(); | 240 onCancelled(); |
248 } | 241 } |
249 }; | 242 }; |
250 | 243 |
251 if (FileTasks.EXECUTABLE_EXTENSIONS.indexOf(extension) !== -1) { | 244 this.ui_.suggestAppsDialog.showByExtensionAndMime( |
fukino
2015/01/20 04:45:03
showByFilename() is not in use now? If so, please
yawano
2015/01/20 08:48:24
showByFilename is removed with the patch set 1. Re
| |
252 this.ui_.suggestAppsDialog.showByFilename(filename, onDialogClosed); | 245 extension, mimeType, onDialogClosed); |
253 } else { | |
254 this.ui_.suggestAppsDialog.showByExtensionAndMime( | |
255 extension, mime, onDialogClosed); | |
256 } | |
257 }.bind(this)); | 246 }.bind(this)); |
258 }; | 247 }; |
259 | 248 |
260 /** | 249 /** |
250 * Get MIME type for an entry. This method first tries to obtain the MIME type | |
251 * from metadata. If it fails, this falls back to obtain the MIME type from its | |
252 * content or name. | |
253 * | |
254 * @param {Entry} entry An entry to obtain its mime type. | |
255 * @return {!Promise} | |
256 * @private | |
257 */ | |
258 TaskController.prototype.getMimeType_ = function(entry) { | |
259 return new Promise(function(resolve, reject) { | |
260 this.metadataCache_.getOne(entry, 'external', function(prop) { | |
261 if (prop && prop.contentMimeType) | |
262 resolve(prop.contentMimeType); | |
263 else | |
264 chrome.fileManagerPrivate.getMimeType(entry.toURL(), resolve); | |
265 }); | |
266 }.bind(this)); | |
267 } | |
268 | |
269 /** | |
261 * Handles change of selection and clears context menu. | 270 * Handles change of selection and clears context menu. |
262 * @private | 271 * @private |
263 */ | 272 */ |
264 TaskController.prototype.onSelectionChanged_ = function() { | 273 TaskController.prototype.onSelectionChanged_ = function() { |
265 var selection = this.selectionHandler_.selection; | 274 var selection = this.selectionHandler_.selection; |
266 // Caller of update context menu action items. | 275 // Caller of update context menu action items. |
267 // FileSelectionHandler.EventType.CHANGE | 276 // FileSelectionHandler.EventType.CHANGE |
268 if (this.dialogType_ === DialogType.FULL_PAGE && | 277 if (this.dialogType_ === DialogType.FULL_PAGE && |
269 selection.directoryCount === 0 && selection.fileCount > 0) { | 278 selection.directoryCount === 0 && selection.fileCount > 0) { |
270 // Show disabled items for position calculation of the menu. They will be | 279 // Show disabled items for position calculation of the menu. They will be |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
351 tasks.executeDefault(); | 360 tasks.executeDefault(); |
352 }.bind(this)); | 361 }.bind(this)); |
353 } else { | 362 } else { |
354 var selection = this.selectionHandler_.selection; | 363 var selection = this.selectionHandler_.selection; |
355 if (selection.entries.length === 1 && | 364 if (selection.entries.length === 1 && |
356 util.isSameEntry(selection.entries[0], entry)) { | 365 util.isSameEntry(selection.entries[0], entry)) { |
357 this.ui_.dialogFooter.okButton.click(); | 366 this.ui_.dialogFooter.okButton.click(); |
358 } | 367 } |
359 } | 368 } |
360 }; | 369 }; |
OLD | NEW |