зеркало из https://github.com/mozilla/pjs.git
add api to allow one to get the mime type and content disposition from imagelib. bug 287286. r=bz sr=shaver
This commit is contained in:
Родитель
dd97b2ede4
Коммит
e66f9a3d35
|
@ -40,15 +40,17 @@
|
|||
#include "nsISupports.idl"
|
||||
|
||||
interface nsIURI;
|
||||
interface imgIRequest;
|
||||
interface nsIProperties;
|
||||
|
||||
/**
|
||||
* imgICache interface
|
||||
*
|
||||
* @author Stuart Parmenter <pavlov@netscape.com>
|
||||
* @version 0.0
|
||||
* @version 0.1
|
||||
* @see imagelib2
|
||||
*/
|
||||
[scriptable, uuid(075e424c-1dd2-11b2-97bc-e5beb94b874e)]
|
||||
[scriptable, uuid(f1b74aae-5661-4753-a21c-66dd644afebc)]
|
||||
interface imgICache : nsISupports
|
||||
{
|
||||
/**
|
||||
|
@ -67,4 +69,17 @@ interface imgICache : nsISupports
|
|||
* NS_ERROR_NOT_AVAILABLE if \a uri was unable to be removed from the cache.
|
||||
*/
|
||||
void removeEntry(in nsIURI uri);
|
||||
|
||||
/**
|
||||
* Find Properties
|
||||
* Used to get properties such as 'type' and 'content-disposition'
|
||||
* 'type' is a nsISupportsCString containing the images' mime type such as 'image/png'
|
||||
* 'content-disposition' will be a nsISupportsCString containing the header
|
||||
* If you call this before any data has been loaded from a URI, it will succeed,
|
||||
* but come back empty.
|
||||
*
|
||||
* @param uri The URI to look up.
|
||||
* @returns NULL if the URL was not found in the cache
|
||||
*/
|
||||
nsIProperties findEntryProperties(in nsIURI uri);
|
||||
};
|
||||
|
|
|
@ -103,6 +103,30 @@ NS_IMETHODIMP imgCache::RemoveEntry(nsIURI *uri)
|
|||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
/* imgIRequest findEntry(in nsIURI uri); */
|
||||
NS_IMETHODIMP imgCache::FindEntryProperties(nsIURI *uri, nsIProperties **_retval)
|
||||
{
|
||||
PRBool expired;
|
||||
// This is an owning reference that must be released.
|
||||
imgRequest *request = nsnull;
|
||||
nsCOMPtr<nsICacheEntryDescriptor> entry;
|
||||
|
||||
// addrefs request
|
||||
imgCache::Get(uri, &expired, &request, getter_AddRefs(entry));
|
||||
|
||||
*_retval = nsnull;
|
||||
|
||||
if (request) {
|
||||
*_retval = request->Properties();
|
||||
NS_ADDREF(*_retval);
|
||||
}
|
||||
|
||||
NS_IF_RELEASE(request);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
static nsCOMPtr<nsICacheSession> gSession = nsnull;
|
||||
static nsCOMPtr<nsICacheSession> gChromeSession = nsnull;
|
||||
|
||||
|
|
|
@ -61,6 +61,7 @@
|
|||
#include "nsIComponentManager.h"
|
||||
#include "nsIProxyObjectManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsISupportsPrimitives.h"
|
||||
|
||||
#include "nsAutoLock.h"
|
||||
#include "nsString.h"
|
||||
|
@ -100,6 +101,10 @@ nsresult imgRequest::Init(nsIChannel *aChannel,
|
|||
NS_ASSERTION(!mImage, "imgRequest::Init -- Multiple calls to init");
|
||||
NS_ASSERTION(aChannel, "imgRequest::Init -- No channel");
|
||||
|
||||
mProperties = do_CreateInstance("@mozilla.org/properties;1");
|
||||
if (!mProperties)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
mChannel = aChannel;
|
||||
|
||||
/* set our loading flag to true here.
|
||||
|
@ -813,6 +818,32 @@ NS_IMETHODIMP imgRequest::OnDataAvailable(nsIRequest *aRequest, nsISupports *ctx
|
|||
LOG_MSG(gImgLog, "imgRequest::OnDataAvailable", "Got content type from the channel");
|
||||
}
|
||||
|
||||
/* set our mimetype as a property */
|
||||
nsCOMPtr<nsISupportsCString> contentType(do_CreateInstance("@mozilla.org/supports-cstring;1"));
|
||||
if (contentType) {
|
||||
contentType->SetData(mContentType);
|
||||
mProperties->Set("type", contentType);
|
||||
}
|
||||
|
||||
/* set our content disposition as a property */
|
||||
nsCAutoString disposition;
|
||||
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(aRequest));
|
||||
if (httpChannel) {
|
||||
httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("content-disposition"), disposition);
|
||||
} else {
|
||||
nsCOMPtr<nsIMultiPartChannel> multiPartChannel(do_QueryInterface(aRequest));
|
||||
if (multiPartChannel) {
|
||||
multiPartChannel->GetContentDisposition(disposition);
|
||||
}
|
||||
}
|
||||
if (!disposition.IsEmpty()) {
|
||||
nsCOMPtr<nsISupportsCString> contentDisposition(do_CreateInstance("@mozilla.org/supports-cstring;1"));
|
||||
if (contentDisposition) {
|
||||
contentDisposition->SetData(disposition);
|
||||
mProperties->Set("content-disposition", contentDisposition);
|
||||
}
|
||||
}
|
||||
|
||||
LOG_MSG_WITH_PARAM(gImgLog, "imgRequest::OnDataAvailable", "content type", mContentType.get());
|
||||
|
||||
nsCAutoString conid(NS_LITERAL_CSTRING("@mozilla.org/image/decoder;2?type=") + mContentType);
|
||||
|
|
|
@ -48,6 +48,7 @@
|
|||
|
||||
#include "nsICacheEntryDescriptor.h"
|
||||
#include "nsIChannel.h"
|
||||
#include "nsIProperties.h"
|
||||
#include "nsIStreamListener.h"
|
||||
#include "nsIURI.h"
|
||||
|
||||
|
@ -99,6 +100,7 @@ private:
|
|||
friend class imgRequestProxy;
|
||||
friend class imgLoader;
|
||||
friend class imgCacheValidator;
|
||||
friend class imgCache;
|
||||
|
||||
inline void SetLoadId(void *aLoadId) {
|
||||
mLoadId = aLoadId;
|
||||
|
@ -112,6 +114,9 @@ private:
|
|||
inline const char *GetMimeType() const {
|
||||
return mContentType.get();
|
||||
}
|
||||
inline nsIProperties *Properties() {
|
||||
return mProperties;
|
||||
}
|
||||
|
||||
// Return true if at least one of our proxies, excluding
|
||||
// aProxyToIgnore, has an observer. aProxyToIgnore may be null.
|
||||
|
@ -137,6 +142,7 @@ private:
|
|||
nsCOMPtr<nsIURI> mURI;
|
||||
nsCOMPtr<imgIContainer> mImage;
|
||||
nsCOMPtr<imgIDecoder> mDecoder;
|
||||
nsCOMPtr<nsIProperties> mProperties;
|
||||
|
||||
nsVoidArray mObservers;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче