home *** CD-ROM | disk | FTP | other *** search
/ Freelog 115 / FreelogNo115-MaiJuin2013.iso / Internet / AvantBrowser / asetup.exe / _data / webkit / chrome.dll / 0 / BINDATA / 539 < prev    next >
Encoding:
Text File  |  2013-04-03  |  11.8 KB  |  407 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. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  6. // Use of this source code is governed by a BSD-style license that can be
  7. // found in the LICENSE file.
  8.  
  9. /**
  10.  * @fileoverview A collection of utility methods for UberPage and its contained
  11.  *     pages.
  12.  */
  13.  
  14. cr.define('uber', function() {
  15.  
  16.   /**
  17.    * Fixed position header elements on the page to be shifted by handleScroll.
  18.    * @type {NodeList}
  19.    */
  20.   var headerElements;
  21.  
  22.   /**
  23.    * This should be called by uber content pages when DOM content has loaded.
  24.    */
  25.   function onContentFrameLoaded() {
  26.     headerElements = document.getElementsByTagName('header');
  27.     document.addEventListener('scroll', handleScroll);
  28.  
  29.     // Trigger the scroll handler to tell the navigation if our page started
  30.     // with some scroll (happens when you use tab restore).
  31.     handleScroll();
  32.  
  33.     window.addEventListener('message', handleWindowMessage);
  34.   }
  35.  
  36.   /**
  37.    * Handles scroll events on the document. This adjusts the position of all
  38.    * headers and updates the parent frame when the page is scrolled.
  39.    * @private
  40.    */
  41.   function handleScroll() {
  42.     var offset = document.body.scrollLeft * -1;
  43.     for (var i = 0; i < headerElements.length; i++)
  44.       headerElements[i].style.webkitTransform = 'translateX(' + offset + 'px)';
  45.  
  46.     invokeMethodOnParent('adjustToScroll', document.body.scrollLeft);
  47.   };
  48.  
  49.   /**
  50.    * Handles 'message' events on window.
  51.    * @param {Event} e The message event.
  52.    */
  53.   function handleWindowMessage(e) {
  54.     if (e.data.method === 'frameSelected')
  55.       handleFrameSelected();
  56.     else if (e.data.method === 'mouseWheel')
  57.       handleMouseWheel(e.data.params);
  58.   }
  59.  
  60.   /**
  61.    * This is called when a user selects this frame via the navigation bar
  62.    * frame (and is triggered via postMessage() from the uber page).
  63.    * @private
  64.    */
  65.   function handleFrameSelected() {
  66.     document.body.scrollLeft = 0;
  67.   }
  68.  
  69.   /**
  70.    * Called when a user mouse wheels (or trackpad scrolls) over the nav frame.
  71.    * The wheel event is forwarded here and we scroll the body.
  72.    * There's no way to figure out the actual scroll amount for a given delta.
  73.    * It differs for every platform and even initWebKitWheelEvent takes a
  74.    * pixel amount instead of a wheel delta. So we just choose something
  75.    * reasonable and hope no one notices the difference.
  76.    * @param {Object} params A structure that holds wheel deltas in X and Y.
  77.    */
  78.   function handleMouseWheel(params) {
  79.     document.body.scrollTop -= params.deltaY * 49 / 120;
  80.     document.body.scrollLeft -= params.deltaX * 49 / 120;
  81.   }
  82.  
  83.   /**
  84.    * Invokes a method on the parent window (UberPage). This is a convenience
  85.    * method for API calls into the uber page.
  86.    * @param {String} method The name of the method to invoke.
  87.    * @param {Object=} opt_params Optional property bag of parameters to pass to
  88.    *     the invoked method.
  89.    * @private
  90.    */
  91.   function invokeMethodOnParent(method, opt_params) {
  92.     if (window.location == window.parent.location)
  93.       return;
  94.  
  95.     invokeMethodOnWindow(window.parent, method, opt_params, 'chrome://chrome');
  96.   }
  97.  
  98.   /**
  99.    * Invokes a method on the target window.
  100.    * @param {String} method The name of the method to invoke.
  101.    * @param {Object=} opt_params Optional property bag of parameters to pass to
  102.    *     the invoked method.
  103.    * @param {String=} opt_url The origin of the target window.
  104.    * @private
  105.    */
  106.   function invokeMethodOnWindow(targetWindow, method, opt_params, opt_url) {
  107.     var data = {method: method, params: opt_params};
  108.     targetWindow.postMessage(data, opt_url ? opt_url : '*');
  109.   }
  110.  
  111.   return {
  112.     invokeMethodOnParent: invokeMethodOnParent,
  113.     invokeMethodOnWindow: invokeMethodOnWindow,
  114.     onContentFrameLoaded: onContentFrameLoaded,
  115.   };
  116. });
  117.  
  118.  
  119. cr.define('help', function() {
  120.   /**
  121.    * Encapsulated handling of the help page.
  122.    */
  123.   function HelpPage() {}
  124.  
  125.   cr.addSingletonGetter(HelpPage);
  126.  
  127.   HelpPage.prototype = {
  128.     __proto__: HTMLDivElement.prototype,
  129.  
  130.     /**
  131.      * Perform initial setup.
  132.      */
  133.     initialize: function() {
  134.       uber.onContentFrameLoaded();
  135.  
  136.       // Set the title.
  137.       var title = loadTimeData.getString('helpTitle');
  138.       uber.invokeMethodOnParent('setTitle', {title: title});
  139.  
  140.       $('product-license').innerHTML = loadTimeData.getString('productLicense');
  141.       if (cr.isChromeOS) {
  142.         $('product-os-license').innerHTML =
  143.             loadTimeData.getString('productOsLicense');
  144.       }
  145.  
  146.       var productTOS = $('product-tos');
  147.       if (productTOS)
  148.         productTOS.innerHTML = loadTimeData.getString('productTOS');
  149.  
  150.       $('get-help').onclick = function() {
  151.         chrome.send('openHelpPage');
  152.       };
  153.       $('report-issue').onclick = function() {
  154.         chrome.send('openFeedbackDialog');
  155.       };
  156.  
  157.       this.maybeSetOnClick_($('more-info-expander'),
  158.           this.toggleMoreInfo_.bind(this));
  159.  
  160.       this.maybeSetOnClick_($('promote'), function() {
  161.         chrome.send('promoteUpdater');
  162.       });
  163.       this.maybeSetOnClick_($('relaunch'), function() {
  164.         chrome.send('relaunchNow');
  165.       });
  166.  
  167.       var channelChanger = $('channel-changer');
  168.       if (channelChanger) {
  169.         this.channelName_ = {
  170.             'stable-channel': loadTimeData.getString('stable'),
  171.             'beta-channel': loadTimeData.getString('beta'),
  172.             'dev-channel': loadTimeData.getString('dev')
  173.         };
  174.         var self = this;
  175.         channelChanger.onchange = function(event) {
  176.           self.setReleaseChannel_(event.target.value);
  177.         }
  178.       }
  179.  
  180.       // Attempt to update.
  181.       chrome.send('onPageLoaded');
  182.     },
  183.  
  184.     /**
  185.      * Toggles the visible state of the 'More Info' section.
  186.      * @private
  187.      */
  188.     toggleMoreInfo_: function() {
  189.       var moreInfo = $('more-info-container');
  190.       var visible = moreInfo.className == 'visible';
  191.       moreInfo.className = visible ? '' : 'visible';
  192.       moreInfo.style.height = visible ? '' : moreInfo.scrollHeight + 'px';
  193.       moreInfo.addEventListener('webkitTransitionEnd', function(event) {
  194.         $('more-info-expander').textContent = visible ?
  195.             loadTimeData.getString('showMoreInfo') :
  196.             loadTimeData.getString('hideMoreInfo');
  197.       });
  198.     },
  199.  
  200.     /**
  201.      * Assigns |method| to the onclick property of |el| if |el| exists.
  202.      * @private
  203.      */
  204.     maybeSetOnClick_: function(el, method) {
  205.       if (el)
  206.         el.onclick = method;
  207.     },
  208.  
  209.     /**
  210.      * @private
  211.      */
  212.     setUpdateImage_: function(state) {
  213.       $('update-status-icon').className = 'update-icon ' + state;
  214.     },
  215.  
  216.     /**
  217.      * @private
  218.      */
  219.     setUpdateStatus_: function(status, message) {
  220.       if (status == 'checking') {
  221.         this.setUpdateImage_('working');
  222.         $('update-status').innerHTML =
  223.             loadTimeData.getString('updateCheckStarted');
  224.       } else if (status == 'updating') {
  225.         this.setUpdateImage_('working');
  226.         $('update-status').innerHTML = loadTimeData.getString('updating');
  227.       } else if (status == 'nearly_updated') {
  228.         this.setUpdateImage_('up-to-date');
  229.         $('update-status').innerHTML =
  230.             loadTimeData.getString('updateAlmostDone');
  231.       } else if (status == 'updated') {
  232.         this.setUpdateImage_('up-to-date');
  233.         $('update-status').innerHTML = loadTimeData.getString('upToDate');
  234.       } else if (status == 'failed') {
  235.         this.setUpdateImage_('failed');
  236.         $('update-status').innerHTML = message;
  237.       }
  238.  
  239.       var container = $('update-status-container');
  240.       if (container) {
  241.         container.hidden = status == 'disabled';
  242.         $('relaunch').hidden = status != 'nearly_updated';
  243.  
  244.         if (!cr.isMac)
  245.           $('update-percentage').hidden = status != 'updating';
  246.       }
  247.     },
  248.  
  249.     /**
  250.      * @private
  251.      */
  252.     setProgress_: function(progress) {
  253.       $('update-percentage').innerHTML = progress + '%';
  254.     },
  255.  
  256.     /**
  257.      * @private
  258.      */
  259.     setPromotionState_: function(state) {
  260.       if (state == 'hidden') {
  261.         $('promote').hidden = true;
  262.       } else if (state == 'enabled') {
  263.         $('promote').disabled = false;
  264.         $('promote').hidden = false;
  265.       } else if (state == 'disabled') {
  266.         $('promote').disabled = true;
  267.         $('promote').hidden = false;
  268.       }
  269.     },
  270.  
  271.     /**
  272.      * @private
  273.      */
  274.     setOSVersion_: function(version) {
  275.       if (!cr.isChromeOS)
  276.         console.error('OS version unsupported on non-CrOS');
  277.  
  278.       $('os-version').parentNode.hidden = (version == '');
  279.       $('os-version').textContent = version;
  280.     },
  281.  
  282.     /**
  283.      * @private
  284.      */
  285.     setOSFirmware_: function(firmware) {
  286.       if (!cr.isChromeOS)
  287.         console.error('OS firmware unsupported on non-CrOS');
  288.  
  289.       $('firmware').parentNode.hidden = (firmware == '');
  290.       $('firmware').textContent = firmware;
  291.     },
  292.  
  293.     /**
  294.      * Sets the given overlay to show. This hides whatever overlay is currently
  295.      * showing, if any.
  296.      * @param {HTMLElement} node The overlay page to show. If null, all
  297.      *     overlays are hidden.
  298.      */
  299.     showOverlay_: function(node) {
  300.       var currentlyShowingOverlay =
  301.         document.querySelector('#overlay .page.showing');
  302.       if (currentlyShowingOverlay)
  303.         currentlyShowingOverlay.classList.remove('showing');
  304.  
  305.       if (node)
  306.         node.classList.add('showing');
  307.       $('overlay').hidden = !node;
  308.     },
  309.  
  310.     /**
  311.      * |enabled| is true if the release channel can be enabled.
  312.      * @private
  313.      */
  314.     updateEnableReleaseChannel_: function(enabled) {
  315.       $('channel-changer-container').hidden = !enabled;
  316.     },
  317.  
  318.     /**
  319.      * @private
  320.      */
  321.     updateSelectedChannel_: function(value) {
  322.       var options = $('channel-changer').querySelectorAll('option');
  323.       for (var i = 0; i < options.length; i++) {
  324.         var option = options[i];
  325.         if (option.value == value)
  326.           option.selected = true;
  327.       }
  328.     },
  329.  
  330.     /**
  331.      * @private
  332.      */
  333.     setReleaseChannel_: function(channel) {
  334.       chrome.send('setReleaseTrack', [channel]);
  335.       $('channel-change-confirmation').hidden = false;
  336.       $('channel-change-confirmation').textContent = loadTimeData.getStringF(
  337.           'channel-changed', this.channelName_[channel]);
  338.     },
  339.  
  340.     /**
  341.      * Sets the value of the "Build Date" field of the "More Info" section.
  342.      * @param {String} buildDate The date of the build.
  343.      * @private
  344.      */
  345.     setBuildDate_: function(buildDate) {
  346.       $('build-date-container').classList.remove('empty');
  347.       $('build-date').textContent = buildDate;
  348.     },
  349.   };
  350.  
  351.   HelpPage.setUpdateStatus = function(status, message) {
  352.     HelpPage.getInstance().setUpdateStatus_(status, message);
  353.   };
  354.  
  355.   HelpPage.setProgress = function(progress) {
  356.     HelpPage.getInstance().setProgress_(progress);
  357.   };
  358.  
  359.   HelpPage.setPromotionState = function(state) {
  360.     HelpPage.getInstance().setPromotionState_(state);
  361.   };
  362.  
  363.   HelpPage.setObsoleteOS = function(obsolete) {
  364.     HelpPage.getInstance().setObsoleteOS_(obsolete);
  365.   };
  366.  
  367.   HelpPage.setOSVersion = function(version) {
  368.     HelpPage.getInstance().setOSVersion_(version);
  369.   };
  370.  
  371.   HelpPage.setOSFirmware = function(firmware) {
  372.     HelpPage.getInstance().setOSFirmware_(firmware);
  373.   };
  374.  
  375.   HelpPage.showOverlay = function(node) {
  376.     HelpPage.getInstance().showOverlay_(node);
  377.   };
  378.  
  379.   HelpPage.updateSelectedChannel = function(channel) {
  380.     HelpPage.getInstance().updateSelectedChannel_(channel);
  381.   };
  382.  
  383.   HelpPage.updateEnableReleaseChannel = function(enabled) {
  384.     HelpPage.getInstance().updateEnableReleaseChannel_(enabled);
  385.   };
  386.  
  387.   HelpPage.setReleaseChannel = function(channel) {
  388.     HelpPage.getInstance().setReleaseChannel_(channel);
  389.   };
  390.  
  391.   HelpPage.setBuildDate = function(buildDate) {
  392.     HelpPage.getInstance().setBuildDate_(buildDate);
  393.   }
  394.  
  395.   // Export
  396.   return {
  397.     HelpPage: HelpPage
  398.   };
  399. });
  400.  
  401. /**
  402.  * onload listener to initialize the HelpPage.
  403.  */
  404. window.onload = function() {
  405.   help.HelpPage.getInstance().initialize();
  406. };
  407.