Refactor WebContentReader out of EditorMac and EditorIOS
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Sep 2017 07:17:43 +0000 (07:17 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Sep 2017 07:17:43 +0000 (07:17 +0000)
https://bugs.webkit.org/show_bug.cgi?id=176770

Reviewed by Sam Weinig.

Source/WebCore:

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:

Source/WebKitLegacy/mac:

* WebCoreSupport/WebEditorClient.mm:

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

18 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Configurations/WebCore.xcconfig
Source/WebCore/PlatformMac.cmake
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/editing/Editor.cpp
Source/WebCore/editing/Editor.h
Source/WebCore/editing/WebContentReader.h [new file with mode: 0644]
Source/WebCore/editing/cocoa/EditorCocoa.mm
Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm [new file with mode: 0644]
Source/WebCore/editing/gtk/EditorGtk.cpp
Source/WebCore/editing/ios/EditorIOS.mm
Source/WebCore/editing/ios/WebContentReaderIOS.mm [new file with mode: 0644]
Source/WebCore/editing/mac/EditorMac.mm
Source/WebCore/editing/mac/WebContentReaderMac.mm [new file with mode: 0644]
Source/WebCore/editing/markup.cpp
Source/WebCore/editing/markup.h
Source/WebKitLegacy/mac/ChangeLog
Source/WebKitLegacy/mac/WebCoreSupport/WebEditorClient.mm

index a4052fddc123826e99f3f0e7fa27573545d88a81..543d1470f2f8ed8db822a71f7bdca6855ffe2b32 100644 (file)
@@ -1,3 +1,60 @@
+2017-09-13  Ryosuke Niwa  <rniwa@webkit.org>
+
+        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  <utatane.tea@gmail.com>
 
         [DFG] Optimize WeakMap::get by adding intrinsic and fixup
index 35fc3e795ff8a29cb031c0593c26bebcddf3e447..76667bae740471d745a9512205eb1cf49d7a3235 100644 (file)
@@ -120,7 +120,7 @@ EXCLUDED_SOURCE_FILE_NAMES_FOR_TOUCH_EVENTS_IF_ENABLED_ = JSTouch*;
 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_internal.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 npruntime.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;
index 55008e669d07dcff3050508f82568f714db360f6..072c6f5fdebb9a9c905b4224c517fbdd5b7c8025 100644 (file)
@@ -203,6 +203,7 @@ list(APPEND WebCore_SOURCES
     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 @@ list(APPEND WebCore_SOURCES
     editing/mac/FrameSelectionMac.mm
     editing/mac/TextAlternativeWithRange.mm
     editing/mac/TextUndoInsertionMarkupMac.mm
+    editing/mac/WebContentReaderMac.mm
 
     fileapi/FileCocoa.mm
 
index 43d848db9c4496c5b54f7817107c7d35c13e451e..30d02ece7841341a2097314a1b618d48aec6de63 100644 (file)
                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 */; };
                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 */; };
                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>"; };
                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>"; };
                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>"; };
                                D0BD4F5A1408850F006839B6 /* DictationCommandIOS.cpp */,
                                D0BD4F5B1408850F006839B6 /* DictationCommandIOS.h */,
                                FED13D390CEA934600D89466 /* EditorIOS.mm */,
+                               9B0811231F67CDC00074BDE2 /* WebContentReaderIOS.mm */,
                        );
                        path = ios;
                        sourceTree = "<group>";
                                9B55EEE81B3E8898005342BC /* EditorCocoa.mm */,
                                7C3E510818DF8F3500C112F7 /* HTMLConverter.h */,
                                7C3E510918DF8F3500C112F7 /* HTMLConverter.mm */,
+                               9B9299B01F6796A4006723C2 /* WebContentReaderCocoa.mm */,
                        );
                        path = cocoa;
                        sourceTree = "<group>";
                                A883DF260F3D045D00F19BF6 /* VisibleSelection.h */,
                                93309DCE099E64910056E581 /* VisibleUnits.cpp */,
                                93309DCF099E64910056E581 /* VisibleUnits.h */,
+                               9BF433761F67619B00E1FD71 /* WebContentReader.h */,
                                93309DD4099E64910056E581 /* WrapContentsInDummySpanCommand.cpp */,
                                93309DD5099E64910056E581 /* WrapContentsInDummySpanCommand.h */,
                                9BAF3B2312C1A39800014BF1 /* WritingDirection.h */,
                                CE7B2DB21586ABAD0098B3FA /* TextAlternativeWithRange.mm */,
                                29FAF4B5195AB08900A522DC /* TextUndoInsertionMarkupMac.h */,
                                29498681195341940072D2BD /* TextUndoInsertionMarkupMac.mm */,
+                               9B9299AD1F67865B006723C2 /* WebContentReaderMac.mm */,
                        );
                        path = mac;
                        sourceTree = "<group>";
                                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 */,
                                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 */,
