Thrown ObjC exception when right clicking on <img> containing mp4 link
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Sep 2017 17:53:47 +0000 (17:53 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Sep 2017 17:53:47 +0000 (17:53 +0000)
https://bugs.webkit.org/show_bug.cgi?id=177370

Reviewed by Darin Adler.

Source/WebKit:

Creating a NSImage from mp4 data will fail and return nil; do a nil-check before attempting
to put the results into a NSMutableArray.

* UIProcess/mac/WebContextMenuProxyMac.mm:
(WebKit::WebContextMenuProxyMac::createShareMenuItem):

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit/mac/ContextMenuImgWithVideo.html: Added.
* TestWebKitAPI/Tests/WebKit/mac/ContextMenuImgWithVideo.mm: Added.
(-[ContextMenuImgWithVideoDelegate _webView:contextMenu:forElement:]):
(TestWebKitAPI::TEST):

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

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.mm
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKit/mac/ContextMenuImgWithVideo.html [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/WebKit/mac/ContextMenuImgWithVideo.mm [new file with mode: 0644]

index b3be734..14429b4 100644 (file)
@@ -1,3 +1,16 @@
+2017-09-26  Jer Noble  <jer.noble@apple.com>
+
+        Thrown ObjC exception when right clicking on <img> containing mp4 link
+        https://bugs.webkit.org/show_bug.cgi?id=177370
+
+        Reviewed by Darin Adler.
+
+        Creating a NSImage from mp4 data will fail and return nil; do a nil-check before attempting
+        to put the results into a NSMutableArray.
+
+        * UIProcess/mac/WebContextMenuProxyMac.mm:
+        (WebKit::WebContextMenuProxyMac::createShareMenuItem):
+
 2017-09-26  Brian Burg  <bburg@apple.com>
 
         Web Automation: add commands to get and set user permissions for pages in an automation session
index 013b515..e9296a1 100644 (file)
@@ -283,8 +283,8 @@ RetainPtr<NSMenuItem> WebContextMenuProxyMac::createShareMenuItem()
     }
 
     if (hitTestData.imageSharedMemory && hitTestData.imageSize) {
-        auto image = adoptNS([[NSImage alloc] initWithData:[NSData dataWithBytes:(unsigned char*)hitTestData.imageSharedMemory->data() length:hitTestData.imageSize]]);
-        [items addObject:image.get()];
+        if (auto image = adoptNS([[NSImage alloc] initWithData:[NSData dataWithBytes:(unsigned char*)hitTestData.imageSharedMemory->data() length:hitTestData.imageSize]]))
+            [items addObject:image.get()];
     }
 
     if (!m_context.selectedText().isEmpty())
index 8f7da43..28dfea5 100644 (file)
@@ -1,3 +1,16 @@
+2017-09-26  Jer Noble  <jer.noble@apple.com>
+
+        Thrown ObjC exception when right clicking on <img> containing mp4 link
+        https://bugs.webkit.org/show_bug.cgi?id=177370
+
+        Reviewed by Darin Adler.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit/mac/ContextMenuImgWithVideo.html: Added.
+        * TestWebKitAPI/Tests/WebKit/mac/ContextMenuImgWithVideo.mm: Added.
+        (-[ContextMenuImgWithVideoDelegate _webView:contextMenu:forElement:]):
+        (TestWebKitAPI::TEST):
+
 2017-09-26  Per Arne Vollan  <pvollan@apple.com>
 
         [Win] 'webkit-patch clean' is failing on bot.
index 7b7d19a..c6fa2cc 100644 (file)
                C9C60E651E53A9DC006DA181 /* autoplay-check-frame.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C9C60E631E53A9BA006DA181 /* autoplay-check-frame.html */; };
                C9C60E661E53A9DC006DA181 /* autoplay-check-in-iframe.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C9C60E641E53A9BA006DA181 /* autoplay-check-in-iframe.html */; };
                C9E6DD351EA97D0800DD78AA /* FirstResponderSuppression.mm in Sources */ = {isa = PBXBuildFile; fileRef = C9E6DD311EA972D800DD78AA /* FirstResponderSuppression.mm */; };
+               CD0BD0A61F79924D001AB2CF /* ContextMenuImgWithVideo.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD0BD0A51F799220001AB2CF /* ContextMenuImgWithVideo.mm */; };
+               CD0BD0A81F79982D001AB2CF /* ContextMenuImgWithVideo.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CD0BD0A71F7997C2001AB2CF /* ContextMenuImgWithVideo.html */; };
                CD321B041E3A85FA00EB21C8 /* video-with-muted-audio-and-webaudio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CD321B031E3A84B700EB21C8 /* video-with-muted-audio-and-webaudio.html */; };
                CD59F53419E9110D00CF1835 /* file-with-mse.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CD59F53219E910AA00CF1835 /* file-with-mse.html */; };
                CD59F53519E9110D00CF1835 /* test-mse.mp4 in Copy Resources */ = {isa = PBXBuildFile; fileRef = CD59F53319E910BC00CF1835 /* test-mse.mp4 */; };
                                F4A32ECB1F0643370047C544 /* contenteditable-in-iframe.html in Copy Resources */,
                                A16F66BA1C40EB4F00BD4D24 /* ContentFiltering.html in Copy Resources */,
                                5142B2731517C8C800C32B19 /* ContextMenuCanCopyURL.html in Copy Resources */,
