Index: components/chrome_apps/webstore_widget/app/main.js |
diff --git a/components/chrome_apps/webstore_widget/app/main.js b/components/chrome_apps/webstore_widget/app/main.js |
index 56b1569ff89bf0a221e16451c9dba342a62ff1f5..1c88b99d34847703f18e00e714fedf11b3323a03 100644 |
--- a/components/chrome_apps/webstore_widget/app/main.js |
+++ b/components/chrome_apps/webstore_widget/app/main.js |
@@ -40,7 +40,8 @@ var defaultStrings = { |
'LINK_TO_WEBSTORE': '[LOCALIZE ME] Learn more...', |
'INSTALLATION_FAILED_MESSAGE': '[LOCALIZE ME] Installation failed!', |
'OK_BUTTON': '[LOCALIZE ME] OK', |
- 'TITLE_PRINTER_PROVIDERS': '[LOCALIZE ME] Select app for your printer' |
+ 'TITLE_PRINTER_PROVIDERS': '[LOCALIZE ME] Select app for your printer', |
+ 'DEFAULT_ERROR_MESSAGE': '[LOCALIZE ME] Failure' |
}; |
@@ -122,7 +123,7 @@ function createPlatformDelegate(strings) { |
function initializeTopbarButtons() { |
$('close-button').addEventListener('click', function(e) { |
e.preventDefault(); |
- chrome.app.window.current().close(); |
+ close(); |
}); |
$('close-button').addEventListener('mousedown', function(e) { |
@@ -139,6 +140,25 @@ function initializeTopbarButtons() { |
}); |
} |
+/** |
+ * @param {!CWSWidgetContainer.Result} result The result reported by the widget. |
+ */ |
+function showWidgetResult(result) { |
+ // TODO(tbarzic): Add some UI to show on success. |
+ if (result != CWSWidgetContainer.Result.FAILED) { |
+ close(); |
+ return; |
+ } |
+ |
+ var dialog = new CWSWidgetContainerErrorDialog($('widget-container-root')); |
+ dialog.show(getString('DEFAULT_ERROR_MESSAGE'), close, close); |
+} |
+ |
+/** Closes the current app window. */ |
+function close() { |
yoshiki
2015/05/12 13:57:15
nit: this overrides window.close() in this scope.
tbarzic
2015/05/12 20:38:51
Done.
|
+ chrome.app.window.current().close(); |
+} |
+ |
window.addEventListener('DOMContentLoaded', function() { |
initializeTopbarButtons(); |
@@ -177,12 +197,15 @@ window.addEventListener('DOMContentLoaded', function() { |
}) |
/** @param {!CWSWidgetContainer.ResolveReason} reason */ |
.then(function(reason) { |
- chrome.app.window.current().close(); |
+ if (reason != CWSWidgetContainer.ResolveReason.DONE) |
+ return; |
+ |
+ var result = widgetContainer.finalizeAndGetResult(); |
+ showWidgetResult(result.result); |
}) |
/** @param {*} error */ |
.catch(function(error) { |
- // TODO(tbarzic): Add error UI. |
- console.error(error); |
+ showWidgetResult(CWSWidgetContainer.Result.FAILED); |
}); |
}); |
}); |