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

Side by Side Diff: chrome/browser/resources/chromeos/arc_support/background.js

Issue 2142933006: arc: Implement scrollable OptIn window content. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * UI Pages. Note the order must be in sync with the ArcAuthService::UIPage 6 * UI Pages. Note the order must be in sync with the ArcAuthService::UIPage
7 * enum. 7 * enum.
8 * @type {Array<string>} 8 * @type {Array<string>}
9 */ 9 */
10 var UI_PAGES = ['none', 10 var UI_PAGES = ['none',
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 */ 59 */
60 var currentDeviceId = null; 60 var currentDeviceId = null;
61 61
62 /** 62 /**
63 * Indicates that terms were accepted by user. 63 * Indicates that terms were accepted by user.
64 * @type {boolean} 64 * @type {boolean}
65 */ 65 */
66 var termsAccepted = false; 66 var termsAccepted = false;
67 67
68 /** 68 /**
69 * Host window inner default width.
70 * @type {int}
71 */
72 var innerWidth = 960;
xiyuan 2016/07/12 21:50:21 Looks like |innerWidth| and |innerHeight| are cons
khmel 2016/07/12 22:05:10 Good point, thanks.
73
74 /**
75 * Host window inner default height.
76 * @type {int}
77 */
78 var innerHeight = 688;
79
80
81 /**
69 * Closes current window in response to request from native code. This does not 82 * Closes current window in response to request from native code. This does not
70 * issue 'cancelAuthCode' message to native code. 83 * issue 'cancelAuthCode' message to native code.
71 */ 84 */
72 function closeWindowInternally() { 85 function closeWindowInternally() {
73 windowClosedInternally = true; 86 windowClosedInternally = true;
74 appWindow.close(); 87 appWindow.close();
75 appWindow = null; 88 appWindow = null;
76 } 89 }
77 90
78 /** 91 /**
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 } 213 }
201 214
202 if (message.action == 'initialize') { 215 if (message.action == 'initialize') {
203 initialize(message.data, message.deviceId); 216 initialize(message.data, message.deviceId);
204 } else if (message.action == 'setMetricsMode') { 217 } else if (message.action == 'setMetricsMode') {
205 setMetricsMode(message.text, message.canEnable, message.on); 218 setMetricsMode(message.text, message.canEnable, message.on);
206 } else if (message.action == 'closeUI') { 219 } else if (message.action == 'closeUI') {
207 closeWindowInternally(); 220 closeWindowInternally();
208 } else if (message.action == 'showPage') { 221 } else if (message.action == 'showPage') {
209 showPageWithStatus(message.page, message.status); 222 showPageWithStatus(message.page, message.status);
223 } else if (message.action == 'setWindowBounds') {
224 setWindowBounds();
210 } 225 }
211 } 226 }
212 227
213 /** 228 /**
214 * Connects to ArcSupportHost. 229 * Connects to ArcSupportHost.
215 */ 230 */
216 function connectPort() { 231 function connectPort() {
217 var hostName = 'com.google.arc_support'; 232 var hostName = 'com.google.arc_support';
218 port = chrome.runtime.connectNative(hostName); 233 port = chrome.runtime.connectNative(hostName);
219 port.onMessage.addListener(onNativeMessage); 234 port.onMessage.addListener(onNativeMessage);
(...skipping 28 matching lines...) Expand all
248 pages[i].hidden = pages[i].id != pageDivId; 263 pages[i].hidden = pages[i].id != pageDivId;
249 } 264 }
250 265
251 if (pageDivId == 'lso-loading') { 266 if (pageDivId == 'lso-loading') {
252 lsoView.src = 'https://accounts.google.com/o/oauth2/v2/auth?client_id=' + 267 lsoView.src = 'https://accounts.google.com/o/oauth2/v2/auth?client_id=' +
253 '1070009224336-sdh77n7uot3oc99ais00jmuft6sk2fg9.apps.' + 268 '1070009224336-sdh77n7uot3oc99ais00jmuft6sk2fg9.apps.' +
254 'googleusercontent.com&response_type=code&redirect_uri=oob&' + 269 'googleusercontent.com&response_type=code&redirect_uri=oob&' +
255 'scope=https://www.google.com/accounts/OAuthLogin&' + 270 'scope=https://www.google.com/accounts/OAuthLogin&' +
256 'device_type=arc_plus_plus&device_id=' + currentDeviceId + 271 'device_type=arc_plus_plus&device_id=' + currentDeviceId +
257 '&hl=' + navigator.language; 272 '&hl=' + navigator.language;
273 console.log(lsoView.src);
xiyuan 2016/07/12 21:50:21 Can we remove this?
khmel 2016/07/12 22:05:10 Yep, forgot to upload this. DONE
258 } 274 }
259 appWindow.show(); 275 appWindow.show();
260 } 276 }
261 277
262 /** 278 /**
263 * Sets error message. 279 * Sets error message.
264 * @param {string} error message. 280 * @param {string} error message.
265 */ 281 */
266 function setErrorMessage(error) { 282 function setErrorMessage(error) {
267 if (!appWindow) { 283 if (!appWindow) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 showPage(UI_PAGES[pageId]); 316 showPage(UI_PAGES[pageId]);
301 } 317 }
302 318
303 /** 319 /**
304 * Loads initial Play Store terms. 320 * Loads initial Play Store terms.
305 */ 321 */
306 function loadInitialTerms() { 322 function loadInitialTerms() {
307 termsView.src = 'https://play.google.com/about/play-terms.html'; 323 termsView.src = 'https://play.google.com/about/play-terms.html';
308 } 324 }
309 325
326 function setWindowBounds() {
327 if (!appWindow) {
328 return;
329 }
330
331 var decorationWidht = appWindow.outerBounds.width -
xiyuan 2016/07/12 21:50:21 decorationWidht -> decorationWidth
khmel 2016/07/12 22:05:10 Done.
332 appWindow.innerBounds.width;
333 var decorationHeight = appWindow.outerBounds.height -
334 appWindow.innerBounds.height;
335
336 var outerWidth = innerWidth + decorationWidht;
337 var outerHeight = innerHeight + decorationHeight;
338 if (outerWidth > screen.availWidth) {
339 outerWidth = screen.availWidth;
340 }
341 if (outerHeight > screen.availHeight) {
342 outerHeight = screen.availHeight;
343 }
344 if (appWindow.outerBounds.width == outerWidth &&
345 appWindow.outerBounds.height == outerHeight) {
346 return;
347 }
348
349 appWindow.outerBounds.width = outerWidth;
350 appWindow.outerBounds.height = outerHeight;
351 appWindow.outerBounds.left = Math.ceil((screen.availWidth - outerWidth) / 2);
352 appWindow.outerBounds.top =
353 Math.ceil((screen.availHeight - outerHeight) / 2);
354 }
355
310 chrome.app.runtime.onLaunched.addListener(function() { 356 chrome.app.runtime.onLaunched.addListener(function() {
311 var onAppContentLoad = function() { 357 var onAppContentLoad = function() {
312 var doc = appWindow.contentWindow.document; 358 var doc = appWindow.contentWindow.document;
313 lsoView = doc.getElementById('arc-support'); 359 lsoView = doc.getElementById('arc-support');
360 lsoView.addContentScripts([
361 { name: 'postProcess',
362 matches: ['https://accounts.google.com/*'],
363 css: { files: ['lso.css'] },
khmel 2016/07/12 21:15:37 To make scroll bars in one style.
xiyuan 2016/07/12 21:50:21 Acknowledged.
364 run_at: 'document_end'
365 }]);
314 366
315 var isApprovalResponse = function(url) { 367 var isApprovalResponse = function(url) {
316 var resultUrlPrefix = 'https://accounts.google.com/o/oauth2/approval?'; 368 var resultUrlPrefix = 'https://accounts.google.com/o/oauth2/approval?';
317 return url.substring(0, resultUrlPrefix.length) == resultUrlPrefix; 369 return url.substring(0, resultUrlPrefix.length) == resultUrlPrefix;
318 }; 370 };
319 371
320 var lsoError = false; 372 var lsoError = false;
321 var onLsoViewRequestResponseStarted = function(details) { 373 var onLsoViewRequestResponseStarted = function(details) {
322 if (isApprovalResponse(details.url)) { 374 if (isApprovalResponse(details.url)) {
323 showPage('arc-loading'); 375 showPage('arc-loading');
324 } 376 }
325 lsoError = false; 377 lsoError = false;
326 }; 378 };
327 379
328 var onLsoViewErrorOccurred = function(details) { 380 var onLsoViewErrorOccurred = function(details) {
329 setErrorMessage(appWindow.contentWindow.loadTimeData.getString( 381 setErrorMessage(appWindow.contentWindow.loadTimeData.getString(
330 'serverError')); 382 'serverError'));
331 showPage('error'); 383 showPage('error');
332 lsoError = true; 384 lsoError = true;
333 }; 385 };
334 386
335 var onLsoViewContentLoad = function() { 387 var onLsoViewContentLoad = function() {
336 if (lsoError) { 388 if (lsoError) {
337 return; 389 return;
338 } 390 }
339 391
340 if (!isApprovalResponse(lsoView.src)) { 392 if (!isApprovalResponse(lsoView.src)) {
341 // Show LSO page when its content is ready. 393 // Show LSO page when its content is ready.
342 showPage('lso'); 394 showPage('lso');
395 // We have fixed width for LSO page in css file in order to prevent
396 // unwanted webview resize animation when it is shown first time. Now
397 // it safe to make it up to window width.
398 lsoView.style.width = '100%';
khmel 2016/07/12 21:15:37 Again workaround for webview 'animation'. Fixed wi
xiyuan 2016/07/12 21:50:21 Acknowledged.
343 return; 399 return;
344 } 400 }
345 401
346 lsoView.executeScript({code: 'document.title;'}, function(results) { 402 lsoView.executeScript({code: 'document.title;'}, function(results) {
347 var authCodePrefix = 'Success code='; 403 var authCodePrefix = 'Success code=';
348 if (results && results.length == 1 && typeof results[0] == 'string' && 404 if (results && results.length == 1 && typeof results[0] == 'string' &&
349 results[0].substring(0, authCodePrefix.length) == authCodePrefix) { 405 results[0].substring(0, authCodePrefix.length) == authCodePrefix) {
350 var authCode = results[0].substring(authCodePrefix.length); 406 var authCode = results[0].substring(authCodePrefix.length);
351 sendNativeMessage('setAuthCode', {code: authCode}); 407 sendNativeMessage('setAuthCode', {code: authCode});
352 } else { 408 } else {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 doc.getElementById('button-send-feedback') 506 doc.getElementById('button-send-feedback')
451 .addEventListener('click', onSendFeedback); 507 .addEventListener('click', onSendFeedback);
452 508
453 connectPort(); 509 connectPort();
454 }; 510 };
455 511
456 var onWindowCreated = function(createdWindow) { 512 var onWindowCreated = function(createdWindow) {
457 appWindow = createdWindow; 513 appWindow = createdWindow;
458 appWindow.contentWindow.onload = onAppContentLoad; 514 appWindow.contentWindow.onload = onAppContentLoad;
459 createdWindow.onClosed.addListener(onWindowClosed); 515 createdWindow.onClosed.addListener(onWindowClosed);
516
517 setWindowBounds();
khmel 2016/07/12 21:15:37 Chrome keeps window previous position. We need res
xiyuan 2016/07/12 21:50:21 Acknowledged.
460 }; 518 };
461 519
462 var onWindowClosed = function() { 520 var onWindowClosed = function() {
463 if (termsReloadTimeout) { 521 if (termsReloadTimeout) {
464 clearTimeout(termsReloadTimeout); 522 clearTimeout(termsReloadTimeout);
465 termsReloadTimeout = null; 523 termsReloadTimeout = null;
466 } 524 }
467 525
468 if (windowClosedInternally) { 526 if (windowClosedInternally) {
469 return; 527 return;
470 } 528 }
471 sendNativeMessage('cancelAuthCode'); 529 sendNativeMessage('cancelAuthCode');
472 }; 530 };
473 531
474 windowClosedInternally = false; 532 windowClosedInternally = false;
533
475 var options = { 534 var options = {
476 'id': 'play_store_wnd', 535 'id': 'play_store_wnd',
477 'resizable': false, 536 'resizable': false,
478 'hidden': true, 537 'hidden': true,
479 'frame': { 538 'frame': {
480 type: 'chrome', 539 type: 'chrome',
481 color: '#ffffff' 540 color: '#ffffff'
482 }, 541 },
483 'innerBounds': { 542 'innerBounds': {
484 'width': 960, 543 'width': innerWidth,
485 'height': 688 544 'height': innerHeight
486 } 545 }
487 }; 546 };
488 chrome.app.window.create('main.html', options, onWindowCreated); 547 chrome.app.window.create('main.html', options, onWindowCreated);
489 }); 548 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698