From 07144d520f2400d60ef0726f8cfc66ddc6645b09 Mon Sep 17 00:00:00 2001 From: "kairo@kairo.at" Date: Thu, 9 Aug 2007 10:59:08 -0700 Subject: [PATCH] bug 384139 - move openURL() to a reusable place in toolkit, r=bsmedberg --- toolkit/content/contentAreaUtils.js | 64 +++++++++++++++++++ .../mozapps/extensions/content/extensions.js | 60 ----------------- 2 files changed, 64 insertions(+), 60 deletions(-) diff --git a/toolkit/content/contentAreaUtils.js b/toolkit/content/contentAreaUtils.js index 83751f75ed9..4acd1fc952f 100644 --- a/toolkit/content/contentAreaUtils.js +++ b/toolkit/content/contentAreaUtils.js @@ -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); + } +} diff --git a/toolkit/mozapps/extensions/content/extensions.js b/toolkit/mozapps/extensions/content/extensions.js index 0af4d68632e..b2d1cc7be3d 100644 --- a/toolkit/mozapps/extensions/content/extensions.js +++ b/toolkit/mozapps/extensions/content/extensions.js @@ -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, "")