| 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 var vrShellUi = (function() { | 5 var vrShellUi = (function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 let ui = new scene.Scene(); | 8 let ui = new scene.Scene(); |
| 9 let uiManager; | 9 let uiManager; |
| 10 | 10 |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 | 281 |
| 282 onTransientTimer() { | 282 onTransientTimer() { |
| 283 let update = new api.UiElementUpdate(); | 283 let update = new api.UiElementUpdate(); |
| 284 update.setVisible(false); | 284 update.setVisible(false); |
| 285 ui.updateElement(this.transientWarning.uiElementId, update); | 285 ui.updateElement(this.transientWarning.uiElementId, update); |
| 286 this.secureOriginTimer = null; | 286 this.secureOriginTimer = null; |
| 287 ui.flush(); | 287 ui.flush(); |
| 288 } | 288 } |
| 289 }; | 289 }; |
| 290 | 290 |
| 291 class Omnibox { | 291 class UrlIndicator { |
| 292 constructor() { | 292 constructor() { |
| 293 this.domUiElement = new DomUiElement('#omnibox-container'); | 293 this.domUiElement = new DomUiElement('#url-indicator-container'); |
| 294 this.enabled = false; | 294 this.enabled = false; |
| 295 this.hidden = false; | 295 this.hidden = false; |
| 296 this.loading = false; | 296 this.loading = false; |
| 297 this.loadProgress = 0; | 297 this.loadProgress = 0; |
| 298 this.level = 0; | 298 this.level = 0; |
| 299 this.visibilityTimeout = 0; | 299 this.visibilityTimeout = 0; |
| 300 this.visibilityTimer = null; | 300 this.visibilityTimer = null; |
| 301 this.nativeState = {}; | 301 this.nativeState = {}; |
| 302 | 302 |
| 303 // Initially invisible. | 303 // Initially invisible. |
| 304 let update = new api.UiElementUpdate(); | 304 let update = new api.UiElementUpdate(); |
| 305 update.setVisible(false); | 305 update.setVisible(false); |
| 306 ui.updateElement(this.domUiElement.uiElementId, update); | 306 ui.updateElement(this.domUiElement.uiElementId, update); |
| 307 this.nativeState.visible = false; | 307 this.nativeState.visible = false; |
| 308 | 308 |
| 309 // Pull some CSS properties so that Javascript can reconfigure the omnibox | 309 // Pull some CSS properties so that Javascript can reconfigure the |
| 310 // programmatically. | 310 // indicator programmatically. |
| 311 let border = | 311 let border = |
| 312 this.domUiElement.domElement.querySelector('#omnibox-border'); | 312 this.domUiElement.domElement.querySelector('#url-indicator-border'); |
| 313 let style = window.getComputedStyle(border); | 313 let style = window.getComputedStyle(border); |
| 314 this.statusBarColor = getStyleString(style, '--statusBarColor'); | 314 this.statusBarColor = getStyleString(style, '--statusBarColor'); |
| 315 this.backgroundColor = style.backgroundColor; | 315 this.backgroundColor = style.backgroundColor; |
| 316 this.fadeTimeMs = getStyleFloat(style, '--fadeTimeMs'); | 316 this.fadeTimeMs = getStyleFloat(style, '--fadeTimeMs'); |
| 317 this.fadeYOffset = getStyleFloat(style, '--fadeYOffset'); | 317 this.fadeYOffset = getStyleFloat(style, '--fadeYOffset'); |
| 318 this.opacity = getStyleFloat(style, '--opacity'); | 318 this.opacity = getStyleFloat(style, '--opacity'); |
| 319 } | 319 } |
| 320 | 320 |
| 321 getSecurityIconElementId(level) { | 321 getSecurityIconElementId(level) { |
| 322 // See security_state.h and getSecurityIconResource() for this mapping. | 322 // See security_state.h and getSecurityIconResource() for this mapping. |
| 323 switch (level) { | 323 switch (level) { |
| 324 case 0: // NONE | 324 case 0: // NONE |
| 325 case 1: // HTTP_SHOW_WARNING | 325 case 1: // HTTP_SHOW_WARNING |
| 326 case 4: // SECURITY_WARNING | 326 case 4: // SECURITY_WARNING |
| 327 return '#omnibox-info-icon'; | 327 return '#url-indicator-info-icon'; |
| 328 case 2: // SECURE: | 328 case 2: // SECURE: |
| 329 case 3: // EV_SECURE: | 329 case 3: // EV_SECURE: |
| 330 return '#omnibox-lock-icon'; | 330 return '#url-indicator-lock-icon'; |
| 331 case 5: // SECURE_WITH_POLICY_INSTALLED_CERT (ChromeOS only) | 331 case 5: // SECURE_WITH_POLICY_INSTALLED_CERT (ChromeOS only) |
| 332 case 6: // DANGEROUS | 332 case 6: // DANGEROUS |
| 333 default: | 333 default: |
| 334 return '#omnibox-warning-icon'; | 334 return '#url-indicator-warning-icon'; |
| 335 } | 335 } |
| 336 } | 336 } |
| 337 | 337 |
| 338 setEnabled(enabled) { | 338 setEnabled(enabled) { |
| 339 this.enabled = enabled; | 339 this.enabled = enabled; |
| 340 this.resetVisibilityTimer(); | 340 this.resetVisibilityTimer(); |
| 341 this.updateState(); | 341 this.updateState(); |
| 342 } | 342 } |
| 343 | 343 |
| 344 setLoading(loading) { | 344 setLoading(loading) { |
| 345 this.loading = loading; | 345 this.loading = loading; |
| 346 this.loadProgress = 0; | 346 this.loadProgress = 0; |
| 347 this.resetVisibilityTimer(); | 347 this.resetVisibilityTimer(); |
| 348 this.updateState(); | 348 this.updateState(); |
| 349 } | 349 } |
| 350 | 350 |
| 351 setLoadProgress(progress) { | 351 setLoadProgress(progress) { |
| 352 this.loadProgress = progress; | 352 this.loadProgress = progress; |
| 353 this.updateState(); | 353 this.updateState(); |
| 354 } | 354 } |
| 355 | 355 |
| 356 setURL(host, path) { | 356 setURL(host, path) { |
| 357 let omnibox = this.domUiElement.domElement; | 357 let indicator = this.domUiElement.domElement; |
| 358 omnibox.querySelector('#domain').innerHTML = host; | 358 indicator.querySelector('#domain').innerHTML = host; |
| 359 omnibox.querySelector('#path').innerHTML = path; | 359 indicator.querySelector('#path').innerHTML = path; |
| 360 this.resetVisibilityTimer(); | 360 this.resetVisibilityTimer(); |
| 361 this.updateState(); | 361 this.updateState(); |
| 362 } | 362 } |
| 363 | 363 |
| 364 setSecurityLevel(level) { | 364 setSecurityLevel(level) { |
| 365 document.querySelector('#omnibox-warning-icon').style.display = 'none'; | 365 document.querySelector('#url-indicator-warning-icon').style.display = |
| 366 document.querySelector('#omnibox-info-icon').style.display = 'none'; | 366 'none'; |
| 367 document.querySelector('#omnibox-lock-icon').style.display = 'none'; | 367 document.querySelector('#url-indicator-info-icon').style.display = 'none'; |
| 368 document.querySelector('#url-indicator-lock-icon').style.display = 'none'; |
| 368 let icon = this.getSecurityIconElementId(level); | 369 let icon = this.getSecurityIconElementId(level); |
| 369 document.querySelector(icon).style.display = 'block'; | 370 document.querySelector(icon).style.display = 'block'; |
| 370 | 371 |
| 371 this.resetVisibilityTimer(); | 372 this.resetVisibilityTimer(); |
| 372 this.updateState(); | 373 this.updateState(); |
| 373 } | 374 } |
| 374 | 375 |
| 375 setVisibilityTimeout(milliseconds) { | 376 setVisibilityTimeout(milliseconds) { |
| 376 this.visibilityTimeout = milliseconds; | 377 this.visibilityTimeout = milliseconds; |
| 377 this.resetVisibilityTimer(); | 378 this.resetVisibilityTimer(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 394 this.updateState(); | 395 this.updateState(); |
| 395 } | 396 } |
| 396 | 397 |
| 397 updateState() { | 398 updateState() { |
| 398 this.setNativeVisibility(this.enabled); | 399 this.setNativeVisibility(this.enabled); |
| 399 | 400 |
| 400 if (!this.enabled) { | 401 if (!this.enabled) { |
| 401 return; | 402 return; |
| 402 } | 403 } |
| 403 | 404 |
| 404 let indicator = document.querySelector('#omnibox-border'); | 405 let indicator = document.querySelector('#url-indicator-border'); |
| 405 if (this.loading) { | 406 if (this.loading) { |
| 406 // Remap load progress range 0-100 as 5-95 percent, to avoid the | 407 // Remap load progress range 0-100 as 5-95 percent, to avoid the |
| 407 // extremities of the rounded ends of the omnibox. | 408 // extremities of the rounded ends of the indicator. |
| 408 let percent = Math.round((this.loadProgress * 0.9 + 0.05) * 100); | 409 let percent = Math.round((this.loadProgress * 0.9 + 0.05) * 100); |
| 409 let gradient = 'linear-gradient(to right, ' + this.statusBarColor + | 410 let gradient = 'linear-gradient(to right, ' + this.statusBarColor + |
| 410 ' 0%, ' + this.statusBarColor + ' ' + percent + '%, ' + | 411 ' 0%, ' + this.statusBarColor + ' ' + percent + '%, ' + |
| 411 this.backgroundColor + ' ' + percent + '%, ' + | 412 this.backgroundColor + ' ' + percent + '%, ' + |
| 412 this.backgroundColor + ' 100%)'; | 413 this.backgroundColor + ' 100%)'; |
| 413 indicator.style.background = gradient; | 414 indicator.style.background = gradient; |
| 414 } else { | 415 } else { |
| 415 indicator.style.background = this.backgroundColor; | 416 indicator.style.background = this.backgroundColor; |
| 416 } | 417 } |
| 417 | 418 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 constructor() { | 458 constructor() { |
| 458 this.mode = api.Mode.UNKNOWN; | 459 this.mode = api.Mode.UNKNOWN; |
| 459 this.menuMode = false; | 460 this.menuMode = false; |
| 460 this.fullscreen = false; | 461 this.fullscreen = false; |
| 461 | 462 |
| 462 this.contentQuad = new ContentQuad(); | 463 this.contentQuad = new ContentQuad(); |
| 463 let contentId = this.contentQuad.getElementId(); | 464 let contentId = this.contentQuad.getElementId(); |
| 464 | 465 |
| 465 this.controls = new Controls(contentId); | 466 this.controls = new Controls(contentId); |
| 466 this.secureOriginWarnings = new SecureOriginWarnings(); | 467 this.secureOriginWarnings = new SecureOriginWarnings(); |
| 467 this.omnibox = new Omnibox(); | 468 this.urlIndicator = new UrlIndicator(); |
| 468 } | 469 } |
| 469 | 470 |
| 470 setMode(mode, menuMode, fullscreen) { | 471 setMode(mode, menuMode, fullscreen) { |
| 471 /** @const */ var OMNIBOX_VISIBILITY_TIMEOUT_MS = 5000; | 472 /** @const */ var URL_INDICATOR_VISIBILITY_TIMEOUT_MS = 5000; |
| 472 | 473 |
| 473 this.mode = mode; | 474 this.mode = mode; |
| 474 this.menuMode = menuMode; | 475 this.menuMode = menuMode; |
| 475 this.fullscreen = fullscreen; | 476 this.fullscreen = fullscreen; |
| 476 | 477 |
| 477 this.contentQuad.setEnabled(mode == api.Mode.STANDARD && !menuMode); | 478 this.contentQuad.setEnabled(mode == api.Mode.STANDARD && !menuMode); |
| 478 this.contentQuad.setFullscreen(fullscreen); | 479 this.contentQuad.setFullscreen(fullscreen); |
| 479 // TODO(crbug/643815): Set aspect ratio on content quad when available. | 480 // TODO(crbug/643815): Set aspect ratio on content quad when available. |
| 480 // TODO(amp): Don't show controls in fullscreen once MENU mode lands. | 481 // TODO(amp): Don't show controls in fullscreen once MENU mode lands. |
| 481 this.controls.setEnabled(mode == api.Mode.STANDARD && !menuMode); | 482 this.controls.setEnabled(mode == api.Mode.STANDARD && !menuMode); |
| 482 this.omnibox.setEnabled(mode == api.Mode.STANDARD && !menuMode); | 483 this.urlIndicator.setEnabled(mode == api.Mode.STANDARD && !menuMode); |
| 483 // TODO(amp): Don't show controls in CINEMA mode once MENU mode lands. | 484 // TODO(amp): Don't show controls in CINEMA mode once MENU mode lands. |
| 484 this.omnibox.setVisibilityTimeout( | 485 this.urlIndicator.setVisibilityTimeout( |
| 485 mode == api.Mode.STANDARD && !menuMode ? | 486 mode == api.Mode.STANDARD && !menuMode ? |
| 486 0 : | 487 0 : |
| 487 OMNIBOX_VISIBILITY_TIMEOUT_MS); | 488 URL_INDICATOR_VISIBILITY_TIMEOUT_MS); |
| 488 this.secureOriginWarnings.setEnabled(mode == api.Mode.WEB_VR); | 489 this.secureOriginWarnings.setEnabled(mode == api.Mode.WEB_VR); |
| 489 | 490 |
| 490 api.setUiCssSize( | 491 api.setUiCssSize( |
| 491 uiRootElement.clientWidth, uiRootElement.clientHeight, UI_DPR); | 492 uiRootElement.clientWidth, uiRootElement.clientHeight, UI_DPR); |
| 492 } | 493 } |
| 493 | 494 |
| 494 setSecurityLevel(level) { | 495 setSecurityLevel(level) { |
| 495 this.omnibox.setSecurityLevel(level); | 496 this.urlIndicator.setSecurityLevel(level); |
| 496 } | 497 } |
| 497 | 498 |
| 498 setWebVRSecureOrigin(secure) { | 499 setWebVRSecureOrigin(secure) { |
| 499 this.secureOriginWarnings.setSecure(secure); | 500 this.secureOriginWarnings.setSecure(secure); |
| 500 } | 501 } |
| 501 | 502 |
| 502 setReloadUiEnabled(enabled) { | 503 setReloadUiEnabled(enabled) { |
| 503 this.controls.setReloadUiEnabled(enabled); | 504 this.controls.setReloadUiEnabled(enabled); |
| 504 } | 505 } |
| 505 }; | 506 }; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 519 uiManager.setSecurityLevel(dict['securityLevel']); | 520 uiManager.setSecurityLevel(dict['securityLevel']); |
| 520 } | 521 } |
| 521 if ('webVRSecureOrigin' in dict) { | 522 if ('webVRSecureOrigin' in dict) { |
| 522 uiManager.setWebVRSecureOrigin(dict['webVRSecureOrigin']); | 523 uiManager.setWebVRSecureOrigin(dict['webVRSecureOrigin']); |
| 523 } | 524 } |
| 524 if ('enableReloadUi' in dict) { | 525 if ('enableReloadUi' in dict) { |
| 525 uiManager.setReloadUiEnabled(dict['enableReloadUi']); | 526 uiManager.setReloadUiEnabled(dict['enableReloadUi']); |
| 526 } | 527 } |
| 527 if ('url' in dict) { | 528 if ('url' in dict) { |
| 528 let url = dict['url']; | 529 let url = dict['url']; |
| 529 uiManager.omnibox.setURL(url['host'], url['path']); | 530 uiManager.urlIndicator.setURL(url['host'], url['path']); |
| 530 } | 531 } |
| 531 if ('loading' in dict) { | 532 if ('loading' in dict) { |
| 532 uiManager.omnibox.setLoading(dict['loading']); | 533 uiManager.urlIndicator.setLoading(dict['loading']); |
| 533 } | 534 } |
| 534 if ('loadProgress' in dict) { | 535 if ('loadProgress' in dict) { |
| 535 uiManager.omnibox.setLoadProgress(dict['loadProgress']); | 536 uiManager.urlIndicator.setLoadProgress(dict['loadProgress']); |
| 536 } | 537 } |
| 537 ui.flush(); | 538 ui.flush(); |
| 538 } | 539 } |
| 539 | 540 |
| 540 return { | 541 return { |
| 541 initialize: initialize, | 542 initialize: initialize, |
| 542 command: command, | 543 command: command, |
| 543 }; | 544 }; |
| 544 })(); | 545 })(); |
| 545 | 546 |
| 546 document.addEventListener('DOMContentLoaded', vrShellUi.initialize); | 547 document.addEventListener('DOMContentLoaded', vrShellUi.initialize); |
| OLD | NEW |