- Revision
- 222119
- Author
- [email protected]
- Date
- 2017-09-15 16:59:35 -0700 (Fri, 15 Sep 2017)
Log Message
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.
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:
Modified Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (222118 => 222119)
--- trunk/LayoutTests/ChangeLog 2017-09-15 23:48:18 UTC (rev 222118)
+++ trunk/LayoutTests/ChangeLog 2017-09-15 23:59:35 UTC (rev 222119)
@@ -1,3 +1,15 @@
+2017-09-15 Ryosuke Niwa <[email protected]>
+
+ 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 <[email protected]>
Follow up to r222111, rebaseline tests for Sierra.
Modified: trunk/LayoutTests/platform/ios/TestExpectations (222118 => 222119)
--- trunk/LayoutTests/platform/ios/TestExpectations 2017-09-15 23:48:18 UTC (rev 222118)
+++ trunk/LayoutTests/platform/ios/TestExpectations 2017-09-15 23:59:35 UTC (rev 222119)
@@ -2258,7 +2258,6 @@
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 ]
Modified: trunk/Source/WebCore/ChangeLog (222118 => 222119)
--- trunk/Source/WebCore/ChangeLog 2017-09-15 23:48:18 UTC (rev 222118)
+++ trunk/Source/WebCore/ChangeLog 2017-09-15 23:59:35 UTC (rev 222119)
@@ -1,3 +1,31 @@
+2017-09-15 Ryosuke Niwa <[email protected]>
+
+ 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 <[email protected]>
Avoid style recomputation when forwarding a focus event to an text field's input type
Modified: trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm (222118 => 222119)
--- trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm 2017-09-15 23:48:18 UTC (rev 222118)
+++ trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm 2017-09-15 23:59:35 UTC (rev 222119)
@@ -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 @@
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;
}
+
+}
Modified: trunk/Source/WebCore/editing/ios/WebContentReaderIOS.mm (222118 => 222119)
--- trunk/Source/WebCore/editing/ios/WebContentReaderIOS.mm 2017-09-15 23:48:18 UTC (rev 222118)
+++ trunk/Source/WebCore/editing/ios/WebContentReaderIOS.mm 2017-09-15 23:59:35 UTC (rev 222119)
@@ -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 @@
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())
Modified: trunk/Source/WebCore/editing/mac/WebContentReaderMac.mm (222118 => 222119)
--- trunk/Source/WebCore/editing/mac/WebContentReaderMac.mm 2017-09-15 23:48:18 UTC (rev 222118)
+++ trunk/Source/WebCore/editing/mac/WebContentReaderMac.mm 2017-09-15 23:59:35 UTC (rev 222119)
@@ -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 @@
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())
Modified: trunk/Source/WebCore/editing/markup.cpp (222118 => 222119)
--- trunk/Source/WebCore/editing/markup.cpp 2017-09-15 23:48:18 UTC (rev 222118)
+++ trunk/Source/WebCore/editing/markup.cpp 2017-09-15 23:59:35 UTC (rev 222119)
@@ -933,26 +933,6 @@
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;
Modified: trunk/Source/WebCore/editing/markup.h (222118 => 222119)
--- trunk/Source/WebCore/editing/markup.h 2017-09-15 23:48:18 UTC (rev 222118)
+++ trunk/Source/WebCore/editing/markup.h 2017-09-15 23:59:35 UTC (rev 222119)
@@ -53,7 +53,6 @@
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*);