diff --git a/mozilla/uriloader/exthandler/mac/nsOSHelperAppService.cpp b/mozilla/uriloader/exthandler/mac/nsOSHelperAppService.cpp index 80c2e132a8c..e8572a6bc92 100644 --- a/mozilla/uriloader/exthandler/mac/nsOSHelperAppService.cpp +++ b/mozilla/uriloader/exthandler/mac/nsOSHelperAppService.cpp @@ -38,104 +38,6 @@ nsOSHelperAppService::nsOSHelperAppService() : nsExternalHelperAppService() nsOSHelperAppService::~nsOSHelperAppService() {} - -NS_IMETHODIMP nsOSHelperAppService::CanHandleContent(const char *aMimeContentType, nsIURI * aURI, PRBool * aCanHandleContent) -{ - // once we have user over ride stuff working, we need to first call up to our base class - // and ask the base class if we can handle the content. This will take care of looking for user specified - // apps for content types. - - // for now we only have defaults to worry about... - // go look up in the windows registry to see if there is a handler for this mime type...if there is return TRUE... - *aCanHandleContent = PR_FALSE; - nsresult rv = nsExternalHelperAppService::CanHandleContent(aMimeContentType, aURI,aCanHandleContent); - - if (NS_FAILED(rv) || *aCanHandleContent == PR_FALSE) - { - nsCOMPtr icService (do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID)); - if (icService) - { - rv = icService->HasMappingForMIMEType(aMimeContentType, aCanHandleContent); - } - } - return rv; -} - -NS_IMETHODIMP nsOSHelperAppService::DoContent(const char *aMimeContentType, nsIURI *aURI, nsISupports *aWindowContext, - PRBool *aAbortProcess, nsIStreamListener ** aStreamListener) -{ - nsresult rv = NS_OK; - nsCOMPtr url = do_QueryInterface(aURI); - - // see if we have user specified information for handling this content type by giving the base class - // first crack at it... - - rv = nsExternalHelperAppService::DoContent(aMimeContentType, aURI, aWindowContext, aAbortProcess, aStreamListener); - - // this is important!! if do content for the base class returned any success code, then assume we are done - // and don't even play around with - if (NS_SUCCEEDED(rv)) - { - if (((strcmp(aMimeContentType, UNKNOWN_CONTENT_TYPE) == 0) || - (strcmp(aMimeContentType, APPLICATION_OCTET_STREAM) == 0)) && - url) - { - // trap for unknown or octet-stream to check for a ".bin" file - char str[16]; - char *strptr = str; - url->GetFileExtension(&strptr); - if (*strptr) - { - if (strcmp(strptr, "bin") != 0) - { - return NS_OK; - } - else - { - // it's a ".bin" file, on Mac, it's probably a MacBinary file - // do lookup in Internet Config - rv = NS_ERROR_FAILURE; - } - } - } - else - { - return NS_OK; - } - } - - *aStreamListener = nsnull; - - // first, try to see if we can find the content based on just the specified content type... - nsCOMPtr mimeInfo; - rv = GetFromMIMEType(aMimeContentType, getter_AddRefs(mimeInfo)); - // if we didn't find a match OR if the extesnion is a .bin, then use internet config... - if (NS_FAILED(rv) || !mimeInfo || strcmp(aMimeContentType, APPLICATION_OCTET_STREAM) == 0) - { - // if the content based search failed, then try looking up based on the file extension.... - if (url) - { - nsXPIDLCString extension; - url->GetFileExtension(getter_Copies(extension)); - if (extension) - rv = GetFromExtension(extension, getter_AddRefs(mimeInfo)); - } - - } - - if (NS_SUCCEEDED(rv) && mimeInfo) - { - // create an app handler to handle the content... - nsXPIDLCString fileExtension; - mimeInfo->FirstExtension(getter_Copies(fileExtension)); - nsExternalAppHandler * handler = CreateNewExternalHandler(mimeInfo, fileExtension, aWindowContext); - handler->QueryInterface(NS_GET_IID(nsIStreamListener), (void **) aStreamListener); - rv = NS_OK; - } - - return rv; -} - NS_IMETHODIMP nsOSHelperAppService::LaunchAppWithTempFile(nsIMIMEInfo * aMIMEInfo, nsIFile * aTempFile) { nsresult rv = NS_OK; diff --git a/mozilla/uriloader/exthandler/mac/nsOSHelperAppService.h b/mozilla/uriloader/exthandler/mac/nsOSHelperAppService.h index 8337093e054..b7778050e7f 100644 --- a/mozilla/uriloader/exthandler/mac/nsOSHelperAppService.h +++ b/mozilla/uriloader/exthandler/mac/nsOSHelperAppService.h @@ -38,8 +38,6 @@ public: virtual ~nsOSHelperAppService(); // override nsIExternalHelperAppService methods.... - NS_IMETHOD CanHandleContent(const char *aMimeContentType, nsIURI * aURI, PRBool *_retval); - NS_IMETHOD DoContent(const char *aMimeContentType, nsIURI *aURI, nsISupports *aWindowContext, PRBool *aAbortProcess, nsIStreamListener **_retval); NS_IMETHOD LaunchAppWithTempFile(nsIMIMEInfo *aMIMEInfo, nsIFile * aTempFile); // override nsIExternalProtocolService methods diff --git a/mozilla/uriloader/exthandler/nsExternalHelperAppService.cpp b/mozilla/uriloader/exthandler/nsExternalHelperAppService.cpp index 55e048766dc..792e3e3e3cd 100644 --- a/mozilla/uriloader/exthandler/nsExternalHelperAppService.cpp +++ b/mozilla/uriloader/exthandler/nsExternalHelperAppService.cpp @@ -197,38 +197,66 @@ nsresult nsExternalHelperAppService::InitDataSource() /* boolean canHandleContent (in string aMimeContentType); */ NS_IMETHODIMP nsExternalHelperAppService::CanHandleContent(const char *aMimeContentType, nsIURI * aURI, PRBool *_retval) { - return NS_ERROR_NOT_IMPLEMENTED; + *_retval = PR_FALSE; + return NS_OK; } -// it's ESSENTIAL that this method return an error code if we were unable to determine how this content should be handle -// this allows derived OS implementations of Docontent to step in and look for OS specific solutions. NS_IMETHODIMP nsExternalHelperAppService::DoContent(const char *aMimeContentType, nsIURI *aURI, nsISupports *aWindowContext, PRBool *aAbortProcess, nsIStreamListener ** aStreamListener) { - InitDataSource(); - - // (1) try to get a mime info object for the content type....if we don't know anything about the type, then - // we certainly can't handle it and we'll just return without creating a stream listener. - *aStreamListener = nsnull; - nsCOMPtr mimeInfo; - nsresult rv = GetMIMEInfoForMimeTypeFromDS(aMimeContentType, getter_AddRefs(mimeInfo)); + nsXPIDLCString fileExtension; - if (NS_SUCCEEDED(rv) && mimeInfo) + // (1) Try to find a mime object by looking the mime type + nsresult rv = GetFromMIMEType(aMimeContentType, getter_AddRefs(mimeInfo)); + + // here's a nifty little trick. If we got a match back for the content type; but the content type is + // unknown or octet (both of these are pretty much unhelpful mime objects), then see if the file extension + // produces a better mime object... + if (((nsCRT::strcmp(aMimeContentType, UNKNOWN_CONTENT_TYPE) == 0) || + (nsCRT::strcmp(aMimeContentType, APPLICATION_OCTET_STREAM) == 0) || + !mimeInfo)) { - // ask the OS specific subclass to create a stream listener for us that binds this suggested application - // even if this fails, return NS_OK... - nsXPIDLCString fileExtension; - mimeInfo->FirstExtension(getter_Copies(fileExtension)); - nsExternalAppHandler * app = CreateNewExternalHandler(mimeInfo, fileExtension, aWindowContext); - if (app) - app->QueryInterface(NS_GET_IID(nsIStreamListener), (void **) aStreamListener); - return NS_OK; + // if we couldn't find one, don't give up yet! Try and see if there is an extension in the + // url itself... + nsCOMPtr url = do_QueryInterface(aURI); + if (url) + { + url->GetFileExtension(getter_Copies(fileExtension)); + nsCOMPtr tempMIMEObject; + GetFromExtension(fileExtension, getter_AddRefs(tempMIMEObject)); + // only over write mimeInfo if we got a non-null temp mime info object. + if (tempMIMEObject) + mimeInfo = tempMIMEObject; + } } - // if we made it here, then we were unable to handle this ourselves..return an error so the - // derived class will know to try OS specific wonders on it. - return NS_ERROR_FAILURE; + // (3) if we STILL don't have a mime object for this content type then give up + // and create a new mime info object for it and use it + if (!mimeInfo) + { + mimeInfo = do_CreateInstance(NS_MIMEINFO_CONTRACTID); + if (mimeInfo) + { + // the file extension was conviently already filled in by our call to FindOSMimeInfoForType. + mimeInfo->SetFileExtensions(fileExtension); + mimeInfo->SetMIMEType(aMimeContentType); + // we may need to add a new method to nsIMIMEService so we can add this mime info object to our mime service. + } + } + + *aStreamListener = nsnull; + if (mimeInfo) + { + // ensure that the file extension field is always filled in + mimeInfo->FirstExtension(getter_Copies(fileExtension)); + + // this code is incomplete and just here to get things started.. + nsExternalAppHandler * handler = CreateNewExternalHandler(mimeInfo, fileExtension, aWindowContext); + handler->QueryInterface(NS_GET_IID(nsIStreamListener), (void **) aStreamListener); + } + + return NS_OK; } NS_IMETHODIMP nsExternalHelperAppService::LaunchAppWithTempFile(nsIMIMEInfo * aMimeInfo, nsIFile * aTempFile) diff --git a/mozilla/uriloader/exthandler/nsExternalHelperAppService.h b/mozilla/uriloader/exthandler/nsExternalHelperAppService.h index fc9201aea74..0ff11d8f45e 100644 --- a/mozilla/uriloader/exthandler/nsExternalHelperAppService.h +++ b/mozilla/uriloader/exthandler/nsExternalHelperAppService.h @@ -75,7 +75,7 @@ public: // rdf data source. This can be a mac file spec, a unix path or a windows path depending on the platform // aFile --> an nsIFile representation of that platform application path. virtual nsresult GetFileTokenForPath(const PRUnichar * platformAppPath, nsIFile ** aFile) = 0; - + protected: nsCOMPtr mOverRideDataSource; diff --git a/mozilla/uriloader/exthandler/os2/nsOSHelperAppService.cpp b/mozilla/uriloader/exthandler/os2/nsOSHelperAppService.cpp index e4fc761cb6f..48ad451e787 100644 --- a/mozilla/uriloader/exthandler/os2/nsOSHelperAppService.cpp +++ b/mozilla/uriloader/exthandler/os2/nsOSHelperAppService.cpp @@ -39,23 +39,6 @@ nsOSHelperAppService::nsOSHelperAppService() : nsExternalHelperAppService() nsOSHelperAppService::~nsOSHelperAppService() {} - -NS_IMETHODIMP nsOSHelperAppService::CanHandleContent(const char *aMimeContentType, nsIURI * aURI, PRBool * aCanHandleContent) -{ - // once we have user over ride stuff working, we need to first call up to our base class - // and ask the base class if we can handle the content. This will take care of looking for user specified - // apps for content types. - - *aCanHandleContent = PR_FALSE; - nsresult rv = nsExternalHelperAppService::CanHandleContent(aMimeContentType, aURI,aCanHandleContent); - - if (NS_FAILED(rv) || *aCanHandleContent == PR_FALSE) - { - - } - return NS_OK; -} - nsresult nsOSHelperAppService::FindOSMimeInfoForType(const char * aMimeContentType, nsIURI * aURI, char ** aFileExtension, nsIMIMEInfo ** aMIMEInfo) { nsresult rv = NS_OK; @@ -108,41 +91,6 @@ nsresult nsOSHelperAppService::FindOSMimeInfoForType(const char * aMimeContentTy return rv; } -NS_IMETHODIMP nsOSHelperAppService::DoContent(const char *aMimeContentType, nsIURI *aURI, nsISupports *aWindowContext, - PRBool *aAbortProcess, nsIStreamListener ** aStreamListener) -{ - nsresult rv = NS_OK; - - // see if we have user specified information for handling this content type by giving the base class - // first crack at it... - - rv = nsExternalHelperAppService::DoContent(aMimeContentType, aURI, aWindowContext, aAbortProcess, aStreamListener); - - // this is important!! if do content for the base class returned any success code, then assume we are done - // and don't even play around with - if (NS_SUCCEEDED(rv)) return NS_OK; - - // okay the base class couldn't do anything so now it's our turn!!! - - // ACK!!! we've done all this work to discover the content type just to find out that windows - // registery uses the extension to figure out the right helper app....that's a bummer... - // now we need to try to get the extension for the content type... - - nsCOMPtr mimeInfo; - nsXPIDLCString fileExtension; - rv = FindOSMimeInfoForType(aMimeContentType, aURI, getter_Copies(fileExtension), getter_AddRefs(mimeInfo)); - - *aStreamListener = nsnull; - if (NS_SUCCEEDED(rv) && mimeInfo) - { - // this code is incomplete and just here to get things started.. - nsExternalAppHandler * handler = CreateNewExternalHandler(mimeInfo, fileExtension, aWindowContext); - handler->QueryInterface(NS_GET_IID(nsIStreamListener), (void **) aStreamListener); - } - - return rv; -} - NS_IMETHODIMP nsOSHelperAppService::LaunchAppWithTempFile(nsIMIMEInfo * aMIMEInfo, nsIFile * aTempFile) { nsresult rv = NS_OK; diff --git a/mozilla/uriloader/exthandler/os2/nsOSHelperAppService.h b/mozilla/uriloader/exthandler/os2/nsOSHelperAppService.h index a09b1fc64f9..4e99a546df5 100644 --- a/mozilla/uriloader/exthandler/os2/nsOSHelperAppService.h +++ b/mozilla/uriloader/exthandler/os2/nsOSHelperAppService.h @@ -38,8 +38,6 @@ public: virtual ~nsOSHelperAppService(); // override nsIExternalHelperAppService methods.... - NS_IMETHOD CanHandleContent(const char *aMimeContentType, nsIURI * aURI, PRBool *_retval); - NS_IMETHOD DoContent(const char *aMimeContentType, nsIURI *aURI, nsISupports *aWindowContext, PRBool *aAbortProcess, nsIStreamListener **_retval); NS_IMETHOD LaunchAppWithTempFile(nsIMIMEInfo *aMIMEInfo, nsIFile * aTempFile); // override nsIExternalProtocolService methods diff --git a/mozilla/uriloader/exthandler/unix/nsOSHelperAppService.cpp b/mozilla/uriloader/exthandler/unix/nsOSHelperAppService.cpp index 09b98b0be7a..3fb34c0d80a 100644 --- a/mozilla/uriloader/exthandler/unix/nsOSHelperAppService.cpp +++ b/mozilla/uriloader/exthandler/unix/nsOSHelperAppService.cpp @@ -36,66 +36,6 @@ nsOSHelperAppService::nsOSHelperAppService() : nsExternalHelperAppService() nsOSHelperAppService::~nsOSHelperAppService() {} - -NS_IMETHODIMP nsOSHelperAppService::CanHandleContent(const char *aMimeContentType, nsIURI * aURI, PRBool * aCanHandleContent) -{ - // once we have user over ride stuff working, we need to first call up to our base class - // and ask the base class if we can handle the content. This will take care of looking for user specified - // apps for content types. - - // for now we only have defaults to worry about... - // go look up in the windows registry to see if there is a handler for this mime type...if there is return TRUE... - - *aCanHandleContent = PR_FALSE; - return NS_OK; -} - -NS_IMETHODIMP nsOSHelperAppService::DoContent(const char *aMimeContentType, nsIURI *aURI, nsISupports *aWindowContext, - PRBool *aAbortProcess, nsIStreamListener ** aStreamListener) -{ - nsresult rv = NS_OK; - - // see if we have user specified information for handling this content type by giving the base class - // first crack at it... - - rv = nsExternalHelperAppService::DoContent(aMimeContentType, aURI, aWindowContext, aAbortProcess, aStreamListener); - - // this is important!! if do content for the base class returned any success code, then assume we are done - // and don't even play around with - if (NS_SUCCEEDED(rv)) return NS_OK; - - // there is no registry on linux (like there is on win32) - // so we can only make up a dummy mime type for this content.... - nsCOMPtr mimeInfo (do_CreateInstance(NS_MIMEINFO_CONTRACTID)); - nsCAutoString fileExtension; - - *aStreamListener = nsnull; - if (aURI) - { - nsCOMPtr url = do_QueryInterface(aURI); - if (url) { - nsXPIDLCString extenion; - url->GetFileExtension(getter_Copies(extenion)); - - fileExtension = "."; - fileExtension.Append(extenion); - } - } - - if (mimeInfo) - { - if (!fileExtension.IsEmpty()) - mimeInfo->SetFileExtensions(fileExtension); - mimeInfo->SetMIMEType(aMimeContentType); - - // this code is incomplete and just here to get things started.. - nsExternalAppHandler * handler = CreateNewExternalHandler(mimeInfo, fileExtension, aWindowContext); - handler->QueryInterface(NS_GET_IID(nsIStreamListener), (void **) aStreamListener); - } - - return NS_OK; -} - NS_IMETHODIMP nsOSHelperAppService::LaunchAppWithTempFile(nsIMIMEInfo * aMIMEInfo, nsIFile * aTempFile) { nsresult rv = NS_OK; diff --git a/mozilla/uriloader/exthandler/unix/nsOSHelperAppService.h b/mozilla/uriloader/exthandler/unix/nsOSHelperAppService.h index f82e7e228c7..4adc6279653 100644 --- a/mozilla/uriloader/exthandler/unix/nsOSHelperAppService.h +++ b/mozilla/uriloader/exthandler/unix/nsOSHelperAppService.h @@ -38,8 +38,6 @@ public: virtual ~nsOSHelperAppService(); // override nsIExternalHelperAppService methods.... - NS_IMETHOD CanHandleContent(const char *aMimeContentType, nsIURI * aURI, PRBool *_retval); - NS_IMETHOD DoContent(const char *aMimeContentType, nsIURI *aURI, nsISupports *aWindowContext, PRBool *aAbortProcess, nsIStreamListener **_retval); NS_IMETHOD LaunchAppWithTempFile(nsIMIMEInfo *aMIMEInfo, nsIFile * aTempFile); // override nsIExternalProtocolService methods diff --git a/mozilla/uriloader/exthandler/win/nsOSHelperAppService.cpp b/mozilla/uriloader/exthandler/win/nsOSHelperAppService.cpp index df487c14070..094f7db01a6 100644 --- a/mozilla/uriloader/exthandler/win/nsOSHelperAppService.cpp +++ b/mozilla/uriloader/exthandler/win/nsOSHelperAppService.cpp @@ -43,100 +43,6 @@ nsOSHelperAppService::nsOSHelperAppService() : nsExternalHelperAppService() nsOSHelperAppService::~nsOSHelperAppService() {} - -NS_IMETHODIMP nsOSHelperAppService::CanHandleContent(const char *aMimeContentType, nsIURI * aURI, PRBool * aCanHandleContent) -{ - // once we have user over ride stuff working, we need to first call up to our base class - // and ask the base class if we can handle the content. This will take care of looking for user specified - // apps for content types. - - *aCanHandleContent = PR_FALSE; - nsresult rv = nsExternalHelperAppService::CanHandleContent(aMimeContentType, aURI,aCanHandleContent); - - if (NS_FAILED(rv) || *aCanHandleContent == PR_FALSE) - { - - } - return NS_OK; -} - -NS_IMETHODIMP nsOSHelperAppService::DoContent(const char *aMimeContentType, nsIURI *aURI, nsISupports *aWindowContext, - PRBool *aAbortProcess, nsIStreamListener ** aStreamListener) -{ - nsresult rv = NS_OK; - - // see if we have user specified information for handling this content type by giving the base class - // first crack at it... - - rv = nsExternalHelperAppService::DoContent(aMimeContentType, aURI, aWindowContext, aAbortProcess, aStreamListener); - - // this is important!! if do content for the base class returned any success code, then assume we are done - // and don't even play around with - if (NS_SUCCEEDED(rv)) return NS_OK; - - // okay the base class couldn't do anything so now it's our turn!!! - // reset our rv value. - rv = NS_OK; - - // ACK!!! we've done all this work to discover the content type just to find out that windows - // registery uses the extension to figure out the right helper app....that's a bummer... - // now we need to try to get the extension for the content type... - - nsCOMPtr mimeInfo; - nsXPIDLCString fileExtension; - - GetFromMIMEType(aMimeContentType, getter_AddRefs(mimeInfo)); - - // here's a nifty little trick. If we got a match back for the content type; but the content type is - // unknown or octet (both of these are pretty much unhelpful mime objects), then see if the file extension - // produces a better mime object... - if (((nsCRT::strcmp(aMimeContentType, UNKNOWN_CONTENT_TYPE) == 0) || - (nsCRT::strcmp(aMimeContentType, APPLICATION_OCTET_STREAM) == 0) || - !mimeInfo)) - { - // if we couldn't find one, don't give up yet! Try and see if there is an extension in the - // url itself... - nsCOMPtr url = do_QueryInterface(aURI); - - if (url) - { - url->GetFileExtension(getter_Copies(fileExtension)); - nsCOMPtr tempMIMEObject; - GetFromExtension(fileExtension, getter_AddRefs(tempMIMEObject)); - // only over write mimeInfo if we got a non-null temp mime info object. - if (tempMIMEObject) - mimeInfo = tempMIMEObject; - } - } - - if (!mimeInfo) - { - // if we didn't get a mime info object then the OS knows nothing about this mime type and WE know nothing about this mime type - // so create a new mime info object and use it.... - mimeInfo = do_CreateInstance(NS_MIMEINFO_CONTRACTID); - if (mimeInfo) - { - // the file extension was conviently already filled in by our call to FindOSMimeInfoForType. - mimeInfo->SetFileExtensions(fileExtension); - mimeInfo->SetMIMEType(aMimeContentType); - // we may need to add a new method to nsIMIMEService so we can add this mime info object to our mime service. - } - } - - *aStreamListener = nsnull; - if (NS_SUCCEEDED(rv) && mimeInfo) - { - // ensure that the file extension field is always filled in - mimeInfo->FirstExtension(getter_Copies(fileExtension)); - - // this code is incomplete and just here to get things started.. - nsExternalAppHandler * handler = CreateNewExternalHandler(mimeInfo, fileExtension, aWindowContext); - handler->QueryInterface(NS_GET_IID(nsIStreamListener), (void **) aStreamListener); - } - - return rv; -} - NS_IMETHODIMP nsOSHelperAppService::LaunchAppWithTempFile(nsIMIMEInfo * aMIMEInfo, nsIFile * aTempFile) { nsresult rv = NS_OK; diff --git a/mozilla/uriloader/exthandler/win/nsOSHelperAppService.h b/mozilla/uriloader/exthandler/win/nsOSHelperAppService.h index a09b1fc64f9..4e99a546df5 100644 --- a/mozilla/uriloader/exthandler/win/nsOSHelperAppService.h +++ b/mozilla/uriloader/exthandler/win/nsOSHelperAppService.h @@ -38,8 +38,6 @@ public: virtual ~nsOSHelperAppService(); // override nsIExternalHelperAppService methods.... - NS_IMETHOD CanHandleContent(const char *aMimeContentType, nsIURI * aURI, PRBool *_retval); - NS_IMETHOD DoContent(const char *aMimeContentType, nsIURI *aURI, nsISupports *aWindowContext, PRBool *aAbortProcess, nsIStreamListener **_retval); NS_IMETHOD LaunchAppWithTempFile(nsIMIMEInfo *aMIMEInfo, nsIFile * aTempFile); // override nsIExternalProtocolService methods