index 64251cf1dc7f69f5cabaca709dec5c7e876595e0..efcf7673312ec48fe8cd08993880201c4cbf2f22 100644 (file)
@@ -3818,15 +3818,4 @@ const Font* Editor::fontForSelection(bool& hasMultipleFonts) const
     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
index 26c027deeee5bb7a7c05b5067653ded4950d9cde..464218291a9320536561915e6ce572c74268f78f 100644 (file)
@@ -92,15 +92,6 @@ enum class MailBlockquoteHandling {
     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 @@ public:
     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 @@ private:
     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 *);
diff --git a/Source/WebCore/editing/WebContentReader.h b/Source/WebCore/editing/WebContentReader.h
new file mode 100644 (file)
index 0000000..11ace20
--- /dev/null
@@ -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
+    
+}
index 7d1c2e97830c42c695e646f75daf0d6e335d5c07..e8a5734508c7e33efd52cea700a4cfc1cd160640 100644 (file)
 #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 {
 
@@ -145,15 +134,6 @@ RetainPtr<NSDictionary> Editor::fontAttributesForSelectionStart() const
     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 @@ void Editor::replaceSelectionWithAttributedString(NSAttributedString *attributed
         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 @@ void Editor::replaceSelectionWithAttributedString(NSAttributedString *attributed
     }
 }
 
-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 = resource->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 @@ RefPtr<SharedBuffer> Editor::dataInRTFFormat(NSAttributedString *string)
     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);
-}
-
 }
diff --git a/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm b/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm
new file mode 100644 (file)
index 0000000..fbaef71
--- /dev/null
@@ -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);
+}
+
+}
index 7a1538459b000a22ab7f6ffc997328aa859950b5..321439a486798e712af835a382dc4bc084a70644 100644 (file)
@@ -65,7 +65,9 @@ static RefPtr<DocumentFragment> createFragmentFromPasteboardData(Pasteboard& pas
         }, &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));
         }
     }
 
index dc6e7155900601fba96f49c1e00bdc04f8f0393a..3ddd3c368153519e9d928fed8223fb99c61477b6 100644 (file)
 #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"
 #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 @@ void Editor::writeImageToPasteboard(Pasteboard& pasteboard, Element& imageElemen
     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)
diff --git a/Source/WebCore/editing/ios/WebContentReaderIOS.mm b/Source/WebCore/editing/ios/WebContentReaderIOS.mm
new file mode 100644 (file)
index 0000000..bc64613
--- /dev/null
@@ -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;
+}
+
+}
index e99fb8a42db74b2c95038d6ebed4db825606bab8..449d34ed59cde0b64ee861e4e0e1abb6761ac080 100644 (file)
 #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"
 #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 @@ void Editor::writeImageToPasteboard(Pasteboard& pasteboard, Element& imageElemen
     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)
diff --git a/Source/WebCore/editing/mac/WebContentReaderMac.mm b/Source/WebCore/editing/mac/WebContentReaderMac.mm
new file mode 100644 (file)
index 0000000..aec17b3
--- /dev/null
@@ -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;
+}
+    
+}
index 8a0b59a0bc38dd12e46e934f6243cc83cd4e917f..5297226137601744914b49883e31e01be53f9eef 100644 (file)
 #include "config.h"
 #include "markup.h"
 
+#include "ArchiveResource.h"
 #include "CSSPrimitiveValue.h"
 #include "CSSPropertyNames.h"
 #include "CSSValue.h"
 #include "CSSValueKeywords.h"
 #include "ChildListMutationScope.h"
 #include "DocumentFragment.h"
+#include "DocumentLoader.h"
 #include "DocumentType.h"
 #include "Editing.h"
 #include "Editor.h"
 #include "ElementIterator.h"
 #include "File.h"
 #include "Frame.h"
+#include "FrameLoader.h"
 #include "HTMLAttachmentElement.h"
 #include "HTMLBRElement.h"
 #include "HTMLBodyElement.h"
 #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 @@ RefPtr<DocumentFragment> createFragmentForTransformToFragment(Document& outputDo
     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;
index 8d4fe389dd2e285c5ddf75b3105028066dfbe479..f95b8ce997b63067ddf487353df874fbb9d9836e 100644 (file)
 
 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> createFragmentFromText(Range& context, cons
 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*);
index e806632a0ea8022dd726a8aeefc47596cbf8c244..0abad9bcf798ad598ae0c31d61bf5cfb365f4a90 100644 (file)
@@ -1,3 +1,12 @@
+2017-09-13  Ryosuke Niwa  <rniwa@webkit.org>
+
+        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  <rniwa@webkit.org>
 
         Dragging & dropping a file creates an attachment element even when it's disabled
index 7fe459da177429ad947b12b770f94d368aa54332..7ad02e5ba4a6edf3e6cb2bf897e1bec84c5ce9ae 100644 (file)
@@ -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>