Implement the HTML5 canvas tainting rules to prevent potential data leakage
[WebKit-https.git] / WebCore / html / CanvasPattern.h
index 1e30229612f760ab1d9a9adee9519484ad0b560a..867870204150fadb4ecb48dfd2b03065cbf2ae43 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
-#ifndef HTMLImagePattern_h
-#define HTMLImagePattern_h
+#ifndef CanvasPattern_h
+#define CanvasPattern_h
 
-#include "CachedObjectClient.h"
-#include "Shared.h"
+#include "CachedResourceClient.h"
+#include <wtf/RefCounted.h>
 
-#if __APPLE__
+#if PLATFORM(CG)
+#include <wtf/RetainPtr.h>
 #include <ApplicationServices/ApplicationServices.h>
+#elif PLATFORM(CAIRO)
+#include <cairo.h>
 #endif
 
 namespace WebCore {
@@ -38,21 +41,45 @@ namespace WebCore {
     class CachedImage;
     class String;
 
-    class CanvasPattern : public Shared<CanvasPattern>, CachedObjectClient {
+    typedef int ExceptionCode;
+
+    class CanvasPattern : public RefCounted<CanvasPattern>, CachedResourceClient {
     public:
-        CanvasPattern(CachedImage*, const String& repetitionType);
+        static void parseRepetitionType(const String&, bool& repeatX, bool& repeatY, ExceptionCode&);
+
+#if PLATFORM(CG)
+        CanvasPattern(CGImageRef, bool repeatX, bool repeatY, bool originClean);
+#elif PLATFORM(CAIRO)
+        CanvasPattern(cairo_surface_t*, bool repeatX, bool repeatY, bool originClean);
+#endif
+        CanvasPattern(CachedImage*, bool repeatX, bool repeatY, bool originClean);
         ~CanvasPattern();
 
+#if PLATFORM(CG)
+        CGImageRef platformImage() const { return m_platformImage.get(); }
+#elif PLATFORM(CAIRO)
+        cairo_surface_t* platformImage() const { return m_platformImage; }
+#endif
         CachedImage* cachedImage() const { return m_cachedImage; }
 
-#if __APPLE__
+#if PLATFORM(CG)
         CGPatternRef createPattern(const CGAffineTransform&);
+#elif PLATFORM(CAIRO)
+        cairo_pattern_t* createPattern(const cairo_matrix_t&);
 #endif
 
+        bool originClean() const { return m_originClean; }
+
     private:
+#if PLATFORM(CG)
+        const RetainPtr<CGImageRef> m_platformImage;
+#elif PLATFORM(CAIRO)
+        cairo_surface_t* const m_platformImage;
+#endif
         CachedImage* const m_cachedImage;
         const bool m_repeatX;
         const bool m_repeatY;
+        bool m_originClean;
     };
 
 } // namespace WebCore