Title: [222239] trunk/Source
Revision
222239
Author
[email protected]
Date
2017-09-19 18:20:29 -0700 (Tue, 19 Sep 2017)

Log Message

Layering violation in Editor::createFragment
https://bugs.webkit.org/show_bug.cgi?id=176123

Reviewed by Darin Adler.

Source/WebCore:

* WebCore.xcodeproj/project.pbxproj:
* editing/cocoa/WebArchiveResourceFromNSAttributedString.h: Added.
* editing/cocoa/WebArchiveResourceFromNSAttributedString.mm: Added.
Added a wrapper class for ArchiveResource, suitable for use as a WebResourceHandler.

* editing/cocoa/WebArchiveResourceWebResourceHandler.h: Added.
* editing/cocoa/WebArchiveResourceWebResourceHandler.mm: Added.
Objects of this class can be passed as "WebResourceHandler", and created instances
of the above class.

* editing/cocoa/WebContentReaderCocoa.mm:
(WebCore::attributesForAttributedStringConversion):
(WebCore::createFragment):
On newer OS versions, don't use WebKitLegacy to convert NSAttributedString to a
document fragment. We now only use system frameworks to convert the attributed
string to HTML source, and parse HTML into a fragment directly in WebCore.

* platform/URL.h: Exported fakeURLWithRelativePart.

Source/WebKitLegacy/mac:

* Misc/WebNSURLExtras.h:
* Misc/WebNSURLExtras.mm:
* WebView/WebFrame.mm:
* WebView/WebHTMLView.mm:
Removed multiple copies of webkit-fake-url creation code, switching to URL::fakeURLWithRelativePart().

* WebCoreSupport/WebEditorClient.mm:
(_WebCreateFragment): Added a stub implementation for older OSes. This is needed
because WebKitLegacy.exp is not passed through preprocessor, so there is no sane
way to avoid exporting the symbol just on newer OSes.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (222238 => 222239)


--- trunk/Source/WebCore/ChangeLog	2017-09-20 00:57:40 UTC (rev 222238)
+++ trunk/Source/WebCore/ChangeLog	2017-09-20 01:20:29 UTC (rev 222239)
@@ -1,3 +1,29 @@
+2017-09-19  Alexey Proskuryakov  <[email protected]>
+
+        Layering violation in Editor::createFragment
+        https://bugs.webkit.org/show_bug.cgi?id=176123
+
+        Reviewed by Darin Adler.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * editing/cocoa/WebArchiveResourceFromNSAttributedString.h: Added.
+        * editing/cocoa/WebArchiveResourceFromNSAttributedString.mm: Added.
+        Added a wrapper class for ArchiveResource, suitable for use as a WebResourceHandler.
+
+        * editing/cocoa/WebArchiveResourceWebResourceHandler.h: Added.
+        * editing/cocoa/WebArchiveResourceWebResourceHandler.mm: Added.
+        Objects of this class can be passed as "WebResourceHandler", and created instances
+        of the above class.
+
+        * editing/cocoa/WebContentReaderCocoa.mm:
+        (WebCore::attributesForAttributedStringConversion):
+        (WebCore::createFragment):
+        On newer OS versions, don't use WebKitLegacy to convert NSAttributedString to a
+        document fragment. We now only use system frameworks to convert the attributed
+        string to HTML source, and parse HTML into a fragment directly in WebCore.
+
+        * platform/URL.h: Exported fakeURLWithRelativePart.
+
 2017-09-19  Youenn Fablet  <[email protected]>
 
         Allow WTF::map to use any class that is iterable and has a size getter

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (222238 => 222239)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2017-09-20 00:57:40 UTC (rev 222238)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2017-09-20 01:20:29 UTC (rev 222239)
@@ -6717,6 +6717,10 @@
 		E182568F0EF2B02D00933242 /* JSWorkerGlobalScope.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E182568D0EF2B02D00933242 /* JSWorkerGlobalScope.cpp */; };
 		E18256900EF2B02D00933242 /* JSWorkerGlobalScope.h in Headers */ = {isa = PBXBuildFile; fileRef = E182568E0EF2B02D00933242 /* JSWorkerGlobalScope.h */; };
 		E18258AC0EF3CD7000933242 /* JSWorkerGlobalScopeCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E18258AB0EF3CD7000933242 /* JSWorkerGlobalScopeCustom.cpp */; };
