| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2007 Alp Toker <alp@atoker.com> | 3 * Copyright (C) 2007 Alp Toker <alp@atoker.com> |
| 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. | 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 if (size.width() > MaxSkiaDim || size.height() > MaxSkiaDim) | 111 if (size.width() > MaxSkiaDim || size.height() > MaxSkiaDim) |
| 112 return false; | 112 return false; |
| 113 return true; | 113 return true; |
| 114 } | 114 } |
| 115 | 115 |
| 116 PassRefPtr<Image> createTransparentImage(const IntSize& size) | 116 PassRefPtr<Image> createTransparentImage(const IntSize& size) |
| 117 { | 117 { |
| 118 ASSERT(canCreateImageBuffer(size)); | 118 ASSERT(canCreateImageBuffer(size)); |
| 119 RefPtr<SkSurface> surface = adoptRef(SkSurface::NewRasterN32Premul(size.widt
h(), size.height())); | 119 RefPtr<SkSurface> surface = adoptRef(SkSurface::NewRasterN32Premul(size.widt
h(), size.height())); |
| 120 surface->getCanvas()->clear(SK_ColorTRANSPARENT); | 120 surface->getCanvas()->clear(SK_ColorTRANSPARENT); |
| 121 return StaticBitmapImage::create(adoptRef(surface->newImageSnapshot())); | 121 return StaticBitmapImage::create(adoptRef(surface->newImageSnapshot()), true
); |
| 122 } | 122 } |
| 123 | 123 |
| 124 } // namespace | 124 } // namespace |
| 125 | 125 |
| 126 inline HTMLCanvasElement::HTMLCanvasElement(Document& document) | 126 inline HTMLCanvasElement::HTMLCanvasElement(Document& document) |
| 127 : HTMLElement(canvasTag, document) | 127 : HTMLElement(canvasTag, document) |
| 128 , DocumentVisibilityObserver(document) | 128 , DocumentVisibilityObserver(document) |
| 129 , m_size(DefaultWidth, DefaultHeight) | 129 , m_size(DefaultWidth, DefaultHeight) |
| 130 , m_ignoreReset(false) | 130 , m_ignoreReset(false) |
| 131 , m_externallyAllocatedMemory(0) | 131 , m_externallyAllocatedMemory(0) |
| (...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 971 return createTransparentImage(size()); | 971 return createTransparentImage(size()); |
| 972 } | 972 } |
| 973 | 973 |
| 974 if (m_context->is3d()) { | 974 if (m_context->is3d()) { |
| 975 m_context->paintRenderingResultsToCanvas(BackBuffer); | 975 m_context->paintRenderingResultsToCanvas(BackBuffer); |
| 976 } | 976 } |
| 977 | 977 |
| 978 RefPtr<SkImage> image = buffer()->newSkImageSnapshot(hint); | 978 RefPtr<SkImage> image = buffer()->newSkImageSnapshot(hint); |
| 979 if (image) { | 979 if (image) { |
| 980 *status = NormalSourceImageStatus; | 980 *status = NormalSourceImageStatus; |
| 981 return StaticBitmapImage::create(image.release()); | 981 return StaticBitmapImage::create(image.release(), true); |
| 982 } | 982 } |
| 983 | 983 |
| 984 *status = InvalidSourceImageStatus; | 984 *status = InvalidSourceImageStatus; |
| 985 return nullptr; | 985 return nullptr; |
| 986 } | 986 } |
| 987 | 987 |
| 988 bool HTMLCanvasElement::wouldTaintOrigin(SecurityOrigin*) const | 988 bool HTMLCanvasElement::wouldTaintOrigin(SecurityOrigin*) const |
| 989 { | 989 { |
| 990 return !originClean(); | 990 return !originClean(); |
| 991 } | 991 } |
| 992 | 992 |
| 993 FloatSize HTMLCanvasElement::elementSize() const | 993 FloatSize HTMLCanvasElement::elementSize() const |
| 994 { | 994 { |
| 995 return FloatSize(width(), height()); | 995 return FloatSize(width(), height()); |
| 996 } | 996 } |
| 997 | 997 |
| 998 IntSize HTMLCanvasElement::bitmapSourceSize() const | 998 IntSize HTMLCanvasElement::bitmapSourceSize() const |
| 999 { | 999 { |
| 1000 return IntSize(width(), height()); | 1000 return IntSize(width(), height()); |
| 1001 } | 1001 } |
| 1002 | 1002 |
| 1003 ScriptPromise HTMLCanvasElement::createImageBitmap(ScriptState* scriptState, Eve
ntTarget& eventTarget, int sx, int sy, int sw, int sh, ExceptionState& exception
State) | 1003 ScriptPromise HTMLCanvasElement::createImageBitmap(ScriptState* scriptState, Eve
ntTarget& eventTarget, int sx, int sy, int sw, int sh, ExceptionState& exception
State) |
| 1004 { | 1004 { |
| 1005 ASSERT(eventTarget.toDOMWindow()); | 1005 ASSERT(eventTarget.toDOMWindow()); |
| 1006 if (!originClean()) { | |
| 1007 exceptionState.throwSecurityError("The canvas element provided is tainte
d with cross-origin data."); | |
| 1008 return ScriptPromise(); | |
| 1009 } | |
| 1010 if (!sw || !sh) { | 1006 if (!sw || !sh) { |
| 1011 exceptionState.throwDOMException(IndexSizeError, String::format("The sou
rce %s provided is 0.", sw ? "height" : "width")); | 1007 exceptionState.throwDOMException(IndexSizeError, String::format("The sou
rce %s provided is 0.", sw ? "height" : "width")); |
| 1012 return ScriptPromise(); | 1008 return ScriptPromise(); |
| 1013 } | 1009 } |
| 1014 return ImageBitmapSource::fulfillImageBitmap(scriptState, isPaintable() ? Im
ageBitmap::create(this, IntRect(sx, sy, sw, sh)) : nullptr); | 1010 return ImageBitmapSource::fulfillImageBitmap(scriptState, isPaintable() ? Im
ageBitmap::create(this, IntRect(sx, sy, sw, sh)) : nullptr); |
| 1015 } | 1011 } |
| 1016 | 1012 |
| 1017 bool HTMLCanvasElement::isOpaque() const | 1013 bool HTMLCanvasElement::isOpaque() const |
| 1018 { | 1014 { |
| 1019 return m_context && !m_context->hasAlpha(); | 1015 return m_context && !m_context->hasAlpha(); |
| 1020 } | 1016 } |
| 1021 | 1017 |
| 1022 } // blink | 1018 } // blink |
| OLD | NEW |