Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp

Issue 1532473002: Add a origin clean flag in ImageBitmap class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: take care of single security origin Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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()), HasS ingleSecurityOrigin);
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 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 if (m_context) 794 if (m_context)
795 setNeedsCompositingUpdate(); 795 setNeedsCompositingUpdate();
796 } 796 }
797 797
798 void HTMLCanvasElement::notifySurfaceInvalid() 798 void HTMLCanvasElement::notifySurfaceInvalid()
799 { 799 {
800 if (m_context && m_context->is2d()) 800 if (m_context && m_context->is2d())
801 m_context->loseContext(CanvasRenderingContext::RealLostContext); 801 m_context->loseContext(CanvasRenderingContext::RealLostContext);
802 } 802 }
803 803
804 bool HTMLCanvasElement::hasSingleSecurityOrigin()
805 {
806 return originClean();
807 }
808
804 DEFINE_TRACE(HTMLCanvasElement) 809 DEFINE_TRACE(HTMLCanvasElement)
805 { 810 {
806 visitor->trace(m_listeners); 811 visitor->trace(m_listeners);
807 visitor->trace(m_context); 812 visitor->trace(m_context);
808 DocumentVisibilityObserver::trace(visitor); 813 DocumentVisibilityObserver::trace(visitor);
809 HTMLElement::trace(visitor); 814 HTMLElement::trace(visitor);
810 } 815 }
811 816
812 void HTMLCanvasElement::updateExternallyAllocatedMemory() const 817 void HTMLCanvasElement::updateExternallyAllocatedMemory() const
813 { 818 {
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
971 return createTransparentImage(size()); 976 return createTransparentImage(size());
972 } 977 }
973 978
974 if (m_context->is3d()) { 979 if (m_context->is3d()) {
975 m_context->paintRenderingResultsToCanvas(BackBuffer); 980 m_context->paintRenderingResultsToCanvas(BackBuffer);
976 } 981 }
977 982
978 RefPtr<SkImage> image = buffer()->newSkImageSnapshot(hint); 983 RefPtr<SkImage> image = buffer()->newSkImageSnapshot(hint);
979 if (image) { 984 if (image) {
980 *status = NormalSourceImageStatus; 985 *status = NormalSourceImageStatus;
981 return StaticBitmapImage::create(image.release()); 986 return StaticBitmapImage::create(image.release(), originClean() ? HasSin gleSecurityOrigin : NoSingleSecurityOrigin);
982 } 987 }
983 988
984 *status = InvalidSourceImageStatus; 989 *status = InvalidSourceImageStatus;
985 return nullptr; 990 return nullptr;
986 } 991 }
987 992
988 bool HTMLCanvasElement::wouldTaintOrigin(SecurityOrigin*) const 993 bool HTMLCanvasElement::wouldTaintOrigin(SecurityOrigin*) const
989 { 994 {
990 return !originClean(); 995 return !originClean();
991 } 996 }
992 997
993 FloatSize HTMLCanvasElement::elementSize() const 998 FloatSize HTMLCanvasElement::elementSize() const
994 { 999 {
995 return FloatSize(width(), height()); 1000 return FloatSize(width(), height());
996 } 1001 }
997 1002
998 IntSize HTMLCanvasElement::bitmapSourceSize() const 1003 IntSize HTMLCanvasElement::bitmapSourceSize() const
999 { 1004 {
1000 return IntSize(width(), height()); 1005 return IntSize(width(), height());
1001 } 1006 }
1002 1007
1003 ScriptPromise HTMLCanvasElement::createImageBitmap(ScriptState* scriptState, Eve ntTarget& eventTarget, int sx, int sy, int sw, int sh, ExceptionState& exception State) 1008 ScriptPromise HTMLCanvasElement::createImageBitmap(ScriptState* scriptState, Eve ntTarget& eventTarget, int sx, int sy, int sw, int sh, ExceptionState& exception State)
1004 { 1009 {
1005 ASSERT(eventTarget.toDOMWindow()); 1010 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) { 1011 if (!sw || !sh) {
1011 exceptionState.throwDOMException(IndexSizeError, String::format("The sou rce %s provided is 0.", sw ? "height" : "width")); 1012 exceptionState.throwDOMException(IndexSizeError, String::format("The sou rce %s provided is 0.", sw ? "height" : "width"));
1012 return ScriptPromise(); 1013 return ScriptPromise();
1013 } 1014 }
1014 return ImageBitmapSource::fulfillImageBitmap(scriptState, isPaintable() ? Im ageBitmap::create(this, IntRect(sx, sy, sw, sh)) : nullptr); 1015 return ImageBitmapSource::fulfillImageBitmap(scriptState, isPaintable() ? Im ageBitmap::create(this, IntRect(sx, sy, sw, sh)) : nullptr);
1015 } 1016 }
1016 1017
1017 bool HTMLCanvasElement::isOpaque() const 1018 bool HTMLCanvasElement::isOpaque() const
1018 { 1019 {
1019 return m_context && !m_context->hasAlpha(); 1020 return m_context && !m_context->hasAlpha();
1020 } 1021 }
1021 1022
1022 } // blink 1023 } // blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698