Hello all,

       Here is one of the ways to send the error signal to the upper layer from
the webkit core codes. Basically I just comment out the
ASSERT code in DocumentLoader::mainReceiveError()
and emit a GTK signal (error-load-page) in the
FrameLoaderClientGtk::shouldFallBack.
with the corresponding error code from Curl. So the main application
could just subscribe
the signal error-load-page, do error handling when the signal callback.

However, as I am new to webkit, I am not sure if it is the proper way
to fire event in this
particular method. Or someone could show me a better way to do it.

    Please note my webkit build is using r41053, GTK+ and Curl backend.
    Enjoy!

Regards,
Jenson

>Hi all
>How can I do error handling in webkit? Suppose I have given wrong URL then
>how can I show proper message? How can I handle this situation?Can you give
>sample example?
>
>Thanks in advance..
>
>Regards,
>Nitin Walke
Index: WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp
===================================================================
--- WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp	(revision 41053)
+++ WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp	(working copy)
@@ -803,9 +803,12 @@
     return ResourceError("", 0, "", "");
 }
 
-bool FrameLoaderClient::shouldFallBack(const ResourceError&)
+bool FrameLoaderClient::shouldFallBack(const ResourceError& error)
 {
-    notImplemented();
+    //notImplemented();
+    gint errorCode = error.errorCode();
+    WebKitWebView* webView = getViewFromFrame(m_frame);
+    g_signal_emit_by_name(webView, "error-load-page", (gpointer)&errorCode);
     return false;
 }
 
Index: WebKit/gtk/webkit/webkitwebview.cpp
===================================================================
--- WebKit/gtk/webkit/webkitwebview.cpp	(revision 41053)
+++ WebKit/gtk/webkit/webkitwebview.cpp	(working copy)
@@ -132,6 +132,7 @@
     COPY_CLIPBOARD,
     PASTE_CLIPBOARD,
     CUT_CLIPBOARD,
+    ERROR_LOAD_PAGE,
     LAST_SIGNAL
 };
 
@@ -1376,6 +1377,24 @@
             g_cclosure_marshal_VOID__VOID,
             G_TYPE_NONE, 0);
 
+    /**
+      * WebKitWebView::error-load-page:
+      * @web_view: the object which received the signal
+      *
+      * The #WebKitWebView::error-load-page signal is a signal which
+      * gets emitted when there is error when loading the page.
+      *
+      */
+     webkit_web_view_signals[ERROR_LOAD_PAGE] = g_signal_new("error-load-page",
+             G_TYPE_FROM_CLASS(webViewClass),
+             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
+             0,
+             NULL,
+             NULL,
+             g_cclosure_marshal_VOID__INT,
+             G_TYPE_NONE,1,
+             G_TYPE_INT);
+
     /*
      * implementations of virtual methods
      */
Index: WebCore/platform/network/curl/ResourceHandleManager.cpp
===================================================================
--- WebCore/platform/network/curl/ResourceHandleManager.cpp	(revision 41053)
+++ WebCore/platform/network/curl/ResourceHandleManager.cpp	(working copy)
@@ -325,8 +325,10 @@
             curl_easy_getinfo(d->m_handle, CURLINFO_EFFECTIVE_URL, &url);
             fprintf(stderr, "Curl ERROR for url='%s', error: '%s'\n", url, curl_easy_strerror(msg->data.result));
 #endif
-            if (d->client())
-                d->client()->didFail(job, ResourceError());
+            if (d->client()) {
+                ResourceError error = ResourceError(String(), (int)msg->data.result, String(), String());
+                d->client()->didFail(job, error);
+            }
         }
 
         removeFromCurl(job);
Index: WebCore/loader/DocumentLoader.cpp
===================================================================
--- WebCore/loader/DocumentLoader.cpp	(revision 41053)
+++ WebCore/loader/DocumentLoader.cpp	(working copy)
@@ -255,7 +255,7 @@
 
 void DocumentLoader::mainReceivedError(const ResourceError& error, bool isComplete)
 {
-    ASSERT(!error.isNull());
+    //ASSERT(!error.isNull());
 
 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
     ApplicationCacheGroup* group = m_candidateApplicationCacheGroup;
Index: WebKitTools/GtkLauncher/main.c
===================================================================
--- WebKitTools/GtkLauncher/main.c	(revision 41053)
+++ WebKitTools/GtkLauncher/main.c	(working copy)
@@ -65,6 +65,13 @@
 }
 
 static void
+error_load_page_cb (WebKitWebView* page, gpointer data)
+{
+	gint *error= (gint *)data;
+	g_printf("Error loading page, return:[%d]\n", *error);
+}
+
+static void
 title_change_cb (WebKitWebView* web_view, WebKitWebFrame* web_frame, const gchar* title, gpointer data)
 {
     if (main_title)
@@ -119,6 +126,7 @@
     g_signal_connect (G_OBJECT (web_view), "load-progress-changed", G_CALLBACK (progress_change_cb), web_view);
     g_signal_connect (G_OBJECT (web_view), "load-committed", G_CALLBACK (load_commit_cb), web_view);
     g_signal_connect (G_OBJECT (web_view), "hovering-over-link", G_CALLBACK (link_hover_cb), web_view);
+    g_signal_connect (G_OBJECT (web_view), "error-load-page", G_CALLBACK (error_load_page_cb), web_view);
 
     return scrolled_window;
 }
_______________________________________________
webkit-dev mailing list
webkit-dev@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev

Reply via email to