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

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

Issue 1847463002: arc: Use v2/auth LSO page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove arc_auth_fetcher Created 4 years, 9 months 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/extensions/api/messaging/arc_support_host.cc ('k') | components/arc.gypi » ('j') | 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 56c757621c4fa5b49c18e9a4c8c27449ca0f24a1..da2577e706eb625f13eff928f3b09243e6d93c77 100644
--- a/chrome/browser/resources/chromeos/arc_support/background.js
+++ b/chrome/browser/resources/chromeos/arc_support/background.js
@@ -124,15 +124,28 @@ function showPage(pageDivId) {
}
if (pageDivId == 'lso-loading') {
- webview.src = 'https://accounts.google.com/o/oauth2/programmatic_auth?' +
- 'scope=https://www.google.com/accounts/OAuthLogin&client_id' +
- '=1070009224336-sdh77n7uot3oc99ais00jmuft6sk2fg9.apps.' +
- 'googleusercontent.com';
+ webview.src = 'https://accounts.google.com/o/oauth2/v2/auth?client_id=' +
+ '1070009224336-sdh77n7uot3oc99ais00jmuft6sk2fg9.apps.' +
+ 'googleusercontent.com&response_type=code&redirect_uri=oob&' +
+ 'scope=https://www.google.com/accounts/OAuthLogin';
}
appWindow.show();
}
/**
+ * Sets error message.
+ * @param {string} error message.
+ */
+function setErrorMessage(error) {
+ if (!appWindow) {
+ return;
+ }
+ var doc = appWindow.contentWindow.document;
+ var messageElement = doc.getElementById('error-message');
+ messageElement.innerText = error;
+}
+
+/**
* Shows requested page.
* @param {int} pageId Index of the page to show. Must be in the array range of
* UI_PAGES.
@@ -145,9 +158,7 @@ function showPageWithStatus(pageId, status) {
}
if (UI_PAGES[pageId] == 'error') {
- var doc = appWindow.contentWindow.document;
- var messageElement = doc.getElementById('error-message');
- messageElement.innerText = status;
+ setErrorMessage(status);
}
showPage(UI_PAGES[pageId]);
}
@@ -157,16 +168,62 @@ chrome.app.runtime.onLaunched.addListener(function() {
var doc = appWindow.contentWindow.document;
webview = doc.getElementById('arc-support');
- var onWebviewRequestCompleted = function(details) {
- showPage('lso');
+ var isApprovalResponse = function(details) {
var resultUrlPrefix =
- 'https://accounts.google.com/o/oauth2/programmatic_auth?';
- if (details.statusCode == 200 &&
- details.url.substring(0, resultUrlPrefix.length) == resultUrlPrefix) {
- sendNativeMessage('checkAuthCode');
+ 'https://accounts.google.com/o/oauth2/approval?';
xiyuan 2016/03/30 17:22:16 nit: 4-space indent
khmel 2016/03/30 21:30:18 Done.
+ return details.statusCode == 200 &&
+ details.url.substring(0, resultUrlPrefix.length) ==
+ resultUrlPrefix;
+ };
+
+ var onWebviewRequestResponseStarted = function(details) {
+ if (isApprovalResponse(details)) {
+ // Hide LSO page that displays auth code.
+ showPage('arc-loading');
+ } else {
+ showPage('lso');
}
};
+ var onWebviewRequestCompleted = function(details) {
+ if (!isApprovalResponse(details)) {
+ return;
+ }
+
+ var attemptCount = 10;
+ var extractAuthCode = function() {
+ if (webview.src == details.url) {
+ webview.executeScript({code: 'document.title;'
+ }, function(results) {
xiyuan 2016/03/30 17:22:16 nit: Can this fit in the previous line?
khmel 2016/03/30 21:30:18 Done.
+ var authCodePrefix = 'Success code=';
+ if (results[0].substring(0, authCodePrefix.length) ==
+ authCodePrefix) {
xiyuan 2016/03/30 17:22:16 nit: indent 2 more spaces
khmel 2016/03/30 21:30:18 Done.
+ var authCode = results[0].substring(authCodePrefix.length);
+ console.log('Auth code:' + authCode);
xiyuan 2016/03/30 17:22:16 debugging log?
khmel 2016/03/30 21:30:17 Done.
+ var message = {
+ 'action': 'setAuthCode',
+ 'code': authCode
+ };
+ port.postMessage(message);
xiyuan 2016/03/30 17:22:16 I wonder whether we can extend sendNativeMessage t
khmel 2016/03/30 21:30:18 Thanks for idea! I was going to implement somethin
+ } else {
+ setErrorMessage('Authorization failed.');
xiyuan 2016/03/30 17:22:16 The string should be put in grd file along with ot
khmel 2016/03/30 21:30:18 Done.
+ showPage('error');
+ }
+ });
+ } else {
+ if (attemptCount > 0) {
+ attemptCount -= 1;
xiyuan 2016/03/30 17:22:16 nit: attemptCount--
khmel 2016/03/30 21:30:17 Done.
+ setTimeout(extractAuthCode, 100);
+ } else {
+ setErrorMessage('Authorization time out.');
+ showPage('error');
+ }
+ }
+ };
+
+ extractAuthCode();
+ };
+
var requestFilter = {
urls: ['<all_urls>'],
types: ['main_frame']
@@ -174,13 +231,15 @@ chrome.app.runtime.onLaunched.addListener(function() {
webview.request.onCompleted.addListener(onWebviewRequestCompleted,
xiyuan 2016/03/30 17:22:15 We probably should use 'contentload' event on the
khmel 2016/03/30 21:30:18 Thanks, it works stable.
requestFilter);
+ webview.request.onResponseStarted.addListener(
xiyuan 2016/03/30 17:22:16 Suggest to use 'loadstart' event.
khmel 2016/03/30 21:30:18 onResponseStarted is executed on earlier stage. Wh
xiyuan 2016/03/30 21:32:42 Acknowledged.
+ onWebviewRequestResponseStarted, requestFilter);
var onGetStarted = function() {
- sendNativeMessage('checkAuthCode');
+ sendNativeMessage('startLSO');
};
var onRetry = function() {
- sendNativeMessage('checkAuthCode');
+ sendNativeMessage('startLSO');
};
doc.getElementById('get-started').addEventListener('click', onGetStarted);
« no previous file with comments | « chrome/browser/extensions/api/messaging/arc_support_host.cc ('k') | components/arc.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698