diff options
author | Simon Hausmann <simon.hausmann@nokia.com> | 2012-05-25 15:09:11 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2012-05-25 15:09:11 +0200 |
commit | a89b2ebb8e192c5e8cea21079bda2ee2c0c7dddd (patch) | |
tree | b7abd9f49ae1d4d2e426a5883bfccd42b8e2ee12 /Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp | |
parent | 8d473cf9743f1d30a16a27114e93bd5af5648d23 (diff) | |
download | qtwebkit-a89b2ebb8e192c5e8cea21079bda2ee2c0c7dddd.tar.gz |
Imported WebKit commit eb5c1b8fe4d4b1b90b5137433fc58a91da0e6878 (http://svn.webkit.org/repository/webkit/trunk@118516)
Diffstat (limited to 'Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp')
-rw-r--r-- | Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp | 79 |
1 files changed, 69 insertions, 10 deletions
diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp index 56b21df49..65dab6ec2 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp @@ -37,6 +37,7 @@ #include "WebKitSettingsPrivate.h" #include "WebKitUIClient.h" #include "WebKitWebContextPrivate.h" +#include "WebKitWebInspectorPrivate.h" #include "WebKitWebResourcePrivate.h" #include "WebKitWebViewBasePrivate.h" #include "WebKitWebViewPrivate.h" @@ -120,6 +121,8 @@ struct _WebKitWebViewPrivate { GRefPtr<WebKitWebResource> mainResource; LoadingResourcesMap loadingResourcesMap; ResourcesMap subresourcesMap; + + GRefPtr<WebKitWebInspector> inspector; }; static guint signals[LAST_SIGNAL] = { 0, }; @@ -1618,10 +1621,21 @@ gdouble webkit_web_view_get_zoom_level(WebKitWebView* webView) return zoomTextOnly ? WKPageGetTextZoomFactor(wkPage) : WKPageGetPageZoomFactor(wkPage); } +struct ValidateEditingCommandAsyncData { + bool isEnabled; + GRefPtr<GCancellable> cancellable; +}; +WEBKIT_DEFINE_ASYNC_DATA_STRUCT(ValidateEditingCommandAsyncData) + static void didValidateCommand(WKStringRef command, bool isEnabled, int32_t state, WKErrorRef, void* context) { GRefPtr<GSimpleAsyncResult> result = adoptGRef(G_SIMPLE_ASYNC_RESULT(context)); - g_simple_async_result_set_op_res_gboolean(result.get(), isEnabled); + ValidateEditingCommandAsyncData* data = static_cast<ValidateEditingCommandAsyncData*>(g_simple_async_result_get_op_res_gpointer(result.get())); + GError* error = 0; + if (g_cancellable_set_error_if_cancelled(data->cancellable.get(), &error)) + g_simple_async_result_take_error(result.get(), error); + else + data->isEnabled = isEnabled; g_simple_async_result_complete(result.get()); } @@ -1629,6 +1643,7 @@ static void didValidateCommand(WKStringRef command, bool isEnabled, int32_t stat * webkit_web_view_can_execute_editing_command: * @web_view: a #WebKitWebView * @command: the command to check + * @cancellable: (allow-none): a #GCancellable or %NULL to ignore * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied * @user_data: (closure): the data to pass to callback function * @@ -1637,13 +1652,17 @@ static void didValidateCommand(WKStringRef command, bool isEnabled, int32_t stat * When the operation is finished, @callback will be called. You can then call * webkit_web_view_can_execute_editing_command_finish() to get the result of the operation. */ -void webkit_web_view_can_execute_editing_command(WebKitWebView* webView, const char* command, GAsyncReadyCallback callback, gpointer userData) +void webkit_web_view_can_execute_editing_command(WebKitWebView* webView, const char* command, GCancellable* cancellable, GAsyncReadyCallback callback, gpointer userData) { g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); g_return_if_fail(command); GSimpleAsyncResult* result = g_simple_async_result_new(G_OBJECT(webView), callback, userData, reinterpret_cast<gpointer>(webkit_web_view_can_execute_editing_command)); + ValidateEditingCommandAsyncData* data = createValidateEditingCommandAsyncData(); + data->cancellable = cancellable; + g_simple_async_result_set_op_res_gpointer(result, data, reinterpret_cast<GDestroyNotify>(destroyValidateEditingCommandAsyncData)); + WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView)); WKRetainPtr<WKStringRef> wkCommand(AdoptWK, WKStringCreateWithUTF8CString(command)); WKPageValidateCommand(toAPI(page), wkCommand.get(), result, didValidateCommand); @@ -1669,7 +1688,9 @@ gboolean webkit_web_view_can_execute_editing_command_finish(WebKitWebView* webVi if (g_simple_async_result_propagate_error(simple, error)) return FALSE; - return g_simple_async_result_get_op_res_gboolean(simple); + + ValidateEditingCommandAsyncData* data = static_cast<ValidateEditingCommandAsyncData*>(g_simple_async_result_get_op_res_gpointer(simple)); + return data->isEnabled; } /** @@ -1730,15 +1751,29 @@ JSGlobalContextRef webkit_web_view_get_javascript_global_context(WebKitWebView* return webView->priv->javascriptGlobalContext; } +struct RunJavaScriptAsyncData { + ~RunJavaScriptAsyncData() + { + if (scriptResult) + webkit_javascript_result_unref(scriptResult); + } + + WebKitJavascriptResult* scriptResult; + GRefPtr<GCancellable> cancellable; +}; +WEBKIT_DEFINE_ASYNC_DATA_STRUCT(RunJavaScriptAsyncData) + static void webkitWebViewRunJavaScriptCallback(WKSerializedScriptValueRef wkSerializedScriptValue, WKErrorRef, void* context) { GRefPtr<GSimpleAsyncResult> result = adoptGRef(G_SIMPLE_ASYNC_RESULT(context)); - if (wkSerializedScriptValue) { + RunJavaScriptAsyncData* data = static_cast<RunJavaScriptAsyncData*>(g_simple_async_result_get_op_res_gpointer(result.get())); + GError* error = 0; + if (g_cancellable_set_error_if_cancelled(data->cancellable.get(), &error)) + g_simple_async_result_take_error(result.get(), error); + else if (wkSerializedScriptValue) { GRefPtr<WebKitWebView> webView = adoptGRef(WEBKIT_WEB_VIEW(g_async_result_get_source_object(G_ASYNC_RESULT(result.get())))); - WebKitJavascriptResult* scriptResult = webkitJavascriptResultCreate(webView.get(), wkSerializedScriptValue); - g_simple_async_result_set_op_res_gpointer(result.get(), scriptResult, reinterpret_cast<GDestroyNotify>(webkit_javascript_result_unref)); + data->scriptResult = webkitJavascriptResultCreate(webView.get(), wkSerializedScriptValue); } else { - GError* error = 0; g_set_error_literal(&error, WEBKIT_JAVASCRIPT_ERROR, WEBKIT_JAVASCRIPT_ERROR_SCRIPT_FAILED, _("An exception was raised in JavaScript")); g_simple_async_result_take_error(result.get(), error); } @@ -1749,6 +1784,7 @@ static void webkitWebViewRunJavaScriptCallback(WKSerializedScriptValueRef wkSeri * webkit_web_view_run_javascript: * @web_view: a #WebKitWebView * @script: the script to run + * @cancellable: (allow-none): a #GCancellable or %NULL to ignore * @callback: (scope async): a #GAsyncReadyCallback to call when the script finished * @user_data: (closure): the data to pass to callback function * @@ -1757,7 +1793,7 @@ static void webkitWebViewRunJavaScriptCallback(WKSerializedScriptValueRef wkSeri * When the operation is finished, @callback will be called. You can then call * webkit_web_view_run_javascript_finish() to get the result of the operation. */ -void webkit_web_view_run_javascript(WebKitWebView* webView, const gchar* script, GAsyncReadyCallback callback, gpointer userData) +void webkit_web_view_run_javascript(WebKitWebView* webView, const gchar* script, GCancellable* cancellable, GAsyncReadyCallback callback, gpointer userData) { g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); g_return_if_fail(script); @@ -1766,6 +1802,9 @@ void webkit_web_view_run_javascript(WebKitWebView* webView, const gchar* script, WKRetainPtr<WKStringRef> wkScript = adoptWK(WKStringCreateWithUTF8CString(script)); GSimpleAsyncResult* result = g_simple_async_result_new(G_OBJECT(webView), callback, userData, reinterpret_cast<gpointer>(webkit_web_view_run_javascript)); + RunJavaScriptAsyncData* data = createRunJavaScriptAsyncData(); + data->cancellable = cancellable; + g_simple_async_result_set_op_res_gpointer(result, data, reinterpret_cast<GDestroyNotify>(destroyRunJavaScriptAsyncData)); WKPageRunJavaScriptInMainFrame(wkPage, wkScript.get(), result, webkitWebViewRunJavaScriptCallback); } @@ -1844,8 +1883,8 @@ WebKitJavascriptResult* webkit_web_view_run_javascript_finish(WebKitWebView* web if (g_simple_async_result_propagate_error(simpleResult, error)) return 0; - WebKitJavascriptResult* scriptResult = static_cast<WebKitJavascriptResult*>(g_simple_async_result_get_op_res_gpointer(simpleResult)); - return scriptResult ? webkit_javascript_result_ref(scriptResult) : 0; + RunJavaScriptAsyncData* data = static_cast<RunJavaScriptAsyncData*>(g_simple_async_result_get_op_res_gpointer(simpleResult)); + return data->scriptResult ? webkit_javascript_result_ref(data->scriptResult) : 0; } /** @@ -1886,3 +1925,23 @@ GList* webkit_web_view_get_subresources(WebKitWebView* webView) return g_list_reverse(subresources); } + +/** + * webkit_web_view_get_inspector: + * @web_view: a #WebKitWebView + * + * Get the #WebKitWebInspector associated to @web_view + * + * Returns: (transfer none): the #WebKitWebInspector of @web_view + */ +WebKitWebInspector* webkit_web_view_get_inspector(WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 0); + + if (!webView->priv->inspector) { + WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView)); + webView->priv->inspector = adoptGRef(webkitWebInspectorCreate(toAPI(page->inspector()))); + } + + return webView->priv->inspector.get(); +} |