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 * Configuration of the Gallery window. | 6 * Configuration of the Gallery window. |
7 * @const | 7 * @const |
8 * @type {Object} | 8 * @type {Object} |
9 */ | 9 */ |
10 var windowCreateOptions = { | 10 var windowCreateOptions = { |
11 id: 'gallery', | 11 id: 'gallery', |
12 innerBounds: { | 12 innerBounds: { |
13 minWidth: 820, | 13 minWidth: 820, |
14 minHeight: 554 | 14 minHeight: 554 |
15 }, | 15 }, |
16 frame: 'none' | 16 frame: 'none' |
17 }; | 17 }; |
18 | 18 |
19 /** | 19 /** |
20 * Backgound object. This is necessary for AppWindowWrapper. | 20 * Backgound object. This is necessary for AppWindowWrapper. |
21 * @type {!BackgroundBase} | 21 * @type {!BackgroundBase} |
22 */ | 22 */ |
23 var background = new BackgroundBase(); | 23 var background = new BackgroundBase(); |
24 | 24 |
25 | 25 |
| 26 /** |
| 27 * Wrapper of gallery window. |
| 28 * @type {SingletonAppWindowWrapper} |
| 29 */ |
| 30 var gallery = new SingletonAppWindowWrapper('gallery.html', |
| 31 windowCreateOptions); |
| 32 |
26 // Initializes the strings. This needs for the volume manager. | 33 // Initializes the strings. This needs for the volume manager. |
27 var loadTimeDataPromise = new Promise(function(fulfill, reject) { | 34 var loadTimeDataPromise = new Promise(function(fulfill, reject) { |
28 chrome.fileManagerPrivate.getStrings(function(stringData) { | 35 chrome.fileManagerPrivate.getStrings(function(stringData) { |
29 loadTimeData.data = stringData; | 36 loadTimeData.data = stringData; |
30 fulfill(true); | 37 fulfill(true); |
31 }); | 38 }); |
32 }); | 39 }); |
33 | 40 |
34 // Initializes the volume manager. This needs for isolated entries. | 41 // Initializes the volume manager. This needs for isolated entries. |
35 var volumeManagerPromise = new Promise(function(fulfill, reject) { | 42 var volumeManagerPromise = new Promise(function(fulfill, reject) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 chrome.fileManagerPrivate.resolveIsolatedEntries( | 76 chrome.fileManagerPrivate.resolveIsolatedEntries( |
70 isolatedEntries, | 77 isolatedEntries, |
71 function(externalEntries) { | 78 function(externalEntries) { |
72 var urls = util.entriesToURLs(externalEntries); | 79 var urls = util.entriesToURLs(externalEntries); |
73 openGalleryWindow(urls, false); | 80 openGalleryWindow(urls, false); |
74 }); | 81 }); |
75 }); | 82 }); |
76 } | 83 } |
77 | 84 |
78 /** | 85 /** |
79 * Returns a function to generate an ID for window. | |
80 * @type {function():string} Function which returns an unique id. | |
81 */ | |
82 var generateWindowId = (function() { | |
83 var seq = 0; | |
84 return function() { | |
85 return 'GALLERY_' + seq++; | |
86 }; | |
87 })(); | |
88 | |
89 /** | |
90 * Opens gallery window. | 86 * Opens gallery window. |
91 * @param {!Array.<string>} urls List of URL to show. | 87 * @param {!Array.<string>} urls List of URL to show. |
92 * @param {boolean} reopen True if reopen, false otherwise. | 88 * @param {boolean} reopen True if reopen, false otherwise. |
93 * @return {!Promise} Promise to be fulfilled on success, or rejected on error. | 89 * @return {!Promise} Promise to be fulfilled on success, or rejected on error. |
94 */ | 90 */ |
95 function openGalleryWindow(urls, reopen) { | 91 function openGalleryWindow(urls, reopen) { |
96 return new Promise(function(fulfill, reject) { | 92 return new Promise(function(fulfill, reject) { |
97 util.URLsToEntries(urls).then(function(result) { | 93 util.URLsToEntries(urls).then(function(result) { |
98 fulfill(util.entriesToURLs(result.entries)); | 94 fulfill(util.entriesToURLs(result.entries)); |
99 }).catch(reject); | 95 }).catch(reject); |
100 }).then(function(urls) { | 96 }).then(function(urls) { |
101 if (urls.length === 0) | 97 if (urls.length === 0) |
102 return Promise.reject('No file to open.'); | 98 return Promise.reject('No file to open.'); |
103 | 99 |
104 var windowId = generateWindowId(); | |
105 | |
106 // Opens a window. | 100 // Opens a window. |
107 return new Promise(function(fulfill, reject) { | 101 return new Promise(function(fulfill, reject) { |
108 var gallery = new AppWindowWrapper('gallery.html', | |
109 windowId, | |
110 windowCreateOptions); | |
111 | |
112 gallery.launch( | 102 gallery.launch( |
113 {urls: urls}, | 103 {urls: urls}, |
114 reopen, | 104 reopen, |
115 fulfill.bind(null, gallery)); | 105 fulfill.bind(null, gallery)); |
116 }).then(function(gallery) { | 106 }).then(function(gallery) { |
117 var galleryDocument = gallery.rawAppWindow.contentWindow.document; | 107 var galleryDocument = gallery.rawAppWindow.contentWindow.document; |
118 if (galleryDocument.readyState == 'complete') | 108 if (galleryDocument.readyState == 'complete') |
119 return gallery; | 109 return gallery; |
120 | 110 |
121 return new Promise(function(fulfill, reject) { | 111 return new Promise(function(fulfill, reject) { |
(...skipping 22 matching lines...) Expand all Loading... |
144 chrome.runtime.onMessageExternal.addListener(function(message) { | 134 chrome.runtime.onMessageExternal.addListener(function(message) { |
145 if (message.name !== 'testResourceLoaded') | 135 if (message.name !== 'testResourceLoaded') |
146 return; | 136 return; |
147 var script = document.createElement('script'); | 137 var script = document.createElement('script'); |
148 script.src = | 138 script.src = |
149 'chrome-extension://' + window.testExtensionId + | 139 'chrome-extension://' + window.testExtensionId + |
150 '/gallery/test_loader.js'; | 140 '/gallery/test_loader.js'; |
151 document.documentElement.appendChild(script); | 141 document.documentElement.appendChild(script); |
152 }); | 142 }); |
153 } | 143 } |
OLD | NEW |