27 #include <nsIInputStream.h>
30 #include <nsComponentManagerUtils.h>
31 #include <nsWeakReference.h>
33 #include <imgIContainer.h>
34 #include <imgIDecoder.h>
35 #include <imgIDecoderObserver.h>
39 public imgIDecoderObserver,
40 public nsSupportsWeakReference
45 NS_DECL_IMGIDECODEROBSERVER
46 NS_DECL_IMGICONTAINEROBSERVER
50 nsCOMPtr<imgIContainer> mContainer;
61 HelperLoader::GetImage(imgIContainer **aImage)
63 NS_ENSURE_ARG_POINTER(aImage);
66 NS_IF_ADDREF (*aImage);
72 HelperLoader::SetImage(imgIContainer *aImage)
80 HelperLoader::GetIsMultiPartChannel(PRBool *aIsMultiPartChannel)
82 NS_ENSURE_ARG_POINTER(aIsMultiPartChannel);
84 *aIsMultiPartChannel = PR_FALSE;
90 HelperLoader::OnStartRequest(imgIRequest *aRequest)
97 HelperLoader::OnStartDecode(imgIRequest *aRequest)
104 HelperLoader::OnStartContainer(imgIRequest *aRequest, imgIContainer
112 HelperLoader::OnStartFrame(imgIRequest *aRequest, PRUint32 aFrame)
119 HelperLoader::OnDataAvailable(imgIRequest *aRequest, PRBool aCurrentFrame,
120 const nsIntRect * aRect)
127 HelperLoader::OnStopFrame(imgIRequest *aRequest, PRUint32 aFrame)
134 HelperLoader::OnStopContainer(imgIRequest *aRequest, imgIContainer
142 HelperLoader::OnStopDecode(imgIRequest *aRequest, nsresult status,
const
143 PRUnichar *statusArg)
150 HelperLoader::OnStopRequest(imgIRequest *aRequest, PRBool aIsLastPart)
157 HelperLoader::FrameChanged(imgIContainer *aContainer,
158 nsIntRect * aDirtyRect)
167 const nsACString& aMimeType,
168 imgIContainer **aContainer)
170 NS_ENSURE_ARG_POINTER(aContainer);
171 NS_ENSURE_ARG_POINTER(aInStr);
175 nsCString decoderCID = NS_LITERAL_CSTRING(
"@mozilla.org/image/decoder;2?type=");
176 decoderCID.Append(aMimeType);
178 nsCOMPtr<imgIDecoder> decoder = do_CreateInstance(decoderCID.get());
180 return NS_ERROR_NOT_AVAILABLE;
185 return NS_ERROR_OUT_OF_MEMORY;
189 loader->SetImage(*aContainer);
191 rv = decoder->Init(loader);
192 NS_ENSURE_SUCCESS(rv, rv);
195 rv = aInStr->Available(&length);
196 NS_ENSURE_SUCCESS(rv, rv);
199 NS_ENSURE_SUCCESS(rv, rv);
200 rv = decoder->WriteFrom(aInStr, length, &written);
201 NS_ENSURE_SUCCESS(rv, rv);
202 if (written != length)
203 NS_WARNING(
"decoder didn't eat all of its vegetables");
204 rv = decoder->Flush();
206 if (rv != NS_ERROR_NOT_IMPLEMENTED) {
207 NS_ENSURE_SUCCESS(rv, rv);
209 rv = decoder->Close();
210 NS_ENSURE_SUCCESS(rv, rv);
214 loader->GetImage(aContainer);
NS_IMPL_ISUPPORTS4(sbDownloadDevice, nsIObserver, sbIDeviceBase, sbIDownloadDevice, sbIMediaListListener) sbDownloadDevice
NS_DECL_ISUPPORTS NS_DECL_IMGILOAD NS_DECL_IMGIDECODEROBSERVER NS_DECL_IMGICONTAINEROBSERVER HelperLoader(void)