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

Side by Side Diff: chrome/browser/resources/extensions/extensions.js

Issue 887803003: extensions: clean up hiding/showing of developer controls. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 5 years, 10 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <include src="../uber/uber_utils.js"> 5 <include src="../uber/uber_utils.js">
6 <include src="extension_code.js"> 6 <include src="extension_code.js">
7 <include src="extension_commands_overlay.js"> 7 <include src="extension_commands_overlay.js">
8 <include src="extension_error_overlay.js"> 8 <include src="extension_error_overlay.js">
9 <include src="extension_focus_manager.js"> 9 <include src="extension_focus_manager.js">
10 <include src="extension_list.js"> 10 <include src="extension_list.js">
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 130
131 // Set the title. 131 // Set the title.
132 uber.setTitle(loadTimeData.getString('extensionSettings')); 132 uber.setTitle(loadTimeData.getString('extensionSettings'));
133 133
134 // This will request the data to show on the page and will get a response 134 // This will request the data to show on the page and will get a response
135 // back in returnExtensionsData. 135 // back in returnExtensionsData.
136 chrome.send('extensionSettingsRequestExtensionsData'); 136 chrome.send('extensionSettingsRequestExtensionsData');
137 137
138 var extensionLoader = extensions.ExtensionLoader.getInstance(); 138 var extensionLoader = extensions.ExtensionLoader.getInstance();
139 139
140 $('toggle-dev-on').addEventListener('change', 140 $('toggle-dev-on').addEventListener('change', function(e) {
141 this.handleToggleDevMode_.bind(this)); 141 this.updateDevControlsVisibility_(true);
142 $('dev-controls').addEventListener('webkitTransitionEnd', 142 chrome.send('extensionSettingsToggleDeveloperMode',
143 this.handleDevControlsTransitionEnd_.bind(this)); 143 [$('toggle-dev-on').checked]);
Dan Beam 2015/01/30 19:41:31 sending a true/false arg makes it harder for the J
144 }.bind(this));
145
146 window.addEventListener('resize', function() {
Dan Beam 2015/01/30 19:41:31 this happens when zoomed
147 this.updateDevControlsVisibility_(false);
148 }.bind(this));
144 149
145 // Set up the three dev mode buttons (load unpacked, pack and update). 150 // Set up the three dev mode buttons (load unpacked, pack and update).
146 $('load-unpacked').addEventListener('click', function(e) { 151 $('load-unpacked').addEventListener('click', function(e) {
147 extensionLoader.loadUnpacked(); 152 extensionLoader.loadUnpacked();
148 }); 153 });
149 $('pack-extension').addEventListener('click', 154 $('pack-extension').addEventListener('click',
150 this.handlePackExtension_.bind(this)); 155 this.handlePackExtension_.bind(this));
151 $('update-extensions-now').addEventListener('click', 156 $('update-extensions-now').addEventListener('click',
152 this.handleUpdateExtensionNow_.bind(this)); 157 this.handleUpdateExtensionNow_.bind(this));
153 158
154 // Set up the close dialog for the apps developer tools promo. 159 // Set up the close dialog for the apps developer tools promo.
155 $('apps-developer-tools-promo').querySelector('.close-button'). 160 $('apps-developer-tools-promo').querySelector('.close-button').
156 addEventListener('click', function(e) { 161 addEventListener('click', function(e) {
157 this.displayPromo_ = false; 162 this.displayPromo_ = false;
158 this.updatePromoVisibility_(); 163 this.updateDevControlsVisibility_(true);
159 chrome.send('extensionSettingsDismissADTPromo'); 164 chrome.send('extensionSettingsDismissADTPromo');
165
166 if (cr.ui.FocusOutlineManager.forDocument(document).visible)
167 $('update-extensions-now').focus();
Dan Beam 2015/01/30 19:41:30 this moves the focus if the keyboard was used to h
160 }.bind(this)); 168 }.bind(this));
161 169
162 if (!loadTimeData.getBoolean('offStoreInstallEnabled')) { 170 if (!loadTimeData.getBoolean('offStoreInstallEnabled')) {
163 this.dragWrapper_ = new cr.ui.DragWrapper(document.documentElement, 171 this.dragWrapper_ = new cr.ui.DragWrapper(document.documentElement,
164 dragWrapperHandler); 172 dragWrapperHandler);
165 } 173 }
166 174
167 extensions.PackExtensionOverlay.getInstance().initializePage(); 175 extensions.PackExtensionOverlay.getInstance().initializePage();
168 176
169 // Hook up the configure commands link to the overlay. 177 // Hook up the configure commands link to the overlay.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 var path = document.location.pathname; 209 var path = document.location.pathname;
202 if (path.length > 1) { 210 if (path.length > 1) {
203 // Skip starting slash and remove trailing slash (if any). 211 // Skip starting slash and remove trailing slash (if any).
204 var overlayName = path.slice(1).replace(/\/$/, ''); 212 var overlayName = path.slice(1).replace(/\/$/, '');
205 if (overlayName == 'configureCommands') 213 if (overlayName == 'configureCommands')
206 this.showExtensionCommandsConfigUi_(); 214 this.showExtensionCommandsConfigUi_();
207 } 215 }
208 }, 216 },
209 217
210 /** 218 /**
211 * Updates the Chrome Apps and Extensions Developer Tools promotion's
212 * visibility.
213 * @private
214 */
215 updatePromoVisibility_: function() {
Dan Beam 2015/01/30 19:41:31 combined updatePromoVisibility_ and handleToggleDe
216 var extensionSettings = $('extension-settings');
217 var visible = extensionSettings.classList.contains('dev-mode') &&
218 this.displayPromo_;
219
220 var adtPromo = $('apps-developer-tools-promo');
221 var controls = adtPromo.querySelectorAll('a, button');
222 Array.prototype.forEach.call(controls, function(control) {
223 control[visible ? 'removeAttribute' : 'setAttribute']('tabindex', '-1');
224 });
225
226 adtPromo.setAttribute('aria-hidden', !visible);
227 extensionSettings.classList.toggle('adt-promo', visible);
228 },
229
230 /**
231 * Handles the Pack Extension button. 219 * Handles the Pack Extension button.
232 * @param {Event} e Change event. 220 * @param {Event} e Change event.
233 * @private 221 * @private
234 */ 222 */
235 handlePackExtension_: function(e) { 223 handlePackExtension_: function(e) {
236 ExtensionSettings.showOverlay($('pack-extension-overlay')); 224 ExtensionSettings.showOverlay($('pack-extension-overlay'));
237 chrome.send('metricsHandler:recordAction', ['Options_PackExtension']); 225 chrome.send('metricsHandler:recordAction', ['Options_PackExtension']);
238 }, 226 },
239 227
240 /** 228 /**
(...skipping 19 matching lines...) Expand all
260 /** 248 /**
261 * Handles the Update Extension Now button. 249 * Handles the Update Extension Now button.
262 * @param {Event} e Change event. 250 * @param {Event} e Change event.
263 * @private 251 * @private
264 */ 252 */
265 handleUpdateExtensionNow_: function(e) { 253 handleUpdateExtensionNow_: function(e) {
266 chrome.send('extensionSettingsAutoupdate'); 254 chrome.send('extensionSettingsAutoupdate');
267 }, 255 },
268 256
269 /** 257 /**
270 * Handles the Toggle Dev Mode button. 258 * Updates the visibility of the developer controls based on whether the
271 * @param {Event} e Change event. 259 * [x] Developer mode checkbox is checked. Also called if a user dismisses
260 * the apps developer tools promo.
261 * @param {boolean} animated Whether to animate any updates.
272 * @private 262 * @private
273 */ 263 */
274 handleToggleDevMode_: function(e) { 264 updateDevControlsVisibility_: function(animated) {
275 if ($('toggle-dev-on').checked) { 265 var showDevControls = $('toggle-dev-on').checked;
276 $('dev-controls').hidden = false; 266 $('extension-settings').classList.toggle('dev-mode', showDevControls);
277 window.setTimeout(function() {
278 $('extension-settings').classList.add('dev-mode');
279 }, 0);
280 } else {
281 $('extension-settings').classList.remove('dev-mode');
282 }
283 window.setTimeout(this.updatePromoVisibility_.bind(this), 0);
284 267
285 chrome.send('extensionSettingsToggleDeveloperMode'); 268 var devControls = $('dev-controls');
286 }, 269 devControls.classList.toggle('animated', animated);
287 270
288 /** 271 var buttons = devControls.querySelector('.button-container');
289 * Called when a transition has ended for #dev-controls. 272 var adtPromo = $('apps-developer-tools-promo');
290 * @param {Event} e webkitTransitionEnd event. 273 [
291 * @private 274 {root: buttons, focusable: showDevControls},
292 */ 275 {root: adtPromo, focusable: showDevControls && this.displayPromo_},
293 handleDevControlsTransitionEnd_: function(e) { 276 ].forEach(function(entry) {
294 if (e.propertyName == 'height' && 277 var controls = entry.root.querySelectorAll('a, button');
295 !$('extension-settings').classList.contains('dev-mode')) { 278 Array.prototype.forEach.call(controls, function(control) {
296 $('dev-controls').hidden = true; 279 control.tabIndex = entry.focusable ? 0 : -1;
297 } 280 });
281 entry.root.setAttribute('aria-hidden', !entry.focusable);
282 });
283
284 window.requestAnimationFrame(function() {
285 devControls.style.height = !showDevControls ? '' :
286 (this.displayPromo_ ? adtPromo.offsetHeight : 0) +
287 buttons.offsetHeight + 'px';
288 }.bind(this));
298 }, 289 },
299 }; 290 };
300 291
301 /** 292 /**
302 * Called by the dom_ui_ to re-populate the page with data representing 293 * Called by the dom_ui_ to re-populate the page with data representing
303 * the current state of installed extensions. 294 * the current state of installed extensions.
304 * @param {ExtensionDataResponse} extensionsData 295 * @param {ExtensionDataResponse} extensionsData
305 */ 296 */
306 ExtensionSettings.returnExtensionsData = function(extensionsData) { 297 ExtensionSettings.returnExtensionsData = function(extensionsData) {
307 // We can get called many times in short order, thus we need to 298 // We can get called many times in short order, thus we need to
(...skipping 14 matching lines...) Expand all
322 extensionsData.extensions.sort(function(a, b) { 313 extensionsData.extensions.sort(function(a, b) {
323 function compare(x, y) { 314 function compare(x, y) {
324 return x < y ? -1 : (x > y ? 1 : 0); 315 return x < y ? -1 : (x > y ? 1 : 0);
325 } 316 }
326 return compare(a.order, b.order) || 317 return compare(a.order, b.order) ||
327 compare(a.name.toLowerCase(), b.name.toLowerCase()) || 318 compare(a.name.toLowerCase(), b.name.toLowerCase()) ||
328 compare(a.id, b.id); 319 compare(a.id, b.id);
329 }); 320 });
330 } 321 }
331 322
323 var supervised = extensionsData.profileIsSupervised;
324
332 var pageDiv = $('extension-settings'); 325 var pageDiv = $('extension-settings');
333 var marginTop = 0; 326 pageDiv.classList.toggle('profile-is-supervised', supervised);
334 if (extensionsData.profileIsSupervised) { 327 pageDiv.classList.toggle('showing-banner', supervised);
335 pageDiv.classList.add('profile-is-supervised');
336 } else {
337 pageDiv.classList.remove('profile-is-supervised');
338 }
339 if (extensionsData.profileIsSupervised) {
340 pageDiv.classList.add('showing-banner');
341 $('toggle-dev-on').disabled = true;
342 marginTop += 45;
343 } else {
344 pageDiv.classList.remove('showing-banner');
345 $('toggle-dev-on').disabled = false;
346 }
347 328
348 pageDiv.style.marginTop = marginTop + 'px'; 329 var devControlsCheckbox = $('toggle-dev-on');
330 devControlsCheckbox.checked = extensionsData.developerMode;
331 devControlsCheckbox.disabled = supervised;
349 332
350 if (extensionsData.developerMode) { 333 var instance = ExtensionSettings.getInstance();
351 pageDiv.classList.add('dev-mode'); 334 instance.displayPromo_ = extensionsData.promoteAppsDevTools;
352 $('toggle-dev-on').checked = true; 335 instance.updateDevControlsVisibility_(false);
Dan Beam 2015/01/30 19:41:30 most of this is purely simplifications or moving f
353 $('dev-controls').hidden = false;
354 } else {
355 pageDiv.classList.remove('dev-mode');
356 $('toggle-dev-on').checked = false;
357 }
358
359 ExtensionSettings.getInstance().displayPromo_ =
360 extensionsData.promoteAppsDevTools;
361 ExtensionSettings.getInstance().updatePromoVisibility_();
362 336
363 $('load-unpacked').disabled = extensionsData.loadUnpackedDisabled; 337 $('load-unpacked').disabled = extensionsData.loadUnpackedDisabled;
364 338
365 ExtensionsList.prototype.data_ = extensionsData; 339 ExtensionsList.prototype.data_ = extensionsData;
366 var extensionList = $('extension-settings-list'); 340 var extensionList = $('extension-settings-list');
367 ExtensionsList.decorate(extensionList); 341 ExtensionsList.decorate(extensionList);
368 }; 342 };
369 343
370 // Indicate that warning |message| has occured for pack of |crx_path| and 344 // Indicate that warning |message| has occured for pack of |crx_path| and
371 // |pem_path| files. Ask if user wants override the warning. Send 345 // |pem_path| files. Ask if user wants override the warning. Send
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 444
471 // Export 445 // Export
472 return { 446 return {
473 ExtensionSettings: ExtensionSettings 447 ExtensionSettings: ExtensionSettings
474 }; 448 };
475 }); 449 });
476 450
477 window.addEventListener('load', function(e) { 451 window.addEventListener('load', function(e) {
478 extensions.ExtensionSettings.getInstance().initialize(); 452 extensions.ExtensionSettings.getInstance().initialize();
479 }); 453 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698