Allow the UIDelegate to customize an image preview
authorbdakin@apple.com <bdakin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 2 Jul 2015 22:10:40 +0000 (22:10 +0000)
committerbdakin@apple.com <bdakin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 2 Jul 2015 22:10:40 +0000 (22:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=146557
-and corresponding-
rdar://problem/21657424

Reviewed by Tim Horton.

Source/WebCore:

Add WEBCORE_EXPORT to use this in WK2.
* loader/cache/CachedResource.h:
(WebCore::CachedResource::url):

Source/WebKit2:

Add imageURL to InteractionInformationAtPosition.
* Shared/InteractionInformationAtPosition.cpp:
(WebKit::InteractionInformationAtPosition::encode):
(WebKit::InteractionInformationAtPosition::decode):
* Shared/InteractionInformationAtPosition.h:

Two new delegate methods.
* UIProcess/API/Cocoa/WKUIDelegatePrivate.h:

Call the delegate methods at the appropriate time.
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView previewViewControllerForPosition:inSourceView:]):
(-[WKContentView commitPreviewViewController:]):

Include the imageURL in InteractionInformationAtPosition.
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::getPositionInformation):

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

Source/WebCore/ChangeLog
Source/WebCore/loader/cache/CachedResource.h
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/InteractionInformationAtPosition.cpp
Source/WebKit2/Shared/InteractionInformationAtPosition.h
Source/WebKit2/UIProcess/API/Cocoa/WKUIDelegatePrivate.h
Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm
Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm

index a9f4e32..f2cba9b 100644 (file)
@@ -1,3 +1,16 @@
+2015-07-02  Beth Dakin  <bdakin@apple.com>
+
+        Allow the UIDelegate to customize an image preview
+        https://bugs.webkit.org/show_bug.cgi?id=146557
+        -and corresponding-
+        rdar://problem/21657424
+
+        Reviewed by Tim Horton.
+
+        Add WEBCORE_EXPORT to use this in WK2.
+        * loader/cache/CachedResource.h:
+        (WebCore::CachedResource::url):
+
 2015-07-02  Brady Eidson  <beidson@apple.com>
 
         Add preference to disable all http-equiv.
 2015-07-02  Brady Eidson  <beidson@apple.com>
 
         Add preference to disable all http-equiv.
index c28219c..11d030e 100644 (file)
@@ -109,7 +109,7 @@ public:
     virtual bool shouldIgnoreHTTPStatusCodeErrors() const { return false; }
 
     ResourceRequest& resourceRequest() { return m_resourceRequest; }
     virtual bool shouldIgnoreHTTPStatusCodeErrors() const { return false; }
 
     ResourceRequest& resourceRequest() { return m_resourceRequest; }
-    const URL& url() const { return m_resourceRequest.url();}
+    WEBCORE_EXPORT const URL& url() const { return m_resourceRequest.url();}
 #if ENABLE(CACHE_PARTITIONING)
     const String& cachePartition() const { return m_resourceRequest.cachePartition(); }
 #endif
 #if ENABLE(CACHE_PARTITIONING)
     const String& cachePartition() const { return m_resourceRequest.cachePartition(); }
 #endif
index a546407..070dc2a 100644 (file)
@@ -1,3 +1,30 @@
+2015-07-02  Beth Dakin  <bdakin@apple.com>
+
+        Allow the UIDelegate to customize an image preview
+        https://bugs.webkit.org/show_bug.cgi?id=146557
+        -and corresponding-
+        rdar://problem/21657424
+
+        Reviewed by Tim Horton.
+
+        Add imageURL to InteractionInformationAtPosition.
+        * Shared/InteractionInformationAtPosition.cpp:
+        (WebKit::InteractionInformationAtPosition::encode):
+        (WebKit::InteractionInformationAtPosition::decode):
+        * Shared/InteractionInformationAtPosition.h:
+
+        Two new delegate methods.
+        * UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
+
+        Call the delegate methods at the appropriate time.
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView previewViewControllerForPosition:inSourceView:]):
+        (-[WKContentView commitPreviewViewController:]):
+
+        Include the imageURL in InteractionInformationAtPosition.
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::getPositionInformation):
+
 2015-07-02  Anders Carlsson  <andersca@apple.com>
 
         Instead of requiring ToT UIKIt, check that UI_WEB_TOUCH_EVENT_HAS_IS_POTENTIAL_TAP is defined to 1
 2015-07-02  Anders Carlsson  <andersca@apple.com>
 
         Instead of requiring ToT UIKIt, check that UI_WEB_TOUCH_EVENT_HAS_IS_POTENTIAL_TAP is defined to 1
