Changeset 145358 in webkit
- Timestamp:
- Mar 11, 2013, 6:07:19 AM (14 years ago)
- Location:
- releases/WebKitGTK/webkit-2.0/Source/WebKit2
- Files:
-
- 13 edited
-
ChangeLog (modified) (1 diff)
-
UIProcess/API/gtk/WebKitError.cpp (modified) (1 diff)
-
UIProcess/API/gtk/WebKitError.h (modified) (3 diffs)
-
UIProcess/API/gtk/WebKitInjectedBundleClient.cpp (modified) (2 diffs)
-
UIProcess/API/gtk/WebKitPrivate.h (modified) (1 diff)
-
UIProcess/API/gtk/WebKitWebView.cpp (modified) (4 diffs)
-
UIProcess/API/gtk/WebKitWebView.h (modified) (2 diffs)
-
UIProcess/API/gtk/WebKitWebViewPrivate.h (modified) (2 diffs)
-
UIProcess/API/gtk/docs/webkit2gtk-sections.txt (modified) (5 diffs)
-
UIProcess/API/gtk/tests/TestWebKitWebView.cpp (modified) (2 diffs)
-
UIProcess/API/gtk/tests/WebViewTest.cpp (modified) (1 diff)
-
UIProcess/API/gtk/tests/WebViewTest.h (modified) (1 diff)
-
WebProcess/InjectedBundle/API/gtk/WebKitWebExtension.cpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
releases/WebKitGTK/webkit-2.0/Source/WebKit2/ChangeLog
r145324 r145358 1 2013-03-10 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 Carlos Garcia Campos. 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 (webkitWebExtensionDidReceiveMessageToPage): Add this method. It 46 handles the new message "GetSnapshot". 47 (didReceiveMessageToPage): Ditto. 48 (webkitWebExtensionCreate): Register method above. 49 1 50 2013-03-10 Xan Lopez <xan@igalia.com> 2 51 -
releases/WebKitGTK/webkit-2.0/Source/WebKit2/UIProcess/API/gtk/WebKitError.cpp
r137469 r145358 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 } -
releases/WebKitGTK/webkit-2.0/Source/WebKit2/UIProcess/API/gtk/WebKitError.h
r111510 r145358 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 -
releases/WebKitGTK/webkit-2.0/Source/WebKit2/UIProcess/API/gtk/WebKitInjectedBundleClient.cpp
r143302 r145358 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(); -
releases/WebKitGTK/webkit-2.0/Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h
r135565 r145358 121 121 unsigned wkEventMouseButtonToWebKitMouseButton(WKEventMouseButton); 122 122 123 enum SnapshotRegion { 124 SnapshotRegionVisible, 125 SnapshotRegionFullDocument 126 }; 127 123 128 #endif // WebKitPrivate_h -
releases/WebKitGTK/webkit-2.0/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp
r145324 r145358 22 22 #include "WebKitWebView.h" 23 23 24 #include "ImageOptions.h" 24 25 #include "PlatformCertificateInfo.h" 25 26 #include "WebCertificateInfo.h" … … 136 137 137 138 typedef HashMap<uint64_t, GRefPtr<WebKitWebResource> > LoadingResourcesMap; 139 typedef HashMap<uint64_t, GRefPtr<GSimpleAsyncResult> > SnapshotResultsMap; 138 140 139 141 struct _WebKitWebViewPrivate { … … 183 185 CString faviconURI; 184 186 unsigned long faviconChangedHandlerID; 187 188 SnapshotResultsMap snapshotResultsMap; 185 189 }; 186 190 … … 3024 3028 } 3025 3029 3030 struct GetSnapshotAsyncData { 3031 GRefPtr<GCancellable> cancellable; 3032 RefPtr<cairo_surface_t> snapshot; 3033 }; 3034 WEBKIT_DEFINE_ASYNC_DATA_STRUCT(GetSnapshotAsyncData) 3035 3036 void webKitWebViewDidReceiveSnapshot(WebKitWebView* webView, uint64_t callbackID, WebImage* webImage) 3037 { 3038 GRefPtr<GSimpleAsyncResult> result = webView->priv->snapshotResultsMap.take(callbackID); 3039 GetSnapshotAsyncData* data = static_cast<GetSnapshotAsyncData*>(g_simple_async_result_get_op_res_gpointer(result.get())); 3040 GError* error = 0; 3041 if (g_cancellable_set_error_if_cancelled(data->cancellable.get(), &error)) 3042 g_simple_async_result_take_error(result.get(), error); 3043 else if (webImage) { 3044 if (RefPtr<ShareableBitmap> image = webImage->bitmap()) 3045 data->snapshot = image->createCairoSurface(); 3046 } else { 3047 g_set_error_literal(&error, WEBKIT_SNAPSHOT_ERROR, WEBKIT_SNAPSHOT_ERROR_FAILED_TO_CREATE, _("There was an error creating the snapshot")); 3048 g_simple_async_result_take_error(result.get(), error); 3049 } 3050 3051 g_simple_async_result_complete(result.get()); 3052 } 3053 3054 COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_SNAPSHOT_REGION_VISIBLE, SnapshotRegionVisible); 3055 COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_SNAPSHOT_REGION_FULL_DOCUMENT, SnapshotRegionFullDocument); 3056 3057 static inline unsigned webKitSnapshotOptionsToSnapshotOptions(WebKitSnapshotOptions options) 3058 { 3059 SnapshotOptions snapshotOptions = 0; 3060 3061 if (!(options & WEBKIT_SNAPSHOT_OPTIONS_INCLUDE_SELECTION_HIGHLIGHTING)) 3062 snapshotOptions |= SnapshotOptionsExcludeSelectionHighlighting; 3063 3064 return snapshotOptions; 3065 } 3066 3067 static inline uint64_t generateSnapshotCallbackID() 3068 { 3069 static uint64_t uniqueCallbackID = 1; 3070 return uniqueCallbackID++; 3071 } 3072 3073 /** 3074 * webkit_web_view_get_snapshot: 3075 * @web_view: a #WebKitWebView 3076 * @options: #WebKitSnapshotOptions for the snapshot 3077 * @region: the #WebKitSnapshotRegion for this snapshot 3078 * @cancellable: (allow-none): a #GCancellable 3079 * @callback: (scope async): a #GAsyncReadyCallback 3080 * @user_data: (closure): user data 3081 * 3082 * Asynchronously retrieves a snapshot of @web_view for @region. 3083 * @options specifies how the snapshot should be rendered. 3084 * 3085 * When the operation is finished, @callback will be called. You must 3086 * call webkit_web_view_get_snapshot_finish() to get the result of the 3087 * operation. 3088 **/ 3089 void webkit_web_view_get_snapshot(WebKitWebView* webView, WebKitSnapshotRegion region, WebKitSnapshotOptions options, GCancellable* cancellable, GAsyncReadyCallback callback, gpointer userData) 3090 { 3091 g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); 3092 3093 GRefPtr<GSimpleAsyncResult> result = adoptGRef(g_simple_async_result_new(G_OBJECT(webView), callback, userData, 3094 reinterpret_cast<gpointer>(webkit_web_view_get_snapshot))); 3095 GetSnapshotAsyncData* data = createGetSnapshotAsyncData(); 3096 data->cancellable = cancellable; 3097 g_simple_async_result_set_op_res_gpointer(result.get(), data, reinterpret_cast<GDestroyNotify>(destroyGetSnapshotAsyncData)); 3098 3099 ImmutableDictionary::MapType message; 3100 uint64_t callbackID = generateSnapshotCallbackID(); 3101 message.set(String::fromUTF8("SnapshotOptions"), WebUInt64::create(static_cast<uint64_t>(webKitSnapshotOptionsToSnapshotOptions(options)))); 3102 message.set(String::fromUTF8("SnapshotRegion"), WebUInt64::create(static_cast<uint64_t>(region))); 3103 message.set(String::fromUTF8("CallbackID"), WebUInt64::create(callbackID)); 3104 3105 webView->priv->snapshotResultsMap.set(callbackID, result.get()); 3106 getPage(webView)->postMessageToInjectedBundle(String::fromUTF8("GetSnapshot"), ImmutableDictionary::adopt(message).get()); 3107 } 3108 3109 /** 3110 * webkit_web_view_get_snapshot_finish: 3111 * @web_view: a #WebKitWebView 3112 * @result: a #GAsyncResult 3113 * @error: return location for error or %NULL to ignore 3114 * 3115 * Finishes an asynchronous operation started with webkit_web_view_get_snapshot(). 3116 * 3117 * Returns: (transfer full): a #cairo_surface_t with the retrieved snapshot or %NULL in error. 3118 **/ 3119 cairo_surface_t* webkit_web_view_get_snapshot_finish(WebKitWebView* webView, GAsyncResult* result, GError** error) 3120 { 3121 g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 0); 3122 g_return_val_if_fail(G_IS_ASYNC_RESULT(result), 0); 3123 3124 GSimpleAsyncResult* simple = G_SIMPLE_ASYNC_RESULT(result); 3125 g_warn_if_fail(g_simple_async_result_get_source_tag(simple) == webkit_web_view_get_snapshot); 3126 3127 if (g_simple_async_result_propagate_error(simple, error)) 3128 return 0; 3129 3130 return cairo_surface_reference(static_cast<GetSnapshotAsyncData*>(g_simple_async_result_get_op_res_gpointer(simple))->snapshot.get()); 3131 } -
releases/WebKitGTK/webkit-2.0/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h
r145324 r145358 160 160 WEBKIT_VIEW_MODE_SOURCE 161 161 } WebKitViewMode; 162 163 /** 164 * WebKitSnapshotOptions: 165 * @WEBKIT_SNAPSHOT_OPTIONS_NONE: Do not include any special options. 166 * @WEBKIT_SNAPSHOT_OPTIONS_INCLUDE_SELECTION_HIGHLIGHTING: Whether to include in the 167 * snapshot the highlight of the selected content. 168 * 169 * Enum values used to specify options when taking a snapshot 170 * from a #WebKitWebView. 171 */ 172 typedef enum { 173 WEBKIT_SNAPSHOT_OPTIONS_NONE = 0, 174 WEBKIT_SNAPSHOT_OPTIONS_INCLUDE_SELECTION_HIGHLIGHTING = 1 << 0, 175 } WebKitSnapshotOptions; 176 177 /** 178 * WebKitSnapshotRegion: 179 * @WEBKIT_SNAPSHOT_REGION_VISIBLE: Specifies a snapshot only for the area that is 180 * visible in the webview 181 * @WEBKIT_SNAPSHOT_REGION_FULL_DOCUMENT: A snapshot of the entire document. 182 * 183 * Enum values used to specify the region from which to get a #WebKitWebView 184 * snapshot 185 */ 186 typedef enum { 187 WEBKIT_SNAPSHOT_REGION_VISIBLE = 0, 188 WEBKIT_SNAPSHOT_REGION_FULL_DOCUMENT, 189 } WebKitSnapshotRegion; 162 190 163 191 struct _WebKitWebView { … … 427 455 GTlsCertificate **certificate, 428 456 GTlsCertificateFlags *errors); 429 457 WEBKIT_API void 458 webkit_web_view_get_snapshot (WebKitWebView *web_view, 459 WebKitSnapshotRegion region, 460 WebKitSnapshotOptions options, 461 GCancellable *cancellable, 462 GAsyncReadyCallback callback, 463 gpointer user_data); 464 465 WEBKIT_API cairo_surface_t * 466 webkit_web_view_get_snapshot_finish (WebKitWebView *web_view, 467 GAsyncResult *result, 468 GError **error); 430 469 G_END_DECLS 431 470 -
releases/WebKitGTK/webkit-2.0/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewPrivate.h
r145324 r145358 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*); -
releases/WebKitGTK/webkit-2.0/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt
r144900 r145358 76 76 WebKitViewMode 77 77 WebKitInsecureContentEvent 78 WebKitSnapshotOptions 79 WebKitSnapshotRegion 78 80 79 81 <SUBSECTION Editing Commands> … … 137 139 webkit_web_view_get_view_mode 138 140 webkit_web_view_get_tls_info 141 webkit_web_view_get_snapshot 142 webkit_web_view_get_snapshot_finish 139 143 140 144 <SUBSECTION WebKitJavascriptResult> … … 611 615 WEBKIT_PRINT_ERROR 612 616 WEBKIT_JAVASCRIPT_ERROR 617 WEBKIT_SNAPSHOT_ERROR 613 618 WebKitNetworkError 614 619 WebKitPluginError … … 617 622 WebKitPrintError 618 623 WebKitJavascriptError 624 WebKitSnapshotError 619 625 webkit_network_error_quark 620 626 webkit_plugin_error_quark … … 623 629 webkit_print_error_quark 624 630 webkit_javascript_error_quark 631 webkit_snapshot_error_quark 625 632 </SECTION> 626 633 -
releases/WebKitGTK/webkit-2.0/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp
r145203 r145358 1083 1083 } 1084 1084 1085 class SnapshotWebViewTest: public WebViewTest { 1086 public: 1087 MAKE_GLIB_TEST_FIXTURE(SnapshotWebViewTest); 1088 1089 SnapshotWebViewTest() 1090 : m_surface(0) 1091 { 1092 } 1093 1094 ~SnapshotWebViewTest() 1095 { 1096 cairo_surface_destroy(m_surface); 1097 } 1098 1099 static void onSnapshotReady(WebKitWebView* web_view, GAsyncResult* res, SnapshotWebViewTest* test) 1100 { 1101 GOwnPtr<GError> error; 1102 test->m_surface = webkit_web_view_get_snapshot_finish(web_view, res, &error.outPtr()); 1103 g_assert(!test->m_surface || !error.get()); 1104 if (error) 1105 g_assert_error(error.get(), WEBKIT_SNAPSHOT_ERROR, WEBKIT_SNAPSHOT_ERROR_FAILED_TO_CREATE); 1106 test->quitMainLoop(); 1107 } 1108 1109 cairo_surface_t* waitForSnapshot(WebKitSnapshotRegion region, WebKitSnapshotOptions options) 1110 { 1111 m_surface = 0; 1112 webkit_web_view_get_snapshot(m_webView, region, options, 0, reinterpret_cast<GAsyncReadyCallback>(onSnapshotReady), this); 1113 g_main_loop_run(m_mainLoop); 1114 return cairo_surface_reference(m_surface); 1115 } 1116 1117 static void onSnapshotCancelledReady(WebKitWebView* web_view, GAsyncResult* res, SnapshotWebViewTest* test) 1118 { 1119 GOwnPtr<GError> error; 1120 test->m_surface = webkit_web_view_get_snapshot_finish(web_view, res, &error.outPtr()); 1121 g_assert(!test->m_surface); 1122 g_assert_error(error.get(), G_IO_ERROR, G_IO_ERROR_CANCELLED); 1123 test->quitMainLoop(); 1124 } 1125 1126 gboolean getSnapshotAndCancel() 1127 { 1128 m_surface = 0; 1129 GRefPtr<GCancellable> cancellable = adoptGRef(g_cancellable_new()); 1130 webkit_web_view_get_snapshot(m_webView, WEBKIT_SNAPSHOT_REGION_VISIBLE, WEBKIT_SNAPSHOT_OPTIONS_NONE, cancellable.get(), reinterpret_cast<GAsyncReadyCallback>(onSnapshotCancelledReady), this); 1131 g_cancellable_cancel(cancellable.get()); 1132 g_main_loop_run(m_mainLoop); 1133 1134 return true; 1135 } 1136 1137 cairo_surface_t* m_surface; 1138 }; 1139 1140 static gboolean cairoSurfacesEqual(cairo_surface_t* s1, cairo_surface_t* s2) 1141 { 1142 return (cairo_image_surface_get_format(s1) == cairo_image_surface_get_format(s2) 1143 && cairo_image_surface_get_width(s1) == cairo_image_surface_get_width(s2) 1144 && cairo_image_surface_get_height(s1) == cairo_image_surface_get_height(s2) 1145 && cairo_image_surface_get_stride(s1) == cairo_image_surface_get_stride(s2) 1146 && !memcmp(const_cast<const void*>(reinterpret_cast<void*>(cairo_image_surface_get_data(s1))), 1147 const_cast<const void*>(reinterpret_cast<void*>(cairo_image_surface_get_data(s2))), 1148 cairo_image_surface_get_height(s1)*cairo_image_surface_get_stride(s1))); 1149 } 1150 1151 static void testWebViewSnapshot(SnapshotWebViewTest* test, gconstpointer) 1152 { 1153 test->loadHtml("<html><body><p>Whatever</p></body></html>", 0); 1154 test->waitUntilLoadFinished(); 1155 1156 // WebView not visible. 1157 cairo_surface_t* surface1 = test->waitForSnapshot(WEBKIT_SNAPSHOT_REGION_VISIBLE, WEBKIT_SNAPSHOT_OPTIONS_NONE); 1158 g_assert(!surface1); 1159 1160 // Show surface, resize to 50x50, try again. 1161 test->showInWindowAndWaitUntilMapped(); 1162 test->resizeView(50, 50); 1163 surface1 = test->waitForSnapshot(WEBKIT_SNAPSHOT_REGION_VISIBLE, WEBKIT_SNAPSHOT_OPTIONS_NONE); 1164 g_assert(surface1); 1165 1166 // obtained surface should be at the most 50x50. Store the size 1167 // for comparison later. 1168 int width = cairo_image_surface_get_width(surface1); 1169 int height = cairo_image_surface_get_height(surface1); 1170 g_assert_cmpint(width, <=, 50); 1171 g_assert_cmpint(height, <=, 50); 1172 1173 cairo_surface_destroy(surface1); 1174 1175 // Select all text in the WebView, request a snapshot ignoring selection. 1176 test->selectAll(); 1177 surface1 = test->waitForSnapshot(WEBKIT_SNAPSHOT_REGION_VISIBLE, WEBKIT_SNAPSHOT_OPTIONS_NONE); 1178 g_assert(surface1); 1179 g_assert_cmpint(cairo_image_surface_get_width(surface1), ==, width); 1180 g_assert_cmpint(cairo_image_surface_get_height(surface1), ==, height); 1181 1182 // Create identical surface. 1183 cairo_surface_t* surface2 = test->waitForSnapshot(WEBKIT_SNAPSHOT_REGION_VISIBLE, WEBKIT_SNAPSHOT_OPTIONS_NONE); 1184 g_assert(surface2); 1185 1186 // Compare these two, they should be identical. 1187 g_assert(cairoSurfacesEqual(surface1, surface2)); 1188 cairo_surface_destroy(surface2); 1189 1190 // Request a new snapshot, including the selection this time. The 1191 // size should be the same but the result must be different to the 1192 // one previously obtained. 1193 surface2 = test->waitForSnapshot(WEBKIT_SNAPSHOT_REGION_VISIBLE, WEBKIT_SNAPSHOT_OPTIONS_INCLUDE_SELECTION_HIGHLIGHTING); 1194 g_assert(surface2); 1195 g_assert_cmpint(cairo_image_surface_get_width(surface2), ==, width); 1196 g_assert_cmpint(cairo_image_surface_get_height(surface2), ==, height); 1197 g_assert(!cairoSurfacesEqual(surface1, surface2)); 1198 cairo_surface_destroy(surface2); 1199 1200 // Request a snapshot of the whole document in the WebView. The 1201 // result should be different from the size obtained previously. 1202 surface2 = test->waitForSnapshot(WEBKIT_SNAPSHOT_REGION_FULL_DOCUMENT, WEBKIT_SNAPSHOT_OPTIONS_NONE); 1203 g_assert(surface2); 1204 g_assert_cmpint(cairo_image_surface_get_width(surface2), >, width); 1205 g_assert_cmpint(cairo_image_surface_get_height(surface2), >, height); 1206 g_assert(!cairoSurfacesEqual(surface1, surface2)); 1207 1208 cairo_surface_destroy(surface1); 1209 cairo_surface_destroy(surface2); 1210 1211 g_assert(test->getSnapshotAndCancel()); 1212 } 1213 1085 1214 void beforeAll() 1086 1215 { … … 1103 1232 SaveWebViewTest::add("WebKitWebView", "save", testWebViewSave); 1104 1233 WebViewTest::add("WebKitWebView", "view-mode", testWebViewMode); 1234 SnapshotWebViewTest::add("WebKitWebView", "snapshot", testWebViewSnapshot); 1105 1235 } 1106 1236 -
releases/WebKitGTK/webkit-2.0/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp
r130755 r145358 199 199 } 200 200 201 void WebViewTest::selectAll() 202 { 203 webkit_web_view_execute_editing_command(m_webView, "SelectAll"); 204 } 205 201 206 static void resourceGetDataCallback(GObject* object, GAsyncResult* result, gpointer userData) 202 207 { -
releases/WebKitGTK/webkit-2.0/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h
r130755 r145358 49 49 void showInWindowAndWaitUntilMapped(GtkWindowType = GTK_WINDOW_POPUP); 50 50 void resizeView(int width, int height); 51 void selectAll(); 51 52 const char* mainResourceData(size_t& mainResourceDataSize); 52 53 -
releases/WebKitGTK/webkit-2.0/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebExtension.cpp
r141102 r145358 21 21 #include "WebKitWebExtension.h" 22 22 23 #include "FrameView.h" 24 #include "ImageOptions.h" 23 25 #include "ImmutableDictionary.h" 24 26 #include "WKBundleAPICast.h" 25 27 #include "WKBundlePage.h" 28 #include "WebImage.h" 26 29 #include "WebKitPrivate.h" 27 30 #include "WebKitWebExtensionPrivate.h" 28 31 #include "WebKitWebPagePrivate.h" 32 #include "WebProcess.h" 29 33 #include <WebCore/DNS.h> 30 34 #include <wtf/HashMap.h> … … 90 94 } 91 95 96 static void webkitWebExtensionDidReceiveMessageToPage(WebKitWebExtension* extension, WebPage* page, const String& messageName, ImmutableDictionary& message) 97 { 98 if (messageName == String("GetSnapshot")) { 99 SnapshotOptions snapshotOptions = static_cast<SnapshotOptions>(static_cast<WebUInt64*>(message.get(String::fromUTF8("SnapshotOptions")))->value()); 100 uint64_t callbackID = static_cast<WebUInt64*>(message.get("CallbackID"))->value(); 101 SnapshotRegion region = static_cast<SnapshotRegion>(static_cast<WebUInt64*>(message.get("SnapshotRegion"))->value()); 102 103 RefPtr<WebImage> snapshotImage; 104 105 if (WebCore::FrameView* frameView = page->mainFrameView()) { 106 WebCore::IntRect snapshotRect; 107 switch (region) { 108 case SnapshotRegionVisible: 109 snapshotRect = frameView->visibleContentRect(WebCore::ScrollableArea::ExcludeScrollbars); 110 break; 111 case SnapshotRegionFullDocument: 112 snapshotRect = WebCore::IntRect(WebCore::IntPoint(0, 0), frameView->contentsSize()); 113 break; 114 default: 115 ASSERT_NOT_REACHED(); 116 } 117 if (!snapshotRect.isEmpty()) 118 snapshotImage = page->scaledSnapshotWithOptions(snapshotRect, 1, snapshotOptions | SnapshotOptionsShareable); 119 } 120 121 ImmutableDictionary::MapType messageReply; 122 messageReply.set("Page", page); 123 messageReply.set("CallbackID", WebUInt64::create(callbackID)); 124 messageReply.set("Snapshot", snapshotImage); 125 WebProcess::shared().injectedBundle()->postMessage("WebPage.DidGetSnapshot", ImmutableDictionary::adopt(messageReply).get()); 126 } else 127 ASSERT_NOT_REACHED(); 128 } 129 92 130 static void didCreatePage(WKBundleRef bundle, WKBundlePageRef page, const void* clientInfo) 93 131 { … … 106 144 } 107 145 146 static void didReceiveMessageToPage(WKBundleRef bundle, WKBundlePageRef page, WKStringRef name, WKTypeRef messageBody, const void* clientInfo) 147 { 148 ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID()); 149 webkitWebExtensionDidReceiveMessageToPage(WEBKIT_WEB_EXTENSION(clientInfo), toImpl(page), toImpl(name)->string(), *toImpl(static_cast<WKDictionaryRef>(messageBody))); 150 } 151 108 152 WebKitWebExtension* webkitWebExtensionCreate(InjectedBundle* bundle) 109 153 { … … 117 161 0, // didInitializePageGroup 118 162 didReceiveMessage, 119 0 //didReceiveMessageToPage163 didReceiveMessageToPage 120 164 }; 121 165 WKBundleSetClient(toAPI(bundle), &wkBundleClient);
Note:
See TracChangeset
for help on using the changeset viewer.