~ubuntu-branches/ubuntu/trusty/fennec/trusty

« back to all changes in this revision

Viewing changes to mobile/components/BrowserCLH.js

  • Committer: Bazaar Package Importer
  • Author(s): Chris Coulson
  • Date: 2011-01-26 20:31:40 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110126203140-zcg54f8ost2vmrxr
Tags: 4.0~b3-0ubuntu1
* New upstream release v4.0 B3 (FENNEC_4_0b3_RELEASE)

* Update build-depends for xulrunner-2.0
  - update debian/control
* Update mozclient to point to the mobile-browser repo
  - update debian/mozclient/fennec.conf
* Build with "--with-system-libxul"
  - update debian/rules
* Add launcher script, based on the one used in Firefox but with the
  unnecessary bits stripped out
  - add debian/fennec.sh
  - update debian/rules
* Refresh patches for new version
  - update debian/patches/bump_gecko_versions_in_application.ini.patch
  - update debian/patches/ubuntu_codes_google.patch
  - update debian/patches/installer.patch
* Drop unneeded patches
  - remove debian/patches/nspr_flags_by_pkg_config_hack.patch
  - remove debian/patches/xul191_l10n.patch
  - update debian/patches/series

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
 
38
38
const Cc = Components.classes;
39
39
const Ci = Components.interfaces;
40
 
const Cr = Components.results;
41
40
const Cu = Components.utils;
42
41
 
43
 
 
44
42
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
43
Cu.import("resource://gre/modules/Services.jsm");
 
44
 
 
45
function openWindow(aParent, aURL, aTarget, aFeatures, aArgs) {
 
46
  let argString = null;
 
47
  if (aArgs) {
 
48
    argString = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString);
 
49
    argString.data = aArgs;
 
50
  }
 
51
  
 
52
  return Services.ww.openWindow(aParent, aURL, aTarget, aFeatures, argString);
 
53
}
 
54
 
 
55
function resolveURIInternal(aCmdLine, aArgument) {
 
56
  let uri = aCmdLine.resolveURI(aArgument);
 
57
 
 
58
  if (!(uri instanceof Ci.nsIFileURL))
 
59
    return uri;
 
60
 
 
61
  try {
 
62
    if (uri.file.exists())
 
63
      return uri;
 
64
  }
 
65
  catch (e) {
 
66
    Cu.reportError(e);
 
67
  }
 
68
 
 
69
  try {
 
70
    let urifixup = Cc["@mozilla.org/docshell/urifixup;1"].getService(Ci.nsIURIFixup);
 
71
    uri = urifixup.createFixupURI(aArgument, 0);
 
72
  }
 
73
  catch (e) {
 
74
    Cu.reportError(e);
 
75
  }
 
76
 
 
77
  return uri;
 
78
}
 
79
 
 
80
/**
 
81
 * Determines whether a home page override is needed.
 
82
 * Returns:
 
83
 *  "new profile" if this is the first run with a new profile.
 
84
 *  "new version" if this is the first run with a build with a different
 
85
 *                      Gecko milestone (i.e. right after an upgrade).
 
86
 *  "none" otherwise.
 
87
 */
 
88
function needHomepageOverride() {
 
89
  let savedmstone = null;
 
90
  try {
 
91
    savedmstone = Services.prefs.getCharPref("browser.startup.homepage_override.mstone");
 
92
  } catch (e) {}
 
93
 
 
94
  if (savedmstone == "ignore")
 
95
    return "none";
 
96
 
 
97
#expand    let ourmstone = "__MOZ_APP_VERSION__";
 
98
 
 
99
  if (ourmstone != savedmstone) {
 
100
    Services.prefs.setCharPref("browser.startup.homepage_override.mstone", ourmstone);
 
101
 
 
102
    return (savedmstone ? "new version" : "new profile");
 
103
  }
 
104
 
 
105
  return "none";
 
106
}
 
107
 
 
108
function getHomePage() {
 
109
  let url = "about:home";
 
110
  try {
 
111
    url = Services.prefs.getComplexValue("browser.startup.homepage", Ci.nsIPrefLocalizedString).data;
 
112
  } catch (e) { }
 
113
 
 
114
  return url;
 
115
}
 
116
 
45
117
 
46
118
function BrowserCLH() { }
47
119
 
49
121
  //
50
122
  // nsICommandLineHandler
51
123
  //
