Source/WebCore/ChangeLog

 12017-09-19 Alexey Proskuryakov <ap@apple.com>
 2
 3 Layering violation in Editor::createFragment
 4 https://bugs.webkit.org/show_bug.cgi?id=176123
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 * WebCore.xcodeproj/project.pbxproj:
 9 * editing/cocoa/WebArchiveResourceFromNSAttributedString.h: Added.
 10 * editing/cocoa/WebArchiveResourceFromNSAttributedString.mm: Added.
 11 Added a wrapper class for ArchiveResource, suitable for use as a WebResourceHandler.
 12
 13 * editing/cocoa/WebArchiveResourceWebResourceHandler.h: Added.
 14 * editing/cocoa/WebArchiveResourceWebResourceHandler.mm: Added.
 15 Objects of this class can be passed as "WebResourceHandler", and created instances
 16 of the above class.
 17
 18 * editing/cocoa/WebContentReaderCocoa.mm:
 19 (WebCore::attributesForAttributedStringConversion):
 20 (WebCore::createFragment):
 21 On newer OS versions, don't use WebKitLegacy to convert NSAttributedString to a
 22 document fragment. We now only use system frameworks to convert the attributed
 23 string to HTML source, and parse HTML into a fragment directly in WebCore.
 24
 25 * platform/URL.h: Exported fakeURLWithRelativePart.
 26
1272017-09-19 Zalan Bujtas <zalan@apple.com>
228
329 Attempt to fix Linux build.
222217

Source/WebCore/WebCore.xcodeproj/project.pbxproj

67136713 E182568F0EF2B02D00933242 /* JSWorkerGlobalScope.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E182568D0EF2B02D00933242 /* JSWorkerGlobalScope.cpp */; };
67146714 E18256900EF2B02D00933242 /* JSWorkerGlobalScope.h in Headers */ = {isa = PBXBuildFile; fileRef = E182568E0EF2B02D00933242 /* JSWorkerGlobalScope.h */; };
67156715 E18258AC0EF3CD7000933242 /* JSWorkerGlobalScopeCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E18258AB0EF3CD7000933242 /* JSWorkerGlobalScopeCustom.cpp */; };
 6716 E18536841F4E481400FE091B /* WebArchiveResourceFromNSAttributedString.h in Headers */ = {isa = PBXBuildFile; fileRef = E18536811F4E472700FE091B /* WebArchiveResourceFromNSAttributedString.h */; };
 6717 E18536851F50906100FE091B /* WebArchiveResourceFromNSAttributedString.mm in Sources */ = {isa = PBXBuildFile; fileRef = E18536821F4E472700FE091B /* WebArchiveResourceFromNSAttributedString.mm */; };
 6718 E18C35431F71970100FF632D /* WebArchiveResourceWebResourceHandler.mm in Sources */ = {isa = PBXBuildFile; fileRef = E18C35421F71970100FF632D /* WebArchiveResourceWebResourceHandler.mm */; };
 6719 E18C35441F71970C00FF632D /* WebArchiveResourceWebResourceHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = E18C35411F7196CD00FF632D /* WebArchiveResourceWebResourceHandler.h */; };
67166720 E18DF33518AAF12C00773E59 /* SerializedCryptoKeyWrap.h in Headers */ = {isa = PBXBuildFile; fileRef = E18DF33418AAF12C00773E59 /* SerializedCryptoKeyWrap.h */; settings = {ATTRIBUTES = (Private, ); }; };
67176721 E18DF33818AAF14D00773E59 /* SerializedCryptoKeyWrapMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = E18DF33618AAF14D00773E59 /* SerializedCryptoKeyWrapMac.mm */; };
67186722 E19727161820549E00592D51 /* CryptoKeyType.h in Headers */ = {isa = PBXBuildFile; fileRef = E19727151820549E00592D51 /* CryptoKeyType.h */; };

