зеркало из https://github.com/mozilla/pjs.git
bug 384139 - move openURL() to a reusable place in toolkit, r=bsmedberg
This commit is contained in:
Родитель
dda6f7522f
Коммит
07144d520f
|
@ -956,3 +956,67 @@ function getCharsetforSave(aDocument)
|
|||
|
||||
return window.content.document.characterSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a URL from chrome, determining if we can handle it internally or need to
|
||||
* launch an external application to handle it.
|
||||
* @param aURL The URL to be opened
|
||||
*/
|
||||
function openURL(aURL)
|
||||
{
|
||||
var ios = Components.classes["@mozilla.org/network/io-service;1"]
|
||||
.getService(Components.interfaces.nsIIOService);
|
||||
var uri = ios.newURI(aURL, null, null);
|
||||
|
||||
var protocolSvc = Components.classes["@mozilla.org/uriloader/external-protocol-service;1"]
|
||||
.getService(Components.interfaces.nsIExternalProtocolService);
|
||||
|
||||
if (!protocolSvc.isExposedProtocol(uri.scheme)) {
|
||||
// If we're not a browser, use the external protocol service to load the URI.
|
||||
protocolSvc.loadUrl(uri);
|
||||
}
|
||||
else {
|
||||
var loadgroup = Components.classes["@mozilla.org/network/load-group;1"]
|
||||
.createInstance(Components.interfaces.nsILoadGroup);
|
||||
var appstartup = Components.classes["@mozilla.org/toolkit/app-startup;1"]
|
||||
.getService(Components.interfaces.nsIAppStartup);
|
||||
|
||||
var loadListener = {
|
||||
onStartRequest: function ll_start(aRequest, aContext) {
|
||||
appstartup.enterLastWindowClosingSurvivalArea();
|
||||
},
|
||||
onStopRequest: function ll_stop(aRequest, aContext, aStatusCode) {
|
||||
appstartup.exitLastWindowClosingSurvivalArea();
|
||||
},
|
||||
QueryInterface: function ll_QI(iid) {
|
||||
if (iid.equals(Components.interfaces.nsISupports) ||
|
||||
iid.equals(Components.interfaces.nsIRequestObserver) ||
|
||||
iid.equals(Components.interfaces.nsISupportsWeakReference))
|
||||
return this;
|
||||
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
}
|
||||
loadgroup.groupObserver = loadListener;
|
||||
|
||||
var uriListener = {
|
||||
onStartURIOpen: function(uri) { return false; },
|
||||
doContent: function(ctype, preferred, request, handler) { return false; },
|
||||
isPreferred: function(ctype, desired) { return false; },
|
||||
canHandleContent: function(ctype, preferred, desired) { return false; },
|
||||
loadCookie: null,
|
||||
parentContentListener: null,
|
||||
getInterface: function(iid) {
|
||||
if (iid.equals(Components.interfaces.nsIURIContentListener))
|
||||
return this;
|
||||
if (iid.equals(Components.interfaces.nsILoadGroup))
|
||||
return loadgroup;
|
||||
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
}
|
||||
|
||||
var channel = ios.newChannelFromURI(uri);
|
||||
var uriLoader = Components.classes["@mozilla.org/uriloader;1"]
|
||||
.getService(Components.interfaces.nsIURILoader);
|
||||
uriLoader.openURI(channel, true, uriListener);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -462,66 +462,6 @@ function getIDFromResourceURI(aURI)
|
|||
return aURI;
|
||||
}
|
||||
|
||||
function openURL(aURL)
|
||||
{
|
||||
const nsILoadGroup = Components.interfaces.nsILoadGroup;
|
||||
var ios = Components.classes["@mozilla.org/network/io-service;1"]
|
||||
.getService(nsIIOService);
|
||||
var uri = ios.newURI(aURL, null, null);
|
||||
|
||||
var protocolSvc = Components.classes["@mozilla.org/uriloader/external-protocol-service;1"]
|
||||
.getService(Components.interfaces.nsIExternalProtocolService);
|
||||
|
||||
if (!protocolSvc.isExposedProtocol(uri.scheme)) {
|
||||
// If we're not a browser, use the external protocol service to load the URI.
|
||||
protocolSvc.loadUrl(uri);
|
||||
}
|
||||
else {
|
||||
var loadgroup = Components.classes["@mozilla.org/network/load-group;1"]
|
||||
.createInstance(nsILoadGroup);
|
||||
var appstartup = Components.classes["@mozilla.org/toolkit/app-startup;1"]
|
||||
.getService(nsIAppStartup);
|
||||
|
||||
var loadListener = {
|
||||
onStartRequest: function ll_start(aRequest, aContext) {
|
||||
appstartup.enterLastWindowClosingSurvivalArea();
|
||||
},
|
||||
onStopRequest: function ll_stop(aRequest, aContext, aStatusCode) {
|
||||
appstartup.exitLastWindowClosingSurvivalArea();
|
||||
},
|
||||
QueryInterface: function ll_QI(iid) {
|
||||
if (iid.equals(Components.interfaces.nsISupports) ||
|
||||
iid.equals(Components.interfaces.nsIRequestObserver) ||
|
||||
iid.equals(Components.interfaces.nsISupportsWeakReference))
|
||||
return this;
|
||||
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
}
|
||||
loadgroup.groupObserver = loadListener;
|
||||
|
||||
var uriListener = {
|
||||
onStartURIOpen: function(uri) { return false; },
|
||||
doContent: function(ctype, preferred, request, handler) { return false; },
|
||||
isPreferred: function(ctype, desired) { return false; },
|
||||
canHandleContent: function(ctype, preferred, desired) { return false; },
|
||||
loadCookie: null,
|
||||
parentContentListener: null,
|
||||
getInterface: function(iid) {
|
||||
if (iid.equals(Components.interfaces.nsIURIContentListener))
|
||||
return this;
|
||||
if (iid.equals(nsILoadGroup))
|
||||
return loadgroup;
|
||||
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
}
|
||||
|
||||
var channel = ios.newChannelFromURI(uri);
|
||||
var uriLoader = Components.classes["@mozilla.org/uriloader;1"]
|
||||
.getService(Components.interfaces.nsIURILoader);
|
||||
uriLoader.openURI(channel, true, uriListener);
|
||||
}
|
||||
}
|
||||
|
||||
function showProgressBar() {
|
||||
var progressBox = document.getElementById("progressBox");
|
||||
var height = document.defaultView.getComputedStyle(progressBox.parentNode, "")
|
||||
|
|
Загрузка…
Ссылка в новой задаче