Changeset 208451 in webkit


Ignore:
Timestamp:
Nov 9, 2016 11:14:17 AM (7 years ago)
Author:
Chris Dumez
Message:

Use Blob URL instead of webkit-fake-url when pasting an image
https://bugs.webkit.org/show_bug.cgi?id=49141

Reviewed by Darin Adler.

Source/WebCore:

Use Blob URL instead of webkit-fake-url when pasting an image.

Tests: editing/pasteboard/paste-image-as-blob-url.html

editing/pasteboard/paste-image-using-image-data.html

  • editing/Editor.h:
  • editing/mac/EditorMac.mm:

(WebCore::Editor::WebContentReader::readImage):
(WebCore::Editor::createFragmentForImageAndURL):

LayoutTests:

Add layout test coverage checking that the image shows as expected and that the
resulting URL is indeed a Blob URL.

  • editing/pasteboard/paste-image-as-blob-url-expected.txt: Added.
  • editing/pasteboard/paste-image-as-blob-url.html: Added.
  • editing/pasteboard/paste-image-using-image-data-expected.html: Added.
  • editing/pasteboard/paste-image-using-image-data.html: Added.
Location:
trunk
Files:
4 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r208450 r208451  
     12016-11-09  Chris Dumez  <cdumez@apple.com>
     2
     3        Use Blob URL instead of webkit-fake-url when pasting an image
     4        https://bugs.webkit.org/show_bug.cgi?id=49141
     5
     6        Reviewed by Darin Adler.
     7
     8        Add layout test coverage checking that the image shows as expected and that the
     9        resulting URL is indeed a Blob URL.
     10
     11        * editing/pasteboard/paste-image-as-blob-url-expected.txt: Added.
     12        * editing/pasteboard/paste-image-as-blob-url.html: Added.
     13        * editing/pasteboard/paste-image-using-image-data-expected.html: Added.
     14        * editing/pasteboard/paste-image-using-image-data.html: Added.
     15
    1162016-11-07  Yusuke Suzuki  <utatane.tea@gmail.com>
    217
  • trunk/Source/WebCore/ChangeLog

    r208449 r208451  
     12016-11-09  Chris Dumez  <cdumez@apple.com>
     2
     3        Use Blob URL instead of webkit-fake-url when pasting an image
     4        https://bugs.webkit.org/show_bug.cgi?id=49141
     5
     6        Reviewed by Darin Adler.
     7
     8        Use Blob URL instead of webkit-fake-url when pasting an image.
     9
     10        Tests: editing/pasteboard/paste-image-as-blob-url.html
     11               editing/pasteboard/paste-image-using-image-data.html
     12
     13        * editing/Editor.h:
     14        * editing/mac/EditorMac.mm:
     15        (WebCore::Editor::WebContentReader::readImage):
     16        (WebCore::Editor::createFragmentForImageAndURL):
     17
    1182016-11-09  Michael Catanzaro  <mcatanzaro@igalia.com>
    219
  • trunk/Source/WebCore/editing/Editor.h

    r208406 r208451  
    519519    RefPtr<Range> adjustedSelectionRange();
    520520    RefPtr<DocumentFragment> createFragmentForImageResourceAndAddResource(RefPtr<ArchiveResource>&&);
     521    Ref<DocumentFragment> createFragmentForImageAndURL(const String&);
    521522    RefPtr<DocumentFragment> createFragmentAndAddResources(NSAttributedString *);
    522523    FragmentAndResources createFragment(NSAttributedString *);
  • trunk/Source/WebCore/editing/mac/EditorMac.mm

    r208406 r208451  
    2727#import "Editor.h"
    2828
     29#import "Blob.h"
    2930#import "CSSPrimitiveValueMappings.h"
    3031#import "CSSValuePool.h"
    3132#import "CachedResourceLoader.h"
    3233#import "ColorMac.h"
     34#import "DOMURL.h"
    3335#import "DataTransfer.h"
    3436#import "DocumentFragment.h"
     
    611613    String typeAsFilenameWithExtension = type;
    612614    typeAsFilenameWithExtension.replace('/', '.');
    613     URL imageURL = URL::fakeURLWithRelativePart(typeAsFilenameWithExtension);
    614 
    615     fragment = frame.editor().createFragmentForImageResourceAndAddResource(ArchiveResource::create(WTFMove(buffer), imageURL, type, emptyString(), emptyString()));
     615
     616    Vector<uint8_t> data;
     617    data.append(buffer->data(), buffer->size());
     618    auto blob = Blob::create(WTFMove(data), type);
     619    ASSERT(frame.document());
     620    String blobURL = DOMURL::createObjectURL(*frame.document(), blob);
     621
     622    fragment = frame.editor().createFragmentForImageAndURL(blobURL);
    616623    return fragment;
    617624}
     
    670677
    671678    return WTFMove(fragment);
     679}
     680
     681Ref<DocumentFragment> Editor::createFragmentForImageAndURL(const String& url)
     682{
     683    auto imageElement = HTMLImageElement::create(*m_frame.document());
     684    imageElement->setAttributeWithoutSynchronization(HTMLNames::srcAttr, url);
     685
     686    auto fragment = document().createDocumentFragment();
     687    fragment->appendChild(imageElement);
     688
     689    return fragment;
    672690}
    673691
  • trunk/Source/WebCore/fileapi/Blob.cpp

    r206208 r208451  
    7878}
    7979
    80 Blob::Blob(Vector<uint8_t> data, const String& contentType)
     80Blob::Blob(Vector<uint8_t>&& data, const String& contentType)
    8181    : m_type(contentType)
    8282    , m_size(data.size())
     
    8888}
    8989
    90 Blob::Blob(Vector<BlobPart> blobParts, const String& contentType)
     90Blob::Blob(Vector<BlobPart>&& blobParts, const String& contentType)
    9191    : m_type(contentType)
    9292    , m_size(-1)
  • trunk/Source/WebCore/fileapi/Blob.h

    r204717 r208451  
    4949    }
    5050
    51     static Ref<Blob> create(Vector<uint8_t> data, const String& contentType)
     51    static Ref<Blob> create(Vector<uint8_t>&& data, const String& contentType)
    5252    {
    5353        return adoptRef(*new Blob(WTFMove(data), contentType));
    5454    }
    5555
    56     static Ref<Blob> create(Vector<BlobPart> blobParts, const String& contentType)
     56    static Ref<Blob> create(Vector<BlobPart>&& blobParts, const String& contentType)
    5757    {
    5858        return adoptRef(*new Blob(WTFMove(blobParts), contentType));
     
    9292protected:
    9393    Blob();
    94     Blob(Vector<uint8_t>, const String& contentType);
    95     Blob(Vector<BlobPart>, const String& contentType);
     94    Blob(Vector<uint8_t>&&, const String& contentType);
     95    Blob(Vector<BlobPart>&&, const String& contentType);
    9696
    9797    enum UninitializedContructor { uninitializedContructor };
  • trunk/Source/WebCore/platform/network/BlobPart.h

    r198869 r208451  
    4343    }
    4444
    45     BlobPart(Vector<uint8_t> data)
     45    BlobPart(Vector<uint8_t>&& data)
    4646        : m_type(Data)
    4747        , m_data(WTFMove(data))
Note: See TracChangeset for help on using the changeset viewer.