home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / firefox-3.0.14 / chrome / browser.jar / content / browser / preferences / phishEULA.js < prev    next >
Encoding:
JavaScript  |  2007-04-22  |  7.0 KB  |  191 lines

  1. //@line 38 "/build/buildd/firefox-3.0-3.0.14+build2+nobinonly/build-tree/mozilla/browser/components/preferences/phishEULA.js"
  2.  
  3. /**
  4.  * gPhishDialog controls the user interface for displaying the privacy policy of
  5.  * an anti-phishing provider. 
  6.  * 
  7.  * The caller (gSecurityPane._userAgreedToPhishingEULA in main.js) invokes this
  8.  * dialog with a single argument - a reference to an object with .providerNum
  9.  * and .userAgreed properties.  This code displays the dialog for the provider
  10.  * as dictated by .providerNum and loads the policy.  When that load finishes,
  11.  * the OK button is enabled and the user can either accept or decline the
  12.  * agreement (a choice which is communicated by setting .userAgreed to true if
  13.  * the user did indeed agree).
  14.  */ 
  15. var gPhishDialog = {
  16.   /**
  17.    * The nsIWebProgress object associated with the privacy policy frame.
  18.    */
  19.   _webProgress: null,
  20.  
  21.   /**
  22.    * Initializes UI and starts the privacy policy loading.
  23.    */
  24.   init: function ()
  25.   {
  26.     const Cc = Components.classes, Ci = Components.interfaces;
  27.  
  28.     var providerNum = window.arguments[0].providerNum;
  29.  
  30.     var phishBefore = document.getElementById("phishBefore");
  31.  
  32.     var prefb = Cc["@mozilla.org/preferences-service;1"].
  33.                 getService(Ci.nsIPrefService).
  34.                 getBranch("browser.safebrowsing.provider.");
  35.  
  36.     // init before-frame and after-frame strings
  37.     // note that description only wraps when the string is the element's
  38.     // *content* and *not* when it's the value attribute
  39.     var providerName = prefb.getComplexValue(providerNum + ".name", Ci.nsISupportsString).data
  40.     var strings = document.getElementById("bundle_phish");
  41.     phishBefore.textContent = strings.getFormattedString("phishBeforeText", [providerName]);
  42.  
  43.     // guaranteed to be present, because only providers with privacy policies
  44.     // are displayed in the prefwindow
  45.     var formatter = Cc["@mozilla.org/toolkit/URLFormatterService;1"].
  46.                     getService(Ci.nsIURLFormatter);
  47.     var privacyURL = formatter.formatURLPref("browser.safebrowsing.provider." +
  48.                                              providerNum +
  49.                                              ".privacy.url",
  50.                                              null);
  51.     var fallbackURL = formatter.formatURLPref("browser.safebrowsing.provider." +
  52.                                               providerNum +
  53.                                               ".privacy.fallbackurl",
  54.                                               null);
  55.     this._progressListener._providerFallbackURL = fallbackURL;
  56.  
  57.     // add progress listener to enable OK, radios when page loads
  58.     var frame = document.getElementById("phishPolicyFrame");
  59.     var docShell = frame.docShell;
  60.  
  61.     // disable unnecessary features
  62.     docShell.allowAuth = false;
  63.     docShell.allowPlugins = false;
  64.     docShell.allowSubframes = false;
  65.  
  66.     var webProgress = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
  67.                               .getInterface(Ci.nsIWebProgress);
  68.     webProgress.addProgressListener(this._progressListener,
  69.                                     Ci.nsIWebProgress.NOTIFY_STATE_WINDOW);
  70.  
  71.     this._webProgress = webProgress; // for easy use later
  72.  
  73.     // start loading the privacyURL
  74.     const loadFlags = Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
  75.     frame.webNavigation.loadURI(privacyURL, loadFlags, null, null, null);
  76.   },
  77.  
  78.   /**
  79.    * The nsIWebProgressListener used to watch the status of the load of the
  80.    * privacy policy; enables the OK button when the load completes.
  81.    */
  82.   _progressListener:
  83.   {
  84.     /**
  85.      * First we try to load the provider url (possibly remote). If that fails
  86.      * to load, we try to load the provider fallback url (must be chrome://).
  87.      * If that also fails, we display an error message.
  88.      */
  89.     _providerLoadFailed: false,
  90.     _providerFallbackLoadFailed: false,
  91.     
  92.     _tryLoad: function(url) {
  93.       const Ci = Components.interfaces;
  94.       const loadFlags = Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
  95.       var frame = document.getElementById("phishPolicyFrame");
  96.       frame.webNavigation.loadURI(url, loadFlags, null, null, null);
  97.     },
  98.  
  99.     onStateChange: function (aWebProgress, aRequest, aStateFlags, aStatus)
  100.     {
  101.       // enable the OK button when the request completes
  102.       const Ci = Components.interfaces, Cr = Components.results;
  103.       if ((aStateFlags & Ci.nsIWebProgressListener.STATE_STOP) &&
  104.           (aStateFlags & Ci.nsIWebProgressListener.STATE_IS_WINDOW)) {
  105.         
  106.         if (Components.isSuccessCode(aRequest.status)) {
  107.           try {
  108.             aRequest.QueryInterface(Ci.nsIHttpChannel);
  109.           } catch (e) {
  110.             // Not an http request url (might be, e.g., chrome:) that loaded
  111.             // successfully, so we can exit.
  112.             return;
  113.           }
  114.  
  115.           // Any response other than 200 OK is an error.
  116.           if (200 == aRequest.responseStatus)
  117.             return;
  118.         }
  119.  
  120.         // Something failed
  121.         if (!this._providerLoadFailed) {
  122.           this._provderLoadFailed = true;
  123.           // Remote EULA failed to load; try loading provider fallback
  124.           this._tryLoad(this._providerFallbackURL);
  125.         } else if (!this._providerFallbackLoadFailed) {
  126.           // Provider fallback failed to load; try loading fallback EULA
  127.           this._providerFallbackLoadFailed = true;
  128.  
  129.           // fire off a load of the fallback policy
  130.           const fallbackURL = "chrome://browser/content/preferences/fallbackEULA.xhtml";
  131.           this._tryLoad(fallbackURL);
  132.  
  133.           // disable radios
  134.           document.getElementById("acceptOrDecline").disabled = true;
  135.         } else {
  136.           throw "Fallback policy failed to load -- what the hay!?!";
  137.         }
  138.       }
  139.     },
  140.     
  141.     onProgressChange: function(aWebProgress, aRequest, aCurSelfProgress,
  142.                                aMaxSelfProgress, aCurTotalProgress,
  143.                                aMaxTotalProgress)
  144.     {
  145.     },
  146.  
  147.     onStatusChange : function(aWebProgress, aRequest, aStatus, aMessage)
  148.     {
  149.     },
  150.  
  151.     QueryInterface : function(aIID)
  152.     {
  153.       const Ci = Components.interfaces;
  154.       if (aIID.equals(Ci.nsIWebProgressListener) ||
  155.           aIID.equals(Ci.nsISupportsWeakReference) ||
  156.           aIID.equals(Ci.nsISupports))
  157.         return this;
  158.       throw Components.results.NS_NOINTERFACE;
  159.     }
  160.   },
  161.  
  162.   /**
  163.    * Signals that the user accepted the privacy policy by setting the window
  164.    * arguments appropriately.  Note that this does *not* change preferences;
  165.    * the opener of this dialog handles that.
  166.    */
  167.   accept: function ()
  168.   {
  169.     window.arguments[0].userAgreed = true;
  170.   },
  171.  
  172.   /**
  173.    * Clean up any XPCOM-JS cycles we may have created.
  174.    */
  175.   uninit: function ()
  176.   {
  177.     // overly aggressive, but better safe than sorry
  178.     this._webProgress.removeProgressListener(this._progressListener);
  179.     this._progressListener = this._webProgress = null;
  180.   },
  181.  
  182.   /**
  183.    * Called when the user changes the agree/disagree radio.
  184.    */
  185.   onchangeRadio: function ()
  186.   {
  187.     var radio = document.getElementById("acceptOrDecline");
  188.     document.documentElement.getButton("accept").disabled = (radio.value == "false");
  189.   }
  190. };
  191.