+		E18536841F4E481400FE091B /* WebArchiveResourceFromNSAttributedString.h in Headers */ = {isa = PBXBuildFile; fileRef = E18536811F4E472700FE091B /* WebArchiveResourceFromNSAttributedString.h */; };
+		E18536851F50906100FE091B /* WebArchiveResourceFromNSAttributedString.mm in Sources */ = {isa = PBXBuildFile; fileRef = E18536821F4E472700FE091B /* WebArchiveResourceFromNSAttributedString.mm */; };
+		E18C35431F71970100FF632D /* WebArchiveResourceWebResourceHandler.mm in Sources */ = {isa = PBXBuildFile; fileRef = E18C35421F71970100FF632D /* WebArchiveResourceWebResourceHandler.mm */; };
+		E18C35441F71970C00FF632D /* WebArchiveResourceWebResourceHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = E18C35411F7196CD00FF632D /* WebArchiveResourceWebResourceHandler.h */; };
 		E18DF33518AAF12C00773E59 /* SerializedCryptoKeyWrap.h in Headers */ = {isa = PBXBuildFile; fileRef = E18DF33418AAF12C00773E59 /* SerializedCryptoKeyWrap.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		E18DF33818AAF14D00773E59 /* SerializedCryptoKeyWrapMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = E18DF33618AAF14D00773E59 /* SerializedCryptoKeyWrapMac.mm */; };
 		E19727161820549E00592D51 /* CryptoKeyType.h in Headers */ = {isa = PBXBuildFile; fileRef = E19727151820549E00592D51 /* CryptoKeyType.h */; };
@@ -15528,6 +15532,10 @@
 		E182568D0EF2B02D00933242 /* JSWorkerGlobalScope.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSWorkerGlobalScope.cpp; sourceTree = "<group>"; };
 		E182568E0EF2B02D00933242 /* JSWorkerGlobalScope.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSWorkerGlobalScope.h; sourceTree = "<group>"; };
 		E18258AB0EF3CD7000933242 /* JSWorkerGlobalScopeCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSWorkerGlobalScopeCustom.cpp; sourceTree = "<group>"; };
+		E18536811F4E472700FE091B /* WebArchiveResourceFromNSAttributedString.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebArchiveResourceFromNSAttributedString.h; sourceTree = "<group>"; };
+		E18536821F4E472700FE091B /* WebArchiveResourceFromNSAttributedString.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WebArchiveResourceFromNSAttributedString.mm; sourceTree = "<group>"; };
+		E18C35411F7196CD00FF632D /* WebArchiveResourceWebResourceHandler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebArchiveResourceWebResourceHandler.h; sourceTree = "<group>"; };
+		E18C35421F71970100FF632D /* WebArchiveResourceWebResourceHandler.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WebArchiveResourceWebResourceHandler.mm; sourceTree = "<group>"; };
 		E18DF33418AAF12C00773E59 /* SerializedCryptoKeyWrap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SerializedCryptoKeyWrap.h; sourceTree = "<group>"; };
 		E18DF33618AAF14D00773E59 /* SerializedCryptoKeyWrapMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SerializedCryptoKeyWrapMac.mm; sourceTree = "<group>"; };
 		E19727151820549E00592D51 /* CryptoKeyType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoKeyType.h; sourceTree = "<group>"; };
@@ -20268,6 +20276,10 @@
 				9B55EEE81B3E8898005342BC /* EditorCocoa.mm */,
 				7C3E510818DF8F3500C112F7 /* HTMLConverter.h */,
 				7C3E510918DF8F3500C112F7 /* HTMLConverter.mm */,
