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="extension_error.js"> | 5 <include src="extension_error.js"> |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * The type of the extension data object. The definition is based on | 8 * The type of the extension data object. The definition is based on |
| 9 * chrome/browser/ui/webui/extensions/extension_basic_info.cc | 9 * chrome/browser/ui/webui/extensions/extension_basic_info.cc |
| 10 * and | 10 * and |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 | 70 |
| 71 /** | 71 /** |
| 72 * Creates a new list of extensions. | 72 * Creates a new list of extensions. |
| 73 * @param {Object=} opt_propertyBag Optional properties. | 73 * @param {Object=} opt_propertyBag Optional properties. |
| 74 * @constructor | 74 * @constructor |
| 75 * @extends {HTMLDivElement} | 75 * @extends {HTMLDivElement} |
| 76 */ | 76 */ |
| 77 var ExtensionsList = cr.ui.define('div'); | 77 var ExtensionsList = cr.ui.define('div'); |
| 78 | 78 |
| 79 /** | 79 /** |
| 80 * @type {Object.<string, boolean>} A map from extension id to a boolean | |
| 81 * indicating whether the incognito warning is showing. This persists | |
| 82 * between calls to decorate. | |
| 83 */ | |
| 84 var butterBarVisibility = {}; | |
| 85 | |
| 86 /** | |
| 87 * @type {Object.<string, number>} A map from extension id to last reloaded | 80 * @type {Object.<string, number>} A map from extension id to last reloaded |
| 88 * timestamp. The timestamp is recorded when the user click the 'Reload' | 81 * timestamp. The timestamp is recorded when the user click the 'Reload' |
| 89 * link. It is used to refresh the icon of an unpacked extension. | 82 * link. It is used to refresh the icon of an unpacked extension. |
| 90 * This persists between calls to decorate. | 83 * This persists between calls to decorate. |
| 91 */ | 84 */ |
| 92 var extensionReloadedTimestamp = {}; | 85 var extensionReloadedTimestamp = {}; |
| 93 | 86 |
| 94 ExtensionsList.prototype = { | 87 ExtensionsList.prototype = { |
| 95 __proto__: HTMLDivElement.prototype, | 88 __proto__: HTMLDivElement.prototype, |
| 96 | 89 |
| 97 /** | 90 /** |
| 98 * Indicates whether an embedded options page that was navigated to through | 91 * Indicates whether an embedded options page that was navigated to through |
| 99 * the '?options=' URL query has been shown to the user. This is necessary | 92 * the '?options=' URL query has been shown to the user. This is necessary |
| 100 * to prevent showExtensionNodes_ from opening the options more than once. | 93 * to prevent showExtensionNodes_ from opening the options more than once. |
| 101 * @type {boolean} | 94 * @type {boolean} |
| 102 * @private | 95 * @private |
| 103 */ | 96 */ |
| 104 optionsShown_: false, | 97 optionsShown_: false, |
| 105 | 98 |
| 99 /** | |
| 100 * Necessary to only show the butterbar once. | |
| 101 * @private {boolean} | |
| 102 */ | |
| 103 butterbarShown_: false, | |
| 104 | |
| 106 decorate: function() { | 105 decorate: function() { |
| 107 this.textContent = ''; | |
| 108 | |
| 109 this.showExtensionNodes_(); | 106 this.showExtensionNodes_(); |
| 110 }, | 107 }, |
| 111 | 108 |
| 112 getIdQueryParam_: function() { | 109 getIdQueryParam_: function() { |
| 113 return parseQueryParams(document.location)['id']; | 110 return parseQueryParams(document.location)['id']; |
| 114 }, | 111 }, |
| 115 | 112 |
| 116 getOptionsQueryParam_: function() { | 113 getOptionsQueryParam_: function() { |
| 117 return parseQueryParams(document.location)['options']; | 114 return parseQueryParams(document.location)['options']; |
| 118 }, | 115 }, |
| 119 | 116 |
| 120 /** | 117 /** |
| 121 * Creates all extension items from scratch. | 118 * Creates all extension items from scratch. |
| 122 * @private | 119 * @private |
| 123 */ | 120 */ |
| 124 showExtensionNodes_: function() { | 121 showExtensionNodes_: function() { |
| 122 // Any node that is not updated will be removed. | |
| 123 var nodes = document.querySelectorAll('.extension-list-item-wrapper[id]'); | |
| 124 for (var i = 0; i < nodes.length; ++i) { | |
| 125 nodes[i].extensionStillInstalled_ = false; | |
| 126 } | |
| 127 | |
| 125 // Iterate over the extension data and add each item to the list. | 128 // Iterate over the extension data and add each item to the list. |
| 126 this.data_.extensions.forEach(this.createNode_, this); | 129 this.data_.extensions.forEach(function(extension) { |
| 130 var node = $(extension.id); | |
| 131 | |
| 132 if (node) { | |
| 133 this.updateNode_(extension, node); | |
| 134 node.extensionStillInstalled_ = true; | |
| 135 } else { | |
| 136 this.createNode_(extension); | |
| 137 } | |
| 138 }, this); | |
| 139 | |
| 140 // Remove extensions that are no longer installed. | |
| 141 for (var i = 0; i < nodes.length; ++i) { | |
| 142 var node = nodes[i]; | |
| 143 if (!node.extensionStillInstalled_) | |
| 144 node.parentElement.removeChild(node); | |
| 145 } | |
| 127 | 146 |
| 128 var idToHighlight = this.getIdQueryParam_(); | 147 var idToHighlight = this.getIdQueryParam_(); |
| 129 if (idToHighlight && $(idToHighlight)) | 148 if (idToHighlight && $(idToHighlight)) |
| 130 this.scrollToNode_(idToHighlight); | 149 this.scrollToNode_(idToHighlight); |
| 131 | 150 |
| 132 var idToOpenOptions = this.getOptionsQueryParam_(); | 151 var idToOpenOptions = this.getOptionsQueryParam_(); |
| 133 if (idToOpenOptions && $(idToOpenOptions)) | 152 if (idToOpenOptions && $(idToOpenOptions)) |
| 134 this.showEmbeddedExtensionOptions_(idToOpenOptions, true); | 153 this.showEmbeddedExtensionOptions_(idToOpenOptions, true); |
| 135 | 154 |
| 136 var noExtensions = this.data_.extensions.length == 0; | 155 var noExtensions = this.data_.extensions.length == 0; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 158 * given in |extension|. | 177 * given in |extension|. |
| 159 * @param {ExtensionData} extension A dictionary of extension metadata. | 178 * @param {ExtensionData} extension A dictionary of extension metadata. |
| 160 * @private | 179 * @private |
| 161 */ | 180 */ |
| 162 createNode_: function(extension) { | 181 createNode_: function(extension) { |
| 163 var template = $('template-collection').querySelector( | 182 var template = $('template-collection').querySelector( |
| 164 '.extension-list-item-wrapper'); | 183 '.extension-list-item-wrapper'); |
| 165 var node = template.cloneNode(true); | 184 var node = template.cloneNode(true); |
| 166 node.id = extension.id; | 185 node.id = extension.id; |
| 167 | 186 |
| 168 if (!extension.enabled || extension.terminated) | 187 // The 'Show Browser Action' button. |
| 169 node.classList.add('inactive-extension'); | 188 this.addListener_('click', node, '.show-button', function(e) { |
| 189 chrome.send('extensionSettingsShowButton', [extension.id]); | |
| 190 }); | |
| 170 | 191 |
| 192 // The 'allow in incognito' checkbox. | |
| 193 this.addListener_('change', node, '.incognito-control input', | |
| 194 function(e) { | |
| 195 var butterBar = node.querySelector('.butter-bar'); | |
| 196 var checked = e.target.checked; | |
| 197 if (!this.butterbarShown_) { | |
| 198 butterBar.hidden = !checked || extension.is_hosted_app; | |
| 199 this.butterbarShown_ = !butterBar.hidden; | |
| 200 } else | |
| 201 butterBar.hidden = true; | |
| 202 chrome.send('extensionSettingsEnableIncognito', | |
| 203 [extension.id, String(checked)]); | |
| 204 }.bind(this)); | |
| 205 | |
| 206 // The 'collect errors' checkbox. This should only be visible if the | |
| 207 // error console is enabled - we can detect this by the existence of the | |
| 208 // |errorCollectionEnabled| property. | |
| 209 this.addListener_('change', node, '.error-collection-control input', | |
| 210 function(e) { | |
| 211 chrome.send('extensionSettingsEnableErrorCollection', | |
| 212 [extension.id, String(e.target.checked)]); | |
| 213 }); | |
| 214 | |
| 215 // The 'allow on all urls' checkbox. This should only be visible if | |
| 216 // active script restrictions are enabled. If they are not enabled, no | |
| 217 // extensions should want all urls. | |
| 218 this.addListener_('click', node, '.all-urls-control', function(e) { | |
| 219 chrome.send('extensionSettingsAllowOnAllUrls', | |
| 220 [extension.id, String(e.target.checked)]); | |
| 221 }); | |
| 222 | |
| 223 // The 'allow file:// access' checkbox. | |
| 224 this.addListener_('click', node, '.file-access-control', function(e) { | |
| 225 chrome.send('extensionSettingsAllowFileAccess', | |
| 226 [extension.id, String(e.target.checked)]); | |
| 227 }); | |
| 228 | |
| 229 // The 'Options' button or link, depending on its behaviour. | |
| 230 // Set an href to get the correct mouse-over appearance (link, | |
| 231 // footer) - but the actual link opening is done through chrome.send | |
| 232 // with a preventDefault(). | |
| 233 node.querySelector('.options-link').href = extension.optionsPageHref; | |
| 234 this.addListener_('click', node, '.options-link', function(e) { | |
| 235 chrome.send('extensionSettingsOptions', [extension.id]); | |
| 236 e.preventDefault(); | |
| 237 }); | |
| 238 | |
| 239 this.addListener_('click', node, '.options-button', function(e) { | |
| 240 this.showEmbeddedExtensionOptions_(extension.id, false); | |
| 241 e.preventDefault(); | |
| 242 }.bind(this)); | |
| 243 | |
| 244 // The 'Permissions' link. | |
| 245 this.addListener_('click', node, '.permissions-link', function(e) { | |
| 246 chrome.send('extensionSettingsPermissions', [extension.id]); | |
| 247 e.preventDefault(); | |
| 248 }); | |
| 249 | |
| 250 // The 'Reload' link. | |
| 251 this.addListener_('click', node, '.reload-link', function(e) { | |
| 252 chrome.send('extensionSettingsReload', [extension.id]); | |
| 253 extensionReloadedTimestamp[extension.id] = Date.now(); | |
| 254 }); | |
| 255 | |
| 256 // The 'Launch' link. | |
| 257 this.addListener_('click', node, '.launch-link', function(e) { | |
| 258 chrome.send('extensionSettingsLaunch', [extension.id]); | |
| 259 }); | |
| 260 | |
| 261 // The 'Reload' terminated link. | |
| 262 this.addListener_('click', node, '.terminated-reload-link', function(e) { | |
| 263 chrome.send('extensionSettingsReload', [extension.id]); | |
| 264 }); | |
| 265 | |
| 266 // The 'Repair' corrupted link. | |
| 267 this.addListener_('click', node, '.corrupted-repair-button', function(e) { | |
| 268 chrome.send('extensionSettingsRepair', [extension.id]); | |
| 269 }); | |
| 270 | |
| 271 // The 'Enabled' checkbox. | |
| 272 this.addListener_('change', node, '.enable-checkbox input', function(e) { | |
| 273 var checked = e.target.checked; | |
| 274 chrome.send('extensionSettingsEnable', [extension.id, String(checked)]); | |
| 275 | |
| 276 // This may seem counter-intuitive (to not set/clear the checkmark) | |
| 277 // but this page will be updated asynchronously if the extension | |
| 278 // becomes enabled/disabled. It also might not become enabled or | |
| 279 // disabled, because the user might e.g. get prompted when enabling | |
| 280 // and choose not to. | |
| 281 e.preventDefault(); | |
| 282 }); | |
| 283 | |
| 284 // 'Remove' button. | |
| 285 var trashTemplate = $('template-collection').querySelector('.trash'); | |
| 286 var trash = trashTemplate.cloneNode(true); | |
| 287 trash.title = loadTimeData.getString('extensionUninstall'); | |
| 288 trash.addEventListener('click', function(e) { | |
| 289 chrome.send('extensionSettingsUninstall', [extension.id]); | |
| 290 }); | |
| 291 node.querySelector('.enable-controls').appendChild(trash); | |
| 292 | |
| 293 // Developer mode //////////////////////////////////////////////////////// | |
| 294 | |
| 295 // The path, if provided by unpacked extension. | |
| 296 this.addListener_('click', node, '.load-path a:first-of-type', | |
| 297 function(e) { | |
| 298 chrome.send('extensionSettingsShowPath', [String(extension.id)]); | |
| 299 e.preventDefault(); | |
| 300 }); | |
| 301 | |
| 302 this.appendChild(node); | |
| 303 this.updateNode_(extension, node); | |
| 304 }, | |
| 305 | |
| 306 /** | |
| 307 * Updates an HTML element for the extension metadata given in |extension|. | |
| 308 * @param {ExtensionData} extension A dictionary of extension metadata. | |
| 309 * @param {Element} node The node that is being updated. | |
| 310 * @private | |
| 311 */ | |
| 312 updateNode_: function(extension, node) { | |
| 313 node.classList.toggle('inactive-extension', | |
| 314 !extension.enabled || extension.terminated); | |
| 315 | |
| 316 node.classList.remove('policy-controlled', 'may-not-modify', | |
| 317 'may-not-remove'); | |
| 171 var classes = []; | 318 var classes = []; |
| 172 if (extension.managedInstall) { | 319 if (extension.managedInstall) { |
| 173 classes.push('policy-controlled', 'may-not-modify'); | 320 classes.push('policy-controlled', 'may-not-modify'); |
| 174 } else if (extension.dependentExtensions.length > 0) { | 321 } else if (extension.dependentExtensions.length > 0) { |
| 175 classes.push('may-not-remove', 'may-not-modify'); | 322 classes.push('may-not-remove', 'may-not-modify'); |
| 176 } else if (extension.recommendedInstall) { | 323 } else if (extension.recommendedInstall) { |
| 177 classes.push('may-not-remove'); | 324 classes.push('may-not-remove'); |
| 178 } else if (extension.suspiciousInstall || | 325 } else if (extension.suspiciousInstall || |
| 179 extension.corruptInstall || | 326 extension.corruptInstall || |
| 180 extension.updateRequiredByPolicy) { | 327 extension.updateRequiredByPolicy) { |
| 181 classes.push('may-not-modify'); | 328 classes.push('may-not-modify'); |
| 182 } | 329 } |
| 183 node.classList.add.apply(node.classList, classes); | 330 node.classList.add.apply(node.classList, classes); |
| 184 | 331 |
| 185 var idToHighlight = this.getIdQueryParam_(); | 332 node.classList.toggle('extension-highlight', |
| 186 if (node.id == idToHighlight) | 333 node.id == this.getIdQueryParam_()); |
| 187 node.classList.add('extension-highlight'); | |
| 188 | 334 |
| 189 var item = node.querySelector('.extension-list-item'); | 335 var item = node.querySelector('.extension-list-item'); |
| 190 // Prevent the image cache of extension icon by using the reloaded | 336 // Prevent the image cache of extension icon by using the reloaded |
| 191 // timestamp as a query string. The timestamp is recorded when the user | 337 // timestamp as a query string. The timestamp is recorded when the user |
| 192 // clicks the 'Reload' link. http://crbug.com/159302. | 338 // clicks the 'Reload' link. http://crbug.com/159302. |
| 193 if (extensionReloadedTimestamp[extension.id]) { | 339 if (extensionReloadedTimestamp[extension.id]) { |
| 194 item.style.backgroundImage = | 340 item.style.backgroundImage = |
| 195 'url(' + extension.icon + '?' + | 341 'url(' + extension.icon + '?' + |
| 196 extensionReloadedTimestamp[extension.id] + ')'; | 342 extensionReloadedTimestamp[extension.id] + ')'; |
| 197 } else { | 343 } else { |
| 198 item.style.backgroundImage = 'url(' + extension.icon + ')'; | 344 item.style.backgroundImage = 'url(' + extension.icon + ')'; |
| 199 } | 345 } |
| 200 | 346 |
| 201 var title = node.querySelector('.extension-title'); | 347 this.setText_(node, '.extension-title', extension.name); |
| 202 title.textContent = extension.name; | 348 this.setText_(node, '.extension-version', extension.version); |
| 203 | 349 this.setText_(node, '.location-text', extension.locationText); |
| 204 var version = node.querySelector('.extension-version'); | 350 this.setText_(node, '.blacklist-text', extension.blacklistText); |
| 205 version.textContent = extension.version; | 351 this.setText_(node, '.extension-description', |
| 206 | 352 extension.description); |
| 207 var locationText = node.querySelector('.location-text'); | |
| 208 locationText.textContent = extension.locationText; | |
| 209 | |
| 210 var blacklistText = node.querySelector('.blacklist-text'); | |
| 211 blacklistText.textContent = extension.blacklistText; | |
| 212 | |
| 213 var description = document.createElement('span'); | |
| 214 description.textContent = extension.description; | |
| 215 node.querySelector('.extension-description').appendChild(description); | |
| 216 | 353 |
| 217 // The 'Show Browser Action' button. | 354 // The 'Show Browser Action' button. |
| 218 if (extension.enable_show_button) { | 355 this.updateVisibility_(node, '.show-button', |
| 219 var showButton = node.querySelector('.show-button'); | 356 extension.enable_show_button); |
| 220 showButton.addEventListener('click', function(e) { | |
| 221 chrome.send('extensionSettingsShowButton', [extension.id]); | |
| 222 }); | |
| 223 showButton.hidden = false; | |
| 224 } | |
| 225 | 357 |
| 226 // The 'allow in incognito' checkbox. | 358 // The 'allow in incognito' checkbox. |
| 227 node.querySelector('.incognito-control').hidden = | 359 this.updateVisibility_(node, '.incognito-control', |
| 228 !this.data_.incognitoAvailable; | 360 this.data_.incognitoAvailable, function(item) { |
| 229 var incognito = node.querySelector('.incognito-control input'); | 361 var incognito = item.querySelector('input'); |
| 230 incognito.disabled = !extension.incognitoCanBeEnabled; | 362 incognito.disabled = !extension.incognitoCanBeEnabled; |
| 231 incognito.checked = extension.enabledIncognito; | 363 incognito.checked = extension.enabledIncognito; |
| 232 if (!incognito.disabled) { | 364 }); |
| 233 incognito.addEventListener('change', function(e) { | 365 |
| 234 var checked = e.target.checked; | 366 // Hide butterBar if incognito is not enabled for the extension. |
| 235 butterBarVisibility[extension.id] = checked; | |
| 236 butterBar.hidden = !checked || extension.is_hosted_app; | |
| 237 chrome.send('extensionSettingsEnableIncognito', | |
| 238 [extension.id, String(checked)]); | |
| 239 }); | |
| 240 } | |
| 241 var butterBar = node.querySelector('.butter-bar'); | 367 var butterBar = node.querySelector('.butter-bar'); |
| 242 butterBar.hidden = !butterBarVisibility[extension.id]; | 368 butterBar.hidden = butterBar.hidden || !extension.enabledIncognito; |
| 243 | 369 |
| 244 // The 'collect errors' checkbox. This should only be visible if the | 370 // The 'collect errors' checkbox. This should only be visible if the |
| 245 // error console is enabled - we can detect this by the existence of the | 371 // error console is enabled - we can detect this by the existence of the |
| 246 // |errorCollectionEnabled| property. | 372 // |errorCollectionEnabled| property. |
| 247 if (extension.wantsErrorCollection) { | 373 this.updateVisibility_(node, '.error-collection-control', |
| 248 node.querySelector('.error-collection-control').hidden = false; | 374 extension.wantsErrorCollection, function(item) { |
| 249 var errorCollection = | 375 item.querySelector('input').checked = extension.errorCollectionEnabled; |
| 250 node.querySelector('.error-collection-control input'); | 376 }); |
| 251 errorCollection.checked = extension.errorCollectionEnabled; | |
| 252 errorCollection.addEventListener('change', function(e) { | |
| 253 chrome.send('extensionSettingsEnableErrorCollection', | |
| 254 [extension.id, String(e.target.checked)]); | |
| 255 }); | |
| 256 } | |
| 257 | 377 |
| 258 // The 'allow on all urls' checkbox. This should only be visible if | 378 // The 'allow on all urls' checkbox. This should only be visible if |
| 259 // active script restrictions are enabled. If they are not enabled, no | 379 // active script restrictions are enabled. If they are not enabled, no |
| 260 // extensions should want all urls. | 380 // extensions should want all urls. |
| 261 if (extension.showAllUrls) { | 381 this.updateVisibility_(node, '.all-urls-control', extension.showAllUrls, |
| 262 var allUrls = node.querySelector('.all-urls-control'); | 382 function(item) { |
| 263 allUrls.addEventListener('click', function(e) { | 383 item.querySelector('input').checked = extension.allowAllUrls; |
| 264 chrome.send('extensionSettingsAllowOnAllUrls', | 384 }); |
| 265 [extension.id, String(e.target.checked)]); | |
| 266 }); | |
| 267 allUrls.querySelector('input').checked = extension.allowAllUrls; | |
| 268 allUrls.hidden = false; | |
| 269 } | |
| 270 | 385 |
| 271 // The 'allow file:// access' checkbox. | 386 // The 'allow file:// access' checkbox. |
| 272 if (extension.wantsFileAccess) { | 387 this.updateVisibility_(node, '.file-access-control', |
| 273 var fileAccess = node.querySelector('.file-access-control'); | 388 extension.wantsFileAccess, function(item) { |
| 274 fileAccess.addEventListener('click', function(e) { | 389 item.querySelector('input').checked = extension.allowFileAccess; |
| 275 chrome.send('extensionSettingsAllowFileAccess', | 390 }); |
| 276 [extension.id, String(e.target.checked)]); | |
| 277 }); | |
| 278 fileAccess.querySelector('input').checked = extension.allowFileAccess; | |
| 279 fileAccess.hidden = false; | |
| 280 } | |
| 281 | 391 |
| 282 // The 'Options' button or link, depending on its behaviour. | 392 // The 'Options' button or link, depending on its behaviour. |
| 283 if (extension.enabled && extension.optionsUrl) { | 393 var optionsEnabled = extension.enabled && !!extension.optionsUrl; |
| 284 var options, optionsClickListener; | 394 this.updateVisibility_(node, '.options-link', optionsEnabled && |
| 285 if (extension.optionsOpenInTab) { | 395 extension.optionsOpenInTab); |
| 286 options = node.querySelector('.options-link'); | 396 this.updateVisibility_(node, '.options-button', optionsEnabled && |
| 287 // Set an href to get the correct mouse-over appearance (link, | 397 !extension.optionsOpenInTab); |
| 288 // footer) - but the actual link opening is done through chrome.send | |
| 289 // with a preventDefault(). | |
| 290 options.setAttribute('href', extension.optionsPageHref); | |
| 291 optionsClickListener = function() { | |
| 292 chrome.send('extensionSettingsOptions', [extension.id]); | |
| 293 }; | |
| 294 } else { | |
| 295 options = node.querySelector('.options-button'); | |
| 296 optionsClickListener = function() { | |
| 297 this.showEmbeddedExtensionOptions_(extension.id, false); | |
| 298 }.bind(this); | |
| 299 } | |
| 300 options.addEventListener('click', function(e) { | |
| 301 optionsClickListener(); | |
| 302 e.preventDefault(); | |
| 303 }); | |
| 304 options.hidden = false; | |
| 305 } | |
| 306 | 398 |
| 307 // The 'Permissions' link. | 399 // The 'View in Web Store/View Web Site' link. |
| 308 var permissions = node.querySelector('.permissions-link'); | 400 var siteLinkEnabled = !!extension.homepageUrl && |
| 309 permissions.addEventListener('click', function(e) { | 401 !extension.enableExtensionInfoDialog; |
| 310 chrome.send('extensionSettingsPermissions', [extension.id]); | 402 this.updateVisibility_(node, '.site-link', siteLinkEnabled, |
| 311 e.preventDefault(); | 403 function(item) { |
| 404 item.href = extension.homepageUrl; | |
| 405 item.textContent = loadTimeData.getString( | |
| 406 extension.homepageProvided ? 'extensionSettingsVisitWebsite' : | |
| 407 'extensionSettingsVisitWebStore'); | |
| 312 }); | 408 }); |
| 313 | 409 |
| 314 // The 'View in Web Store/View Web Site' link. | 410 // The 'Reload' link. |
| 315 if (extension.homepageUrl && !extension.enableExtensionInfoDialog) { | 411 this.updateVisibility_(node, '.reload-link', extension.allow_reload); |
| 316 var siteLink = node.querySelector('.site-link'); | |
| 317 siteLink.href = extension.homepageUrl; | |
| 318 siteLink.textContent = loadTimeData.getString( | |
| 319 extension.homepageProvided ? 'extensionSettingsVisitWebsite' : | |
| 320 'extensionSettingsVisitWebStore'); | |
| 321 siteLink.hidden = false; | |
| 322 } | |
| 323 | 412 |
| 324 if (extension.allow_reload) { | 413 // The 'Launch' link. |
| 325 // The 'Reload' link. | 414 this.updateVisibility_(node, '.launch-link', extension.allow_reload && |
| 326 var reload = node.querySelector('.reload-link'); | 415 extension.is_platform_app); |
| 327 reload.addEventListener('click', function(e) { | |
| 328 chrome.send('extensionSettingsReload', [extension.id]); | |
| 329 extensionReloadedTimestamp[extension.id] = Date.now(); | |
| 330 }); | |
| 331 reload.hidden = false; | |
| 332 | 416 |
| 333 if (extension.is_platform_app) { | 417 // The 'Reload' terminated link. |
| 334 // The 'Launch' link. | 418 var isTerminated = extension.terminated; |
| 335 var launch = node.querySelector('.launch-link'); | 419 this.updateVisibility_(node, '.terminated-reload-link', isTerminated); |
| 336 launch.addEventListener('click', function(e) { | |
| 337 chrome.send('extensionSettingsLaunch', [extension.id]); | |
| 338 }); | |
| 339 launch.hidden = false; | |
| 340 } | |
| 341 } | |
| 342 | 420 |
| 343 if (extension.terminated) { | 421 // The 'Repair' corrupted link. |
| 344 var terminatedReload = node.querySelector('.terminated-reload-link'); | 422 var canRepair = !isTerminated && extension.corruptInstall && |
| 345 terminatedReload.hidden = false; | 423 extension.isFromStore; |
| 346 terminatedReload.onclick = function() { | 424 this.updateVisibility_(node, '.corrupted-repair-button', canRepair); |
| 347 chrome.send('extensionSettingsReload', [extension.id]); | 425 |
| 348 }; | 426 // The 'Enabled' checkbox. |
| 349 } else if (extension.corruptInstall && extension.isFromStore) { | 427 var isOK = !isTerminated && !canRepair; |
| 350 var repair = node.querySelector('.corrupted-repair-button'); | 428 this.updateVisibility_(node, '.enable-checkbox', isOK, function(item) { |
| 351 repair.hidden = false; | |
| 352 repair.onclick = function() { | |
| 353 chrome.send('extensionSettingsRepair', [extension.id]); | |
| 354 }; | |
| 355 } else { | |
| 356 // The 'Enabled' checkbox. | |
| 357 var enable = node.querySelector('.enable-checkbox'); | |
| 358 enable.hidden = false; | |
| 359 var enableCheckboxDisabled = extension.managedInstall || | 429 var enableCheckboxDisabled = extension.managedInstall || |
| 360 extension.suspiciousInstall || | 430 extension.suspiciousInstall || |
| 361 extension.corruptInstall || | 431 extension.corruptInstall || |
| 362 extension.updateRequiredByPolicy || | 432 extension.updateRequiredByPolicy || |
| 363 extension.dependentExtensions.length > 0; | 433 extension.dependentExtensions.length > 0; |
| 364 enable.querySelector('input').disabled = enableCheckboxDisabled; | 434 item.querySelector('input').disabled = enableCheckboxDisabled; |
| 435 item.querySelector('input').checked = extension.enabled; | |
| 436 }); | |
| 365 | 437 |
| 366 if (extension.managedInstall) { | 438 // Button for extensions controlled by policy. |
| 367 var indicator = new cr.ui.ControlledIndicator(); | 439 var controlNode = node.querySelector('.enable-controls'); |
| 368 indicator.classList.add('controlled-extension-indicator'); | 440 var indicator = |
| 369 indicator.setAttribute('controlled-by', 'policy'); | 441 controlNode.querySelector('.controlled-extension-indicator'); |
| 370 var textPolicy = extension.policyText || ''; | 442 var needsIndicator = isOK && extension.managedInstall; |
| 371 indicator.setAttribute('textpolicy', textPolicy); | |
| 372 indicator.image.setAttribute('aria-label', textPolicy); | |
| 373 node.querySelector('.enable-controls').appendChild(indicator); | |
| 374 } | |
| 375 | 443 |
| 376 if (!enableCheckboxDisabled) { | 444 if (needsIndicator && !indicator) { |
| 377 enable.addEventListener('click', function(e) { | 445 indicator = new cr.ui.ControlledIndicator(); |
| 378 // When e.target is the label instead of the checkbox, it doesn't | 446 indicator.classList.add('controlled-extension-indicator'); |
| 379 // have the checked property and the state of the checkbox is | 447 indicator.setAttribute('controlled-by', 'policy'); |
| 380 // left unchanged. | 448 var textPolicy = extension.policyText || ''; |
| 381 var checked = e.target.checked; | 449 indicator.setAttribute('textpolicy', textPolicy); |
| 382 if (checked == undefined) | 450 indicator.image.setAttribute('aria-label', textPolicy); |
| 383 checked = !e.currentTarget.querySelector('input').checked; | 451 controlNode.appendChild(indicator); |
| 384 chrome.send('extensionSettingsEnable', | 452 } else if (!needsIndicator && indicator) { |
| 385 [extension.id, checked ? 'true' : 'false']); | 453 controlNode.removeChild(indicator); |
| 386 | |
| 387 // This may seem counter-intuitive (to not set/clear the checkmark) | |
| 388 // but this page will be updated asynchronously if the extension | |
| 389 // becomes enabled/disabled. It also might not become enabled or | |
| 390 // disabled, because the user might e.g. get prompted when enabling | |
| 391 // and choose not to. | |
| 392 e.preventDefault(); | |
| 393 }); | |
| 394 } | |
| 395 | |
| 396 enable.querySelector('input').checked = extension.enabled; | |
| 397 } | 454 } |
| 398 | 455 |
| 399 // 'Remove' button. | |
| 400 var trashTemplate = $('template-collection').querySelector('.trash'); | |
| 401 var trash = trashTemplate.cloneNode(true); | |
| 402 trash.title = loadTimeData.getString('extensionUninstall'); | |
| 403 trash.addEventListener('click', function(e) { | |
| 404 butterBarVisibility[extension.id] = false; | |
| 405 chrome.send('extensionSettingsUninstall', [extension.id]); | |
| 406 }); | |
| 407 node.querySelector('.enable-controls').appendChild(trash); | |
| 408 | |
| 409 // Developer mode //////////////////////////////////////////////////////// | 456 // Developer mode //////////////////////////////////////////////////////// |
| 410 | 457 |
| 411 // First we have the id. | 458 // First we have the id. |
| 412 var idLabel = node.querySelector('.extension-id'); | 459 var idLabel = node.querySelector('.extension-id'); |
| 413 idLabel.textContent = ' ' + extension.id; | 460 idLabel.textContent = ' ' + extension.id; |
| 414 | 461 |
| 415 // Then the path, if provided by unpacked extension. | 462 // Then the path, if provided by unpacked extension. |
| 416 if (extension.isUnpacked) { | 463 this.updateVisibility_(node, '.load-path', extension.isUnpacked, |
| 417 var loadPath = node.querySelector('.load-path'); | 464 function(item) { |
| 418 loadPath.hidden = false; | 465 item.querySelector('a:first-of-type').textContent = |
| 419 var pathLink = loadPath.querySelector('a:nth-of-type(1)'); | 466 ' ' + extension.prettifiedPath; |
| 420 pathLink.textContent = ' ' + extension.prettifiedPath; | 467 }); |
| 421 pathLink.addEventListener('click', function(e) { | |
| 422 chrome.send('extensionSettingsShowPath', [String(extension.id)]); | |
| 423 e.preventDefault(); | |
| 424 }); | |
| 425 } | |
| 426 | 468 |
| 427 // Then the 'managed, cannot uninstall/disable' message. | 469 // Then the 'managed, cannot uninstall/disable' message. |
| 428 if (extension.managedInstall || extension.recommendedInstall) { | 470 // We would like to hide managed installed message since this |
| 429 node.querySelector('.managed-message').hidden = false; | 471 // extension is disabled. |
| 430 } else { | 472 var isRequired = extension.managedInstall || extension.recommendedInstall; |
| 431 if (extension.suspiciousInstall) { | 473 this.updateVisibility_(node, '.managed-message', isRequired && |
| 432 // Then the 'This isn't from the webstore, looks suspicious' message. | 474 !extension.updateRequiredByPolicy); |
| 433 node.querySelector('.suspicious-install-message').hidden = false; | 475 |
| 434 } | 476 // Then the 'This isn't from the webstore, looks suspicious' message. |
| 435 if (extension.corruptInstall) { | 477 this.updateVisibility_(node, '.suspicious-install-message', !isRequired && |
| 436 // Then the 'This is a corrupt extension' message. | 478 extension.suspiciousInstall); |
| 437 node.querySelector('.corrupt-install-message').hidden = false; | 479 |
| 438 } | 480 // Then the 'This is a corrupt extension' message. |
| 439 } | 481 this.updateVisibility_(node, '.corrupt-install-message', !isRequired && |
| 482 extension.corruptInstall); | |
| 440 | 483 |
| 441 // Then the 'An update required by enterprise policy' message. Note that | 484 // Then the 'An update required by enterprise policy' message. Note that |
| 442 // a force-installed extension might be disabled due to being outdated | 485 // a force-installed extension might be disabled due to being outdated |
| 443 // as well. | 486 // as well. |
| 444 if (extension.updateRequiredByPolicy) { | 487 this.updateVisibility_(node, '.update-required-message', |
| 445 node.querySelector('.update-required-message').hidden = false; | 488 extension.updateRequiredByPolicy); |
| 446 // We would like to hide managed installed message since this | |
| 447 // extension is disabled. | |
| 448 node.querySelector('.managed-message').hidden = true; | |
| 449 } | |
| 450 | 489 |
| 451 if (extension.dependentExtensions.length > 0) { | 490 // The 'following extensions depend on this extension' list. |
| 452 node.classList.add('developer-extras'); | 491 var hasDependents = extension.dependentExtensions.length > 0; |
| 453 var dependentMessage = | 492 node.classList.toggle('developer-extras', hasDependents); |
| 454 node.querySelector('.dependent-extensions-message'); | 493 this.updateVisibility_(node, '.dependent-extensions-message', |
| 455 dependentMessage.hidden = false; | 494 hasDependents, function(item) { |
| 456 var dependentList = dependentMessage.querySelector('ul'); | 495 var dependentList = item.querySelector('ul'); |
| 496 dependentList.textContent = ''; | |
| 457 var dependentTemplate = $('template-collection').querySelector( | 497 var dependentTemplate = $('template-collection').querySelector( |
| 458 '.dependent-list-item'); | 498 '.dependent-list-item'); |
| 459 extension.dependentExtensions.forEach(function(elem) { | 499 extension.dependentExtensions.forEach(function(elem) { |
| 460 var depNode = dependentTemplate.cloneNode(true); | 500 var depNode = dependentTemplate.cloneNode(true); |
| 461 depNode.querySelector('.dep-extension-title').textContent = elem.name; | 501 depNode.querySelector('.dep-extension-title').textContent = elem.name; |
| 462 depNode.querySelector('.dep-extension-id').textContent = elem.id; | 502 depNode.querySelector('.dep-extension-id').textContent = elem.id; |
| 463 dependentList.appendChild(depNode); | 503 dependentList.appendChild(depNode); |
| 464 }); | 504 }); |
| 465 } | 505 }); |
| 466 | 506 |
| 467 // Then active views. | 507 // The active views. |
| 468 if (extension.views.length > 0) { | 508 this.updateVisibility_(node, '.active-views', extension.views.length > 0, |
| 469 var activeViews = node.querySelector('.active-views'); | 509 function(item) { |
| 470 activeViews.hidden = false; | 510 var link = item.querySelector('a'); |
| 471 var link = activeViews.querySelector('a'); | 511 |
| 512 // Link needs to be an only child before the list is updated. | |
| 513 while (link.nextElementSibling) | |
| 514 item.removeChild(link.nextElementSibling); | |
| 515 | |
| 516 // Link needs to be cleaned up if it was used before. | |
| 517 link.textContent = ''; | |
| 518 if (link.clickHandler) | |
| 519 link.removeEventListener('click', link.clickHandler); | |
| 472 | 520 |
| 473 extension.views.forEach(function(view, i) { | 521 extension.views.forEach(function(view, i) { |
| 474 var displayName = view.generatedBackgroundPage ? | 522 var displayName = view.generatedBackgroundPage ? |
| 475 loadTimeData.getString('backgroundPage') : view.path; | 523 loadTimeData.getString('backgroundPage') : view.path; |
| 476 var label = displayName + | 524 var label = displayName + |
| 477 (view.incognito ? | 525 (view.incognito ? |
| 478 ' ' + loadTimeData.getString('viewIncognito') : '') + | 526 ' ' + loadTimeData.getString('viewIncognito') : '') + |
| 479 (view.renderProcessId == -1 ? | 527 (view.renderProcessId == -1 ? |
| 480 ' ' + loadTimeData.getString('viewInactive') : ''); | 528 ' ' + loadTimeData.getString('viewInactive') : ''); |
| 481 link.textContent = label; | 529 link.textContent = label; |
| 482 link.addEventListener('click', function(e) { | 530 link.clickHandler = function(e) { |
| 483 // TODO(estade): remove conversion to string? | 531 // TODO(estade): remove conversion to string? |
| 484 chrome.send('extensionSettingsInspect', [ | 532 chrome.send('extensionSettingsInspect', [ |
| 485 String(extension.id), | 533 String(extension.id), |
| 486 String(view.renderProcessId), | 534 String(view.renderProcessId), |
| 487 String(view.renderViewId), | 535 String(view.renderViewId), |
| 488 view.incognito | 536 view.incognito |
| 489 ]); | 537 ]); |
| 490 }); | 538 }; |
| 539 link.addEventListener('click', link.clickHandler); | |
| 491 | 540 |
| 492 if (i < extension.views.length - 1) { | 541 if (i < extension.views.length - 1) { |
| 493 link = link.cloneNode(true); | 542 link = link.cloneNode(true); |
| 494 activeViews.appendChild(link); | 543 item.appendChild(link); |
| 495 } | 544 } |
| 496 }); | 545 }); |
| 497 } | 546 }); |
| 498 | 547 |
| 499 // The extension warnings (describing runtime issues). | 548 // The extension warnings (describing runtime issues). |
| 500 if (extension.warnings) { | 549 this.updateVisibility_(node, '.extension-warnings', !!extension.warnings, |
| 501 var panel = node.querySelector('.extension-warnings'); | 550 function(item) { |
| 502 panel.hidden = false; | 551 var warningList = item.querySelector('ul'); |
| 503 var list = panel.querySelector('ul'); | 552 warningList.textContent = ''; |
| 504 extension.warnings.forEach(function(warning) { | 553 extension.warnings.forEach(function(warning) { |
| 505 list.appendChild(document.createElement('li')).innerText = warning; | 554 var li = document.createElement('li'); |
| 555 warningList.appendChild(li).innerText = warning; | |
| 506 }); | 556 }); |
| 507 } | 557 }); |
| 508 | 558 |
| 509 // If the ErrorConsole is enabled, we should have manifest and/or runtime | 559 // If the ErrorConsole is enabled, we should have manifest and/or runtime |
| 510 // errors. Otherwise, we may have install warnings. We should not have | 560 // errors. Otherwise, we may have install warnings. We should not have |
| 511 // both ErrorConsole errors and install warnings. | 561 // both ErrorConsole errors and install warnings. |
| 512 if (extension.manifestErrors) { | 562 // Errors. |
| 513 var panel = node.querySelector('.manifest-errors'); | 563 this.updateErrors_(node.querySelector('.manifest-errors'), |
| 514 panel.hidden = false; | 564 extension.manifestErrors); |
|
Dan Beam
2015/02/12 20:46:19
indent off
hcarmona
2015/02/12 22:02:28
Done.
| |
| 515 panel.appendChild(new extensions.ExtensionErrorList( | 565 this.updateErrors_(node.querySelector('.runtime-errors'), |
| 516 extension.manifestErrors)); | 566 extension.runtimeErrors); |
| 517 } | |
| 518 if (extension.runtimeErrors) { | |
| 519 var panel = node.querySelector('.runtime-errors'); | |
| 520 panel.hidden = false; | |
| 521 panel.appendChild(new extensions.ExtensionErrorList( | |
| 522 extension.runtimeErrors)); | |
| 523 } | |
| 524 if (extension.installWarnings) { | |
| 525 var panel = node.querySelector('.install-warnings'); | |
| 526 panel.hidden = false; | |
| 527 var list = panel.querySelector('ul'); | |
| 528 extension.installWarnings.forEach(function(warning) { | |
| 529 var li = document.createElement('li'); | |
| 530 li.innerText = warning.message; | |
| 531 list.appendChild(li); | |
| 532 }); | |
| 533 } | |
| 534 | 567 |
| 535 this.appendChild(node); | 568 // Install warnings. |
| 569 this.updateVisibility_(node, '.install-warnings', | |
| 570 !!extension.installWarnings, function(item) { | |
| 571 var installWarningList = item.querySelector('ul'); | |
| 572 installWarningList.textContent = ''; | |
| 573 if (extension.installWarnings) { | |
| 574 extension.installWarnings.forEach(function(warning) { | |
| 575 var li = document.createElement('li'); | |
| 576 li.innerText = warning.message; | |
| 577 installWarningList.appendChild(li); | |
| 578 }); | |
| 579 } | |
| 580 }); | |
| 581 | |
| 536 if (location.hash.substr(1) == extension.id) { | 582 if (location.hash.substr(1) == extension.id) { |
| 537 // Scroll beneath the fixed header so that the extension is not | 583 // Scroll beneath the fixed header so that the extension is not |
| 538 // obscured. | 584 // obscured. |
| 539 var topScroll = node.offsetTop - $('page-header').offsetHeight; | 585 var topScroll = node.offsetTop - $('page-header').offsetHeight; |
| 540 var pad = parseInt(window.getComputedStyle(node, null).marginTop, 10); | 586 var pad = parseInt(window.getComputedStyle(node, null).marginTop, 10); |
| 541 if (!isNaN(pad)) | 587 if (!isNaN(pad)) |
| 542 topScroll -= pad / 2; | 588 topScroll -= pad / 2; |
| 543 setScrollTopForDocument(document, topScroll); | 589 setScrollTopForDocument(document, topScroll); |
| 544 } | 590 } |
| 545 }, | 591 }, |
| 546 | 592 |
| 547 /** | 593 /** |
| 594 * Adds a listener to an element. | |
| 595 * @param {string} type The type of listener to add. | |
| 596 * @param {Element} node Ancestor of the element specified by |query|. | |
| 597 * @param {string} query A query to select an element in |node|. | |
| 598 * @param {function(Event)} handler The function that should be called | |
| 599 * on click. | |
| 600 * @private | |
| 601 */ | |
| 602 addListener_: function(type, node, query, handler) { | |
| 603 node.querySelector(query).addEventListener(type, handler); | |
| 604 }, | |
| 605 | |
| 606 /** | |
| 607 * Updates an element's textContent. | |
| 608 * @param {Element} node Ancestor of the element specified by |query|. | |
| 609 * @param {string} query A query to select an element in |node|. | |
| 610 * @param {string} textContent | |
| 611 * @private | |
| 612 */ | |
| 613 setText_: function(node, query, textContent) { | |
| 614 node.querySelector(query).textContent = textContent; | |
| 615 }, | |
| 616 | |
| 617 /** | |
| 618 * Updates an element's visibility and calls |shownCallback| if it is | |
| 619 * visible. | |
| 620 * @param {Element} node Ancestor of the element specified by |query|. | |
| 621 * @param {string} query A query to select an element in |node|. | |
| 622 * @param {boolean} visible Whether the element should be visible or not. | |
| 623 * @param {function(Element)} [shownCallback] Callback if the element is | |
|
Dan Beam
2015/02/12 20:46:19
{function(Element)=} opt_shownCallback
hcarmona
2015/02/12 22:02:28
Done.
| |
| 624 * visible. The element passed in will be the element specified by | |
| 625 * |query|. | |
| 626 * @private | |
| 627 */ | |
| 628 updateVisibility_: function(node, query, visible, shownCallback) { | |
| 629 var item = assert(node.querySelector(query)); | |
| 630 item.hidden = !visible; | |
| 631 if (visible && shownCallback) | |
| 632 shownCallback(item); | |
| 633 }, | |
| 634 | |
| 635 /** | |
| 636 * Updates an element to show a list of errors. | |
| 637 * @param {Element} panel An element to hold the errors. | |
| 638 * @param {Array<RuntimeError>} [errors] The errors to be displayed. | |
|
Dan Beam
2015/02/12 20:46:20
= + opt_
hcarmona
2015/02/12 22:02:28
errors should not be optional. Updated the annotat
Dan Beam
2015/02/12 22:39:03
yeah, that's fine as well
| |
| 639 * @private | |
| 640 */ | |
| 641 updateErrors_: function(panel, errors) { | |
| 642 // TODO(hcarmona): Look into updating the ExtensionErrorList rather than | |
| 643 // rebuilding it every time. | |
| 644 panel.hidden = !errors || errors.length == 0; | |
| 645 panel.textContent = ''; | |
| 646 if (!panel.hidden) { | |
| 647 panel.appendChild( | |
| 648 new extensions.ExtensionErrorList(assertInstanceof(errors, Array))); | |
| 649 } | |
| 650 }, | |
| 651 | |
| 652 /** | |
| 548 * Opens the extension options overlay for the extension with the given id. | 653 * Opens the extension options overlay for the extension with the given id. |
| 549 * @param {string} extensionId The id of extension whose options page should | 654 * @param {string} extensionId The id of extension whose options page should |
| 550 * be displayed. | 655 * be displayed. |
| 551 * @param {boolean} scroll Whether the page should scroll to the extension | 656 * @param {boolean} scroll Whether the page should scroll to the extension |
| 552 * @private | 657 * @private |
| 553 */ | 658 */ |
| 554 showEmbeddedExtensionOptions_: function(extensionId, scroll) { | 659 showEmbeddedExtensionOptions_: function(extensionId, scroll) { |
| 555 if (this.optionsShown_) | 660 if (this.optionsShown_) |
| 556 return; | 661 return; |
| 557 | 662 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 591 // TODO(dbeam): why do we need to focus <extensionoptions> before and | 696 // TODO(dbeam): why do we need to focus <extensionoptions> before and |
| 592 // after its showing animation? Makes very little sense to me. | 697 // after its showing animation? Makes very little sense to me. |
| 593 overlay.setInitialFocus(); | 698 overlay.setInitialFocus(); |
| 594 }, | 699 }, |
| 595 }; | 700 }; |
| 596 | 701 |
| 597 return { | 702 return { |
| 598 ExtensionsList: ExtensionsList | 703 ExtensionsList: ExtensionsList |
| 599 }; | 704 }; |
| 600 }); | 705 }); |
| OLD | NEW |