334747, 339893 - desktop application feed readers do not display their app name properly or launch with the specified feed on OSX due to lack of support for a function to get the application bundle name, and a method to invoke an application bundle on OS X with a URL. Add an attribute to nsILocalFileMac called bundleDisplayName to show the application's name, and a method to nsIShellService called openApplicationWithURL which launches an application with a URL parameter appropriately across platforms (nsIProcess on windows and linux, LaunchServices on OS X). Update the client code to use bundleDisplayName, and also the <filefield> binding in preferences to use it too. r=mark sr=darin

This commit is contained in:
beng@bengoodger.com
2006-06-27 22:38:55 +00:00
parent 1fb81c21bf
commit ec204208bd
9 changed files with 176 additions and 29 deletions

View File

@@ -38,8 +38,9 @@
#include "nsISupports.idl"
interface nsIDOMElement;
interface nsILocalFile;
[scriptable, uuid(d6f62053-3769-46f6-bd2b-0a1440d6c394)]
[scriptable, uuid(FD63944D-F851-4116-A372-962E4D030B2D)]
interface nsIShellService : nsISupports
{
/**
@@ -112,5 +113,14 @@ interface nsIShellService : nsISupports
* entire screen. A rgb value, where (r << 16 | g << 8 | b)
*/
attribute unsigned long desktopBackgroundColor;
/**
* Opens an application with a specific URI to load.
* @param application
* The application file (or bundle directory, on OS X)
* @param uri
* The uri to be loaded by the application
*/
void openApplicationWithURI(in nsILocalFile aApplication, in ACString aURI);
};

View File

@@ -49,6 +49,7 @@
#include "nsIStringBundle.h"
#include "gfxIImageFrame.h"
#include "nsIOutputStream.h"
#include "nsIProcess.h"
#include "nsNetUtil.h"
#include "nsIDOMHTMLImageElement.h"
#include "nsIImageLoadingContent.h"
@@ -541,3 +542,22 @@ nsGNOMEShellService::OpenApplication(PRInt32 aApplication)
return err ? NS_OK : NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsGNOMEShellService::OpenApplicationWithURI(nsILocalFile* aApplication, const nsACString& aURI)
{
nsresult rv;
nsCOMPtr<nsIProcess> process =
do_CreateInstance("@mozilla.org/process/util;1", &rv);
if (NS_FAILED(rv))
return rv;
rv = process->Init(aApplication);
if (NS_FAILED(rv))
return rv;
const nsPromiseFlatCString& spec = PromiseFlatCString(aURI);
const char* specStr = spec.get();
PRUint32 pid;
return process->Run(PR_FALSE, &specStr, 1, &pid);
}

View File

@@ -42,6 +42,7 @@
#include "nsIImageLoadingContent.h"
#include "nsIDocument.h"
#include "nsIContent.h"
#include "nsILocalFileMac.h"
#include "nsIObserverService.h"
#include "nsIPrefService.h"
#include "nsIServiceManager.h"
@@ -457,3 +458,41 @@ nsMacShellService::SetDesktopBackgroundColor(PRUint32 aColor)
// supports.
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsMacShellService::OpenApplicationWithURI(nsILocalFile* aApplication, const nsACString& aURI)
{
nsCOMPtr<nsILocalFileMac> lfm(do_QueryInterface(aApplication));
CFURLRef appURL;
nsresult rv = lfm->GetCFURL(&appURL);
if (NS_FAILED(rv))
return rv;
const nsPromiseFlatCString& spec = PromiseFlatCString(aURI);
const UInt8* uriString = (const UInt8*)spec.get();
CFURLRef uri = ::CFURLCreateWithBytes(NULL, uriString, aURI.Length(),
kCFStringEncodingUTF8, NULL);
if (!uri)
return NS_ERROR_OUT_OF_MEMORY;
CFArrayRef uris = ::CFArrayCreate(NULL, (const void**)&uri, 1, NULL);
if (!uris) {
::CFRelease(uri);
return NS_ERROR_OUT_OF_MEMORY;
}
LSLaunchURLSpec launchSpec;
launchSpec.appURL = appURL;
launchSpec.itemURLs = uris;
launchSpec.passThruParams = NULL;
launchSpec.launchFlags = kLSLaunchDefaults;
launchSpec.asyncRefCon = NULL;
OSErr err = ::LSOpenFromURLSpec(&launchSpec, NULL);
::CFRelease(uris);
::CFRelease(uri);
return err != noErr ? NS_ERROR_FAILURE : NS_OK;
}

View File

@@ -54,6 +54,7 @@
#include "nsShellService.h"
#include "nsWindowsShellService.h"
#include "nsIObserverService.h"
#include "nsIProcess.h"
#include "nsICategoryManager.h"
#include "nsBrowserCompsCID.h"
#include "nsNativeCharsetUtils.h"
@@ -1079,3 +1080,22 @@ nsWindowsShellService::Observe(nsISupports* aObject, const char* aTopic, const P
return NS_OK;
}
NS_IMETHODIMP
nsWindowsShellService::OpenApplicationWithURI(nsILocalFile* aApplication, const ACString& aURI)
{
nsresult rv;
nsCOMPtr<nsIProcess> process =
do_CreateInstance("@mozilla.org/process/util;1", &rv);
if (NS_FAILED(rv))
return rv;
rv = process->Init(aApplication);
if (NS_FAILED(rv))
return rv;
const nsPromiseFlatCString& spec = PromiseFlatCString(aURI);
const char* specStr = spec.get();
PRUint32 pid;
return process->Run(PR_FALSE, &specStr, 1, &pid);
}