1552015524 E182568D0EF2B02D00933242 /* JSWorkerGlobalScope.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSWorkerGlobalScope.cpp; sourceTree = "<group>"; };
1552115525 E182568E0EF2B02D00933242 /* JSWorkerGlobalScope.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSWorkerGlobalScope.h; sourceTree = "<group>"; };
1552215526 E18258AB0EF3CD7000933242 /* JSWorkerGlobalScopeCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSWorkerGlobalScopeCustom.cpp; sourceTree = "<group>"; };
 15527 E18536811F4E472700FE091B /* WebArchiveResourceFromNSAttributedString.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebArchiveResourceFromNSAttributedString.h; sourceTree = "<group>"; };
 15528 E18536821F4E472700FE091B /* WebArchiveResourceFromNSAttributedString.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WebArchiveResourceFromNSAttributedString.mm; sourceTree = "<group>"; };
 15529 E18C35411F7196CD00FF632D /* WebArchiveResourceWebResourceHandler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebArchiveResourceWebResourceHandler.h; sourceTree = "<group>"; };
 15530 E18C35421F71970100FF632D /* WebArchiveResourceWebResourceHandler.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WebArchiveResourceWebResourceHandler.mm; sourceTree = "<group>"; };
1552315531 E18DF33418AAF12C00773E59 /* SerializedCryptoKeyWrap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SerializedCryptoKeyWrap.h; sourceTree = "<group>"; };
1552415532 E18DF33618AAF14D00773E59 /* SerializedCryptoKeyWrapMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SerializedCryptoKeyWrapMac.mm; sourceTree = "<group>"; };
1552515533 E19727151820549E00592D51 /* CryptoKeyType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoKeyType.h; sourceTree = "<group>"; };

2026020268 9B55EEE81B3E8898005342BC /* EditorCocoa.mm */,
2026120269 7C3E510818DF8F3500C112F7 /* HTMLConverter.h */,
2026220270 7C3E510918DF8F3500C112F7 /* HTMLConverter.mm */,
 20271 E18536811F4E472700FE091B /* WebArchiveResourceFromNSAttributedString.h */,
 20272 E18536821F4E472700FE091B /* WebArchiveResourceFromNSAttributedString.mm */,
 20273 E18C35411F7196CD00FF632D /* WebArchiveResourceWebResourceHandler.h */,
 20274 E18C35421F71970100FF632D /* WebArchiveResourceWebResourceHandler.mm */,
2026320275 9B9299B01F6796A4006723C2 /* WebContentReaderCocoa.mm */,
2026420276 );
2026520277 path = cocoa;

2887028882 316DCB201E78CA55001B5F87 /* JSRTCOfferAnswerOptions.h in Headers */,
2887128883 07969DBA17D14151007FF842 /* JSRTCPeerConnection.h in Headers */,
2887228884 07969DB817D14151007FF842 /* JSRTCPeerConnectionIceEvent.h in Headers */,
 28885 E18C35441F71970C00FF632D /* WebArchiveResourceWebResourceHandler.h in Headers */,
2887328886 5E2C43741BCF0D750001E2BE /* JSRTCRtpParameters.h in Headers */,
2887428887 5E2C43721BCF0D750001E2BC /* JSRTCRtpReceiver.h in Headers */,
2887528888 5E2C43741BCF0D750001E2BC /* JSRTCRtpSender.h in Headers */,

3035830371 0806E57A12893045007CED32 /* SVGMatrix.h in Headers */,
3035930372 08CA3D4412894A3800FFF260 /* SVGMatrixTearOff.h in Headers */,
3036030373 7CE58D5C1DD7EC9C00128552 /* SVGMatrixValue.h in Headers */,
 30374 E18536841F4E481400FE091B /* WebArchiveResourceFromNSAttributedString.h in Headers */,
3036130375 B2227A4B0D00BF220071B782 /* SVGMetadataElement.h in Headers */,
3036230376 B2A1F2B10CEF0ABF00442F6A /* SVGMissingGlyphElement.h in Headers */,
3036330377 B2227A4E0D00BF220071B782 /* SVGMPathElement.h in Headers */,

