Implement the HTML5 canvas tainting rules to prevent potential data leakage
[WebKit-https.git] / WebCore / html / CanvasPattern.h
index 57b489b0f0e9ed681741ffb7509f66a260ba58c8..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 "CachedResourceClient.h"
-#include "Shared.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 {
@@ -40,32 +43,43 @@ namespace WebCore {
 
     typedef int ExceptionCode;
 
-    class CanvasPattern : public Shared<CanvasPattern>, CachedResourceClient {
+    class CanvasPattern : public RefCounted<CanvasPattern>, CachedResourceClient {
     public:
         static void parseRepetitionType(const String&, bool& repeatX, bool& repeatY, ExceptionCode&);
 
-#if __APPLE__
-        CanvasPattern(CGImageRef, bool repeatX, bool repeatY);
+#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);
+        CanvasPattern(CachedImage*, bool repeatX, bool repeatY, bool originClean);
         ~CanvasPattern();
 
-#if __APPLE__
-        CGImageRef platformImage() const { return m_platformImage; }
+#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 __APPLE__
-        const CGImageRef m_platformImage;
+#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