iOS: Use blob URL instead of a WebKit fake URL when pasting an image
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 15 Sep 2017 23:59:35 +0000 (23:59 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 15 Sep 2017 23:59:35 +0000 (23:59 +0000)
https://bugs.webkit.org/show_bug.cgi?id=176986
<rdar://problem/34455052>

Reviewed by Wenson Hsieh.

Source/WebCore:

Fixed the bug that pasting an image on iOS resulted in an img element with src attribute
set to a WebKit fake URL so that the Web content could never save it.

Like r208451 on Mac, use a Blob URL instead.

This patch also removes createFragmentForImageResourceAndAddResource since it's no longer used.

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

* editing/cocoa/WebContentReaderCocoa.mm:
(WebCore::WebContentReader::readImage): Moved the code here from WebContentReaderMac.mm.
* editing/ios/WebContentReaderIOS.mm:
(WebCore::WebContentReader::readImage): Deleted. This is the code
* editing/mac/WebContentReaderMac.mm:
(WebCore::WebContentReader::readImage): Moved to WebContentReaderCocoa.mm. Note that
typeAsFilenameWithExtension was dead code after r208451
* editing/markup.cpp:
(WebCore::createFragmentForImageResourceAndAddResource): Deleted.
* editing/markup.h:

LayoutTests:

Removed the failing expectation on the test added by r208451 now that it passes on iOS.

* platform/ios/TestExpectations:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222119 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/platform/ios/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm
Source/WebCore/editing/ios/WebContentReaderIOS.mm
Source/WebCore/editing/mac/WebContentReaderMac.mm
Source/WebCore/editing/markup.cpp
Source/WebCore/editing/markup.h

index b278d0514c380c71f19bde7cb4319de95b9ecd3f..5de2fd4fc26d8517d22fd5a4dc500bf6dce3014a 100644 (file)
@@ -1,3 +1,15 @@
+2017-09-15  Ryosuke Niwa  <rniwa@webkit.org>
+
+        iOS: Use blob URL instead of a WebKit fake URL when pasting an image
+        https://bugs.webkit.org/show_bug.cgi?id=176986
+        <rdar://problem/34455052>
+
+        Reviewed by Wenson Hsieh.
+
+        Removed the failing expectation on the test added by r208451 now that it passes on iOS.
+
+        * platform/ios/TestExpectations:
+
 2017-09-15  Ryan Haddad  <ryanhaddad@apple.com>
 
         Follow up to r222111, rebaseline tests for Sierra.
index 1b0365f41f364e1e8335e173b56f169cea827e36..3f8ad2ebedad72932ded0bf08a593b1c9f37ee79 100644 (file)
@@ -2258,7 +2258,6 @@ editing/pasteboard/page-zoom.html [ Failure ]
 editing/pasteboard/paste-before-tab-span.html [ Failure ]
 editing/pasteboard/paste-blockquote-3.html [ Failure ]
 editing/pasteboard/paste-global-selection.html [ Failure ]
-editing/pasteboard/paste-image-as-blob-url.html [ Failure ]
 editing/pasteboard/paste-list-004.html [ Failure ]
 editing/pasteboard/paste-placeholder-input.html [ Failure ]
 editing/pasteboard/paste-plaintext-user-select-none.html [ Failure ]
index 218144edb6ea657e86d904b7cde12386e5f69d86..dd603d673d2ee2b66b391eea8754f659ffc5288d 100644 (file)
@@ -1,3 +1,31 @@
+2017-09-15  Ryosuke Niwa  <rniwa@webkit.org>
+
+        iOS: Use blob URL instead of a WebKit fake URL when pasting an image
+        https://bugs.webkit.org/show_bug.cgi?id=176986
+        <rdar://problem/34455052>
+
+        Reviewed by Wenson Hsieh.
+
+        Fixed the bug that pasting an image on iOS resulted in an img element with src attribute
+        set to a WebKit fake URL so that the Web content could never save it.
+
+        Like r208451 on Mac, use a Blob URL instead.
+
+        This patch also removes createFragmentForImageResourceAndAddResource since it's no longer used.
+
+        Tests: LayoutTests/editing/pasteboard/paste-image-as-blob-url.html
+
+        * editing/cocoa/WebContentReaderCocoa.mm:
+        (WebCore::WebContentReader::readImage): Moved the code here from WebContentReaderMac.mm.
+        * editing/ios/WebContentReaderIOS.mm:
+        (WebCore::WebContentReader::readImage): Deleted. This is the code 
+        * editing/mac/WebContentReaderMac.mm:
+        (WebCore::WebContentReader::readImage): Moved to WebContentReaderCocoa.mm. Note that
+        typeAsFilenameWithExtension was dead code after r208451
+        * editing/markup.cpp:
+        (WebCore::createFragmentForImageResourceAndAddResource): Deleted.
+        * editing/markup.h:
+
 2017-09-15  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         Avoid style recomputation when forwarding a focus event to an text field's input type
index e4a71198ce6a63403aa1b2ed5fd5b6df84238008..328c44b4f0089a2ed98dafc2bed2966a6ad76d22 100644 (file)
@@ -27,7 +27,9 @@
 #include "WebContentReader.h"
 
 #include "ArchiveResource.h"
+#include "Blob.h"
 #include "CachedResourceLoader.h"
+#include "DOMURL.h"
 #include "Document.h"
 #include "DocumentFragment.h"
 #include "DocumentLoader.h"
@@ -166,4 +168,16 @@ bool WebContentReader::readPlainText(const String& text)
     return true;
 }
 
