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 'use strict'; | 5 'use strict'; |
6 | 6 |
7 /** | 7 /** |
8 * Media manager class. | 8 * Media manager class. |
9 * This class supports the information for the media file. | 9 * This class supports the information for the media file. |
10 * @param {FileEntry} entry Entry of media file. This must be a external entry. | 10 * @param {FileEntry} entry Entry of media file. This must be a external entry. |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 }.bind(this)); | 95 }.bind(this)); |
96 }; | 96 }; |
97 | 97 |
98 /** | 98 /** |
99 * Retrieves the mime of file. | 99 * Retrieves the mime of file. |
100 * | 100 * |
101 * @return {Promise} Promise which is resolved with the mime. Reject if failed. | 101 * @return {Promise} Promise which is resolved with the mime. Reject if failed. |
102 */ | 102 */ |
103 MediaManager.prototype.getMime = function() { | 103 MediaManager.prototype.getMime = function() { |
104 if (this.cachedDriveProp_) | 104 if (this.cachedDriveProp_) |
105 return Promise.resolve(this.cachedDriveProp_.thumbnailUrl); | 105 return Promise.resolve(this.cachedDriveProp_.contentMimeType || ''); |
106 | 106 |
107 return new Promise(function(fulfill, reject) { | 107 return new Promise(function(fulfill, reject) { |
108 chrome.fileBrowserPrivate.getEntryProperties( | 108 chrome.fileBrowserPrivate.getEntryProperties( |
109 [this.entry_.toURL()], fulfill); | 109 [this.entry_.toURL()], fulfill); |
110 }.bind(this)).then(function(props) { | 110 }.bind(this)).then(function(props) { |
111 if (!props || !props[0] || !props[0].contentMimeType) { | 111 if (!props || !props[0]) { |
| 112 return Promise.reject('Mime fetch failed.'); |
| 113 } else if (!props[0].contentMimeType) { |
112 // TODO(yoshiki): Adds a logic to guess the mime. | 114 // TODO(yoshiki): Adds a logic to guess the mime. |
113 return Promise.reject('Mime fetch failed.'); | 115 this.cachedDriveProp_ = props[0]; |
| 116 return ''; |
114 } else { | 117 } else { |
115 this.cachedDriveProp_ = props[0]; | 118 this.cachedDriveProp_ = props[0]; |
116 return props[0].contentMimeType; | 119 return props[0].contentMimeType; |
117 } | 120 } |
118 }.bind(this)); | 121 }.bind(this)); |
119 }; | 122 }; |
120 | 123 |
121 /** | 124 /** |
122 * Retrieves the thumbnail url of file. | 125 * Retrieves the thumbnail url of file. |
123 * | 126 * |
124 * @return {Promise} Promise which is resolved with the url. Reject if failed. | 127 * @return {Promise} Promise which is resolved with the url. Reject if failed. |
125 */ | 128 */ |
126 MediaManager.prototype.getThumbnail = function() { | 129 MediaManager.prototype.getThumbnail = function() { |
127 if (this.cachedDriveProp_) | 130 if (this.cachedDriveProp_) |
128 return Promise.resolve(this.cachedDriveProp_.thumbnailUrl); | 131 return Promise.resolve(this.cachedDriveProp_.thumbnailUrl || ''); |
129 | 132 |
130 return new Promise(function(fulfill, reject) { | 133 return new Promise(function(fulfill, reject) { |
131 chrome.fileBrowserPrivate.getEntryProperties( | 134 chrome.fileBrowserPrivate.getEntryProperties( |
132 [this.entry_.toURL()], fulfill); | 135 [this.entry_.toURL()], fulfill); |
133 }.bind(this)).then(function(props) { | 136 }.bind(this)).then(function(props) { |
134 if (!props || !props[0] || !props[0].thumbnailUrl) { | 137 if (!props || !props[0]) { |
135 // TODO(yoshiki): Adds a logic to guess the mime. | |
136 return Promise.reject('Thumbnail fetch failed.'); | 138 return Promise.reject('Thumbnail fetch failed.'); |
137 } else { | 139 } else { |
138 this.cachedDriveProp_ = props[0]; | 140 this.cachedDriveProp_ = props[0]; |
139 return props[0].thumbnailUrl; | 141 return props[0].thumbnailUrl || ''; |
140 } | 142 } |
141 }.bind(this)); | 143 }.bind(this)); |
142 }; | 144 }; |
OLD | NEW |