build/bloatcycle.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/build/bloatcycle.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,164 @@
     1.4 +<script>
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/*
    1.10 +  From mozilla/toolkit/content
    1.11 +  These files did not have a license
    1.12 +*/
    1.13 +
    1.14 +function quitHook()
    1.15 +{
    1.16 +  var xhr = new XMLHttpRequest();
    1.17 +  xhr.open("GET", "http://" + location.host + "/server/shutdown", true);
    1.18 +  xhr.onreadystatechange = function (event)
    1.19 +    {
    1.20 +      if (xhr.readyState == 4)
    1.21 +        goQuitApplication();
    1.22 +    };
    1.23 +  xhr.send(null);
    1.24 +}
    1.25 +
    1.26 +function canQuitApplication()
    1.27 +{
    1.28 +  var os = Components.classes["@mozilla.org/observer-service;1"]
    1.29 +    .getService(Components.interfaces.nsIObserverService);
    1.30 +  if (!os) 
    1.31 +  {
    1.32 +    return true;
    1.33 +  }
    1.34 +  
    1.35 +  try 
    1.36 +  {
    1.37 +    var cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"]
    1.38 +      .createInstance(Components.interfaces.nsISupportsPRBool);
    1.39 +    os.notifyObservers(cancelQuit, "quit-application-requested", null);
    1.40 +    
    1.41 +    // Something aborted the quit process. 
    1.42 +    if (cancelQuit.data)
    1.43 +    {
    1.44 +      return false;
    1.45 +    }
    1.46 +  }
    1.47 +  catch (ex) 
    1.48 +  {
    1.49 +  }
    1.50 +  os.notifyObservers(null, "quit-application-granted", null);
    1.51 +  return true;
    1.52 +}
    1.53 +
    1.54 +function goQuitApplication()
    1.55 +{
    1.56 +  const privs = 'UniversalXPConnect';
    1.57 +
    1.58 +  try
    1.59 +  {
    1.60 +    netscape.security.PrivilegeManager.enablePrivilege(privs);
    1.61 +  }
    1.62 +  catch(ex)
    1.63 +  {
    1.64 +    throw('goQuitApplication: privilege failure ' + ex);
    1.65 +  }
    1.66 +
    1.67 +  if (!canQuitApplication())
    1.68 +  {
    1.69 +    return false;
    1.70 +  }
    1.71 +
    1.72 +  const kAppStartup = '@mozilla.org/toolkit/app-startup;1';
    1.73 +  const kAppShell   = '@mozilla.org/appshell/appShellService;1';
    1.74 +  var   appService;
    1.75 +  var   forceQuit;
    1.76 +
    1.77 +  if (kAppStartup in Components.classes)
    1.78 +  {
    1.79 +    appService = Components.classes[kAppStartup].
    1.80 +      getService(Components.interfaces.nsIAppStartup);
    1.81 +    forceQuit  = Components.interfaces.nsIAppStartup.eForceQuit;
    1.82 +
    1.83 +  }
    1.84 +  else if (kAppShell in Components.classes)
    1.85 +  {
    1.86 +    appService = Components.classes[kAppShell].
    1.87 +      getService(Components.interfaces.nsIAppShellService);
    1.88 +    forceQuit = Components.interfaces.nsIAppShellService.eForceQuit;
    1.89 +  }
    1.90 +  else
    1.91 +  {
    1.92 +    throw 'goQuitApplication: no AppStartup/appShell';
    1.93 +  }
    1.94 +
    1.95 +  var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService();
    1.96 +
    1.97 +  var windowManagerInterface = windowManager.
    1.98 +    QueryInterface(Components.interfaces.nsIWindowMediator);
    1.99 +
   1.100 +  var enumerator = windowManagerInterface.getEnumerator(null);
   1.101 +
   1.102 +  while (enumerator.hasMoreElements())
   1.103 +  {
   1.104 +    var domWindow = enumerator.getNext();
   1.105 +    if (("tryToClose" in domWindow) && !domWindow.tryToClose())
   1.106 +    {
   1.107 +      return false;
   1.108 +    }
   1.109 +    domWindow.close();
   1.110 +  }
   1.111 +
   1.112 +  try
   1.113 +  {
   1.114 +    appService.quit(forceQuit);
   1.115 +  }
   1.116 +  catch(ex)
   1.117 +  {
   1.118 +    throw('goQuitApplication: ' + ex);
   1.119 +  }
   1.120 +
   1.121 +  return true;
   1.122 +}
   1.123 +
   1.124 +// bloat test driver for TestGtkEmbed
   1.125 +//
   1.126 +// set |user_pref("dom.allow_scripts_to_close_windows", true);| to 
   1.127 +// allow this to close the window when the loop is done.
   1.128 +//
   1.129 +//     "ftp://ftp.mozilla.org",   // not supported for TestGtkEmbed
   1.130 +//
   1.131 +
   1.132 +var list = 
   1.133 +    [
   1.134 +     "sample.html",
   1.135 +     "forms.html",
   1.136 +     "grid.html",
   1.137 +     "forms.html",
   1.138 +     "elements.html"
   1.139 +    ];
   1.140 +var interval = 5000; // 15000
   1.141 +var idx = 0;
   1.142 +var w;
   1.143 +
   1.144 +window.onload = function () {
   1.145 +    w = window.open("about:blank");
   1.146 +    window.setTimeout(loadURL, interval); 
   1.147 +};
   1.148 +function loadURL () {
   1.149 +    w.location.href = list[idx++];
   1.150 +    if (idx < list.length) {
   1.151 +	window.setTimeout(loadURL, interval);
   1.152 +    } else {
   1.153 +        if (navigator.platform.indexOf('Mac') != -1) {
   1.154 +            goQuitApplication();	
   1.155 +        } else {
   1.156 +            window.setTimeout("w.close();", interval);
   1.157 +            window.setTimeout("window.close();", interval*2);
   1.158 +        }
   1.159 +    }
   1.160 +}
   1.161 +var i;
   1.162 +
   1.163 +for(i=0; i < list.length;i++) {
   1.164 +    document.write(list[i]);
   1.165 +    document.write("<br>");
   1.166 +}
   1.167 +</script>

mercurial