Bug 19656

Summary: [SOUP] The gio code should call didFail() instead of didFinishLoading() in case of error
Product: WebKit Reporter: Marco Barisione <marco.barisione>
Component: WebKitGTKAssignee: Marco Barisione <marco.barisione>
Status: RESOLVED FIXED    
Severity: Normal    
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: PC   
OS: OS X 10.5   
Attachments:
Description Flags
Call didFail in case of error
eric: review-
Call didFail in case of error mrowe: review+

Description Marco Barisione 2008-06-18 08:45:44 PDT
At the moment ther gio code in the soup back-end call didFinishLoading() in case of error, this should be changed to didFail().
Comment 1 Marco Barisione 2008-06-18 09:01:06 PDT
Created attachment 21819 [details]
Call didFail in case of error
Comment 2 Eric Seidel (no email) 2008-08-02 01:11:00 PDT
Comment on attachment 21819 [details]
Call didFail in case of error

We really should have a GOwnPtr which knows how to call g_free on the associated pointer.  In that case:
      gchar* uri = g_file_get_uri (d->m_gfile);
 519         ResourceError resourceError("webkit-network-error", ERROR_TRANSPORT, uri, String::fromUTF8(error->message));
 520         g_free(uri);

would not need the g_free line.  Stupid c-style memory management.  Bleh.  (No offense to your code, I just have a general hatred towards languages and APIs which make it easy for you to stab yourself in the foot, or leak memory.)

WebKit style does not have a space between the function name and the (
+        gchar* uri = g_file_get_uri (d->m_gfile);

So we make 2 copies of the buffer just to send this URI off to ResourceError.  Is it possible to avoid this?

You should consider adding an inline function which created the resource error from the gfile handle and returned it to you.   That would eliminate 6 lines of copy-paste code.

Then these calls just become:

client->didFail(handle, networkErrorForFile(d->m_gfile, error));

static inline ResourceError networkErrorForFile(gfile* file, gerror* error)
{
    gchar* uri = g_file_get_uri(d->m_gfile);
    ResourceError resourceError("webkit-network-error", ERROR_TRANSPORT, uri, String::fromUTF8(error->message));
    g_free(uri);
   return resourceError;
}

r- for the style errors.  And I would encourage you to use a static inline to eliminate this copy-paste code.
Comment 3 Marco Barisione 2008-08-04 04:45:45 PDT
Created attachment 22629 [details]
Call didFail in case of error

Adding something like GOwnPtr and GObjectPtr could be a good idea but it's something for a separate patch.

"So we make 2 copies of the buffer just to send this URI off to ResourceError. 
Is it possible to avoid this?"

What do you mean? The copy from the GFile to a char and then to a String? In this case I don't see any solution.
Comment 4 Mark Rowe (bdash) 2008-08-19 22:15:31 PDT
Comment on attachment 22629 [details]
Call didFail in case of error

r=me
Comment 5 Jan Alonzo 2008-08-21 04:23:53 PDT
landed in r35872. Thanks for the patch and for the review!