Title: [186236] trunk/Source
Revision
186236
Author
bda...@apple.com
Date
2015-07-02 15:10:40 -0700 (Thu, 02 Jul 2015)

Log Message

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.

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):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (186235 => 186236)


--- trunk/Source/WebCore/ChangeLog	2015-07-02 21:39:37 UTC (rev 186235)
+++ trunk/Source/WebCore/ChangeLog	2015-07-02 22:10:40 UTC (rev 186236)
@@ -1,3 +1,16 @@
+2015-07-02  Beth Dakin  <bda...@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  <beid...@apple.com>
 
         Add preference to disable all http-equiv.

Modified: trunk/Source/WebCore/loader/cache/CachedResource.h (186235 => 186236)


--- trunk/Source/WebCore/loader/cache/CachedResource.h	2015-07-02 21:39:37 UTC (rev 186235)
+++ trunk/Source/WebCore/loader/cache/CachedResource.h	2015-07-02 22:10:40 UTC (rev 186236)
@@ -109,7 +109,7 @@
     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

Modified: trunk/Source/WebKit2/ChangeLog (186235 => 186236)


--- trunk/Source/WebKit2/ChangeLog	2015-07-02 21:39:37 UTC (rev 186235)
+++ trunk/Source/WebKit2/ChangeLog	2015-07-02 22:10:40 UTC (rev 186236)
@@ -1,3 +1,30 @@
+2015-07-02  Beth Dakin  <bda...@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  <ander...@apple.com>
 
         Instead of requiring ToT UIKIt, check that UI_WEB_TOUCH_EVENT_HAS_IS_POTENTIAL_TAP is defined to 1

Modified: trunk/Source/WebKit2/Shared/InteractionInformationAtPosition.cpp (186235 => 186236)


--- trunk/Source/WebKit2/Shared/InteractionInformationAtPosition.cpp	2015-07-02 21:39:37 UTC (rev 186235)
+++ trunk/Source/WebKit2/Shared/InteractionInformationAtPosition.cpp	2015-07-02 22:10:40 UTC (rev 186236)
@@ -41,6 +41,7 @@
     encoder << touchCalloutEnabled;
     encoder << clickableElementName;
     encoder << url;
+    encoder << imageURL;
     encoder << title;
     encoder << bounds;
 
@@ -73,6 +74,9 @@
     if (!decoder.decode(result.url))
         return false;
 
+    if (!decoder.decode(result.imageURL))
+        return false;
+
     if (!decoder.decode(result.title))
         return false;
 

Modified: trunk/Source/WebKit2/Shared/InteractionInformationAtPosition.h (186235 => 186236)


--- trunk/Source/WebKit2/Shared/InteractionInformationAtPosition.h	2015-07-02 21:39:37 UTC (rev 186235)
+++ trunk/Source/WebKit2/Shared/InteractionInformationAtPosition.h	2015-07-02 22:10:40 UTC (rev 186236)
@@ -54,6 +54,7 @@
     bool touchCalloutEnabled;
     String clickableElementName;
     String url;
+    String imageURL;
     String title;
     WebCore::IntRect bounds;
     RefPtr<ShareableBitmap> image;

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKUIDelegatePrivate.h (186235 => 186236)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKUIDelegatePrivate.h	2015-07-02 21:39:37 UTC (rev 186235)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKUIDelegatePrivate.h	2015-07-02 22:10:40 UTC (rev 186236)
@@ -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;
+- (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
 

Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm (186235 => 186236)


--- trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm	2015-07-02 21:39:37 UTC (rev 186235)
+++ trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm	2015-07-02 22:10:40 UTC (rev 186236)
@@ -3213,10 +3213,11 @@
         canShowLinkPreview = NO;
     }
 
+    id <WKUIDelegatePrivate> uiDelegate = static_cast<id <WKUIDelegatePrivate>>([_webView UIDelegate]);
+
     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];
@@ -3232,7 +3233,12 @@
     }
 
     if (canShowImagePreview) {
+        String absoluteImageURL = _positionInformation.imageURL;
+        if (absoluteImageURL.isEmpty() || !(WebCore::protocolIsInHTTPFamily(absoluteImageURL) || WebCore::protocolIs(absoluteImageURL, "data")))
+            return nil;
         _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];
     }
 
@@ -3241,10 +3247,18 @@
 
 - (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;
+    }
 
-    id<WKUIDelegatePrivate> uiDelegate = static_cast<id <WKUIDelegatePrivate>>([_webView UIDelegate]);
     if ([uiDelegate respondsToSelector:@selector(_webView:commitPreviewedViewController:)]) {
         [uiDelegate _webView:_webView commitPreviewedViewController:viewController];
         return;

Modified: trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm (186235 => 186236)


--- trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm	2015-07-02 21:39:37 UTC (rev 186235)
+++ trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm	2015-07-02 22:10:40 UTC (rev 186236)
@@ -2141,6 +2141,7 @@
                 } 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());
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to