Chromium Code Reviews| 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 16 matching lines...) Expand all Loading... | |
| 27 | 27 |
| 28 #include "config.h" | 28 #include "config.h" |
| 29 #include "core/html/HTMLCanvasElement.h" | 29 #include "core/html/HTMLCanvasElement.h" |
| 30 | 30 |
| 31 #include "bindings/core/v8/ExceptionMessages.h" | 31 #include "bindings/core/v8/ExceptionMessages.h" |
| 32 #include "bindings/core/v8/ExceptionState.h" | 32 #include "bindings/core/v8/ExceptionState.h" |
| 33 #include "bindings/core/v8/ScriptController.h" | 33 #include "bindings/core/v8/ScriptController.h" |
| 34 #include "core/HTMLNames.h" | 34 #include "core/HTMLNames.h" |
| 35 #include "core/dom/Document.h" | 35 #include "core/dom/Document.h" |
| 36 #include "core/dom/ExceptionCode.h" | 36 #include "core/dom/ExceptionCode.h" |
| 37 #include "core/fileapi/File.h" | |
| 37 #include "core/frame/LocalFrame.h" | 38 #include "core/frame/LocalFrame.h" |
| 38 #include "core/frame/Settings.h" | 39 #include "core/frame/Settings.h" |
| 39 #include "core/html/ImageData.h" | 40 #include "core/html/ImageData.h" |
| 40 #include "core/html/canvas/CanvasContextCreationAttributes.h" | 41 #include "core/html/canvas/CanvasContextCreationAttributes.h" |
| 41 #include "core/html/canvas/CanvasFontCache.h" | 42 #include "core/html/canvas/CanvasFontCache.h" |
| 42 #include "core/html/canvas/CanvasRenderingContext.h" | 43 #include "core/html/canvas/CanvasRenderingContext.h" |
| 43 #include "core/html/canvas/CanvasRenderingContextFactory.h" | 44 #include "core/html/canvas/CanvasRenderingContextFactory.h" |
| 44 #include "core/layout/LayoutHTMLCanvas.h" | 45 #include "core/layout/LayoutHTMLCanvas.h" |
| 45 #include "core/paint/DeprecatedPaintLayer.h" | 46 #include "core/paint/DeprecatedPaintLayer.h" |
| 46 #include "platform/MIMETypeRegistry.h" | 47 #include "platform/MIMETypeRegistry.h" |
| 47 #include "platform/RuntimeEnabledFeatures.h" | 48 #include "platform/RuntimeEnabledFeatures.h" |
| 48 #include "platform/graphics/Canvas2DImageBufferSurface.h" | 49 #include "platform/graphics/Canvas2DImageBufferSurface.h" |
| 49 #include "platform/graphics/ExpensiveCanvasHeuristicParameters.h" | 50 #include "platform/graphics/ExpensiveCanvasHeuristicParameters.h" |
| 50 #include "platform/graphics/ImageBuffer.h" | 51 #include "platform/graphics/ImageBuffer.h" |
| 51 #include "platform/graphics/RecordingImageBufferSurface.h" | 52 #include "platform/graphics/RecordingImageBufferSurface.h" |
| 52 #include "platform/graphics/StaticBitmapImage.h" | 53 #include "platform/graphics/StaticBitmapImage.h" |
| 53 #include "platform/graphics/UnacceleratedImageBufferSurface.h" | 54 #include "platform/graphics/UnacceleratedImageBufferSurface.h" |
| 54 #include "platform/graphics/gpu/AcceleratedImageBufferSurface.h" | 55 #include "platform/graphics/gpu/AcceleratedImageBufferSurface.h" |
| 55 #include "platform/transforms/AffineTransform.h" | 56 #include "platform/transforms/AffineTransform.h" |
| 56 #include "public/platform/Platform.h" | 57 #include "public/platform/Platform.h" |
| 58 #include "public/platform/WebTraceLocation.h" | |
| 59 #include "wtf/Functional.h" | |
| 57 #include <math.h> | 60 #include <math.h> |
| 58 #include <v8.h> | 61 #include <v8.h> |
| 59 | 62 |
| 60 namespace blink { | 63 namespace blink { |
| 61 | 64 |
| 62 using namespace HTMLNames; | 65 using namespace HTMLNames; |
| 63 | 66 |
| 64 namespace { | 67 namespace { |
| 65 | 68 |
| 66 // These values come from the WhatWG spec. | 69 // These values come from the WhatWG spec. |
| (...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 531 if (!qualityArgument.isEmpty()) { | 534 if (!qualityArgument.isEmpty()) { |
| 532 v8::Local<v8::Value> v8Value = qualityArgument.v8Value(); | 535 v8::Local<v8::Value> v8Value = qualityArgument.v8Value(); |
| 533 if (v8Value->IsNumber()) { | 536 if (v8Value->IsNumber()) { |
| 534 quality = v8Value.As<v8::Number>()->Value(); | 537 quality = v8Value.As<v8::Number>()->Value(); |
| 535 qualityPtr = &quality; | 538 qualityPtr = &quality; |
| 536 } | 539 } |
| 537 } | 540 } |
| 538 return toDataURLInternal(mimeType, qualityPtr, BackBuffer); | 541 return toDataURLInternal(mimeType, qualityPtr, BackBuffer); |
| 539 } | 542 } |
| 540 | 543 |
| 544 void HTMLCanvasElement::toBlob(FileCallback* callback, const String& mimeType, c onst ScriptValue& qualityArgument, ExceptionState& exceptionState) const | |
| 545 { | |
| 546 if (!originClean()) { | |
| 547 exceptionState.throwSecurityError("Tainted canvases may not be exported. "); | |
| 548 return; | |
| 549 } | |
| 550 | |
| 551 File* resultBlob = nullptr; | |
| 552 if (!isPaintable()) { | |
| 553 // If the canvas element's bitmap has no pixels | |
| 554 return; | |
|
Noel Gordon
2015/08/28 08:53:47
I don't think the spec allows us to just return he
xlai (Olivia)
2015/08/28 19:54:19
Acknowledged. The spec says "If the canvas element
| |
| 555 } | |
| 556 | |
| 557 double quality; | |
| 558 if (!qualityArgument.isEmpty()) { | |
| 559 v8::Local<v8::Value> v8Value = qualityArgument.v8Value(); | |
| 560 if (v8Value->IsNumber()) { | |
| 561 quality = v8Value.As<v8::Number>()->Value(); | |
| 562 } | |
| 563 } | |
| 564 | |
| 565 String encodingMimeType = toEncodingMimeType(mimeType); | |
| 566 | |
| 567 ImageData* imageData = toImageData(BackBuffer); | |
| 568 ScopedDisposal<ImageData> disposer(imageData); | |
| 569 | |
| 570 // Perform image encoding | |
| 571 Vector<char> encodedImage; | |
| 572 ImageDataBuffer(imageData->size(), imageData->data()->data()).encodeImage(en codingMimeType, &quality, &encodedImage); | |
|
Noel Gordon
2015/08/28 08:53:47
encodeImage is bool returning (success/failure).
xlai (Olivia)
2015/08/28 19:54:19
Acknowledged. I will explain in the overall messag
| |
| 573 resultBlob = File::create(encodedImage.data(), encodedImage.size(), encoding MimeType); | |
| 574 | |
| 575 Platform::current()->mainThread()->postTask(FROM_HERE, bind(&FileCallback::h andleEvent, callback, resultBlob)); | |
| 576 } | |
| 577 | |
| 541 SecurityOrigin* HTMLCanvasElement::securityOrigin() const | 578 SecurityOrigin* HTMLCanvasElement::securityOrigin() const |
| 542 { | 579 { |
| 543 return document().securityOrigin(); | 580 return document().securityOrigin(); |
| 544 } | 581 } |
| 545 | 582 |
| 546 bool HTMLCanvasElement::originClean() const | 583 bool HTMLCanvasElement::originClean() const |
| 547 { | 584 { |
| 548 if (document().settings() && document().settings()->disableReadingFromCanvas ()) | 585 if (document().settings() && document().settings()->disableReadingFromCanvas ()) |
| 549 return false; | 586 return false; |
| 550 return m_originClean; | 587 return m_originClean; |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 904 { | 941 { |
| 905 return FloatSize(width(), height()); | 942 return FloatSize(width(), height()); |
| 906 } | 943 } |
| 907 | 944 |
| 908 bool HTMLCanvasElement::isOpaque() const | 945 bool HTMLCanvasElement::isOpaque() const |
| 909 { | 946 { |
| 910 return m_context && !m_context->hasAlpha(); | 947 return m_context && !m_context->hasAlpha(); |
| 911 } | 948 } |
| 912 | 949 |
| 913 } // blink | 950 } // blink |
| OLD | NEW |