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

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: style changes 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 * @const {number}
71 */
72 var INNER_WIDTH = 960;
73
74 /**
75 * Host window inner default height.
76 * @const {number}
77 */
78 var INNER_HEIGHT = 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 showPage(UI_PAGES[pageId]); 315 showPage(UI_PAGES[pageId]);
301 } 316 }
302 317
303 /** 318 /**
304 * Loads initial Play Store terms. 319 * Loads initial Play Store terms.
305 */ 320 */
306 function loadInitialTerms() { 321 function loadInitialTerms() {
307 termsView.src = 'https://play.google.com/about/play-terms.html'; 322 termsView.src = 'https://play.google.com/about/play-terms.html';
308 } 323 }
309 324
325 function setWindowBounds() {
326 if (!appWindow) {
327 return;
328 }
329
330 var decorationWidth = appWindow.outerBounds.width -
331 appWindow.innerBounds.width;
332 var decorationHeight = appWindow.outerBounds.height -
333 appWindow.innerBounds.height;
334
335 var outerWidth = INNER_WIDTH + decorationWidth;
336 var outerHeight = INNER_HEIGHT + decorationHeight;
337 if (outerWidth > screen.availWidth) {
338 outerWidth = screen.availWidth;
339 }
340 if (outerHeight > screen.availHeight) {
341 outerHeight = screen.availHeight;
342 }
343 if (appWindow.outerBounds.width == outerWidth &&
344 appWindow.outerBounds.height == outerHeight) {
345 return;
346 }
347
348 appWindow.outerBounds.width = outerWidth;
349 appWindow.outerBounds.height = outerHeight;
350 appWindow.outerBounds.left = Math.ceil((screen.availWidth - outerWidth) / 2);
351 appWindow.outerBounds.top =
352 Math.ceil((screen.availHeight - outerHeight) / 2);
353 }
354
310 chrome.app.runtime.onLaunched.addListener(function() { 355 chrome.app.runtime.onLaunched.addListener(function() {
311 var onAppContentLoad = function() { 356 var onAppContentLoad = function() {
312 var doc = appWindow.contentWindow.document; 357 var doc = appWindow.contentWindow.document;
313 lsoView = doc.getElementById('arc-support'); 358 lsoView = doc.getElementById('arc-support');
359 lsoView.addContentScripts([
360 { name: 'postProcess',
361 matches: ['https://accounts.google.com/*'],
362 css: { files: ['lso.css'] },
363 run_at: 'document_end'
364 }]);
314 365
315 var isApprovalResponse = function(url) { 366 var isApprovalResponse = function(url) {
316 var resultUrlPrefix = 'https://accounts.google.com/o/oauth2/approval?'; 367 var resultUrlPrefix = 'https://accounts.google.com/o/oauth2/approval?';
317 return url.substring(0, resultUrlPrefix.length) == resultUrlPrefix; 368 return url.substring(0, resultUrlPrefix.length) == resultUrlPrefix;
318 }; 369 };
319 370
320 var lsoError = false; 371 var lsoError = false;
321 var onLsoViewRequestResponseStarted = function(details) { 372 var onLsoViewRequestResponseStarted = function(details) {
322 if (isApprovalResponse(details.url)) { 373 if (isApprovalResponse(details.url)) {
323 showPage('arc-loading'); 374 showPage('arc-loading');
324 } 375 }
325 lsoError = false; 376 lsoError = false;
326 }; 377 };
327 378
328 var onLsoViewErrorOccurred = function(details) { 379 var onLsoViewErrorOccurred = function(details) {
329 setErrorMessage(appWindow.contentWindow.loadTimeData.getString( 380 setErrorMessage(appWindow.contentWindow.loadTimeData.getString(
330 'serverError')); 381 'serverError'));
331 showPage('error'); 382 showPage('error');
332 lsoError = true; 383 lsoError = true;
333 }; 384 };
334 385
335 var onLsoViewContentLoad = function() { 386 var onLsoViewContentLoad = function() {
336 if (lsoError) { 387 if (lsoError) {
337 return; 388 return;
338 } 389 }
339 390
340 if (!isApprovalResponse(lsoView.src)) { 391 if (!isApprovalResponse(lsoView.src)) {
341 // Show LSO page when its content is ready. 392 // Show LSO page when its content is ready.
342 showPage('lso'); 393 showPage('lso');
394 // We have fixed width for LSO page in css file in order to prevent
395 // unwanted webview resize animation when it is shown first time. Now
396 // it safe to make it up to window width.
397 lsoView.style.width = '100%';
343 return; 398 return;
344 } 399 }
345 400
346 lsoView.executeScript({code: 'document.title;'}, function(results) { 401 lsoView.executeScript({code: 'document.title;'}, function(results) {
347 var authCodePrefix = 'Success code='; 402 var authCodePrefix = 'Success code=';
348 if (results && results.length == 1 && typeof results[0] == 'string' && 403 if (results && results.length == 1 && typeof results[0] == 'string' &&
349 results[0].substring(0, authCodePrefix.length) == authCodePrefix) { 404 results[0].substring(0, authCodePrefix.length) == authCodePrefix) {
350 var authCode = results[0].substring(authCodePrefix.length); 405 var authCode = results[0].substring(authCodePrefix.length);
351 sendNativeMessage('setAuthCode', {code: authCode}); 406 sendNativeMessage('setAuthCode', {code: authCode});
352 } else { 407 } else {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 doc.getElementById('button-send-feedback') 505 doc.getElementById('button-send-feedback')
451 .addEventListener('click', onSendFeedback); 506 .addEventListener('click', onSendFeedback);
452 507
453 connectPort(); 508 connectPort();
454 }; 509 };
455 510
456 var onWindowCreated = function(createdWindow) { 511 var onWindowCreated = function(createdWindow) {
457 appWindow = createdWindow; 512 appWindow = createdWindow;
458 appWindow.contentWindow.onload = onAppContentLoad; 513 appWindow.contentWindow.onload = onAppContentLoad;
459 createdWindow.onClosed.addListener(onWindowClosed); 514 createdWindow.onClosed.addListener(onWindowClosed);
515
516 setWindowBounds();
460 }; 517 };
461 518
462 var onWindowClosed = function() { 519 var onWindowClosed = function() {
463 if (termsReloadTimeout) { 520 if (termsReloadTimeout) {
464 clearTimeout(termsReloadTimeout); 521 clearTimeout(termsReloadTimeout);
465 termsReloadTimeout = null; 522 termsReloadTimeout = null;
466 } 523 }
467 524
468 if (windowClosedInternally) { 525 if (windowClosedInternally) {
469 return; 526 return;
470 } 527 }
471 sendNativeMessage('cancelAuthCode'); 528 sendNativeMessage('cancelAuthCode');
472 }; 529 };
473 530
474 windowClosedInternally = false; 531 windowClosedInternally = false;
532
475 var options = { 533 var options = {
476 'id': 'play_store_wnd', 534 'id': 'play_store_wnd',
477 'resizable': false, 535 'resizable': false,
478 'hidden': true, 536 'hidden': true,
479 'frame': { 537 'frame': {
480 type: 'chrome', 538 type: 'chrome',
481 color: '#ffffff' 539 color: '#ffffff'
482 }, 540 },
483 'innerBounds': { 541 'innerBounds': {
484 'width': 960, 542 'width': INNER_WIDTH,
485 'height': 688 543 'height': INNER_HEIGHT
486 } 544 }
487 }; 545 };
488 chrome.app.window.create('main.html', options, onWindowCreated); 546 chrome.app.window.create('main.html', options, onWindowCreated);
489 }); 547 });
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/arc/arc_support_host.cc ('k') | chrome/browser/resources/chromeos/arc_support/lso.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698