+                               CD0BD0A81F79982D001AB2CF /* ContextMenuImgWithVideo.html in Copy Resources */,
                                5C2936961D5C00ED00DEAB1E /* CookieMessage.html in Copy Resources */,
                                7AEAD4811E20122700416EFE /* CrossPartitionFileSchemeAccess.html in Copy Resources */,
                                F4AB578A1F65165400DB0DA1 /* custom-draggable-div.html in Copy Resources */,
                C9C60E631E53A9BA006DA181 /* autoplay-check-frame.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "autoplay-check-frame.html"; sourceTree = "<group>"; };
                C9C60E641E53A9BA006DA181 /* autoplay-check-in-iframe.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "autoplay-check-in-iframe.html"; sourceTree = "<group>"; };
                C9E6DD311EA972D800DD78AA /* FirstResponderSuppression.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = FirstResponderSuppression.mm; sourceTree = "<group>"; };
+               CD0BD0A51F799220001AB2CF /* ContextMenuImgWithVideo.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ContextMenuImgWithVideo.mm; sourceTree = "<group>"; };
+               CD0BD0A71F7997C2001AB2CF /* ContextMenuImgWithVideo.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = ContextMenuImgWithVideo.html; sourceTree = "<group>"; };
                CD225C071C45A69200140761 /* ParsedContentRange.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ParsedContentRange.cpp; sourceTree = "<group>"; };
                CD321B031E3A84B700EB21C8 /* video-with-muted-audio-and-webaudio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "video-with-muted-audio-and-webaudio.html"; sourceTree = "<group>"; };
                CD5393C71757BA9700C07123 /* MD5.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MD5.cpp; sourceTree = "<group>"; };
                        children = (
                                9BD423991E04BD9800200395 /* AttributedSubstringForProposedRangeWithImage.mm */,
                                8349D3C11DB96DDA004A9F65 /* ContextMenuDownload.mm */,
+                               CD0BD0A71F7997C2001AB2CF /* ContextMenuImgWithVideo.html */,
+                               CD0BD0A51F799220001AB2CF /* ContextMenuImgWithVideo.mm */,
                                BCAA485714A044D40088FAC4 /* EditorCommands.mm */,
                                C0C5D3BC14598B6F00A802A6 /* GetBackingScaleFactor.mm */,
                                C0C5D3BD14598B6F00A802A6 /* GetBackingScaleFactor_Bundle.mm */,
                                7CCE7EB81A411A7E00447C4C /* ContextMenuCanCopyURL.mm in Sources */,
                                37FB72971DB2E82F00E41BE4 /* ContextMenuDefaultItemsHaveTags.mm in Sources */,
                                8349D3C21DB96DDE004A9F65 /* ContextMenuDownload.mm in Sources */,
+                               CD0BD0A61F79924D001AB2CF /* ContextMenuImgWithVideo.mm in Sources */,
                                5C2936931D5BF70D00DEAB1E /* CookieAcceptPolicy.mm in Sources */,
                                51D1249B1E785425002B2820 /* CookieManager.cpp in Sources */,
                                9999108B1F393C96008AD455 /* Copying.mm in Sources */,
diff --git a/Tools/TestWebKitAPI/Tests/WebKit/mac/ContextMenuImgWithVideo.html b/Tools/TestWebKitAPI/Tests/WebKit/mac/ContextMenuImgWithVideo.html
new file mode 100644 (file)
index 0000000..4cc4087
--- /dev/null
@@ -0,0 +1 @@
+<img src=test.mp4 width=200 height=200 />
diff --git a/Tools/TestWebKitAPI/Tests/WebKit/mac/ContextMenuImgWithVideo.mm b/Tools/TestWebKitAPI/Tests/WebKit/mac/ContextMenuImgWithVideo.mm
new file mode 100644 (file)
index 0000000..de16762
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * 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"
+
+#if WK_API_ENABLED
+
+#import "PlatformUtilities.h"
+#import "Test.h"
+#import "TestWKWebView.h"
+#import <Carbon/Carbon.h>
+#import <WebKit/WKUIDelegatePrivate.h>
+#import <wtf/mac/AppKitCompatibilityDeclarations.h>
+
+static bool contextMenuShown = false;
+
+@interface ContextMenuImgWithVideoDelegate : NSObject <WKUIDelegate>
+@end
+
+@implementation ContextMenuImgWithVideoDelegate
+- (NSMenu*)_webView:(WKWebView*)webView contextMenu:(NSMenu*)menu forElement:(_WKContextMenuElementInfo*)element
+{
+    contextMenuShown = true;
+    return nil;
+}
+@end
+
+namespace TestWebKitAPI {
+
+TEST(WebKit, ContextMenuImgWithVideo)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600)]);
+    webView.get().UIDelegate = [[[ContextMenuImgWithVideoDelegate alloc] init] autorelease];
+    [webView synchronouslyLoadTestPageNamed:@"ContextMenuImgWithVideo"];
+
+    NSWindow* window = [webView window];
+    NSEvent* event = [NSEvent mouseEventWithType:NSEventTypeRightMouseDown
+        location:NSMakePoint(100, window.frame.size.height - 100)
+        modifierFlags:0
+        timestamp:GetCurrentEventTime()
+        windowNumber:[window windowNumber]
+        context:[NSGraphicsContext currentContext]
+        eventNumber:0
+        clickCount:0
+        pressure:0.0];
+
+    NSView* subView = [webView hitTest:[event locationInWindow]];
+    if (!subView)
+        return;
+
+    contextMenuShown = false;
+    [subView mouseDown:event];
+    Util::run(&contextMenuShown);
+}
+
+} // namespace TestWebKitAPI
+
+#endif // WK_API_ENABLED