index 825220b..3996721 100644 (file)
@@ -41,6 +41,7 @@ void InteractionInformationAtPosition::encode(IPC::ArgumentEncoder& encoder) con
     encoder << touchCalloutEnabled;
     encoder << clickableElementName;
     encoder << url;
     encoder << touchCalloutEnabled;
     encoder << clickableElementName;
     encoder << url;
+    encoder << imageURL;
     encoder << title;
     encoder << bounds;
 
     encoder << title;
     encoder << bounds;
 
@@ -73,6 +74,9 @@ bool InteractionInformationAtPosition::decode(IPC::ArgumentDecoder& decoder, Int
     if (!decoder.decode(result.url))
         return false;
 
     if (!decoder.decode(result.url))
         return false;
 
+    if (!decoder.decode(result.imageURL))
+        return false;
+
     if (!decoder.decode(result.title))
         return false;
 
     if (!decoder.decode(result.title))
         return false;
 
index 8901135..2c151bb 100644 (file)
@@ -54,6 +54,7 @@ struct InteractionInformationAtPosition {
     bool touchCalloutEnabled;
     String clickableElementName;
     String url;
     bool touchCalloutEnabled;
     String clickableElementName;
     String url;
+    String imageURL;
     String title;
     WebCore::IntRect bounds;
     RefPtr<ShareableBitmap> image;
     String title;
     WebCore::IntRect bounds;
     RefPtr<ShareableBitmap> image;
index b8a12c5..54a56fc 100644 (file)
@@ -56,6 +56,8 @@
 - (BOOL)_webView:(WKWebView *)webView shouldRequestGeolocationAuthorizationForURL:(NSURL *)url isMainFrame:(BOOL)isMainFrame mainFrameURL:(NSURL *)mainFrameURL;
 - (UIViewController *)_webView:(WKWebView *)webView previewViewControllerForURL:(NSURL *)url;
 - (void)_webView:(WKWebView *)webView commitPreviewedViewController:(UIViewController *)previewedViewController;
 - (BOOL)_webView:(WKWebView *)webView shouldRequestGeolocationAuthorizationForURL:(NSURL *)url isMainFrame:(BOOL)isMainFrame mainFrameURL:(NSURL *)mainFrameURL;
 - (UIViewController *)_webView:(WKWebView *)webView previewViewControllerForURL:(NSURL *)url;
 - (void)_webView:(WKWebView *)webView commitPreviewedViewController:(UIViewController *)previewedViewController;
+- (void)_webView:(WKWebView *)webView willPreviewImageWithURL:(NSURL *)imageURL WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
+- (void)_webView:(WKWebView *)webView commitPreviewedImageWithURL:(NSURL *)imageURL WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
 - (void)_webView:(WKWebView *)webView didDismissPreviewViewController:(UIViewController *)previewedViewController;
 #endif
 
 - (void)_webView:(WKWebView *)webView didDismissPreviewViewController:(UIViewController *)previewedViewController;
 #endif
 
index c8b6885..c63052c 100644 (file)
@@ -3213,10 +3213,11 @@ static bool isAssistableInputType(InputType type)
         canShowLinkPreview = NO;
     }
 
         canShowLinkPreview = NO;
     }
 
