Title: [96833] trunk/Source/WebKit2
Revision
96833
Author
[email protected]
Date
2011-10-06 11:03:11 -0700 (Thu, 06 Oct 2011)

Log Message

[GTK] Add estimated-progress property to WebKitWebLoaderClient
https://bugs.webkit.org/show_bug.cgi?id=69509

Reviewed by Martin Robinson.

It allows to monitor the estimated progress of a lof operation by
connecting to the notify signal.

* UIProcess/API/gtk/WebKitWebLoaderClient.cpp:
(didChangeProgress): Update estimated-progress property and notify when
it changes.
(webkitWebLoaderClientConstructed): Add implementations for
didStartProgress, didChangeProgress and didFinishProgress.
(webkitWebLoaderClientGetProperty):
(webkit_web_loader_client_class_init): Add estimated-progress property.
(webkit_web_loader_client_get_estimated_progress): Returns the
value of estimated-progress property.
* UIProcess/API/gtk/WebKitWebLoaderClient.h:
* UIProcess/API/gtk/tests/testloading.c:
(webLoadingFixtureSetup):
(loadProgressEstimatedProgressChanged):
(loadProgressLoadFinished):
(testLoadProgress):
(main):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (96832 => 96833)


--- trunk/Source/WebKit2/ChangeLog	2011-10-06 17:53:18 UTC (rev 96832)
+++ trunk/Source/WebKit2/ChangeLog	2011-10-06 18:03:11 UTC (rev 96833)
@@ -1,5 +1,32 @@
 2011-10-06  Carlos Garcia Campos  <[email protected]>
 
+        [GTK] Add estimated-progress property to WebKitWebLoaderClient
+        https://bugs.webkit.org/show_bug.cgi?id=69509
+
+        Reviewed by Martin Robinson.
+
+        It allows to monitor the estimated progress of a lof operation by
+        connecting to the notify signal.
+
+        * UIProcess/API/gtk/WebKitWebLoaderClient.cpp:
+        (didChangeProgress): Update estimated-progress property and notify when
+        it changes.
+        (webkitWebLoaderClientConstructed): Add implementations for
+        didStartProgress, didChangeProgress and didFinishProgress.
+        (webkitWebLoaderClientGetProperty):
+        (webkit_web_loader_client_class_init): Add estimated-progress property.
+        (webkit_web_loader_client_get_estimated_progress): Returns the
+        value of estimated-progress property.
+        * UIProcess/API/gtk/WebKitWebLoaderClient.h:
+        * UIProcess/API/gtk/tests/testloading.c:
+        (webLoadingFixtureSetup):
+        (loadProgressEstimatedProgressChanged):
+        (loadProgressLoadFinished):
+        (testLoadProgress):
+        (main):
+
+2011-10-06  Carlos Garcia Campos  <[email protected]>
+
         [GTK] Implement cache model for WebKit2
         https://bugs.webkit.org/show_bug.cgi?id=68434
 

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebLoaderClient.cpp (96832 => 96833)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebLoaderClient.cpp	2011-10-06 17:53:18 UTC (rev 96832)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebLoaderClient.cpp	2011-10-06 18:03:11 UTC (rev 96833)
@@ -46,11 +46,14 @@
 enum {
     PROP_0,
 
-    PROP_WEB_VIEW
+    PROP_WEB_VIEW,
+    PROP_ESTIMATED_PROGRESS
 };
 
 struct _WebKitWebLoaderClientPrivate {
     GRefPtr<WebKitWebView> view;
+
+    gdouble estimatedProgress;
 };
 
 static guint signals[LAST_SIGNAL] = { 0, };
@@ -121,6 +124,18 @@
                   webError.get(), &returnValue);
 }
 
+static void didChangeProgress(WKPageRef page, const void* clientInfo)
+{
+    WebKitWebLoaderClient* client = WEBKIT_WEB_LOADER_CLIENT(clientInfo);
+    gdouble estimatedProgress = WKPageGetEstimatedProgress(page);
+
+    if (client->priv->estimatedProgress == estimatedProgress)
+        return;
+
+    client->priv->estimatedProgress = estimatedProgress;
+    g_object_notify(G_OBJECT(clientInfo), "estimated-progress");
+}
+
 static void webkitWebLoaderClientConstructed(GObject* object)
 {
     WebKitWebLoaderClient* client = WEBKIT_WEB_LOADER_CLIENT(object);
@@ -145,9 +160,9 @@
         0,       // didRunInsecureContentForFrame
         0,       // canAuthenticateAgainstProtectionSpaceInFrame
         0,       // didReceiveAuthenticationChallengeInFrame
-        0,       // didStartProgress
-        0,       // didChangeProgress
-        0,       // didFinishProgress
+        didChangeProgress, // didStartProgress
+        didChangeProgress,
+        didChangeProgress, // didFinishProgress
         0,       // didBecomeUnresponsive
         0,       // didBecomeResponsive
         0,       // processDidCrash
@@ -193,6 +208,9 @@
     case PROP_WEB_VIEW:
         g_value_set_object(value, client->priv->view.get());
         break;
+    case PROP_ESTIMATED_PROGRESS:
+        g_value_set_double(value, webkit_web_loader_client_get_estimated_progress(client));
+        break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec);
     }
