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

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

Issue 1060993003: [Extensions UI] Use developerPrivate API for profile configuration (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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="../../../../ui/webui/resources/js/cr/ui/focus_row.js"> 5 <include src="../../../../ui/webui/resources/js/cr/ui/focus_row.js">
6 <include src="../../../../ui/webui/resources/js/cr/ui/focus_grid.js"> 6 <include src="../../../../ui/webui/resources/js/cr/ui/focus_grid.js">
7 <include src="../uber/uber_utils.js"> 7 <include src="../uber/uber_utils.js">
8 <include src="extension_code.js"> 8 <include src="extension_code.js">
9 <include src="extension_commands_overlay.js"> 9 <include src="extension_commands_overlay.js">
10 <include src="extension_error_overlay.js"> 10 <include src="extension_error_overlay.js">
11 <include src="extension_focus_manager.js"> 11 <include src="extension_focus_manager.js">
12 <include src="extension_list.js"> 12 <include src="extension_list.js">
13 <include src="pack_extension_overlay.js"> 13 <include src="pack_extension_overlay.js">
14 <include src="extension_loader.js"> 14 <include src="extension_loader.js">
15 <include src="extension_options_overlay.js"> 15 <include src="extension_options_overlay.js">
16 16
17 <if expr="chromeos"> 17 <if expr="chromeos">
18 <include src="chromeos/kiosk_apps.js"> 18 <include src="chromeos/kiosk_apps.js">
19 </if> 19 </if>
20 20
21 /**
22 * The type of the extension data object. The definition is based on
23 * chrome/browser/ui/webui/extensions/extension_settings_handler.cc:
24 * ExtensionSettingsHandler::HandleRequestExtensionsData()
25 * @typedef {{developerMode: boolean,
26 * enableAppInfoDialog: boolean,
27 * incognitoAvailable: boolean,
28 * loadUnpackedDisabled: boolean,
29 * profileIsSupervised: boolean}}
30 */
31 var ExtensionDataResponse;
32
33 // Used for observing function of the backend datasource for this page by 21 // Used for observing function of the backend datasource for this page by
34 // tests. 22 // tests.
35 var webuiResponded = false; 23 var webuiResponded = false;
36 24
37 cr.define('extensions', function() { 25 cr.define('extensions', function() {
38 var ExtensionList = extensions.ExtensionList; 26 var ExtensionList = extensions.ExtensionList;
39 27
40 // Implements the DragWrapper handler interface. 28 // Implements the DragWrapper handler interface.
41 var dragWrapperHandler = { 29 var dragWrapperHandler = {
42 /** @override */ 30 /** @override */
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 measureCheckboxStrings(); 131 measureCheckboxStrings();
144 132
145 // Set the title. 133 // Set the title.
146 uber.setTitle(loadTimeData.getString('extensionSettings')); 134 uber.setTitle(loadTimeData.getString('extensionSettings'));
147 135
148 var extensionList = new ExtensionList(); 136 var extensionList = new ExtensionList();
149 extensionList.id = 'extension-settings-list'; 137 extensionList.id = 'extension-settings-list';
150 var wrapper = $('extension-list-wrapper'); 138 var wrapper = $('extension-list-wrapper');
151 wrapper.insertBefore(extensionList, wrapper.firstChild); 139 wrapper.insertBefore(extensionList, wrapper.firstChild);
152 140
153 // This will request the data to show on the page and will get a response 141 this.update_();
154 // back in returnExtensionsData. 142 // TODO(devlin): Remove this once all notifications are moved to events on
155 chrome.send('extensionSettingsRequestExtensionsData'); 143 // the developerPrivate api.
144 chrome.send('extensionSettingsRegister');
156 145
157 var extensionLoader = extensions.ExtensionLoader.getInstance(); 146 var extensionLoader = extensions.ExtensionLoader.getInstance();
158 147
159 $('toggle-dev-on').addEventListener('change', function(e) { 148 $('toggle-dev-on').addEventListener('change', function(e) {
160 this.updateDevControlsVisibility_(true); 149 this.updateDevControlsVisibility_(true);
161 extensionList.updateFocusableElements(); 150 extensionList.updateFocusableElements();
162 chrome.send('extensionSettingsToggleDeveloperMode', 151 chrome.developerPrivate.updateProfileConfiguration(
163 [$('toggle-dev-on').checked]); 152 {inDeveloperMode: e.target.checked});
164 }.bind(this)); 153 }.bind(this));
165 154
166 window.addEventListener('resize', function() { 155 window.addEventListener('resize', function() {
167 this.updateDevControlsVisibility_(false); 156 this.updateDevControlsVisibility_(false);
168 }.bind(this)); 157 }.bind(this));
169 158
170 // Set up the three dev mode buttons (load unpacked, pack and update). 159 // Set up the three dev mode buttons (load unpacked, pack and update).
171 $('load-unpacked').addEventListener('click', function(e) { 160 $('load-unpacked').addEventListener('click', function(e) {
172 extensionLoader.loadUnpacked(); 161 extensionLoader.loadUnpacked();
173 }); 162 });
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 var path = document.location.pathname; 208 var path = document.location.pathname;
220 if (path.length > 1) { 209 if (path.length > 1) {
221 // Skip starting slash and remove trailing slash (if any). 210 // Skip starting slash and remove trailing slash (if any).
222 var overlayName = path.slice(1).replace(/\/$/, ''); 211 var overlayName = path.slice(1).replace(/\/$/, '');
223 if (overlayName == 'configureCommands') 212 if (overlayName == 'configureCommands')
224 this.showExtensionCommandsConfigUi_(); 213 this.showExtensionCommandsConfigUi_();
225 } 214 }
226 }, 215 },
227 216
228 /** 217 /**
218 * Updates the extensions page to the latest profile and extensions
219 * configuration.
220 * @private
221 */
222 update_: function() {
223 chrome.developerPrivate.getProfileConfiguration(
224 this.returnProfileConfiguration_.bind(this));
225 },
226
227 /**
228 * [Re]-Populates the page with data representing the current state of
229 * installed extensions.
230 * @param {ProfileInfo} profileInfo
231 * @private
232 */
233 returnProfileConfiguration_: function(profileInfo) {
234 webuiResponded = true;
235 /** @const */
236 var supervised = profileInfo.isSupervised;
237
238 var pageDiv = $('extension-settings');
239 pageDiv.classList.toggle('profile-is-supervised', supervised);
240 pageDiv.classList.toggle('showing-banner', supervised);
241
242 var devControlsCheckbox = $('toggle-dev-on');
243 devControlsCheckbox.checked = profileInfo.inDeveloperMode;
244 devControlsCheckbox.disabled = supervised;
245
246 this.updateDevControlsVisibility_(false);
247
248 $('load-unpacked').disabled = !profileInfo.canLoadUnpacked;
249 var extensionList = $('extension-settings-list');
250 extensionList.updateExtensionsData(
251 profileInfo.isIncognitoAvailable,
252 profileInfo.appInfoDialogEnabled).then(function() {
253 // We can get called many times in short order, thus we need to
254 // be careful to remove the 'finished loading' timeout.
255 if (this.loadingTimeout_)
256 window.clearTimeout(this.loadingTimeout_);
257 document.documentElement.classList.add('loading');
258 this.loadingTimeout_ = window.setTimeout(function() {
259 document.documentElement.classList.remove('loading');
260 }, 0);
261
262 /** @const */
263 var hasExtensions = extensionList.getNumExtensions() != 0;
264 $('no-extensions').hidden = hasExtensions;
265 $('extension-list-wrapper').hidden = !hasExtensions;
266 $('extension-settings-list').updateFocusableElements();
267 }.bind(this));
268 },
269
270 /**
229 * Handles the Pack Extension button. 271 * Handles the Pack Extension button.
230 * @param {Event} e Change event. 272 * @param {Event} e Change event.
231 * @private 273 * @private
232 */ 274 */
233 handlePackExtension_: function(e) { 275 handlePackExtension_: function(e) {
234 ExtensionSettings.showOverlay($('pack-extension-overlay')); 276 ExtensionSettings.showOverlay($('pack-extension-overlay'));
235 chrome.send('metricsHandler:recordAction', ['Options_PackExtension']); 277 chrome.send('metricsHandler:recordAction', ['Options_PackExtension']);
236 }, 278 },
237 279
238 /** 280 /**
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 }); 326 });
285 buttons.setAttribute('aria-hidden', !showDevControls); 327 buttons.setAttribute('aria-hidden', !showDevControls);
286 328
287 window.requestAnimationFrame(function() { 329 window.requestAnimationFrame(function() {
288 devControls.style.height = !showDevControls ? '' : 330 devControls.style.height = !showDevControls ? '' :
289 buttons.offsetHeight + 'px'; 331 buttons.offsetHeight + 'px';
290 }.bind(this)); 332 }.bind(this));
291 }, 333 },
292 }; 334 };
293 335
294 /** 336 ExtensionSettings.onExtensionsChanged = function() {
295 * Called by the dom_ui_ to re-populate the page with data representing 337 ExtensionSettings.getInstance().update_();
296 * the current state of installed extensions.
297 * @param {ExtensionDataResponse} extensionsData
298 */
299 ExtensionSettings.returnExtensionsData = function(extensionsData) {
300 webuiResponded = true;
301
302 var supervised = extensionsData.profileIsSupervised;
303
304 var pageDiv = $('extension-settings');
305 pageDiv.classList.toggle('profile-is-supervised', supervised);
306 pageDiv.classList.toggle('showing-banner', supervised);
307
308 var devControlsCheckbox = $('toggle-dev-on');
309 devControlsCheckbox.checked = extensionsData.developerMode;
310 devControlsCheckbox.disabled = supervised;
311
312 ExtensionSettings.getInstance().updateDevControlsVisibility_(false);
313
314 $('load-unpacked').disabled = extensionsData.loadUnpackedDisabled;
315 var extensionList = $('extension-settings-list');
316 extensionList.updateExtensionsData(
317 extensionsData.incognitoAvailable,
318 extensionsData.enableAppInfoDialog).then(function() {
319 // We can get called many times in short order, thus we need to
320 // be careful to remove the 'finished loading' timeout.
321 if (this.loadingTimeout_)
322 window.clearTimeout(this.loadingTimeout_);
323 this.loadingTimeout_ = window.setTimeout(function() {
324 document.documentElement.classList.remove('loading');
325 }, 0);
326
327 var hasExtensions = extensionList.getNumExtensions() != 0;
328 $('no-extensions').hidden = hasExtensions;
329 $('extension-list-wrapper').hidden = !hasExtensions;
330 $('extension-settings-list').updateFocusableElements();
331 }.bind(this));
332 }; 338 };
333 339
334 /** 340 /**
335 * Returns the current overlay or null if one does not exist. 341 * Returns the current overlay or null if one does not exist.
336 * @return {Element} The overlay element. 342 * @return {Element} The overlay element.
337 */ 343 */
338 ExtensionSettings.getCurrentOverlay = function() { 344 ExtensionSettings.getCurrentOverlay = function() {
339 return document.querySelector('#overlay .page.showing'); 345 return document.querySelector('#overlay .page.showing');
340 }; 346 };
341 347
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 // Export 443 // Export
438 return { 444 return {
439 ExtensionSettings: ExtensionSettings 445 ExtensionSettings: ExtensionSettings
440 }; 446 };
441 }); 447 });
442 448
443 window.addEventListener('load', function(e) { 449 window.addEventListener('load', function(e) {
444 document.documentElement.classList.add('loading'); 450 document.documentElement.classList.add('loading');
445 extensions.ExtensionSettings.getInstance().initialize(); 451 extensions.ExtensionSettings.getInstance().initialize();
446 }); 452 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698