OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 cr.define('options', function() { |
| 6 /** |
| 7 * Creates a new list of extensions. |
| 8 * @param {Object=} opt_propertyBag Optional properties. |
| 9 * @constructor |
| 10 * @extends {cr.ui.div} |
| 11 */ |
| 12 var ExtensionsList = cr.ui.define('div'); |
| 13 |
| 14 var handleInstalled = false; |
| 15 |
| 16 ExtensionsList.prototype = { |
| 17 __proto__: HTMLDivElement.prototype, |
| 18 |
| 19 /** @inheritDoc */ |
| 20 decorate: function() { |
| 21 this.initControlsAndHandlers_(); |
| 22 |
| 23 var showingDetails = []; |
| 24 var showingWarning = []; |
| 25 this.deleteExistingExtensionNodes_(showingDetails, showingWarning); |
| 26 |
| 27 this.showExtensionNodes_(showingDetails, showingWarning); |
| 28 }, |
| 29 |
| 30 /** |
| 31 * Initializes the controls (toggle section and button) and installs |
| 32 * handlers. |
| 33 * @private |
| 34 */ |
| 35 initControlsAndHandlers_: function() { |
| 36 // Make sure developer mode section is set correctly as per saved setting. |
| 37 var toggleButton = $('toggle-dev-on'); |
| 38 var toggleSection = $('dev'); |
| 39 if (this.data_.developerMode) { |
| 40 toggleSection.classList.add('dev-open'); |
| 41 toggleSection.classList.remove('dev-closed'); |
| 42 toggleButton.checked = true; |
| 43 } else { |
| 44 toggleSection.classList.remove('dev-open'); |
| 45 toggleSection.classList.add('dev-closed'); |
| 46 } |
| 47 |
| 48 // Install handler for key presses. |
| 49 if (!handleInstalled) { |
| 50 document.addEventListener('keyup', this.upEventHandler_.bind(this)); |
| 51 document.addEventListener('mouseup', this.upEventHandler_.bind(this)); |
| 52 handleInstalled = true; |
| 53 } |
| 54 }, |
| 55 |
| 56 /** |
| 57 * Deletes the existing Extension nodes from the page to make room for new |
| 58 * ones. It also keeps track of who was showing details so when the |
| 59 * extension list gets recreated we can recreate that state. |
| 60 * @param {Array} showingDetails An array that will contain the list of id's |
| 61 * of extension that had the details section expanded. |
| 62 * @param {Array} showingWarning An array that will contain the list of id's |
| 63 * of extension that were showing a warning. |
| 64 * @private |
| 65 */ |
| 66 deleteExistingExtensionNodes_: function(showingDetails, showingWarning) { |
| 67 // Delete all child nodes before adding them back and while we are at it |
| 68 // make a note of which ones were in expanded state (and which showing |
| 69 // the warning) so we can restore those to the same state afterwards. |
| 70 while (this.hasChildNodes()){ |
| 71 var child = this.firstChild; |
| 72 |
| 73 // See if the item is expanded. |
| 74 if (child.classList.contains('extension-list-item-expanded')) |
| 75 showingDetails.push(child.id); |
| 76 |
| 77 // See if the butterbar is showing. |
| 78 var butterBar = document.getElementById(child.id + '_incognitoWarning'); |
| 79 if (!(butterBar === null) && !butterBar.hidden) |
| 80 showingWarning.push(child.id); |
| 81 |
| 82 // Now we can delete it. |
| 83 this.removeChild(child); |
| 84 } |
| 85 }, |
| 86 |
| 87 /** |
| 88 * Handles decorating the details section. |
| 89 * @param {Element} details The div that the details should be attached to. |
| 90 * @param {Object} extension The extension we are shoting the details for. |
| 91 * @param {boolean} expanded Whether to show the details expanded or not. |
| 92 * @param {boolean} showButterbar Whether to show the incognito warning or |
| 93 * not. |
| 94 * @private |
| 95 */ |
| 96 showExtensionNodes_: function(showingDetails, showingWarning) { |
| 97 // Keeps track of differences in checkbox width. |
| 98 var minCheckboxWidth = 999999; |
| 99 var maxCheckboxWidth = 0; |
| 100 |
| 101 // Iterate over the extension data and add each item to the list. |
| 102 for (var i = 0; i < this.data_.extensions.length; ++i) { |
| 103 var extension = this.data_.extensions[i]; |
| 104 var id = extension.id; |
| 105 |
| 106 var wrapper = this.ownerDocument.createElement('div'); |
| 107 |
| 108 // Figure out if the item should open expanded or not based on the state |
| 109 // of things before we deleted the items. |
| 110 var iter = showingDetails.length; |
| 111 var expanded = false; |
| 112 while (iter--) { |
| 113 if (showingDetails[iter] == id) { |
| 114 expanded = true; |
| 115 break; |
| 116 } |
| 117 } |
| 118 // Figure out if the butterbar should be showing. |
| 119 iter = showingWarning.length; |
| 120 var butterbar = false; |
| 121 while (iter--) { |
| 122 if (showingWarning[iter] == id) { |
| 123 butterbar = true; |
| 124 break; |
| 125 } |
| 126 } |
| 127 |
| 128 wrapper.classList.add(expanded ? 'extension-list-item-expanded' : |
| 129 'extension-list-item-collaped'); |
| 130 if (!extension.enabled) |
| 131 wrapper.classList.add('disabled'); |
| 132 wrapper.id = id; |
| 133 this.appendChild(wrapper); |
| 134 |
| 135 var vbox_outer = this.ownerDocument.createElement('div'); |
| 136 vbox_outer.classList.add('vbox'); |
| 137 vbox_outer.classList.add('extension-list-item'); |
| 138 wrapper.appendChild(vbox_outer); |
| 139 |
| 140 var hbox = this.ownerDocument.createElement('div'); |
| 141 hbox.classList.add('hbox'); |
| 142 vbox_outer.appendChild(hbox); |
| 143 |
| 144 // Add a container div for the zippy, so we can extend the hit area. |
| 145 var container = this.ownerDocument.createElement('div'); |
| 146 // Clicking anywhere on the div expands/collapses the details. |
| 147 container.classList.add('extension-zippy-container'); |
| 148 container.addEventListener('click', this.handleZippyClick_.bind(this)); |
| 149 hbox.appendChild(container); |
| 150 |
| 151 // On the far left we have the zippy icon. |
| 152 div = this.ownerDocument.createElement('div'); |
| 153 div.id = id + '_zippy'; |
| 154 div.classList.add('extension-zippy-default'); |
| 155 div.classList.add(expanded ? 'extension-zippy-expanded' : |
| 156 'extension-zippy-collapsed'); |
| 157 container.appendChild(div); |
| 158 |
| 159 // Next to it, we have the extension icon. |
| 160 icon = this.ownerDocument.createElement('img'); |
| 161 icon.classList.add('extension-icon'); |
| 162 icon.src = extension.icon; |
| 163 hbox.appendChild(icon); |
| 164 |
| 165 // Start a vertical box for showing the details. |
| 166 var vbox = this.ownerDocument.createElement('div'); |
| 167 vbox.classList.add('vbox'); |
| 168 vbox.classList.add('stretch'); |
| 169 hbox.appendChild(vbox); |
| 170 |
| 171 div = this.ownerDocument.createElement('div'); |
| 172 vbox.appendChild(div); |
| 173 |
| 174 // Title comes next. |
| 175 var title = this.ownerDocument.createElement('span'); |
| 176 title.classList.add('extension-title'); |
| 177 title.textContent = extension.name; |
| 178 vbox.appendChild(title); |
| 179 |
| 180 // Followed by version. |
| 181 var version = this.ownerDocument.createElement('span'); |
| 182 version.classList.add('extension-version'); |
| 183 version.textContent = extension.version; |
| 184 vbox.appendChild(version); |
| 185 |
| 186 div = this.ownerDocument.createElement('div'); |
| 187 vbox.appendChild(div); |
| 188 |
| 189 // And below that we have description (if provided). |
| 190 if (extension.description.length > 0) { |
| 191 var description = this.ownerDocument.createElement('span'); |
| 192 description.classList.add('extension-description'); |
| 193 description.textContent = extension.description; |
| 194 vbox.appendChild(description); |
| 195 } |
| 196 |
| 197 // Immediately following the description, we have the |
| 198 // Options link (optional). |
| 199 if (extension.options_url) { |
| 200 var link = this.ownerDocument.createElement('a'); |
| 201 link.classList.add('extension-links-trailing'); |
| 202 link.textContent = localStrings.getString('extensionSettingsOptions'); |
| 203 link.href = '#'; |
| 204 link.addEventListener('click', this.handleOptions_.bind(this)); |
| 205 vbox.appendChild(link); |
| 206 } |
| 207 |
| 208 // Then the optional Visit Website link. |
| 209 if (extension.homepageUrl) { |
| 210 var link = this.ownerDocument.createElement('a'); |
| 211 link.classList.add('extension-links-trailing'); |
| 212 link.textContent = |
| 213 localStrings.getString('extensionSettingsVisitWebsite'); |
| 214 link.href = '#'; |
| 215 link.addEventListener('click', this.handleVisitWebsite_.bind(this)); |
| 216 vbox.appendChild(link); |
| 217 } |
| 218 |
| 219 // And now the details section that is normally hidden. |
| 220 var details = this.ownerDocument.createElement('div'); |
| 221 details.classList.add('vbox'); |
| 222 vbox.appendChild(details); |
| 223 |
| 224 this.decorateDetailsSection_(details, extension, expanded, butterbar); |
| 225 |
| 226 // And on the right of the details we have the Enable/Enabled checkbox. |
| 227 div = this.ownerDocument.createElement('div'); |
| 228 hbox.appendChild(div); |
| 229 |
| 230 var section = this.ownerDocument.createElement('section'); |
| 231 section.classList.add('extension-enabling'); |
| 232 div.appendChild(section); |
| 233 |
| 234 // The Enable checkbox. |
| 235 var input = this.ownerDocument.createElement('input'); |
| 236 input.addEventListener('click', this.handleEnable_.bind(this)); |
| 237 input.type = 'checkbox'; |
| 238 input.name = 'toggle-' + id; |
| 239 if (!extension.mayDisable) |
| 240 input.disabled = true; |
| 241 if (extension.enabled) |
| 242 input.checked = true; |
| 243 input.id = 'toggle-' + id; |
| 244 section.appendChild(input); |
| 245 var label = this.ownerDocument.createElement('label'); |
| 246 label.classList.add('extension-enabling-label'); |
| 247 if (extension.enabled) |
| 248 label.classList.add('extension-enabling-label-bold'); |
| 249 label.setAttribute('for', 'toggle-' + id); |
| 250 label.id = 'toggle-' + id + '-label'; |
| 251 if (extension.enabled) { |
| 252 // Enabled (with a d). |
| 253 label.textContent = |
| 254 localStrings.getString('extensionSettingsEnabled'); |
| 255 } else { |
| 256 // Enable (no d). |
| 257 label.textContent = localStrings.getString('extensionSettingsEnable'); |
| 258 } |
| 259 section.appendChild(label); |
| 260 |
| 261 if (label.offsetWidth > maxCheckboxWidth) |
| 262 maxCheckboxWidth = label.offsetWidth; |
| 263 if (label.offsetWidth < minCheckboxWidth) |
| 264 minCheckboxWidth = label.offsetWidth; |
| 265 |
| 266 // And, on the far right we have the uninstall button. |
| 267 var button = this.ownerDocument.createElement('button'); |
| 268 button.classList.add('extension-delete'); |
| 269 button.id = id; |
| 270 if (!extension.mayDisable) |
| 271 button.disabled = true; |
| 272 button.textContent = localStrings.getString('extensionSettingsRemove'); |
| 273 button.addEventListener('click', this.handleUninstall_.bind(this)); |
| 274 hbox.appendChild(button); |
| 275 } |
| 276 |
| 277 // Do another pass, making sure checkboxes line up. |
| 278 var difference = maxCheckboxWidth - minCheckboxWidth; |
| 279 for (var i = 0; i < this.data_.extensions.length; ++i) { |
| 280 var extension = this.data_.extensions[i]; |
| 281 var id = extension.id; |
| 282 var label = $('toggle-' + id + '-label'); |
| 283 if (label.offsetWidth < maxCheckboxWidth) |
| 284 label.style.marginRight = difference.toString() + 'px'; |
| 285 } |
| 286 }, |
| 287 |
| 288 /** |
| 289 * Handles decorating the details section. |
| 290 * @param {Element} details The div that the details should be attached to. |
| 291 * @param {Object} extension The extension we are shoting the details for. |
| 292 * @param {boolean} expanded Whether to show the details expanded or not. |
| 293 * @param {boolean} showButterbar Whether to show the incognito warning or |
| 294 * not. |
| 295 * @private |
| 296 */ |
| 297 decorateDetailsSection_: function(details, extension, |
| 298 expanded, showButterbar) { |
| 299 // This container div is needed because vbox display |
| 300 // overrides display:hidden. |
| 301 var details_contents = this.ownerDocument.createElement('div'); |
| 302 details_contents.classList.add(expanded ? 'extension-details-visible' : |
| 303 'extension-details-hidden'); |
| 304 details_contents.id = extension.id + '_details'; |
| 305 details.appendChild(details_contents); |
| 306 |
| 307 var div = this.ownerDocument.createElement('div'); |
| 308 div.classList.add('informative-text'); |
| 309 details_contents.appendChild(div); |
| 310 |
| 311 // Keep track of how many items we'll show in the details section. |
| 312 var itemsShown = 0; |
| 313 |
| 314 if (this.data_.developerMode) { |
| 315 // First we have the id. |
| 316 var content = this.ownerDocument.createElement('div'); |
| 317 content.textContent = |
| 318 localStrings.getString('extensionSettingsExtensionId') + |
| 319 ' ' + extension.id; |
| 320 div.appendChild(content); |
| 321 itemsShown++; |
| 322 |
| 323 // Then, the path, if provided by unpacked extension. |
| 324 if (extension.isUnpacked) { |
| 325 content = this.ownerDocument.createElement('div'); |
| 326 content.textContent = |
| 327 localStrings.getString('extensionSettingsExtensionPath') + |
| 328 ' ' + extension.path; |
| 329 div.appendChild(content); |
| 330 itemsShown++; |
| 331 } |
| 332 |
| 333 // Then, the 'managed, cannot uninstall/disable' message. |
| 334 if (!extension.mayDisable) { |
| 335 content = this.ownerDocument.createElement('div'); |
| 336 content.textContent = |
| 337 localStrings.getString('extensionSettingsPolicyControlled'); |
| 338 div.appendChild(content); |
| 339 itemsShown++; |
| 340 } |
| 341 |
| 342 // Then active views: |
| 343 if (extension.views.length > 0) { |
| 344 var table = this.ownerDocument.createElement('table'); |
| 345 table.classList.add('extension-inspect-table'); |
| 346 div.appendChild(table); |
| 347 var tr = this.ownerDocument.createElement('tr'); |
| 348 table.appendChild(tr); |
| 349 var td = this.ownerDocument.createElement('td'); |
| 350 td.classList.add('extension-inspect-left-column'); |
| 351 tr.appendChild(td); |
| 352 var span = this.ownerDocument.createElement('span'); |
| 353 td.appendChild(span); |
| 354 span.textContent = |
| 355 localStrings.getString('extensionSettingsInspectViews'); |
| 356 |
| 357 td = this.ownerDocument.createElement('td'); |
| 358 for (var i = 0; i < extension.views.length; ++i) { |
| 359 // Then active views: |
| 360 content = this.ownerDocument.createElement('div'); |
| 361 var link = this.ownerDocument.createElement('a'); |
| 362 link.classList.add('extension-links-view'); |
| 363 link.textContent = extension.views[i].path; |
| 364 link.id = extension.id; |
| 365 link.href = '#'; |
| 366 link.addEventListener('click', this.sendInspectMessage_.bind(this)); |
| 367 content.appendChild(link); |
| 368 td.appendChild(content); |
| 369 tr.appendChild(td); |
| 370 |
| 371 itemsShown++; |
| 372 } |
| 373 } |
| 374 } |
| 375 |
| 376 var content = this.ownerDocument.createElement('div'); |
| 377 details_contents.appendChild(content); |
| 378 |
| 379 // Then Reload: |
| 380 if (extension.enabled && extension.allow_reload) { |
| 381 var link = this.ownerDocument.createElement('a'); |
| 382 link.classList.add('extension-links-trailing'); |
| 383 link.textContent = localStrings.getString('extensionSettingsReload'); |
| 384 link.id = extension.id; |
| 385 link.href = '#'; |
| 386 link.addEventListener('click', this.handleReload_.bind(this)); |
| 387 content.appendChild(link); |
| 388 itemsShown++; |
| 389 } |
| 390 |
| 391 // Then Show (Browser Action) Button: |
| 392 if (extension.enabled && extension.enable_show_button) { |
| 393 link = this.ownerDocument.createElement('a'); |
| 394 link.classList.add('extension-links-trailing'); |
| 395 link.textContent = |
| 396 localStrings.getString('extensionSettingsShowButton'); |
| 397 link.id = extension.id; |
| 398 link.href = '#'; |
| 399 link.addEventListener('click', this.handleShowButton_.bind(this)); |
| 400 content.appendChild(link); |
| 401 itemsShown++; |
| 402 } |
| 403 |
| 404 if (extension.enabled && !extension.wantsFileAccess) { |
| 405 // The 'allow in incognito' checkbox. |
| 406 var label = this.ownerDocument.createElement('label'); |
| 407 label.classList.add('extension-checkbox-label'); |
| 408 content.appendChild(label); |
| 409 var input = this.ownerDocument.createElement('input'); |
| 410 input.addEventListener('click', |
| 411 this.handleToggleEnableIncognito_.bind(this)); |
| 412 input.id = extension.id; |
| 413 input.type = 'checkbox'; |
| 414 if (extension.enabledIncognito) |
| 415 input.checked = true; |
| 416 label.appendChild(input); |
| 417 var span = this.ownerDocument.createElement('span'); |
| 418 span.classList.add('extension-checkbox-span'); |
| 419 span.textContent = |
| 420 localStrings.getString('extensionSettingsEnableIncognito'); |
| 421 label.appendChild(span); |
| 422 itemsShown++; |
| 423 } |
| 424 |
| 425 if (extension.enabled && !extension.wantsFileAccess) { |
| 426 // The 'allow access to file URLs' checkbox. |
| 427 label = this.ownerDocument.createElement('label'); |
| 428 label.classList.add('extension-checkbox-label'); |
| 429 content.appendChild(label); |
| 430 var input = this.ownerDocument.createElement('input'); |
| 431 input.addEventListener('click', |
| 432 this.handleToggleAllowFileUrls_.bind(this)); |
| 433 input.id = extension.id; |
| 434 input.type = 'checkbox'; |
| 435 if (extension.allowFileAccess) |
| 436 input.checked = true; |
| 437 label.appendChild(input); |
| 438 var span = this.ownerDocument.createElement('span'); |
| 439 span.classList.add('extension-checkbox-span'); |
| 440 span.textContent = |
| 441 localStrings.getString('extensionSettingsAllowFileAccess'); |
| 442 label.appendChild(span); |
| 443 itemsShown++; |
| 444 } |
| 445 |
| 446 if (extension.enabled && !extension.is_hosted_app) { |
| 447 // And add a hidden warning message for allowInIncognito. |
| 448 content = this.ownerDocument.createElement('div'); |
| 449 content.id = extension.id + '_incognitoWarning'; |
| 450 content.classList.add('butter-bar'); |
| 451 content.hidden = !showButterbar; |
| 452 details_contents.appendChild(content); |
| 453 |
| 454 var span = this.ownerDocument.createElement('span'); |
| 455 span.innerHTML = |
| 456 localStrings.getString('extensionSettingsIncognitoWarning'); |
| 457 content.appendChild(span); |
| 458 itemsShown++; |
| 459 } |
| 460 |
| 461 var zippy = extension.id + '_zippy'; |
| 462 $(zippy).style.display = (itemsShown > 0) ? 'block' : 'none'; |
| 463 }, |
| 464 |
| 465 /** |
| 466 * A lookup helper function to find an extension based on an id. |
| 467 * @param {string} id The |id| of the extension to look up. |
| 468 * @private |
| 469 */ |
| 470 getExtensionWithId_: function(id) { |
| 471 for (var i = 0; i < this.data_.extensions.length; ++i) { |
| 472 if (this.data_.extensions[i].id == id) |
| 473 return this.data_.extensions[i]; |
| 474 } |
| 475 return null; |
| 476 }, |
| 477 |
| 478 /** |
| 479 * A lookup helper function to find the first node that has an id (starting |
| 480 * at |node| and going up the parent chain. |
| 481 * @param {Element} node The node to start looking at. |
| 482 * @private |
| 483 */ |
| 484 findIdNode_: function(node) { |
| 485 while (node.id.length == 0) { |
| 486 node = node.parentNode; |
| 487 if (!node) |
| 488 return null; |
| 489 } |
| 490 return node; |
| 491 }, |
| 492 |
| 493 /** |
| 494 * Handles the mouseclick on the zippy icon (that expands and collapses the |
| 495 * details section). |
| 496 * @param {Event} e Change event. |
| 497 * @private |
| 498 */ |
| 499 handleZippyClick_: function(e) { |
| 500 var node = this.findIdNode_(e.target.parentNode); |
| 501 var iter = this.firstChild; |
| 502 while (iter) { |
| 503 var zippy = $(iter.id + '_zippy'); |
| 504 var details = $(iter.id + '_details'); |
| 505 if (iter.id == node.id) { |
| 506 // Toggle visibility. |
| 507 if (iter.classList.contains('extension-list-item-expanded')) { |
| 508 // Hide yo kids! Hide yo wife! |
| 509 zippy.classList.remove('extension-zippy-expanded'); |
| 510 zippy.classList.add('extension-zippy-collapsed'); |
| 511 details.classList.remove('extension-details-visible'); |
| 512 details.classList.add('extension-details-hidden'); |
| 513 iter.classList.remove('extension-list-item-expanded'); |
| 514 iter.classList.add('extension-list-item-collaped'); |
| 515 |
| 516 // Hide yo incognito warning. |
| 517 var butterBar = this.ownerDocument.getElementById( |
| 518 iter.id + '_incognitoWarning'); |
| 519 if (!(butterBar === null)) |
| 520 butterBar.hidden = true; |
| 521 } else { |
| 522 // Show the contents. |
| 523 zippy.classList.remove('extension-zippy-collapsed'); |
| 524 zippy.classList.add('extension-zippy-expanded'); |
| 525 details.classList.remove('extension-details-hidden'); |
| 526 details.classList.add('extension-details-visible'); |
| 527 iter.classList.remove('extension-list-item-collaped'); |
| 528 iter.classList.add('extension-list-item-expanded'); |
| 529 } |
| 530 } |
| 531 iter = iter.nextSibling; |
| 532 } |
| 533 }, |
| 534 |
| 535 /** |
| 536 * Handles the mouse-up and keyboard-up events. This is used to limit the |
| 537 * number of items to show in the list, when the user is searching for items |
| 538 * with the search box. Otherwise, if one match is found, the whole list of |
| 539 * extensions would be shown when we only want the matching items to be |
| 540 * found. |
| 541 * @param {Event} e Change event. |
| 542 * @private |
| 543 */ |
| 544 upEventHandler_: function(e) { |
| 545 var searchString = $('search-field').value.toLowerCase(); |
| 546 var child = this.firstChild; |
| 547 while (child){ |
| 548 var extension = this.getExtensionWithId_(child.id); |
| 549 if (searchString.length == 0) { |
| 550 // Show all. |
| 551 child.classList.remove('search-suppress'); |
| 552 } else { |
| 553 // If the search string does not appear within the text of the |
| 554 // extension, then hide it. |
| 555 if ((extension.name.toLowerCase().indexOf(searchString) < 0) && |
| 556 (extension.version.toLowerCase().indexOf(searchString) < 0) && |
| 557 (extension.description.toLowerCase().indexOf(searchString) < 0)) { |
| 558 // Hide yo extension! |
| 559 child.classList.add('search-suppress'); |
| 560 } else { |
| 561 // Show yourself! |
| 562 child.classList.remove('search-suppress'); |
| 563 } |
| 564 } |
| 565 child = child.nextSibling; |
| 566 } |
| 567 }, |
| 568 |
| 569 /** |
| 570 * Handles the Reload Extension functionality. |
| 571 * @param {Event} e Change event. |
| 572 * @private |
| 573 */ |
| 574 handleReload_: function(e) { |
| 575 var node = this.findIdNode_(e.target); |
| 576 chrome.send('extensionSettingsReload', [node.id]); |
| 577 }, |
| 578 |
| 579 /** |
| 580 * Handles the Show (Browser Action) Button functionality. |
| 581 * @param {Event} e Change event. |
| 582 * @private |
| 583 */ |
| 584 handleShowButton_: function(e) { |
| 585 var node = this.findIdNode_(e.target); |
| 586 chrome.send('extensionSettingsShowButton', [node.id]); |
| 587 }, |
| 588 |
| 589 /** |
| 590 * Handles the Enable/Disable Extension functionality. |
| 591 * @param {Event} e Change event. |
| 592 * @private |
| 593 */ |
| 594 handleEnable_: function(e) { |
| 595 var node = this.findIdNode_(e.target.parentNode); |
| 596 var extension = this.getExtensionWithId_(node.id); |
| 597 chrome.send('extensionSettingsEnable', |
| 598 [node.id, extension.enabled ? 'false' : 'true']); |
| 599 chrome.send('extensionSettingsRequestExtensionsData'); |
| 600 }, |
| 601 |
| 602 /** |
| 603 * Handles the Uninstall Extension functionality. |
| 604 * @param {Event} e Change event. |
| 605 * @private |
| 606 */ |
| 607 handleUninstall_: function(e) { |
| 608 var node = this.findIdNode_(e.target.parentNode); |
| 609 chrome.send('extensionSettingsUninstall', [node.id]); |
| 610 chrome.send('extensionSettingsRequestExtensionsData'); |
| 611 }, |
| 612 |
| 613 /** |
| 614 * Handles the View Options link. |
| 615 * @param {Event} e Change event. |
| 616 * @private |
| 617 */ |
| 618 handleOptions_: function(e) { |
| 619 var node = this.findIdNode_(e.target.parentNode); |
| 620 var extension = this.getExtensionWithId_(node.id); |
| 621 chrome.send('extensionSettingsOptions', [extension.id]); |
| 622 }, |
| 623 |
| 624 /** |
| 625 * Handles the Visit Extension Website link. |
| 626 * @param {Event} e Change event. |
| 627 * @private |
| 628 */ |
| 629 handleVisitWebsite_: function(e) { |
| 630 var node = this.findIdNode_(e.target.parentNode); |
| 631 var extension = this.getExtensionWithId_(node.id); |
| 632 document.location = extension.homepageUrl; |
| 633 }, |
| 634 |
| 635 /** |
| 636 * Handles the Enable Extension In Incognito functionality. |
| 637 * @param {Event} e Change event. |
| 638 * @private |
| 639 */ |
| 640 handleToggleEnableIncognito_: function(e) { |
| 641 var node = this.findIdNode_(e.target); |
| 642 var butterBar = document.getElementById(node.id + '_incognitoWarning'); |
| 643 butterBar.hidden = !e.target.checked; |
| 644 chrome.send('extensionSettingsEnableIncognito', |
| 645 [node.id, String(e.target.checked)]); |
| 646 }, |
| 647 |
| 648 /** |
| 649 * Handles the Allow On File URLs functionality. |
| 650 * @param {Event} e Change event. |
| 651 * @private |
| 652 */ |
| 653 handleToggleAllowFileUrls_: function(e) { |
| 654 var node = this.findIdNode_(e.target); |
| 655 chrome.send('extensionSettingsAllowFileAccess', |
| 656 [node.id, String(e.target.checked)]); |
| 657 }, |
| 658 |
| 659 /** |
| 660 * Tell the C++ ExtensionDOMHandler to inspect the page detailed in |
| 661 * |viewData|. |
| 662 * @param {Event} e Change event. |
| 663 * @private |
| 664 */ |
| 665 sendInspectMessage_: function(e) { |
| 666 var extension = this.getExtensionWithId_(e.srcElement.id); |
| 667 for (var i = 0; i < extension.views.length; ++i) { |
| 668 if (extension.views[i].path == e.srcElement.innerText) { |
| 669 // TODO(aa): This is ghetto, but WebUIBindings doesn't support sending |
| 670 // anything other than arrays of strings, and this is all going to get |
| 671 // replaced with V8 extensions soon anyway. |
| 672 chrome.send('extensionSettingsInspect', [ |
| 673 String(extension.views[i].renderProcessId), |
| 674 String(extension.views[i].renderViewId) |
| 675 ]); |
| 676 } |
| 677 } |
| 678 }, |
| 679 }; |
| 680 |
| 681 return { |
| 682 ExtensionsList: ExtensionsList |
| 683 }; |
| 684 }); |
OLD | NEW |