2 * Copyright (c) 2013, Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef ImageBitmapFactories_h
32 #define ImageBitmapFactories_h
34 #include "bindings/core/v8/ScriptPromise.h"
35 #include "bindings/core/v8/ScriptPromiseResolver.h"
36 #include "bindings/core/v8/ScriptState.h"
37 #include "core/fileapi/FileReaderLoader.h"
38 #include "core/fileapi/FileReaderLoaderClient.h"
39 #include "platform/Supplementable.h"
40 #include "platform/geometry/IntRect.h"
41 #include "wtf/Forward.h"
42 #include "wtf/HashSet.h"
47 class CanvasRenderingContext2D;
50 class HTMLCanvasElement;
51 class HTMLImageElement;
52 class HTMLVideoElement;
55 class ExecutionContext;
57 class ImageBitmapFactories FINAL : public NoBaseWillBeGarbageCollectedFinalized<ImageBitmapFactories>, public WillBeHeapSupplement<LocalDOMWindow>, public WillBeHeapSupplement<WorkerGlobalScope> {
58 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(ImageBitmapFactories);
61 static ScriptPromise createImageBitmap(ScriptState*, EventTarget&, HTMLImageElement*, ExceptionState&);
62 static ScriptPromise createImageBitmap(ScriptState*, EventTarget&, HTMLImageElement*, int sx, int sy, int sw, int sh, ExceptionState&);
63 static ScriptPromise createImageBitmap(ScriptState*, EventTarget&, HTMLVideoElement*, ExceptionState&);
64 static ScriptPromise createImageBitmap(ScriptState*, EventTarget&, HTMLVideoElement*, int sx, int sy, int sw, int sh, ExceptionState&);
65 static ScriptPromise createImageBitmap(ScriptState*, EventTarget&, CanvasRenderingContext2D*, ExceptionState&);
66 static ScriptPromise createImageBitmap(ScriptState*, EventTarget&, CanvasRenderingContext2D*, int sx, int sy, int sw, int sh, ExceptionState&);
67 static ScriptPromise createImageBitmap(ScriptState*, EventTarget&, HTMLCanvasElement*, ExceptionState&);
68 static ScriptPromise createImageBitmap(ScriptState*, EventTarget&, HTMLCanvasElement*, int sx, int sy, int sw, int sh, ExceptionState&);
69 static ScriptPromise createImageBitmap(ScriptState*, EventTarget&, Blob*, ExceptionState&);
70 static ScriptPromise createImageBitmap(ScriptState*, EventTarget&, Blob*, int sx, int sy, int sw, int sh, ExceptionState&);
71 static ScriptPromise createImageBitmap(ScriptState*, EventTarget&, ImageData*, ExceptionState&);
72 static ScriptPromise createImageBitmap(ScriptState*, EventTarget&, ImageData*, int sx, int sy, int sw, int sh, ExceptionState&);
73 static ScriptPromise createImageBitmap(ScriptState*, EventTarget&, ImageBitmap*, ExceptionState&);
74 static ScriptPromise createImageBitmap(ScriptState*, EventTarget&, ImageBitmap*, int sx, int sy, int sw, int sh, ExceptionState&);
76 virtual ~ImageBitmapFactories() { }
81 static const char* supplementName();
84 class ImageBitmapLoader FINAL : public GarbageCollectedFinalized<ImageBitmapLoader>, public FileReaderLoaderClient {
86 static ImageBitmapLoader* create(ImageBitmapFactories& factory, const IntRect& cropRect, ScriptState* scriptState)
88 return new ImageBitmapLoader(factory, cropRect, scriptState);
91 void loadBlobAsync(ExecutionContext*, Blob*);
92 ScriptPromise promise() { return m_resolver->promise(); }
96 virtual ~ImageBitmapLoader() { }
99 ImageBitmapLoader(ImageBitmapFactories&, const IntRect&, ScriptState*);
101 void rejectPromise();
103 // FileReaderLoaderClient
104 virtual void didStartLoading() OVERRIDE { }
105 virtual void didReceiveData() OVERRIDE { }
106 virtual void didFinishLoading() OVERRIDE;
107 virtual void didFail(FileError::ErrorCode) OVERRIDE;
109 FileReaderLoader m_loader;
110 RawPtrWillBeMember<ImageBitmapFactories> m_factory;
111 RefPtr<ScriptPromiseResolver> m_resolver;
115 static ImageBitmapFactories& from(EventTarget&);
117 template<class GlobalObject>
118 static ImageBitmapFactories& fromInternal(GlobalObject&);
120 void addLoader(ImageBitmapLoader*);
121 void didFinishLoading(ImageBitmapLoader*);
123 PersistentHeapHashSetWillBeHeapHashSet<Member<ImageBitmapLoader> > m_pendingLoaders;
128 #endif // ImageBitmapFactories_h