WebKit2: Need a way to get a snapshot of the visible contents of a page from the...
authorjberlin@webkit.org <jberlin@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Apr 2011 17:43:39 +0000 (17:43 +0000)
committerjberlin@webkit.org <jberlin@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Apr 2011 17:43:39 +0000 (17:43 +0000)
https://bugs.webkit.org/show_bug.cgi?id=59035

Reviewed by Sam Weinig.

Added a sync call from the UI Process to the Web Process with comments saying that it should
be removed as soon as possible.

* UIProcess/API/C/WKPage.cpp:
(WKPageVisibleContentsSnapshot):
* UIProcess/API/C/WKPagePrivate.h:

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::createSnapshotOfVisibleContent):
* UIProcess/WebPageProxy.h:

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::createSnapshotOfVisibleContent):
Ask the FrameView for the visibleContentRect, and call scaledSnapshotInDocumentCoordinates
with a scale factor of 1 (which preserves the current scaling of the page - e.g. if the
page is already zoomed then the snapshot will reflect the zoomed content).
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/C/WKPage.cpp
Source/WebKit2/UIProcess/API/C/WKPagePrivate.h
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h
Source/WebKit2/WebProcess/WebPage/WebPage.messages.in

index 513ebca..7e579ff 100644 (file)
@@ -1,3 +1,29 @@
+2011-04-21  Jessie Berlin  <jberlin@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        WebKit2: Need a way to get a snapshot of the visible contents of a page from the UI Process.
+        https://bugs.webkit.org/show_bug.cgi?id=59035
+
+        Added a sync call from the UI Process to the Web Process with comments saying that it should
+        be removed as soon as possible.
+
+        * UIProcess/API/C/WKPage.cpp:
+        (WKPageVisibleContentsSnapshot):
+        * UIProcess/API/C/WKPagePrivate.h:
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::createSnapshotOfVisibleContent):
+        * UIProcess/WebPageProxy.h:
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::createSnapshotOfVisibleContent):
+        Ask the FrameView for the visibleContentRect, and call scaledSnapshotInDocumentCoordinates
+        with a scale factor of 1 (which preserves the current scaling of the page - e.g. if the
+        page is already zoomed then the snapshot will reflect the zoomed content).
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+
 2011-04-20  Dominic Cooney  <dominicc@chromium.org>
 
         Reviewed by Dimitri Glazkov.
index 18bc5a7..140182f 100644 (file)
@@ -31,6 +31,7 @@
 #include "WKAPICast.h"
 #include "WebBackForwardList.h"
 #include "WebData.h"
+#include "WebImage.h"
 #include "WebPageProxy.h"
 #include "WebProcessProxy.h"
 
@@ -550,3 +551,9 @@ void WKPageDrawPagesToPDF(WKPageRef page, WKFrameRef frame, uint32_t first, uint
 }
 #endif
 
+WKImageRef WKPageCreateSnapshotOfVisibleContent(WKPageRef page)
+{
+    RefPtr<WebImage> webImage = toImpl(page)->createSnapshotOfVisibleContent();
+    return toAPI(webImage.release().leakRef());
+}
+
index 2c1f985..fdc59ce 100644 (file)
@@ -64,6 +64,10 @@ typedef void (*WKPageDrawToPDFFunction)(WKDataRef data, WKErrorRef error, void*
 WK_EXPORT void WKPageBeginPrinting(WKPageRef page, WKFrameRef frame, WKPrintInfo);
 WK_EXPORT void WKPageDrawPagesToPDF(WKPageRef page, WKFrameRef frame, uint32_t first, uint32_t count, WKPageDrawToPDFFunction callback, void* context);
 
+// FIXME: This is in violation of the no synchronous messages to the Web Process policy and should
+// be removed as soon as possible.
+WK_EXPORT WKImageRef WKPageCreateSnapshotOfVisibleContent(WKPageRef page);
+
 #ifdef __cplusplus
 }
 #endif
