| OLD | NEW |
| 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', |
| 11 'terms-loading', | |
| 12 'terms', | 11 'terms', |
| 13 'lso-loading', | 12 'lso-loading', |
| 14 'lso', | 13 'lso', |
| 15 'arc-loading', | 14 'arc-loading', |
| 16 'error', | 15 'error', |
| 17 'error-with-feedback']; | 16 'error-with-feedback']; |
| 18 | 17 |
| 19 /** | 18 /** |
| 20 * Chrome window that hosts UI. Only one window is allowed. | 19 * Chrome window that hosts UI. Only one window is allowed. |
| 21 * @type {chrome.app.window.AppWindow} | 20 * @type {chrome.app.window.AppWindow} |
| 22 */ | 21 */ |
| 23 var appWindow = null; | 22 var appWindow = null; |
| 24 | 23 |
| 25 /** | 24 /** |
| 26 * Contains Web content provided by Google authorization server. | 25 * Contains Web content provided by Google authorization server. |
| 27 * @type {WebView} | 26 * @type {WebView} |
| 28 */ | 27 */ |
| 29 var lsoView = null; | 28 var lsoView = null; |
| 30 | 29 |
| 31 /** | 30 /** @type {TermsOfServicePage} */ |
| 32 * Contains Play Store terms, loaded externally. | 31 var termsPage = null; |
| 33 * @type {WebView} | |
| 34 */ | |
| 35 var termsView = null; | |
| 36 | |
| 37 /** | |
| 38 * @type {MetricsPreferenceCheckbox} | |
| 39 */ | |
| 40 var metricsCheckbox = null; | |
| 41 | |
| 42 /** | |
| 43 * @type {PreferenceCheckbox} | |
| 44 */ | |
| 45 var backupRestoreCheckbox = null; | |
| 46 | |
| 47 /** | |
| 48 * @type {PreferenceCheckbox} | |
| 49 */ | |
| 50 var locationServiceCheckbox = null; | |
| 51 | 32 |
| 52 /** | 33 /** |
| 53 * Used for bidirectional communication with native code. | 34 * Used for bidirectional communication with native code. |
| 54 * @type {chrome.runtime.Port} | 35 * @type {chrome.runtime.Port} |
| 55 */ | 36 */ |
| 56 var port = null; | 37 var port = null; |
| 57 | 38 |
| 58 /** | 39 /** |
| 59 * Stores current device id. | 40 * Stores current device id. |
| 60 * @type {string} | 41 * @type {string} |
| 61 */ | 42 */ |
| 62 var currentDeviceId = null; | 43 var currentDeviceId = null; |
| 63 | 44 |
| 64 /** | 45 /** |
| 65 * Indicates that terms were accepted by user. | 46 * Indicates that terms were accepted by user. |
| 66 * @type {boolean} | 47 * @type {boolean} |
| 48 * TODO: This should be a part of TermsOfServicePage. |
| 67 */ | 49 */ |
| 68 var termsAccepted = false; | 50 var termsAccepted = false; |
| 69 | 51 |
| 70 /** | 52 /** |
| 71 * Indicates that current user has managed Arc. | |
| 72 * @type {boolean} | |
| 73 */ | |
| 74 var arcManaged = false; | |
| 75 | |
| 76 /** | |
| 77 * Host window inner default width. | 53 * Host window inner default width. |
| 78 * @const {number} | 54 * @const {number} |
| 79 */ | 55 */ |
| 80 var INNER_WIDTH = 960; | 56 var INNER_WIDTH = 960; |
| 81 | 57 |
| 82 /** | 58 /** |
| 83 * Host window inner default height. | 59 * Host window inner default height. |
| 84 * @const {number} | 60 * @const {number} |
| 85 */ | 61 */ |
| 86 var INNER_HEIGHT = 688; | 62 var INNER_HEIGHT = 688; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 // tags are not the target of the translation (but those content text is | 188 // tags are not the target of the translation (but those content text is |
| 213 // the translation target). | 189 // the translation target). |
| 214 // So, meanwhile, we set the link everytime we update the text. | 190 // So, meanwhile, we set the link everytime we update the text. |
| 215 // TODO: fix the translation text, and main html. | 191 // TODO: fix the translation text, and main html. |
| 216 var learnMoreLink = this.label_.querySelector(this.learnMoreLinkId_); | 192 var learnMoreLink = this.label_.querySelector(this.learnMoreLinkId_); |
| 217 learnMoreLink.addEventListener( | 193 learnMoreLink.addEventListener( |
| 218 'click', (event) => this.onLearnMoreLinkClicked(event)); | 194 'click', (event) => this.onLearnMoreLinkClicked(event)); |
| 219 var settingsLink = this.label_.querySelector('#settings-link'); | 195 var settingsLink = this.label_.querySelector('#settings-link'); |
| 220 settingsLink.addEventListener( | 196 settingsLink.addEventListener( |
| 221 'click', (event) => this.onSettingsLinkClicked(event)); | 197 'click', (event) => this.onSettingsLinkClicked(event)); |
| 222 | |
| 223 // Applying metrics mode changes page layout, update terms height. | |
| 224 updateTermsHeight(); | |
| 225 } | 198 } |
| 226 | 199 |
| 227 /** Called when "settings" link is clicked. */ | 200 /** Called when "settings" link is clicked. */ |
| 228 onSettingsLinkClicked(event) { | 201 onSettingsLinkClicked(event) { |
| 229 chrome.browser.openTab({'url': 'chrome://settings'}, function() {}); | 202 chrome.browser.openTab({'url': 'chrome://settings'}, function() {}); |
| 230 event.preventDefault(); | 203 event.preventDefault(); |
| 231 } | 204 } |
| 232 }; | 205 }; |
| 233 | 206 |
| 207 /** |
| 208 * Represents the page loading state. |
| 209 * @enum {number} |
| 210 */ |
| 211 var LoadState = { |
| 212 UNLOADED: 0, |
| 213 LOADING: 1, |
| 214 ABORTED: 2, |
| 215 LOADED: 3, |
| 216 }; |
| 234 | 217 |
| 235 /** | 218 /** |
| 236 * Applies localization for html content and sets terms webview. | 219 * Handles events for Terms-Of-Service page. Also this implements the async |
| 237 * @param {!Object} data Localized strings and relevant information. | 220 * loading of Terms-Of-Service content. |
| 238 * @param {string} deviceId Current device id. | |
| 239 */ | 221 */ |
| 240 function initialize(data, deviceId) { | 222 class TermsOfServicePage { |
| 241 currentDeviceId = deviceId; | |
| 242 var doc = appWindow.contentWindow.document; | |
| 243 var loadTimeData = appWindow.contentWindow.loadTimeData; | |
| 244 loadTimeData.data = data; | |
| 245 appWindow.contentWindow.i18nTemplate.process(doc, loadTimeData); | |
| 246 | 223 |
| 247 // Initialize preference connected checkboxes in terms of service page. | 224 /** |
| 248 metricsCheckbox = new MetricsPreferenceCheckbox( | 225 * @param {Element} container The container of the page. |
| 249 doc.getElementById('metrics-preference'), | 226 * @param {boolean} isManaged Set true if ARC is managed. |
| 250 data.learnMoreStatistics, | 227 * @param {string} countryCode The country code for the terms of service. |
| 251 '#learn-more-link-metrics', | 228 * @param {MetricsPreferenceCheckbox} metricsCheckbox. The checkbox for the |
| 252 data.isOwnerProfile, | 229 * metrics preference. |
| 253 data.textMetricsDisabled, | 230 * @param {PreferenceCheckbox} backupRestoreCheckbox The checkbox for the |
| 254 data.textMetricsEnabled, | 231 * backup-restore preference. |
| 255 data.textMetricsManagedDisabled, | 232 * @param {PreferenceCheckbox} locationServiceCheckbox The checkbox for the |
| 256 data.textMetricsManagedEnabled); | 233 * location service. |
| 257 backupRestoreCheckbox = new PreferenceCheckbox( | 234 */ |
| 258 doc.getElementById('backup-restore-preference'), | 235 constructor( |
| 259 data.learnMoreBackupAndRestore, | 236 container, isManaged, countryCode, |
| 260 '#learn-more-link-backup-restore', | 237 metricsCheckbox, backupRestoreCheckbox, locationServiceCheckbox) { |
| 261 data.controlledByPolicy); | 238 this.loadingContainer_ = |
| 262 locationServiceCheckbox = new PreferenceCheckbox( | 239 container.querySelector('#terms-of-service-loading'); |
| 263 doc.getElementById('location-service-preference'), | 240 this.contentContainer_ = |
| 264 data.learnMoreLocationServices, | 241 container.querySelector('#terms-of-service-content'); |
| 265 '#learn-more-link-location-service', | |
| 266 data.controlledByPolicy); | |
| 267 | 242 |
| 268 // Initialize terms of service view. | 243 this.metricsCheckbox_ = metricsCheckbox; |
| 269 var countryCode = data.countryCode.toLowerCase(); | 244 this.backupRestoreCheckbox_ = backupRestoreCheckbox; |
| 270 var scriptSetCountryCode = 'document.countryCode = \'' + countryCode + '\';'; | 245 this.locationServiceCheckbox_ = locationServiceCheckbox; |
| 271 termsView.addContentScripts([ | 246 |
| 247 this.isManaged_ = isManaged; |
| 248 |
| 249 // Set event listener for webview loading. |
| 250 this.termsView_ = container.querySelector('#terms-view'); |
| 251 this.termsView_.addEventListener( |
| 252 'loadstart', () => this.onTermsViewLoadStarted_()); |
| 253 this.termsView_.addEventListener( |
| 254 'contentload', () => this.onTermsViewLoaded_()); |
| 255 this.termsView_.addEventListener( |
| 256 'loadabort', (event) => this.onTermsViewLoadAborted_(event.reason)); |
| 257 |
| 258 var scriptSetCountryCode = |
| 259 'document.countryCode = \'' + countryCode.toLowerCase() + '\';'; |
| 260 this.termsView_.addContentScripts([ |
| 272 { name: 'preProcess', | 261 { name: 'preProcess', |
| 273 matches: ['https://play.google.com/*'], | 262 matches: ['https://play.google.com/*'], |
| 274 js: { code: scriptSetCountryCode }, | 263 js: { code: scriptSetCountryCode }, |
| 275 run_at: 'document_start' | 264 run_at: 'document_start' |
| 276 }, | 265 }, |
| 277 { name: 'postProcess', | 266 { name: 'postProcess', |
| 278 matches: ['https://play.google.com/*'], | 267 matches: ['https://play.google.com/*'], |
| 279 css: { files: ['playstore.css'] }, | 268 css: { files: ['playstore.css'] }, |
| 280 js: { files: ['playstore.js'] }, | 269 js: { files: ['playstore.js'] }, |
| 281 run_at: 'document_end' | 270 run_at: 'document_end' |
| 282 }]); | 271 }]); |
| 283 arcManaged = data.arcManaged; | 272 |
| 284 setTermsVisible(!arcManaged); | 273 // webview is not allowed to open links in the new window. Hook these |
| 274 // events and open links in overlay dialog. |
| 275 this.termsView_.addEventListener('newwindow', function(event) { |
| 276 event.preventDefault(); |
| 277 showURLOverlay(event.targetUrl); |
| 278 }); |
| 279 this.state_ = LoadState.UNLOADED; |
| 280 |
| 281 // On managed case, do not show TermsOfService section. Note that the |
| 282 // checkbox for the prefereces are still visible. |
| 283 var visibility = isManaged ? 'hidden' : 'visible'; |
| 284 container.querySelector('#terms-title').style.visibility = visibility; |
| 285 container.querySelector('#terms-container').style.visibility = visibility; |
| 286 |
| 287 // Set event handler for buttons. |
| 288 container.querySelector('#button-agree') |
| 289 .addEventListener('click', () => this.onAgree()); |
| 290 container.querySelector('#button-cancel') |
| 291 .addEventListener('click', () => this.onCancel_()); |
| 292 } |
| 293 |
| 294 /** Called when the TermsOfService page is shown. */ |
| 295 onShow() { |
| 296 termsAccepted = false; |
| 297 |
| 298 if (this.isManaged_ || this.state_ == LoadState.LOADED) { |
| 299 // Note: in managed case, because it does not show the contents of terms |
| 300 // of service, it is ok to show the content container immediately. |
| 301 this.showContent_(); |
| 302 } else { |
| 303 this.startTermsViewLoading_(); |
| 304 } |
| 305 } |
| 306 |
| 307 /** Shows the loaded terms-of-service content. */ |
| 308 showContent_() { |
| 309 this.loadingContainer_.hidden = true; |
| 310 this.contentContainer_.hidden = false; |
| 311 this.updateTermsHeight_(); |
| 312 } |
| 313 |
| 314 /** |
| 315 * Updates terms view height manually because webview is not automatically |
| 316 * resized in case parent div element gets resized. |
| 317 */ |
| 318 updateTermsHeight_() { |
| 319 // Update the height in next cycle to prevent webview animation and |
| 320 // wrong layout caused by whole-page layout change. |
| 321 setTimeout(function() { |
| 322 var doc = appWindow.contentWindow.document; |
| 323 // Reset terms-view height in order to stabilize style computation. For |
| 324 // some reason, child webview affects final result. |
| 325 this.termsView_.style.height = '0px'; |
| 326 var termsContainer = |
| 327 this.contentContainer_.querySelector('#terms-container'); |
| 328 var style = window.getComputedStyle(termsContainer, null); |
| 329 this.termsView_.style.height = style.getPropertyValue('height'); |
| 330 }.bind(this), 0); |
| 331 } |
| 332 |
| 333 /** Starts to load the terms of service webview content. */ |
| 334 startTermsViewLoading_() { |
| 335 if (this.state_ == LoadState.LOADING) { |
| 336 // If there already is inflight loading task, do nothing. |
| 337 return; |
| 338 } |
| 339 this.termsView_.src = 'https://play.google.com/about/play-terms.html'; |
| 340 } |
| 341 |
| 342 /** Called when the terms-view starts to be loaded. */ |
| 343 onTermsViewLoadStarted_() { |
| 344 // Note: Reloading can be triggered by user action. E.g., user may select |
| 345 // their language by selection at the bottom of the Terms Of Service |
| 346 // content. |
| 347 this.state_ = LoadState.LOADING; |
| 348 // Show loading page. |
| 349 this.loadingContainer_.hidden = false; |
| 350 this.contentContainer_.hidden = true; |
| 351 } |
| 352 |
| 353 /** Called when the terms-view is loaded. */ |
| 354 onTermsViewLoaded_() { |
| 355 // This is called also when the loading is failed. |
| 356 // In such a case, onTermsViewLoadAborted_() is called in advance, and |
| 357 // state_ is set to ABORTED. Here, switch the view only for the |
| 358 // successful loading case. |
| 359 if (this.state_ == LoadState.LOADING) { |
| 360 this.state_ = LoadState.LOADED; |
| 361 this.showContent_(); |
| 362 } |
| 363 } |
| 364 |
| 365 /** Called when the terms-view loading is aborted. */ |
| 366 onTermsViewLoadAborted_(reason) { |
| 367 console.error('TermsView loading is aborted: ' + reason); |
| 368 // Mark ABORTED so that onTermsViewLoaded_() won't show the content view. |
| 369 this.state_ = LoadState.ABORTED; |
| 370 setErrorMessage( |
| 371 appWindow.contentWindow.loadTimeData.getString('serverError')); |
| 372 showPage('error'); |
| 373 } |
| 374 |
| 375 /** Called when "AGREE" button is clicked. */ |
| 376 onAgree() { |
| 377 termsAccepted = true; |
| 378 |
| 379 sendNativeMessage('onAgreed', { |
| 380 isMetricsEnabled: this.metricsCheckbox_.isChecked(), |
| 381 isBackupRestoreEnabled: this.backupRestoreCheckbox_.isChecked(), |
| 382 isLocationServiceEnabled: this.locationServiceCheckbox_.isChecked() |
| 383 }); |
| 384 } |
| 385 |
| 386 /** Called when "CANCEL" button is clicked. */ |
| 387 onCancel_() { |
| 388 if (appWindow) { |
| 389 appWindow.close(); |
| 390 } |
| 391 } |
| 392 |
| 393 /** Called when metrics preference is updated. */ |
| 394 onMetricxPreferenceChanged(isEnabled, isManaged) { |
| 395 this.metricsCheckbox_.onPreferenceChanged(isEnabled, isManaged); |
| 396 |
| 397 // Applying metrics mode may change page layout, update terms height. |
| 398 this.updateTermsHeight_(); |
| 399 } |
| 400 |
| 401 /** Called when backup-restore preference is updated. */ |
| 402 onBackupRestorePreferenceChanged(isEnabled, isManaged) { |
| 403 this.backupRestoreCheckbox_.onPreferenceChanged(isEnabled, isManaged); |
| 404 } |
| 405 |
| 406 /** Called when location service preference is updated. */ |
| 407 onLocationServicePreferenceChanged(isEnabled, isManaged) { |
| 408 this.locationServiceCheckbox_.onPreferenceChanged(isEnabled, isManaged); |
| 409 } |
| 410 }; |
| 411 |
| 412 /** |
| 413 * Applies localization for html content and sets terms webview. |
| 414 * @param {!Object} data Localized strings and relevant information. |
| 415 * @param {string} deviceId Current device id. |
| 416 */ |
| 417 function initialize(data, deviceId) { |
| 418 currentDeviceId = deviceId; |
| 419 var doc = appWindow.contentWindow.document; |
| 420 var loadTimeData = appWindow.contentWindow.loadTimeData; |
| 421 loadTimeData.data = data; |
| 422 appWindow.contentWindow.i18nTemplate.process(doc, loadTimeData); |
| 423 |
| 424 // Initialize preference connected checkboxes in terms of service page. |
| 425 termsPage = new TermsOfServicePage( |
| 426 doc.getElementById('terms'), |
| 427 data.arcManaged, |
| 428 data.countryCode, |
| 429 new MetricsPreferenceCheckbox( |
| 430 doc.getElementById('metrics-preference'), |
| 431 data.learnMoreStatistics, |
| 432 '#learn-more-link-metrics', |
| 433 data.isOwnerProfile, |
| 434 data.textMetricsDisabled, |
| 435 data.textMetricsEnabled, |
| 436 data.textMetricsManagedDisabled, |
| 437 data.textMetricsManagedEnabled), |
| 438 new PreferenceCheckbox( |
| 439 doc.getElementById('backup-restore-preference'), |
| 440 data.learnMoreBackupAndRestore, |
| 441 '#learn-more-link-backup-restore', |
| 442 data.controlledByPolicy), |
| 443 new PreferenceCheckbox( |
| 444 doc.getElementById('location-service-preference'), |
| 445 data.learnMoreLocationServices, |
| 446 '#learn-more-link-location-service', |
| 447 data.controlledByPolicy)); |
| 285 } | 448 } |
| 286 | 449 |
| 287 /** | 450 /** |
| 288 * Sets visibility of Terms of Service. | |
| 289 * @param {boolean} visible Whether the Terms of Service visible or not. | |
| 290 */ | |
| 291 function setTermsVisible(visible) { | |
| 292 var doc = appWindow.contentWindow.document; | |
| 293 var styleVisibility = visible ? 'visible' : 'hidden'; | |
| 294 doc.getElementById('terms-title').style.visibility = styleVisibility; | |
| 295 doc.getElementById('terms-container').style.visibility = styleVisibility; | |
| 296 } | |
| 297 | |
| 298 /** | |
| 299 * Updates terms view height manually because webview is not automatically | |
| 300 * resized in case parent div element gets resized. | |
| 301 */ | |
| 302 function updateTermsHeight() { | |
| 303 var setTermsHeight = function() { | |
| 304 var doc = appWindow.contentWindow.document; | |
| 305 var termsContainer = doc.getElementById('terms-container'); | |
| 306 // Reset terms-view height in order to stabilize style computation. For | |
| 307 // some reason, child webview affects final result. | |
| 308 termsView.style.height = '0px'; | |
| 309 var style = window.getComputedStyle(termsContainer, null); | |
| 310 var height = style.getPropertyValue('height'); | |
| 311 termsView.style.height = height; | |
| 312 }; | |
| 313 setTimeout(setTermsHeight, 0); | |
| 314 } | |
| 315 | |
| 316 /** | |
| 317 * Handles native messages received from ArcSupportHost. | 451 * Handles native messages received from ArcSupportHost. |
| 318 * @param {!Object} message The message received. | 452 * @param {!Object} message The message received. |
| 319 */ | 453 */ |
| 320 function onNativeMessage(message) { | 454 function onNativeMessage(message) { |
| 321 if (!message.action) { | 455 if (!message.action) { |
| 322 return; | 456 return; |
| 323 } | 457 } |
| 324 | 458 |
| 325 if (!appWindow) { | 459 if (!appWindow) { |
| 326 console.warn('Received native message when window is not available.'); | 460 console.warn('Received native message when window is not available.'); |
| 327 return; | 461 return; |
| 328 } | 462 } |
| 329 | 463 |
| 330 if (message.action == 'initialize') { | 464 if (message.action == 'initialize') { |
| 331 initialize(message.data, message.deviceId); | 465 initialize(message.data, message.deviceId); |
| 332 } else if (message.action == 'setMetricsMode') { | 466 } else if (message.action == 'setMetricsMode') { |
| 333 metricsCheckbox.onPreferenceChanged(message.enabled, message.managed); | 467 termsPage.onMetricxPreferenceChanged(message.enabled, message.managed); |
| 334 } else if (message.action == 'setBackupAndRestoreMode') { | 468 } else if (message.action == 'setBackupAndRestoreMode') { |
| 335 backupRestoreCheckbox.onPreferenceChanged(message.enabled, message.managed); | 469 termsPage.onBackupRestorePreferenceChanged( |
| 470 message.enabled, message.managed); |
| 336 } else if (message.action == 'setLocationServiceMode') { | 471 } else if (message.action == 'setLocationServiceMode') { |
| 337 locationServiceCheckbox.onPreferenceChanged( | 472 termsPage.onLocationServicePreferenceChanged( |
| 338 message.enabled, message.managed); | 473 message.enabled, message.managed); |
| 339 } else if (message.action == 'closeWindow') { | 474 } else if (message.action == 'closeWindow') { |
| 340 if (appWindow) { | 475 if (appWindow) { |
| 341 appWindow.close(); | 476 appWindow.close(); |
| 342 } | 477 } |
| 343 } else if (message.action == 'showPage') { | 478 } else if (message.action == 'showPage') { |
| 344 showPageWithStatus(message.page, message.status); | 479 showPageWithStatus(message.page, message.status); |
| 345 } else if (message.action == 'setWindowBounds') { | 480 } else if (message.action == 'setWindowBounds') { |
| 346 setWindowBounds(); | 481 setWindowBounds(); |
| 347 } | 482 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 if (pageDivId == 'lso-loading') { | 519 if (pageDivId == 'lso-loading') { |
| 385 lsoView.src = 'https://accounts.google.com/o/oauth2/v2/auth?client_id=' + | 520 lsoView.src = 'https://accounts.google.com/o/oauth2/v2/auth?client_id=' + |
| 386 '1070009224336-sdh77n7uot3oc99ais00jmuft6sk2fg9.apps.' + | 521 '1070009224336-sdh77n7uot3oc99ais00jmuft6sk2fg9.apps.' + |
| 387 'googleusercontent.com&response_type=code&redirect_uri=oob&' + | 522 'googleusercontent.com&response_type=code&redirect_uri=oob&' + |
| 388 'scope=https://www.google.com/accounts/OAuthLogin&' + | 523 'scope=https://www.google.com/accounts/OAuthLogin&' + |
| 389 'device_type=arc_plus_plus&device_id=' + currentDeviceId + | 524 'device_type=arc_plus_plus&device_id=' + currentDeviceId + |
| 390 '&hl=' + navigator.language; | 525 '&hl=' + navigator.language; |
| 391 } | 526 } |
| 392 appWindow.show(); | 527 appWindow.show(); |
| 393 if (pageDivId == 'terms') { | 528 if (pageDivId == 'terms') { |
| 394 updateTermsHeight(); | 529 termsPage.onShow(); |
| 395 } | 530 } |
| 396 } | 531 } |
| 397 | 532 |
| 398 /** | 533 /** |
| 399 * Sets error message. | 534 * Sets error message. |
| 400 * @param {string} error message. | 535 * @param {string} error message. |
| 401 */ | 536 */ |
| 402 function setErrorMessage(error) { | 537 function setErrorMessage(error) { |
| 403 if (!appWindow) { | 538 if (!appWindow) { |
| 404 return; | 539 return; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 * @param {int} pageId Index of the page to show. Must be in the array range of | 606 * @param {int} pageId Index of the page to show. Must be in the array range of |
| 472 * UI_PAGES. | 607 * UI_PAGES. |
| 473 * @param {string} status associated with page string status, error message for | 608 * @param {string} status associated with page string status, error message for |
| 474 * example. | 609 * example. |
| 475 */ | 610 */ |
| 476 function showPageWithStatus(pageId, status) { | 611 function showPageWithStatus(pageId, status) { |
| 477 if (!appWindow) { | 612 if (!appWindow) { |
| 478 return; | 613 return; |
| 479 } | 614 } |
| 480 | 615 |
| 481 if (UI_PAGES[pageId] == 'terms-loading') { | 616 if (UI_PAGES[pageId] != 'terms') { |
| 482 termsAccepted = arcManaged; | |
| 483 if (termsAccepted) { | |
| 484 showPage('terms'); | |
| 485 return; | |
| 486 } | |
| 487 loadInitialTerms(); | |
| 488 } else { | |
| 489 // Explicit request to start not from start page. Assume terms are | 617 // Explicit request to start not from start page. Assume terms are |
| 490 // accepted in this case. | 618 // accepted in this case. |
| 619 // TODO: this is only for controling "RETRY" button. Remove this. |
| 491 termsAccepted = true; | 620 termsAccepted = true; |
| 492 } | 621 } |
| 493 | 622 |
| 494 if (UI_PAGES[pageId] == 'error' || | 623 if (UI_PAGES[pageId] == 'error' || |
| 495 UI_PAGES[pageId] == 'error-with-feedback') { | 624 UI_PAGES[pageId] == 'error-with-feedback') { |
| 496 setErrorMessage(status); | 625 setErrorMessage(status); |
| 497 } | 626 } |
| 498 showPage(UI_PAGES[pageId]); | 627 showPage(UI_PAGES[pageId]); |
| 499 } | 628 } |
| 500 | 629 |
| 501 /** | |
| 502 * Loads initial Play Store terms. | |
| 503 */ | |
| 504 function loadInitialTerms() { | |
| 505 termsView.src = 'https://play.google.com/about/play-terms.html'; | |
| 506 } | |
| 507 | |
| 508 function setWindowBounds() { | 630 function setWindowBounds() { |
| 509 if (!appWindow) { | 631 if (!appWindow) { |
| 510 return; | 632 return; |
| 511 } | 633 } |
| 512 | 634 |
| 513 var decorationWidth = appWindow.outerBounds.width - | 635 var decorationWidth = appWindow.outerBounds.width - |
| 514 appWindow.innerBounds.width; | 636 appWindow.innerBounds.width; |
| 515 var decorationHeight = appWindow.outerBounds.height - | 637 var decorationHeight = appWindow.outerBounds.height - |
| 516 appWindow.innerBounds.height; | 638 appWindow.innerBounds.height; |
| 517 | 639 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 urls: ['<all_urls>'], | 721 urls: ['<all_urls>'], |
| 600 types: ['main_frame'] | 722 types: ['main_frame'] |
| 601 }; | 723 }; |
| 602 | 724 |
| 603 lsoView.request.onResponseStarted.addListener( | 725 lsoView.request.onResponseStarted.addListener( |
| 604 onLsoViewRequestResponseStarted, requestFilter); | 726 onLsoViewRequestResponseStarted, requestFilter); |
| 605 lsoView.request.onErrorOccurred.addListener( | 727 lsoView.request.onErrorOccurred.addListener( |
| 606 onLsoViewErrorOccurred, requestFilter); | 728 onLsoViewErrorOccurred, requestFilter); |
| 607 lsoView.addEventListener('contentload', onLsoViewContentLoad); | 729 lsoView.addEventListener('contentload', onLsoViewContentLoad); |
| 608 | 730 |
| 609 termsView = doc.getElementById('terms-view'); | |
| 610 | |
| 611 var termsError = false; | |
| 612 var onTermsViewBeforeRequest = function(details) { | |
| 613 showPage('terms-loading'); | |
| 614 termsError = false; | |
| 615 }; | |
| 616 | |
| 617 var onTermsViewErrorOccurred = function(details) { | |
| 618 termsAccepted = false; | |
| 619 setErrorMessage(appWindow.contentWindow.loadTimeData.getString( | |
| 620 'serverError')); | |
| 621 showPage('error'); | |
| 622 termsError = true; | |
| 623 }; | |
| 624 | |
| 625 var onTermsViewContentLoad = function() { | |
| 626 if (termsError) { | |
| 627 return; | |
| 628 } | |
| 629 showPage('terms'); | |
| 630 }; | |
| 631 | |
| 632 termsView.request.onBeforeRequest.addListener(onTermsViewBeforeRequest, | |
| 633 requestFilter); | |
| 634 termsView.request.onErrorOccurred.addListener(onTermsViewErrorOccurred, | |
| 635 requestFilter); | |
| 636 termsView.addEventListener('contentload', onTermsViewContentLoad); | |
| 637 | |
| 638 | |
| 639 // webview is not allowed to open links in the new window. Hook these events | |
| 640 // and open links in overlay dialog. | |
| 641 termsView.addEventListener('newwindow', function(event) { | |
| 642 event.preventDefault(); | |
| 643 showURLOverlay(event.targetUrl); | |
| 644 }); | |
| 645 | |
| 646 var onAgree = function() { | |
| 647 termsAccepted = true; | |
| 648 | |
| 649 sendNativeMessage('onAgreed', { | |
| 650 isMetricsEnabled: metricsCheckbox.isChecked(), | |
| 651 isBackupRestoreEnabled: backupRestoreCheckbox.isChecked(), | |
| 652 isLocationServiceEnabled: locationServiceCheckbox.isChecked() | |
| 653 }); | |
| 654 }; | |
| 655 | |
| 656 var onCancel = function() { | |
| 657 if (appWindow) { | |
| 658 appWindow.close(); | |
| 659 } | |
| 660 }; | |
| 661 | |
| 662 var onRetry = function() { | 731 var onRetry = function() { |
| 663 if (termsAccepted) { | 732 if (termsAccepted) { |
| 664 // Reuse the onAgree() in case that the user has already accepted | 733 // Reuse the onAgree() in case that the user has already accepted |
| 665 // the ToS. | 734 // the ToS. |
| 666 onAgree(); | 735 termsPage.onAgree(); |
| 667 } else { | 736 } else { |
| 668 loadInitialTerms(); | 737 // Here 'error' page should be visible. So switch to 'terms' page |
| 738 // to show the progress page, which triggers reloading. |
| 739 showPage('terms'); |
| 669 } | 740 } |
| 670 }; | 741 }; |
| 671 | 742 |
| 672 var onSendFeedback = function() { | 743 var onSendFeedback = function() { |
| 673 sendNativeMessage('onSendFeedbackClicked'); | 744 sendNativeMessage('onSendFeedbackClicked'); |
| 674 }; | 745 }; |
| 675 | 746 |
| 676 doc.getElementById('button-agree').addEventListener('click', onAgree); | |
| 677 doc.getElementById('button-cancel').addEventListener('click', onCancel); | |
| 678 doc.getElementById('button-retry').addEventListener('click', onRetry); | 747 doc.getElementById('button-retry').addEventListener('click', onRetry); |
| 679 doc.getElementById('button-send-feedback') | 748 doc.getElementById('button-send-feedback') |
| 680 .addEventListener('click', onSendFeedback); | 749 .addEventListener('click', onSendFeedback); |
| 681 doc.getElementById('overlay-close').addEventListener('click', hideOverlay); | 750 doc.getElementById('overlay-close').addEventListener('click', hideOverlay); |
| 682 doc.getElementById('privacy-policy-link').addEventListener( | 751 doc.getElementById('privacy-policy-link').addEventListener( |
| 683 'click', showPrivacyPolicyOverlay); | 752 'click', showPrivacyPolicyOverlay); |
| 684 | 753 |
| 685 var overlay = doc.getElementById('overlay-container'); | 754 var overlay = doc.getElementById('overlay-container'); |
| 686 appWindow.contentWindow.cr.ui.overlay.setupOverlay(overlay); | 755 appWindow.contentWindow.cr.ui.overlay.setupOverlay(overlay); |
| 687 appWindow.contentWindow.cr.ui.overlay.globalInitialization(); | 756 appWindow.contentWindow.cr.ui.overlay.globalInitialization(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 type: 'chrome', | 788 type: 'chrome', |
| 720 color: '#ffffff' | 789 color: '#ffffff' |
| 721 }, | 790 }, |
| 722 'innerBounds': { | 791 'innerBounds': { |
| 723 'width': INNER_WIDTH, | 792 'width': INNER_WIDTH, |
| 724 'height': INNER_HEIGHT | 793 'height': INNER_HEIGHT |
| 725 } | 794 } |
| 726 }; | 795 }; |
| 727 chrome.app.window.create('main.html', options, onWindowCreated); | 796 chrome.app.window.create('main.html', options, onWindowCreated); |
| 728 }); | 797 }); |
| OLD | NEW |