52
 
  handle: function fs_handle(cmdLine) {
 
124
  handle: function fs_handle(aCmdLine) {
53
125
    // Instantiate the search service so the search engine cache is created now
54
126
    // instead when the application is running. The install process will register
55
127
    // this component by using the -silent command line flag, thereby creating
56
128
    // the cache during install, not runtime.
57
129
    // NOTE: This code assumes this CLH is run before the nsDefaultCLH, which
58
130
    // consumes the "-silent" flag.
59
 
    if (cmdLine.findFlag("silent", false) > -1) {
60
 
      let searchService = Cc["@mozilla.org/browser/search-service;1"].
61
 
                          getService(Ci.nsIBrowserSearchService);
 
131
    if (aCmdLine.findFlag("silent", false) > -1) {
 
132
      let searchService = Services.search;
62
133
      let autoComplete = Cc["@mozilla.org/autocomplete/search;1?name=history"].
63
134
                         getService(Ci.nsIAutoCompleteSearch);
64
 
    }
65
 
 
 
135
      return;
 
136
    }
 
137
 
 
138
    // Handle chrome windows loaded via commandline
 
139
    let chromeParam = aCmdLine.handleFlagWithParam("chrome", false);
 
140
    if (chromeParam) {
 
141
      try {
 
142
        // Only load URIs which do not inherit chrome privs
 
143
        let features = "chrome,dialog=no,all";
 
144
        let uri = resolveURIInternal(aCmdLine, chromeParam);
 
145
        let netutil = Cc["@mozilla.org/network/util;1"].getService(Ci.nsINetUtil);
 
146
        if (!netutil.URIChainHasFlags(uri, Ci.nsIHttpProtocolHandler.URI_INHERITS_SECURITY_CONTEXT)) {
 
147
          openWindow(null, uri.spec, "_blank", features, null);
 
148
 
 
149
          // Stop the normal commandline processing from continuing
 
150
          aCmdLine.preventDefault = true;
 
151
        }
 
152
      }
 
153
      catch (e) {
 
154
        Cu.reportError(e);
 
155
      }
 
156
      return;
 
157
    }
 
158
 
 
159
    // Keep an array of possible URL arguments
 
160
    let uris = [];
 
161
 
 
162
    // Check for the "url" flag
 
163
    let uriFlag = aCmdLine.handleFlagWithParam("url", false);
 
164
    if (uriFlag) {
 
165
      let uri = resolveURIInternal(aCmdLine, uriFlag);
 
166
      if (uri)
 
167
        uris.push(uri);
 
168
    }
 
169
 
 
170
    for (let i = 0; i < aCmdLine.length; i++) {
 
171
      let arg = aCmdLine.getArgument(i);
 
172
      if (!arg || arg[0] == '-')
 
173
        continue;
 
174
 
 
175
      let uri = resolveURIInternal(aCmdLine, arg);
 
176
      if (uri)
 
177
        uris.push(uri);
 
178
    }
 
179
 
 
180
    // Open the main browser window, if we don't already have one
66
181
    let win;
67
182
    try {
68
 
      var windowMediator =
69
 
        Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
 
183
      win = Services.wm.getMostRecentWindow("navigator:browser");
 
184
      if (!win) {
 
185
        // Default to the saved homepage
 
186
        let defaultURL = getHomePage();
 
187
  
 
188
        // Override the default if we have a new profile
 
189
        if (needHomepageOverride() == "new profile")
 
190
            defaultURL = "about:firstrun";
 
191
  
 
192
        // Override the default if we have a URL passed on command line
 
193
        if (uris.length > 0) {
 
194
          defaultURL = uris[0].spec;
 
195
          uris = uris.slice(1);
 
196
        }
70
197
 
71
 
      win = windowMediator.getMostRecentWindow("navigator:browser");
72
 
      if (!win)
73
 
        return;
 
198
        win = openWindow(null, "chrome://browser/content/browser.xul", "_blank", "chrome,dialog=no,all", defaultURL);
 
199
      }
74
200
 
75
201
      win.focus();
76
 
      cmdLine.preventDefault = true;
 
202
 
 
203
      // Stop the normal commandline processing from continuing. We just opened the main browser window
 
204
      aCmdLine.preventDefault = true;
77
205
    } catch (e) { }
78
206
 
79
 
    // Assumption:  All CLH arguments we've received have been sent remotely,
80
 
    // or we wouldn't already have a window.  Therefore: open 'em all!
81
 
    for (let i = 0; i < cmdLine.length; i++) {
82
 
      let arg = cmdLine.getArgument(i);
83
 
      if (!arg || arg[0] == '-')
84
 
        continue;
85
 
 
86
 
      let uri = cmdLine.resolveURI(arg);
87
 
      if (uri)
88
 
        win.browserDOMWindow.openURI(uri, null, Ci.nsIBrowserDOMWindow.OPEN_NEWTAB, null);
89
 
    }
 
207
    // Assumption: All remaining command line arguments have been sent remotely (browser is already running)
 
208
    // Action: Open any URLs we find into an existing browser window
 
209
 
 
210
    // First, get a browserDOMWindow object
 
211
    while (!win.browserDOMWindow)
 
212
      Services.tm.currentThread.processNextEvent(true);
 
213
 
 
214
    // Open any URIs into new tabs
 
215
    for (let i = 0; i < uris.length; i++)
 
216
      win.browserDOMWindow.openURI(uris[i], null, Ci.nsIBrowserDOMWindow.OPEN_NEWTAB,
 
217
                                   Ci.nsIBrowserDOMWindow.OPEN_EXTERNAL);
90
218
  },
91
219
 
92
220
  // QI
93
221
  QueryInterface: XPCOMUtils.generateQI([Ci.nsICommandLineHandler]),
94
222
 
95
223
  // XPCOMUtils factory
96
 
  classDescription: "Command Line Handler",
97
 
  contractID: "@mozilla.org/mobile/browser-clh;1",
98
224
  classID: Components.ID("{be623d20-d305-11de-8a39-0800200c9a66}"),
99
 
  _xpcom_categories: [{ category: "command-line-handler", entry: "m-browser" }],
100
225
};
101
226
 
102
227
var components = [ BrowserCLH ];
103
 
 
104
 
function NSGetModule(compMgr, fileSpec) {
105
 
  return XPCOMUtils.generateModule(components);
106
 
}
 
228
const NSGetFactory = XPCOMUtils.generateNSGetFactory(components);