Changeset 148526 in webkit
- Timestamp:
- Apr 16, 2013 11:29:43 AM (11 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r148524 r148526 1 2013-04-16 Claudio Saavedra <csaavedra@igalia.com> 2 3 [GTK][WK2] Add API to retrieve a snapshot from a webview 4 https://bugs.webkit.org/show_bug.cgi?id=98270 5 6 Reviewed by Anders Carlsson. 7 8 This adds the GTK+ API necessary to retrieve a snapshot from a 9 webview asynchronously. The API uses the injected bundle 10 internally to get the snapshot from the WebProcess. 11 12 * UIProcess/API/gtk/WebKitError.cpp: 13 (webkit_snapshot_error_quark): Add snapshot API related error 14 quark. 15 * UIProcess/API/gtk/WebKitError.h: Add snapshot error handling. 16 * UIProcess/API/gtk/WebKitInjectedBundleClient.cpp: 17 (didReceiveWebViewMessageFromInjectedBundle): Handle the new 18 "DidGetSnapshot" message. 19 * UIProcess/API/gtk/WebKitPrivate.h: Add SnapshotRegion enum. 20 * UIProcess/API/gtk/WebKitWebView.cpp: 21 (_WebKitWebViewPrivate): Add a map for the snapshot results. 22 (GetSnapshotAsyncData): 23 (webKitWebViewDidReceiveSnapshot): 24 (webKitSnapshotRegionToSnapshotRegion): Helper method for casting 25 the region option enumeration. 26 (generateSnapshotCallbackID): Method to generate unique callback 27 ids. 28 (webkit_web_view_get_snapshot): 29 (webkit_web_view_get_snapshot_finish): New snapshotting API. 30 * UIProcess/API/gtk/WebKitWebView.h: Ditto. 31 * UIProcess/API/gtk/WebKitWebViewPrivate.h: Add the private method 32 to handle a received snapshot. 33 * UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Add the new API 34 bits. 35 * UIProcess/API/gtk/tests/TestWebKitWebView.cpp: 36 (cairoSurfacesEqual): Add helper to compare cairo_surface_t 37 structs. 38 (testWebViewSnapshot): New test. 39 (beforeAll): Add the new test. 40 * UIProcess/API/gtk/tests/WebViewTest.cpp: 41 (WebViewTest::selectAll): Add method to help test snapshots 42 including selection. 43 * UIProcess/API/gtk/tests/WebViewTest.h: Ditto 44 * WebProcess/InjectedBundle/API/gtk/WebKitWebExtension.cpp: 45 (didReceiveMessageToPage): Ditto. 46 (webkitWebExtensionCreate): Register method above. 47 * WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp: 48 (webkitWebPageDidReceiveMessage): Add this method. It 49 handles the new message "GetSnapshot". 50 * WebProcess/InjectedBundle/API/gtk/WebKitWebPagePrivate.h: 51 Add method above. 52 1 53 2013-04-16 Timothy Hatcher <timothy@apple.com> 2 54 -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitError.cpp
r137469 r148526 92 92 return g_quark_from_static_string("WebKitJavascriptError"); 93 93 } 94 95 GQuark webkit_snapshot_error_quark() 96 { 97 return g_quark_from_static_string("WebKitSnapshotError"); 98 } -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitError.h
r111510 r148526 36 36 #define WEBKIT_PRINT_ERROR webkit_print_error_quark () 37 37 #define WEBKIT_JAVASCRIPT_ERROR webkit_print_error_quark () 38 #define WEBKIT_SNAPSHOT_ERROR webkit_snapshot_error_quark () 38 39 39 40 /** … … 131 132 } WebKitJavascriptError; 132 133 134 /** 135 * WebKitSnapshotError: 136 * @WEBKIT_SNAPSHOT_ERROR_FAILED_TO_CREATE: An error occurred when creating a webpage snapshot. 137 * 138 * Enum values used to denote errors happending when creating snapshots of #WebKitWebView 139 */ 140 typedef enum { 141 WEBKIT_SNAPSHOT_ERROR_FAILED_TO_CREATE = 799 142 } WebKitSnapshotError; 143 133 144 WEBKIT_API GQuark 134 145 webkit_network_error_quark (void); … … 149 160 webkit_javascript_error_quark (void); 150 161 162 WEBKIT_API GQuark 163 webkit_snapshot_error_quark (void); 164 151 165 G_END_DECLS 152 166 -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitInjectedBundleClient.cpp
r143302 r148526 21 21 #include "WebKitInjectedBundleClient.h" 22 22 23 #include "WebImage.h" 23 24 #include "WebKitURIRequestPrivate.h" 24 25 #include "WebKitURIResponsePrivate.h" … … 91 92 webkitWebResourceFailed(resource.get(), resourceError.get()); 92 93 webkitWebViewRemoveLoadingWebResource(webView, resourceIdentifier->value()); 94 } else if (g_str_equal(messageName, "DidGetSnapshot")) { 95 WebUInt64* callbackID = static_cast<WebUInt64*>(message.get("CallbackID")); 96 WebImage* image = static_cast<WebImage*>(message.get("Snapshot")); 97 webKitWebViewDidReceiveSnapshot(webView, callbackID->value(), image); 93 98 } else 94 99 ASSERT_NOT_REACHED(); -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h
r135565 r148526 121 121 unsigned wkEventMouseButtonToWebKitMouseButton(WKEventMouseButton); 122 122 123 enum SnapshotRegion { 124 SnapshotRegionVisible, 125 SnapshotRegionFullDocument 126 }; 127 123 128 #endif // WebKitPrivate_h -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp
r148294 r148526 22 22 #include "WebKitWebView.h" 23 23 24 #include "ImageOptions.h" 24 25 #include "PlatformCertificateInfo.h" 25 26 #include "WebCertificateInfo.h" … … 134 135 135 136 typedef HashMap<uint64_t, GRefPtr<WebKitWebResource> > LoadingResourcesMap; 137 typedef HashMap<uint64_t, GRefPtr<GSimpleAsyncResult> > SnapshotResultsMap; 136 138 137 139 struct _WebKitWebViewPrivate { … … 179 181 CString faviconURI; 180 182 unsigned long faviconChangedHandlerID; 183 184 SnapshotResultsMap snapshotResultsMap; 181 185 }; 182 186 … … 2921 2925 return !!certificateInfo.certificate(); 2922 2926 } 2927 2928 struct GetSnapshotAsyncData { 2929 GRefPtr<GCancellable> cancellable; 2930 RefPtr<cairo_surface_t> snapshot; 2931 }; 2932 WEBKIT_DEFINE_ASYNC_DATA_STRUCT(GetSnapshotAsyncData) 2933 2934 void webKitWebViewDidReceiveSnapshot(WebKitWebView* webView, uint64_t callbackID, WebImage* webImage) 2935 { 2936 GRefPtr<GSimpleAsyncResult> result = webView->priv->snapshotResultsMap.take(callbackID); 2937 GetSnapshotAsyncData* data = static_cast<GetSnapshotAsyncData*>(g_simple_async_result_get_op_res_gpointer(result.get())); 2938 GError* error = 0; 2939 if (g_cancellable_set_error_if_cancelled(data->cancellable.get(), &error)) 2940 g_simple_async_result_take_error(result.get(), error); 2941 else if (webImage) { 2942 if (RefPtr<ShareableBitmap> image = webImage->bitmap()) 2943 data->snapshot = image->createCairoSurface(); 2944 } else { 2945 g_set_error_literal(&error, WEBKIT_SNAPSHOT_ERROR, WEBKIT_SNAPSHOT_ERROR_FAILED_TO_CREATE, _("There was an error creating the snapshot")); 2946 g_simple_async_result_take_error(result.get(), error); 2947 } 2948 2949 g_simple_async_result_complete(result.get()); 2950 } 2951 2952 COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_SNAPSHOT_REGION_VISIBLE, SnapshotRegionVisible); 2953 COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_SNAPSHOT_REGION_FULL_DOCUMENT, SnapshotRegionFullDocument); 2954 2955 static inline unsigned webKitSnapshotOptionsToSnapshotOptions(WebKitSnapshotOptions options) 2956 { 2957 SnapshotOptions snapshotOptions = 0; 2958 2959 if (!(options & WEBKIT_SNAPSHOT_OPTIONS_INCLUDE_SELECTION_HIGHLIGHTING)) 2960 snapshotOptions |= SnapshotOptionsExcludeSelectionHighlighting; 2961 2962 return snapshotOptions; 2963 } 2964 2965 static inline uint64_t generateSnapshotCallbackID() 2966 { 2967 static uint64_t uniqueCallbackID = 1; 2968 return uniqueCallbackID++; 2969 } 2970 2971 /** 2972 * webkit_web_view_get_snapshot: 2973 * @web_view: a #WebKitWebView 2974 * @options: #WebKitSnapshotOptions for the snapshot 2975 * @region: the #WebKitSnapshotRegion for this snapshot 2976 * @cancellable: (allow-none): a #GCancellable 2977 * @callback: (scope async): a #GAsyncReadyCallback 2978 * @user_data: (closure): user data 2979 * 2980 * Asynchronously retrieves a snapshot of @web_view for @region. 2981 * @options specifies how the snapshot should be rendered. 2982 * 2983 * When the operation is finished, @callback will be called. You must 2984 * call webkit_web_view_get_snapshot_finish() to get the result of the 2985 * operation. 2986 */ 2987 void webkit_web_view_get_snapshot(WebKitWebView* webView, WebKitSnapshotRegion region, WebKitSnapshotOptions options, GCancellable* cancellable, GAsyncReadyCallback callback, gpointer userData) 2988 { 2989 g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); 2990 2991 GRefPtr<GSimpleAsyncResult> result = adoptGRef(g_simple_async_result_new(G_OBJECT(webView), callback, userData, 2992 reinterpret_cast<gpointer>(webkit_web_view_get_snapshot))); 2993 GetSnapshotAsyncData* data = createGetSnapshotAsyncData(); 2994 data->cancellable = cancellable; 2995 g_simple_async_result_set_op_res_gpointer(result.get(), data, reinterpret_cast<GDestroyNotify>(destroyGetSnapshotAsyncData)); 2996 2997 ImmutableDictionary::MapType message; 2998 uint64_t callbackID = generateSnapshotCallbackID(); 2999 message.set(String::fromUTF8("SnapshotOptions"), WebUInt64::create(static_cast<uint64_t>(webKitSnapshotOptionsToSnapshotOptions(options)))); 3000 message.set(String::fromUTF8("SnapshotRegion"), WebUInt64::create(static_cast<uint64_t>(region))); 3001 message.set(String::fromUTF8("CallbackID"), WebUInt64::create(callbackID)); 3002 3003 webView->priv->snapshotResultsMap.set(callbackID, result.get()); 3004 getPage(webView)->postMessageToInjectedBundle(String::fromUTF8("GetSnapshot"), ImmutableDictionary::adopt(message).get()); 3005 } 3006 3007 /** 3008 * webkit_web_view_get_snapshot_finish: 3009 * @web_view: a #WebKitWebView 3010 * @result: a #GAsyncResult 3011 * @error: return location for error or %NULL to ignore 3012 * 3013 * Finishes an asynchronous operation started with webkit_web_view_get_snapshot(). 3014 * 3015 * Returns: (transfer full): a #cairo_surface_t with the retrieved snapshot or %NULL in error. 3016 */ 3017 cairo_surface_t* webkit_web_view_get_snapshot_finish(WebKitWebView* webView, GAsyncResult* result, GError** error) 3018 { 3019 g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 0); 3020 g_return_val_if_fail(G_IS_ASYNC_RESULT(result), 0); 3021 3022 GSimpleAsyncResult* simple = G_SIMPLE_ASYNC_RESULT(result); 3023 g_warn_if_fail(g_simple_async_result_get_source_tag(simple) == webkit_web_view_get_snapshot); 3024 3025 if (g_simple_async_result_propagate_error(simple, error)) 3026 return 0; 3027 3028 return cairo_surface_reference(static_cast<GetSnapshotAsyncData*>(g_simple_async_result_get_op_res_gpointer(simple))->snapshot.get()); 3029 } -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h
r143341 r148526 159 159 WEBKIT_VIEW_MODE_SOURCE 160 160 } WebKitViewMode; 161 162 /** 163 * WebKitSnapshotOptions: 164 * @WEBKIT_SNAPSHOT_OPTIONS_NONE: Do not include any special options. 165 * @WEBKIT_SNAPSHOT_OPTIONS_INCLUDE_SELECTION_HIGHLIGHTING: Whether to include in the 166 * snapshot the highlight of the selected content. 167 * 168 * Enum values used to specify options when taking a snapshot 169 * from a #WebKitWebView. 170 */ 171 typedef enum { 172 WEBKIT_SNAPSHOT_OPTIONS_NONE = 0, 173 WEBKIT_SNAPSHOT_OPTIONS_INCLUDE_SELECTION_HIGHLIGHTING = 1 << 0, 174 } WebKitSnapshotOptions; 175 176 /** 177 * WebKitSnapshotRegion: 178 * @WEBKIT_SNAPSHOT_REGION_VISIBLE: Specifies a snapshot only for the area that is 179 * visible in the webview 180 * @WEBKIT_SNAPSHOT_REGION_FULL_DOCUMENT: A snapshot of the entire document. 181 * 182 * Enum values used to specify the region from which to get a #WebKitWebView 183 * snapshot 184 */ 185 typedef enum { 186 WEBKIT_SNAPSHOT_REGION_VISIBLE = 0, 187 WEBKIT_SNAPSHOT_REGION_FULL_DOCUMENT, 188 } WebKitSnapshotRegion; 161 189 162 190 struct _WebKitWebView { … … 419 447 GTlsCertificate **certificate, 420 448 GTlsCertificateFlags *errors); 421 449 WEBKIT_API void 450 webkit_web_view_get_snapshot (WebKitWebView *web_view, 451 WebKitSnapshotRegion region, 452 WebKitSnapshotOptions options, 453 GCancellable *cancellable, 454 GAsyncReadyCallback callback, 455 gpointer user_data); 456 457 WEBKIT_API cairo_surface_t * 458 webkit_web_view_get_snapshot_finish (WebKitWebView *web_view, 459 GAsyncResult *result, 460 GError **error); 422 461 G_END_DECLS 423 462 -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewPrivate.h
r143302 r148526 28 28 #define WebKitWebViewPrivate_h 29 29 30 #include "WebImage.h" 30 31 #include "WebKitWebView.h" 31 32 #include <wtf/text/CString.h> … … 51 52 void webkitWebViewRunFileChooserRequest(WebKitWebView*, WebKitFileChooserRequest*); 52 53 WebKitWebResource* webkitWebViewGetLoadingWebResource(WebKitWebView*, uint64_t resourceIdentifier); 54 void webKitWebViewDidReceiveSnapshot(WebKitWebView*, uint64_t callbackID, WebKit::WebImage*); 53 55 void webkitWebViewRemoveLoadingWebResource(WebKitWebView*, uint64_t resourceIdentifier); 54 56 bool webkitWebViewEnterFullScreen(WebKitWebView*); -
trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt
r143341 r148526 76 76 WebKitViewMode 77 77 WebKitInsecureContentEvent 78 WebKitSnapshotOptions 79 WebKitSnapshotRegion 78 80 79 81 <SUBSECTION Editing Commands> … … 135 137 webkit_web_view_get_view_mode 136 138 webkit_web_view_get_tls_info 139 webkit_web_view_get_snapshot 140 webkit_web_view_get_snapshot_finish 137 141 138 142 <SUBSECTION WebKitJavascriptResult> … … 608 612 WEBKIT_PRINT_ERROR 609 613 WEBKIT_JAVASCRIPT_ERROR 614 WEBKIT_SNAPSHOT_ERROR 610 615 WebKitNetworkError 611 616 WebKitPluginError … … 614 619 WebKitPrintError 615 620 WebKitJavascriptError 621 WebKitSnapshotError 616 622 webkit_network_error_quark 617 623 webkit_plugin_error_quark … … 620 626 webkit_print_error_quark 621 627 webkit_javascript_error_quark 628 webkit_snapshot_error_quark 622 629 </SECTION> 623 630 -
trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp
r148088 r148526 1147 1147 } 1148 1148 1149 class SnapshotWebViewTest: public WebViewTest { 1150 public: 1151 MAKE_GLIB_TEST_FIXTURE(SnapshotWebViewTest); 1152 1153 SnapshotWebViewTest() 1154 : m_surface(0) 1155 { 1156 } 1157 1158 ~SnapshotWebViewTest() 1159 { 1160 cairo_surface_destroy(m_surface); 1161 } 1162 1163 static void onSnapshotReady(WebKitWebView* web_view, GAsyncResult* res, SnapshotWebViewTest* test) 1164 { 1165 GOwnPtr<GError> error; 1166 test->m_surface = webkit_web_view_get_snapshot_finish(web_view, res, &error.outPtr()); 1167 g_assert(!test->m_surface || !error.get()); 1168 if (error) 1169 g_assert_error(error.get(), WEBKIT_SNAPSHOT_ERROR, WEBKIT_SNAPSHOT_ERROR_FAILED_TO_CREATE); 1170 test->quitMainLoop(); 1171 } 1172 1173 cairo_surface_t* waitForSnapshot(WebKitSnapshotRegion region, WebKitSnapshotOptions options) 1174 { 1175 m_surface = 0; 1176 webkit_web_view_get_snapshot(m_webView, region, options, 0, reinterpret_cast<GAsyncReadyCallback>(onSnapshotReady), this); 1177 g_main_loop_run(m_mainLoop); 1178 return cairo_surface_reference(m_surface); 1179 } 1180 1181 static void onSnapshotCancelledReady(WebKitWebView* web_view, GAsyncResult* res, SnapshotWebViewTest* test) 1182 { 1183 GOwnPtr<GError> error; 1184 test->m_surface = webkit_web_view_get_snapshot_finish(web_view, res, &error.outPtr()); 1185 g_assert(!test->m_surface); 1186 g_assert_error(error.get(), G_IO_ERROR, G_IO_ERROR_CANCELLED); 1187 test->quitMainLoop(); 1188 } 1189 1190 gboolean getSnapshotAndCancel() 1191 { 1192 m_surface = 0; 1193 GRefPtr<GCancellable> cancellable = adoptGRef(g_cancellable_new()); 1194 webkit_web_view_get_snapshot(m_webView, WEBKIT_SNAPSHOT_REGION_VISIBLE, WEBKIT_SNAPSHOT_OPTIONS_NONE, cancellable.get(), reinterpret_cast<GAsyncReadyCallback>(onSnapshotCancelledReady), this); 1195 g_cancellable_cancel(cancellable.get()); 1196 g_main_loop_run(m_mainLoop); 1197 1198 return true; 1199 } 1200 1201 cairo_surface_t* m_surface; 1202 }; 1203 1204 static gboolean cairoSurfacesEqual(cairo_surface_t* s1, cairo_surface_t* s2) 1205 { 1206 return (cairo_image_surface_get_format(s1) == cairo_image_surface_get_format(s2) 1207 && cairo_image_surface_get_width(s1) == cairo_image_surface_get_width(s2) 1208 && cairo_image_surface_get_height(s1) == cairo_image_surface_get_height(s2) 1209 && cairo_image_surface_get_stride(s1) == cairo_image_surface_get_stride(s2) 1210 && !memcmp(const_cast<const void*>(reinterpret_cast<void*>(cairo_image_surface_get_data(s1))), 1211 const_cast<const void*>(reinterpret_cast<void*>(cairo_image_surface_get_data(s2))), 1212 cairo_image_surface_get_height(s1)*cairo_image_surface_get_stride(s1))); 1213 } 1214 1215 static void testWebViewSnapshot(SnapshotWebViewTest* test, gconstpointer) 1216 { 1217 test->loadHtml("<html><body><p>Whatever</p></body></html>", 0); 1218 test->waitUntilLoadFinished(); 1219 1220 // WebView not visible. 1221 cairo_surface_t* surface1 = test->waitForSnapshot(WEBKIT_SNAPSHOT_REGION_VISIBLE, WEBKIT_SNAPSHOT_OPTIONS_NONE); 1222 g_assert(!surface1); 1223 1224 // Show surface, resize to 50x50, try again. 1225 test->showInWindowAndWaitUntilMapped(); 1226 test->resizeView(50, 50); 1227 surface1 = test->waitForSnapshot(WEBKIT_SNAPSHOT_REGION_VISIBLE, WEBKIT_SNAPSHOT_OPTIONS_NONE); 1228 g_assert(surface1); 1229 1230 // obtained surface should be at the most 50x50. Store the size 1231 // for comparison later. 1232 int width = cairo_image_surface_get_width(surface1); 1233 int height = cairo_image_surface_get_height(surface1); 1234 g_assert_cmpint(width, <=, 50); 1235 g_assert_cmpint(height, <=, 50); 1236 1237 cairo_surface_destroy(surface1); 1238 1239 // Select all text in the WebView, request a snapshot ignoring selection. 1240 test->selectAll(); 1241 surface1 = test->waitForSnapshot(WEBKIT_SNAPSHOT_REGION_VISIBLE, WEBKIT_SNAPSHOT_OPTIONS_NONE); 1242 g_assert(surface1); 1243 g_assert_cmpint(cairo_image_surface_get_width(surface1), ==, width); 1244 g_assert_cmpint(cairo_image_surface_get_height(surface1), ==, height); 1245 1246 // Create identical surface. 1247 cairo_surface_t* surface2 = test->waitForSnapshot(WEBKIT_SNAPSHOT_REGION_VISIBLE, WEBKIT_SNAPSHOT_OPTIONS_NONE); 1248 g_assert(surface2); 1249 1250 // Compare these two, they should be identical. 1251 g_assert(cairoSurfacesEqual(surface1, surface2)); 1252 cairo_surface_destroy(surface2); 1253 1254 // Request a new snapshot, including the selection this time. The 1255 // size should be the same but the result must be different to the 1256 // one previously obtained. 1257 surface2 = test->waitForSnapshot(WEBKIT_SNAPSHOT_REGION_VISIBLE, WEBKIT_SNAPSHOT_OPTIONS_INCLUDE_SELECTION_HIGHLIGHTING); 1258 g_assert(surface2); 1259 g_assert_cmpint(cairo_image_surface_get_width(surface2), ==, width); 1260 g_assert_cmpint(cairo_image_surface_get_height(surface2), ==, height); 1261 g_assert(!cairoSurfacesEqual(surface1, surface2)); 1262 cairo_surface_destroy(surface2); 1263 1264 // Request a snapshot of the whole document in the WebView. The 1265 // result should be different from the size obtained previously. 1266 surface2 = test->waitForSnapshot(WEBKIT_SNAPSHOT_REGION_FULL_DOCUMENT, WEBKIT_SNAPSHOT_OPTIONS_NONE); 1267 g_assert(surface2); 1268 g_assert_cmpint(cairo_image_surface_get_width(surface2), >, width); 1269 g_assert_cmpint(cairo_image_surface_get_height(surface2), >, height); 1270 g_assert(!cairoSurfacesEqual(surface1, surface2)); 1271 1272 cairo_surface_destroy(surface1); 1273 cairo_surface_destroy(surface2); 1274 1275 g_assert(test->getSnapshotAndCancel()); 1276 } 1277 1149 1278 void beforeAll() 1150 1279 { … … 1167 1296 SaveWebViewTest::add("WebKitWebView", "save", testWebViewSave); 1168 1297 WebViewTest::add("WebKitWebView", "view-mode", testWebViewMode); 1298 SnapshotWebViewTest::add("WebKitWebView", "snapshot", testWebViewSnapshot); 1169 1299 WebViewTest::add("WebKitWebView", "page-visibility", testWebViewPageVisibility); 1170 1300 } -
trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp
r148088 r148526 208 208 } 209 209 210 void WebViewTest::selectAll() 211 { 212 webkit_web_view_execute_editing_command(m_webView, "SelectAll"); 213 } 214 210 215 static void resourceGetDataCallback(GObject* object, GAsyncResult* result, gpointer userData) 211 216 { -
trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h
r148088 r148526 50 50 void showInWindowAndWaitUntilMapped(GtkWindowType = GTK_WINDOW_POPUP); 51 51 void resizeView(int width, int height); 52 void selectAll(); 52 53 const char* mainResourceData(size_t& mainResourceDataSize); 53 54 -
trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebExtension.cpp
r141102 r148526 106 106 } 107 107 108 static void didReceiveMessageToPage(WKBundleRef bundle, WKBundlePageRef page, WKStringRef name, WKTypeRef messageBody, const void* clientInfo) 109 { 110 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 111 if (WebKitWebPage* webPage = WEBKIT_WEB_EXTENSION(clientInfo)->priv->pages.get(toImpl(page)).get()) 112 webkitWebPageDidReceiveMessage(webPage, toImpl(name)->string(), *toImpl(static_cast<WKDictionaryRef>(messageBody))); 113 } 114 108 115 WebKitWebExtension* webkitWebExtensionCreate(InjectedBundle* bundle) 109 116 { … … 117 124 0, // didInitializePageGroup 118 125 didReceiveMessage, 119 0 //didReceiveMessageToPage126 didReceiveMessageToPage 120 127 }; 121 128 WKBundleSetClient(toAPI(bundle), &wkBundleClient); -
trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp
r148281 r148526 21 21 #include "WebKitWebPage.h" 22 22 23 #include "ImageOptions.h" 23 24 #include "ImmutableDictionary.h" 24 25 #include "InjectedBundle.h" … … 26 27 #include "WKBundleFrame.h" 27 28 #include "WebFrame.h" 29 #include "WebImage.h" 28 30 #include "WebKitDOMDocumentPrivate.h" 29 31 #include "WebKitPrivate.h" … … 31 33 #include "WebProcess.h" 32 34 #include <WebCore/Frame.h> 35 #include <WebCore/FrameView.h> 33 36 34 37 using namespace WebKit; … … 197 200 } 198 201 202 void webkitWebPageDidReceiveMessage(WebKitWebPage* page, const String& messageName, ImmutableDictionary& message) 203 { 204 if (messageName == String("GetSnapshot")) { 205 SnapshotOptions snapshotOptions = static_cast<SnapshotOptions>(static_cast<WebUInt64*>(message.get("SnapshotOptions"))->value()); 206 uint64_t callbackID = static_cast<WebUInt64*>(message.get("CallbackID"))->value(); 207 SnapshotRegion region = static_cast<SnapshotRegion>(static_cast<WebUInt64*>(message.get("SnapshotRegion"))->value()); 208 209 RefPtr<WebImage> snapshotImage; 210 WebPage* webPage = page->priv->webPage; 211 if (WebCore::FrameView* frameView = webPage->mainFrameView()) { 212 WebCore::IntRect snapshotRect; 213 switch (region) { 214 case SnapshotRegionVisible: 215 snapshotRect = frameView->visibleContentRect(WebCore::ScrollableArea::ExcludeScrollbars); 216 break; 217 case SnapshotRegionFullDocument: 218 snapshotRect = WebCore::IntRect(WebCore::IntPoint(0, 0), frameView->contentsSize()); 219 break; 220 default: 221 ASSERT_NOT_REACHED(); 222 } 223 if (!snapshotRect.isEmpty()) 224 snapshotImage = webPage->scaledSnapshotWithOptions(snapshotRect, 1, snapshotOptions | SnapshotOptionsShareable); 225 } 226 227 ImmutableDictionary::MapType messageReply; 228 messageReply.set("Page", webPage); 229 messageReply.set("CallbackID", WebUInt64::create(callbackID)); 230 messageReply.set("Snapshot", snapshotImage); 231 WebProcess::shared().injectedBundle()->postMessage("WebPage.DidGetSnapshot", ImmutableDictionary::adopt(messageReply).get()); 232 } else 233 ASSERT_NOT_REACHED(); 234 } 235 199 236 /** 200 237 * webkit_web_page_get_dom_document: -
trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPagePrivate.h
r139305 r148526 21 21 #define WebKitWebPagePrivate_h 22 22 23 #include "ImmutableDictionary.h" 23 24 #include "WebKitWebPage.h" 24 25 #include "WebPage.h" 25 26 26 27 WebKitWebPage* webkitWebPageCreate(WebKit::WebPage*); 28 void webkitWebPageDidReceiveMessage(WebKitWebPage*, const String& messageName, WebKit::ImmutableDictionary& message); 27 29 28 30 #endif // WebKitWebPagePrivate_h
Note: See TracChangeset
for help on using the changeset viewer.