Diff
Modified: trunk/LayoutTests/ChangeLog (208450 => 208451)
--- trunk/LayoutTests/ChangeLog 2016-11-09 19:10:42 UTC (rev 208450)
+++ trunk/LayoutTests/ChangeLog 2016-11-09 19:14:17 UTC (rev 208451)
@@ -1,3 +1,18 @@
+2016-11-09 Chris Dumez <[email protected]>
+
+ 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.
+
+ 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.
+
2016-11-07 Yusuke Suzuki <[email protected]>
[JSC] The implementation of 8 bit operation in MacroAssembler should care about uint8_t / int8_t
Added: trunk/LayoutTests/editing/pasteboard/paste-image-as-blob-url-expected.txt (0 => 208451)
--- trunk/LayoutTests/editing/pasteboard/paste-image-as-blob-url-expected.txt (rev 0)
+++ trunk/LayoutTests/editing/pasteboard/paste-image-as-blob-url-expected.txt 2016-11-09 19:14:17 UTC (rev 208451)
@@ -0,0 +1,12 @@
+Tests that pasted images use blob URL, not webkit fake URLs.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS pastedImages.length is 1
+PASS url.protocol is "blob:"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
+
Added: trunk/LayoutTests/editing/pasteboard/paste-image-as-blob-url.html (0 => 208451)
--- trunk/LayoutTests/editing/pasteboard/paste-image-as-blob-url.html (rev 0)
+++ trunk/LayoutTests/editing/pasteboard/paste-image-as-blob-url.html 2016-11-09 19:14:17 UTC (rev 208451)
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+<div id="destination" contenteditable="true" style="width: 500px; height: 100px; border: solid red 1px"></div>
+<iframe id="iframe" src="" _onload_="selectInFrame()"></iframe>
+</body>
+<script>
+ description("Tests that pasted images use blob URL, not webkit fake URLs.");
+ jsTestIsAsync = true;
+
+ function selectInFrame() {
+ if (window.internals)
+ window.internals.settings.setPreferMIMETypeForImages(true);
+ var iframe = document.getElementById("iframe");
+ var iframeDocument = iframe.contentDocument;
+ var destination = document.getElementById("destination");
+ iframeDocument.body.focus();
+ iframeDocument.execCommand("SelectAll");
+ iframeDocument.execCommand("Copy");
+ destination.focus();
+ document.execCommand("Paste");
+
+ pastedImages = destination.getElementsByTagName("img");
+ shouldBe("pastedImages.length", "1");
+ img = pastedImages[0];
+ url = "" URL(img.src);
+ shouldBeEqualToString("url.protocol", "blob:");
+
+ finishJSTest();
+ }
+</script>
+<script src=""
+</html>
Added: trunk/LayoutTests/editing/pasteboard/paste-image-using-image-data-expected.html (0 => 208451)
--- trunk/LayoutTests/editing/pasteboard/paste-image-using-image-data-expected.html (rev 0)
+++ trunk/LayoutTests/editing/pasteboard/paste-image-using-image-data-expected.html 2016-11-09 19:14:17 UTC (rev 208451)
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<html>
+<body>
+<div id="destination" contenteditable="true" style="width: 500px; height: 100px; border: solid red 1px">
+<img src=""
+</div>
+<iframe id="iframe" src=""
+</body>
+</html>
Added: trunk/LayoutTests/editing/pasteboard/paste-image-using-image-data.html (0 => 208451)
--- trunk/LayoutTests/editing/pasteboard/paste-image-using-image-data.html (rev 0)
+++ trunk/LayoutTests/editing/pasteboard/paste-image-using-image-data.html 2016-11-09 19:14:17 UTC (rev 208451)
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html>
+<body>
+<div id="destination" contenteditable="true" style="width: 500px; height: 100px; border: solid red 1px"></div>
+<iframe id="iframe" src="" _onload_="selectInFrame()"></iframe>
+</body>
+<script>
+ function selectInFrame() {
+ if (window.internals)
+ window.internals.settings.setPreferMIMETypeForImages(true);
+ var iframe = document.getElementById("iframe");
+ var iframeDocument = iframe.contentDocument;
+ var destination = document.getElementById("destination");
+ iframeDocument.body.focus();
+ iframeDocument.execCommand("SelectAll");
+ iframeDocument.execCommand("Copy");
+ destination.focus();
+ document.execCommand("Paste");
+ destination.blur();
+ }
+</script>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (208450 => 208451)
--- trunk/Source/WebCore/ChangeLog 2016-11-09 19:10:42 UTC (rev 208450)
+++ trunk/Source/WebCore/ChangeLog 2016-11-09 19:14:17 UTC (rev 208451)
@@ -1,3 +1,20 @@
+2016-11-09 Chris Dumez <[email protected]>
+
+ 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.
+
+ 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):
+
2016-11-09 Michael Catanzaro <[email protected]>
Fix error message when SQLite initialization fails
Modified: trunk/Source/WebCore/editing/Editor.h (208450 => 208451)
--- trunk/Source/WebCore/editing/Editor.h 2016-11-09 19:10:42 UTC (rev 208450)
+++ trunk/Source/WebCore/editing/Editor.h 2016-11-09 19:14:17 UTC (rev 208451)
@@ -518,6 +518,7 @@
RefPtr<SharedBuffer> imageInWebArchiveFormat(Element&);
RefPtr<Range> adjustedSelectionRange();
RefPtr<DocumentFragment> createFragmentForImageResourceAndAddResource(RefPtr<ArchiveResource>&&);
+ Ref<DocumentFragment> createFragmentForImageAndURL(const String&);
RefPtr<DocumentFragment> createFragmentAndAddResources(NSAttributedString *);
FragmentAndResources createFragment(NSAttributedString *);
void fillInUserVisibleForm(PasteboardURL&);
Modified: trunk/Source/WebCore/editing/mac/EditorMac.mm (208450 => 208451)
--- trunk/Source/WebCore/editing/mac/EditorMac.mm 2016-11-09 19:10:42 UTC (rev 208450)
+++ trunk/Source/WebCore/editing/mac/EditorMac.mm 2016-11-09 19:14:17 UTC (rev 208451)
@@ -26,10 +26,12 @@
#import "config.h"
#import "Editor.h"
+#import "Blob.h"
#import "CSSPrimitiveValueMappings.h"
#import "CSSValuePool.h"
#import "CachedResourceLoader.h"
#import "ColorMac.h"
+#import "DOMURL.h"
#import "DataTransfer.h"
#import "DocumentFragment.h"
#import "DocumentLoader.h"
@@ -610,9 +612,14 @@
ASSERT(type.contains('/'));
String typeAsFilenameWithExtension = type;
typeAsFilenameWithExtension.replace('/', '.');
- URL imageURL = URL::fakeURLWithRelativePart(typeAsFilenameWithExtension);
- fragment = frame.editor().createFragmentForImageResourceAndAddResource(ArchiveResource::create(WTFMove(buffer), imageURL, type, emptyString(), emptyString()));
+ Vector<uint8_t> data;
+ data.append(buffer->data(), buffer->size());
+ auto blob = Blob::create(WTFMove(data), type);
+ ASSERT(frame.document());
+ String blobURL = DOMURL::createObjectURL(*frame.document(), blob);
+
+ fragment = frame.editor().createFragmentForImageAndURL(blobURL);
return fragment;
}
@@ -671,6 +678,17 @@
return WTFMove(fragment);
}
+Ref<DocumentFragment> Editor::createFragmentForImageAndURL(const String& url)
+{
+ auto imageElement = HTMLImageElement::create(*m_frame.document());
+ imageElement->setAttributeWithoutSynchronization(HTMLNames::srcAttr, url);
+
+ auto fragment = document().createDocumentFragment();
+ fragment->appendChild(imageElement);
+
+ return fragment;
+}
+
RefPtr<DocumentFragment> Editor::createFragmentAndAddResources(NSAttributedString *string)
{
if (!m_frame.page() || !document().isHTMLDocument())
Modified: trunk/Source/WebCore/fileapi/Blob.cpp (208450 => 208451)
--- trunk/Source/WebCore/fileapi/Blob.cpp 2016-11-09 19:10:42 UTC (rev 208450)
+++ trunk/Source/WebCore/fileapi/Blob.cpp 2016-11-09 19:14:17 UTC (rev 208451)
@@ -77,7 +77,7 @@
ThreadableBlobRegistry::registerBlobURL(m_internalURL, Vector<BlobPart>(), String());
}
-Blob::Blob(Vector<uint8_t> data, const String& contentType)
+Blob::Blob(Vector<uint8_t>&& data, const String& contentType)
: m_type(contentType)
, m_size(data.size())
{
@@ -87,7 +87,7 @@
ThreadableBlobRegistry::registerBlobURL(m_internalURL, WTFMove(blobParts), contentType);
}
-Blob::Blob(Vector<BlobPart> blobParts, const String& contentType)
+Blob::Blob(Vector<BlobPart>&& blobParts, const String& contentType)
: m_type(contentType)
, m_size(-1)
{
Modified: trunk/Source/WebCore/fileapi/Blob.h (208450 => 208451)
--- trunk/Source/WebCore/fileapi/Blob.h 2016-11-09 19:10:42 UTC (rev 208450)
+++ trunk/Source/WebCore/fileapi/Blob.h 2016-11-09 19:14:17 UTC (rev 208451)
@@ -48,12 +48,12 @@
return adoptRef(*new Blob);
}
- static Ref<Blob> create(Vector<uint8_t> data, const String& contentType)
+ static Ref<Blob> create(Vector<uint8_t>&& data, const String& contentType)
{
return adoptRef(*new Blob(WTFMove(data), contentType));
}
- static Ref<Blob> create(Vector<BlobPart> blobParts, const String& contentType)
+ static Ref<Blob> create(Vector<BlobPart>&& blobParts, const String& contentType)
{
return adoptRef(*new Blob(WTFMove(blobParts), contentType));
}
@@ -91,8 +91,8 @@
protected:
Blob();
- Blob(Vector<uint8_t>, const String& contentType);
- Blob(Vector<BlobPart>, const String& contentType);
+ Blob(Vector<uint8_t>&&, const String& contentType);
+ Blob(Vector<BlobPart>&&, const String& contentType);
enum UninitializedContructor { uninitializedContructor };
Blob(UninitializedContructor);
Modified: trunk/Source/WebCore/platform/network/BlobPart.h (208450 => 208451)
--- trunk/Source/WebCore/platform/network/BlobPart.h 2016-11-09 19:10:42 UTC (rev 208450)
+++ trunk/Source/WebCore/platform/network/BlobPart.h 2016-11-09 19:14:17 UTC (rev 208451)
@@ -42,7 +42,7 @@
{
}
- BlobPart(Vector<uint8_t> data)
+ BlobPart(Vector<uint8_t>&& data)
: m_type(Data)
, m_data(WTFMove(data))
{