Chromium Code Reviews| 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 * @param {Object.<string, string>} stringData String data. | 8 * @param {Object.<string, string>} stringData String data. |
| 9 * @param {VolumeManager} volumeManager Volume manager. | 9 * @param {VolumeManager} volumeManager Volume manager. |
| 10 */ | 10 */ |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 allEntries: args[1] | 135 allEntries: args[1] |
| 136 }); | 136 }); |
| 137 }); | 137 }); |
| 138 | 138 |
| 139 // Close previous window. | 139 // Close previous window. |
| 140 var closePromise; | 140 var closePromise; |
| 141 if (appWindowPromise) { | 141 if (appWindowPromise) { |
| 142 closePromise = appWindowPromise.then(function(appWindow) { | 142 closePromise = appWindowPromise.then(function(appWindow) { |
| 143 return new Promise(function(fulfill) { | 143 return new Promise(function(fulfill) { |
| 144 appWindow.close(); | 144 appWindow.close(); |
| 145 appWindow.onClosed.addListener(fulfill); | 145 try { |
| 146 appWindow.onClosed.addListener(fulfill); | |
| 147 } catch (error) { | |
| 148 // Sometimes it failes to addListener. | |
|
yoshiki
2014/05/23 06:16:13
The handler should be registered before closing it
hirono
2014/05/26 02:21:48
Done.
| |
| 149 fulfill(); | |
| 150 } | |
| 146 }); | 151 }); |
| 147 }); | 152 }); |
| 148 } else { | 153 } else { |
| 149 closePromise = Promise.resolve(); | 154 closePromise = Promise.resolve(); |
| 150 } | 155 } |
| 151 var createdWindowPromise = closePromise.then(function() { | 156 var createdWindowPromise = closePromise.then(function() { |
| 152 return new Promise(function(fulfill) { | 157 return new Promise(function(fulfill) { |
| 153 chrome.app.window.create( | 158 chrome.app.window.create( |
| 154 'gallery.html', | 159 'gallery.html', |
| 155 { | 160 { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 176 Promise.all([ | 181 Promise.all([ |
| 177 appWindowPromise, | 182 appWindowPromise, |
| 178 allEntriesPromise, | 183 allEntriesPromise, |
| 179 selectedEntriesPromise | 184 selectedEntriesPromise |
| 180 ]).then(function(args) { | 185 ]).then(function(args) { |
| 181 args[0].contentWindow.loadEntries(args[1], args[2]); | 186 args[0].contentWindow.loadEntries(args[1], args[2]); |
| 182 }).catch(function(error) { | 187 }).catch(function(error) { |
| 183 console.error(error.stack || error); | 188 console.error(error.stack || error); |
| 184 }); | 189 }); |
| 185 }); | 190 }); |
| OLD | NEW |