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

Side by Side Diff: chrome/browser/resources/vr_shell/vr_shell_ui.js

Issue 2435623003: Implement (but do not enable) HTML UI-driven WebVR security warnings. (Closed)
Patch Set: Created 4 years, 2 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 cr.define('chrome.vrShellUi', function() { 5 cr.define('chrome.vrShellUi', function() {
6 'use strict'; 6 'use strict';
7 7
8 var scene = new ui.Scene(); 8 var scene = new ui.Scene();
9 var state; 9 var state;
10 10
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 54
55 onMouseEnter() { 55 onMouseEnter() {
56 this.configure(1, 1, 0.015); 56 this.configure(1, 1, 0.015);
57 } 57 }
58 58
59 onMouseLeave() { 59 onMouseLeave() {
60 this.configure(0.8, 0, 0); 60 this.configure(0.8, 0, 0);
61 } 61 }
62 }; 62 };
63 63
64 class UiState { 64 class UiState {
mthiesse 2016/10/19 20:11:56 No preference for where or when you do this, but w
cjgrant 2016/10/21 17:40:48 Done.
65 constructor() { 65 constructor() {
66 this.mode = -1; 66 this.mode = -1;
67 this.secureOrigin = true;
68
69 // Permanent WebVR security warning.
70 this.webVrSecureWarning = new DomUiElement('#webvr-not-secure-permanent');
71 var distance = 0.7;
72 var angleUp = 16.3 * Math.PI / 180.0;
bshe 2016/10/20 18:01:53 Should the above two variables be a const? Similar
cjgrant 2016/10/21 17:40:48 Done (with additional refactoring).
73 var update = new api.UiElementUpdate();
74 update.setScale(distance, distance, 1);
75 update.setTranslation(0, Math.sin(angleUp),
76 -distance * Math.cos(angleUp));
77 update.setRotation(1.0, 0.0, 0.0, angleUp);
78 update.setPassive(true);
79 update.setVisible(false);
80 update.setLockToFieldOfView(true);
81 scene.updateElement(this.webVrSecureWarning.uiElementId, update);
82
83 // Temporary WebVR security warning.
84 this.webVrTransientSecureWarning = new DomUiElement(
85 '#webvr-not-secure-transient');
86 update = new api.UiElementUpdate();
87 update.setScale(distance, distance, 1);
88 update.setTranslation(0, 0, -distance);
89 update.setPassive(true);
90 update.setVisible(false);
91 update.setLockToFieldOfView(true);
92 scene.updateElement(this.webVrTransientSecureWarning.uiElementId, update);
93
67 this.createMenuButtons(); 94 this.createMenuButtons();
68 scene.flush(); 95 scene.flush();
69 } 96 }
70 97
71 createMenuButtons() { 98 createMenuButtons() {
72 this.menuButtons = []; 99 this.menuButtons = [];
73 var buttons = [ 100 var buttons = [
74 ['#back', function() { 101 ['#back', function() {
75 api.doAction(api.Action.HISTORY_BACK); 102 api.doAction(api.Action.HISTORY_BACK);
76 }], 103 }],
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 showMenuButtons(visible) { 138 showMenuButtons(visible) {
112 for (var i = 0; i < this.menuButtons.length; i++) { 139 for (var i = 0; i < this.menuButtons.length; i++) {
113 var update = new api.UiElementUpdate(); 140 var update = new api.UiElementUpdate();
114 update.setVisible(visible); 141 update.setVisible(visible);
115 scene.updateElement(this.menuButtons[i].uiElementId, update); 142 scene.updateElement(this.menuButtons[i].uiElementId, update);
116 } 143 }
117 scene.flush(); 144 scene.flush();
118 } 145 }
119 146
120 setMode(mode) { 147 setMode(mode) {
148 this.mode = mode;
bshe 2016/10/20 18:01:53 This got me wonder which will be called first from
cjgrant 2016/10/21 17:40:48 In 2D mode, we don't get a call to VrShell to set
bshe 2016/10/21 18:10:47 This can be in a separate CL if it make sense. But
121 this.showMenuButtons(mode == api.Mode.STANDARD); 149 this.showMenuButtons(mode == api.Mode.STANDARD);
150 this.updateSecureOriginWarnings();
151 }
152
153 setSecureOrigin(secure) {
154 if (!secure) {
155 this.secureOriginTimer = setTimeout(
bshe 2016/10/20 18:01:53 Do you need to clear the previous timer if not fir
cjgrant 2016/10/21 17:40:49 Done. Good catch.
156 this.onSecureOriginTimer.bind(this), 30000);
157 } else {
158 if (this.secureOriginTimer) {
159 clearInterval(this.secureOriginTimer);
160 this.secureOriginTimer = null;
161 }
162 }
163 this.secureOrigin = secure;
mthiesse 2016/10/19 20:11:56 nit: isSecureOrigin
cjgrant 2016/10/21 17:40:49 Done.
164 this.updateSecureOriginWarnings();
165 }
166
167 onSecureOriginTimer() {
168 this.secureOriginTimer = null;
169 this.updateSecureOriginWarnings();
170 }
171
172 updateSecureOriginWarnings() {
173 var visible = (this.mode == 1 && !this.secureOrigin);
bshe 2016/10/20 18:01:53 nit: prefer to use an enum instead of 1.
cjgrant 2016/10/21 17:40:48 Done.
174 var transientVisible = (visible && this.secureOriginTimer);
175
176 var update = new api.UiElementUpdate();
177 update.setVisible(visible);
178 scene.updateElement(this.webVrSecureWarning.uiElementId, update);
179 update = new api.UiElementUpdate();
180 update.setVisible(transientVisible);
181 scene.updateElement(this.webVrTransientSecureWarning.uiElementId, update);
182 scene.flush();
122 } 183 }
123 }; 184 };
124 185
125 function initialize() { 186 function initialize() {
126 187
127 // Change the body background so that the transparency applies. 188 // Change the body background so that the transparency applies.
128 window.setTimeout(function() { 189 window.setTimeout(function() {
129 document.body.parentNode.style.backgroundColor = 'rgba(255,255,255,0)'; 190 document.body.parentNode.style.backgroundColor = 'rgba(255,255,255,0)';
130 }, 100); 191 }, 100);
131 192
132 state = new UiState(); 193 state = new UiState();
133 194
134 api.domLoaded(); 195 api.domLoaded();
135 } 196 }
136 197
137 function command(dict) { 198 function command(dict) {
138 if ('mode' in dict) { 199 if ('mode' in dict) {
139 state.setMode(dict['mode']); 200 state.setMode(dict['mode']);
140 } 201 }
202 if ('secureOrigin' in dict) {
203 state.setSecureOrigin(dict['secureOrigin']);
204 }
141 } 205 }
142 206
143 return { 207 return {
144 initialize: initialize, 208 initialize: initialize,
145 command: command, 209 command: command,
146 }; 210 };
147 }); 211 });
148 212
149 document.addEventListener('DOMContentLoaded', chrome.vrShellUi.initialize); 213 document.addEventListener('DOMContentLoaded', chrome.vrShellUi.initialize);
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698