+    id <WKUIDelegatePrivate> uiDelegate = static_cast<id <WKUIDelegatePrivate>>([_webView UIDelegate]);
+
     if (canShowLinkPreview) {
         _previewType = PreviewElementType::Link;
         NSURL *targetURL = [NSURL _web_URLWithWTFString:_positionInformation.url];
     if (canShowLinkPreview) {
         _previewType = PreviewElementType::Link;
         NSURL *targetURL = [NSURL _web_URLWithWTFString:_positionInformation.url];
-        id<WKUIDelegatePrivate> uiDelegate = static_cast<id <WKUIDelegatePrivate>>([_webView UIDelegate]);
         if ([uiDelegate respondsToSelector:@selector(_webView:previewViewControllerForURL:)]) {
             _highlightLongPressCanClick = NO;
             return [uiDelegate _webView:_webView previewViewControllerForURL:targetURL];
         if ([uiDelegate respondsToSelector:@selector(_webView:previewViewControllerForURL:)]) {
             _highlightLongPressCanClick = NO;
             return [uiDelegate _webView:_webView previewViewControllerForURL:targetURL];
@@ -3232,7 +3233,12 @@ static bool isAssistableInputType(InputType type)
     }
 
     if (canShowImagePreview) {
     }
 
     if (canShowImagePreview) {
+        String absoluteImageURL = _positionInformation.imageURL;
+        if (absoluteImageURL.isEmpty() || !(WebCore::protocolIsInHTTPFamily(absoluteImageURL) || WebCore::protocolIs(absoluteImageURL, "data")))
+            return nil;
         _previewType = PreviewElementType::Image;
         _previewType = PreviewElementType::Image;
+        if ([uiDelegate respondsToSelector:@selector(_webView:willPreviewImageWithURL:)])
+            [uiDelegate _webView:_webView willPreviewImageWithURL:[NSURL _web_URLWithWTFString:_positionInformation.imageURL]];
         return [[[WKImagePreviewViewController alloc] initWithCGImage:_positionInformation.image->makeCGImageCopy()] autorelease];
     }
 
         return [[[WKImagePreviewViewController alloc] initWithCGImage:_positionInformation.image->makeCGImageCopy()] autorelease];
     }
 
@@ -3241,10 +3247,18 @@ static bool isAssistableInputType(InputType type)
 
 - (void)commitPreviewViewController:(UIViewController *)viewController
 {
 
 - (void)commitPreviewViewController:(UIViewController *)viewController
 {
-    if (_previewType != PreviewElementType::Link)
+    id <WKUIDelegatePrivate> uiDelegate = static_cast<id <WKUIDelegatePrivate>>([_webView UIDelegate]);
+    if (_previewType == PreviewElementType::Image) {
+        if ([uiDelegate respondsToSelector:@selector(_webView:commitPreviewedImageWithURL:)]) {
+            String absoluteImageURL = _positionInformation.imageURL;
+            if (absoluteImageURL.isEmpty() || !(WebCore::protocolIsInHTTPFamily(absoluteImageURL) || WebCore::protocolIs(absoluteImageURL, "data")))
+                return;
+            [uiDelegate _webView:_webView commitPreviewedImageWithURL:[NSURL _web_URLWithWTFString:absoluteImageURL]];
+            return;
+        }
         return;
         return;
+    }
 
 
-    id<WKUIDelegatePrivate> uiDelegate = static_cast<id <WKUIDelegatePrivate>>([_webView UIDelegate]);
     if ([uiDelegate respondsToSelector:@selector(_webView:commitPreviewedViewController:)]) {
         [uiDelegate _webView:_webView commitPreviewedViewController:viewController];
         return;
     if ([uiDelegate respondsToSelector:@selector(_webView:commitPreviewedViewController:)]) {
         [uiDelegate _webView:_webView commitPreviewedViewController:viewController];
         return;
index b38d9ec..23de83e 100644 (file)
@@ -2141,6 +2141,7 @@ void WebPage::getPositionInformation(const IntPoint& point, InteractionInformati
                 } else if (element->renderer() && element->renderer()->isRenderImage()) {
                     auto& renderImage = downcast<RenderImage>(*(element->renderer()));
                     if (renderImage.cachedImage() && !renderImage.cachedImage()->errorOccurred()) {
                 } else if (element->renderer() && element->renderer()->isRenderImage()) {
                     auto& renderImage = downcast<RenderImage>(*(element->renderer()));
                     if (renderImage.cachedImage() && !renderImage.cachedImage()->errorOccurred()) {
+                        info.imageURL = [(NSURL *)element->document().completeURL(renderImage.cachedImage()->url()) absoluteString];
                         if (Image* image = renderImage.cachedImage()->imageForRenderer(&renderImage)) {
                             FloatSize screenSizeInPixels = screenSize();
                             screenSizeInPixels.scale(corePage()->deviceScaleFactor());
                         if (Image* image = renderImage.cachedImage()->imageForRenderer(&renderImage)) {
                             FloatSize screenSizeInPixels = screenSize();
                             screenSizeInPixels.scale(corePage()->deviceScaleFactor());