Skip to content

Commit

Permalink
Bug 389969 - There is no protocol handling dialog. r=cbiesinger, sr=d…
Browse files Browse the repository at this point in the history
…mose, a=schrep
  • Loading branch information
sdwilsh@shawnwilsher.com committed Jul 30, 2007
1 parent c310f89 commit e50a443
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 24 deletions.
4 changes: 4 additions & 0 deletions netwerk/mime/public/nsIMIMEInfo.idl
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ interface nsIHandlerInfo : nsISupports {
attribute nsHandlerInfoAction preferredAction;

const long saveToDisk = 0;
/**
* Used to indicate that we know nothing about what to do with this. You
* could consider this to be not initialized.
*/
const long alwaysAsk = 1;
const long useHelperApp = 2;
const long handleInternally = 3;
Expand Down
14 changes: 10 additions & 4 deletions uriloader/exthandler/beos/nsOSHelperAppService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,21 +233,27 @@ nsOSHelperAppService::GetMIMEInfoFromOS(const nsACString& aMIMEType, const nsACS
}

already_AddRefed<nsIHandlerInfo>
nsOSHelperAppService::GetProtocolInfoFromOS(const nsACString &aScheme)
nsOSHelperAppService::GetProtocolInfoFromOS(const nsACString &aScheme,
PRBool *found)
{
NS_ASSERTION(!aScheme.IsEmpty(), "No scheme was specified!");

PRBool exists;
nsresult rv = OSProtocolHandlerExists(nsPromiseFlatCString(aScheme).get(),
&exists);
if (NS_FAILED(rv) || !exists)
found);
if (NS_FAILED(rv))
return nsnull;

nsMIMEInfoBeOS *handlerInfo =
new nsMIMEInfoBeOS(aScheme, nsMIMEInfoBase::eProtocolInfo);
NS_ENSURE_TRUE(handlerInfo, nsnull);
NS_ADDREF(handlerInfo);

if (!*found) {
// Code that calls this requires an object regardless if the OS has
// something for us, so we return the empty object.
return handlerInfo;
}

nsAutoString desc;
GetApplicationDescription(aScheme, desc);
handlerInfo->SetDefaultDescription(desc);
Expand Down
3 changes: 2 additions & 1 deletion uriloader/exthandler/beos/nsOSHelperAppService.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ class nsOSHelperAppService : public nsExternalHelperAppService
virtual ~nsOSHelperAppService();

already_AddRefed<nsIMIMEInfo> GetMIMEInfoFromOS(const nsACString& aMIMEType, const nsACString& aFileExt, PRBool *aFound);
already_AddRefed<nsIHandlerInfo> GetProtocolInfoFromOS(const nsACString &aScheme);
already_AddRefed<nsIHandlerInfo> GetProtocolInfoFromOS(const nsACString &aScheme,
PRBool *found);

// override nsIExternalProtocolService methods
nsresult OSProtocolHandlerExists(const char * aProtocolScheme, PRBool * aHandlerExists);
Expand Down
14 changes: 10 additions & 4 deletions uriloader/exthandler/mac/nsOSHelperAppService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,21 +316,27 @@ nsOSHelperAppService::GetMIMEInfoFromOS(const nsACString& aMIMEType,
}

already_AddRefed<nsIHandlerInfo>
nsOSHelperAppService::GetProtocolInfoFromOS(const nsACString &aScheme)
nsOSHelperAppService::GetProtocolInfoFromOS(const nsACString &aScheme,
PRBool *found)
{
NS_ASSERTION(!aScheme.IsEmpty(), "No scheme was specified!");

PRBool exists;
nsresult rv = OSProtocolHandlerExists(nsPromiseFlatCString(aScheme).get(),
&exists);
if (NS_FAILED(rv) || !exists)
found);
if (NS_FAILED(rv))
return nsnull;

nsMIMEInfoMac *handlerInfo =
new nsMIMEInfoMac(aScheme, nsMIMEInfoBase::eProtocolInfo);
NS_ENSURE_TRUE(handlerInfo, nsnull);
NS_ADDREF(handlerInfo);

if (!*found) {
// Code that calls this requires an object regardless if the OS has
// something for us, so we return the empty object.
return handlerInfo;
}

nsAutoString desc;
GetApplicationDescription(aScheme, desc);
handlerInfo->SetDefaultDescription(desc);
Expand Down
3 changes: 2 additions & 1 deletion uriloader/exthandler/mac/nsOSHelperAppService.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ class nsOSHelperAppService : public nsExternalHelperAppService
// method overrides --> used to hook the mime service into internet config....
NS_IMETHOD GetFromTypeAndExtension(const nsACString& aType, const nsACString& aFileExt, nsIMIMEInfo ** aMIMEInfo);
already_AddRefed<nsIMIMEInfo> GetMIMEInfoFromOS(const nsACString& aMIMEType, const nsACString& aFileExt, PRBool * aFound);
already_AddRefed<nsIHandlerInfo> GetProtocolInfoFromOS(const nsACString &aScheme);
already_AddRefed<nsIHandlerInfo> GetProtocolInfoFromOS(const nsACString &aScheme,
PRBool *found);

// GetFileTokenForPath must be implemented by each platform.
// platformAppPath --> a platform specific path to an application that we got out of the
Expand Down
10 changes: 8 additions & 2 deletions uriloader/exthandler/nsExternalHelperAppService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1337,7 +1337,8 @@ nsExternalHelperAppService::GetProtocolHandlerInfo(const nsACString &aScheme,
// and subclasses have lots of good platform specific-knowledge of local
// applications which we might need later. For now, just use nsMIMEInfoImpl
// instead of implementating a separate nsIHandlerInfo object.
*aHandlerInfo = GetProtocolInfoFromOS(aScheme).get();
PRBool exists;
*aHandlerInfo = GetProtocolInfoFromOS(aScheme, &exists).get();
if (!(*aHandlerInfo)) {
// Either it knows nothing, or we ran out of memory
return NS_ERROR_FAILURE;
Expand All @@ -1350,8 +1351,13 @@ nsExternalHelperAppService::GetProtocolHandlerInfo(const nsACString &aScheme,
// the user, so these defaults are OK.
// XXX this is a bit different than the MIME system, so we may want to look
// into this more in the future.
(*aHandlerInfo)->SetPreferredAction(nsIHandlerInfo::useSystemDefault);
(*aHandlerInfo)->SetAlwaysAskBeforeHandling(PR_TRUE);
// If no OS default existed, we set the preferred action to alwaysAsk. This
// really means not initialized to all the code...
if (exists)
(*aHandlerInfo)->SetPreferredAction(nsIHandlerInfo::useSystemDefault);
else
(*aHandlerInfo)->SetPreferredAction(nsIHandlerInfo::alwaysAsk);
} else if (NS_FAILED(rv)) {
NS_RELEASE(*aHandlerInfo);
return rv;
Expand Down
3 changes: 2 additions & 1 deletion uriloader/exthandler/nsExternalHelperAppService.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ class nsExternalHelperAppService
* @param aScheme The protocol scheme we are looking for.
* @return An nsIHanderInfo for the protocol.
*/
virtual already_AddRefed<nsIHandlerInfo> GetProtocolInfoFromOS(const nsACString &aScheme) = 0;
virtual already_AddRefed<nsIHandlerInfo> GetProtocolInfoFromOS(const nsACString &aScheme,
PRBool *found) = 0;

/**
* Given a string identifying an application, create an nsIFile representing
Expand Down
2 changes: 1 addition & 1 deletion uriloader/exthandler/nsMIMEInfoImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ nsMIMEInfoImpl::GetDefaultDescription(nsAString& aDefaultDescription)
NS_IMETHODIMP
nsMIMEInfoImpl::GetHasDefaultHandler(PRBool * _retval)
{
*_retval = PR_FALSE;
*_retval = !mDefaultAppDescription.IsEmpty();
if (mDefaultApplication) {
PRBool exists;
*_retval = NS_SUCCEEDED(mDefaultApplication->Exists(&exists)) && exists;
Expand Down
14 changes: 10 additions & 4 deletions uriloader/exthandler/unix/nsOSHelperAppService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1635,24 +1635,30 @@ nsOSHelperAppService::GetMIMEInfoFromOS(const nsACString& aType,
}

already_AddRefed<nsIHandlerInfo>
nsOSHelperAppService::GetProtocolInfoFromOS(const nsACString &aScheme)
nsOSHelperAppService::GetProtocolInfoFromOS(const nsACString &aScheme,
PRBool *found)
{
NS_ASSERTION(!aScheme.IsEmpty(), "No scheme was specified!");

// We must check that a registered handler exists so that gnome_url_show
// doesn't fallback to gnomevfs.
// See nsGNOMERegistry::LoadURL and bug 389632.
PRBool exists;
nsresult rv = OSProtocolHandlerExists(nsPromiseFlatCString(aScheme).get(),
&exists);
if (NS_FAILED(rv) || !exists)
found);
if (NS_FAILED(rv))
return nsnull;

nsMIMEInfoUnix *handlerInfo =
new nsMIMEInfoUnix(aScheme, nsMIMEInfoBase::eProtocolInfo);
NS_ENSURE_TRUE(handlerInfo, nsnull);
NS_ADDREF(handlerInfo);

if (!*found) {
// Code that calls this requires an object regardless if the OS has
// something for us, so we return the empty object.
return handlerInfo;
}

nsAutoString desc;
GetApplicationDescription(aScheme, desc);
handlerInfo->SetDefaultDescription(desc);
Expand Down
3 changes: 2 additions & 1 deletion uriloader/exthandler/unix/nsOSHelperAppService.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ class nsOSHelperAppService : public nsExternalHelperAppService
already_AddRefed<nsIMIMEInfo> GetMIMEInfoFromOS(const nsACString& aMimeType,
const nsACString& aFileExt,
PRBool *aFound);
already_AddRefed<nsIHandlerInfo> GetProtocolInfoFromOS(const nsACString &aScheme);
already_AddRefed<nsIHandlerInfo> GetProtocolInfoFromOS(const nsACString &aScheme,
PRBool *found);

// override nsIExternalProtocolService methods
nsresult OSProtocolHandlerExists(const char * aProtocolScheme, PRBool * aHandlerExists);
Expand Down
14 changes: 10 additions & 4 deletions uriloader/exthandler/win/nsOSHelperAppService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,21 +554,27 @@ already_AddRefed<nsIMIMEInfo> nsOSHelperAppService::GetMIMEInfoFromOS(const nsAC
}

already_AddRefed<nsIHandlerInfo>
nsOSHelperAppService::GetProtocolInfoFromOS(const nsACString &aScheme)
nsOSHelperAppService::GetProtocolInfoFromOS(const nsACString &aScheme,
PRBool *found)
{
NS_ASSERTION(!aScheme.IsEmpty(), "No scheme was specified!");

PRBool exists;
nsresult rv = OSProtocolHandlerExists(nsPromiseFlatCString(aScheme).get(),
&exists);
if (NS_FAILED(rv) || !exists)
found);
if (NS_FAILED(rv))
return nsnull;

nsMIMEInfoWin *handlerInfo =
new nsMIMEInfoWin(aScheme, nsMIMEInfoBase::eProtocolInfo);
NS_ENSURE_TRUE(handlerInfo, nsnull);
NS_ADDREF(handlerInfo);

if (!*found) {
// Code that calls this requires an object regardless if the OS has
// something for us, so we return the empty object.
return handlerInfo;
}

nsAutoString desc;
GetApplicationDescription(aScheme, desc);
handlerInfo->SetDefaultDescription(desc);
Expand Down
3 changes: 2 additions & 1 deletion uriloader/exthandler/win/nsOSHelperAppService.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ class nsOSHelperAppService : public nsExternalHelperAppService

// method overrides for windows registry look up steps....
already_AddRefed<nsIMIMEInfo> GetMIMEInfoFromOS(const nsACString& aMIMEType, const nsACString& aFileExt, PRBool *aFound);
already_AddRefed<nsIHandlerInfo> GetProtocolInfoFromOS(const nsACString &aScheme);
already_AddRefed<nsIHandlerInfo> GetProtocolInfoFromOS(const nsACString &aScheme,
PRBool *found);

/** Get the string value of a registry value and store it in result.
* @return PR_TRUE on success, PR_FALSE on failure
Expand Down

0 comments on commit e50a443

Please sign in to comment.