Diff
Modified: branches/safari-600.3-branch/Source/WebKit/mac/ChangeLog (176343 => 176344)
--- branches/safari-600.3-branch/Source/WebKit/mac/ChangeLog 2014-11-19 22:12:19 UTC (rev 176343)
+++ branches/safari-600.3-branch/Source/WebKit/mac/ChangeLog 2014-11-19 22:14:42 UTC (rev 176344)
@@ -1,5 +1,24 @@
2014-11-19 Dana Burkart <[email protected]>
+ Merge r176288. rdar://problem/18840382
+
+ 2014-11-18 Tim Horton <[email protected]>
+
+ Avoid re-encoding action menu image data
+ https://bugs.webkit.org/show_bug.cgi?id=138817
+ <rdar://problem/18840382>
+
+ Reviewed by Anders Carlsson.
+
+ * WebView/WebActionMenuController.mm:
+ (-[WebActionMenuController _defaultMenuItemsForImage:]):
+ (-[WebActionMenuController _addImageToPhotos:]):
+ Build a temporary filename from a UUID and the image's desired extension.
+ Use the Image's encoded data instead of re-encoding it with CGImageDestination.
+ Build an image menu only if we have an image, URL, data, and extension.
+
+2014-11-19 Dana Burkart <[email protected]>
+
Merge r176220. rdar://problem/18944893
2014-11-17 Beth Dakin <[email protected]>
Modified: branches/safari-600.3-branch/Source/WebKit/mac/WebView/WebActionMenuController.mm (176343 => 176344)
--- branches/safari-600.3-branch/Source/WebKit/mac/WebView/WebActionMenuController.mm 2014-11-19 22:12:19 UTC (rev 176343)
+++ branches/safari-600.3-branch/Source/WebKit/mac/WebView/WebActionMenuController.mm 2014-11-19 22:14:42 UTC (rev 176344)
@@ -38,9 +38,11 @@
#import "WebViewInternal.h"
#import <ImageIO/ImageIO.h>
#import <ImageKit/ImageKit.h>
+#import <WebCore/ArchiveResource.h>
#import <WebCore/DataDetection.h>
#import <WebCore/DataDetectorsSPI.h>
#import <WebCore/DictionaryLookup.h>
+#import <WebCore/DocumentLoader.h>
#import <WebCore/Editor.h>
#import <WebCore/Element.h>
#import <WebCore/EventHandler.h>
@@ -57,6 +59,7 @@
#import <WebCore/Range.h>
#import <WebCore/RenderElement.h>
#import <WebCore/RenderObject.h>
+#import <WebCore/SharedBuffer.h>
#import <WebCore/SoftLinking.h>
#import <WebCore/TextCheckerClient.h>
#import <WebKitSystemInterface.h>
@@ -329,11 +332,15 @@
RetainPtr<NSMenuItem> shareItem = [self _createActionMenuItemForTag:WebActionMenuItemTagShareImage];
if (Image* image = _hitTestResult.image()) {
- RetainPtr<CGImageRef> cgImage = image->getCGImageRef();
- RetainPtr<NSImage> nsImage = adoptNS([[NSImage alloc] initWithCGImage:cgImage.get() size:NSZeroSize]);
- _sharingServicePicker = adoptNS([[NSSharingServicePicker alloc] initWithItems:@[ nsImage.get() ]]);
- [_sharingServicePicker setDelegate:self];
- [shareItem setSubmenu:[_sharingServicePicker menu]];
+ RefPtr<SharedBuffer> buffer = image->data();
+ if (buffer) {
+ RetainPtr<NSData> nsData = [NSData dataWithBytes:buffer->data() length:buffer->size()];
+ RetainPtr<NSImage> nsImage = adoptNS([[NSImage alloc] initWithData:nsData.get()]);
+ _sharingServicePicker = adoptNS([[NSSharingServicePicker alloc] initWithItems:@[ nsImage.get() ]]);
+ [_sharingServicePicker setDelegate:self];
+ [shareItem setSubmenu:[_sharingServicePicker menu]];
+ } else
+ [shareItem setEnabled:NO];
}
return @[ copyImageItem.get(), addToPhotosItem.get(), saveToDownloadsItem.get(), shareItem.get() ];
@@ -405,19 +412,23 @@
if (!image)
return;
- RetainPtr<CGImageRef> cgImage = image->getCGImageRef();
+ String imageExtension = image->filenameExtension();
+ if (imageExtension.isEmpty())
+ return;
+ RefPtr<SharedBuffer> buffer = image->data();
+ if (!buffer)
+ return;
+ RetainPtr<NSData> nsData = [NSData dataWithBytes:buffer->data() length:buffer->size()];
+ RetainPtr<NSString> suggestedFilename = [[[NSProcessInfo processInfo] globallyUniqueString] stringByAppendingPathExtension:imageExtension];
+
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- NSString * const suggestedFilename = @"image.jpg";
-
- NSString *filePath = pathToPhotoOnDisk(suggestedFilename);
+ NSString *filePath = pathToPhotoOnDisk(suggestedFilename.get());
if (!filePath)
return;
NSURL *fileURL = [NSURL fileURLWithPath:filePath];
- auto dest = adoptCF(CGImageDestinationCreateWithURL((CFURLRef)fileURL, kUTTypeJPEG, 1, nullptr));
- CGImageDestinationAddImage(dest.get(), cgImage.get(), nullptr);
- CGImageDestinationFinalize(dest.get());
+ [nsData writeToURL:fileURL atomically:NO];
dispatch_async(dispatch_get_main_queue(), ^{
// This API provides no way to report failure, but if 18420778 is fixed so that it does, we should handle this.
@@ -828,7 +839,8 @@
return [self _defaultMenuItemsForMailtoLink];
}
- if (_hitTestResult.image() && !_hitTestResult.absoluteImageURL().isEmpty()) {
+ Image* image = _hitTestResult.image();
+ if (image && !_hitTestResult.absoluteImageURL().isEmpty() && !image->filenameExtension().isEmpty() && image->data() && !image->data()->isEmpty()) {
_type = WebActionMenuImage;
return [self _defaultMenuItemsForImage];
}
Modified: branches/safari-600.3-branch/Source/WebKit2/ChangeLog (176343 => 176344)
--- branches/safari-600.3-branch/Source/WebKit2/ChangeLog 2014-11-19 22:12:19 UTC (rev 176343)
+++ branches/safari-600.3-branch/Source/WebKit2/ChangeLog 2014-11-19 22:14:42 UTC (rev 176344)
@@ -1,5 +1,38 @@
2014-11-19 Dana Burkart <[email protected]>
+ Merge r176288. rdar://problem/18840382
+
+ 2014-11-18 Tim Horton <[email protected]>
+
+ Avoid re-encoding action menu image data
+ https://bugs.webkit.org/show_bug.cgi?id=138817
+ <rdar://problem/18840382>
+
+ Reviewed by Anders Carlsson.
+
+ * Shared/mac/ActionMenuHitTestResult.h:
+ * Shared/mac/ActionMenuHitTestResult.mm:
+ (WebKit::ActionMenuHitTestResult::encode):
+ (WebKit::ActionMenuHitTestResult::decode):
+ Store and encode a SharedMemory with the raw encoded image data,
+ instead of re-painting the image into a ShareableBitmap.
+
+ * UIProcess/mac/WKActionMenuController.mm:
+ (-[WKActionMenuController _hitTestResultImage]):
+ (-[WKActionMenuController _defaultMenuItemsForImage]):
+ (-[WKActionMenuController _copyImage:]):
+ (-[WKActionMenuController _addImageToPhotos:]):
+ (-[WKActionMenuController _defaultMenuItems]):
+ (-[WKActionMenuController _canAddMediaToPhotos]): Deleted.
+ Build a temporary filename from a UUID and the image's desired extension.
+ Use the Image's encoded data instead of re-encoding it with CGImageDestination.
+ Build an image menu only if we have an image, URL, data, and extension.
+
+ * WebProcess/WebPage/mac/WebPageMac.mm:
+ (WebKit::WebPage::performActionMenuHitTestAtLocation):
+
+2014-11-19 Dana Burkart <[email protected]>
+
Merge r176238. rdar://problem/18990674
2014-11-17 Conrad Shultz <[email protected]>
Modified: branches/safari-600.3-branch/Source/WebKit2/Shared/mac/ActionMenuHitTestResult.h (176343 => 176344)
--- branches/safari-600.3-branch/Source/WebKit2/Shared/mac/ActionMenuHitTestResult.h 2014-11-19 22:12:19 UTC (rev 176343)
+++ branches/safari-600.3-branch/Source/WebKit2/Shared/mac/ActionMenuHitTestResult.h 2014-11-19 22:14:42 UTC (rev 176344)
@@ -26,7 +26,9 @@
#ifndef ActionMenuHitTestResult_h
#define ActionMenuHitTestResult_h
+#include "DataReference.h"
#include "ShareableBitmap.h"
+#include "SharedMemory.h"
#include "TextIndicator.h"
#include "WebHitTestResult.h"
#include <WebCore/FloatRect.h>
@@ -50,7 +52,8 @@
WebHitTestResult::Data hitTestResult;
String lookupText;
- RefPtr<ShareableBitmap> image;
+ RefPtr<SharedMemory> imageSharedMemory;
+ String imageExtension;
RetainPtr<DDActionContext> actionContext;
WebCore::FloatRect detectedDataBoundingBox;
Modified: branches/safari-600.3-branch/Source/WebKit2/Shared/mac/ActionMenuHitTestResult.mm (176343 => 176344)
--- branches/safari-600.3-branch/Source/WebKit2/Shared/mac/ActionMenuHitTestResult.mm 2014-11-19 22:12:19 UTC (rev 176343)
+++ branches/safari-600.3-branch/Source/WebKit2/Shared/mac/ActionMenuHitTestResult.mm 2014-11-19 22:14:42 UTC (rev 176344)
@@ -42,15 +42,13 @@
encoder << hitTestLocationInViewCooordinates;
encoder << hitTestResult;
encoder << lookupText;
+ encoder << imageExtension;
- ShareableBitmap::Handle handle;
+ SharedMemory::Handle imageHandle;
+ if (imageSharedMemory && imageSharedMemory->size())
+ imageSharedMemory->createHandle(imageHandle, SharedMemory::ReadOnly);
+ encoder << imageHandle;
- // FIXME: We should consider sharing the raw original resource data so that metadata and whatnot are preserved.
- if (image)
- image->createHandle(handle, SharedMemory::ReadOnly);
-
- encoder << handle;
-
bool hasActionContext = actionContext;
encoder << hasActionContext;
if (hasActionContext) {
@@ -82,13 +80,16 @@
if (!decoder.decode(actionMenuHitTestResult.lookupText))
return false;
- ShareableBitmap::Handle handle;
- if (!decoder.decode(handle))
+ if (!decoder.decode(actionMenuHitTestResult.imageExtension))
return false;
- if (!handle.isNull())
- actionMenuHitTestResult.image = ShareableBitmap::create(handle, SharedMemory::ReadOnly);
+ SharedMemory::Handle imageHandle;
+ if (!decoder.decode(imageHandle))
+ return false;
+ if (!imageHandle.isNull())
+ actionMenuHitTestResult.imageSharedMemory = SharedMemory::create(imageHandle, SharedMemory::ReadOnly);
+
bool hasActionContext;
if (!decoder.decode(hasActionContext))
return false;
Modified: branches/safari-600.3-branch/Source/WebKit2/UIProcess/mac/WKActionMenuController.mm (176343 => 176344)
--- branches/safari-600.3-branch/Source/WebKit2/UIProcess/mac/WKActionMenuController.mm 2014-11-19 22:12:19 UTC (rev 176343)
+++ branches/safari-600.3-branch/Source/WebKit2/UIProcess/mac/WKActionMenuController.mm 2014-11-19 22:14:42 UTC (rev 176344)
@@ -458,6 +458,16 @@
#pragma mark Image actions
+- (NSImage *)_hitTestResultImage
+{
+ RefPtr<SharedMemory> imageSharedMemory = _hitTestResult.imageSharedMemory;
+ if (!imageSharedMemory)
+ return nil;
+
+ RetainPtr<NSImage> nsImage = adoptNS([[NSImage alloc] initWithData:[NSData dataWithBytes:imageSharedMemory->data() length:imageSharedMemory->size()]]);
+ return nsImage.autorelease();
+}
+
- (NSArray *)_defaultMenuItemsForImage
{
RetainPtr<NSMenuItem> copyImageItem = [self _createActionMenuItemForTag:kWKContextActionItemTagCopyImage];
@@ -469,10 +479,8 @@
RetainPtr<NSMenuItem> saveToDownloadsItem = [self _createActionMenuItemForTag:kWKContextActionItemTagSaveImageToDownloads];
RetainPtr<NSMenuItem> shareItem = [self _createActionMenuItemForTag:kWKContextActionItemTagShareImage];
- if (RefPtr<ShareableBitmap> bitmap = _hitTestResult.image) {
- RetainPtr<CGImageRef> image = bitmap->makeCGImage();
- RetainPtr<NSImage> nsImage = adoptNS([[NSImage alloc] initWithCGImage:image.get() size:NSZeroSize]);
- _sharingServicePicker = adoptNS([[NSSharingServicePicker alloc] initWithItems:@[ nsImage.get() ]]);
+ if (RetainPtr<NSImage> image = [self _hitTestResultImage]) {
+ _sharingServicePicker = adoptNS([[NSSharingServicePicker alloc] initWithItems:@[ image.get() ]]);
[_sharingServicePicker setDelegate:self];
[shareItem setSubmenu:[_sharingServicePicker menu]];
}
@@ -482,14 +490,12 @@
- (void)_copyImage:(id)sender
{
- RefPtr<ShareableBitmap> bitmap = _hitTestResult.image;
- if (!bitmap)
+ RetainPtr<NSImage> image = [self _hitTestResultImage];
+ if (!image)
return;
- RetainPtr<CGImageRef> image = bitmap->makeCGImage();
- RetainPtr<NSImage> nsImage = adoptNS([[NSImage alloc] initWithCGImage:image.get() size:NSZeroSize]);
[[NSPasteboard generalPasteboard] clearContents];
- [[NSPasteboard generalPasteboard] writeObjects:@[ nsImage.get() ]];
+ [[NSPasteboard generalPasteboard] writeObjects:@[ image.get() ]];
}
- (void)_saveImageToDownloads:(id)sender
@@ -553,22 +559,20 @@
if (![self _canAddMediaToPhotos])
return;
- RefPtr<ShareableBitmap> bitmap = _hitTestResult.image;
- if (!bitmap)
+ RefPtr<SharedMemory> imageSharedMemory = _hitTestResult.imageSharedMemory;
+ if (!imageSharedMemory->size() || _hitTestResult.imageExtension.isEmpty())
return;
- RetainPtr<CGImageRef> image = bitmap->makeCGImage();
+ RetainPtr<NSData> imageData = adoptNS([[NSData alloc] initWithBytes:imageSharedMemory->data() length:imageSharedMemory->size()]);
+ RetainPtr<NSString> suggestedFilename = [[[NSProcessInfo processInfo] globallyUniqueString] stringByAppendingPathExtension:_hitTestResult.imageExtension];
+
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- NSString * const suggestedFilename = @"image.jpg";
-
- NSString *filePath = pathToPhotoOnDisk(suggestedFilename);
+ NSString *filePath = pathToPhotoOnDisk(suggestedFilename.get());
if (!filePath)
return;
NSURL *fileURL = [NSURL fileURLWithPath:filePath];
- auto dest = adoptCF(CGImageDestinationCreateWithURL((CFURLRef)fileURL, kUTTypeJPEG, 1, nullptr));
- CGImageDestinationAddImage(dest.get(), image.get(), nullptr);
- CGImageDestinationFinalize(dest.get());
+ [imageData writeToURL:fileURL atomically:NO];
dispatch_async(dispatch_get_main_queue(), ^{
// This API provides no way to report failure, but if 18420778 is fixed so that it does, we should handle this.
@@ -909,7 +913,7 @@
return [self _defaultMenuItemsForVideo];
}
- if (!hitTestResult->absoluteImageURL().isEmpty() && _hitTestResult.image) {
+ if (!hitTestResult->absoluteImageURL().isEmpty() && _hitTestResult.imageSharedMemory && !_hitTestResult.imageExtension.isEmpty()) {
_type = kWKActionMenuImage;
return [self _defaultMenuItemsForImage];
}
Modified: branches/safari-600.3-branch/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm (176343 => 176344)
--- branches/safari-600.3-branch/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm 2014-11-19 22:12:19 UTC (rev 176343)
+++ branches/safari-600.3-branch/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm 2014-11-19 22:14:42 UTC (rev 176344)
@@ -1004,9 +1004,13 @@
m_lastActionMenuHitTestResult = hitTestResult;
if (Image* image = hitTestResult.image()) {
- actionMenuResult.image = ShareableBitmap::createShareable(IntSize(image->size()), ShareableBitmap::SupportsAlpha);
- if (actionMenuResult.image)
- actionMenuResult.image->createGraphicsContext()->drawImage(image, ColorSpaceDeviceRGB, IntPoint());
+ RefPtr<SharedBuffer> buffer = image->data();
+ String imageExtension = image->filenameExtension();
+ if (!imageExtension.isEmpty() && buffer) {
+ actionMenuResult.imageSharedMemory = SharedMemory::create(buffer->size());
+ memcpy(actionMenuResult.imageSharedMemory->data(), buffer->data(), buffer->size());
+ actionMenuResult.imageExtension = imageExtension;
+ }
}
bool pageOverlayDidOverrideDataDetectors = false;