Chromium Code Reviews| 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 f668037969f2da7f27ca2b052b2f6926f2690868..51059d8e1be400f93d57f88841c9373f3732540b 100644 |
| --- a/chrome/browser/resources/chromeos/arc_support/background.js |
| +++ b/chrome/browser/resources/chromeos/arc_support/background.js |
| @@ -59,6 +59,19 @@ var termsReloadTimeout = null; |
| var currentDeviceId = null; |
| /** |
| + * Indicates that OptIn flow is started in silent mode and no user interaction |
| + * is expected. |
| + * @type {boolean} |
| + */ |
| +var silentMode = false; |
| + |
| +/** |
| + * Timeout to retry LSO in silent mode. |
| + * @type {object} |
| + */ |
| +var retryTimeout = null; |
| + |
| +/** |
| * Closes current window in response to request from native code. This does not |
| * issue 'cancelAuthCode' message to native code. |
| */ |
| @@ -66,6 +79,7 @@ function closeWindowInternally() { |
| windowClosedInternally = true; |
| appWindow.close(); |
| appWindow = null; |
| + cancelRetry(); |
| } |
| /** |
| @@ -82,9 +96,11 @@ function sendNativeMessage(code, opt_Props) { |
| * Applies localization for html content and sets terms webview. |
| * @param {!Object} data Localized strings and relevant information. |
| * @param {string} deviceId Current device id. |
| + * @param {boolean} _silentMode Indicates if OptIn started in silent mode. |
| */ |
| -function initialize(data, deviceId) { |
| +function initialize(data, deviceId, _silentMode) { |
|
xiyuan
2016/06/27 23:20:42
This looks strange. To avoid the name conflict, we
khmel
2016/06/28 20:05:38
Thanks, that it is what I was looking for.
|
| currentDeviceId = deviceId; |
| + silentMode = _silentMode; |
| var doc = appWindow.contentWindow.document; |
| var loadTimeData = appWindow.contentWindow.loadTimeData; |
| loadTimeData.data = data; |
| @@ -171,7 +187,7 @@ function onNativeMessage(message) { |
| } |
| if (message.action == 'initialize') { |
| - initialize(message.data, message.deviceId); |
| + initialize(message.data, message.deviceId, message.silentMode); |
| } else if (message.action == 'setMetricsMode') { |
| setMetricsMode(message.text, message.canEnable, message.on); |
| } else if (message.action == 'closeUI') { |
| @@ -191,6 +207,30 @@ function connectPort() { |
| } |
| /** |
| + * Cancels current request to get authority code from LSO if it was previously |
| + * scheduled. |
| + */ |
| +function cancelRetry() { |
| + if (!retryTimeout) { |
| + return; |
| + } |
| + clearTimeout(retryTimeout); |
| + retryTimeout = null; |
| +} |
| + |
| +/** |
| + * Schedules next retry to get authority code from LSO. Previous request is |
| + * automatically canceled. |
| + */ |
| +function scheduleRetry() { |
| + cancelRetry(); |
| + var retry = function() { |
| + showPage('lso-loading'); |
| + }; |
| + retryTimeout = setTimeout(retry, 60000); |
| +} |
| + |
| +/** |
| * Shows requested page and hide others. Show appWindow if it was hidden before |
| * for non 'none' pages. For 'none' page this closes host window. |
| * @param {string} pageDivId id of divider of the page to show. |
| @@ -227,7 +267,16 @@ function showPage(pageDivId) { |
| 'device_type=arc_plus_plus&device_id=' + currentDeviceId + |
| '&hl=' + navigator.language; |
| } |
| - appWindow.show(); |
| + |
| + if (!silentMode) { |
| + appWindow.show(); |
| + } else { |
| + if (pageDivId == 'arc-loading') { |
| + cancelRetry(); |
| + } else { |
| + scheduleRetry(); |
| + } |
| + } |
| } |
| /** |
| @@ -297,6 +346,11 @@ chrome.app.runtime.onLaunched.addListener(function() { |
| if (!isApprovalResponse(lsoView.src)) { |
| // Show LSO page when its content is ready. |
| showPage('lso'); |
| + if (silentMode) { |
| + var submitAproveCode = |
|
xiyuan
2016/06/27 23:20:42
submitAproveCode -> submitAp*p*roveCode
khmel
2016/06/28 20:05:38
Done.
|
| + 'document.getElementById("connect_approve").submit();'; |
| + lsoView.executeScript({code: submitAproveCode}, function(results) {}); |
| + } |
| return; |
| } |
| @@ -306,6 +360,7 @@ chrome.app.runtime.onLaunched.addListener(function() { |
| authCodePrefix) { |
| var authCode = results[0].substring(authCodePrefix.length); |
| sendNativeMessage('setAuthCode', {code: authCode}); |
| + cancelRetry(); |
| } else { |
| setErrorMessage(appWindow.contentWindow.loadTimeData.getString( |
| 'authorizationFailed')); |
| @@ -398,6 +453,7 @@ chrome.app.runtime.onLaunched.addListener(function() { |
| clearTimeout(termsReloadTimeout); |
| termsReloadTimeout = null; |
| } |
| + cancelRetry(); |
| if (windowClosedInternally) { |
| return; |