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
3 // found in the LICENSE file.
6 * Configuration of the Gallery window.
10 var windowCreateOptions = {
23 * Backgound object. This is necessary for AppWindowWrapper.
24 * @type {!BackgroundBase}
26 var background = new BackgroundBase();
29 * Wrapper of gallery window.
30 * @type {SingletonAppWindowWrapper}
32 var gallery = new SingletonAppWindowWrapper('gallery.html',
36 * Opens gallery window.
37 * @param {!Array<string>} urls List of URL to show.
38 * @return {!Promise} Promise to be fulfilled on success, or rejected on error.
40 function openGalleryWindow(urls) {
41 return new Promise(function(fulfill, reject) {
42 util.URLsToEntries(urls).then(function(result) {
43 fulfill(util.entriesToURLs(result.entries));
45 }).then(function(urls) {
46 if (urls.length === 0)
47 return Promise.reject('No file to open.');
50 return new Promise(function(fulfill, reject) {
54 fulfill.bind(null, gallery));
55 }).then(function(gallery) {
56 var galleryDocument = gallery.rawAppWindow.contentWindow.document;
57 if (galleryDocument.readyState == 'complete')
60 return new Promise(function(fulfill, reject) {
61 galleryDocument.addEventListener(
62 'DOMContentLoaded', fulfill.bind(null, gallery));
65 }).then(function(gallery) {
66 gallery.rawAppWindow.show();
67 return gallery.rawAppWindow.contentWindow.appID;
68 }).catch(function(error) {
69 console.error('Launch failed' + error.stack || error);
70 return Promise.reject(error);
74 background.setLaunchHandler(openGalleryWindow);