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 cdcae9a540b5437e2d0c03b4fd4330cf10421385..fabdb42d9055513d13ddb5b4c64d8e262ecd653f 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 5f342c2d87b449b5a37f802f8fc857fca6150ce5..a27a880fd13a31ced1393ade143fb47c390746b7 100644 (file)
@@ -54,6 +54,7 @@ struct ActionMenuHitTestResult {
 
     String lookupText;
     RefPtr<SharedMemory> imageSharedMemory;
+    uint64_t imageSize;
     String imageExtension;
 
     RetainPtr<DDActionContext> actionContext;
index d013652b9fe2a728ef81b2ec534a7b6541f2a77d..64c0b2c749a39de6fd57e20783f54101a3513c82 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 c0a554d4d6b9f097bcc0ea3ea25c35630dc4d157..fd7ec5a6111eb2493758f761569b7793bb42c025 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 c13b6386a90d666b85ee663797084235ecf7db7a..d274e8d58e30bba1ab4af8092f68ee4588e96818 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();
             }
         }
     }