+				E18536811F4E472700FE091B /* WebArchiveResourceFromNSAttributedString.h */,
+				E18536821F4E472700FE091B /* WebArchiveResourceFromNSAttributedString.mm */,
+				E18C35411F7196CD00FF632D /* WebArchiveResourceWebResourceHandler.h */,
+				E18C35421F71970100FF632D /* WebArchiveResourceWebResourceHandler.mm */,
 				9B9299B01F6796A4006723C2 /* WebContentReaderCocoa.mm */,
 			);
 			path = cocoa;
@@ -28884,6 +28896,7 @@
 				316DCB201E78CA55001B5F87 /* JSRTCOfferAnswerOptions.h in Headers */,
 				07969DBA17D14151007FF842 /* JSRTCPeerConnection.h in Headers */,
 				07969DB817D14151007FF842 /* JSRTCPeerConnectionIceEvent.h in Headers */,
+				E18C35441F71970C00FF632D /* WebArchiveResourceWebResourceHandler.h in Headers */,
 				5E2C43741BCF0D750001E2BE /* JSRTCRtpParameters.h in Headers */,
 				5E2C43721BCF0D750001E2BC /* JSRTCRtpReceiver.h in Headers */,
 				5E2C43741BCF0D750001E2BC /* JSRTCRtpSender.h in Headers */,
@@ -30372,6 +30385,7 @@
 				0806E57A12893045007CED32 /* SVGMatrix.h in Headers */,
 				08CA3D4412894A3800FFF260 /* SVGMatrixTearOff.h in Headers */,
 				7CE58D5C1DD7EC9C00128552 /* SVGMatrixValue.h in Headers */,
+				E18536841F4E481400FE091B /* WebArchiveResourceFromNSAttributedString.h in Headers */,
 				B2227A4B0D00BF220071B782 /* SVGMetadataElement.h in Headers */,
 				B2A1F2B10CEF0ABF00442F6A /* SVGMissingGlyphElement.h in Headers */,
 				B2227A4E0D00BF220071B782 /* SVGMPathElement.h in Headers */,
@@ -32714,6 +32728,7 @@
 				A6148A7812E41E3B0044A784 /* JSHTMLKeygenElement.cpp in Sources */,
 				1AE2AB210A1CE63B00B42B25 /* JSHTMLLabelElement.cpp in Sources */,
 				1AE2AB230A1CE63B00B42B25 /* JSHTMLLegendElement.cpp in Sources */,
+				E18C35431F71970100FF632D /* WebArchiveResourceWebResourceHandler.mm in Sources */,
 				1AE2AB250A1CE63B00B42B25 /* JSHTMLLIElement.cpp in Sources */,
 				A80E7B100A19D606007FB8C5 /* JSHTMLLinkElement.cpp in Sources */,
 				1AE2AB270A1CE63B00B42B25 /* JSHTMLMapElement.cpp in Sources */,
@@ -32881,6 +32896,7 @@
 				A1CC56781F4614A500A4555B /* JSPaymentRequest.cpp in Sources */,
 				A1F600571F4765050077E83F /* JSPaymentRequestUpdateEvent.cpp in Sources */,
 				A1F600591F4765050077E83F /* JSPaymentRequestUpdateEventInit.cpp in Sources */,
+				E18536851F50906100FE091B /* WebArchiveResourceFromNSAttributedString.mm in Sources */,
 				A1CC567A1F4614AA00A4555B /* JSPaymentResponse.cpp in Sources */,
 				A1CC567C1F4614AF00A4555B /* JSPaymentShippingOption.cpp in Sources */,
 				A1CC567E1F4614B400A4555B /* JSPaymentShippingType.cpp in Sources */,