+bool WebContentReader::readImage(Ref<SharedBuffer>&& buffer, const String& type)
+{
+    Vector<uint8_t> data;
+    data.append(buffer->data(), buffer->size());
+    auto blob = Blob::create(WTFMove(data), type);
+    ASSERT(frame.document());
+    auto& document = *frame.document();
+    String blobURL = DOMURL::createObjectURL(document, blob);
+    addFragment(createFragmentForImageAndURL(document, blobURL));
+    return true;
+}
+
 }
index 53df6f8e5b804aab1e4ae181fec8be207fde159e..796e6e8f2383364469f9c9664ff2893c7b004c38 100644 (file)
@@ -27,7 +27,6 @@
 #import "WebContentReader.h"
 
 #import "ArchiveResource.h"
-#import "DOMURL.h"
 #import "Document.h"
 #import "DocumentFragment.h"
 #import "DocumentLoader.h"
@@ -62,23 +61,6 @@ bool WebContentReader::readHTML(const String& string)
     return true;
 }
 
-bool WebContentReader::readImage(Ref<SharedBuffer>&& buffer, const String& type)
-{
-    RetainPtr<CFStringRef> stringType = type.createCFString();
-    RetainPtr<NSString> filenameExtension = adoptNS((NSString *)UTTypeCopyPreferredTagWithClass(stringType.get(), kUTTagClassFilenameExtension));
-    NSString *relativeURLPart = [@"image" stringByAppendingString:filenameExtension.get()];
-    String mimeType = MIMETypeFromUTI(type);
-
-    // FIXME: Use a blob URL instead.
-    auto archive = ArchiveResource::create(WTFMove(buffer), URL::fakeURLWithRelativePart(relativeURLPart), mimeType, emptyString(), emptyString());
-    ASSERT(archive);
-    auto fragment = createFragmentForImageResourceAndAddResource(frame, *archive);
-    if (!fragment)
-        return false;
-    addFragment(fragment.releaseNonNull());
-    return true;
-}
-
 bool WebContentReader::readURL(const URL& url, const String& title)
 {
     if (url.isEmpty())
index e6ded37827f0e01b685b6cec3dc361475cb9152f..1b82dca2f4ef413b2b8ff9753e745d45647d15be 100644 (file)
@@ -27,7 +27,6 @@
 #import "WebContentReader.h"
 
 #import "ArchiveResource.h"
-#import "DOMURL.h"
 #import "Document.h"
 #import "DocumentFragment.h"
 #import "DocumentLoader.h"
@@ -100,23 +99,6 @@ bool WebContentReader::readHTML(const String& string)
     return fragment;
 }
 
-bool WebContentReader::readImage(Ref<SharedBuffer>&& buffer, const String& type)
-{
-    ASSERT(type.contains('/'));
-    String typeAsFilenameWithExtension = type;
-    typeAsFilenameWithExtension.replace('/', '.');
-
-    Vector<uint8_t> data;
-    data.append(buffer->data(), buffer->size());
-    auto blob = Blob::create(WTFMove(data), type);
-    ASSERT(frame.document());
-    Document& document = *frame.document();
-    String blobURL = DOMURL::createObjectURL(document, blob);
-
-    fragment = createFragmentForImageAndURL(document, blobURL);
-    return fragment;
-}
-
 bool WebContentReader::readURL(const URL& url, const String& title)
 {
     if (url.string().isEmpty())
index 5297226137601744914b49883e31e01be53f9eef..bcc1ccbd9f2fa47bba8879c732aa587cf652cf7c 100644 (file)
@@ -933,26 +933,6 @@ Ref<DocumentFragment> createFragmentForImageAndURL(Document& document, const Str
     return fragment;
 }
 
-RefPtr<DocumentFragment> createFragmentForImageResourceAndAddResource(Frame& frame, Ref<ArchiveResource>&& resource)
-{
-    if (!frame.document())
-        return nullptr;
-
-    Ref<Document> document = *frame.document();
-    String resourceURL = resource->url().string();
-
-    if (DocumentLoader* loader = frame.loader().documentLoader())
-        loader->addArchiveResource(WTFMove(resource));
-
-    auto imageElement = HTMLImageElement::create(document.get());
-    imageElement->setAttributeWithoutSynchronization(HTMLNames::srcAttr, resourceURL);
-
-    auto fragment = document->createDocumentFragment();
-    fragment->appendChild(imageElement);
-
-    return WTFMove(fragment);
-}
-
 static Vector<Ref<HTMLElement>> collectElementsToRemoveFromFragment(ContainerNode& container)
 {
     Vector<Ref<HTMLElement>> toRemove;
index 381c9cb19ce6389954aae4d0ff56c70f5f31c584..ac94693c102cd1a0d812b76ca3b4cc94f2b19dda 100644 (file)
@@ -53,7 +53,6 @@ WEBCORE_EXPORT Ref<DocumentFragment> createFragmentFromMarkup(Document&, const S
 ExceptionOr<Ref<DocumentFragment>> createFragmentForInnerOuterHTML(Element&, const String& markup, ParserContentPolicy);
 RefPtr<DocumentFragment> createFragmentForTransformToFragment(Document&, const String& sourceString, const String& sourceMIMEType);
 Ref<DocumentFragment> createFragmentForImageAndURL(Document&, const String&);
-RefPtr<DocumentFragment> createFragmentForImageResourceAndAddResource(Frame&, Ref<ArchiveResource>&&);
 ExceptionOr<Ref<DocumentFragment>> createContextualFragment(Element&, const String& markup, ParserContentPolicy);
 
 bool isPlainTextMarkup(Node*);