Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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. | |
| 155 chrome.send('extensionSettingsRequestExtensionsData'); | |
| 156 | 142 |
| 157 var extensionLoader = extensions.ExtensionLoader.getInstance(); | 143 var extensionLoader = extensions.ExtensionLoader.getInstance(); |
| 158 | 144 |
| 159 $('toggle-dev-on').addEventListener('change', function(e) { | 145 $('toggle-dev-on').addEventListener('change', function(e) { |
| 160 this.updateDevControlsVisibility_(true); | 146 this.updateDevControlsVisibility_(true); |
| 161 extensionList.updateFocusableElements(); | 147 extensionList.updateFocusableElements(); |
| 162 chrome.send('extensionSettingsToggleDeveloperMode', | 148 chrome.developerPrivate.updateProfileConfiguration( |
| 163 [$('toggle-dev-on').checked]); | 149 {inDeveloperMode: e.target.checked}); |
| 164 }.bind(this)); | 150 }.bind(this)); |
| 165 | 151 |
| 166 window.addEventListener('resize', function() { | 152 window.addEventListener('resize', function() { |
| 167 this.updateDevControlsVisibility_(false); | 153 this.updateDevControlsVisibility_(false); |
| 168 }.bind(this)); | 154 }.bind(this)); |
| 169 | 155 |
| 170 // Set up the three dev mode buttons (load unpacked, pack and update). | 156 // Set up the three dev mode buttons (load unpacked, pack and update). |
| 171 $('load-unpacked').addEventListener('click', function(e) { | 157 $('load-unpacked').addEventListener('click', function(e) { |
| 172 extensionLoader.loadUnpacked(); | 158 extensionLoader.loadUnpacked(); |
| 173 }); | 159 }); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 219 var path = document.location.pathname; | 205 var path = document.location.pathname; |
| 220 if (path.length > 1) { | 206 if (path.length > 1) { |
| 221 // Skip starting slash and remove trailing slash (if any). | 207 // Skip starting slash and remove trailing slash (if any). |
| 222 var overlayName = path.slice(1).replace(/\/$/, ''); | 208 var overlayName = path.slice(1).replace(/\/$/, ''); |
| 223 if (overlayName == 'configureCommands') | 209 if (overlayName == 'configureCommands') |
| 224 this.showExtensionCommandsConfigUi_(); | 210 this.showExtensionCommandsConfigUi_(); |
| 225 } | 211 } |
| 226 }, | 212 }, |
| 227 | 213 |
| 228 /** | 214 /** |
| 215 * Updates the extensions page to the latest profile and extensions | |
| 216 * configuration. | |
| 217 * @private | |
| 218 */ | |
| 219 update_: function() { | |
| 220 chrome.developerPrivate.getProfileConfiguration( | |
| 221 this.returnProfileConfiguration_.bind(this)); | |
| 222 }, | |
| 223 | |
| 224 /** | |
| 225 * [Re]-Populates the page with data representing the current state of | |
| 226 * installed extensions. | |
| 227 * @param {ProfileInfo} profileInfo | |
| 228 * @private | |
| 229 */ | |
| 230 returnProfileConfiguration_: function(profileInfo) { | |
| 231 webuiResponded = true; | |
| 232 var supervised = profileInfo.isSupervised; | |
|
Dan Beam
2015/04/10 02:48:06
nit: when it fits: /** @const */
Devlin
2015/04/10 16:30:38
Done.
| |
| 233 | |
| 234 var pageDiv = $('extension-settings'); | |
| 235 pageDiv.classList.toggle('profile-is-supervised', supervised); | |
| 236 pageDiv.classList.toggle('showing-banner', supervised); | |
| 237 | |
| 238 var devControlsCheckbox = $('toggle-dev-on'); | |
| 239 devControlsCheckbox.checked = profileInfo.inDeveloperMode; | |
| 240 devControlsCheckbox.disabled = supervised; | |
| 241 | |
| 242 this.updateDevControlsVisibility_(false); | |
| 243 | |
| 244 $('load-unpacked').disabled = !profileInfo.canLoadUnpacked; | |
| 245 var extensionList = $('extension-settings-list'); | |
| 246 extensionList.updateExtensionsData( | |
| 247 profileInfo.isIncognitoAvailable, | |
| 248 profileInfo.appInfoDialogEnabled).then(function() { | |
| 249 // We can get called many times in short order, thus we need to | |
| 250 // be careful to remove the 'finished loading' timeout. | |
| 251 if (this.loadingTimeout_) | |
| 252 window.clearTimeout(this.loadingTimeout_); | |
| 253 document.documentElement.classList.add('loading'); | |
| 254 this.loadingTimeout_ = window.setTimeout(function() { | |
| 255 document.documentElement.classList.remove('loading'); | |
| 256 }, 0); | |
| 257 | |
| 258 var hasExtensions = extensionList.getNumExtensions() != 0; | |
| 259 $('no-extensions').hidden = hasExtensions; | |
| 260 $('extension-list-wrapper').hidden = !hasExtensions; | |
| 261 $('extension-settings-list').updateFocusableElements(); | |
| 262 }.bind(this)); | |
| 263 }, | |
| 264 | |
| 265 /** | |
| 229 * Handles the Pack Extension button. | 266 * Handles the Pack Extension button. |
| 230 * @param {Event} e Change event. | 267 * @param {Event} e Change event. |
| 231 * @private | 268 * @private |
| 232 */ | 269 */ |
| 233 handlePackExtension_: function(e) { | 270 handlePackExtension_: function(e) { |
| 234 ExtensionSettings.showOverlay($('pack-extension-overlay')); | 271 ExtensionSettings.showOverlay($('pack-extension-overlay')); |
| 235 chrome.send('metricsHandler:recordAction', ['Options_PackExtension']); | 272 chrome.send('metricsHandler:recordAction', ['Options_PackExtension']); |
| 236 }, | 273 }, |
| 237 | 274 |
| 238 /** | 275 /** |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 284 }); | 321 }); |
| 285 buttons.setAttribute('aria-hidden', !showDevControls); | 322 buttons.setAttribute('aria-hidden', !showDevControls); |
| 286 | 323 |
| 287 window.requestAnimationFrame(function() { | 324 window.requestAnimationFrame(function() { |
| 288 devControls.style.height = !showDevControls ? '' : | 325 devControls.style.height = !showDevControls ? '' : |
| 289 buttons.offsetHeight + 'px'; | 326 buttons.offsetHeight + 'px'; |
| 290 }.bind(this)); | 327 }.bind(this)); |
| 291 }, | 328 }, |
| 292 }; | 329 }; |
| 293 | 330 |
| 294 /** | 331 ExtensionSettings.onExtensionsChanged = function() { |
| 295 * Called by the dom_ui_ to re-populate the page with data representing | 332 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 }; | 333 }; |
| 333 | 334 |
| 334 /** | 335 /** |
| 335 * Returns the current overlay or null if one does not exist. | 336 * Returns the current overlay or null if one does not exist. |
| 336 * @return {Element} The overlay element. | 337 * @return {Element} The overlay element. |
| 337 */ | 338 */ |
| 338 ExtensionSettings.getCurrentOverlay = function() { | 339 ExtensionSettings.getCurrentOverlay = function() { |
| 339 return document.querySelector('#overlay .page.showing'); | 340 return document.querySelector('#overlay .page.showing'); |
| 340 }; | 341 }; |
| 341 | 342 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 437 // Export | 438 // Export |
| 438 return { | 439 return { |
| 439 ExtensionSettings: ExtensionSettings | 440 ExtensionSettings: ExtensionSettings |
| 440 }; | 441 }; |
| 441 }); | 442 }); |
| 442 | 443 |
| 443 window.addEventListener('load', function(e) { | 444 window.addEventListener('load', function(e) { |
| 444 document.documentElement.classList.add('loading'); | 445 document.documentElement.classList.add('loading'); |
| 445 extensions.ExtensionSettings.getInstance().initialize(); | 446 extensions.ExtensionSettings.getInstance().initialize(); |
| 446 }); | 447 }); |
| OLD | NEW |