3269832712 A6148A7812E41E3B0044A784 /* JSHTMLKeygenElement.cpp in Sources */,
3269932713 1AE2AB210A1CE63B00B42B25 /* JSHTMLLabelElement.cpp in Sources */,
3270032714 1AE2AB230A1CE63B00B42B25 /* JSHTMLLegendElement.cpp in Sources */,
 32715 E18C35431F71970100FF632D /* WebArchiveResourceWebResourceHandler.mm in Sources */,
3270132716 1AE2AB250A1CE63B00B42B25 /* JSHTMLLIElement.cpp in Sources */,
3270232717 A80E7B100A19D606007FB8C5 /* JSHTMLLinkElement.cpp in Sources */,
3270332718 1AE2AB270A1CE63B00B42B25 /* JSHTMLMapElement.cpp in Sources */,

3286532880 A1CC56781F4614A500A4555B /* JSPaymentRequest.cpp in Sources */,
3286632881 A1F600571F4765050077E83F /* JSPaymentRequestUpdateEvent.cpp in Sources */,
3286732882 A1F600591F4765050077E83F /* JSPaymentRequestUpdateEventInit.cpp in Sources */,
 32883 E18536851F50906100FE091B /* WebArchiveResourceFromNSAttributedString.mm in Sources */,
3286832884 A1CC567A1F4614AA00A4555B /* JSPaymentResponse.cpp in Sources */,
3286932885 A1CC567C1F4614AF00A4555B /* JSPaymentShippingOption.cpp in Sources */,
3287032886 A1CC567E1F4614B400A4555B /* JSPaymentShippingType.cpp in Sources */,
222122

Source/WebCore/editing/cocoa/WebArchiveResourceFromNSAttributedString.h

 1/*
 2 * Copyright (C) 2017 Apple Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 23 * THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#pragma once
 27
 28#import <wtf/RefPtr.h>
 29
 30namespace WebCore {
 31class ArchiveResource;
 32}
 33
 34@interface WebArchiveResourceFromNSAttributedString : NSObject {
 35@package
 36 RefPtr<WebCore::ArchiveResource> resource;
 37}
 38- (instancetype)initWithData:(NSData *)data URL:(NSURL *)URL MIMEType:(NSString *)MIMEType textEncodingName:(NSString *)textEncodingName frameName:(NSString *)frameName;
 39- (NSURL *)URL;
 40
 41@end
nonexistent

Source/WebCore/editing/cocoa/WebArchiveResourceFromNSAttributedString.mm

 1/*
 2 * Copyright (C) 2017 Apple Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 23 * THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#import "config.h"
 27#import "WebArchiveResourceFromNSAttributedString.h"
 28
 29#import "ArchiveResource.h"
 30
 31using namespace WebCore;
 32
 33@implementation WebArchiveResourceFromNSAttributedString
 34
 35- (instancetype)initWithData:(NSData *)data URL:(NSURL *)URL MIMEType:(NSString *)MIMEType textEncodingName:(NSString *)textEncodingName frameName:(NSString *)frameName
 36{
 37 if (!(self = [super init]))
 38 return nil;
 39
 40 if (!data || !URL || !MIMEType) {
 41 [self release];
 42 return nil;
 43 }
 44
 45 resource = ArchiveResource::create(SharedBuffer::create(adoptNS([data copy]).get()), URL, MIMEType, textEncodingName, frameName, nil);
 46 if (!resource) {
 47 [self release];
 48 return nil;
 49 }
 50
 51 return self;
 52}
 53
 54- (NSURL *)URL
 55{
 56 return resource->url();
 57}
 58
 59@end
nonexistent

Source/WebCore/editing/cocoa/WebArchiveResourceWebResourceHandler.h

 1/*
 2 * Copyright (C) 2017 Apple Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 23 * THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#pragma once
 27
 28@interface WebArchiveResourceWebResourceHandler : NSObject {
 29}
 30- (id)resourceForData:(NSData *)data URL:(NSURL *)url MIMEType:(NSString *)mimeType textEncodingName:(NSString *)textEncodingName frameName:(NSString *)frameName;
 31@end
nonexistent

Source/WebCore/editing/cocoa/WebArchiveResourceWebResourceHandler.mm

 1
 2/*
 3 * Copyright (C) 2017 Apple Inc. All rights reserved.
 4 *
 5 * Redistribution and use in source and binary forms, with or without
 6 * modification, are permitted provided that the following conditions
 7 * are met:
 8 * 1. Redistributions of source code must retain the above copyright
 9 * notice, this list of conditions and the following disclaimer.
 10 * 2. Redistributions in binary form must reproduce the above copyright
 11 * notice, this list of conditions and the following disclaimer in the
 12 * documentation and/or other materials provided with the distribution.
 13 *
 14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
 15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
 18 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 24 * THE POSSIBILITY OF SUCH DAMAGE.
 25 */
 26
 27#import "config.h"
 28#import "WebArchiveResourceWebResourceHandler.h"
 29
 30#import "WebArchiveResourceFromNSAttributedString.h"
 31
 32@implementation WebArchiveResourceWebResourceHandler
 33
 34- (id)resourceForData:(NSData *)data URL:(NSURL *)url MIMEType:(NSString *)mimeType textEncodingName:(NSString *)textEncodingName frameName:(NSString *)frameName
 35{
 36 return [[[WebArchiveResourceFromNSAttributedString alloc] initWithData:data URL:url MIMEType:mimeType textEncodingName:textEncodingName frameName:frameName] autorelease];
 37}
 38
 39@end