Added: trunk/Source/WebCore/editing/cocoa/WebArchiveResourceFromNSAttributedString.h (0 => 222239)


--- trunk/Source/WebCore/editing/cocoa/WebArchiveResourceFromNSAttributedString.h	                        (rev 0)
+++ trunk/Source/WebCore/editing/cocoa/WebArchiveResourceFromNSAttributedString.h	2017-09-20 01:20:29 UTC (rev 222239)
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 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
+
+#import <wtf/RefPtr.h>
+
+namespace WebCore {
+class ArchiveResource;
+}
+
+@interface WebArchiveResourceFromNSAttributedString : NSObject {
+@package
+    RefPtr<WebCore::ArchiveResource> resource;
+}
+- (instancetype)initWithData:(NSData *)data URL:(NSURL *)URL MIMEType:(NSString *)MIMEType textEncodingName:(NSString *)textEncodingName frameName:(NSString *)frameName;
+- (NSURL *)URL;
+
+@end

Added: trunk/Source/WebCore/editing/cocoa/WebArchiveResourceFromNSAttributedString.mm (0 => 222239)


--- trunk/Source/WebCore/editing/cocoa/WebArchiveResourceFromNSAttributedString.mm	                        (rev 0)
+++ trunk/Source/WebCore/editing/cocoa/WebArchiveResourceFromNSAttributedString.mm	2017-09-20 01:20:29 UTC (rev 222239)
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 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.
+ */
+
+#import "config.h"
+#import "WebArchiveResourceFromNSAttributedString.h"
+
+#import "ArchiveResource.h"
+
+using namespace WebCore;
+
+@implementation WebArchiveResourceFromNSAttributedString
+
+- (instancetype)initWithData:(NSData *)data URL:(NSURL *)URL MIMEType:(NSString *)MIMEType textEncodingName:(NSString *)textEncodingName frameName:(NSString *)frameName
+{
+    if (!(self = [super init]))
+        return nil;
+
+    if (!data || !URL || !MIMEType) {
+        [self release];
+        return nil;
+    }
+
+    resource = ArchiveResource::create(SharedBuffer::create(adoptNS([data copy]).get()), URL, MIMEType, textEncodingName, frameName, nil);
+    if (!resource) {
+        [self release];
+        return nil;
+    }
+
+    return self;
+}
+
+- (NSURL *)URL
+{
+    return resource->url();
+}
+
+@end

Added: trunk/Source/WebCore/editing/cocoa/WebArchiveResourceWebResourceHandler.h (0 => 222239)


--- trunk/Source/WebCore/editing/cocoa/WebArchiveResourceWebResourceHandler.h	                        (rev 0)
+++ trunk/Source/WebCore/editing/cocoa/WebArchiveResourceWebResourceHandler.h	2017-09-20 01:20:29 UTC (rev 222239)
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 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
+
+@interface WebArchiveResourceWebResourceHandler : NSObject {
+}
+- (id)resourceForData:(NSData *)data URL:(NSURL *)url MIMEType:(NSString *)mimeType textEncodingName:(NSString *)textEncodingName frameName:(NSString *)frameName;
+@end

Added: trunk/Source/WebCore/editing/cocoa/WebArchiveResourceWebResourceHandler.mm (0 => 222239)


--- trunk/Source/WebCore/editing/cocoa/WebArchiveResourceWebResourceHandler.mm	                        (rev 0)
+++ trunk/Source/WebCore/editing/cocoa/WebArchiveResourceWebResourceHandler.mm	2017-09-20 01:20:29 UTC (rev 222239)
@@ -0,0 +1,39 @@
+
+/*
+ * Copyright (C) 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.
+ */
+
+#import "config.h"
+#import "WebArchiveResourceWebResourceHandler.h"
+
+#import "WebArchiveResourceFromNSAttributedString.h"
+
+@implementation WebArchiveResourceWebResourceHandler
+
+- (id)resourceForData:(NSData *)data URL:(NSURL *)url MIMEType:(NSString *)mimeType textEncodingName:(NSString *)textEncodingName frameName:(NSString *)frameName
+{
+    return [[[WebArchiveResourceFromNSAttributedString alloc] initWithData:data URL:url MIMEType:mimeType textEncodingName:textEncodingName frameName:frameName] autorelease];
+}
+
+@end

