mobile/android/components/BrowserCLH.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 const Cc = Components.classes;
     6 const Ci = Components.interfaces;
     7 const Cu = Components.utils;
     9 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
    10 Cu.import("resource://gre/modules/Services.jsm");
    13 function dump(a) {
    14   Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService).logStringMessage(a);
    15 }
    17 function openWindow(aParent, aURL, aTarget, aFeatures, aArgs) {
    18   let argsArray = Cc["@mozilla.org/supports-array;1"].createInstance(Ci.nsISupportsArray);
    19   let urlString = null;
    20   let pinnedBool = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool);
    21   let guestBool = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool);
    22   let widthInt = Cc["@mozilla.org/supports-PRInt32;1"].createInstance(Ci.nsISupportsPRInt32);
    23   let heightInt = Cc["@mozilla.org/supports-PRInt32;1"].createInstance(Ci.nsISupportsPRInt32);
    25   if ("url" in aArgs) {
    26     urlString = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString);
    27     urlString.data = aArgs.url;
    28   }
    29   widthInt.data = "width" in aArgs ? aArgs.width : 1;
    30   heightInt.data = "height" in aArgs ? aArgs.height : 1;
    31   pinnedBool.data = "pinned" in aArgs ? aArgs.pinned : false;
    32   guestBool.data = "guest" in aArgs ? aArgs["guest"] : false;
    34   argsArray.AppendElement(urlString, false);
    35   argsArray.AppendElement(widthInt, false);
    36   argsArray.AppendElement(heightInt, false);
    37   argsArray.AppendElement(pinnedBool, false);
    38   argsArray.AppendElement(guestBool, false);
    39   return Services.ww.openWindow(aParent, aURL, aTarget, aFeatures, argsArray);
    40 }
    43 function resolveURIInternal(aCmdLine, aArgument) {
    44   let uri = aCmdLine.resolveURI(aArgument);
    45   if (uri)
    46     return uri;
    48   try {
    49     let urifixup = Cc["@mozilla.org/docshell/urifixup;1"].getService(Ci.nsIURIFixup);
    50     uri = urifixup.createFixupURI(aArgument, 0);
    51   } catch (e) {
    52     Cu.reportError(e);
    53   }
    55   return uri;
    56 }
    58 function BrowserCLH() {}
    60 BrowserCLH.prototype = {
    61   handle: function fs_handle(aCmdLine) {
    62     let openURL = "about:home";
    63     let pinned = false;
    64     let guest = false;
    66     let width = 1;
    67     let height = 1;
    69     try {
    70       openURL = aCmdLine.handleFlagWithParam("url", false);
    71     } catch (e) { /* Optional */ }
    72     try {
    73       pinned = aCmdLine.handleFlag("webapp", false);
    74     } catch (e) { /* Optional */ }
    75     try {
    76       guest = aCmdLine.handleFlag("guest", false);
    77     } catch (e) { /* Optional */ }
    79     try {
    80       width = aCmdLine.handleFlagWithParam("width", false);
    81     } catch (e) { /* Optional */ }
    82     try {
    83       height = aCmdLine.handleFlagWithParam("height", false);
    84     } catch (e) { /* Optional */ }
    86     try {
    87       let uri = resolveURIInternal(aCmdLine, openURL);
    88       if (!uri)
    89         return;
    91       // Let's get a head start on opening the network connection to the URI we are about to load
    92       Services.io.QueryInterface(Ci.nsISpeculativeConnect).speculativeConnect(uri, null);
    94       let browserWin = Services.wm.getMostRecentWindow("navigator:browser");
    95       if (browserWin) {
    96         if (!pinned) {
    97           browserWin.browserDOMWindow.openURI(uri, null, Ci.nsIBrowserDOMWindow.OPEN_NEWTAB, Ci.nsIBrowserDOMWindow.OPEN_EXTERNAL);
    98         }
    99       } else {
   100         let args = {
   101           url: openURL,
   102           pinned: pinned,
   103           width: width,
   104           height: height,
   105           guest: guest
   106         };
   108         // Make sure webapps do not have: locationbar, personalbar, menubar, statusbar, and toolbar
   109         let flags = "chrome,dialog=no";
   110         if (!pinned)
   111           flags += ",all";
   113         browserWin = openWindow(null, "chrome://browser/content/browser.xul", "_blank", flags, args);
   114       }
   116       aCmdLine.preventDefault = true;
   117     } catch (x) {
   118       dump("BrowserCLH.handle: " + x);
   119     }
   120   },
   122   // QI
   123   QueryInterface: XPCOMUtils.generateQI([Ci.nsICommandLineHandler]),
   125   // XPCOMUtils factory
   126   classID: Components.ID("{be623d20-d305-11de-8a39-0800200c9a66}")
   127 };
   129 var components = [ BrowserCLH ];
   130 this.NSGetFactory = XPCOMUtils.generateNSGetFactory(components);

mercurial