Commit b9333852 authored by Kuo Jen Wei's avatar Kuo Jen Wei Committed by Commit Bot

[CCA] Convert gallerybutton.js into ES6 module.

Bug: 141518780
Test: Pass closure compiler check, tast run <DUT> 'camera.CCAUI*' on
both HALv1 and v3 devices.

Change-Id: I73a9cf7befd738171822bc58cb746ccf712f354d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1983695
Commit-Queue: Kuo Jen Wei <inker@chromium.org>
Commit-Queue: Shik Chen <shik@chromium.org>
Auto-Submit: Kuo Jen Wei <inker@chromium.org>
Reviewed-by: default avatarShik Chen <shik@chromium.org>
Cr-Commit-Position: refs/heads/master@{#728478}
parent 6663e0d0
...@@ -53,6 +53,9 @@ js_library("intent") { ...@@ -53,6 +53,9 @@ js_library("intent") {
js_library("gallerybutton") { js_library("gallerybutton") {
deps = [ deps = [
":chrome_util", ":chrome_util",
"models:filesystem",
"models:result_saver",
"models:video_saver",
] ]
externs_list = [ externs_list = [
"$externs_path/file_manager_private.js", "$externs_path/file_manager_private.js",
......
...@@ -2,17 +2,23 @@ ...@@ -2,17 +2,23 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
'use strict'; import {assert, assertInstanceof} from './chrome_util.js';
import {FileVideoSaver} from './models/file_video_saver.js';
import * as filesystem from './models/filesystem.js';
// eslint-disable-next-line no-unused-vars
import {ResultSaver} from './models/result_saver.js';
import * as util from './util.js';
/** /**
* Namespace for the Camera app. * Width of thumbnail used by cover photo of gallery button.
* @type {number}
*/ */
var cca = cca || {}; const THUMBNAIL_WIDTH = 240;
/** /**
* Cover photo of gallery button. * Cover photo of gallery button.
*/ */
cca.CoverPhoto = class { class CoverPhoto {
/** /**
* @param {!FileEntry} file File entry of cover photo. * @param {!FileEntry} file File entry of cover photo.
* @param {!string} thumbnailUrl Url to its thumbnail. * @param {!string} thumbnailUrl Url to its thumbnail.
...@@ -49,38 +55,31 @@ cca.CoverPhoto = class { ...@@ -49,38 +55,31 @@ cca.CoverPhoto = class {
/** /**
* Creates CoverPhoto objects from photo file. * Creates CoverPhoto objects from photo file.
* @param {!FileEntry} file * @param {!FileEntry} file
* @return {!Promise<!cca.CoverPhoto>} * @return {!Promise<!CoverPhoto>}
*/ */
static async create(file) { static async create(file) {
const fileUrl = await cca.models.FileSystem.pictureURL(file); const fileUrl = await filesystem.pictureURL(file);
const isVideo = cca.models.FileSystem.hasVideoPrefix(file); const isVideo = filesystem.hasVideoPrefix(file);
const thumbnail = await cca.util.scalePicture( const thumbnail =
fileUrl, isVideo, cca.CoverPhoto.THUMBNAIL_WIDTH); await util.scalePicture(fileUrl, isVideo, THUMBNAIL_WIDTH);
URL.revokeObjectURL(fileUrl); URL.revokeObjectURL(fileUrl);
return new cca.CoverPhoto(file, URL.createObjectURL(thumbnail)); return new CoverPhoto(file, URL.createObjectURL(thumbnail));
} }
}; }
/**
* Width of thumbnail.
* @type {number}
* @const
*/
cca.CoverPhoto.THUMBNAIL_WIDTH = 240;
/** /**
* Creates a controller for the gallery-button. * Creates a controller for the gallery-button.
* @implements {cca.models.ResultSaver} * @implements {ResultSaver}
*/ */
cca.GalleryButton = class { export class GalleryButton {
/** /**
* @public * @public
*/ */
constructor() { constructor() {
/** /**
* Cover photo from latest saved picture. * Cover photo from latest saved picture.
* @type {?cca.CoverPhoto} * @type {?CoverPhoto}
* @private * @private
*/ */
this.cover_ = null; this.cover_ = null;
...@@ -89,7 +88,7 @@ cca.GalleryButton = class { ...@@ -89,7 +88,7 @@ cca.GalleryButton = class {
* @type {!HTMLButtonElement} * @type {!HTMLButtonElement}
* @private * @private
*/ */
this.button_ = cca.assertInstanceof( this.button_ = assertInstanceof(
document.querySelector('#gallery-enter'), HTMLButtonElement); document.querySelector('#gallery-enter'), HTMLButtonElement);
/** /**
...@@ -126,7 +125,7 @@ cca.GalleryButton = class { ...@@ -126,7 +125,7 @@ cca.GalleryButton = class {
* @private * @private
*/ */
async updateCover_(file) { async updateCover_(file) {
const cover = file === null ? null : await cca.CoverPhoto.create(file); const cover = file === null ? null : await CoverPhoto.create(file);
if (this.cover_ === cover) { if (this.cover_ === cover) {
return; return;
} }
...@@ -152,25 +151,24 @@ cca.GalleryButton = class { ...@@ -152,25 +151,24 @@ cca.GalleryButton = class {
// Checks existence of cached cover photo. // Checks existence of cached cover photo.
if (this.cover_ !== null) { if (this.cover_ !== null) {
const file = await cca.models.FileSystem.getFile( const file =
dir, this.cover_.name, /* create */ false); await filesystem.getFile(dir, this.cover_.name, /* create */ false);
if (file !== null) { if (file !== null) {
return; return;
} }
} }
// Rescan file system. // Rescan file system.
const files = await cca.models.FileSystem.getEntries(); const files = await filesystem.getEntries();
if (files.length === 0) { if (files.length === 0) {
await this.updateCover_(null); await this.updateCover_(null);
return; return;
} }
const filesWithTime = await Promise.all(files.map( const filesWithTime = await Promise.all(
async (file) => ({ files.map(async (file) => ({
file, file,
time: time: (await filesystem.getMetadata(file)).modificationTime,
(await cca.models.FileSystem.getMetadata(file)).modificationTime, })));
})));
const lastFile = const lastFile =
filesWithTime.reduce((last, cur) => last.time > cur.time ? last : cur) filesWithTime.reduce((last, cur) => last.time > cur.time ? last : cur)
.file; .file;
...@@ -205,10 +203,10 @@ cca.GalleryButton = class { ...@@ -205,10 +203,10 @@ cca.GalleryButton = class {
// nothing. // nothing.
// TODO(yuli): Support showing images by EXIF orientation // TODO(yuli): Support showing images by EXIF orientation
// instead. // instead.
cca.util.orientPhoto(blob, resolve, () => resolve(blob)); util.orientPhoto(blob, resolve, () => resolve(blob));
}); });
const file = await cca.models.FileSystem.saveBlob(orientedPhoto, name); const file = await filesystem.saveBlob(orientedPhoto, name);
cca.assert(file !== null); assert(file !== null);
await this.updateCover_(file); await this.updateCover_(file);
} }
...@@ -216,8 +214,8 @@ cca.GalleryButton = class { ...@@ -216,8 +214,8 @@ cca.GalleryButton = class {
* @override * @override
*/ */
async startSaveVideo() { async startSaveVideo() {
const tempFile = await cca.models.FileSystem.createTempVideoFile(); const tempFile = await filesystem.createTempVideoFile();
return cca.models.FileVideoSaver.create(tempFile); return FileVideoSaver.create(tempFile);
} }
/** /**
...@@ -225,8 +223,13 @@ cca.GalleryButton = class { ...@@ -225,8 +223,13 @@ cca.GalleryButton = class {
*/ */
async finishSaveVideo(video, name) { async finishSaveVideo(video, name) {
const tempFile = await video.endWrite(); const tempFile = await video.endWrite();
const file = await cca.models.FileSystem.saveVideo(tempFile, name); const file = await filesystem.saveVideo(tempFile, name);
cca.assert(file !== null); assert(file !== null);
await this.updateCover_(file); await this.updateCover_(file);
} }
}; }
/**
* @typedef {GalleryButton}
*/
cca.GalleryButton = GalleryButton;
...@@ -21,6 +21,7 @@ js_library("filenamer") { ...@@ -21,6 +21,7 @@ js_library("filenamer") {
js_library("filesystem") { js_library("filesystem") {
deps = [ deps = [
":filenamer",
"../browser_proxy:browser_proxy", "../browser_proxy:browser_proxy",
] ]
} }
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
<script type="module" src="../js/device/constraints_preferrer.js"></script> <script type="module" src="../js/device/constraints_preferrer.js"></script>
<script type="module" src="../js/device/device_info_updater.js"></script> <script type="module" src="../js/device/device_info_updater.js"></script>
<script type="module" src="../js/models/filenamer.js"></script> <script type="module" src="../js/models/filenamer.js"></script>
<script defer src="../js/gallerybutton.js"></script> <script type="module" src="../js/gallerybutton.js"></script>
<script type="module" src="../js/models/filesystem.js"></script> <script type="module" src="../js/models/filesystem.js"></script>
<script type="module" src="../js/models/result_saver.js"></script> <script type="module" src="../js/models/result_saver.js"></script>
<script type="module" src="../js/models/video_saver_interface.js"></script> <script type="module" src="../js/models/video_saver_interface.js"></script>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment