Source/WebCore: "Attempt to insert nil value " exception when calling attributed...
authoradele@apple.com <adele@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Mar 2012 21:05:32 +0000 (21:05 +0000)
committeradele@apple.com <adele@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Mar 2012 21:05:32 +0000 (21:05 +0000)
https://bugs.webkit.org/show_bug.cgi?id=81630
<rdar://problem/10650660>

Reviewed by Alexey Proskuryakov.

Test: TestWebKitAPI/Tests/mac/AttributedString.mm

If content is using a custom font, then the platform font will be nil and needs to be nil checked.

* platform/mac/HTMLConverter.mm: (+[WebHTMLConverter editingAttributedStringFromRange:]):

Tools: "Attempt to insert nil value " exception when calling attributed string APIs on content with a custom font
https://bugs.webkit.org/show_bug.cgi?id=81630
<rdar://problem/10650660>

Reviewed by Alexey Proskuryakov.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/mac/Ahem.ttf: Added.
* TestWebKitAPI/Tests/mac/AttributedString.mm: Added.
(-[AttributedStringTest webView:didFinishLoadForFrame:]):
(TestWebKitAPI):
(TestWebKitAPI::didFinishLoadForFrame):
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/mac/attributedStringCustomFont.html: Added.

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

Source/WebCore/ChangeLog
Source/WebCore/platform/mac/HTMLConverter.mm
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/mac/Ahem.ttf [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/mac/AttributedString.mm [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/mac/attributedStringCustomFont.html [new file with mode: 0644]

index 0e7ecb0..bfd731a 100644 (file)
@@ -1,3 +1,17 @@
+2012-03-20  Adele Peterson  <adele@apple.com>
+
+        "Attempt to insert nil value " exception when calling attributed string APIs on content with a custom font
+        https://bugs.webkit.org/show_bug.cgi?id=81630
+        <rdar://problem/10650660> 
+
+        Reviewed by Alexey Proskuryakov. 
+
+        Test: TestWebKitAPI/Tests/mac/AttributedString.mm 
+
+        If content is using a custom font, then the platform font will be nil and needs to be nil checked.
+
+        * platform/mac/HTMLConverter.mm: (+[WebHTMLConverter editingAttributedStringFromRange:]):
+
 2012-03-20  Julien Chaffraix  <jchaffraix@webkit.org>
 
         Make distributeExtraLogicalHeightToRows return the consumed logical height
index 47d5fe0..22db81c 100644 (file)
@@ -1695,8 +1695,8 @@ static NSInteger _colCompare(id block1, id block2, void *)
         RenderStyle* style = renderer->style();
         if (style->textDecorationsInEffect() & UNDERLINE)
             [attrs.get() setObject:[NSNumber numberWithInteger:NSUnderlineStyleSingle] forKey:NSUnderlineStyleAttributeName];
-        NSFont *font = style->font().primaryFont()->getNSFont();
-        [attrs.get() setObject:font forKey:NSFontAttributeName];
+        if (NSFont *font = style->font().primaryFont()->getNSFont())
+            [attrs.get() setObject:font forKey:NSFontAttributeName];
         if (style->visitedDependentColor(CSSPropertyColor).alpha())
             [attrs.get() setObject:nsColor(style->visitedDependentColor(CSSPropertyColor)) forKey:NSForegroundColorAttributeName];
         else
index 8d14345..8f2d5f1 100644 (file)
@@ -1,3 +1,20 @@
+2012-03-20  Adele Peterson  <adele@apple.com>
+
+        "Attempt to insert nil value " exception when calling attributed string APIs on content with a custom font
+        https://bugs.webkit.org/show_bug.cgi?id=81630
+        <rdar://problem/10650660>
+
+        Reviewed by Alexey Proskuryakov.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/mac/Ahem.ttf: Added.
+        * TestWebKitAPI/Tests/mac/AttributedString.mm: Added.
+        (-[AttributedStringTest webView:didFinishLoadForFrame:]):
+        (TestWebKitAPI):
+        (TestWebKitAPI::didFinishLoadForFrame):
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/Tests/mac/attributedStringCustomFont.html: Added.
+
 2012-03-20  Eric Seidel  <eric@webkit.org>
 
         Add link on queues.webkit.org to kov's fancy queue-depth graph
index 955a9b3..54df878 100644 (file)
@@ -62,6 +62,9 @@
                93F7E86C14DC8E4D00C84A99 /* NewFirstVisuallyNonEmptyLayoutFrames.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93F7E86B14DC8E4D00C84A99 /* NewFirstVisuallyNonEmptyLayoutFrames.cpp */; };
                93F7E86F14DC8E5C00C84A99 /* NewFirstVisuallyNonEmptyLayoutFrames_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93F7E86E14DC8E5B00C84A99 /* NewFirstVisuallyNonEmptyLayoutFrames_Bundle.cpp */; };
                A7A966DB140ECCC8005EF9B4 /* CheckedArithmeticOperations.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7A966DA140ECCC8005EF9B4 /* CheckedArithmeticOperations.cpp */; };
