From 0466f581c35b44fbf7dd0b63cb43f07f01e4c742 Mon Sep 17 00:00:00 2001 From: "xiyuan@chromium.org" Date: Wed, 10 Aug 2011 05:39:16 +0000 Subject: [ChromeOS] Reset Gaia UI and show error if needed. There are cases where Gaia authentication passed but login still fails, e.g. using a valid Google account that is not in whitelist. We want to reset Gaia UI with an error message when this happens. BUG=chromium-os:18801 TEST=Verify fix for chromium-os:18801. Review URL: http://codereview.chromium.org/7607019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@96133 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/chromeos/login/webui_login_view.cc | 6 ++++ chrome/browser/resources/chromeos/login/bubble.js | 31 +++++++++++++++------ chrome/browser/resources/chromeos/login/oobe.js | 32 ++++++++++++++++++---- .../resources/chromeos/login/screen_gaia_signin.js | 9 ++++++ 4 files changed, 65 insertions(+), 13 deletions(-) diff --git a/chrome/browser/chromeos/login/webui_login_view.cc b/chrome/browser/chromeos/login/webui_login_view.cc index ba4c0af..47f573a 100644 --- a/chrome/browser/chromeos/login/webui_login_view.cc +++ b/chrome/browser/chromeos/login/webui_login_view.cc @@ -257,6 +257,12 @@ bool WebUILoginView::TakeFocus(bool reverse) { void WebUILoginView::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { unhandled_keyboard_event_handler_.HandleKeyboardEvent(event, GetFocusManager()); + + // Make sure error bubble is cleared on keyboard event. This is needed + // when the focus is inside an iframe. + WebUI* web_ui = GetWebUI(); + if (web_ui) + web_ui->CallJavascriptFunction("cr.ui.Oobe.clearErrors"); } } // namespace chromeos diff --git a/chrome/browser/resources/chromeos/login/bubble.js b/chrome/browser/resources/chromeos/login/bubble.js index 7b1bf2fa..2487623 100644 --- a/chrome/browser/resources/chromeos/login/bubble.js +++ b/chrome/browser/resources/chromeos/login/bubble.js @@ -33,23 +33,20 @@ cr.define('cr.ui', function() { /** * Shows the bubble for given anchor element. - * @param {!HTMLElement} el Anchor element of the bubble. + * @param {number} x X position of bubble's reference point. + * @param {number} y Y position of bubble's reference point. * @param {HTMLElement} content Content to show in bubble. * @public */ - showContentForElement: function(el, content) { + showContentAt: function(x, y, content) { const ARROW_OFFSET = 14; - const HORIZONTAL_PADDING = 10; - const VERTICAL_PADDING = 5; - var elementOrigin = Oobe.getOffset(el); - var anchorX = elementOrigin.left + HORIZONTAL_PADDING - ARROW_OFFSET; - var anchorY = elementOrigin.top + el.offsetHeight + VERTICAL_PADDING; + var anchorX = x - ARROW_OFFSET; + var anchorY = y; this.style.left = anchorX + 'px'; this.style.top = anchorY + 'px'; - this.anchor_ = el; this.innerHTML = ''; this.appendChild(content); this.hidden = false; @@ -59,6 +56,24 @@ cr.define('cr.ui', function() { /** * Shows the bubble for given anchor element. * @param {!HTMLElement} el Anchor element of the bubble. + * @param {HTMLElement} content Content to show in bubble. + * @public + */ + showContentForElement: function(el, content) { + const HORIZONTAL_PADDING = 10; + const VERTICAL_PADDING = 5; + + var elementOrigin = Oobe.getOffset(el); + var anchorX = elementOrigin.left + HORIZONTAL_PADDING; + var anchorY = elementOrigin.top + el.offsetHeight + VERTICAL_PADDING; + + this.anchor_ = el; + this.showContentAt(anchorX, anchorY, content); + }, + + /** + * Shows the bubble for given anchor element. + * @param {!HTMLElement} el Anchor element of the bubble. * @param {string} text Text content to show in bubble. * @public */ diff --git a/chrome/browser/resources/chromeos/login/oobe.js b/chrome/browser/resources/chromeos/login/oobe.js index 0f3ad64..72ede4e 100644 --- a/chrome/browser/resources/chromeos/login/oobe.js +++ b/chrome/browser/resources/chromeos/login/oobe.js @@ -455,8 +455,12 @@ cr.define('cr.ui', function() { */ Oobe.resetSigninUI = function() { var currentScreenId = Oobe.getInstance().currentScreen.id; + if (localStrings.getString('authType') == 'webui') - $('signin').reset(currentScreenId == SCREEN_SIGNIN); + $(SCREEN_SIGNIN).reset(currentScreenId == SCREEN_SIGNIN); + else + $(SCREEN_GAIA_SIGNIN).reset(currentScreenId == SCREEN_GAIA_SIGNIN); + $('pod-row').reset(currentScreenId == SCREEN_ACCOUNT_PICKER); }; @@ -470,11 +474,19 @@ cr.define('cr.ui', function() { Oobe.showSignInError = function(loginAttempts, message, link, helpId) { var currentScreenId = Oobe.getInstance().currentScreen.id; var anchor = undefined; + var anchorPos = undefined; if (currentScreenId == SCREEN_SIGNIN) { anchor = $('email'); // Show email field so that bubble shows up at the right location. - $('signin').reset(true); + $(SCREEN_SIGNIN).reset(true); + } else if (currentScreenId == SCREEN_GAIA_SIGNIN) { + // Use anchorPos since we won't be able to get the input fields of Gaia. + anchorPos = Oobe.getOffset(Oobe.getInstance().currentScreen); + + // TODO(xiyuan): Find a reliable way to align with Gaia UI. + anchorPos.left += 60; + anchorPos.top += 105; } else if (currentScreenId == SCREEN_ACCOUNT_PICKER && $('pod-row').activated) { const MAX_LOGIN_ATTEMMPTS_IN_POD = 3; @@ -485,8 +497,8 @@ cr.define('cr.ui', function() { anchor = $('pod-row').activated.mainInput; } - if (!anchor) { - console.log('Warning: Failed to find anchor element for error :' + + if (!anchor && !anchorPos) { + console.log('Warning: Failed to find anchor for error :' + message); return; } @@ -510,7 +522,17 @@ cr.define('cr.ui', function() { error.appendChild(helpLink); } - $('bubble').showContentForElement(anchor, error); + if (anchor) + $('bubble').showContentForElement(anchor, error); + else if (anchorPos) + $('bubble').showContentAt(anchorPos.left, anchorPos.top, error); + }; + + /** + * Clears error bubble. + */ + Oobe.clearErrors = function() { + $('bubble').hide(); }; /** diff --git a/chrome/browser/resources/chromeos/login/screen_gaia_signin.js b/chrome/browser/resources/chromeos/login/screen_gaia_signin.js index 6df1a5cd..3a3bc48 100644 --- a/chrome/browser/resources/chromeos/login/screen_gaia_signin.js +++ b/chrome/browser/resources/chromeos/login/screen_gaia_signin.js @@ -79,6 +79,15 @@ cr.define('login', function() { if (msg.method == 'completeLogin' && this.isAuthExtMessage_(e)) { chrome.send('completeLogin', [msg.email, msg.password] ); } + }, + + /** + * Clears input fields and switches to input mode. + * @param {boolean} takeFocus True to take focus. + */ + reset: function(takeFocus) { + // Reload and show the sign-in UI. + Oobe.showSigninUI(); } }; -- cgit v1.1