Bug 118417 - [GTK] FrameLoaderClient: Refactor naked pointers to use smart pointers
Summary: [GTK] FrameLoaderClient: Refactor naked pointers to use smart pointers
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Page Loading (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-07-05 08:33 PDT by Brian Holt
Modified: 2013-07-08 03:14 PDT (History)
8 users (show)

See Also:


Attachments
Patch (3.80 KB, patch)
2013-07-05 08:38 PDT, Brian Holt
no flags Details | Formatted Diff | Diff
Patch (3.80 KB, patch)
2013-07-05 08:57 PDT, Brian Holt
no flags Details | Formatted Diff | Diff
Revised patch (5.03 KB, patch)
2013-07-08 01:36 PDT, Brian Holt
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Brian Holt 2013-07-05 08:33:26 PDT
FrameLoaderClient::dispatchDidFailLoad(const ResourceError& error) has a number of naked pointers that should be refactored to use smart pointers.
Comment 1 Brian Holt 2013-07-05 08:38:42 PDT
Created attachment 206155 [details]
Patch
Comment 2 Brian Holt 2013-07-05 08:45:29 PDT
This fix was motivated after looking for other areas in the codebase that may have memory leaks.  There are no leaks in this function, however with this refactoring any changes in the future are less likely to introduce unexpected errors.

I have run the gtk tests and can confirm that they pass after this change.
Comment 3 Mario Sanchez Prada 2013-07-05 08:49:01 PDT
Comment on attachment 206155 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=206155&action=review

Good patch. I've just added a couple of minor comments as an informal review.

> Source/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp:1075
> +    if (isHandled || !shouldFallBack(error)) {

You don't need that extra { now you got a single line if

> Source/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp:1084
> +    GRefPtr<GFile> errorFile(adoptGRef(g_file_new_for_uri(errorURI.get())));

We normally use the = assignment for this kind of statments:

 GRefPtr<GFile> errorFile = adoptGRef(g_file_new_for_uri(errorURI.get()));
Comment 4 Brian Holt 2013-07-05 08:57:03 PDT
Created attachment 206157 [details]
Patch
Comment 5 Chris Dumez 2013-07-05 09:07:17 PDT
Comment on attachment 206157 [details]
Patch

Looks fine. r=me.
Comment 6 Carlos Garcia Campos 2013-07-05 09:10:07 PDT
Comment on attachment 206157 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=206157&action=review

> Source/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp:1083
> +    GOwnPtr<gchar> errorURI(g_filename_to_uri(errorPath.get(), 0, 0));
> +    GRefPtr<GFile> errorFile = adoptGRef(g_file_new_for_uri(errorURI.get()));

I know the code was already that way, but I wondering why we need to convert the path to uri instead of using g_file_new_for_path() directly, if it's possible we could take advantage that you are changing this code to improve this too.

> Source/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp:1091
> +        gboolean loaded = g_file_load_contents(errorFile.get(), 0, &fileContent.outPtr(), 0, 0, 0);
>          if (!loaded)
>              content = makeString("<html><body>", webError->message, "</body></html>");

You can probably do if (!g_file_load_contents(errorFile.get(), 0, &fileContent.outPtr(), 0, 0, 0)) and you don't need the local variable that is only used for this.
Comment 7 Carlos Garcia Campos 2013-07-05 09:10:56 PDT
Oops, I didn't mean to change the flag, please feel free to r+ it again, sorry.
Comment 8 Chris Dumez 2013-07-05 09:15:38 PDT
(In reply to comment #7)
> Oops, I didn't mean to change the flag, please feel free to r+ it again, sorry.

It's fine. Since you have comments, I'll let you handle this one :)
Comment 9 Brian Holt 2013-07-08 01:25:43 PDT
Comment on attachment 206157 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=206157&action=review

>> Source/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp:1083
>> +    GRefPtr<GFile> errorFile = adoptGRef(g_file_new_for_uri(errorURI.get()));
> 
> I know the code was already that way, but I wondering why we need to convert the path to uri instead of using g_file_new_for_path() directly, if it's possible we could take advantage that you are changing this code to improve this too.

Good point, I wasn't really focusing on simplifying the logic but it makes sense to do so now.

>> Source/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp:1091
>>              content = makeString("<html><body>", webError->message, "</body></html>");
> 
> You can probably do if (!g_file_load_contents(errorFile.get(), 0, &fileContent.outPtr(), 0, 0, 0)) and you don't need the local variable that is only used for this.

ok
Comment 10 Brian Holt 2013-07-08 01:36:19 PDT
Created attachment 206223 [details]
Revised patch
Comment 11 Carlos Garcia Campos 2013-07-08 02:08:53 PDT
Comment on attachment 206223 [details]
Revised patch

Thanks!
Comment 12 Brian Holt 2013-07-08 02:14:59 PDT
Comment on attachment 206223 [details]
Revised patch

Would you mind setting cg+ ?
Comment 13 WebKit Commit Bot 2013-07-08 03:13:58 PDT
Comment on attachment 206223 [details]
Revised patch

Clearing flags on attachment: 206223

Committed r152446: <http://trac.webkit.org/changeset/152446>
Comment 14 WebKit Commit Bot 2013-07-08 03:14:03 PDT
All reviewed patches have been landed.  Closing bug.