index ea0b6fb..eb33bd3 100644 (file)
@@ -3040,6 +3040,16 @@ void WebPageProxy::linkClicked(const String& url, const WebMouseEvent& event)
     process()->send(Messages::WebPage::LinkClicked(url, event), m_pageID, 0);
 }
 
+PassRefPtr<WebImage> WebPageProxy::createSnapshotOfVisibleContent()
+{
+    ShareableBitmap::Handle snapshotHandle;
+    // Do not wait for more than a second (arbitrary) for the WebProcess to get the snapshot so
+    // that the UI Process is not permanently stuck waiting on a potentially crashing Web Process.
+    static const double createSnapshotOfVisibleContentSyncMessageTimeout = 1.0;
+    process()->sendSync(Messages::WebPage::CreateSnapshotOfVisibleContent(), Messages::WebPage::CreateSnapshotOfVisibleContent::Reply(snapshotHandle), m_pageID, createSnapshotOfVisibleContentSyncMessageTimeout);
+    return WebImage::create(ShareableBitmap::create(snapshotHandle));
+}
+
 #if PLATFORM(MAC)
 
 void WebPageProxy::substitutionsPanelIsShowing(bool& isShowing)
index 1eeeff5..778e74d 100644 (file)
@@ -490,6 +490,10 @@ public:
     void saveDataToFileInDownloadsFolder(const String& suggestedFilename, const String& mimeType, const String& originatingURLString, WebData*);
 
     void linkClicked(const String&, const WebMouseEvent&);
+
+    // FIXME: This is in violation of the no synchronous messages to the Web Process policy and
+    // should be removed as soon as possible.
+    PassRefPtr<WebImage> createSnapshotOfVisibleContent();
  
 private:
     WebPageProxy(PageClient*, PassRefPtr<WebProcessProxy>, WebPageGroup*, uint64_t pageID);
index 7707965..28e580c 100644 (file)
@@ -845,6 +845,16 @@ PassRefPtr<WebImage> WebPage::snapshotInDocumentCoordinates(const IntRect& rect,
     return scaledSnapshotInDocumentCoordinates(rect, 1, options);
 }
 
+void WebPage::createSnapshotOfVisibleContent(ShareableBitmap::Handle& snapshotHandle)
+{
+    FrameView* frameView = m_mainFrame->coreFrame()->view();
+    if (!frameView)
+        return;
+    IntRect contentRect = frameView->visibleContentRect(false);
+    RefPtr<WebImage> snapshotImage = scaledSnapshotInDocumentCoordinates(contentRect, 1, ImageOptionsShareable);
+    snapshotImage->bitmap()->createHandle(snapshotHandle);
+}
+
 void WebPage::pageDidScroll()
 {
     // Hide the find indicator.
index 7828b45..d4c3411 100644 (file)
@@ -42,6 +42,7 @@
 #include "MessageSender.h"
 #include "Plugin.h"
 #include "SandboxExtension.h"
+#include "ShareableBitmap.h"
 #include "WebEditCommand.h"
 #include <WebCore/DragData.h>
 #include <WebCore/Editor.h>
@@ -268,6 +269,7 @@ public:
     PassRefPtr<WebImage> snapshotInViewCoordinates(const WebCore::IntRect&, ImageOptions);
     PassRefPtr<WebImage> snapshotInDocumentCoordinates(const WebCore::IntRect&, ImageOptions);
     PassRefPtr<WebImage> scaledSnapshotInDocumentCoordinates(const WebCore::IntRect&, double scaleFactor, ImageOptions);
+    void createSnapshotOfVisibleContent(ShareableBitmap::Handle&);
 
     static const WebEvent* currentEvent();
 
index 673e8d6..ebd64fe 100644 (file)
@@ -215,4 +215,6 @@ messages -> WebPage {
 #if PLATFORM(MAC) && !defined(BUILDING_ON_SNOW_LEOPARD)
     HandleCorrectionPanelResult(String result)
 #endif
+
+    CreateSnapshotOfVisibleContent() -> (WebKit::ShareableBitmap::Handle snapshotHandle)
 }