home *** CD-ROM | disk | FTP | other *** search
/ Freelog 115 / FreelogNo115-MaiJuin2013.iso / Internet / AvantBrowser / asetup.exe / _data / webkit / chrome.dll / 0 / BINDATA / 528 < prev    next >
Encoding:
Text File  |  2013-04-03  |  11.6 KB  |  331 lines

  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
  3. // found in the LICENSE file.
  4.  
  5. cr.define('options', function() {
  6.   'use strict';
  7.  
  8.   /**
  9.    * A lookup helper function to find the first node that has an id (starting
  10.    * at |node| and going up the parent chain).
  11.    * @param {Element} node The node to start looking at.
  12.    */
  13.   function findIdNode(node) {
  14.     while (node && !node.id) {
  15.       node = node.parentNode;
  16.     }
  17.     return node;
  18.   }
  19.  
  20.   /**
  21.    * Creates a new list of extensions.
  22.    * @param {Object=} opt_propertyBag Optional properties.
  23.    * @constructor
  24.    * @extends {cr.ui.div}
  25.    */
  26.   var ExtensionsList = cr.ui.define('div');
  27.  
  28.   /**
  29.    * @type {Object.<string, boolean>} A map from extension id to a boolean
  30.    *     indicating whether the incognito warning is showing. This persists
  31.    *     between calls to decorate.
  32.    */
  33.   var butterBarVisibility = {};
  34.  
  35.   ExtensionsList.prototype = {
  36.     __proto__: HTMLDivElement.prototype,
  37.  
  38.     /** @override */
  39.     decorate: function() {
  40.       this.textContent = '';
  41.  
  42.       this.showExtensionNodes_();
  43.     },
  44.  
  45.     getIdQueryParam_: function() {
  46.       return parseQueryParams(document.location)['id'];
  47.     },
  48.  
  49.     /**
  50.      * Creates all extension items from scratch.
  51.      * @private
  52.      */
  53.     showExtensionNodes_: function() {
  54.       // Iterate over the extension data and add each item to the list.
  55.       this.data_.extensions.forEach(this.createNode_, this);
  56.  
  57.       var id_to_highlight = this.getIdQueryParam_();
  58.       if (id_to_highlight) {
  59.         // Scroll offset should be calculated slightly higher than the actual
  60.         // offset of the element being scrolled to, so that it ends up not all
  61.         // the way at the top. That way it is clear that there are more elements
  62.         // above the element being scrolled to.
  63.         var scroll_fudge = 1.2;
  64.         var offset = $(id_to_highlight).offsetTop -
  65.                      (scroll_fudge * $(id_to_highlight).clientHeight);
  66.         var wrapper = this.parentNode;
  67.         var list = wrapper.parentNode;
  68.         list.scrollTop = offset;
  69.       }
  70.  
  71.       if (this.data_.extensions.length == 0)
  72.         this.classList.add('empty-extension-list');
  73.       else
  74.         this.classList.remove('empty-extension-list');
  75.     },
  76.  
  77.     /**
  78.      * Synthesizes and initializes an HTML element for the extension metadata
  79.      * given in |extension|.
  80.      * @param {Object} extension A dictionary of extension metadata.
  81.      * @private
  82.      */
  83.     createNode_: function(extension) {
  84.       var template = $('template-collection').querySelector(
  85.           '.extension-list-item-wrapper');
  86.       var node = template.cloneNode(true);
  87.       node.id = extension.id;
  88.  
  89.       if (!extension.enabled || extension.terminated)
  90.         node.classList.add('inactive-extension');
  91.  
  92.       if (!extension.userModifiable)
  93.         node.classList.add('may-not-disable');
  94.  
  95.       var id_to_highlight = this.getIdQueryParam_();
  96.       if (node.id == id_to_highlight)
  97.         node.classList.add('extension-highlight');
  98.  
  99.       var item = node.querySelector('.extension-list-item');
  100.       item.style.backgroundImage = 'url(' + extension.icon + ')';
  101.  
  102.       var title = node.querySelector('.extension-title');
  103.       title.textContent = extension.name;
  104.  
  105.       var version = node.querySelector('.extension-version');
  106.       version.textContent = extension.version;
  107.  
  108.       var disableReason = node.querySelector('.extension-disable-reason');
  109.       disableReason.textContent = extension.disableReason;
  110.  
  111.       var locationText = node.querySelector('.location-text');
  112.       locationText.textContent = extension.locationText;
  113.  
  114.       var description = node.querySelector('.extension-description span');
  115.       description.textContent = extension.description;
  116.  
  117.       // The 'Show Browser Action' button.
  118.       if (extension.enable_show_button) {
  119.         var showButton = node.querySelector('.show-button');
  120.         showButton.addEventListener('click', function(e) {
  121.           chrome.send('extensionSettingsShowButton', [extension.id]);
  122.         });
  123.         showButton.hidden = false;
  124.       }
  125.  
  126.       // The 'allow in incognito' checkbox.
  127.       var incognito = node.querySelector('.incognito-control input');
  128.       incognito.disabled = !extension.incognitoCanBeEnabled;
  129.       incognito.checked = extension.enabledIncognito;
  130.       if (!incognito.disabled) {
  131.         incognito.addEventListener('change', function(e) {
  132.           var checked = e.target.checked;
  133.           butterBarVisibility[extension.id] = checked;
  134.           butterBar.hidden = !checked || extension.is_hosted_app;
  135.           chrome.send('extensionSettingsEnableIncognito',
  136.                       [extension.id, String(checked)]);
  137.         });
  138.       }
  139.       var butterBar = node.querySelector('.butter-bar');
  140.       butterBar.hidden = !butterBarVisibility[extension.id];
  141.  
  142.       // The 'allow file:// access' checkbox.
  143.       if (extension.wantsFileAccess) {
  144.         var fileAccess = node.querySelector('.file-access-control');
  145.         fileAccess.addEventListener('click', function(e) {
  146.           chrome.send('extensionSettingsAllowFileAccess',
  147.                       [extension.id, String(e.target.checked)]);
  148.         });
  149.         fileAccess.querySelector('input').checked = extension.allowFileAccess;
  150.         fileAccess.hidden = false;
  151.       }
  152.  
  153.       // The 'Options' checkbox.
  154.       if (extension.enabled && extension.optionsUrl) {
  155.         var options = node.querySelector('.options-link');
  156.         options.addEventListener('click', function(e) {
  157.           chrome.send('extensionSettingsOptions', [extension.id]);
  158.           e.preventDefault();
  159.         });
  160.         options.hidden = false;
  161.       }
  162.  
  163.       if (extension.allow_activity) {
  164.         var activity = node.querySelector('.activity-link');
  165.         activity.addEventListener('click', function(e) {
  166.           chrome.send('navigateToUrl', [
  167.             'chrome://extension-activity?extensionId=' + extension.id,
  168.             '_blank',
  169.             e.button,
  170.             e.altKey,
  171.             e.ctrlKey,
  172.             e.metaKey,
  173.             e.shiftKey
  174.           ]);
  175.           e.preventDefault();
  176.         });
  177.         activity.hidden = false;
  178.       }
  179.  
  180.       // The 'View in Web Store/View Web Site' link.
  181.       if (extension.homepageUrl) {
  182.         var siteLink = node.querySelector('.site-link');
  183.         siteLink.href = extension.homepageUrl;
  184.         siteLink.textContent = loadTimeData.getString(
  185.                 extension.homepageProvided ? 'extensionSettingsVisitWebsite' :
  186.                                              'extensionSettingsVisitWebStore');
  187.         siteLink.hidden = false;
  188.       }
  189.  
  190.       if (extension.allow_reload) {
  191.         // The 'Reload' link.
  192.         var reload = node.querySelector('.reload-link');
  193.         reload.addEventListener('click', function(e) {
  194.           chrome.send('extensionSettingsReload', [extension.id]);
  195.         });
  196.         reload.hidden = false;
  197.  
  198.         if (extension.is_platform_app) {
  199.           // The 'Launch' link.
  200.           var launch = node.querySelector('.launch-link');
  201.           launch.addEventListener('click', function(e) {
  202.             chrome.send('extensionSettingsLaunch', [extension.id]);
  203.           });
  204.           launch.hidden = false;
  205.  
  206.           // The 'Restart' link.
  207.           var restart = node.querySelector('.restart-link');
  208.           restart.addEventListener('click', function(e) {
  209.             chrome.send('extensionSettingsRestart', [extension.id]);
  210.           });
  211.           restart.hidden = false;
  212.         }
  213.       }
  214.  
  215.       if (!extension.terminated) {
  216.         // The 'Enabled' checkbox.
  217.         var enable = node.querySelector('.enable-checkbox');
  218.         enable.hidden = false;
  219.         enable.querySelector('input').disabled = !extension.userModifiable;
  220.  
  221.         if (extension.userModifiable) {
  222.           enable.addEventListener('click', function(e) {
  223.             chrome.send('extensionSettingsEnable',
  224.                         [extension.id, e.target.checked ? 'true' : 'false']);
  225.  
  226.             // This may seem counter-intuitive (to not set/clear the checkmark)
  227.             // but this page will be updated asynchronously if the extension
  228.             // becomes enabled/disabled. It also might not become enabled or
  229.             // disabled, because the user might e.g. get prompted when enabling
  230.             // and choose not to.
  231.             e.preventDefault();
  232.           });
  233.         }
  234.  
  235.         enable.querySelector('input').checked = extension.enabled;
  236.       } else {
  237.         var terminated_reload = node.querySelector('.terminated-reload-link');
  238.         terminated_reload.hidden = false;
  239.         terminated_reload.addEventListener('click', function(e) {
  240.           chrome.send('extensionSettingsReload', [extension.id]);
  241.         });
  242.       }
  243.  
  244.       // 'Remove' button.
  245.       var trashTemplate = $('template-collection').querySelector('.trash');
  246.       var trash = trashTemplate.cloneNode(true);
  247.       trash.title = loadTimeData.getString('extensionUninstall');
  248.       trash.addEventListener('click', function(e) {
  249.         chrome.send('extensionSettingsUninstall', [extension.id]);
  250.       });
  251.       node.querySelector('.enable-controls').appendChild(trash);
  252.  
  253.       // Developer mode ////////////////////////////////////////////////////////
  254.  
  255.       // First we have the id.
  256.       var idLabel = node.querySelector('.extension-id');
  257.       idLabel.textContent = ' ' + extension.id;
  258.  
  259.       // Then the path, if provided by unpacked extension.
  260.       if (extension.isUnpacked) {
  261.         var loadPath = node.querySelector('.load-path');
  262.         loadPath.hidden = false;
  263.         loadPath.querySelector('span:nth-of-type(2)').textContent =
  264.             ' ' + extension.path;
  265.       }
  266.  
  267.       // Then the 'managed, cannot uninstall/disable' message.
  268.       if (!extension.userModifiable)
  269.         node.querySelector('.managed-message').hidden = false;
  270.  
  271.       // Then active views.
  272.       if (extension.views.length > 0) {
  273.         var activeViews = node.querySelector('.active-views');
  274.         activeViews.hidden = false;
  275.         var link = activeViews.querySelector('a');
  276.  
  277.         extension.views.forEach(function(view, i) {
  278.           var label = view.path +
  279.               (view.incognito ?
  280.                   ' ' + loadTimeData.getString('viewIncognito') : '') +
  281.               (view.renderProcessId == -1 ?
  282.                   ' ' + loadTimeData.getString('viewInactive') : '');
  283.           link.textContent = label;
  284.           link.addEventListener('click', function(e) {
  285.             // TODO(estade): remove conversion to string?
  286.             chrome.send('extensionSettingsInspect', [
  287.               String(extension.id),
  288.               String(view.renderProcessId),
  289.               String(view.renderViewId),
  290.               view.incognito
  291.             ]);
  292.           });
  293.  
  294.           if (i < extension.views.length - 1) {
  295.             link = link.cloneNode(true);
  296.             activeViews.appendChild(link);
  297.           }
  298.         });
  299.       }
  300.  
  301.       // The extension warnings (describing runtime issues).
  302.       if (extension.warnings) {
  303.         var panel = node.querySelector('.extension-warnings');
  304.         panel.hidden = false;
  305.         var list = panel.querySelector('ul');
  306.         extension.warnings.forEach(function(warning) {
  307.           list.appendChild(document.createElement('li')).innerText = warning;
  308.         });
  309.       }
  310.  
  311.       // The install warnings.
  312.       if (extension.installWarnings) {
  313.         var panel = node.querySelector('.install-warnings');
  314.         panel.hidden = false;
  315.         var list = panel.querySelector('ul');
  316.         extension.installWarnings.forEach(function(warning) {
  317.           var li = document.createElement('li');
  318.           li[warning.isHTML ? 'innerHTML' : 'innerText'] = warning.message;
  319.           list.appendChild(li);
  320.         });
  321.       }
  322.  
  323.       this.appendChild(node);
  324.     }
  325.   };
  326.  
  327.   return {
  328.     ExtensionsList: ExtensionsList
  329.   };
  330. });
  331.