@@ -224,7 +242,7 @@
     clientClass->load_failed = webkitWebLoaderClientLoadFailed;
 
     /**
-     * WebKitWebView:web-view:
+     * WebKitWebLoaderClient:web-view:
      *
      * The #WebKitWebView of the loader client.
      */
@@ -235,6 +253,23 @@
                                                         "The web view for the loader client",
                                                         WEBKIT_TYPE_WEB_VIEW,
                                                         static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)));
+    /**
+     * WebKitWebLoaderClient:estimated-progress:
+     *
+     * An estimate of the percent completion for the current loading operation.
+     * This value will range from 0.0 to 1.0 and, once a load completes,
+     * will remain at 1.0 until a new load starts, at which point it
+     * will be reset to 0.0.
+     * The value is an estimate based on the total number of bytes expected
+     * to be received for a document, including all its possible subresources.
+     */
+    g_object_class_install_property(objectClass,
+                                    PROP_ESTIMATED_PROGRESS,
+                                    g_param_spec_double("estimated-progress",
+                                                        "Estimated Progress",
+                                                        "An estimate of the percent completion for a document load",
+                                                        0.0, 1.0, 0.0,
+                                                        WEBKIT_PARAM_READABLE));
 
     /**
      * WebKitWebLoaderClient::provisional-load-started:
@@ -383,3 +418,21 @@
 
     g_type_class_add_private(clientClass, sizeof(WebKitWebLoaderClientPrivate));
 }
+
+/**
+ * webkit_web_loader_client_get_estimated_progress:
+ * @client: a #WebKitWebLoaderClient
+ *
+ * Gets the value of #WebKitWebLoaderClient:estimated-progress.
+ * You can monitor the estimated progress of a load operation by
+ * connecting to the ::notify signal of @client.
+ *
+ * Returns: an estimate of the of the percent complete for a document
+ *     load as a range from 0.0 to 1.0.
+ */
+gdouble webkit_web_loader_client_get_estimated_progress(WebKitWebLoaderClient* client)
+{
+    g_return_val_if_fail(WEBKIT_IS_WEB_LOADER_CLIENT(client), 0.);
+
+    return client->priv->estimatedProgress;
+}

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebLoaderClient.h (96832 => 96833)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebLoaderClient.h	2011-10-06 17:53:18 UTC (rev 96832)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebLoaderClient.h	2011-10-06 18:03:11 UTC (rev 96833)
@@ -63,8 +63,11 @@
 };
 
 WEBKIT_API GType
-webkit_web_loader_client_get_type (void);
+webkit_web_loader_client_get_type               (void);
 
+WEBKIT_API gdouble
+webkit_web_loader_client_get_estimated_progress (WebKitWebLoaderClient* client);
+
 G_END_DECLS
 
 #endif

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/testloading.c (96832 => 96833)


--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/testloading.c	2011-10-06 17:53:18 UTC (rev 96832)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/testloading.c	2011-10-06 18:03:11 UTC (rev 96833)
@@ -64,6 +64,7 @@
     gboolean hasBeenCommitted;
     gboolean hasBeenFinished;
     gboolean hasBeenFailed;
+    gdouble progress;
 } WebLoadingFixture;
 
 static void webLoadingFixtureSetup(WebLoadingFixture *fixture, gconstpointer data)
@@ -76,6 +77,7 @@
     fixture->hasBeenCommitted = FALSE;
     fixture->hasBeenFinished = FALSE;
     fixture->hasBeenFailed = FALSE;
+    fixture->progress = 0;
 }
 
 static void webLoadingFixtureTeardown(WebLoadingFixture *fixture, gconstpointer data)
@@ -252,6 +254,37 @@
     g_main_loop_run(fixture->loop);
 }
 
+static void loadProgressEstimatedProgressChanged(GObject *object, GParamSpec *pspec, WebLoadingFixture *fixture)
+{
+    gdouble progress = webkit_web_loader_client_get_estimated_progress(WEBKIT_WEB_LOADER_CLIENT(object));
+
+    g_assert_cmpfloat(fixture->progress, <, progress);
+    fixture->progress = progress;
+}
+
+static gboolean loadProgressLoadFinished(WebKitWebLoaderClient *client, WebLoadingFixture *fixture)
+{
+    g_assert_cmpfloat(fixture->progress, ==, 1.0);
+    g_main_loop_quit(fixture->loop);
+
+    return TRUE;
+}
+
+static void testLoadProgress(WebLoadingFixture *fixture, gconstpointer data)
+{
+    char *uriString;
+    WebKitWebLoaderClient *client = webkit_web_view_get_loader_client(fixture->webView);
+
+    g_signal_connect(client, "load-finished", G_CALLBACK(loadProgressLoadFinished), fixture);
+    g_signal_connect(client, "notify::estimated-progress", G_CALLBACK(loadProgressEstimatedProgressChanged), fixture);
+
+    uriString = getURIForPath("/");
+    webkit_web_view_load_uri(fixture->webView, uriString);
+    g_free(uriString);
+
+    g_main_loop_run(fixture->loop);
+}
+
 int main(int argc, char **argv)
 {
     SoupServer *server;
@@ -285,6 +318,11 @@
                webLoadingFixtureSetup,
                testLoadAlternateContent,
                webLoadingFixtureTeardown);
+    g_test_add("/webkit2/loading/progress",
+               WebLoadingFixture, NULL,
+               webLoadingFixtureSetup,
+               testLoadProgress,
+               webLoadingFixtureTeardown);
 
     return g_test_run();
 }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to