Title: [152446] trunk/Source
Revision
152446
Author
[email protected]
Date
2013-07-08 03:13:06 -0700 (Mon, 08 Jul 2013)

Log Message

[GTK] FrameLoaderClient: Refactor naked pointers to use smart pointers
https://bugs.webkit.org/show_bug.cgi?id=118417

Patch by Brian Holt <[email protected]> on 2013-07-08
Reviewed by Carlos Garcia Campos.

Use GOwnPtr and GRefPtr where possible.

* WebCoreSupport/FrameLoaderClientGtk.cpp:
(WebKit::FrameLoaderClient::dispatchDidFailLoad):

Modified Paths

Diff

Modified: trunk/Source/WebCore/platform/gtk/SharedBufferGtk.cpp (152445 => 152446)


--- trunk/Source/WebCore/platform/gtk/SharedBufferGtk.cpp	2013-07-08 09:02:51 UTC (rev 152445)
+++ trunk/Source/WebCore/platform/gtk/SharedBufferGtk.cpp	2013-07-08 10:13:06 UTC (rev 152446)
@@ -20,6 +20,7 @@
 #include "SharedBuffer.h"
 
 #include "FileSystem.h"
+#include <wtf/gobject/GOwnPtr.h>
 #include <wtf/text/CString.h>
 
 #include <glib.h>
@@ -33,17 +34,15 @@
         return 0;
 
     CString filename = fileSystemRepresentation(filePath);
-    gchar* contents;
+    GOwnPtr<gchar> contents;
     gsize size;
-    GError* error = 0;
-    if (!g_file_get_contents(filename.data(), &contents, &size, &error)) {
+    GOwnPtr<GError> error;
+    if (!g_file_get_contents(filename.data(), &contents.outPtr(), &size, &error.outPtr())) {
         LOG_ERROR("Failed to fully read contents of file %s - %s", filenameForDisplay(filePath).utf8().data(), error->message);
-        g_error_free(error);
         return 0;
     }
 
-    RefPtr<SharedBuffer> result = SharedBuffer::create(contents, size);
-    g_free(contents);
+    RefPtr<SharedBuffer> result = SharedBuffer::create(contents.get(), size);
 
     return result.release();
 }

Modified: trunk/Source/WebKit/gtk/ChangeLog (152445 => 152446)


--- trunk/Source/WebKit/gtk/ChangeLog	2013-07-08 09:02:51 UTC (rev 152445)
+++ trunk/Source/WebKit/gtk/ChangeLog	2013-07-08 10:13:06 UTC (rev 152446)
@@ -1,3 +1,15 @@
+2013-07-08  Brian Holt  <[email protected]>
+
+        [GTK] FrameLoaderClient: Refactor naked pointers to use smart pointers
+        https://bugs.webkit.org/show_bug.cgi?id=118417
+
+        Reviewed by Carlos Garcia Campos.
+
+        Use GOwnPtr and GRefPtr where possible.
+
+        * WebCoreSupport/FrameLoaderClientGtk.cpp:
+        (WebKit::FrameLoaderClient::dispatchDidFailLoad):
+
 2013-07-04  Mario Sanchez Prada  <[email protected]>
 
         [ATK] Do not expose '\n' for wrapped lines with ATK_TEXT_BOUNDARY_CHAR

Modified: trunk/Source/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp (152445 => 152446)


--- trunk/Source/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp	2013-07-08 09:02:51 UTC (rev 152445)
+++ trunk/Source/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp	2013-07-08 10:13:06 UTC (rev 152446)
@@ -1065,50 +1065,33 @@
     notifyStatus(m_frame, WEBKIT_LOAD_FAILED);
 
     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());
+    GOwnPtr<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);
+    g_signal_emit_by_name(webView, "load-error", m_frame, error.failingURL().utf8().data(), webError.get(), &isHandled);
 
-    if (isHandled) {
-        g_error_free(webError);
+    if (isHandled || !shouldFallBack(error))
         return;
-    }
 
-    if (!shouldFallBack(error)) {
-        g_error_free(webError);
-        return;
-    }
-
     m_loadingErrorPage = true;
 
     String content;
-    gchar* fileContent = 0;
     GOwnPtr<gchar> errorPath(g_build_filename(sharedResourcesPath().data(), "resources", "error.html", NULL));
-    gchar* errorURI = g_filename_to_uri(errorPath.get(), 0, 0);
+    GRefPtr<GFile> errorFile = adoptGRef(g_file_new_for_path(errorPath.get()));
 
-    GFile* errorFile = g_file_new_for_uri(errorURI);
-    g_free(errorURI);
-
     if (!errorFile)
         content = makeString("<html><body>", webError->message, "</body></html>");
     else {
-        gboolean loaded = g_file_load_contents(errorFile, 0, &fileContent, 0, 0, 0);
-        if (!loaded)
+        GOwnPtr<gchar> fileContent;
+        if (!g_file_load_contents(errorFile.get(), 0, &fileContent.outPtr(), 0, 0, 0))
             content = makeString("<html><body>", webError->message, "</body></html>");
         else
-            content = String::format(fileContent, error.failingURL().utf8().data(), webError->message);
+            content = String::format(fileContent.get(), error.failingURL().utf8().data(), webError->message);
     }
 
     webkit_web_frame_load_alternate_string(m_frame, content.utf8().data(), 0, error.failingURL().utf8().data());
-
-    g_free(fileContent);
-
-    if (errorFile)
-        g_object_unref(errorFile);
-
-    g_error_free(webError);
 }
 
 void FrameLoaderClient::convertMainResourceLoadToDownload(WebCore::DocumentLoader* documentLoader, const ResourceRequest& request, const ResourceResponse& response)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to