| 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 * promoteAppsDevTools: boolean}} | |
| 31 */ | |
| 32 var ExtensionDataResponse; | |
| 33 | |
| 34 // 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 |
| 35 // tests. | 22 // tests. |
| 36 var webuiResponded = false; | 23 var webuiResponded = false; |
| 37 | 24 |
| 38 cr.define('extensions', function() { | 25 cr.define('extensions', function() { |
| 39 var ExtensionList = extensions.ExtensionList; | 26 var ExtensionList = extensions.ExtensionList; |
| 40 | 27 |
| 41 // Implements the DragWrapper handler interface. | 28 // Implements the DragWrapper handler interface. |
| 42 var dragWrapperHandler = { | 29 var dragWrapperHandler = { |
| 43 /** @override */ | 30 /** @override */ |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 measureCheckboxStrings(); | 138 measureCheckboxStrings(); |
| 152 | 139 |
| 153 // Set the title. | 140 // Set the title. |
| 154 uber.setTitle(loadTimeData.getString('extensionSettings')); | 141 uber.setTitle(loadTimeData.getString('extensionSettings')); |
| 155 | 142 |
| 156 var extensionList = new ExtensionList(); | 143 var extensionList = new ExtensionList(); |
| 157 extensionList.id = 'extension-settings-list'; | 144 extensionList.id = 'extension-settings-list'; |
| 158 var wrapper = $('extension-list-wrapper'); | 145 var wrapper = $('extension-list-wrapper'); |
| 159 wrapper.insertBefore(extensionList, wrapper.firstChild); | 146 wrapper.insertBefore(extensionList, wrapper.firstChild); |
| 160 | 147 |
| 161 // This will request the data to show on the page and will get a response | 148 this.update_(); |
| 162 // back in returnExtensionsData. | |
| 163 chrome.send('extensionSettingsRequestExtensionsData'); | |
| 164 | 149 |
| 165 var extensionLoader = extensions.ExtensionLoader.getInstance(); | 150 var extensionLoader = extensions.ExtensionLoader.getInstance(); |
| 166 | 151 |
| 167 $('toggle-dev-on').addEventListener('change', function(e) { | 152 $('toggle-dev-on').addEventListener('change', function(e) { |
| 168 this.updateDevControlsVisibility_(true); | 153 this.updateDevControlsVisibility_(true); |
| 169 extensionList.updateFocusableElements(); | 154 extensionList.updateFocusableElements(); |
| 170 chrome.send('extensionSettingsToggleDeveloperMode', | 155 chrome.developerPrivate.updateProfileConfiguration( |
| 171 [$('toggle-dev-on').checked]); | 156 {inDeveloperMode: e.target.checked}); |
| 172 }.bind(this)); | 157 }.bind(this)); |
| 173 | 158 |
| 174 window.addEventListener('resize', function() { | 159 window.addEventListener('resize', function() { |
| 175 this.updateDevControlsVisibility_(false); | 160 this.updateDevControlsVisibility_(false); |
| 176 }.bind(this)); | 161 }.bind(this)); |
| 177 | 162 |
| 178 // Set up the three dev mode buttons (load unpacked, pack and update). | 163 // Set up the three dev mode buttons (load unpacked, pack and update). |
| 179 $('load-unpacked').addEventListener('click', function(e) { | 164 $('load-unpacked').addEventListener('click', function(e) { |
| 180 extensionLoader.loadUnpacked(); | 165 extensionLoader.loadUnpacked(); |
| 181 }); | 166 }); |
| 182 $('pack-extension').addEventListener('click', | 167 $('pack-extension').addEventListener('click', |
| 183 this.handlePackExtension_.bind(this)); | 168 this.handlePackExtension_.bind(this)); |
| 184 $('update-extensions-now').addEventListener('click', | 169 $('update-extensions-now').addEventListener('click', |
| 185 this.handleUpdateExtensionNow_.bind(this)); | 170 this.handleUpdateExtensionNow_.bind(this)); |
| 186 | 171 |
| 187 // Set up the close dialog for the apps developer tools promo. | 172 // Set up the close dialog for the apps developer tools promo. |
| 188 $('apps-developer-tools-promo').querySelector('.close-button'). | 173 $('apps-developer-tools-promo').querySelector('.close-button'). |
| 189 addEventListener('click', function(e) { | 174 addEventListener('click', function(e) { |
| 190 this.displayPromo_ = false; | 175 this.displayPromo_ = false; |
| 191 this.updateDevControlsVisibility_(true); | 176 this.updateDevControlsVisibility_(true); |
| 192 chrome.send('extensionSettingsDismissADTPromo'); | 177 chrome.developerPrivate.updateProfileConfiguration( |
| 178 {dismissedAdtPromo: true}); |
| 193 | 179 |
| 194 if (cr.ui.FocusOutlineManager.forDocument(document).visible) | 180 if (cr.ui.FocusOutlineManager.forDocument(document).visible) |
| 195 $('update-extensions-now').focus(); | 181 $('update-extensions-now').focus(); |
| 196 }.bind(this)); | 182 }.bind(this)); |
| 197 | 183 |
| 198 if (!loadTimeData.getBoolean('offStoreInstallEnabled')) { | 184 if (!loadTimeData.getBoolean('offStoreInstallEnabled')) { |
| 199 this.dragWrapper_ = new cr.ui.DragWrapper(document.documentElement, | 185 this.dragWrapper_ = new cr.ui.DragWrapper(document.documentElement, |
| 200 dragWrapperHandler); | 186 dragWrapperHandler); |
| 201 this.dragEnabled_ = true; | 187 this.dragEnabled_ = true; |
| 202 } | 188 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 var path = document.location.pathname; | 224 var path = document.location.pathname; |
| 239 if (path.length > 1) { | 225 if (path.length > 1) { |
| 240 // Skip starting slash and remove trailing slash (if any). | 226 // Skip starting slash and remove trailing slash (if any). |
| 241 var overlayName = path.slice(1).replace(/\/$/, ''); | 227 var overlayName = path.slice(1).replace(/\/$/, ''); |
| 242 if (overlayName == 'configureCommands') | 228 if (overlayName == 'configureCommands') |
| 243 this.showExtensionCommandsConfigUi_(); | 229 this.showExtensionCommandsConfigUi_(); |
| 244 } | 230 } |
| 245 }, | 231 }, |
| 246 | 232 |
| 247 /** | 233 /** |
| 234 * Updates the extensions page to the latest profile and extensions |
| 235 * configuration. |
| 236 * @private |
| 237 */ |
| 238 update_: function() { |
| 239 chrome.developerPrivate.getProfileConfiguration( |
| 240 this.returnProfileConfiguration_.bind(this)); |
| 241 }, |
| 242 |
| 243 /** |
| 244 * [Re]-Populates the page with data representing the current state of |
| 245 * installed extensions. |
| 246 * @param {ProfileInfo} profileInfo |
| 247 * @private |
| 248 */ |
| 249 returnProfileConfiguration_: function(profileInfo) { |
| 250 webuiResponded = true; |
| 251 var supervised = profileInfo.isSupervised; |
| 252 |
| 253 var pageDiv = $('extension-settings'); |
| 254 pageDiv.classList.toggle('profile-is-supervised', supervised); |
| 255 pageDiv.classList.toggle('showing-banner', supervised); |
| 256 |
| 257 var devControlsCheckbox = $('toggle-dev-on'); |
| 258 devControlsCheckbox.checked = profileInfo.inDeveloperMode; |
| 259 devControlsCheckbox.disabled = supervised; |
| 260 |
| 261 this.displayPromo_ = profileInfo.shouldShowAdtPromo; |
| 262 this.updateDevControlsVisibility_(false); |
| 263 |
| 264 $('load-unpacked').disabled = !profileInfo.canLoadUnpacked; |
| 265 var extensionList = $('extension-settings-list'); |
| 266 extensionList.updateExtensionsData( |
| 267 profileInfo.isIncognitoAvailable, |
| 268 profileInfo.appInfoDialogEnabled).then(function() { |
| 269 // We can get called many times in short order, thus we need to |
| 270 // be careful to remove the 'finished loading' timeout. |
| 271 if (this.loadingTimeout_) |
| 272 window.clearTimeout(this.loadingTimeout_); |
| 273 document.documentElement.classList.add('loading'); |
| 274 this.loadingTimeout_ = window.setTimeout(function() { |
| 275 document.documentElement.classList.remove('loading'); |
| 276 }, 0); |
| 277 |
| 278 var hasExtensions = extensionList.getNumExtensions() != 0; |
| 279 $('no-extensions').hidden = hasExtensions; |
| 280 $('extension-list-wrapper').hidden = !hasExtensions; |
| 281 $('extension-settings-list').updateFocusableElements(); |
| 282 }.bind(this)); |
| 283 }, |
| 284 |
| 285 /** |
| 248 * Handles the Pack Extension button. | 286 * Handles the Pack Extension button. |
| 249 * @param {Event} e Change event. | 287 * @param {Event} e Change event. |
| 250 * @private | 288 * @private |
| 251 */ | 289 */ |
| 252 handlePackExtension_: function(e) { | 290 handlePackExtension_: function(e) { |
| 253 ExtensionSettings.showOverlay($('pack-extension-overlay')); | 291 ExtensionSettings.showOverlay($('pack-extension-overlay')); |
| 254 chrome.send('metricsHandler:recordAction', ['Options_PackExtension']); | 292 chrome.send('metricsHandler:recordAction', ['Options_PackExtension']); |
| 255 }, | 293 }, |
| 256 | 294 |
| 257 /** | 295 /** |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 }); | 349 }); |
| 312 | 350 |
| 313 window.requestAnimationFrame(function() { | 351 window.requestAnimationFrame(function() { |
| 314 devControls.style.height = !showDevControls ? '' : | 352 devControls.style.height = !showDevControls ? '' : |
| 315 (this.displayPromo_ ? adtPromo.offsetHeight : 0) + | 353 (this.displayPromo_ ? adtPromo.offsetHeight : 0) + |
| 316 buttons.offsetHeight + 'px'; | 354 buttons.offsetHeight + 'px'; |
| 317 }.bind(this)); | 355 }.bind(this)); |
| 318 }, | 356 }, |
| 319 }; | 357 }; |
| 320 | 358 |
| 321 /** | 359 ExtensionSettings.onExtensionsChanged = function() { |
| 322 * Called by the dom_ui_ to re-populate the page with data representing | 360 ExtensionSettings.getInstance().update_(); |
| 323 * the current state of installed extensions. | |
| 324 * @param {ExtensionDataResponse} extensionsData | |
| 325 */ | |
| 326 ExtensionSettings.returnExtensionsData = function(extensionsData) { | |
| 327 webuiResponded = true; | |
| 328 | |
| 329 var supervised = extensionsData.profileIsSupervised; | |
| 330 | |
| 331 var pageDiv = $('extension-settings'); | |
| 332 pageDiv.classList.toggle('profile-is-supervised', supervised); | |
| 333 pageDiv.classList.toggle('showing-banner', supervised); | |
| 334 | |
| 335 var devControlsCheckbox = $('toggle-dev-on'); | |
| 336 devControlsCheckbox.checked = extensionsData.developerMode; | |
| 337 devControlsCheckbox.disabled = supervised; | |
| 338 | |
| 339 var instance = ExtensionSettings.getInstance(); | |
| 340 instance.displayPromo_ = extensionsData.promoteAppsDevTools; | |
| 341 instance.updateDevControlsVisibility_(false); | |
| 342 | |
| 343 $('load-unpacked').disabled = extensionsData.loadUnpackedDisabled; | |
| 344 var extensionList = $('extension-settings-list'); | |
| 345 extensionList.updateExtensionsData( | |
| 346 extensionsData.incognitoAvailable, | |
| 347 extensionsData.enableAppInfoDialog).then(function() { | |
| 348 // We can get called many times in short order, thus we need to | |
| 349 // be careful to remove the 'finished loading' timeout. | |
| 350 if (this.loadingTimeout_) | |
| 351 window.clearTimeout(this.loadingTimeout_); | |
| 352 this.loadingTimeout_ = window.setTimeout(function() { | |
| 353 document.documentElement.classList.remove('loading'); | |
| 354 }, 0); | |
| 355 | |
| 356 var hasExtensions = extensionList.getNumExtensions() != 0; | |
| 357 $('no-extensions').hidden = hasExtensions; | |
| 358 $('extension-list-wrapper').hidden = !hasExtensions; | |
| 359 $('extension-settings-list').updateFocusableElements(); | |
| 360 }.bind(this)); | |
| 361 }; | 361 }; |
| 362 | 362 |
| 363 /** | 363 /** |
| 364 * Returns the current overlay or null if one does not exist. | 364 * Returns the current overlay or null if one does not exist. |
| 365 * @return {Element} The overlay element. | 365 * @return {Element} The overlay element. |
| 366 */ | 366 */ |
| 367 ExtensionSettings.getCurrentOverlay = function() { | 367 ExtensionSettings.getCurrentOverlay = function() { |
| 368 return document.querySelector('#overlay .page.showing'); | 368 return document.querySelector('#overlay .page.showing'); |
| 369 }; | 369 }; |
| 370 | 370 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 // Export | 466 // Export |
| 467 return { | 467 return { |
| 468 ExtensionSettings: ExtensionSettings | 468 ExtensionSettings: ExtensionSettings |
| 469 }; | 469 }; |
| 470 }); | 470 }); |
| 471 | 471 |
| 472 window.addEventListener('load', function(e) { | 472 window.addEventListener('load', function(e) { |
| 473 document.documentElement.classList.add('loading'); | 473 document.documentElement.classList.add('loading'); |
| 474 extensions.ExtensionSettings.getInstance().initialize(); | 474 extensions.ExtensionSettings.getInstance().initialize(); |
| 475 }); | 475 }); |
| OLD | NEW |