Loading image/imgIRequest.idl +8 −0 Original line number Diff line number Diff line Loading @@ -100,6 +100,14 @@ interface imgIRequest : nsIRequest readonly attribute string mimeType; /** * The filename that should be used when saving the image. This is determined * from the Content-Disposition, if present, or the uri of the image. This * filename should be validated using nsIMIMEService::GetValidFilenameForSaving * before creating the file. */ readonly attribute ACString fileName; /** * Clone this request; the returned request will have aObserver as the * observer. aObserver will be notified synchronously (before the clone() Loading image/imgRequest.cpp +26 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ #include "nsIScriptSecurityManager.h" #include "nsComponentManagerUtils.h" #include "nsContentUtils.h" #include "nsEscape.h" #include "plstr.h" // PL_strcasestr(...) #include "prtime.h" // for PR_Now Loading @@ -38,6 +39,7 @@ #include "nsIProtocolHandler.h" #include "imgIRequest.h" #include "nsProperties.h" #include "nsIURL.h" #include "mozilla/IntegerPrintfMacros.h" #include "mozilla/SizeOfState.h" Loading Loading @@ -461,6 +463,30 @@ already_AddRefed<image::Image> imgRequest::GetImage() const { return image.forget(); } void imgRequest::GetFileName(nsACString& aFileName) { nsAutoString fileName; nsCOMPtr<nsISupportsCString> supportscstr; if (NS_SUCCEEDED(mProperties->Get("content-disposition", NS_GET_IID(nsISupportsCString), getter_AddRefs(supportscstr))) && supportscstr) { nsAutoCString cdHeader; supportscstr->GetData(cdHeader); NS_GetFilenameFromDisposition(fileName, cdHeader); } if (fileName.IsEmpty()) { nsCOMPtr<nsIURL> imgUrl(do_QueryInterface(mURI)); if (imgUrl) { imgUrl->GetFileName(aFileName); NS_UnescapeURL(aFileName); } } else { aFileName = NS_ConvertUTF16toUTF8(fileName); } } int32_t imgRequest::Priority() const { int32_t priority = nsISupportsPriority::PRIORITY_NORMAL; nsCOMPtr<nsISupportsPriority> p = do_QueryInterface(mRequest); Loading image/imgRequest.h +2 −0 Original line number Diff line number Diff line Loading @@ -151,6 +151,8 @@ class imgRequest final : public nsIStreamListener, /// Returns a non-owning pointer to this imgRequest's MIME type. const char* GetMimeType() const { return mContentType.get(); } void GetFileName(nsACString& aFileName); /// @return the priority of the underlying network request, or /// PRIORITY_NORMAL if it doesn't support nsISupportsPriority. int32_t Priority() const; Loading image/imgRequestProxy.cpp +10 −0 Original line number Diff line number Diff line Loading @@ -747,6 +747,16 @@ imgRequestProxy::GetMimeType(char** aMimeType) { return NS_OK; } NS_IMETHODIMP imgRequestProxy::GetFileName(nsACString& aFileName) { if (!GetOwner()) { return NS_ERROR_FAILURE; } GetOwner()->GetFileName(aFileName); return NS_OK; } imgRequestProxy* imgRequestProxy::NewClonedProxy() { return new imgRequestProxy(); } Loading Loading
image/imgIRequest.idl +8 −0 Original line number Diff line number Diff line Loading @@ -100,6 +100,14 @@ interface imgIRequest : nsIRequest readonly attribute string mimeType; /** * The filename that should be used when saving the image. This is determined * from the Content-Disposition, if present, or the uri of the image. This * filename should be validated using nsIMIMEService::GetValidFilenameForSaving * before creating the file. */ readonly attribute ACString fileName; /** * Clone this request; the returned request will have aObserver as the * observer. aObserver will be notified synchronously (before the clone() Loading
image/imgRequest.cpp +26 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ #include "nsIScriptSecurityManager.h" #include "nsComponentManagerUtils.h" #include "nsContentUtils.h" #include "nsEscape.h" #include "plstr.h" // PL_strcasestr(...) #include "prtime.h" // for PR_Now Loading @@ -38,6 +39,7 @@ #include "nsIProtocolHandler.h" #include "imgIRequest.h" #include "nsProperties.h" #include "nsIURL.h" #include "mozilla/IntegerPrintfMacros.h" #include "mozilla/SizeOfState.h" Loading Loading @@ -461,6 +463,30 @@ already_AddRefed<image::Image> imgRequest::GetImage() const { return image.forget(); } void imgRequest::GetFileName(nsACString& aFileName) { nsAutoString fileName; nsCOMPtr<nsISupportsCString> supportscstr; if (NS_SUCCEEDED(mProperties->Get("content-disposition", NS_GET_IID(nsISupportsCString), getter_AddRefs(supportscstr))) && supportscstr) { nsAutoCString cdHeader; supportscstr->GetData(cdHeader); NS_GetFilenameFromDisposition(fileName, cdHeader); } if (fileName.IsEmpty()) { nsCOMPtr<nsIURL> imgUrl(do_QueryInterface(mURI)); if (imgUrl) { imgUrl->GetFileName(aFileName); NS_UnescapeURL(aFileName); } } else { aFileName = NS_ConvertUTF16toUTF8(fileName); } } int32_t imgRequest::Priority() const { int32_t priority = nsISupportsPriority::PRIORITY_NORMAL; nsCOMPtr<nsISupportsPriority> p = do_QueryInterface(mRequest); Loading
image/imgRequest.h +2 −0 Original line number Diff line number Diff line Loading @@ -151,6 +151,8 @@ class imgRequest final : public nsIStreamListener, /// Returns a non-owning pointer to this imgRequest's MIME type. const char* GetMimeType() const { return mContentType.get(); } void GetFileName(nsACString& aFileName); /// @return the priority of the underlying network request, or /// PRIORITY_NORMAL if it doesn't support nsISupportsPriority. int32_t Priority() const; Loading
image/imgRequestProxy.cpp +10 −0 Original line number Diff line number Diff line Loading @@ -747,6 +747,16 @@ imgRequestProxy::GetMimeType(char** aMimeType) { return NS_OK; } NS_IMETHODIMP imgRequestProxy::GetFileName(nsACString& aFileName) { if (!GetOwner()) { return NS_ERROR_FAILURE; } GetOwner()->GetFileName(aFileName); return NS_OK; } imgRequestProxy* imgRequestProxy::NewClonedProxy() { return new imgRequestProxy(); } Loading