Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3059)

Unified Diff: chrome/browser/resources/chromeos/arc_support/background.js

Issue 2472223002: WIP (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/arc/arc_support_host.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/chromeos/arc_support/background.js
diff --git a/chrome/browser/resources/chromeos/arc_support/background.js b/chrome/browser/resources/chromeos/arc_support/background.js
index e4d1d5d6c5f28bab67c08308d766f137f6672030..a70425540c436a1c5bde19eaea567003cd3fa2e0 100644
--- a/chrome/browser/resources/chromeos/arc_support/background.js
+++ b/chrome/browser/resources/chromeos/arc_support/background.js
@@ -3,19 +3,6 @@
// found in the LICENSE file.
/**
- * UI Pages. Note the order must be in sync with the ArcAuthService::UIPage
- * enum.
- * @type {Array<string>}
- */
-var UI_PAGES = ['none',
- 'terms',
- 'lso-loading',
- 'lso',
- 'arc-loading',
- 'error',
- 'error-with-feedback'];
-
-/**
* Chrome window that hosts UI. Only one window is allowed.
* @type {chrome.app.window.AppWindow}
*/
@@ -367,9 +354,8 @@ class TermsOfServicePage {
console.error('TermsView loading is aborted: ' + reason);
// Mark ABORTED so that onTermsViewLoaded_() won't show the content view.
this.state_ = LoadState.ABORTED;
- setErrorMessage(
- appWindow.contentWindow.loadTimeData.getString('serverError'));
- showPage('error');
+ showErrorPage(
+ appWindow.contentWindow.loadTimeData.getString('serverError'), false);
}
/** Called when "AGREE" button is clicked. */
@@ -476,7 +462,19 @@ function onNativeMessage(message) {
appWindow.close();
}
} else if (message.action == 'showPage') {
- showPageWithStatus(message.page, message.status);
+ if (message.page != 'terms') {
+ // Explicit request to start not from start page. Assume terms are
+ // accepted in this case.
+ // TODO(hidehiko): this is only for controling "RETRY" button. Remove
+ // this.
+ termsAccepted = true;
+ }
+ showPage(message.page);
+ } else if (message.action == 'showErrorPage') {
+ // TODO(hidehiko): this is only for controling "RETRY" button. Remove
+ // this.
+ termsAccepted = true;
+ showErrorPage(message.errorMessage, message.showFeedbackButton);
} else if (message.action == 'setWindowBounds') {
setWindowBounds();
}
@@ -503,15 +501,7 @@ function showPage(pageDivId) {
hideOverlay();
var doc = appWindow.contentWindow.document;
- var pages = doc.getElementsByClassName('section');
- var sendFeedbackElement = doc.getElementById('button-send-feedback');
- if (pageDivId == 'error-with-feedback') {
- // Only show feedback button if the pageDivId is 'error-with-feedback'.
- sendFeedbackElement.hidden = false;
- pageDivId = 'error';
- } else {
- sendFeedbackElement.hidden = true;
- }
+ var pages = doc.getElementsByClassName("section");
for (var i = 0; i < pages.length; i++) {
pages[i].hidden = pages[i].id != pageDivId;
}
@@ -531,6 +521,28 @@ function showPage(pageDivId) {
}
/**
+ * Shows the error page with setting the given error message.
+ * @param {string} errorMessage L10n error message text.
+ * @param {boolean} showFeedbackButton true if feedback button should be shown.
+ */
+function showErrorPage(errorMessage, showFeedbackButton) {
+ if (!appWindow) {
+ return;
+ }
+
+ // Set error text.
+ var doc = appWindow.contentWindow.document;
+ var messageElement = doc.getElementById('error-message');
+ messageElement.innerText = error;
+
+ // Set visibility of the feedback button.
+ var sendFeedbackElement = doc.getElementById('button-send-feedback');
+ sendFeedbackElement.hidden = !showFeedbackButton;
+
+ showPage('error');
+}
+
+/**
* Sets error message.
* @param {string} error message.
*/
@@ -601,32 +613,6 @@ function hideOverlay() {
overlayContainer.hidden = true;
}
-/**
- * Shows requested page.
- * @param {int} pageId Index of the page to show. Must be in the array range of
- * UI_PAGES.
- * @param {string} status associated with page string status, error message for
- * example.
- */
-function showPageWithStatus(pageId, status) {
- if (!appWindow) {
- return;
- }
-
- if (UI_PAGES[pageId] != 'terms') {
- // Explicit request to start not from start page. Assume terms are
- // accepted in this case.
- // TODO: this is only for controling "RETRY" button. Remove this.
- termsAccepted = true;
- }
-
- if (UI_PAGES[pageId] == 'error' ||
- UI_PAGES[pageId] == 'error-with-feedback') {
- setErrorMessage(status);
- }
- showPage(UI_PAGES[pageId]);
-}
-
function setWindowBounds() {
if (!appWindow) {
return;
@@ -654,7 +640,7 @@ function setWindowBounds() {
appWindow.outerBounds.height = outerHeight;
appWindow.outerBounds.left = Math.ceil((screen.availWidth - outerWidth) / 2);
appWindow.outerBounds.top =
- Math.ceil((screen.availHeight - outerHeight) / 2);
+ Math.ceil((screen.availHeight - outerHeight) / 2);
}
chrome.app.runtime.onLaunched.addListener(function() {
@@ -682,9 +668,9 @@ chrome.app.runtime.onLaunched.addListener(function() {
};
var onLsoViewErrorOccurred = function(details) {
- setErrorMessage(appWindow.contentWindow.loadTimeData.getString(
- 'serverError'));
- showPage('error');
+ showErrorPage(
+ appWindow.contentWindow.loadTimeData.getString('serverError'),
+ false);
lsoError = true;
};
@@ -710,9 +696,10 @@ chrome.app.runtime.onLaunched.addListener(function() {
var authCode = results[0].substring(authCodePrefix.length);
sendNativeMessage('onAuthSucceeded', {code: authCode});
} else {
- setErrorMessage(appWindow.contentWindow.loadTimeData.getString(
- 'authorizationFailed'));
- showPage('error');
+ showErrorPage(
+ appWindow.contentWindow.loadTimeData.getString(
+ 'authorizationFailed'),
+ false);
}
});
};
« no previous file with comments | « chrome/browser/chromeos/arc/arc_support_host.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698