Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: ui/file_manager/file_manager/foreground/js/quick_view_controller.js

Issue 2181953003: Improved security of Quick View by rendering videos and audios inside webview. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nit Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 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 * Controller for QuickView. 6 * Controller for QuickView.
7 * 7 *
8 * @param {!FilesQuickView} quickView 8 * @param {!FilesQuickView} quickView
9 * @param {!MetadataModel} metadataModel File system metadata. 9 * @param {!MetadataModel} metadataModel File system metadata.
10 * @param {!FileSelectionHandler} selectionHandler 10 * @param {!FileSelectionHandler} selectionHandler
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 QuickViewController.prototype.getQuickViewParameters_ = function(entry, items) { 226 QuickViewController.prototype.getQuickViewParameters_ = function(entry, items) {
227 var item = items[0]; 227 var item = items[0];
228 var type = FileType.getType(entry).type; 228 var type = FileType.getType(entry).type;
229 229
230 /** @type {!QuickViewParams} */ 230 /** @type {!QuickViewParams} */
231 var params = { 231 var params = {
232 type: type, 232 type: type,
233 filePath: entry.name, 233 filePath: entry.name,
234 }; 234 };
235 235
236 /**
237 * @type function(!FileEntry): !Promise<!File>
238 */
239 var getFile = function(entry) {
240 return new Promise(function(resolve, reject) {
241 entry.file(resolve, reject);
242 });
243 };
244
236 if (type === 'image') { 245 if (type === 'image') {
237 if (item.externalFileUrl) { 246 if (item.externalFileUrl) {
238 if (item.thumbnailUrl) { 247 if (item.thumbnailUrl) {
239 return this.loadThumbnailFromDrive_(item.thumbnailUrl) 248 return this.loadThumbnailFromDrive_(item.thumbnailUrl)
240 .then(function(result) { 249 .then(function(result) {
241 if (result.status === 'success') 250 if (result.status === 'success')
242 params.contentUrl = result.data; 251 params.contentUrl = result.data;
243 return params; 252 return params;
244 }.bind(this)); 253 }.bind(this));
245 } 254 }
246 } else { 255 } else {
247 return new Promise(function(resolve, reject) { 256 return getFile(entry).then(function(file) {
248 entry.file(function(file) { 257 params.contentUrl = URL.createObjectURL(file);
249 params.contentUrl = URL.createObjectURL(file); 258 return params;
250 resolve(params);
251 });
252 }); 259 });
253 } 260 }
254 } else if (type === 'video') { 261 } else if (type === 'video') {
255 if (item.externalFileUrl) { 262 if (item.externalFileUrl) {
256 if (item.thumbnailUrl) { 263 if (item.thumbnailUrl) {
257 return this.loadThumbnailFromDrive_(item.thumbnailUrl) 264 return this.loadThumbnailFromDrive_(item.thumbnailUrl)
258 .then(function(result) { 265 .then(function(result) {
259 if (result.status === 'success') { 266 if (result.status === 'success') {
260 params.videoPoster = result.data; 267 params.videoPoster = result.data;
261 } 268 }
262 return params; 269 return params;
263 }); 270 });
264 } 271 }
265 } else { 272 } else {
266 params.contentUrl = entry.toURL();
267 params.autoplay = true; 273 params.autoplay = true;
268 if (item.thumbnailUrl) { 274 if (item.thumbnailUrl) {
269 params.videoPoster = item.thumbnailUrl; 275 params.videoPoster = item.thumbnailUrl;
270 } 276 }
277 return getFile(entry).then(function(file) {
278 params.contentUrl = URL.createObjectURL(file);
279 return params;
280 });
271 } 281 }
272 } else if (type === 'audio') { 282 } else if (type === 'audio') {
273 if (item.externalFileUrl) { 283 if (item.externalFileUrl) {
274 // If the file is in Drive, we ask user to open it with external app. 284 // If the file is in Drive, we ask user to open it with external app.
275 } else { 285 } else {
276 params.contentUrl = entry.toURL();
277 params.autoplay = true; 286 params.autoplay = true;
278 return this.metadataModel_.get([entry], ['contentThumbnailUrl']) 287 return Promise
279 .then(function(entry, items) { 288 .all([
289 this.metadataModel_.get([entry], ['contentThumbnailUrl']),
290 getFile(entry)
291 ])
292 .then(function(values) {
293 /** @type {!Array<!MetadataItem>} */
294 var items = values[0];
295 /** @type {!File} */
296 var file = values[1];
280 var item = items[0]; 297 var item = items[0];
281 if (item.contentThumbnailUrl) { 298 if (item.contentThumbnailUrl) {
282 params.audioArtwork = item.contentThumbnailUrl; 299 params.audioArtwork = item.contentThumbnailUrl;
283 } 300 }
301 params.contentUrl = URL.createObjectURL(file);
284 return params; 302 return params;
285 }.bind(this, entry)); 303 });
286 } 304 }
287 } 305 }
288 return Promise.resolve(params); 306 return Promise.resolve(params);
289 }; 307 };
290 308
291 /** 309 /**
292 * Loads a thumbnail from Drive. 310 * Loads a thumbnail from Drive.
293 * 311 *
294 * @param {string} url Thumbnail url 312 * @param {string} url Thumbnail url
295 * @return Promise<{{status: string, data:string, width:number, height:number}}> 313 * @return Promise<{{status: string, data:string, width:number, height:number}}>
296 * @private 314 * @private
297 */ 315 */
298 QuickViewController.prototype.loadThumbnailFromDrive_ = function(url) { 316 QuickViewController.prototype.loadThumbnailFromDrive_ = function(url) {
299 return new Promise(function(resolve) { 317 return new Promise(function(resolve) {
300 ImageLoaderClient.getInstance().load(url, resolve) 318 ImageLoaderClient.getInstance().load(url, resolve)
301 }); 319 });
302 }; 320 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698