+               B55F11A01516834F00915916 /* AttributedString.mm in Sources */ = {isa = PBXBuildFile; fileRef = B55F119F1516834F00915916 /* AttributedString.mm */; };
+               B55F11B71517D03300915916 /* attributedStringCustomFont.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = B55F11B01517A2C400915916 /* attributedStringCustomFont.html */; };
+               B55F11BE15191A0600915916 /* Ahem.ttf in Copy Resources */ = {isa = PBXBuildFile; fileRef = B55F11B9151916E600915916 /* Ahem.ttf */; };
                BC029B181486AD6400817DA9 /* RetainPtr.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC029B161486AD6400817DA9 /* RetainPtr.cpp */; };
                BC029B1C1486B25900817DA9 /* RetainPtr.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC029B1B1486B25900817DA9 /* RetainPtr.mm */; };
                BC131885117114B600B69727 /* PlatformUtilitiesMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC131884117114B600B69727 /* PlatformUtilitiesMac.mm */; };
                        dstPath = TestWebKitAPI.resources;
                        dstSubfolderSpec = 7;
                        files = (
+                               B55F11BE15191A0600915916 /* Ahem.ttf in Copy Resources */,
+                               B55F11B71517D03300915916 /* attributedStringCustomFont.html in Copy Resources */,
                                5142B2731517C8C800C32B19 /* ContextMenuCanCopyURL.html in Copy Resources */,
                                517E7E04151119C100D0B008 /* MemoryCachePruneWithinResourceLoadDelegate.html in Copy Resources */,
                                379028B914FAC24C007E6B43 /* acceptsFirstMouse.html in Copy Resources */,
                93F7E86B14DC8E4D00C84A99 /* NewFirstVisuallyNonEmptyLayoutFrames.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NewFirstVisuallyNonEmptyLayoutFrames.cpp; sourceTree = "<group>"; };
                93F7E86E14DC8E5B00C84A99 /* NewFirstVisuallyNonEmptyLayoutFrames_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NewFirstVisuallyNonEmptyLayoutFrames_Bundle.cpp; sourceTree = "<group>"; };
                A7A966DA140ECCC8005EF9B4 /* CheckedArithmeticOperations.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CheckedArithmeticOperations.cpp; path = WTF/CheckedArithmeticOperations.cpp; sourceTree = "<group>"; };
+               B55F119F1516834F00915916 /* AttributedString.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AttributedString.mm; sourceTree = "<group>"; };
+               B55F11B01517A2C400915916 /* attributedStringCustomFont.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = attributedStringCustomFont.html; sourceTree = "<group>"; };
+               B55F11B9151916E600915916 /* Ahem.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = Ahem.ttf; sourceTree = "<group>"; };
                BC029B161486AD6400817DA9 /* RetainPtr.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RetainPtr.cpp; sourceTree = "<group>"; };
                BC029B1B1486B25900817DA9 /* RetainPtr.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = RetainPtr.mm; path = WTF/ns/RetainPtr.mm; sourceTree = "<group>"; };
                BC131883117114A800B69727 /* PlatformUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformUtilities.h; sourceTree = "<group>"; };
                        children = (
                                C07E6CB013FD737C0038B22B /* Resources */,
                                379028B514FABD92007E6B43 /* AcceptsFirstMouse.mm */,
+                               B55F119F1516834F00915916 /* AttributedString.mm */,
                                5142B2701517C88B00C32B19 /* ContextMenuCanCopyURL.mm */,
                                37DC678B140D7C5000ABCCDB /* DOMRangeOfString.mm */,
                                C07E6CAE13FD67650038B22B /* DynamicDeviceScaleFactor.mm */,
                C07E6CB013FD737C0038B22B /* Resources */ = {
                        isa = PBXGroup;
                        children = (
+                               B55F11B9151916E600915916 /* Ahem.ttf */,
+                               B55F11B01517A2C400915916 /* attributedStringCustomFont.html */,
                                379028B814FABE49007E6B43 /* acceptsFirstMouse.html */,
                                5142B2721517C89100C32B19 /* ContextMenuCanCopyURL.html */,
                                37DC678F140D7D3A00ABCCDB /* DOMRangeOfString.html */,
                                E490296814E2E3A4002BEDD1 /* TypingStyleCrash.mm in Sources */,
                                379028B614FABD92007E6B43 /* AcceptsFirstMouse.mm in Sources */,
                                3776BC63150946BC0043A66D /* DeviceScaleFactorInDashboardRegions.mm in Sources */,
+                               B55F11A01516834F00915916 /* AttributedString.mm in Sources */,
                                517E7DFC15110EA600D0B008 /* MemoryCachePruneWithinResourceLoadDelegate.mm in Sources */,
                                51FBBB4D1513D4E900822738 /* WebViewCanPasteURL.mm in Sources */,
                                5142B2711517C88B00C32B19 /* ContextMenuCanCopyURL.mm in Sources */,
diff --git a/Tools/TestWebKitAPI/Tests/mac/Ahem.ttf b/Tools/TestWebKitAPI/Tests/mac/Ahem.ttf
new file mode 100644 (file)
index 0000000..ac81cb0
Binary files /dev/null and b/Tools/TestWebKitAPI/Tests/mac/Ahem.ttf differ
diff --git a/Tools/TestWebKitAPI/Tests/mac/AttributedString.mm b/Tools/TestWebKitAPI/Tests/mac/AttributedString.mm
new file mode 100644 (file)
index 0000000..a9e1b54
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2012 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.
+ */
+
+#include "config.h"
+#include "PlatformUtilities.h"
+#include "PlatformWebView.h"
+#include <wtf/RetainPtr.h>
+
+
+@interface AttributedStringTest : NSObject {
+}
+@end
+
+static bool didFinishLoad;
+
+@implementation AttributedStringTest
+
+- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
+{
+    didFinishLoad = true;
+}
+@end
+
+namespace TestWebKitAPI {
+
+static void didFinishLoadForFrame(WKPageRef, WKFrameRef, WKTypeRef, const void*)
+{
+    didFinishLoad = true;
+}
+
+TEST(WebKit1, AttributedStringTest)
+{
+    RetainPtr<WebView> webView(AdoptNS, [[WebView alloc] initWithFrame:NSMakeRect(0, 0, 120, 200) frameName:nil groupName:nil]);
+    RetainPtr<AttributedStringTest> testController(AdoptNS, [AttributedStringTest new]);
+    
+    webView.get().frameLoadDelegate = testController.get();
+    [[webView.get() mainFrame] loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"attributedStringCustomFont" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]];
+    
+    Util::run(&didFinishLoad);
+    didFinishLoad = false;
+        
+    NSAttributedString *attrString = [(NSView <NSTextInput> *)[[[webView.get() mainFrame] frameView] documentView] attributedSubstringFromRange:NSMakeRange(0, 5)];
+
+    EXPECT_TRUE([[attrString string] isEqual:@"Lorem"]);
+}
+
+TEST(WebKit2, AttributedStringTest)
+{
+    WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate());
+    PlatformWebView webView(context.get());
+    
+    WKPageLoaderClient loaderClient;
+    memset(&loaderClient, 0, sizeof(loaderClient));
+    loaderClient.version = 0;
+    loaderClient.didFinishLoadForFrame = didFinishLoadForFrame;
+    WKPageSetPageLoaderClient(webView.page(), &loaderClient);
+    
+    WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("attributedStringCustomFont", "html")).get());
+
+    Util::run(&didFinishLoad);
+    didFinishLoad = false;
+    
+    NSRange range = NSMakeRange(0, 5);
+    NSRange actualRange;
+    NSAttributedString *attrString = [webView.platformView() attributedSubstringForProposedRange:range actualRange:&actualRange];
+    EXPECT_TRUE([[attrString string] isEqual:@"Lorem"]);
+}
+
+    
+} // namespace TestWebKitAPI
diff --git a/Tools/TestWebKitAPI/Tests/mac/attributedStringCustomFont.html b/Tools/TestWebKitAPI/Tests/mac/attributedStringCustomFont.html
new file mode 100644 (file)
index 0000000..1e6b90a
--- /dev/null
@@ -0,0 +1,15 @@
+<html>
+    <head>
+        <style>
+            @font-face {
+                font-family: customFont;
+                src: url(Ahem.ttf);
+            }
+        </style>
+    </head>
+    <body contenteditable style="font-family: customFont; font-size: 48px;">Lorem Ipsum
+        <script>
+            document.body.focus();
+        </script>
+    </body>
+</html>