Modified: trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm (222238 => 222239)


--- trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm	2017-09-20 00:57:40 UTC (rev 222238)
+++ trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm	2017-09-20 01:20:29 UTC (rev 222239)
@@ -23,50 +23,105 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include "config.h"
-#include "WebContentReader.h"
+#import "config.h"
+#import "WebContentReader.h"
 
-#include "ArchiveResource.h"
-#include "Blob.h"
-#include "CachedResourceLoader.h"
-#include "DOMURL.h"
-#include "Document.h"
-#include "DocumentFragment.h"
-#include "DocumentLoader.h"
-#include "Frame.h"
-#include "FrameLoader.h"
-#include "FrameLoaderClient.h"
-#include "HTMLImageElement.h"
-#include "LegacyWebArchive.h"
-#include "Page.h"
-#include "Settings.h"
-#include "WebNSAttributedStringExtras.h"
-#include "markup.h"
-#include <pal/spi/cocoa/NSAttributedStringSPI.h>
-#include <wtf/SoftLinking.h>
+#import "ArchiveResource.h"
+#import "Blob.h"
+#import "CachedResourceLoader.h"
+#import "DOMURL.h"
+#import "Document.h"
+#import "DocumentFragment.h"
+#import "DocumentLoader.h"
+#import "Frame.h"
+#import "FrameLoader.h"
+#import "FrameLoaderClient.h"
+#import "HTMLBodyElement.h"
+#import "HTMLImageElement.h"
+#import "LegacyWebArchive.h"
+#import "Page.h"
+#import "Settings.h"
+#import "WebArchiveResourceFromNSAttributedString.h"
+#import "WebArchiveResourceWebResourceHandler.h"
+#import "WebNSAttributedStringExtras.h"
+#import "markup.h"
+#import <pal/spi/cocoa/NSAttributedStringSPI.h>
+#import <wtf/SoftLinking.h>
 
-#if PLATFORM(IOS)
+#if (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300)
+@interface NSAttributedString ()
+- (NSString *)_htmlDocumentFragmentString:(NSRange)range documentAttributes:(NSDictionary *)dict subresources:(NSArray **)subresources;
+@end
+#elif PLATFORM(IOS)
 SOFT_LINK_PRIVATE_FRAMEWORK(WebKitLegacy)
-#endif
-
-#if PLATFORM(MAC)
+#elif 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).
+#if (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED < 110000) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101300)
 SOFT_LINK(WebKitLegacy, _WebCreateFragment, void, (WebCore::Document& document, NSAttributedString *string, WebCore::FragmentAndResources& result), (document, string, result))
