ImageFactory.h (3205B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 2 * 3 * This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_image_ImageFactory_h 8 #define mozilla_image_ImageFactory_h 9 10 #include "nsCOMPtr.h" 11 #include "nsProxyRelease.h" 12 #include "nsStringFwd.h" 13 14 class nsIRequest; 15 class nsIURI; 16 17 namespace mozilla { 18 namespace image { 19 20 class Image; 21 class MultipartImage; 22 class ProgressTracker; 23 24 class ImageFactory { 25 public: 26 /** 27 * Registers vars with Preferences. Should only be called on the main thread. 28 */ 29 static void Initialize(); 30 31 /** 32 * Creates a new image with the given properties. 33 * Can be called on or off the main thread. 34 * 35 * @param aRequest The associated request. 36 * @param aProgressTracker A status tracker for the image to use. 37 * @param aMimeType The mimetype of the image. 38 * @param aURI The URI of the image. 39 * @param aIsMultiPart Whether the image is part of a multipart request. 40 * @param aInnerWindowId The window this image belongs to. 41 */ 42 static already_AddRefed<Image> CreateImage(nsIRequest* aRequest, 43 ProgressTracker* aProgressTracker, 44 const nsCString& aMimeType, 45 nsIURI* aURI, bool aIsMultiPart, 46 uint64_t aInnerWindowId); 47 /** 48 * Creates a new image which isn't associated with a URI or loaded through 49 * the usual image loading mechanism. 50 * 51 * @param aMimeType The mimetype of the image. 52 * @param aSizeHint The length of the source data for the image. 53 */ 54 static already_AddRefed<Image> CreateAnonymousImage( 55 const nsCString& aMimeType, uint32_t aSizeHint = 0); 56 57 /** 58 * Creates a new multipart/x-mixed-replace image wrapper, and initializes it 59 * with the first part. Subsequent parts should be passed to the existing 60 * MultipartImage via MultipartImage::BeginTransitionToPart(). 61 * 62 * @param aFirstPart An image containing the first part of the multipart 63 * stream. 64 * @param aProgressTracker A progress tracker for the multipart image. 65 */ 66 static already_AddRefed<MultipartImage> CreateMultipartImage( 67 Image* aFirstPart, ProgressTracker* aProgressTracker); 68 69 private: 70 // Factory functions that create specific types of image containers. 71 static already_AddRefed<Image> CreateRasterImage( 72 nsIRequest* aRequest, ProgressTracker* aProgressTracker, 73 const nsCString& aMimeType, nsIURI* aURI, uint32_t aImageFlags, 74 uint64_t aInnerWindowId); 75 76 static already_AddRefed<Image> CreateVectorImage( 77 nsIRequest* aRequest, ProgressTracker* aProgressTracker, 78 const nsCString& aMimeType, nsIURI* aURI, uint32_t aImageFlags, 79 uint64_t aInnerWindowId); 80 81 // This is a static factory class, so disallow instantiation. 82 virtual ~ImageFactory() = 0; 83 }; 84 85 } // namespace image 86 } // namespace mozilla 87 88 #endif // mozilla_image_ImageFactory_h