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 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 { | 376 { |
377 String lowercaseMimeType = mimeType.lower(); | 377 String lowercaseMimeType = mimeType.lower(); |
378 | 378 |
379 // FIXME: Make isSupportedImageMIMETypeForEncoding threadsafe (to allow this
method to be used on a worker thread). | 379 // FIXME: Make isSupportedImageMIMETypeForEncoding threadsafe (to allow this
method to be used on a worker thread). |
380 if (mimeType.isNull() || !MIMETypeRegistry::isSupportedImageMIMETypeForEncod
ing(lowercaseMimeType)) | 380 if (mimeType.isNull() || !MIMETypeRegistry::isSupportedImageMIMETypeForEncod
ing(lowercaseMimeType)) |
381 lowercaseMimeType = "image/png"; | 381 lowercaseMimeType = "image/png"; |
382 | 382 |
383 return lowercaseMimeType; | 383 return lowercaseMimeType; |
384 } | 384 } |
385 | 385 |
386 String HTMLCanvasElement::toDataURL(const String& mimeType, const double* qualit
y, ExceptionState& exceptionState) | 386 const AtomicString HTMLCanvasElement::imageSourceURL() const |
387 { | 387 { |
388 if (!m_originClean) { | 388 return AtomicString(toDataURLInternal("image/png", 0)); |
389 exceptionState.throwSecurityError("Tainted canvases may not be exported.
"); | 389 } |
390 return String(); | |
391 } | |
392 | 390 |
| 391 String HTMLCanvasElement::toDataURLInternal(const String& mimeType, const double
* quality) const |
| 392 { |
393 if (m_size.isEmpty() || !buffer()) | 393 if (m_size.isEmpty() || !buffer()) |
394 return String("data:,"); | 394 return String("data:,"); |
395 | 395 |
396 String encodingMimeType = toEncodingMimeType(mimeType); | 396 String encodingMimeType = toEncodingMimeType(mimeType); |
397 | 397 |
398 // Try to get ImageData first, as that may avoid lossy conversions. | 398 // Try to get ImageData first, as that may avoid lossy conversions. |
399 RefPtrWillBeRawPtr<ImageData> imageData = getImageData(); | 399 RefPtrWillBeRawPtr<ImageData> imageData = getImageData(); |
400 | 400 |
401 if (imageData) | 401 if (imageData) |
402 return ImageDataToDataURL(ImageDataBuffer(imageData->size(), imageData->
data()), encodingMimeType, quality); | 402 return ImageDataToDataURL(ImageDataBuffer(imageData->size(), imageData->
data()), encodingMimeType, quality); |
403 | 403 |
404 if (m_context) | 404 if (m_context) |
405 m_context->paintRenderingResultsToCanvas(); | 405 m_context->paintRenderingResultsToCanvas(); |
406 | 406 |
407 return buffer()->toDataURL(encodingMimeType, quality); | 407 return buffer()->toDataURL(encodingMimeType, quality); |
408 } | 408 } |
409 | 409 |
410 PassRefPtrWillBeRawPtr<ImageData> HTMLCanvasElement::getImageData() | 410 String HTMLCanvasElement::toDataURL(const String& mimeType, const double* qualit
y, ExceptionState& exceptionState) const |
| 411 { |
| 412 if (!m_originClean) { |
| 413 exceptionState.throwSecurityError("Tainted canvases may not be exported.
"); |
| 414 return String(); |
| 415 } |
| 416 |
| 417 return toDataURLInternal(mimeType, quality); |
| 418 } |
| 419 |
| 420 PassRefPtrWillBeRawPtr<ImageData> HTMLCanvasElement::getImageData() const |
411 { | 421 { |
412 if (!m_context || !m_context->is3d()) | 422 if (!m_context || !m_context->is3d()) |
413 return nullptr; | 423 return nullptr; |
414 return toWebGLRenderingContext(m_context.get())->paintRenderingResultsToImag
eData(); | 424 return toWebGLRenderingContext(m_context.get())->paintRenderingResultsToImag
eData(); |
415 } | 425 } |
416 | 426 |
417 SecurityOrigin* HTMLCanvasElement::securityOrigin() const | 427 SecurityOrigin* HTMLCanvasElement::securityOrigin() const |
418 { | 428 { |
419 return document().securityOrigin(); | 429 return document().securityOrigin(); |
420 } | 430 } |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 { | 706 { |
697 return !originClean(); | 707 return !originClean(); |
698 } | 708 } |
699 | 709 |
700 FloatSize HTMLCanvasElement::sourceSize() const | 710 FloatSize HTMLCanvasElement::sourceSize() const |
701 { | 711 { |
702 return FloatSize(width(), height()); | 712 return FloatSize(width(), height()); |
703 } | 713 } |
704 | 714 |
705 } | 715 } |
OLD | NEW |