OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 //<include src="../../../../ui/webui/resources/js/cr.js"> | 5 //<include src="../../../../ui/webui/resources/js/cr.js"> |
6 //<include src="../../../../ui/webui/resources/js/load_time_data.js"> | 6 //<include src="../../../../ui/webui/resources/js/load_time_data.js"> |
7 //<include src="../../../../ui/webui/resources/js/i18n_template_no_process.js"> | 7 //<include src="../../../../ui/webui/resources/js/i18n_template_no_process.js"> |
8 //<include src="../../../../ui/webui/resources/js/cr/event_target.js"> | 8 //<include src="../../../../ui/webui/resources/js/cr/event_target.js"> |
9 //<include src="../../../../ui/webui/resources/js/cr/ui/dialogs.js"> | 9 //<include src="../../../../ui/webui/resources/js/cr/ui/dialogs.js"> |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 } | 33 } |
34 | 34 |
35 /** | 35 /** |
36 * Default strings. | 36 * Default strings. |
37 */ | 37 */ |
38 var defaultStrings = { | 38 var defaultStrings = { |
39 'language': 'en', | 39 'language': 'en', |
40 'LINK_TO_WEBSTORE': '[LOCALIZE ME] Learn more...', | 40 'LINK_TO_WEBSTORE': '[LOCALIZE ME] Learn more...', |
41 'INSTALLATION_FAILED_MESSAGE': '[LOCALIZE ME] Installation failed!', | 41 'INSTALLATION_FAILED_MESSAGE': '[LOCALIZE ME] Installation failed!', |
42 'OK_BUTTON': '[LOCALIZE ME] OK', | 42 'OK_BUTTON': '[LOCALIZE ME] OK', |
43 'TITLE_PRINTER_PROVIDERS': '[LOCALIZE ME] Select app for your printer' | 43 'TITLE_PRINTER_PROVIDERS': '[LOCALIZE ME] Select app for your printer', |
| 44 'DEFAULT_ERROR_MESSAGE': '[LOCALIZE ME] Failure' |
44 }; | 45 }; |
45 | 46 |
46 /** | 47 /** |
47 * @param {string} id The string id. | 48 * @param {string} id The string id. |
48 * @return {string} | 49 * @return {string} |
49 */ | 50 */ |
50 function getString(id) { | 51 function getString(id) { |
51 return loadTimeData.getString(id) || defaultStrings[id] || ''; | 52 return loadTimeData.getString(id) || defaultStrings[id] || ''; |
52 } | 53 } |
53 | 54 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 } | 115 } |
115 callback(token); | 116 callback(token); |
116 }); | 117 }); |
117 } | 118 } |
118 }; | 119 }; |
119 } | 120 } |
120 | 121 |
121 function initializeTopbarButtons() { | 122 function initializeTopbarButtons() { |
122 $('close-button').addEventListener('click', function(e) { | 123 $('close-button').addEventListener('click', function(e) { |
123 e.preventDefault(); | 124 e.preventDefault(); |
124 chrome.app.window.current().close(); | 125 closeAppWindow(); |
125 }); | 126 }); |
126 | 127 |
127 $('close-button').addEventListener('mousedown', function(e) { | 128 $('close-button').addEventListener('mousedown', function(e) { |
128 e.preventDefault(); | 129 e.preventDefault(); |
129 }); | 130 }); |
130 | 131 |
131 $('minimize-button').addEventListener('click', function(e) { | 132 $('minimize-button').addEventListener('click', function(e) { |
132 e.preventDefault(); | 133 e.preventDefault(); |
133 chrome.app.window.current().minimize(); | 134 chrome.app.window.current().minimize(); |
134 }); | 135 }); |
135 | 136 |
136 $('minimize-button').addEventListener('mousedown', function(e) { | 137 $('minimize-button').addEventListener('mousedown', function(e) { |
137 e.preventDefault(); | 138 e.preventDefault(); |
138 }); | 139 }); |
139 } | 140 } |
140 | 141 |
| 142 /** |
| 143 * @param {!CWSWidgetContainer.Result} result The result reported by the widget. |
| 144 */ |
| 145 function showWidgetResult(result) { |
| 146 // TODO(tbarzic): Add some UI to show on success. |
| 147 if (result != CWSWidgetContainer.Result.FAILED) { |
| 148 closeAppWindow(); |
| 149 return; |
| 150 } |
| 151 |
| 152 var dialog = new CWSWidgetContainerErrorDialog($('widget-container-root')); |
| 153 dialog.show(getString('DEFAULT_ERROR_MESSAGE'), |
| 154 closeAppWindow, |
| 155 closeAppWindow); |
| 156 } |
| 157 |
| 158 /** Closes the current app window. */ |
| 159 function closeAppWindow() { |
| 160 chrome.app.window.current().close(); |
| 161 } |
| 162 |
141 window.addEventListener('DOMContentLoaded', function() { | 163 window.addEventListener('DOMContentLoaded', function() { |
142 initializeTopbarButtons(); | 164 initializeTopbarButtons(); |
143 | 165 |
144 chrome.webstoreWidgetPrivate.getStrings(function(strings) { | 166 chrome.webstoreWidgetPrivate.getStrings(function(strings) { |
145 loadTimeData.data = strings; | 167 loadTimeData.data = strings; |
146 i18nTemplate.process(document, loadTimeData); | 168 i18nTemplate.process(document, loadTimeData); |
147 | 169 |
148 cr.ui.dialogs.BaseDialog.OK_LABEL = getString('OK_BUTTON'); | 170 cr.ui.dialogs.BaseDialog.OK_LABEL = getString('OK_BUTTON'); |
149 | 171 |
150 document.title = getString('TITLE_PRINTER_PROVIDERS'); | 172 document.title = getString('TITLE_PRINTER_PROVIDERS'); |
(...skipping 18 matching lines...) Expand all Loading... |
169 document, root, platformDelegate, {} /* state */); | 191 document, root, platformDelegate, {} /* state */); |
170 | 192 |
171 widgetContainer.ready() | 193 widgetContainer.ready() |
172 /** @return {!Promise.<CWSWidgetContainer.ResolveReason>} */ | 194 /** @return {!Promise.<CWSWidgetContainer.ResolveReason>} */ |
173 .then(function() { | 195 .then(function() { |
174 return widgetContainer.start(window.params.filter, | 196 return widgetContainer.start(window.params.filter, |
175 window.params.webstoreUrl); | 197 window.params.webstoreUrl); |
176 }) | 198 }) |
177 /** @param {!CWSWidgetContainer.ResolveReason} reason */ | 199 /** @param {!CWSWidgetContainer.ResolveReason} reason */ |
178 .then(function(reason) { | 200 .then(function(reason) { |
179 chrome.app.window.current().close(); | 201 if (reason != CWSWidgetContainer.ResolveReason.DONE) |
| 202 return; |
| 203 |
| 204 var result = widgetContainer.finalizeAndGetResult(); |
| 205 showWidgetResult(result.result); |
180 }) | 206 }) |
181 /** @param {*} error */ | 207 /** @param {*} error */ |
182 .catch(function(error) { | 208 .catch(function(error) { |
183 // TODO(tbarzic): Add error UI. | 209 showWidgetResult(CWSWidgetContainer.Result.FAILED); |
184 console.error(error); | |
185 }); | 210 }); |
186 }); | 211 }); |
187 }); | 212 }); |
188 })(); | 213 })(); |
OLD | NEW |