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

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

Issue 255563004: Implement "Save image as" for canvas (blink side). (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 7 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
« no previous file with comments | « Source/core/html/HTMLCanvasElement.h ('k') | Source/core/loader/NavigationPolicy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 { 368 {
369 String lowercaseMimeType = mimeType.lower(); 369 String lowercaseMimeType = mimeType.lower();
370 370
371 // FIXME: Make isSupportedImageMIMETypeForEncoding threadsafe (to allow this method to be used on a worker thread). 371 // FIXME: Make isSupportedImageMIMETypeForEncoding threadsafe (to allow this method to be used on a worker thread).
372 if (mimeType.isNull() || !MIMETypeRegistry::isSupportedImageMIMETypeForEncod ing(lowercaseMimeType)) 372 if (mimeType.isNull() || !MIMETypeRegistry::isSupportedImageMIMETypeForEncod ing(lowercaseMimeType))
373 lowercaseMimeType = "image/png"; 373 lowercaseMimeType = "image/png";
374 374
375 return lowercaseMimeType; 375 return lowercaseMimeType;
376 } 376 }
377 377
378 String HTMLCanvasElement::toDataURL(const String& mimeType, const double* qualit y, ExceptionState& exceptionState) 378 const AtomicString HTMLCanvasElement::imageSourceURL() const
379 { 379 {
380 if (!m_originClean) { 380 return AtomicString(toDataURLInternal("image/png", 0));
381 exceptionState.throwSecurityError("Tainted canvases may not be exported. "); 381 }
382 return String();
383 }
384 382
383 String HTMLCanvasElement::toDataURLInternal(const String& mimeType, const double * quality) const
384 {
385 if (m_size.isEmpty() || !buffer()) 385 if (m_size.isEmpty() || !buffer())
386 return String("data:,"); 386 return String("data:,");
387 387
388 String encodingMimeType = toEncodingMimeType(mimeType); 388 String encodingMimeType = toEncodingMimeType(mimeType);
389 389
390 // Try to get ImageData first, as that may avoid lossy conversions. 390 // Try to get ImageData first, as that may avoid lossy conversions.
391 RefPtrWillBeRawPtr<ImageData> imageData = getImageData(); 391 RefPtrWillBeRawPtr<ImageData> imageData = getImageData();
392 392
393 if (imageData) 393 if (imageData)
394 return ImageDataToDataURL(ImageDataBuffer(imageData->size(), imageData-> data()), encodingMimeType, quality); 394 return ImageDataToDataURL(ImageDataBuffer(imageData->size(), imageData-> data()), encodingMimeType, quality);
395 395
396 if (m_context) 396 if (m_context)
397 m_context->paintRenderingResultsToCanvas(); 397 m_context->paintRenderingResultsToCanvas();
398 398
399 return buffer()->toDataURL(encodingMimeType, quality); 399 return buffer()->toDataURL(encodingMimeType, quality);
400 } 400 }
401 401
402 PassRefPtrWillBeRawPtr<ImageData> HTMLCanvasElement::getImageData() 402 String HTMLCanvasElement::toDataURL(const String& mimeType, const double* qualit y, ExceptionState& exceptionState) const
403 {
404 if (!m_originClean) {
405 exceptionState.throwSecurityError("Tainted canvases may not be exported. ");
406 return String();
407 }
408
409 return toDataURLInternal(mimeType, quality);
410 }
411
412 PassRefPtrWillBeRawPtr<ImageData> HTMLCanvasElement::getImageData() const
403 { 413 {
404 if (!m_context || !m_context->is3d()) 414 if (!m_context || !m_context->is3d())
405 return nullptr; 415 return nullptr;
406 return toWebGLRenderingContext(m_context.get())->paintRenderingResultsToImag eData(); 416 return toWebGLRenderingContext(m_context.get())->paintRenderingResultsToImag eData();
407 } 417 }
408 418
409 SecurityOrigin* HTMLCanvasElement::securityOrigin() const 419 SecurityOrigin* HTMLCanvasElement::securityOrigin() const
410 { 420 {
411 return document().securityOrigin(); 421 return document().securityOrigin();
412 } 422 }
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 { 696 {
687 return !originClean(); 697 return !originClean();
688 } 698 }
689 699
690 FloatSize HTMLCanvasElement::sourceSize() const 700 FloatSize HTMLCanvasElement::sourceSize() const
691 { 701 {
692 return FloatSize(width(), height()); 702 return FloatSize(width(), height());
693 } 703 }
694 704
695 } 705 }
OLDNEW
« no previous file with comments | « Source/core/html/HTMLCanvasElement.h ('k') | Source/core/loader/NavigationPolicy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698