+#endif
 
 namespace WebCore {
 
+#if (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300)
+
+static NSDictionary *attributesForAttributedStringConversion()
+{
+    // This function needs to be kept in sync with identically named one in WebKitLegacy, which is used on older OS versions.
+    RetainPtr<NSArray> excludedElements = adoptNS([[NSArray alloc] initWithObjects:
+        // Omit style since we want style to be inline so the fragment can be easily inserted.
+        @"style",
+        // Omit xml so the result is not XHTML.
+        @"xml",
+        // Omit tags that will get stripped when converted to a fragment anyway.
+        @"doctype", @"html", @"head", @"body",
+        // Omit deprecated tags.
+        @"applet", @"basefont", @"center", @"dir", @"font", @"menu", @"s", @"strike", @"u",
+        // Omit object so no file attachments are part of the fragment.
+        @"object", nil]);
+
+#if PLATFORM(IOS)
+    static NSString * const NSExcludedElementsDocumentAttribute = @"ExcludedElements";
+#endif
+
+    return @{
+        NSExcludedElementsDocumentAttribute: excludedElements.get(),
+        @"InterchangeNewline": @YES,
+        @"CoalesceTabSpans": @YES,
+        @"OutputBaseURL": [(NSURL *)URL::fakeURLWithRelativePart(emptyString()) retain], // The value needs +1 refcount, as NSAttributedString over-releases it.
+        @"WebResourceHandler": [WebArchiveResourceWebResourceHandler new],
+    };
+}
+
 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;
+    Document& document = *frame.document();
+
+    NSArray *subresources = nil;
+    NSString *fragmentString = [string _htmlDocumentFragmentString:NSMakeRange(0, [string length]) documentAttributes:attributesForAttributedStringConversion() subresources:&subresources];
+    auto fragment = DocumentFragment::create(document);
+    fragment->parseHTML(fragmentString, document.body(), DisallowScriptingAndPluginContent);
+
+    result.fragment = WTFMove(fragment);
+    for (WebArchiveResourceFromNSAttributedString *resource in subresources)
+        result.resources.append(*resource->resource);
+
+    return result;
+}
+
+#else
+
+static FragmentAndResources createFragment(Frame& frame, NSAttributedString *string)
+{
+    FragmentAndResources result;
     _WebCreateFragment(*frame.document(), string, result);
     return result;
 }
 
+#endif
+
 RefPtr<DocumentFragment> createFragmentAndAddResources(Frame& frame, NSAttributedString *string)
 {
     if (!frame.page() || !frame.document())

Modified: trunk/Source/WebCore/platform/URL.h (222238 => 222239)


--- trunk/Source/WebCore/platform/URL.h	2017-09-20 00:57:40 UTC (rev 222238)
+++ trunk/Source/WebCore/platform/URL.h	2017-09-20 01:20:29 UTC (rev 222239)
@@ -75,7 +75,7 @@
     WEBCORE_EXPORT URL(const URL& base, const String& relative);
     URL(const URL& base, const String& relative, const TextEncoding&);
 
-    static URL fakeURLWithRelativePart(const String&);
+    WEBCORE_EXPORT static URL fakeURLWithRelativePart(const String&);
     WEBCORE_EXPORT static URL fileURLWithFileSystemPath(const String&);
 
     String strippedForUseAsReferrer() const;

Modified: trunk/Source/WebKitLegacy/mac/ChangeLog (222238 => 222239)


--- trunk/Source/WebKitLegacy/mac/ChangeLog	2017-09-20 00:57:40 UTC (rev 222238)
+++ trunk/Source/WebKitLegacy/mac/ChangeLog	2017-09-20 01:20:29 UTC (rev 222239)
@@ -1,3 +1,21 @@
+2017-09-19  Alexey Proskuryakov  <[email protected]>
+
+        Layering violation in Editor::createFragment
+        https://bugs.webkit.org/show_bug.cgi?id=176123
+
+        Reviewed by Darin Adler.
+
+        * Misc/WebNSURLExtras.h:
+        * Misc/WebNSURLExtras.mm:
+        * WebView/WebFrame.mm:
+        * WebView/WebHTMLView.mm:
+        Removed multiple copies of webkit-fake-url creation code, switching to URL::fakeURLWithRelativePart().
+
+        * WebCoreSupport/WebEditorClient.mm:
+        (_WebCreateFragment): Added a stub implementation for older OSes. This is needed
+        because WebKitLegacy.exp is not passed through preprocessor, so there is no sane
+        way to avoid exporting the symbol just on newer OSes.
+
 2017-09-19  Ryosuke Niwa  <[email protected]>
 
         On iOS, getData can't get text set by setData during copy event

Modified: trunk/Source/WebKitLegacy/mac/Misc/WebNSURLExtras.h (222238 => 222239)


--- trunk/Source/WebKitLegacy/mac/Misc/WebNSURLExtras.h	2017-09-20 00:57:40 UTC (rev 222238)
+++ trunk/Source/WebKitLegacy/mac/Misc/WebNSURLExtras.h	2017-09-20 01:20:29 UTC (rev 222239)
@@ -71,11 +71,6 @@
 
 - (NSURL *)_webkit_URLFromURLOrSchemelessFileURL;
 
-#if TARGET_OS_IPHONE
-// FIXME: This method name needs a prefix.
-+ (NSURL *)uniqueURLWithRelativePart:(NSString *)relativePart;
-#endif
-
 @end
 
 @interface NSString (WebNSURLExtras)

Modified: trunk/Source/WebKitLegacy/mac/Misc/WebNSURLExtras.mm (222238 => 222239)


--- trunk/Source/WebKitLegacy/mac/Misc/WebNSURLExtras.mm	2017-09-20 00:57:40 UTC (rev 222238)
+++ trunk/Source/WebKitLegacy/mac/Misc/WebNSURLExtras.mm	2017-09-20 01:20:29 UTC (rev 222239)
@@ -46,11 +46,6 @@
 using namespace WebCore;
 using namespace WTF;
 
-#if PLATFORM(IOS)
-// Fake URL scheme.
-#define WebDataProtocolScheme @"webkit-fake-url"
-#endif
-
 #define URL_BYTES_BUFFER_LENGTH 2048
 
 @implementation NSURL (WebNSURLExtras)
@@ -217,20 +212,6 @@
 
     return [NSURL URLWithString:[@"file:" stringByAppendingString:[self absoluteString]]];
 }
