Images shared to photos via action menu are padded with zeroes at the end
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 Mar 2015 22:05:59 +0000 (22:05 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 Mar 2015 22:05:59 +0000 (22:05 +0000)
https://bugs.webkit.org/show_bug.cgi?id=142985

Reviewed by Anders Carlsson.

* Shared/mac/ActionMenuHitTestResult.h:
* Shared/mac/ActionMenuHitTestResult.mm:
(WebKit::ActionMenuHitTestResult::encode):
(WebKit::ActionMenuHitTestResult::decode):
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::performActionMenuHitTestAtLocation):
Send the size of the image separately from the SharedMemory.
The SharedMemory's size can be rounded up, so we need to keep the original
size around in order to write the data to disk.

* UIProcess/mac/WKActionMenuController.mm:
(-[WKActionMenuController _hitTestResultImage]):
(-[WKActionMenuController _addImageToPhotos:]):
Use the image size instead of the SharedMemory size.

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

Source/WebKit2/ChangeLog
Source/WebKit2/Shared/mac/ActionMenuHitTestResult.h
Source/WebKit2/Shared/mac/ActionMenuHitTestResult.mm
Source/WebKit2/UIProcess/mac/WKActionMenuController.mm
Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm

index cdcae9a..fabdb42 100644 (file)
@@ -1,3 +1,25 @@
+2015-03-23  Tim Horton  <timothy_horton@apple.com>
+
+        Images shared to photos via action menu are padded with zeroes at the end
+        https://bugs.webkit.org/show_bug.cgi?id=142985
+
+        Reviewed by Anders Carlsson.
+
+        * Shared/mac/ActionMenuHitTestResult.h:
+        * Shared/mac/ActionMenuHitTestResult.mm:
+        (WebKit::ActionMenuHitTestResult::encode):
+        (WebKit::ActionMenuHitTestResult::decode):
+        * WebProcess/WebPage/mac/WebPageMac.mm:
+        (WebKit::WebPage::performActionMenuHitTestAtLocation):
+        Send the size of the image separately from the SharedMemory.
+        The SharedMemory's size can be rounded up, so we need to keep the original
+        size around in order to write the data to disk.
+
+        * UIProcess/mac/WKActionMenuController.mm:
+        (-[WKActionMenuController _hitTestResultImage]):
+        (-[WKActionMenuController _addImageToPhotos:]):
+        Use the image size instead of the SharedMemory size.
+
 2015-03-23  Enrica Casucci  <enrica@apple.com>
 
         [iOS] WebContent crash attempting to select text with a gesture at RenderObject::absoluteBoundingBoxRect.
index 5f342c2..a27a880 100644 (file)
@@ -54,6 +54,7 @@ struct ActionMenuHitTestResult {
 
     String lookupText;
     RefPtr<SharedMemory> imageSharedMemory;
+    uint64_t imageSize;
     String imageExtension;
 
     RetainPtr<DDActionContext> actionContext;
index d013652..64c0b2c 100644 (file)
@@ -45,9 +45,10 @@ void ActionMenuHitTestResult::encode(IPC::ArgumentEncoder& encoder) const
     encoder << imageExtension;
 
     SharedMemory::Handle imageHandle;
-    if (imageSharedMemory && imageSharedMemory->size())
+    if (imageSharedMemory && imageSharedMemory->data())
         imageSharedMemory->createHandle(imageHandle, SharedMemory::ReadOnly);
     encoder << imageHandle;
+    encoder << imageSize;
 
     bool hasActionContext = actionContext;
     encoder << hasActionContext;
@@ -98,6 +99,9 @@ bool ActionMenuHitTestResult::decode(IPC::ArgumentDecoder& decoder, ActionMenuHi
     if (!imageHandle.isNull())
         actionMenuHitTestResult.imageSharedMemory = SharedMemory::create(imageHandle, SharedMemory::ReadOnly);
 
+    if (!decoder.decode(actionMenuHitTestResult.imageSize))
+        return false;
+
     bool hasActionContext;
     if (!decoder.decode(hasActionContext))
         return false;
index c0a554d..fd7ec5a 100644 (file)
@@ -245,7 +245,7 @@ using namespace WebKit;
     if (!imageSharedMemory)
         return nil;
 
-    RetainPtr<NSImage> nsImage = adoptNS([[NSImage alloc] initWithData:[NSData dataWithBytes:imageSharedMemory->data() length:imageSharedMemory->size()]]);
+    RetainPtr<NSImage> nsImage = adoptNS([[NSImage alloc] initWithData:[NSData dataWithBytes:imageSharedMemory->data() length:_hitTestResult.imageSize]]);
     return nsImage.autorelease();
 }
 
@@ -335,10 +335,10 @@ static NSString *pathToPhotoOnDisk(NSString *suggestedFilename)
         return;
 
     RefPtr<SharedMemory> imageSharedMemory = _hitTestResult.imageSharedMemory;
-    if (!imageSharedMemory->size() || _hitTestResult.imageExtension.isEmpty())
+    if (!imageSharedMemory->data() || _hitTestResult.imageExtension.isEmpty() || !_hitTestResult.imageSize)
         return;
 
-    RetainPtr<NSData> imageData = adoptNS([[NSData alloc] initWithBytes:imageSharedMemory->data() length:imageSharedMemory->size()]);
+    RetainPtr<NSData> imageData = adoptNS([[NSData alloc] initWithBytes:imageSharedMemory->data() length:_hitTestResult.imageSize]);
     RetainPtr<NSString> suggestedFilename = [[[NSProcessInfo processInfo] globallyUniqueString] stringByAppendingPathExtension:_hitTestResult.imageExtension];
 
     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
index c13b638..d274e8d 100644 (file)
@@ -1062,6 +1062,7 @@ void WebPage::performActionMenuHitTestAtLocation(WebCore::FloatPoint locationInV
                 actionMenuResult.imageSharedMemory = SharedMemory::create(buffer->size());
                 memcpy(actionMenuResult.imageSharedMemory->data(), buffer->data(), buffer->size());
                 actionMenuResult.imageExtension = imageExtension;
+                actionMenuResult.imageSize = buffer->size();
             }
         }
     }