Changeset 222239 in webkit
- Timestamp:
- Sep 19, 2017 6:20:29 PM (7 years ago)
- Location:
- trunk/Source
- Files:
-
- 4 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r222238 r222239 1 2017-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 * 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 1 27 2017-09-19 Youenn Fablet <youenn@apple.com> 2 28 -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r222225 r222239 6718 6718 E18256900EF2B02D00933242 /* JSWorkerGlobalScope.h in Headers */ = {isa = PBXBuildFile; fileRef = E182568E0EF2B02D00933242 /* JSWorkerGlobalScope.h */; }; 6719 6719 E18258AC0EF3CD7000933242 /* JSWorkerGlobalScopeCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E18258AB0EF3CD7000933242 /* JSWorkerGlobalScopeCustom.cpp */; }; 6720 E18536841F4E481400FE091B /* WebArchiveResourceFromNSAttributedString.h in Headers */ = {isa = PBXBuildFile; fileRef = E18536811F4E472700FE091B /* WebArchiveResourceFromNSAttributedString.h */; }; 6721 E18536851F50906100FE091B /* WebArchiveResourceFromNSAttributedString.mm in Sources */ = {isa = PBXBuildFile; fileRef = E18536821F4E472700FE091B /* WebArchiveResourceFromNSAttributedString.mm */; }; 6722 E18C35431F71970100FF632D /* WebArchiveResourceWebResourceHandler.mm in Sources */ = {isa = PBXBuildFile; fileRef = E18C35421F71970100FF632D /* WebArchiveResourceWebResourceHandler.mm */; }; 6723 E18C35441F71970C00FF632D /* WebArchiveResourceWebResourceHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = E18C35411F7196CD00FF632D /* WebArchiveResourceWebResourceHandler.h */; }; 6720 6724 E18DF33518AAF12C00773E59 /* SerializedCryptoKeyWrap.h in Headers */ = {isa = PBXBuildFile; fileRef = E18DF33418AAF12C00773E59 /* SerializedCryptoKeyWrap.h */; settings = {ATTRIBUTES = (Private, ); }; }; 6721 6725 E18DF33818AAF14D00773E59 /* SerializedCryptoKeyWrapMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = E18DF33618AAF14D00773E59 /* SerializedCryptoKeyWrapMac.mm */; }; … … 15529 15533 E182568E0EF2B02D00933242 /* JSWorkerGlobalScope.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSWorkerGlobalScope.h; sourceTree = "<group>"; }; 15530 15534 E18258AB0EF3CD7000933242 /* JSWorkerGlobalScopeCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSWorkerGlobalScopeCustom.cpp; sourceTree = "<group>"; }; 15535 E18536811F4E472700FE091B /* WebArchiveResourceFromNSAttributedString.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebArchiveResourceFromNSAttributedString.h; sourceTree = "<group>"; }; 15536 E18536821F4E472700FE091B /* WebArchiveResourceFromNSAttributedString.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WebArchiveResourceFromNSAttributedString.mm; sourceTree = "<group>"; }; 15537 E18C35411F7196CD00FF632D /* WebArchiveResourceWebResourceHandler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebArchiveResourceWebResourceHandler.h; sourceTree = "<group>"; }; 15538 E18C35421F71970100FF632D /* WebArchiveResourceWebResourceHandler.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WebArchiveResourceWebResourceHandler.mm; sourceTree = "<group>"; }; 15531 15539 E18DF33418AAF12C00773E59 /* SerializedCryptoKeyWrap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SerializedCryptoKeyWrap.h; sourceTree = "<group>"; }; 15532 15540 E18DF33618AAF14D00773E59 /* SerializedCryptoKeyWrapMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SerializedCryptoKeyWrapMac.mm; sourceTree = "<group>"; }; … … 20269 20277 7C3E510818DF8F3500C112F7 /* HTMLConverter.h */, 20270 20278 7C3E510918DF8F3500C112F7 /* HTMLConverter.mm */, 20279 E18536811F4E472700FE091B /* WebArchiveResourceFromNSAttributedString.h */, 20280 E18536821F4E472700FE091B /* WebArchiveResourceFromNSAttributedString.mm */, 20281 E18C35411F7196CD00FF632D /* WebArchiveResourceWebResourceHandler.h */, 20282 E18C35421F71970100FF632D /* WebArchiveResourceWebResourceHandler.mm */, 20271 20283 9B9299B01F6796A4006723C2 /* WebContentReaderCocoa.mm */, 20272 20284 ); … … 28885 28897 07969DBA17D14151007FF842 /* JSRTCPeerConnection.h in Headers */, 28886 28898 07969DB817D14151007FF842 /* JSRTCPeerConnectionIceEvent.h in Headers */, 28899 E18C35441F71970C00FF632D /* WebArchiveResourceWebResourceHandler.h in Headers */, 28887 28900 5E2C43741BCF0D750001E2BE /* JSRTCRtpParameters.h in Headers */, 28888 28901 5E2C43721BCF0D750001E2BC /* JSRTCRtpReceiver.h in Headers */, … … 30373 30386 08CA3D4412894A3800FFF260 /* SVGMatrixTearOff.h in Headers */, 30374 30387 7CE58D5C1DD7EC9C00128552 /* SVGMatrixValue.h in Headers */, 30388 E18536841F4E481400FE091B /* WebArchiveResourceFromNSAttributedString.h in Headers */, 30375 30389 B2227A4B0D00BF220071B782 /* SVGMetadataElement.h in Headers */, 30376 30390 B2A1F2B10CEF0ABF00442F6A /* SVGMissingGlyphElement.h in Headers */, … … 32715 32729 1AE2AB210A1CE63B00B42B25 /* JSHTMLLabelElement.cpp in Sources */, 32716 32730 1AE2AB230A1CE63B00B42B25 /* JSHTMLLegendElement.cpp in Sources */, 32731 E18C35431F71970100FF632D /* WebArchiveResourceWebResourceHandler.mm in Sources */, 32717 32732 1AE2AB250A1CE63B00B42B25 /* JSHTMLLIElement.cpp in Sources */, 32718 32733 A80E7B100A19D606007FB8C5 /* JSHTMLLinkElement.cpp in Sources */, … … 32882 32897 A1F600571F4765050077E83F /* JSPaymentRequestUpdateEvent.cpp in Sources */, 32883 32898 A1F600591F4765050077E83F /* JSPaymentRequestUpdateEventInit.cpp in Sources */, 32899 E18536851F50906100FE091B /* WebArchiveResourceFromNSAttributedString.mm in Sources */, 32884 32900 A1CC567A1F4614AA00A4555B /* JSPaymentResponse.cpp in Sources */, 32885 32901 A1CC567C1F4614AF00A4555B /* JSPaymentShippingOption.cpp in Sources */, -
trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm
r222119 r222239 24 24 */ 25 25 26 #include "config.h" 27 #include "WebContentReader.h" 28 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> 26 #import "config.h" 27 #import "WebContentReader.h" 28 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) 56 SOFT_LINK_PRIVATE_FRAMEWORK(WebKitLegacy) 57 #elif PLATFORM(MAC) 58 SOFT_LINK_FRAMEWORK_IN_UMBRELLA(WebKit, WebKitLegacy) 59 #endif 60 61 #if (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED < 110000) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101300) 62 SOFT_LINK(WebKitLegacy, _WebCreateFragment, void, (WebCore::Document& document, NSAttributedString *string, WebCore::FragmentAndResources& result), (document, string, result)) 63 #endif 64 65 namespace WebCore { 66 67 #if (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300) 68 69 static 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]); 47 83 48 84 #if PLATFORM(IOS) 49 SOFT_LINK_PRIVATE_FRAMEWORK(WebKitLegacy) 50 #endif 51 52 #if PLATFORM(MAC) 53 SOFT_LINK_FRAMEWORK_IN_UMBRELLA(WebKit, WebKitLegacy) 54 #endif 55 56 // FIXME: Get rid of this and change NSAttributedString conversion so it doesn't use WebKitLegacy (cf. rdar://problem/30597352).57 SOFT_LINK(WebKitLegacy, _WebCreateFragment, void, (WebCore::Document& document, NSAttributedString *string, WebCore::FragmentAndResources& result), (document, string, result)) 58 59 namespace WebCore { 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 } 60 96 61 97 static FragmentAndResources createFragment(Frame& frame, NSAttributedString *string) 62 98 { 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. 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 116 static FragmentAndResources createFragment(Frame& frame, NSAttributedString *string) 117 { 65 118 FragmentAndResources result; 66 119 _WebCreateFragment(*frame.document(), string, result); 67 120 return result; 68 121 } 122 123 #endif 69 124 70 125 RefPtr<DocumentFragment> createFragmentAndAddResources(Frame& frame, NSAttributedString *string) -
trunk/Source/WebCore/platform/URL.h
r222093 r222239 76 76 URL(const URL& base, const String& relative, const TextEncoding&); 77 77 78 static URL fakeURLWithRelativePart(const String&);78 WEBCORE_EXPORT static URL fakeURLWithRelativePart(const String&); 79 79 WEBCORE_EXPORT static URL fileURLWithFileSystemPath(const String&); 80 80 -
trunk/Source/WebKitLegacy/mac/ChangeLog
r222228 r222239 1 2017-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 1 19 2017-09-19 Ryosuke Niwa <rniwa@webkit.org> 2 20 -
trunk/Source/WebKitLegacy/mac/Misc/WebNSURLExtras.h
r201763 r222239 72 72 - (NSURL *)_webkit_URLFromURLOrSchemelessFileURL; 73 73 74 #if TARGET_OS_IPHONE75 // FIXME: This method name needs a prefix.76 + (NSURL *)uniqueURLWithRelativePart:(NSString *)relativePart;77 #endif78 79 74 @end 80 75 -
trunk/Source/WebKitLegacy/mac/Misc/WebNSURLExtras.mm
r201763 r222239 47 47 using namespace WTF; 48 48 49 #if PLATFORM(IOS)50 // Fake URL scheme.51 #define WebDataProtocolScheme @"webkit-fake-url"52 #endif53 54 49 #define URL_BYTES_BUFFER_LENGTH 2048 55 50 … … 218 213 return [NSURL URLWithString:[@"file:" stringByAppendingString:[self absoluteString]]]; 219 214 } 220 221 #if PLATFORM(IOS)222 + (NSURL *)uniqueURLWithRelativePart:(NSString *)relativePart223 {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)234 215 @end 235 216 -
trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebEditorClient.mm
r221960 r222239 102 102 #endif 103 103 104 #if (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED < 110000) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101300) 104 105 @interface NSAttributedString (WebNSAttributedStringDetails) 105 106 - (DOMDocumentFragment *)_documentFromRange:(NSRange)range document:(DOMDocument *)document documentAttributes:(NSDictionary *)attributes subresources:(NSArray **)subresources; 106 107 @end 108 #endif 107 109 108 110 static WebViewInsertAction kit(EditorInsertAction action) … … 436 438 } 437 439 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__)) 445 void _WebCreateFragment(Document&, NSAttributedString *, FragmentAndResources&) 446 { 447 RELEASE_ASSERT_NOT_REACHED(); 448 } 449 450 #else 451 438 452 static NSDictionary *attributesForAttributedStringConversion() 439 453 { 454 // This function needs to be kept in sync with identically named one in WebCore, which is used on newer OS versions. 440 455 NSArray *excludedElements = [[NSArray alloc] initWithObjects: 441 456 // Omit style since we want style to be inline so the fragment can be easily inserted. … … 471 486 result.resources.append([resource _coreResource]); 472 487 } 488 489 #endif 473 490 474 491 void WebEditorClient::setInsertionPasteboard(const String& pasteboardName) -
trunk/Source/WebKitLegacy/mac/WebView/WebFrame.mm
r221559 r222239 2296 2296 { 2297 2297 WebResource *resource = [[WebResource alloc] initWithData:data 2298 URL: [NSURL uniqueURLWithRelativePart:relativeURLPart]2298 URL:URL::fakeURLWithRelativePart(relativeURLPart) 2299 2299 MIMEType:mimeType 2300 2300 textEncodingName:nil -
trunk/Source/WebKitLegacy/mac/WebView/WebHTMLView.mm
r222150 r222239 787 787 #define STANDARD_BOLD_WEIGHT 9 788 788 789 // Fake URL scheme.790 #define WebDataProtocolScheme @"webkit-fake-url"791 792 789 #if PLATFORM(MAC) 793 790 … … 1130 1127 } 1131 1128 1132 static NSURL *uniqueURLWithRelativePart(NSString *relativePart)1133 {1134 return [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@/%@", WebDataProtocolScheme, [NSUUID UUID], relativePart]];1135 }1136 1137 1129 - (DOMDocumentFragment *)_documentFragmentFromPasteboard:(NSPasteboard *)pasteboard 1138 1130 inContext:(DOMRange *)context … … 2333 2325 auto filename = [imageMIMEType stringByReplacingOccurrencesOfString:@"/" withString:@"."]; 2334 2326 auto resource = adoptNS([[WebResource alloc] initWithData:[pasteboard dataForType:pasteboardType] 2335 URL: uniqueURLWithRelativePart(filename) MIMEType:imageMIMEType textEncodingName:nil frameName:nil]);2327 URL:URL::fakeURLWithRelativePart(filename) MIMEType:imageMIMEType textEncodingName:nil frameName:nil]); 2336 2328 return [[self _dataSource] _documentFragmentWithImageResource:resource.get()]; 2337 2329 } … … 7301 7293 @end 7302 7294 7295 #if (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED < 110000) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101300) 7303 7296 // This is used by AppKit/TextKit and is implemented here in part so that WebDataProtocolScheme is only defined once. 7304 7297 // FIXME: Really should have an @interface for this somewhere in this file or an include. Not sure why it compiles without one. … … 7307 7300 + (NSURL *)_web_uniqueWebDataURL 7308 7301 { 7309 return [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@", WebDataProtocolScheme, [NSUUID UUID]]];7302 return URL::fakeURLWithRelativePart(emptyString()); 7310 7303 } 7311 7304 7312 7305 @end 7306 #endif 7313 7307 7314 7308 #if PLATFORM(MAC)
Note: See TracChangeset
for help on using the changeset viewer.