-
-#if PLATFORM(IOS)
-+ (NSURL *)uniqueURLWithRelativePart:(NSString *)relativePart
-{
-    CFUUIDRef UUIDRef = CFUUIDCreate(kCFAllocatorDefault);
-    NSString *UUIDString = (NSString *)CFUUIDCreateString(kCFAllocatorDefault, UUIDRef);
-    CFRelease(UUIDRef);
-    NSURL *URL = "" URLWithString:[NSString stringWithFormat:@"%@://%@/%@", WebDataProtocolScheme, UUIDString, relativePart]];
-    CFRelease(UUIDString);
-    
-    return URL;
-}
-
-#endif // PLATFORM(IOS)
 @end
 
 @implementation NSString (WebNSURLExtras)

Modified: trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebEditorClient.mm (222238 => 222239)


--- trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebEditorClient.mm	2017-09-20 00:57:40 UTC (rev 222238)
+++ trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebEditorClient.mm	2017-09-20 01:20:29 UTC (rev 222239)
@@ -101,9 +101,11 @@
 @end
 #endif
 
+#if (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED < 110000) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101300)
 @interface NSAttributedString (WebNSAttributedStringDetails)
 - (DOMDocumentFragment *)_documentFromRange:(NSRange)range document:(DOMDocument *)document documentAttributes:(NSDictionary *)attributes subresources:(NSArray **)subresources;
 @end
+#endif
 
 static WebViewInsertAction kit(EditorInsertAction action)
 {
@@ -435,8 +437,21 @@
     return URL;
 }
 
