Commit 5757029f authored by jmalonzo@webkit.org's avatar jmalonzo@webkit.org

2009-04-25 Jan Michael Alonzo <jmalonzo@webkit.org>

         Reviewed by Xan Lopez.

         [GTK] Error reporting
         https://bugs.webkit.org/show_bug.cgi?id=18344

         Add a WebKitWebFrame API to load alternate content for unreachable URLs.
         Also add a new signal "load-error" for handling load errors.

         * WebCoreSupport/FrameLoaderClientGtk.cpp:
         (WebKit::FrameLoaderClient::postProgressFinishedNotification):
         (WebKit::FrameLoaderClient::dispatchDidFailLoading):
         (WebKit::FrameLoaderClient::dispatchDidFailProvisionalLoad):
         (WebKit::FrameLoaderClient::dispatchDidFailLoad):
         * webkit/webkitwebframe.cpp:
         * webkit/webkitwebframe.h:
         * webkit/webkitwebview.cpp:

git-svn-id: svn://svn.chromium.org/blink/trunk@42864 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent ddc4a7b5
2009-04-25 Jan Michael Alonzo <jmalonzo@webkit.org>
Reviewed by Xan Lopez.
[GTK] Error reporting
https://bugs.webkit.org/show_bug.cgi?id=18344
Add a WebKitWebFrame API to load alternate content for unreachable URLs.
Also add a new signal "load-error" for handling load errors.
* WebCoreSupport/FrameLoaderClientGtk.cpp:
(WebKit::FrameLoaderClient::postProgressFinishedNotification):
(WebKit::FrameLoaderClient::dispatchDidFailLoading):
(WebKit::FrameLoaderClient::dispatchDidFailProvisionalLoad):
(WebKit::FrameLoaderClient::dispatchDidFailLoad):
* webkit/webkitwebframe.cpp:
* webkit/webkitwebframe.h:
* webkit/webkitwebview.cpp:
2009-04-24 Jan Michael Alonzo <jmalonzo@webkit.org> 2009-04-24 Jan Michael Alonzo <jmalonzo@webkit.org>
Rubber-stamped by Gustavo Noronha. Rubber-stamped by Gustavo Noronha.
......
...@@ -57,6 +57,7 @@ ...@@ -57,6 +57,7 @@
#include "webkitprivate.h" #include "webkitprivate.h"
#include <JavaScriptCore/APICast.h> #include <JavaScriptCore/APICast.h>
#include <glib.h>
#include <stdio.h> #include <stdio.h>
#if PLATFORM(UNIX) #if PLATFORM(UNIX)
#include <sys/utsname.h> #include <sys/utsname.h>
...@@ -811,8 +812,9 @@ void FrameLoaderClient::dispatchDidFinishLoading(DocumentLoader*, unsigned long ...@@ -811,8 +812,9 @@ void FrameLoaderClient::dispatchDidFinishLoading(DocumentLoader*, unsigned long
notImplemented(); notImplemented();
} }
void FrameLoaderClient::dispatchDidFailLoading(DocumentLoader*, unsigned long identifier, const ResourceError&) void FrameLoaderClient::dispatchDidFailLoading(DocumentLoader*, unsigned long identifier, const ResourceError& error)
{ {
// FIXME: when does this occur and what should happen?
notImplemented(); notImplemented();
} }
...@@ -822,13 +824,35 @@ bool FrameLoaderClient::dispatchDidLoadResourceFromMemoryCache(DocumentLoader*, ...@@ -822,13 +824,35 @@ bool FrameLoaderClient::dispatchDidLoadResourceFromMemoryCache(DocumentLoader*,
return false; return false;
} }
void FrameLoaderClient::dispatchDidFailProvisionalLoad(const ResourceError&) void FrameLoaderClient::dispatchDidFailProvisionalLoad(const ResourceError& error)
{ {
dispatchDidFailLoad(error);
// FIXME: load-done is deprecated. Please remove when signal's been removed.
g_signal_emit_by_name(m_frame, "load-done", false); g_signal_emit_by_name(m_frame, "load-done", false);
} }
void FrameLoaderClient::dispatchDidFailLoad(const ResourceError&) void FrameLoaderClient::dispatchDidFailLoad(const ResourceError& error)
{ {
WebKitWebView* webView = getViewFromFrame(m_frame);
GError* webError = g_error_new_literal(g_quark_from_string(error.domain().utf8().data()),
error.errorCode(),
error.localizedDescription().utf8().data());
gboolean isHandled = false;
g_signal_emit_by_name(webView, "load-error", m_frame, error.failingURL().utf8().data(), webError, &isHandled);
if (isHandled) {
g_error_free(webError);
return;
}
String content = String::format("<html><head><title>%d</title></head><body>%s</body></html>",
error.errorCode(), webError->message);
webkit_web_frame_load_alternate_string(m_frame, content.utf8().data(),
NULL, error.failingURL().utf8().data());
g_error_free(webError);
// FIXME: load-done is deprecated. Please remove when signal's been removed.
g_signal_emit_by_name(m_frame, "load-done", false); g_signal_emit_by_name(m_frame, "load-done", false);
} }
......
...@@ -167,6 +167,15 @@ static void webkit_web_frame_class_init(WebKitWebFrameClass* frameClass) ...@@ -167,6 +167,15 @@ static void webkit_web_frame_class_init(WebKitWebFrameClass* frameClass)
g_cclosure_marshal_VOID__VOID, g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0); G_TYPE_NONE, 0);
/**
* WebKitWebFrame::load-done
* @web_frame: the object on which the signal is emitted
*
* Emitted when frame loading is done.
*
* Deprecated: Use WebKitWebView::load-finished instead, and/or
* WebKitWebView::load-error to be notified of load errors
*/
webkit_web_frame_signals[LOAD_DONE] = g_signal_new("load-done", webkit_web_frame_signals[LOAD_DONE] = g_signal_new("load-done",
G_TYPE_FROM_CLASS(frameClass), G_TYPE_FROM_CLASS(frameClass),
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
...@@ -398,6 +407,25 @@ void webkit_web_frame_load_uri(WebKitWebFrame* frame, const gchar* uri) ...@@ -398,6 +407,25 @@ void webkit_web_frame_load_uri(WebKitWebFrame* frame, const gchar* uri)
coreFrame->loader()->load(ResourceRequest(KURL(KURL(), String::fromUTF8(uri))), false); coreFrame->loader()->load(ResourceRequest(KURL(KURL(), String::fromUTF8(uri))), false);
} }
static void webkit_web_frame_load_data(WebKitWebFrame* frame, const gchar* content, const gchar* mimeType, const gchar* encoding, const gchar* baseURL, const gchar* unreachableURL)
{
Frame* coreFrame = core(frame);
ASSERT(coreFrame);
KURL baseKURL = baseURL ? KURL(KURL(), String::fromUTF8(baseURL)) : blankURL();
ResourceRequest request(baseKURL);
RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(content, g_utf8_strlen(content, -1));
SubstituteData substituteData(sharedBuffer.release(),
mimeType ? String::fromUTF8(mimeType) : String::fromUTF8("text/html"),
encoding ? String::fromUTF8(encoding) : String::fromUTF8("UTF-8"),
baseKURL,
KURL(KURL(), String::fromUTF8(unreachableURL)));
coreFrame->loader()->load(request, substituteData, false);
}
/** /**
* webkit_web_frame_load_string: * webkit_web_frame_load_string:
* @frame: a #WebKitWebFrame * @frame: a #WebKitWebFrame
...@@ -420,15 +448,28 @@ void webkit_web_frame_load_string(WebKitWebFrame* frame, const gchar* content, c ...@@ -420,15 +448,28 @@ void webkit_web_frame_load_string(WebKitWebFrame* frame, const gchar* content, c
g_return_if_fail(WEBKIT_IS_WEB_FRAME(frame)); g_return_if_fail(WEBKIT_IS_WEB_FRAME(frame));
g_return_if_fail(content); g_return_if_fail(content);
Frame* coreFrame = core(frame); webkit_web_frame_load_data(frame, content, contentMimeType, contentEncoding, baseUri, NULL);
if (!coreFrame) }
return;
KURL url(KURL(), baseUri ? String::fromUTF8(baseUri) : ""); /**
RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(content, strlen(content)); * webkit_web_frame_load_alternate_string:
SubstituteData substituteData(sharedBuffer.release(), contentMimeType ? String(contentMimeType) : "text/html", contentEncoding ? String(contentEncoding) : "UTF-8", blankURL(), url); * @frame: a #WebKitWebFrame
* @content: the alternate content to display as the main page of the @frame
* @base_url: the base URI for relative locations
* @unreachable_url: the URL for the alternate page content
*
* Request loading of an alternate content for a URL that is unreachable.
* Using this method will preserve the back-forward list. The URI passed in
* @base_url has to be an absolute URI.
*
* Since: 1.1.6
*/
void webkit_web_frame_load_alternate_string(WebKitWebFrame* frame, const gchar* content, const gchar* baseURL, const gchar* unreachableURL)
{
g_return_if_fail(WEBKIT_IS_WEB_FRAME(frame));
g_return_if_fail(content);
coreFrame->loader()->load(ResourceRequest(url), substituteData, false); webkit_web_frame_load_data(frame, content, NULL, NULL, baseURL, unreachableURL);
} }
/** /**
......
...@@ -93,6 +93,12 @@ webkit_web_frame_load_string (WebKitWebFrame *frame, ...@@ -93,6 +93,12 @@ webkit_web_frame_load_string (WebKitWebFrame *frame,
const gchar *encoding, const gchar *encoding,
const gchar *base_uri); const gchar *base_uri);
WEBKIT_API void
webkit_web_frame_load_alternate_string (WebKitWebFrame *frame,
const gchar *content,
const gchar *base_url,
const gchar *unreachable_url);
WEBKIT_API void WEBKIT_API void
webkit_web_frame_load_request (WebKitWebFrame *frame, webkit_web_frame_load_request (WebKitWebFrame *frame,
WebKitNetworkRequest *request); WebKitNetworkRequest *request);
......
...@@ -122,6 +122,7 @@ enum { ...@@ -122,6 +122,7 @@ enum {
LOAD_STARTED, LOAD_STARTED,
LOAD_COMMITTED, LOAD_COMMITTED,
LOAD_PROGRESS_CHANGED, LOAD_PROGRESS_CHANGED,
LOAD_ERROR,
LOAD_FINISHED, LOAD_FINISHED,
TITLE_CHANGED, TITLE_CHANGED,
HOVERING_OVER_LINK, HOVERING_OVER_LINK,
...@@ -1300,6 +1301,31 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass) ...@@ -1300,6 +1301,31 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass)
G_TYPE_NONE, 1, G_TYPE_NONE, 1,
G_TYPE_INT); G_TYPE_INT);
/**
* WebKitWebView::load-error
* @web_view: the object on which the signal is emitted
* @web_frame: the #WebKitWebFrame
* @uri: the URI that triggered the error
* @web_error: the #GError that was triggered
*
* An error occurred while loading. By default, if the signal is not
* handled, the @web_view will display a stock error page. You need to
* handle the signal if you want to provide your own error page.
*
* Since: 1.1.6
*/
webkit_web_view_signals[LOAD_ERROR] = g_signal_new("load-error",
G_TYPE_FROM_CLASS(webViewClass),
(GSignalFlags)(G_SIGNAL_RUN_LAST),
0,
g_signal_accumulator_true_handled,
NULL,
webkit_marshal_BOOLEAN__OBJECT_STRING_POINTER,
G_TYPE_BOOLEAN, 3,
WEBKIT_TYPE_WEB_FRAME,
G_TYPE_STRING,
G_TYPE_POINTER);
webkit_web_view_signals[LOAD_FINISHED] = g_signal_new("load-finished", webkit_web_view_signals[LOAD_FINISHED] = g_signal_new("load-finished",
G_TYPE_FROM_CLASS(webViewClass), G_TYPE_FROM_CLASS(webViewClass),
(GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment