|
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_IMAGELIB_IMAGEFACTORY_H_ |
|
8 #define MOZILLA_IMAGELIB_IMAGEFACTORY_H_ |
|
9 |
|
10 #include "nsCOMPtr.h" |
|
11 #include "nsProxyRelease.h" |
|
12 |
|
13 class nsCString; |
|
14 class nsIRequest; |
|
15 class imgStatusTracker; |
|
16 |
|
17 namespace mozilla { |
|
18 namespace image { |
|
19 |
|
20 class Image; |
|
21 class ImageURL; |
|
22 |
|
23 class ImageFactory |
|
24 { |
|
25 public: |
|
26 /** |
|
27 * Registers vars with Preferences. Should only be called on the main thread. |
|
28 */ |
|
29 static void Initialize(); |
|
30 |
|
31 /** |
|
32 * Determines whether it's safe to retarget OnDataAvailable for an image. |
|
33 * |
|
34 * @param aURI The URI of the image. |
|
35 * @param aIsMultipart Whether the image is part of a multipart request. |
|
36 */ |
|
37 static bool CanRetargetOnDataAvailable(ImageURL* aURI, bool aIsMultiPart); |
|
38 |
|
39 /** |
|
40 * Creates a new image with the given properties. |
|
41 * Can be called on or off the main thread. |
|
42 * |
|
43 * @param aRequest The associated request. |
|
44 * @param aStatusTracker A status tracker for the image to use. |
|
45 * @param aMimeType The mimetype of the image. |
|
46 * @param aURI The URI of the image. |
|
47 * @param aIsMultiPart Whether the image is part of a multipart request. |
|
48 * @param aInnerWindowId The window this image belongs to. |
|
49 */ |
|
50 static already_AddRefed<Image> CreateImage(nsIRequest* aRequest, |
|
51 imgStatusTracker* aStatusTracker, |
|
52 const nsCString& aMimeType, |
|
53 ImageURL* aURI, |
|
54 bool aIsMultiPart, |
|
55 uint32_t aInnerWindowId); |
|
56 /** |
|
57 * Creates a new image which isn't associated with a URI or loaded through |
|
58 * the usual image loading mechanism. |
|
59 * |
|
60 * @param aMimeType The mimetype of the image. |
|
61 */ |
|
62 static already_AddRefed<Image> CreateAnonymousImage(const nsCString& aMimeType); |
|
63 |
|
64 private: |
|
65 // Factory functions that create specific types of image containers. |
|
66 static already_AddRefed<Image> CreateRasterImage(nsIRequest* aRequest, |
|
67 imgStatusTracker* aStatusTracker, |
|
68 const nsCString& aMimeType, |
|
69 ImageURL* aURI, |
|
70 uint32_t aImageFlags, |
|
71 uint32_t aInnerWindowId); |
|
72 |
|
73 static already_AddRefed<Image> CreateVectorImage(nsIRequest* aRequest, |
|
74 imgStatusTracker* aStatusTracker, |
|
75 const nsCString& aMimeType, |
|
76 ImageURL* aURI, |
|
77 uint32_t aImageFlags, |
|
78 uint32_t aInnerWindowId); |
|
79 |
|
80 // This is a static factory class, so disallow instantiation. |
|
81 virtual ~ImageFactory() = 0; |
|
82 }; |
|
83 |
|
84 } // namespace image |
|
85 } // namespace mozilla |
|
86 |
|
87 #endif // MOZILLA_IMAGELIB_IMAGEFACTORY_H_ |