+#if (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300)
+
+// FIXME: Remove both this stub and the real version of this function below once we don't need the real version on any supported platform.
+// This stub is not used outside WebKit, but it's here so we won't get a linker error.
+__attribute__((__noreturn__))
+void _WebCreateFragment(Document&, NSAttributedString *, FragmentAndResources&)
+{
+    RELEASE_ASSERT_NOT_REACHED();
+}
+
+#else
+
 static NSDictionary *attributesForAttributedStringConversion()
 {
+    // This function needs to be kept in sync with identically named one in WebCore, which is used on newer OS versions.
     NSArray *excludedElements = [[NSArray alloc] initWithObjects:
         // Omit style since we want style to be inline so the fragment can be easily inserted.
         @"style",
@@ -471,6 +486,8 @@
         result.resources.append([resource _coreResource]);
 }
 
+#endif
+
 void WebEditorClient::setInsertionPasteboard(const String& pasteboardName)
 {
 #if !PLATFORM(IOS)

Modified: trunk/Source/WebKitLegacy/mac/WebView/WebFrame.mm (222238 => 222239)


--- trunk/Source/WebKitLegacy/mac/WebView/WebFrame.mm	2017-09-20 00:57:40 UTC (rev 222238)
+++ trunk/Source/WebKitLegacy/mac/WebView/WebFrame.mm	2017-09-20 01:20:29 UTC (rev 222239)
@@ -2295,7 +2295,7 @@
 - (DOMDocumentFragment *)_documentFragmentForImageData:(NSData *)data withRelativeURLPart:(NSString *)relativeURLPart andMIMEType:(NSString *)mimeType
 {
     WebResource *resource = [[WebResource alloc] initWithData:data
-                                                          URL:[NSURL uniqueURLWithRelativePart:relativeURLPart]
+                                                          URL:URL::fakeURLWithRelativePart(relativeURLPart)
                                                      MIMEType:mimeType
                                              textEncodingName:nil
                                                     frameName:nil];

Modified: trunk/Source/WebKitLegacy/mac/WebView/WebHTMLView.mm (222238 => 222239)


--- trunk/Source/WebKitLegacy/mac/WebView/WebHTMLView.mm	2017-09-20 00:57:40 UTC (rev 222238)
+++ trunk/Source/WebKitLegacy/mac/WebView/WebHTMLView.mm	2017-09-20 01:20:29 UTC (rev 222239)
@@ -786,9 +786,6 @@
 #define MIN_BOLD_WEIGHT 7
 #define STANDARD_BOLD_WEIGHT 9
 
-// Fake URL scheme.
-#define WebDataProtocolScheme @"webkit-fake-url"
-
 #if PLATFORM(MAC)
 
 // <rdar://problem/4985524> References to WebCoreScrollView as a subview of a WebHTMLView may be present
@@ -1129,11 +1126,6 @@
     return elements;
 }
 
-static NSURL *uniqueURLWithRelativePart(NSString *relativePart)
-{
-    return [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@/%@", WebDataProtocolScheme, [NSUUID UUID], relativePart]];
-}
-
 - (DOMDocumentFragment *)_documentFragmentFromPasteboard:(NSPasteboard *)pasteboard
                                                inContext:(DOMRange *)context
                                           allowPlainText:(BOOL)allowPlainText
@@ -2332,7 +2324,7 @@
 {
     auto filename = [imageMIMEType stringByReplacingOccurrencesOfString:@"/" withString:@"."];
     auto resource = adoptNS([[WebResource alloc] initWithData:[pasteboard dataForType:pasteboardType]
-        URL:uniqueURLWithRelativePart(filename) MIMEType:imageMIMEType textEncodingName:nil frameName:nil]);
+        URL:URL::fakeURLWithRelativePart(filename) MIMEType:imageMIMEType textEncodingName:nil frameName:nil]);
     return [[self _dataSource] _documentFragmentWithImageResource:resource.get()];
 }
 
@@ -7300,6 +7292,7 @@
 
 @end
 
+#if (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED < 110000) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101300)
 // This is used by AppKit/TextKit and is implemented here in part so that WebDataProtocolScheme is only defined once.
 // FIXME: Really should have an @interface for this somewhere in this file or an include. Not sure why it compiles without one.
 @implementation NSURL (WebDataURL)
@@ -7306,10 +7299,11 @@
 
 + (NSURL *)_web_uniqueWebDataURL
 {
-    return [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@", WebDataProtocolScheme, [NSUUID UUID]]];
+    return URL::fakeURLWithRelativePart(emptyString());
 }
 
 @end
+#endif
 
 #if PLATFORM(MAC)
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to