| 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 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 } | 558 } |
| 559 } | 559 } |
| 560 return toDataURLInternal(mimeType, quality, BackBuffer); | 560 return toDataURLInternal(mimeType, quality, BackBuffer); |
| 561 } | 561 } |
| 562 | 562 |
| 563 void HTMLCanvasElement::encodeImageAsync(DOMUint8ClampedArray* imageData, IntSiz
e imageSize, FileCallback* callback, const String& mimeType, double quality) | 563 void HTMLCanvasElement::encodeImageAsync(DOMUint8ClampedArray* imageData, IntSiz
e imageSize, FileCallback* callback, const String& mimeType, double quality) |
| 564 { | 564 { |
| 565 OwnPtr<Vector<char>> encodedImage(adoptPtr(new Vector<char>())); | 565 OwnPtr<Vector<char>> encodedImage(adoptPtr(new Vector<char>())); |
| 566 | 566 |
| 567 if (!ImageDataBuffer(imageSize, imageData->data()).encodeImage(mimeType, qua
lity, encodedImage.get())) { | 567 if (!ImageDataBuffer(imageSize, imageData->data()).encodeImage(mimeType, qua
lity, encodedImage.get())) { |
| 568 Platform::current()->mainThread()->taskRunner()->postTask(FROM_HERE, bin
d(&FileCallback::handleEvent, callback, nullptr)); | 568 Platform::current()->mainThread()->taskRunner()->postTask(BLINK_FROM_HER
E, bind(&FileCallback::handleEvent, callback, nullptr)); |
| 569 } else { | 569 } else { |
| 570 Platform::current()->mainThread()->taskRunner()->postTask(FROM_HERE, thr
eadSafeBind(&HTMLCanvasElement::createBlobAndCall, encodedImage.release(), mimeT
ype, AllowCrossThreadAccess(callback))); | 570 Platform::current()->mainThread()->taskRunner()->postTask(BLINK_FROM_HER
E, threadSafeBind(&HTMLCanvasElement::createBlobAndCall, encodedImage.release(),
mimeType, AllowCrossThreadAccess(callback))); |
| 571 } | 571 } |
| 572 } | 572 } |
| 573 | 573 |
| 574 void HTMLCanvasElement::createBlobAndCall(PassOwnPtr<Vector<char>> encodedImage,
const String& mimeType, FileCallback* callback) | 574 void HTMLCanvasElement::createBlobAndCall(PassOwnPtr<Vector<char>> encodedImage,
const String& mimeType, FileCallback* callback) |
| 575 { | 575 { |
| 576 // The main thread takes ownership of encoded image vector | 576 // The main thread takes ownership of encoded image vector |
| 577 OwnPtr<Vector<char>> enc(encodedImage); | 577 OwnPtr<Vector<char>> enc(encodedImage); |
| 578 | 578 |
| 579 File* resultBlob = File::create(enc->data(), enc->size(), mimeType); | 579 File* resultBlob = File::create(enc->data(), enc->size(), mimeType); |
| 580 Platform::current()->mainThread()->taskRunner()->postTask(FROM_HERE, bind(&F
ileCallback::handleEvent, callback, resultBlob)); | 580 Platform::current()->mainThread()->taskRunner()->postTask(BLINK_FROM_HERE, b
ind(&FileCallback::handleEvent, callback, resultBlob)); |
| 581 } | 581 } |
| 582 | 582 |
| 583 void HTMLCanvasElement::toBlob(FileCallback* callback, const String& mimeType, c
onst ScriptValue& qualityArgument, ExceptionState& exceptionState) | 583 void HTMLCanvasElement::toBlob(FileCallback* callback, const String& mimeType, c
onst ScriptValue& qualityArgument, ExceptionState& exceptionState) |
| 584 { | 584 { |
| 585 if (!originClean()) { | 585 if (!originClean()) { |
| 586 exceptionState.throwSecurityError("Tainted canvases may not be exported.
"); | 586 exceptionState.throwSecurityError("Tainted canvases may not be exported.
"); |
| 587 return; | 587 return; |
| 588 } | 588 } |
| 589 | 589 |
| 590 if (!isPaintable()) { | 590 if (!isPaintable()) { |
| 591 // If the canvas element's bitmap has no pixels | 591 // If the canvas element's bitmap has no pixels |
| 592 Platform::current()->mainThread()->taskRunner()->postTask(FROM_HERE, bin
d(&FileCallback::handleEvent, callback, nullptr)); | 592 Platform::current()->mainThread()->taskRunner()->postTask(BLINK_FROM_HER
E, bind(&FileCallback::handleEvent, callback, nullptr)); |
| 593 return; | 593 return; |
| 594 } | 594 } |
| 595 | 595 |
| 596 double quality = UndefinedQualityValue; | 596 double quality = UndefinedQualityValue; |
| 597 if (!qualityArgument.isEmpty()) { | 597 if (!qualityArgument.isEmpty()) { |
| 598 v8::Local<v8::Value> v8Value = qualityArgument.v8Value(); | 598 v8::Local<v8::Value> v8Value = qualityArgument.v8Value(); |
| 599 if (v8Value->IsNumber()) { | 599 if (v8Value->IsNumber()) { |
| 600 quality = v8Value.As<v8::Number>()->Value(); | 600 quality = v8Value.As<v8::Number>()->Value(); |
| 601 } | 601 } |
| 602 } | 602 } |
| 603 | 603 |
| 604 String encodingMimeType = toEncodingMimeType(mimeType); | 604 String encodingMimeType = toEncodingMimeType(mimeType); |
| 605 | 605 |
| 606 ImageData* imageData = toImageData(BackBuffer); | 606 ImageData* imageData = toImageData(BackBuffer); |
| 607 // imageData unref its data, which we still keep alive for the async toBlob
thread | 607 // imageData unref its data, which we still keep alive for the async toBlob
thread |
| 608 ScopedDisposal<ImageData> disposer(imageData); | 608 ScopedDisposal<ImageData> disposer(imageData); |
| 609 | 609 |
| 610 // Add a ref to keep image data alive until completion of encoding | 610 // Add a ref to keep image data alive until completion of encoding |
| 611 RefPtr<DOMUint8ClampedArray> imageDataRef(imageData->data()); | 611 RefPtr<DOMUint8ClampedArray> imageDataRef(imageData->data()); |
| 612 | 612 |
| 613 getToBlobThreadInstance()->taskRunner()->postTask(FROM_HERE, new Task(thread
SafeBind(&HTMLCanvasElement::encodeImageAsync, AllowCrossThreadAccess(imageDataR
ef.release().leakRef()), imageData->size(), AllowCrossThreadAccess(callback), en
codingMimeType, quality))); | 613 getToBlobThreadInstance()->taskRunner()->postTask(BLINK_FROM_HERE, new Task(
threadSafeBind(&HTMLCanvasElement::encodeImageAsync, AllowCrossThreadAccess(imag
eDataRef.release().leakRef()), imageData->size(), AllowCrossThreadAccess(callbac
k), encodingMimeType, quality))); |
| 614 } | 614 } |
| 615 | 615 |
| 616 SecurityOrigin* HTMLCanvasElement::securityOrigin() const | 616 SecurityOrigin* HTMLCanvasElement::securityOrigin() const |
| 617 { | 617 { |
| 618 return document().securityOrigin(); | 618 return document().securityOrigin(); |
| 619 } | 619 } |
| 620 | 620 |
| 621 bool HTMLCanvasElement::originClean() const | 621 bool HTMLCanvasElement::originClean() const |
| 622 { | 622 { |
| 623 if (document().settings() && document().settings()->disableReadingFromCanvas
()) | 623 if (document().settings() && document().settings()->disableReadingFromCanvas
()) |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 979 { | 979 { |
| 980 return FloatSize(width(), height()); | 980 return FloatSize(width(), height()); |
| 981 } | 981 } |
| 982 | 982 |
| 983 bool HTMLCanvasElement::isOpaque() const | 983 bool HTMLCanvasElement::isOpaque() const |
| 984 { | 984 { |
| 985 return m_context && !m_context->hasAlpha(); | 985 return m_context && !m_context->hasAlpha(); |
| 986 } | 986 } |
| 987 | 987 |
| 988 } // blink | 988 } // blink |
| OLD | NEW |