nonexistent

Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm

2323 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2424 */
2525
26 #include "config.h"
27 #include "WebContentReader.h"
 26#import "config.h"
 27#import "WebContentReader.h"
2828
29 #include "ArchiveResource.h"
30 #include "Blob.h"
31 #include "CachedResourceLoader.h"
32 #include "DOMURL.h"
33 #include "Document.h"
34 #include "DocumentFragment.h"
35 #include "DocumentLoader.h"
36 #include "Frame.h"
37 #include "FrameLoader.h"
38 #include "FrameLoaderClient.h"
39 #include "HTMLImageElement.h"
40 #include "LegacyWebArchive.h"
41 #include "Page.h"
42 #include "Settings.h"
43 #include "WebNSAttributedStringExtras.h"
44 #include "markup.h"
45 #include <pal/spi/cocoa/NSAttributedStringSPI.h>
46 #include <wtf/SoftLinking.h>
47 
48 #if PLATFORM(IOS)
 29#import "ArchiveResource.h"
 30#import "Blob.h"
 31#import "CachedResourceLoader.h"
 32#import "DOMURL.h"
 33#import "Document.h"
 34#import "DocumentFragment.h"
 35#import "DocumentLoader.h"
 36#import "Frame.h"
 37#import "FrameLoader.h"
 38#import "FrameLoaderClient.h"
 39#import "HTMLBodyElement.h"
 40#import "HTMLImageElement.h"
 41#import "LegacyWebArchive.h"
 42#import "Page.h"
 43#import "Settings.h"
 44#import "WebArchiveResourceFromNSAttributedString.h"
 45#import "WebArchiveResourceWebResourceHandler.h"
 46#import "WebNSAttributedStringExtras.h"
 47#import "markup.h"
 48#import <pal/spi/cocoa/NSAttributedStringSPI.h>
 49#import <wtf/SoftLinking.h>
 50
 51#if (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300)
 52@interface NSAttributedString ()
 53- (NSString *)_htmlDocumentFragmentString:(NSRange)range documentAttributes:(NSDictionary *)dict subresources:(NSArray **)subresources;
 54@end
 55#elif PLATFORM(IOS)
4956SOFT_LINK_PRIVATE_FRAMEWORK(WebKitLegacy)
50 #endif
51 
52 #if PLATFORM(MAC)
 57#elif PLATFORM(MAC)
