Diff
Modified: trunk/Source/WebCore/ChangeLog (221959 => 221960)
--- trunk/Source/WebCore/ChangeLog 2017-09-13 07:02:13 UTC (rev 221959)
+++ trunk/Source/WebCore/ChangeLog 2017-09-13 07:17:43 UTC (rev 221960)
@@ -1,3 +1,60 @@
+2017-09-13 Ryosuke Niwa <[email protected]>
+
+ Refactor WebContentReader out of EditorMac and EditorIOS
+ https://bugs.webkit.org/show_bug.cgi?id=176770
+
+ Reviewed by Sam Weinig.
+
+ Extracted WebContentReader.h, WebContentReaderMac.mm, and WebContentIOS.mm from Pasteboard.h,
+ EditorMac.mm, and EditorIOS.mm respectively.
+
+ Also moved createFragmentAndAddResources from EditorCocoa.mm to WebContentReaderCocoa.mm
+ and createFragmentForImageAndURL and createFragmentForImageResourceAndAddResource to markup.cpp.
+
+ * Configurations/WebCore.xcconfig:
+ * PlatformMac.cmake:
+ * WebCore.xcodeproj/project.pbxproj:
+ * editing/Editor.cpp:
+ (WebCore::Editor::createFragmentForImageAndURL): Deleted.
+ * editing/Editor.h:
+ * editing/WebContentReader.h: Added.
+ * editing/cocoa/EditorCocoa.mm:
+ (WebCore::Editor::replaceSelectionWithAttributedString):
+ (WebCore::Editor::createFragment): Deleted.
+ (WebCore::Editor::createFragmentForImageResourceAndAddResource): Deleted.
+ (WebCore::Editor::createFragmentAndAddResources): Deleted.
+ * editing/cocoa/WebContentReaderCocoa.mm: Added.
+ (WebCore::createFragmentForImageResourceAndAddResource):
+ (WebCore::createFragment):
+ (WebCore::createFragmentAndAddResources):
+ * editing/ios/EditorIOS.mm:
+ (WebCore::Editor::WebContentReader): Moved to WebContentReaderIOS.mm.
+ * editing/ios/WebContentReaderIOS.mm: Added.
+ (WebCore::WebContentReader::addFragment):
+ (WebCore::WebContentReader::readWebArchive):
+ (WebCore::WebContentReader::readFilenames):
+ (WebCore::WebContentReader::readHTML):
+ (WebCore::WebContentReader::readRTFD):
+ (WebCore::WebContentReader::readRTF):
+ (WebCore::WebContentReader::readImage):
+ (WebCore::WebContentReader::readURL):
+ (WebCore::WebContentReader::readPlainText):
+ * editing/mac/EditorMac.mm:
+ (WebCore::Editor::WebContentReader): Moved to WebContentReaderMac.mm.
+ * editing/mac/WebContentReaderMac.mm: Added.
+ (WebCore::WebContentReader::readWebArchive):
+ (WebCore::WebContentReader::readFilenames):
+ (WebCore::WebContentReader::readHTML):
+ (WebCore::WebContentReader::readRTFD):
+ (WebCore::WebContentReader::readRTF):
+ (WebCore::WebContentReader::readImage):
+ (WebCore::WebContentReader::readURL):
+ (WebCore::WebContentReader::readPlainText):
+ * editing/markup.cpp:
+ (WebCore::createFragmentForImageAndURL):
+ (WebCore::createFragmentForImageResourceAndAddResource):
+ * editing/markup.h:
+
2017-09-12 Yusuke Suzuki <[email protected]>
[DFG] Optimize WeakMap::get by adding intrinsic and fixup
Modified: trunk/Source/WebCore/Configurations/WebCore.xcconfig (221959 => 221960)
--- trunk/Source/WebCore/Configurations/WebCore.xcconfig 2017-09-13 07:02:13 UTC (rev 221959)
+++ trunk/Source/WebCore/Configurations/WebCore.xcconfig 2017-09-13 07:17:43 UTC (rev 221960)
@@ -120,7 +120,7 @@
EXCLUDED_SOURCE_FILE_NAMES_FOR_GESTURE_EVENTS = $(EXCLUDED_SOURCE_FILE_NAMES_FOR_GESTURE_EVENTS_IF_ENABLED_$(ENABLE_IOS_GESTURE_EVENTS)$(ENABLE_MAC_GESTURE_EVENTS));
EXCLUDED_SOURCE_FILE_NAMES_FOR_GESTURE_EVENTS_IF_ENABLED_ = JSGesture* DOMGesture*;
-EXCLUDED_SOURCE_FILE_NAMES[sdk=iphone*] = *.tiff *Cursor.png AccessibilityObjectMac.mm AXObjectCacheMac.mm ColorMac.mm Cursor.cpp CursorMac.mm DataTransferMac.mm EditorMac.mm EventHandlerMac.mm EventLoopMac.mm GeolocationServiceMac.mm GraphicsContext3DOpenGLES.cpp IconDatabase.cpp IconMac.mm LocalCurrentGraphicsContext.mm MIMETypeRegistryMac.mm MediaPlayerPrivateQTKit.mm NSScrollerImpDetails.mm NetworkStateNotifierMac.cpp PasteboardMac.mm PlatformEventFactoryMac.mm PlatformMouseEventMac.mm PlatformPasteboardMac.mm PlatformScreenMac.mm PlatformSpeechSynthesizerMac.mm RunLoopMac.mm SSLKeyGeneratorMac.mm ScrollViewMac.mm ScrollbarThemeMac.mm SharedTimerMac.mm SystemTimeMac.cpp ThemeMac.mm ThreadCheck.mm UserAgentMac.mm WebAccessibilityObjectWrapperMac.mm WebCoreSystemInterface.mm WebCoreView.m WebVideoFullscreenController.mm WebVideoFullscreenHUDWindowController.mm WebWindowAnimation.mm WidgetMac.mm DisplayRefreshMonitorMac.cpp npapi.h npfunctions.h npruntime.h npruntime_in
ternal.h $(EXCLUDED_SOURCE_FILE_NAMES_FOR_TOUCH_EVENTS) $(EXCLUDED_SOURCE_FILE_NAMES_FOR_GESTURE_EVENTS);
+EXCLUDED_SOURCE_FILE_NAMES[sdk=iphone*] = *.tiff *Cursor.png AccessibilityObjectMac.mm AXObjectCacheMac.mm ColorMac.mm Cursor.cpp CursorMac.mm DataTransferMac.mm EditorMac.mm EventHandlerMac.mm EventLoopMac.mm GeolocationServiceMac.mm GraphicsContext3DOpenGLES.cpp IconDatabase.cpp IconMac.mm LocalCurrentGraphicsContext.mm MIMETypeRegistryMac.mm MediaPlayerPrivateQTKit.mm NSScrollerImpDetails.mm NetworkStateNotifierMac.cpp PasteboardMac.mm PlatformEventFactoryMac.mm PlatformMouseEventMac.mm PlatformPasteboardMac.mm PlatformScreenMac.mm PlatformSpeechSynthesizerMac.mm RunLoopMac.mm SSLKeyGeneratorMac.mm ScrollViewMac.mm ScrollbarThemeMac.mm SharedTimerMac.mm SystemTimeMac.cpp ThemeMac.mm ThreadCheck.mm UserAgentMac.mm WebAccessibilityObjectWrapperMac.mm WebContentReaderMac.mm WebCoreSystemInterface.mm WebCoreView.m WebVideoFullscreenController.mm WebVideoFullscreenHUDWindowController.mm WebWindowAnimation.mm WidgetMac.mm DisplayRefreshMonitorMac.cpp npapi.h npfunctions.h np
runtime.h npruntime_internal.h $(EXCLUDED_SOURCE_FILE_NAMES_FOR_TOUCH_EVENTS) $(EXCLUDED_SOURCE_FILE_NAMES_FOR_GESTURE_EVENTS);
EXCLUDED_SOURCE_FILE_NAMES[sdk=macosx*] = *IOS.h *IOS.cpp *IOS.mm WAKAppKitStubs.h WAKClipView.h WAKResponder.h WAKScrollView.h WAKView.h WAKViewPrivate.h WAKWindow.h WKContentObservation.h WKGraphics.h WKTypes.h WKUtilities.h WKView.h WKViewPrivate.h WebCoreThread.h WebCoreThreadMessage.h WebCoreThreadRun.h WebCoreThreadSystemInterface.h $(EXCLUDED_SOURCE_FILE_NAMES_FOR_TOUCH_EVENTS) $(EXCLUDED_SOURCE_FILE_NAMES_FOR_GESTURE_EVENTS);
WK_EMPTY_ = YES;
Modified: trunk/Source/WebCore/PlatformMac.cmake (221959 => 221960)
--- trunk/Source/WebCore/PlatformMac.cmake 2017-09-13 07:02:13 UTC (rev 221959)
+++ trunk/Source/WebCore/PlatformMac.cmake 2017-09-13 07:17:43 UTC (rev 221960)
@@ -203,6 +203,7 @@
editing/cocoa/DataDetection.mm
editing/cocoa/EditorCocoa.mm
editing/cocoa/HTMLConverter.mm
+ editing/cocoa/WebContentReaderCocoa.mm
editing/mac/AlternativeTextUIController.mm
editing/mac/DictionaryLookup.mm
@@ -210,6 +211,7 @@
editing/mac/FrameSelectionMac.mm
editing/mac/TextAlternativeWithRange.mm
editing/mac/TextUndoInsertionMarkupMac.mm
+ editing/mac/WebContentReaderMac.mm
fileapi/FileCocoa.mm
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (221959 => 221960)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2017-09-13 07:02:13 UTC (rev 221959)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2017-09-13 07:17:43 UTC (rev 221960)
@@ -4278,6 +4278,7 @@
9A528E8417D7F52F00AA9518 /* FloatingObjects.h in Headers */ = {isa = PBXBuildFile; fileRef = 9A528E8217D7F52F00AA9518 /* FloatingObjects.h */; settings = {ATTRIBUTES = (Private, ); }; };
9AB1F38018E2489A00534743 /* CSSToLengthConversionData.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AB1F37E18E2489A00534743 /* CSSToLengthConversionData.h */; };
9AB1F38118E2489A00534743 /* CSSToLengthConversionData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AB1F37F18E2489A00534743 /* CSSToLengthConversionData.cpp */; };
+ 9B0811241F67CDC00074BDE2 /* WebContentReaderIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9B0811231F67CDC00074BDE2 /* WebContentReaderIOS.mm */; };
9B098BD81F3D60DC002DD562 /* DataTransferItem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9B098BD51F3D6033002DD562 /* DataTransferItem.cpp */; };
9B098BE21F3D68AF002DD562 /* JSDataTransferItemList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9B098BDF1F3D673D002DD562 /* JSDataTransferItemList.cpp */; };
9B098BE41F3D68B3002DD562 /* JSDataTransferItem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9B098BDD1F3D673D002DD562 /* JSDataTransferItem.cpp */; };
@@ -4302,10 +4303,13 @@
9B6C41531344949000085B62 /* StringWithDirection.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B6C41521344949000085B62 /* StringWithDirection.h */; settings = {ATTRIBUTES = (Private, ); }; };
9B714E201C91166900AC0E92 /* EventPath.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9B714E1E1C91166900AC0E92 /* EventPath.cpp */; };
9B714E211C91166900AC0E92 /* EventPath.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B714E1F1C91166900AC0E92 /* EventPath.h */; };
+ 9B9299AE1F67865B006723C2 /* WebContentReaderMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9B9299AD1F67865B006723C2 /* WebContentReaderMac.mm */; };
+ 9B9299B21F6796A4006723C2 /* WebContentReaderCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9B9299B01F6796A4006723C2 /* WebContentReaderCocoa.mm */; };
9BA273F4172206BB0097CE47 /* LogicalSelectionOffsetCaches.h in Headers */ = {isa = PBXBuildFile; fileRef = 9BA273F3172206BB0097CE47 /* LogicalSelectionOffsetCaches.h */; };
9BAB6C6C12550631001626D4 /* EditingStyle.h in Headers */ = {isa = PBXBuildFile; fileRef = 9BAB6C6A12550631001626D4 /* EditingStyle.h */; settings = {ATTRIBUTES = (Private, ); }; };
9BAB6C6D12550631001626D4 /* EditingStyle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9BAB6C6B12550631001626D4 /* EditingStyle.cpp */; };
9BAF3B2412C1A39800014BF1 /* WritingDirection.h in Headers */ = {isa = PBXBuildFile; fileRef = 9BAF3B2312C1A39800014BF1 /* WritingDirection.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ 9BBA2CAB1F679E0C00FD1C1E /* WebContentReader.h in Headers */ = {isa = PBXBuildFile; fileRef = 9BF433761F67619B00E1FD71 /* WebContentReader.h */; settings = {ATTRIBUTES = (Private, ); }; };
9BC5F9E01D5AAF6B002B749D /* JSCustomElementRegistryCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9BC5F9DF1D5AAF6A002B749D /* JSCustomElementRegistryCustom.cpp */; };
9BC6C21B13CCC97B008E0337 /* HTMLTextFormControlElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 9BC6C21913CCC97B008E0337 /* HTMLTextFormControlElement.h */; settings = {ATTRIBUTES = (Private, ); }; };
9BC6C21C13CCC97B008E0337 /* HTMLTextFormControlElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9BC6C21A13CCC97B008E0337 /* HTMLTextFormControlElement.cpp */; };
@@ -12659,6 +12663,7 @@
9B03D8061BB3110D00B764DA /* JSDOMBindingInternalsBuiltins.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDOMBindingInternalsBuiltins.h; sourceTree = "<group>"; };
9B03D8061BB3110D00B764E8 /* WritableStreamBuiltins.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WritableStreamBuiltins.h; sourceTree = "<group>"; };
9B03D8061BB3110D00B764E9 /* WritableStreamInternalsBuiltins.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WritableStreamInternalsBuiltins.h; sourceTree = "<group>"; };
+ 9B0811231F67CDC00074BDE2 /* WebContentReaderIOS.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WebContentReaderIOS.mm; sourceTree = "<group>"; };
9B098BD51F3D6033002DD562 /* DataTransferItem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DataTransferItem.cpp; sourceTree = "<group>"; };
9B098BDD1F3D673D002DD562 /* JSDataTransferItem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDataTransferItem.cpp; sourceTree = "<group>"; };
9B098BDE1F3D673D002DD562 /* JSDataTransferItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDataTransferItem.h; sourceTree = "<group>"; };
@@ -12693,6 +12698,8 @@
9B6C41521344949000085B62 /* StringWithDirection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringWithDirection.h; sourceTree = "<group>"; };
9B714E1E1C91166900AC0E92 /* EventPath.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EventPath.cpp; sourceTree = "<group>"; };
9B714E1F1C91166900AC0E92 /* EventPath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EventPath.h; sourceTree = "<group>"; };
+ 9B9299AD1F67865B006723C2 /* WebContentReaderMac.mm */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 4; path = WebContentReaderMac.mm; sourceTree = "<group>"; };
+ 9B9299B01F6796A4006723C2 /* WebContentReaderCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebContentReaderCocoa.mm; sourceTree = "<group>"; };
9BA273F3172206BB0097CE47 /* LogicalSelectionOffsetCaches.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LogicalSelectionOffsetCaches.h; sourceTree = "<group>"; };
9BA827781F06156500F71E75 /* NavigationDisabler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NavigationDisabler.h; sourceTree = "<group>"; };
9BAB6C6A12550631001626D4 /* EditingStyle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EditingStyle.h; sourceTree = "<group>"; };
@@ -12713,6 +12720,7 @@
9BD8A95918BEFC7600987E9A /* CollectionIndexCache.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CollectionIndexCache.cpp; sourceTree = "<group>"; };
9BE671091D5AEB0400345514 /* JSCustomElementRegistry.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCustomElementRegistry.cpp; sourceTree = "<group>"; };
9BE6710A1D5AEB0400345514 /* JSCustomElementRegistry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSCustomElementRegistry.h; sourceTree = "<group>"; };
+ 9BF433761F67619B00E1FD71 /* WebContentReader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebContentReader.h; sourceTree = "<group>"; };
9BF9A87E1648DD2F001C6B23 /* JSHTMLFormControlsCollection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSHTMLFormControlsCollection.cpp; sourceTree = "<group>"; };
9BF9A87F1648DD2F001C6B23 /* JSHTMLFormControlsCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSHTMLFormControlsCollection.h; sourceTree = "<group>"; };
9D63800F1AF16E160031A15C /* StyleSelfAlignmentData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StyleSelfAlignmentData.h; sourceTree = "<group>"; };
@@ -18246,6 +18254,7 @@
D0BD4F5A1408850F006839B6 /* DictationCommandIOS.cpp */,
D0BD4F5B1408850F006839B6 /* DictationCommandIOS.h */,
FED13D390CEA934600D89466 /* EditorIOS.mm */,
+ 9B0811231F67CDC00074BDE2 /* WebContentReaderIOS.mm */,
);
path = ios;
sourceTree = "<group>";
@@ -20082,6 +20091,7 @@
9B55EEE81B3E8898005342BC /* EditorCocoa.mm */,
7C3E510818DF8F3500C112F7 /* HTMLConverter.h */,
7C3E510918DF8F3500C112F7 /* HTMLConverter.mm */,
+ 9B9299B01F6796A4006723C2 /* WebContentReaderCocoa.mm */,
);
path = cocoa;
sourceTree = "<group>";
@@ -20457,6 +20467,7 @@
A883DF260F3D045D00F19BF6 /* VisibleSelection.h */,
93309DCE099E64910056E581 /* VisibleUnits.cpp */,
93309DCF099E64910056E581 /* VisibleUnits.h */,
+ 9BF433761F67619B00E1FD71 /* WebContentReader.h */,
93309DD4099E64910056E581 /* WrapContentsInDummySpanCommand.cpp */,
93309DD5099E64910056E581 /* WrapContentsInDummySpanCommand.h */,
9BAF3B2312C1A39800014BF1 /* WritingDirection.h */,
@@ -25342,6 +25353,7 @@
CE7B2DB21586ABAD0098B3FA /* TextAlternativeWithRange.mm */,
29FAF4B5195AB08900A522DC /* TextUndoInsertionMarkupMac.h */,
29498681195341940072D2BD /* TextUndoInsertionMarkupMac.mm */,
+ 9B9299AD1F67865B006723C2 /* WebContentReaderMac.mm */,
);
path = mac;
sourceTree = "<group>";
@@ -30501,6 +30513,7 @@
07D637401BB0B11300256CE9 /* WebAudioSourceProviderAVFObjC.h in Headers */,
1F36EA9C1E21BA1700621E25 /* WebBackgroundTaskController.h in Headers */,
A56C5B9B189F34570082D13C /* WebConsoleAgent.h in Headers */,
+ 9BBA2CAB1F679E0C00FD1C1E /* WebContentReader.h in Headers */,
419BE7591BC7F42B00E1C85B /* WebCoreBuiltinNames.h in Headers */,
2D3EF44A1917915C00034184 /* WebCoreCALayerExtras.h in Headers */,
515F79541CFCA3D500CCED93 /* WebCoreCrossThreadCopier.h in Headers */,
@@ -34262,6 +34275,9 @@
CDA29A311CBF74DA00901CCF /* WebAVPlayerController.mm in Sources */,
1F36EA9D1E21BA1700621E25 /* WebBackgroundTaskController.mm in Sources */,
A56C5B9A189F34570082D13C /* WebConsoleAgent.cpp in Sources */,
+ 9B9299B21F6796A4006723C2 /* WebContentReaderCocoa.mm in Sources */,
+ 9B0811241F67CDC00074BDE2 /* WebContentReaderIOS.mm in Sources */,
+ 9B9299AE1F67865B006723C2 /* WebContentReaderMac.mm in Sources */,
CD7E05221651C28200C1201F /* WebCoreAVFResourceLoader.mm in Sources */,
2D3EF44B1917915C00034184 /* WebCoreCALayerExtras.mm in Sources */,
515F79531CFCA3D000CCED93 /* WebCoreCrossThreadCopier.cpp in Sources */,
Modified: trunk/Source/WebCore/editing/Editor.cpp (221959 => 221960)
--- trunk/Source/WebCore/editing/Editor.cpp 2017-09-13 07:02:13 UTC (rev 221959)
+++ trunk/Source/WebCore/editing/Editor.cpp 2017-09-13 07:17:43 UTC (rev 221960)
@@ -3818,15 +3818,4 @@
return font;
}
-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;
-}
-
} // namespace WebCore
Modified: trunk/Source/WebCore/editing/Editor.h (221959 => 221960)
--- trunk/Source/WebCore/editing/Editor.h 2017-09-13 07:02:13 UTC (rev 221959)
+++ trunk/Source/WebCore/editing/Editor.h 2017-09-13 07:17:43 UTC (rev 221960)
@@ -92,15 +92,6 @@
IgnoreBlockquote,
};
-#if PLATFORM(COCOA)
-
-struct FragmentAndResources {
- RefPtr<DocumentFragment> fragment;
- Vector<Ref<ArchiveResource>> resources;
-};
-
-#endif
-
enum TemporarySelectionOption : uint8_t {
// By default, no additional options are enabled.
TemporarySelectionOptionDefault = 0,
@@ -508,11 +499,7 @@
void setIsGettingDictionaryPopupInfo(bool b) { m_isGettingDictionaryPopupInfo = b; }
bool isGettingDictionaryPopupInfo() const { return m_isGettingDictionaryPopupInfo; }
- Ref<DocumentFragment> createFragmentForImageAndURL(const String&);
-
private:
- class WebContentReader;
-
Document& document() const;
bool canDeleteRange(Range*) const;
@@ -548,9 +535,6 @@
RefPtr<SharedBuffer> selectionInWebArchiveFormat();
String selectionInHTMLFormat();
RefPtr<SharedBuffer> imageInWebArchiveFormat(Element&);
- RefPtr<DocumentFragment> createFragmentForImageResourceAndAddResource(RefPtr<ArchiveResource>&&);
- RefPtr<DocumentFragment> createFragmentAndAddResources(NSAttributedString *);
- FragmentAndResources createFragment(NSAttributedString *);
String userVisibleString(const URL&);
static RefPtr<SharedBuffer> dataInRTFDFormat(NSAttributedString *);
Added: trunk/Source/WebCore/editing/WebContentReader.h (0 => 221960)
--- trunk/Source/WebCore/editing/WebContentReader.h (rev 0)
+++ trunk/Source/WebCore/editing/WebContentReader.h 2017-09-13 07:17:43 UTC (rev 221960)
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2013-2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "Frame.h"
+#include "Pasteboard.h"
+#include "Range.h"
+
+namespace WebCore {
+
+class ArchiveResource;
+
+class WebContentReader final : public PasteboardWebContentReader {
+public:
+ Frame& frame;
+ Range& context;
+ const bool allowPlainText;
+
+ RefPtr<DocumentFragment> fragment;
+ bool madeFragmentFromPlainText;
+
+ WebContentReader(Frame& frame, Range& context, bool allowPlainText)
+ : frame(frame)
+ , context(context)
+ , allowPlainText(allowPlainText)
+ , madeFragmentFromPlainText(false)
+ {
+ }
+
+#if PLATFORM(IOS)
+ void addFragment(RefPtr<DocumentFragment>&&);
+#endif
+
+private:
+#if !(PLATFORM(GTK) || PLATFORM(WIN))
+ bool readWebArchive(SharedBuffer*) override;
+ bool readFilenames(const Vector<String>&) override;
+ bool readHTML(const String&) override;
+ bool readRTFD(SharedBuffer&) override;
+ bool readRTF(SharedBuffer&) override;
+ bool readImage(Ref<SharedBuffer>&&, const String& type) override;
+ bool readURL(const URL&, const String& title) override;
+#endif
+ bool readPlainText(const String&) override;
+};
+
+#if PLATFORM(COCOA)
+struct FragmentAndResources {
+ RefPtr<DocumentFragment> fragment;
+ Vector<Ref<ArchiveResource>> resources;
+};
+
+RefPtr<DocumentFragment> createFragmentAndAddResources(Frame&, NSAttributedString*);
+#endif
+
+}
Modified: trunk/Source/WebCore/editing/cocoa/EditorCocoa.mm (221959 => 221960)
--- trunk/Source/WebCore/editing/cocoa/EditorCocoa.mm 2017-09-13 07:02:13 UTC (rev 221959)
+++ trunk/Source/WebCore/editing/cocoa/EditorCocoa.mm 2017-09-13 07:17:43 UTC (rev 221960)
@@ -48,21 +48,10 @@
#import "RenderElement.h"
#import "RenderStyle.h"
#import "Text.h"
+#import "WebContentReader.h"
#import <pal/spi/cocoa/NSAttributedStringSPI.h>
#import <wtf/BlockObjCExceptions.h>
-#import <wtf/SoftLinking.h>
-#if PLATFORM(IOS)
-SOFT_LINK_PRIVATE_FRAMEWORK(WebKitLegacy)
-#endif
-
-#if PLATFORM(MAC)
-SOFT_LINK_FRAMEWORK_IN_UMBRELLA(WebKit, WebKitLegacy)
-#endif
-
-// FIXME: Get rid of this and change NSAttributedString conversion so it doesn't use WebKitLegacy (cf. rdar://problem/30597352).
-SOFT_LINK(WebKitLegacy, _WebCreateFragment, void, (WebCore::Document& document, NSAttributedString *string, WebCore::FragmentAndResources& result), (document, string, result))
-
namespace WebCore {
void Editor::getTextDecorationAttributesRespectingTypingStyle(const RenderStyle& style, NSMutableDictionary* result) const
@@ -145,15 +134,6 @@
return attributes;
}
-FragmentAndResources Editor::createFragment(NSAttributedString *string)
-{
- // FIXME: The algorithm to convert an attributed string into HTML should be implemented here in WebCore.
- // For now, though, we call into WebKitLegacy, which in turn calls into AppKit/TextKit.
- FragmentAndResources result;
- _WebCreateFragment(*m_frame.document(), string, result);
- return result;
-}
-
static RefPtr<SharedBuffer> archivedDataForAttributedString(NSAttributedString *attributedString)
{
if (!attributedString.length)
@@ -236,7 +216,7 @@
return;
if (m_frame.selection().selection().isContentRichlyEditable()) {
- RefPtr<DocumentFragment> fragment = createFragmentAndAddResources(attributedString);
+ RefPtr<DocumentFragment> fragment = createFragmentAndAddResources(m_frame, attributedString);
if (fragment && shouldInsertFragment(*fragment, selectedRange().get(), EditorInsertAction::Pasted))
pasteAsFragment(fragment.releaseNonNull(), false, false, mailBlockquoteHandling);
} else {
@@ -246,31 +226,6 @@
}
}
-RefPtr<DocumentFragment> Editor::createFragmentForImageResourceAndAddResource(RefPtr<ArchiveResource>&& resource)
-{
- if (!resource)
- return nullptr;
-
- // FIXME: Why is this different?
-#if PLATFORM(MAC)
- String resourceURL = resource->url().string();
-#else
- NSURL *URL = ""
- String resourceURL = URL.isFileURL ? URL.absoluteString : resource->url();
-#endif
-
- if (DocumentLoader* loader = m_frame.loader().documentLoader())
- loader->addArchiveResource(resource.releaseNonNull());
-
- auto imageElement = HTMLImageElement::create(*m_frame.document());
- imageElement->setAttributeWithoutSynchronization(HTMLNames::srcAttr, resourceURL);
-
- auto fragment = m_frame.document()->createDocumentFragment();
- fragment->appendChild(imageElement);
-
- return WTFMove(fragment);
-}
-
RefPtr<SharedBuffer> Editor::dataInRTFDFormat(NSAttributedString *string)
{
NSUInteger length = string.length;
@@ -297,37 +252,4 @@
return nullptr;
}
-RefPtr<DocumentFragment> Editor::createFragmentAndAddResources(NSAttributedString *string)
-{
- if (!m_frame.page() || !m_frame.document())
- return nullptr;
-
- auto& document = *m_frame.document();
- if (!document.isHTMLDocument() || !string)
- return nullptr;
-
- bool wasDeferringCallbacks = m_frame.page()->defersLoading();
- if (!wasDeferringCallbacks)
- m_frame.page()->setDefersLoading(true);
-
- auto& cachedResourceLoader = document.cachedResourceLoader();
- bool wasImagesEnabled = cachedResourceLoader.imagesEnabled();
- if (wasImagesEnabled)
- cachedResourceLoader.setImagesEnabled(false);
-
- auto fragmentAndResources = createFragment(string);
-
- if (auto* loader = m_frame.loader().documentLoader()) {
- for (auto& resource : fragmentAndResources.resources)
- loader->addArchiveResource(WTFMove(resource));
- }
-
- if (wasImagesEnabled)
- cachedResourceLoader.setImagesEnabled(true);
- if (!wasDeferringCallbacks)
- m_frame.page()->setDefersLoading(false);
-
- return WTFMove(fragmentAndResources.fragment);
}
-
-}
Added: trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm (0 => 221960)
--- trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm (rev 0)
+++ trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm 2017-09-13 07:17:43 UTC (rev 221960)
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2006-2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebContentReader.h"
+
+#include "ArchiveResource.h"
+#include "CachedResourceLoader.h"
+#include "Document.h"
+#include "DocumentFragment.h"
+#include "DocumentLoader.h"
+#include "Frame.h"
+#include "FrameLoader.h"
+#include "HTMLImageElement.h"
+#include "Page.h"
+#include <wtf/SoftLinking.h>
+
+#if PLATFORM(IOS)
+SOFT_LINK_PRIVATE_FRAMEWORK(WebKitLegacy)
+#endif
+
+#if PLATFORM(MAC)
+SOFT_LINK_FRAMEWORK_IN_UMBRELLA(WebKit, WebKitLegacy)
+#endif
+
+// FIXME: Get rid of this and change NSAttributedString conversion so it doesn't use WebKitLegacy (cf. rdar://problem/30597352).
+SOFT_LINK(WebKitLegacy, _WebCreateFragment, void, (WebCore::Document& document, NSAttributedString *string, WebCore::FragmentAndResources& result), (document, string, result))
+
+namespace WebCore {
+
+static FragmentAndResources createFragment(Frame& frame, NSAttributedString *string)
+{
+ // FIXME: The algorithm to convert an attributed string into HTML should be implemented here in WebCore.
+ // For now, though, we call into WebKitLegacy, which in turn calls into AppKit/TextKit.
+ FragmentAndResources result;
+ _WebCreateFragment(*frame.document(), string, result);
+ return result;
+}
+
+RefPtr<DocumentFragment> createFragmentAndAddResources(Frame& frame, NSAttributedString *string)
+{
+ if (!frame.page() || !frame.document())
+ return nullptr;
+
+ auto& document = *frame.document();
+ if (!document.isHTMLDocument() || !string)
+ return nullptr;
+
+ bool wasDeferringCallbacks = frame.page()->defersLoading();
+ if (!wasDeferringCallbacks)
+ frame.page()->setDefersLoading(true);
+
+ auto& cachedResourceLoader = document.cachedResourceLoader();
+ bool wasImagesEnabled = cachedResourceLoader.imagesEnabled();
+ if (wasImagesEnabled)
+ cachedResourceLoader.setImagesEnabled(false);
+
+ auto fragmentAndResources = createFragment(frame, string);
+
+ if (auto* loader = frame.loader().documentLoader()) {
+ for (auto& resource : fragmentAndResources.resources)
+ loader->addArchiveResource(WTFMove(resource));
+ }
+
+ if (wasImagesEnabled)
+ cachedResourceLoader.setImagesEnabled(true);
+ if (!wasDeferringCallbacks)
+ frame.page()->setDefersLoading(false);
+
+ return WTFMove(fragmentAndResources.fragment);
+}
+
+}
Modified: trunk/Source/WebCore/editing/gtk/EditorGtk.cpp (221959 => 221960)
--- trunk/Source/WebCore/editing/gtk/EditorGtk.cpp 2017-09-13 07:02:13 UTC (rev 221959)
+++ trunk/Source/WebCore/editing/gtk/EditorGtk.cpp 2017-09-13 07:17:43 UTC (rev 221960)
@@ -65,7 +65,9 @@
}, &buffer);
if (status == CAIRO_STATUS_SUCCESS) {
auto blob = Blob::create(WTFMove(buffer), "image/png");
- return frame.editor().createFragmentForImageAndURL(DOMURL::createObjectURL(*frame.document(), blob));
+ if (!frame.document())
+ return nullptr;
+ return createFragmentForImageAndURL(*frame.document(), DOMURL::createObjectURL(*frame.document(), blob));
}
}
Modified: trunk/Source/WebCore/editing/ios/EditorIOS.mm (221959 => 221960)
--- trunk/Source/WebCore/editing/ios/EditorIOS.mm 2017-09-13 07:02:13 UTC (rev 221959)
+++ trunk/Source/WebCore/editing/ios/EditorIOS.mm 2017-09-13 07:17:43 UTC (rev 221960)
@@ -29,28 +29,18 @@
#import "CSSComputedStyleDeclaration.h"
#import "CSSPrimitiveValueMappings.h"
#import "CachedImage.h"
-#import "CachedResourceLoader.h"
#import "DataTransfer.h"
#import "DictationCommandIOS.h"
#import "DocumentFragment.h"
-#import "DocumentLoader.h"
#import "DocumentMarkerController.h"
#import "Editing.h"
#import "EditorClient.h"
-#import "FontCascade.h"
#import "Frame.h"
-#import "FrameLoader.h"
-#import "FrameLoaderClient.h"
-#import "HTMLAnchorElement.h"
#import "HTMLConverter.h"
-#import "HTMLImageElement.h"
#import "HTMLInputElement.h"
#import "HTMLNames.h"
#import "HTMLParserIdioms.h"
#import "HTMLTextAreaElement.h"
-#import "LegacyWebArchive.h"
-#import "NodeTraversal.h"
-#import "Page.h"
#import "Pasteboard.h"
#import "RenderBlock.h"
#import "RenderImage.h"
@@ -58,12 +48,9 @@
#import "StyleProperties.h"
#import "Text.h"
#import "TypingCommand.h"
-#import "UTIUtilities.h"
#import "WAKAppKitStubs.h"
+#import "WebContentReader.h"
#import "markup.h"
-#import <MobileCoreServices/MobileCoreServices.h>
-#import <pal/spi/cocoa/NSAttributedStringSPI.h>
-#import <wtf/SoftLinking.h>
#import <wtf/text/StringBuilder.h>
namespace WebCore {
@@ -227,158 +214,6 @@
pasteboard.write(pasteboardImage);
}
-class Editor::WebContentReader final : public PasteboardWebContentReader {
-public:
- WebContentReader(Frame& frame, Range& context, bool allowPlainText)
- : frame(frame)
- , context(context)
- , allowPlainText(allowPlainText)
- , madeFragmentFromPlainText(false)
- {
- }
-
- void addFragment(RefPtr<DocumentFragment>&&);
-
- Frame& frame;
- Range& context;
- const bool allowPlainText;
-
- RefPtr<DocumentFragment> fragment;
- bool madeFragmentFromPlainText;
-
-private:
- bool readWebArchive(SharedBuffer*) override;
- bool readFilenames(const Vector<String>&) override;
- bool readHTML(const String&) override;
- bool readRTFD(SharedBuffer&) override;
- bool readRTF(SharedBuffer&) override;
- bool readImage(Ref<SharedBuffer>&&, const String& type) override;
- bool readURL(const URL&, const String& title) override;
- bool readPlainText(const String&) override;
-};
-
-void Editor::WebContentReader::addFragment(RefPtr<DocumentFragment>&& newFragment)
-{
- if (!newFragment)
- return;
-
- if (!fragment) {
- fragment = WTFMove(newFragment);
- return;
- }
-
- while (auto* firstChild = newFragment->firstChild()) {
- if (fragment->appendChild(*firstChild).hasException())
- break;
- }
-}
-
-bool Editor::WebContentReader::readWebArchive(SharedBuffer* buffer)
-{
- if (!frame.document())
- return false;
-
- if (!buffer)
- return false;
-
- auto archive = LegacyWebArchive::create(URL(), *buffer);
- if (!archive)
- return false;
-
- auto* mainResource = archive->mainResource();
- if (!mainResource)
- return false;
-
- auto& type = mainResource->mimeType();
- if (!frame.loader().client().canShowMIMETypeAsHTML(type))
- return false;
-
- // FIXME: The code in createFragmentAndAddResources calls setDefersLoading(true). Don't we need that here?
- if (auto* loader = frame.loader().documentLoader())
- loader->addAllArchiveResources(*archive);
-
- auto markupString = String::fromUTF8(mainResource->data().data(), mainResource->data().size());
- addFragment(createFragmentFromMarkup(*frame.document(), markupString, mainResource->url(), DisallowScriptingAndPluginContent));
- return true;
-}
-
-bool Editor::WebContentReader::readFilenames(const Vector<String>&)
-{
- return false;
-}
-
-bool Editor::WebContentReader::readHTML(const String& string)
-{
- if (!frame.document())
- return false;
-
- addFragment(createFragmentFromMarkup(*frame.document(), string, emptyString(), DisallowScriptingAndPluginContent));
- return true;
-}
-
-bool Editor::WebContentReader::readRTFD(SharedBuffer& buffer)
-{
- addFragment(frame.editor().createFragmentAndAddResources(adoptNS([[NSAttributedString alloc] initWithRTFD:buffer.createNSData().get() documentAttributes:nullptr]).get()));
- return fragment;
-}
-
-bool Editor::WebContentReader::readRTF(SharedBuffer& buffer)
-{
- addFragment(frame.editor().createFragmentAndAddResources(adoptNS([[NSAttributedString alloc] initWithRTF:buffer.createNSData().get() documentAttributes:nullptr]).get()));
- return fragment;
-}
-
-bool Editor::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);
-
- addFragment(frame.editor().createFragmentForImageResourceAndAddResource(ArchiveResource::create(WTFMove(buffer), URL::fakeURLWithRelativePart(relativeURLPart), mimeType, emptyString(), emptyString())));
- return fragment;
-}
-
-bool Editor::WebContentReader::readURL(const URL& url, const String& title)
-{
- if (url.isEmpty())
- return false;
-
- if (!frame.editor().client()->hasRichlyEditableSelection()) {
- if (readPlainText([(NSURL *)url absoluteString]))
- return true;
- }
-
- if ([(NSURL *)url isFileURL])
- return false;
-
- auto anchor = HTMLAnchorElement::create(*frame.document());
- anchor->setAttributeWithoutSynchronization(HTMLNames::hrefAttr, url.string());
-
- String linkText = title.length() ? title : String([[(NSURL *)url absoluteString] precomposedStringWithCanonicalMapping]);
- anchor->appendChild(frame.document()->createTextNode(linkText));
-
- auto newFragment = frame.document()->createDocumentFragment();
- if (fragment)
- newFragment->appendChild(Text::create(*frame.document(), { &space, 1 }));
- newFragment->appendChild(anchor);
- addFragment(WTFMove(newFragment));
- return true;
-}
-
-bool Editor::WebContentReader::readPlainText(const String& text)
-{
- if (!allowPlainText)
- return false;
-
- addFragment(createFragmentFromText(context, [text precomposedStringWithCanonicalMapping]));
- if (!fragment)
- return false;
-
- madeFragmentFromPlainText = true;
- return true;
-}
-
// FIXME: Should give this function a name that makes it clear it adds resources to the document loader as a side effect.
// Or refactor so it does not do that.
RefPtr<DocumentFragment> Editor::webContentFromPasteboard(Pasteboard& pasteboard, Range& context, bool allowPlainText, bool& chosePlainText)
Added: trunk/Source/WebCore/editing/ios/WebContentReaderIOS.mm (0 => 221960)
--- trunk/Source/WebCore/editing/ios/WebContentReaderIOS.mm (rev 0)
+++ trunk/Source/WebCore/editing/ios/WebContentReaderIOS.mm 2017-09-13 07:17:43 UTC (rev 221960)
@@ -0,0 +1,179 @@
+/*
+ * Copyright (C) 2006-2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "WebContentReader.h"
+
+#import "ArchiveResource.h"
+#import "DOMURL.h"
+#import "Document.h"
+#import "DocumentFragment.h"
+#import "DocumentLoader.h"
+#import "Editor.h"
+#import "EditorClient.h"
+#import "FragmentScriptingPermission.h"
+#import "FrameLoader.h"
+#import "FrameLoaderClient.h"
+#import "HTMLAnchorElement.h"
+#import "HTMLNames.h"
+#import "LegacyWebArchive.h"
+#import "MIMETypeRegistry.h"
+#import "Text.h"
+#import "UTIUtilities.h"
+#import "WebNSAttributedStringExtras.h"
+#import "markup.h"
+#import <MobileCoreServices/MobileCoreServices.h>
+#import <pal/spi/cocoa/NSAttributedStringSPI.h>
+#import <wtf/unicode/CharacterNames.h>
+
+namespace WebCore {
+
+void WebContentReader::addFragment(RefPtr<DocumentFragment>&& newFragment)
+{
+ if (!newFragment)
+ return;
+
+ if (!fragment) {
+ fragment = WTFMove(newFragment);
+ return;
+ }
+
+ while (auto* firstChild = newFragment->firstChild()) {
+ if (fragment->appendChild(*firstChild).hasException())
+ break;
+ }
+}
+
+bool WebContentReader::readWebArchive(SharedBuffer* buffer)
+{
+ if (!frame.document())
+ return false;
+
+ if (!buffer)
+ return false;
+
+ auto archive = LegacyWebArchive::create(URL(), *buffer);
+ if (!archive)
+ return false;
+
+ auto* mainResource = archive->mainResource();
+ if (!mainResource)
+ return false;
+
+ auto& type = mainResource->mimeType();
+ if (!frame.loader().client().canShowMIMETypeAsHTML(type))
+ return false;
+
+ // FIXME: The code in createFragmentAndAddResources calls setDefersLoading(true). Don't we need that here?
+ if (auto* loader = frame.loader().documentLoader())
+ loader->addAllArchiveResources(*archive);
+
+ auto markupString = String::fromUTF8(mainResource->data().data(), mainResource->data().size());
+ addFragment(createFragmentFromMarkup(*frame.document(), markupString, mainResource->url(), DisallowScriptingAndPluginContent));
+ return true;
+}
+
+bool WebContentReader::readFilenames(const Vector<String>&)
+{
+ return false;
+}
+
+bool WebContentReader::readHTML(const String& string)
+{
+ if (!frame.document())
+ return false;
+
+ addFragment(createFragmentFromMarkup(*frame.document(), string, emptyString(), DisallowScriptingAndPluginContent));
+ return true;
+}
+
+bool WebContentReader::readRTFD(SharedBuffer& buffer)
+{
+ addFragment(createFragmentAndAddResources(frame, adoptNS([[NSAttributedString alloc] initWithRTFD:buffer.createNSData().get() documentAttributes:nullptr]).get()));
+ return fragment;
+}
+
+bool WebContentReader::readRTF(SharedBuffer& buffer)
+{
+ addFragment(createFragmentAndAddResources(frame, adoptNS([[NSAttributedString alloc] initWithRTF:buffer.createNSData().get() documentAttributes:nullptr]).get()));
+ return fragment;
+}
+
+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);
+ addFragment(createFragmentForImageResourceAndAddResource(frame, *archive));
+ return fragment;
+}
+
+bool WebContentReader::readURL(const URL& url, const String& title)
+{
+ if (url.isEmpty())
+ return false;
+
+ // FIXME: This code shoudln't be accessing selection and changing the behavior.
+ if (!frame.editor().client()->hasRichlyEditableSelection()) {
+ if (readPlainText([(NSURL *)url absoluteString]))
+ return true;
+ }
+
+ if ([(NSURL *)url isFileURL])
+ return false;
+
+ auto anchor = HTMLAnchorElement::create(*frame.document());
+ anchor->setAttributeWithoutSynchronization(HTMLNames::hrefAttr, url.string());
+
+ String linkText = title.length() ? title : String([[(NSURL *)url absoluteString] precomposedStringWithCanonicalMapping]);
+ anchor->appendChild(frame.document()->createTextNode(linkText));
+
+ auto newFragment = frame.document()->createDocumentFragment();
+ if (fragment)
+ newFragment->appendChild(Text::create(*frame.document(), { &space, 1 }));
+ newFragment->appendChild(anchor);
+ addFragment(WTFMove(newFragment));
+ return true;
+}
+
+bool WebContentReader::readPlainText(const String& text)
+{
+ if (!allowPlainText)
+ return false;
+
+ addFragment(createFragmentFromText(context, [text precomposedStringWithCanonicalMapping]));
+ if (!fragment)
+ return false;
+
+ madeFragmentFromPlainText = true;
+ return true;
+}
+
+}
Modified: trunk/Source/WebCore/editing/mac/EditorMac.mm (221959 => 221960)
--- trunk/Source/WebCore/editing/mac/EditorMac.mm 2017-09-13 07:02:13 UTC (rev 221959)
+++ trunk/Source/WebCore/editing/mac/EditorMac.mm 2017-09-13 07:17:43 UTC (rev 221960)
@@ -29,29 +29,17 @@
#import "Blob.h"
#import "CSSPrimitiveValueMappings.h"
#import "CSSValuePool.h"
-#import "DOMURL.h"
#import "DataTransfer.h"
#import "DocumentFragment.h"
-#import "DocumentLoader.h"
#import "Editing.h"
#import "Editor.h"
#import "EditorClient.h"
-#import "File.h"
-#import "FontCascade.h"
#import "Frame.h"
-#import "FrameLoader.h"
-#import "FrameLoaderClient.h"
#import "FrameView.h"
-#import "HTMLAnchorElement.h"
-#import "HTMLAttachmentElement.h"
#import "HTMLConverter.h"
#import "HTMLElement.h"
-#import "HTMLImageElement.h"
#import "HTMLNames.h"
#import "LegacyWebArchive.h"
-#import "MIMETypeRegistry.h"
-#import "NodeTraversal.h"
-#import "Page.h"
#import "Pasteboard.h"
#import "PasteboardStrategy.h"
#import "PlatformStrategies.h"
@@ -60,12 +48,11 @@
#import "RenderImage.h"
#import "RuntimeApplicationChecks.h"
#import "RuntimeEnabledFeatures.h"
-#import "Settings.h"
#import "StyleProperties.h"
-#import "Text.h"
-#import "TypingCommand.h"
+#import "WebContentReader.h"
#import "WebNSAttributedStringExtras.h"
#import "markup.h"
+#import <AppKit/AppKit.h>
#import <pal/system/Sound.h>
namespace WebCore {
@@ -299,186 +286,6 @@
pasteboard.write(pasteboardImage);
}
-class Editor::WebContentReader final : public PasteboardWebContentReader {
-public:
- Frame& frame;
- Range& context;
- const bool allowPlainText;
-
- RefPtr<DocumentFragment> fragment;
- bool madeFragmentFromPlainText;
-
- WebContentReader(Frame& frame, Range& context, bool allowPlainText)
- : frame(frame)
- , context(context)
- , allowPlainText(allowPlainText)
- , madeFragmentFromPlainText(false)
- {
- }
-
-private:
- bool readWebArchive(SharedBuffer*) override;
- bool readFilenames(const Vector<String>&) override;
- bool readHTML(const String&) override;
- bool readRTFD(SharedBuffer&) override;
- bool readRTF(SharedBuffer&) override;
- bool readImage(Ref<SharedBuffer>&&, const String& type) override;
- bool readURL(const URL&, const String& title) override;
- bool readPlainText(const String&) override;
-};
-
-bool Editor::WebContentReader::readWebArchive(SharedBuffer* buffer)
-{
- if (frame.settings().preferMIMETypeForImages())
- return false;
-
- if (!frame.document())
- return false;
-
- if (!buffer)
- return false;
-
- auto archive = LegacyWebArchive::create(URL(), *buffer);
- if (!archive)
- return false;
-
- RefPtr<ArchiveResource> mainResource = archive->mainResource();
- if (!mainResource)
- return false;
-
- const String& type = mainResource->mimeType();
-
- if (frame.loader().client().canShowMIMETypeAsHTML(type)) {
- // FIXME: The code in createFragmentAndAddResources calls setDefersLoading(true). Don't we need that here?
- if (DocumentLoader* loader = frame.loader().documentLoader())
- loader->addAllArchiveResources(*archive);
-
- String markupString = String::fromUTF8(mainResource->data().data(), mainResource->data().size());
- fragment = createFragmentFromMarkup(*frame.document(), markupString, mainResource->url(), DisallowScriptingAndPluginContent);
- return true;
- }
-
- if (MIMETypeRegistry::isSupportedImageMIMEType(type)) {
- fragment = frame.editor().createFragmentForImageResourceAndAddResource(WTFMove(mainResource));
- return true;
- }
-
- return false;
-}
-
-bool Editor::WebContentReader::readFilenames(const Vector<String>& paths)
-{
- if (paths.isEmpty())
- return false;
-
- if (!frame.document())
- return false;
- Document& document = *frame.document();
-
- fragment = document.createDocumentFragment();
-
- for (auto& text : paths) {
-#if ENABLE(ATTACHMENT_ELEMENT)
- if (RuntimeEnabledFeatures::sharedFeatures().attachmentElementEnabled()) {
- auto attachment = HTMLAttachmentElement::create(attachmentTag, document);
- attachment->setFile(File::create([[NSURL fileURLWithPath:text] path]).ptr());
- fragment->appendChild(attachment);
- continue;
- }
-#endif
- auto paragraph = createDefaultParagraphElement(document);
- paragraph->appendChild(document.createTextNode(frame.editor().client()->userVisibleString([NSURL fileURLWithPath:text])));
- fragment->appendChild(paragraph);
- }
-
- return true;
-}
-
-bool Editor::WebContentReader::readHTML(const String& string)
-{
- String stringOmittingMicrosoftPrefix = string;
-
- // This code was added to make HTML paste from Microsoft Word on Mac work, back in 2004.
- // It's a simple-minded way to ignore the CF_HTML clipboard format, just skipping over the
- // description part and parsing the entire context plus fragment.
- if (string.startsWith("Version:")) {
- size_t location = string.findIgnoringCase("<html");
- if (location != notFound)
- stringOmittingMicrosoftPrefix = string.substring(location);
- }
-
- if (stringOmittingMicrosoftPrefix.isEmpty())
- return false;
-
- if (!frame.document())
- return false;
- Document& document = *frame.document();
-
- fragment = createFragmentFromMarkup(document, stringOmittingMicrosoftPrefix, emptyString(), DisallowScriptingAndPluginContent);
- return fragment;
-}
-
-bool Editor::WebContentReader::readRTFD(SharedBuffer& buffer)
-{
- if (frame.settings().preferMIMETypeForImages())
- return false;
-
- fragment = frame.editor().createFragmentAndAddResources(adoptNS([[NSAttributedString alloc] initWithRTFD:buffer.createNSData().get() documentAttributes:nullptr]).get());
- return fragment;
-}
-
-bool Editor::WebContentReader::readRTF(SharedBuffer& buffer)
-{
- if (frame.settings().preferMIMETypeForImages())
- return false;
-
- fragment = frame.editor().createFragmentAndAddResources(adoptNS([[NSAttributedString alloc] initWithRTF:buffer.createNSData().get() documentAttributes:nullptr]).get());
- return fragment;
-}
-
-bool Editor::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());
- String blobURL = DOMURL::createObjectURL(*frame.document(), blob);
-
- fragment = frame.editor().createFragmentForImageAndURL(blobURL);
- return fragment;
-}
-
-bool Editor::WebContentReader::readURL(const URL& url, const String& title)
-{
- if (url.string().isEmpty())
- return false;
-
- auto anchor = HTMLAnchorElement::create(*frame.document());
- anchor->setAttributeWithoutSynchronization(HTMLNames::hrefAttr, url.string());
- anchor->appendChild(frame.document()->createTextNode([title precomposedStringWithCanonicalMapping]));
-
- fragment = frame.document()->createDocumentFragment();
- fragment->appendChild(anchor);
- return true;
-}
-
-bool Editor::WebContentReader::readPlainText(const String& text)
-{
- if (!allowPlainText)
- return false;
-
- fragment = createFragmentFromText(context, [text precomposedStringWithCanonicalMapping]);
- if (!fragment)
- return false;
-
- madeFragmentFromPlainText = true;
- return true;
-}
-
// FIXME: Should give this function a name that makes it clear it adds resources to the document loader as a side effect.
// Or refactor so it does not do that.
RefPtr<DocumentFragment> Editor::webContentFromPasteboard(Pasteboard& pasteboard, Range& context, bool allowPlainText, bool& chosePlainText)
Added: trunk/Source/WebCore/editing/mac/WebContentReaderMac.mm (0 => 221960)
--- trunk/Source/WebCore/editing/mac/WebContentReaderMac.mm (rev 0)
+++ trunk/Source/WebCore/editing/mac/WebContentReaderMac.mm 2017-09-13 07:17:43 UTC (rev 221960)
@@ -0,0 +1,205 @@
+/*
+ * Copyright (C) 2006-2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "WebContentReader.h"
+
+#import "ArchiveResource.h"
+#import "DOMURL.h"
+#import "Document.h"
+#import "DocumentFragment.h"
+#import "DocumentLoader.h"
+#import "File.h"
+#import "FragmentScriptingPermission.h"
+#import "FrameLoader.h"
+#import "FrameLoaderClient.h"
+#import "HTMLAnchorElement.h"
+#import "HTMLAttachmentElement.h"
+#import "HTMLNames.h"
+#import "LegacyWebArchive.h"
+#import "MIMETypeRegistry.h"
+#import "RuntimeEnabledFeatures.h"
+#import "Settings.h"
+#import "Text.h"
+#import "WebNSAttributedStringExtras.h"
+#import "markup.h"
+
+namespace WebCore {
+
+bool WebContentReader::readWebArchive(SharedBuffer* buffer)
+{
+ if (frame.settings().preferMIMETypeForImages())
+ return false;
+
+ if (!frame.document())
+ return false;
+
+ if (!buffer)
+ return false;
+
+ auto archive = LegacyWebArchive::create(URL(), *buffer);
+ if (!archive)
+ return false;
+
+ RefPtr<ArchiveResource> mainResource = archive->mainResource();
+ if (!mainResource)
+ return false;
+
+ const String& type = mainResource->mimeType();
+
+ if (frame.loader().client().canShowMIMETypeAsHTML(type)) {
+ // FIXME: The code in createFragmentAndAddResources calls setDefersLoading(true). Don't we need that here?
+ if (DocumentLoader* loader = frame.loader().documentLoader())
+ loader->addAllArchiveResources(*archive);
+
+ String markupString = String::fromUTF8(mainResource->data().data(), mainResource->data().size());
+ fragment = createFragmentFromMarkup(*frame.document(), markupString, mainResource->url(), DisallowScriptingAndPluginContent);
+ return true;
+ }
+
+ if (MIMETypeRegistry::isSupportedImageMIMEType(type)) {
+ fragment = createFragmentForImageResourceAndAddResource(frame, mainResource.releaseNonNull());
+ return true;
+ }
+
+ return false;
+}
+
+bool WebContentReader::readFilenames(const Vector<String>& paths)
+{
+ if (paths.isEmpty())
+ return false;
+
+ if (!frame.document())
+ return false;
+ Document& document = *frame.document();
+
+ fragment = document.createDocumentFragment();
+
+ for (auto& text : paths) {
+#if ENABLE(ATTACHMENT_ELEMENT)
+ if (RuntimeEnabledFeatures::sharedFeatures().attachmentElementEnabled()) {
+ auto attachment = HTMLAttachmentElement::create(HTMLNames::attachmentTag, document);
+ attachment->setFile(File::create([[NSURL fileURLWithPath:text] path]).ptr());
+ fragment->appendChild(attachment);
+ continue;
+ }
+#else
+ auto paragraph = createDefaultParagraphElement(document);
+ paragraph->appendChild(document.createTextNode(frame.editor().client()->userVisibleString([NSURL fileURLWithPath:text])));
+ fragment->appendChild(paragraph);
+#endif
+ }
+
+ return true;
+}
+
+bool WebContentReader::readHTML(const String& string)
+{
+ String stringOmittingMicrosoftPrefix = string;
+
+ // This code was added to make HTML paste from Microsoft Word on Mac work, back in 2004.
+ // It's a simple-minded way to ignore the CF_HTML clipboard format, just skipping over the
+ // description part and parsing the entire context plus fragment.
+ if (string.startsWith("Version:")) {
+ size_t location = string.findIgnoringCase("<html");
+ if (location != notFound)
+ stringOmittingMicrosoftPrefix = string.substring(location);
+ }
+
+ if (stringOmittingMicrosoftPrefix.isEmpty())
+ return false;
+
+ if (!frame.document())
+ return false;
+ Document& document = *frame.document();
+
+ fragment = createFragmentFromMarkup(document, stringOmittingMicrosoftPrefix, emptyString(), DisallowScriptingAndPluginContent);
+ return fragment;
+}
+
+bool WebContentReader::readRTFD(SharedBuffer& buffer)
+{
+ if (frame.settings().preferMIMETypeForImages())
+ return false;
+
+ fragment = createFragmentAndAddResources(frame, adoptNS([[NSAttributedString alloc] initWithRTFD:buffer.createNSData().get() documentAttributes:nullptr]).get());
+ return fragment;
+}
+
+bool WebContentReader::readRTF(SharedBuffer& buffer)
+{
+ if (frame.settings().preferMIMETypeForImages())
+ return false;
+
+ fragment = createFragmentAndAddResources(frame, adoptNS([[NSAttributedString alloc] initWithRTF:buffer.createNSData().get() documentAttributes:nullptr]).get());
+ 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())
+ return false;
+
+ auto anchor = HTMLAnchorElement::create(*frame.document());
+ anchor->setAttributeWithoutSynchronization(HTMLNames::hrefAttr, url.string());
+ anchor->appendChild(frame.document()->createTextNode([title precomposedStringWithCanonicalMapping]));
+
+ fragment = frame.document()->createDocumentFragment();
+ fragment->appendChild(anchor);
+ return true;
+}
+
+bool WebContentReader::readPlainText(const String& text)
+{
+ if (!allowPlainText)
+ return false;
+
+ fragment = createFragmentFromText(context, [text precomposedStringWithCanonicalMapping]);
+ if (!fragment)
+ return false;
+
+ madeFragmentFromPlainText = true;
+ return true;
+}
+
+}
Modified: trunk/Source/WebCore/editing/markup.cpp (221959 => 221960)
--- trunk/Source/WebCore/editing/markup.cpp 2017-09-13 07:02:13 UTC (rev 221959)
+++ trunk/Source/WebCore/editing/markup.cpp 2017-09-13 07:17:43 UTC (rev 221960)
@@ -29,6 +29,7 @@
#include "config.h"
#include "markup.h"
+#include "ArchiveResource.h"
#include "CSSPrimitiveValue.h"
#include "CSSPropertyNames.h"
#include "CSSValue.h"
@@ -35,6 +36,7 @@
#include "CSSValueKeywords.h"
#include "ChildListMutationScope.h"
#include "DocumentFragment.h"
+#include "DocumentLoader.h"
#include "DocumentType.h"
#include "Editing.h"
#include "Editor.h"
@@ -41,6 +43,7 @@
#include "ElementIterator.h"
#include "File.h"
#include "Frame.h"
+#include "FrameLoader.h"
#include "HTMLAttachmentElement.h"
#include "HTMLBRElement.h"
#include "HTMLBodyElement.h"
@@ -47,6 +50,7 @@
#include "HTMLDivElement.h"
#include "HTMLHeadElement.h"
#include "HTMLHtmlElement.h"
+#include "HTMLImageElement.h"
#include "HTMLNames.h"
#include "HTMLTableElement.h"
#include "HTMLTextAreaElement.h"
@@ -918,6 +922,37 @@
return fragment;
}
+Ref<DocumentFragment> createFragmentForImageAndURL(Document& document, const String& url)
+{
+ auto imageElement = HTMLImageElement::create(document);
+ imageElement->setAttributeWithoutSynchronization(HTMLNames::srcAttr, url);
+
+ auto fragment = document.createDocumentFragment();
+ fragment->appendChild(imageElement);
+
+ 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 (221959 => 221960)
--- trunk/Source/WebCore/editing/markup.h 2017-09-13 07:02:13 UTC (rev 221959)
+++ trunk/Source/WebCore/editing/markup.h 2017-09-13 07:17:43 UTC (rev 221960)
@@ -33,10 +33,12 @@
namespace WebCore {
+class ArchiveResource;
class ContainerNode;
class Document;
class DocumentFragment;
class Element;
+class Frame;
class HTMLElement;
class URL;
class Node;
@@ -51,6 +53,8 @@
WEBCORE_EXPORT Ref<DocumentFragment> createFragmentFromMarkup(Document&, const String& markup, const String& baseURL, ParserContentPolicy = AllowScriptingContent);
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*);
Modified: trunk/Source/WebKitLegacy/mac/ChangeLog (221959 => 221960)
--- trunk/Source/WebKitLegacy/mac/ChangeLog 2017-09-13 07:02:13 UTC (rev 221959)
+++ trunk/Source/WebKitLegacy/mac/ChangeLog 2017-09-13 07:17:43 UTC (rev 221960)
@@ -1,3 +1,12 @@
+2017-09-13 Ryosuke Niwa <[email protected]>
+
+ Refactor WebContentReader out of EditorMac and EditorIOS
+ https://bugs.webkit.org/show_bug.cgi?id=176770
+
+ Reviewed by Sam Weinig.
+
+ * WebCoreSupport/WebEditorClient.mm:
+
2017-09-12 Ryosuke Niwa <[email protected]>
Dragging & dropping a file creates an attachment element even when it's disabled
Modified: trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebEditorClient.mm (221959 => 221960)
--- trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebEditorClient.mm 2017-09-13 07:02:13 UTC (rev 221959)
+++ trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebEditorClient.mm 2017-09-13 07:17:43 UTC (rev 221960)
@@ -57,6 +57,7 @@
#import <WebCore/Document.h>
#import <WebCore/DocumentFragment.h>
#import <WebCore/Editor.h>
+#import <WebCore/Event.h>
#import <WebCore/FloatQuad.h>
#import <WebCore/Frame.h>
#import <WebCore/FrameView.h>
@@ -74,6 +75,7 @@
#import <WebCore/UndoStep.h>
#import <WebCore/UserTypingGestureIndicator.h>
#import <WebCore/VisibleUnits.h>
+#import <WebCore/WebContentReader.h>
#import <WebCore/WebCoreObjCExtras.h>
#import <pal/spi/mac/NSSpellCheckerSPI.h>
#import <runtime/InitializeThreading.h>