5358SOFT_LINK_FRAMEWORK_IN_UMBRELLA(WebKit, WebKitLegacy)
5459#endif
5560
56 // FIXME: Get rid of this and change NSAttributedString conversion so it doesn't use WebKitLegacy (cf. rdar://problem/30597352).
 61#if (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED < 110000) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101300)
5762SOFT_LINK(WebKitLegacy, _WebCreateFragment, void, (WebCore::Document& document, NSAttributedString *string, WebCore::FragmentAndResources& result), (document, string, result))
 63#endif
5864
5965namespace WebCore {
6066
 67#if (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300)
 68
 69static NSDictionary *attributesForAttributedStringConversion()
 70{
 71 // This function needs to be kept in sync with identically named one in WebKitLegacy, which is used on older OS versions.
 72 RetainPtr<NSArray> excludedElements = adoptNS([[NSArray alloc] initWithObjects:
 73 // Omit style since we want style to be inline so the fragment can be easily inserted.
 74 @"style",
 75 // Omit xml so the result is not XHTML.
 76 @"xml",
 77 // Omit tags that will get stripped when converted to a fragment anyway.
 78 @"doctype", @"html", @"head", @"body",
 79 // Omit deprecated tags.
 80 @"applet", @"basefont", @"center", @"dir", @"font", @"menu", @"s", @"strike", @"u",
 81 // Omit object so no file attachments are part of the fragment.
 82 @"object", nil]);
 83
 84#if PLATFORM(IOS)
 85 static NSString * const NSExcludedElementsDocumentAttribute = @"ExcludedElements";
 86#endif
 87
 88 return @{
 89 NSExcludedElementsDocumentAttribute: excludedElements.get(),
 90 @"InterchangeNewline": @YES,
 91 @"CoalesceTabSpans": @YES,
 92 @"OutputBaseURL": [(NSURL *)URL::fakeURLWithRelativePart(emptyString()) retain], // The value needs +1 refcount, as NSAttributedString over-releases it.
 93 @"WebResourceHandler": [WebArchiveResourceWebResourceHandler new],
 94 };
 95}
 96
 97static FragmentAndResources createFragment(Frame& frame, NSAttributedString *string)
 98{
 99 FragmentAndResources result;
 100 Document& document = *frame.document();
 101
 102 NSArray *subresources = nil;
 103 NSString *fragmentString = [string _htmlDocumentFragmentString:NSMakeRange(0, [string length]) documentAttributes:attributesForAttributedStringConversion() subresources:&subresources];
 104 auto fragment = DocumentFragment::create(document);
 105 fragment->parseHTML(fragmentString, document.body(), DisallowScriptingAndPluginContent);
 106
 107 result.fragment = WTFMove(fragment);
 108 for (WebArchiveResourceFromNSAttributedString *resource in subresources)
 109 result.resources.append(*resource->resource);
 110
 111 return result;
 112}
 113
 114#else
 115
61116static FragmentAndResources createFragment(Frame& frame, NSAttributedString *string)
62117{
63  // FIXME: The algorithm to convert an attributed string into HTML should be implemented here in WebCore.
64  // For now, though, we call into WebKitLegacy, which in turn calls into AppKit/TextKit.
65118 FragmentAndResources result;
66119 _WebCreateFragment(*frame.document(), string, result);
67120 return result;
68121}
69122
 123#endif
 124
70125RefPtr<DocumentFragment> createFragmentAndAddResources(Frame& frame, NSAttributedString *string)
71126{
72127 if (!frame.page() || !frame.document())
222122

Source/WebCore/platform/URL.h

@@public:
7575 WEBCORE_EXPORT URL(const URL& base, const String& relative);
7676 URL(const URL& base, const String& relative, const TextEncoding&);
7777
78  static URL fakeURLWithRelativePart(const String&);
 78 WEBCORE_EXPORT static URL fakeURLWithRelativePart(const String&);
7979 WEBCORE_EXPORT static URL fileURLWithFileSystemPath(const String&);
8080
8181 String strippedForUseAsReferrer() const;
222122

Source/WebKitLegacy/mac/ChangeLog

 12017-09-19 Alexey Proskuryakov <ap@apple.com>
 2
 3 Layering violation in Editor::createFragment
 4 https://bugs.webkit.org/show_bug.cgi?id=176123
 5
 6 Reviewed by Darin Adler.
 7
 8 * Misc/WebNSURLExtras.h:
 9 * Misc/WebNSURLExtras.mm:
 10 * WebView/WebFrame.mm:
 11 * WebView/WebHTMLView.mm:
 12 Removed multiple copies of webkit-fake-url creation code, switching to URL::fakeURLWithRelativePart().
 13
 14 * WebCoreSupport/WebEditorClient.mm:
 15 (_WebCreateFragment): Added a stub implementation for older OSes. This is needed
 16 because WebKitLegacy.exp is not passed through preprocessor, so there is no sane
 17 way to avoid exporting the symbol just on newer OSes.
 18
1192017-09-18 Andy Estes <aestes@apple.com>
220
321 [Mac] Upstream miscellaneous WebKitSystemInterface functions
222217

Source/WebKitLegacy/mac/Misc/WebNSURLExtras.h

@@@interface NSURL (WebNSURLExtras)
7171
7272- (NSURL *)_webkit_URLFromURLOrSchemelessFileURL;
7373
74 #if TARGET_OS_IPHONE
75 // FIXME: This method name needs a prefix.
76 + (NSURL *)uniqueURLWithRelativePart:(NSString *)relativePart;
77 #endif
78 
7974@end
8075
8176@interface NSString (WebNSURLExtras)
222122

Source/WebKitLegacy/mac/Misc/WebNSURLExtras.mm

4646using namespace WebCore;
4747using namespace WTF;
4848
49 #if PLATFORM(IOS)
50 // Fake URL scheme.
51 #define WebDataProtocolScheme @"webkit-fake-url"
52 #endif
53 
5449#define URL_BYTES_BUFFER_LENGTH 2048
5550
5651@implementation NSURL (WebNSURLExtras)

@@- (NSURL *)_webkit_URLFromURLOrSchemeles
217212
218213 return [NSURL URLWithString:[@"file:" stringByAppendingString:[self absoluteString]]];
219214}
220 
221 #if PLATFORM(IOS)
222 + (NSURL *)uniqueURLWithRelativePart:(NSString *)relativePart
223 {
224  CFUUIDRef UUIDRef = CFUUIDCreate(kCFAllocatorDefault);
225  NSString *UUIDString = (NSString *)CFUUIDCreateString(kCFAllocatorDefault, UUIDRef);
226  CFRelease(UUIDRef);
227  NSURL *URL = [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@/%@", WebDataProtocolScheme, UUIDString, relativePart]];
228  CFRelease(UUIDString);
229 
230  return URL;
231 }
232 
233 #endif // PLATFORM(IOS)
234215@end
235216
236217@implementation NSString (WebNSURLExtras)
222122

Source/WebKitLegacy/mac/WebCoreSupport/WebEditorClient.mm

@@- (NSString *)languageForWordRange:(NSRa
101101@end
102102#endif
103103
 104#if (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED < 110000) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101300)
104105@interface NSAttributedString (WebNSAttributedStringDetails)
105106- (DOMDocumentFragment *)_documentFromRange:(NSRange)range document:(DOMDocument *)document documentAttributes:(NSDictionary *)attributes subresources:(NSArray **)subresources;
106107@end
 108#endif
107109
108110static WebViewInsertAction kit(EditorInsertAction action)
109111{

@@NSURL *WebEditorClient::canonicalizeURLS
435437 return URL;
436438}
437439
 440#if (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300)
 441
 442// 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.
 443// This stub is not used outside WebKit, but it's here so we won't get a linker error.
 444__attribute__((__noreturn__))
 445void _WebCreateFragment(Document&, NSAttributedString *, FragmentAndResources&)
 446{
 447 RELEASE_ASSERT_NOT_REACHED();
 448}
 449
 450#else
 451
438452static NSDictionary *attributesForAttributedStringConversion()
439453{
 454 // This function needs to be kept in sync with identically named one in WebCore, which is used on newer OS versions.
440455 NSArray *excludedElements = [[NSArray alloc] initWithObjects:
441456 // Omit style since we want style to be inline so the fragment can be easily inserted.
442457 @"style",

@@void _WebCreateFragment(Document& docume
471486 result.resources.append([resource _coreResource]);
472487}
473488
 489#endif
 490
474491void WebEditorClient::setInsertionPasteboard(const String& pasteboardName)
475492{
476493#if !PLATFORM(IOS)
222122

Source/WebKitLegacy/mac/WebView/WebFrame.mm

@@- (DOMDocumentFragment *)_documentFragme
22952295- (DOMDocumentFragment *)_documentFragmentForImageData:(NSData *)data withRelativeURLPart:(NSString *)relativeURLPart andMIMEType:(NSString *)mimeType
22962296{
22972297 WebResource *resource = [[WebResource alloc] initWithData:data
2298  URL:[NSURL uniqueURLWithRelativePart:relativeURLPart]
 2298 URL:URL::fakeURLWithRelativePart(relativeURLPart)
22992299 MIMEType:mimeType
23002300 textEncodingName:nil
23012301 frameName:nil];
222122

Source/WebKitLegacy/mac/WebView/WebHTMLView.mm

@@const float _WebHTMLViewPrintingMaximumS
784784#define MIN_BOLD_WEIGHT 7
785785#define STANDARD_BOLD_WEIGHT 9
786786
787 // Fake URL scheme.
788 #define WebDataProtocolScheme @"webkit-fake-url"
789 
790787#if PLATFORM(MAC)
791788
792789// <rdar://problem/4985524> References to WebCoreScrollView as a subview of a WebHTMLView may be present

@@+ (NSArray *)_excludedElementsForAttribu
11271124 return elements;
11281125}
11291126
1130 static NSURL *uniqueURLWithRelativePart(NSString *relativePart)
1131 {
1132  return [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@/%@", WebDataProtocolScheme, [NSUUID UUID], relativePart]];
1133 }
1134 
11351127- (DOMDocumentFragment *)_documentFragmentFromPasteboard:(NSPasteboard *)pasteboard
11361128 inContext:(DOMRange *)context
11371129 allowPlainText:(BOOL)allowPlainText

@@- (DOMDocumentFragment *)_web_documentFr
23302322{
23312323 auto filename = [imageMIMEType stringByReplacingOccurrencesOfString:@"/" withString:@"."];
23322324 auto resource = adoptNS([[WebResource alloc] initWithData:[pasteboard dataForType:pasteboardType]
2333  URL:uniqueURLWithRelativePart(filename) MIMEType:imageMIMEType textEncodingName:nil frameName:nil]);
 2325 URL:URL::fakeURLWithRelativePart(filename) MIMEType:imageMIMEType textEncodingName:nil frameName:nil]);
23342326 return [[self _dataSource] _documentFragmentWithImageResource:resource.get()];
23352327}
23362328

@@- (BOOL)_findString:(NSString *)string o
72987290
72997291@end
73007292
 7293#if (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED < 110000) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101300)
73017294// This is used by AppKit/TextKit and is implemented here in part so that WebDataProtocolScheme is only defined once.
73027295// FIXME: Really should have an @interface for this somewhere in this file or an include. Not sure why it compiles without one.
73037296@implementation NSURL (WebDataURL)
73047297
73057298+ (NSURL *)_web_uniqueWebDataURL
73067299{
7307  return [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@", WebDataProtocolScheme, [NSUUID UUID]]];
 7300 return URL::fakeURLWithRelativePart(emptyString());
73087301}
73097302
73107303@end
 7304#endif
73117305
73127306#if PLATFORM(MAC)
73137307
222122