Changeset 96833 in webkit


Ignore:
Timestamp:
Oct 6, 2011 11:03:11 AM (13 years ago)
Author:
Carlos Garcia Campos
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):

Location:
trunk/Source/WebKit2
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r96829 r96833  
     12011-10-06  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Add estimated-progress property to WebKitWebLoaderClient
     4        https://bugs.webkit.org/show_bug.cgi?id=69509
     5
     6        Reviewed by Martin Robinson.
     7
     8        It allows to monitor the estimated progress of a lof operation by
     9        connecting to the notify signal.
     10
     11        * UIProcess/API/gtk/WebKitWebLoaderClient.cpp:
     12        (didChangeProgress): Update estimated-progress property and notify when
     13        it changes.
     14        (webkitWebLoaderClientConstructed): Add implementations for
     15        didStartProgress, didChangeProgress and didFinishProgress.
     16        (webkitWebLoaderClientGetProperty):
     17        (webkit_web_loader_client_class_init): Add estimated-progress property.
     18        (webkit_web_loader_client_get_estimated_progress): Returns the
     19        value of estimated-progress property.
     20        * UIProcess/API/gtk/WebKitWebLoaderClient.h:
     21        * UIProcess/API/gtk/tests/testloading.c:
     22        (webLoadingFixtureSetup):
     23        (loadProgressEstimatedProgressChanged):
     24        (loadProgressLoadFinished):
     25        (testLoadProgress):
     26        (main):
     27
    1282011-10-06  Carlos Garcia Campos  <cgarcia@igalia.com>
    229
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebLoaderClient.cpp

    r96616 r96833  
    4747    PROP_0,
    4848
    49     PROP_WEB_VIEW
     49    PROP_WEB_VIEW,
     50    PROP_ESTIMATED_PROGRESS
    5051};
    5152
    5253struct _WebKitWebLoaderClientPrivate {
    5354    GRefPtr<WebKitWebView> view;
     55
     56    gdouble estimatedProgress;
    5457};
    5558
     
    120123    g_signal_emit(WEBKIT_WEB_LOADER_CLIENT(clientInfo), signals[LOAD_FAILED], 0, resourceError.failingURL().utf8().data(),
    121124                  webError.get(), &returnValue);
     125}
     126
     127static void didChangeProgress(WKPageRef page, const void* clientInfo)
     128{
     129    WebKitWebLoaderClient* client = WEBKIT_WEB_LOADER_CLIENT(clientInfo);
     130    gdouble estimatedProgress = WKPageGetEstimatedProgress(page);
     131
     132    if (client->priv->estimatedProgress == estimatedProgress)
     133        return;
     134
     135    client->priv->estimatedProgress = estimatedProgress;
     136    g_object_notify(G_OBJECT(clientInfo), "estimated-progress");
    122137}
    123138
     
    146161        0,       // canAuthenticateAgainstProtectionSpaceInFrame
    147162        0,       // didReceiveAuthenticationChallengeInFrame
    148         0,      // didStartProgress
    149         0,       // didChangeProgress
    150         0,      // didFinishProgress
     163        didChangeProgress, // didStartProgress
     164        didChangeProgress,
     165        didChangeProgress, // didFinishProgress
    151166        0,       // didBecomeUnresponsive
    152167        0,       // didBecomeResponsive
     
    194209        g_value_set_object(value, client->priv->view.get());
    195210        break;
     211    case PROP_ESTIMATED_PROGRESS:
     212        g_value_set_double(value, webkit_web_loader_client_get_estimated_progress(client));
     213        break;
    196214    default:
    197215        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec);
     
    225243
    226244    /**
    227      * WebKitWebView:web-view:
     245     * WebKitWebLoaderClient:web-view:
    228246     *
    229247     * The #WebKitWebView of the loader client.
     
    236254                                                        WEBKIT_TYPE_WEB_VIEW,
    237255                                                        static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)));
     256    /**
     257     * WebKitWebLoaderClient:estimated-progress:
     258     *
     259     * An estimate of the percent completion for the current loading operation.
     260     * This value will range from 0.0 to 1.0 and, once a load completes,
     261     * will remain at 1.0 until a new load starts, at which point it
     262     * will be reset to 0.0.
     263     * The value is an estimate based on the total number of bytes expected
     264     * to be received for a document, including all its possible subresources.
     265     */
     266    g_object_class_install_property(objectClass,
     267                                    PROP_ESTIMATED_PROGRESS,
     268                                    g_param_spec_double("estimated-progress",
     269                                                        "Estimated Progress",
     270                                                        "An estimate of the percent completion for a document load",
     271                                                        0.0, 1.0, 0.0,
     272                                                        WEBKIT_PARAM_READABLE));
    238273
    239274    /**
     
    384419    g_type_class_add_private(clientClass, sizeof(WebKitWebLoaderClientPrivate));
    385420}
     421
     422/**
     423 * webkit_web_loader_client_get_estimated_progress:
     424 * @client: a #WebKitWebLoaderClient
     425 *
     426 * Gets the value of #WebKitWebLoaderClient:estimated-progress.
     427 * You can monitor the estimated progress of a load operation by
     428 * connecting to the ::notify signal of @client.
     429 *
     430 * Returns: an estimate of the of the percent complete for a document
     431 *     load as a range from 0.0 to 1.0.
     432 */
     433gdouble webkit_web_loader_client_get_estimated_progress(WebKitWebLoaderClient* client)
     434{
     435    g_return_val_if_fail(WEBKIT_IS_WEB_LOADER_CLIENT(client), 0.);
     436
     437    return client->priv->estimatedProgress;
     438}
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebLoaderClient.h

    r96821 r96833  
    6464
    6565WEBKIT_API GType
    66 webkit_web_loader_client_get_type (void);
     66webkit_web_loader_client_get_type               (void);
     67
     68WEBKIT_API gdouble
     69webkit_web_loader_client_get_estimated_progress (WebKitWebLoaderClient* client);
    6770
    6871G_END_DECLS
  • trunk/Source/WebKit2/UIProcess/API/gtk/tests/testloading.c

    r96614 r96833  
    6565    gboolean hasBeenFinished;
    6666    gboolean hasBeenFailed;
     67    gdouble progress;
    6768} WebLoadingFixture;
    6869
     
    7778    fixture->hasBeenFinished = FALSE;
    7879    fixture->hasBeenFailed = FALSE;
     80    fixture->progress = 0;
    7981}
    8082
     
    248250    uriString = getURIForPath("/alternate");
    249251    webkit_web_view_load_alternate_html(fixture->webView, "<html><body>Alternate Content</body></html>", NULL, uriString);
     252    g_free(uriString);
     253
     254    g_main_loop_run(fixture->loop);
     255}
     256
     257static void loadProgressEstimatedProgressChanged(GObject *object, GParamSpec *pspec, WebLoadingFixture *fixture)
     258{
     259    gdouble progress = webkit_web_loader_client_get_estimated_progress(WEBKIT_WEB_LOADER_CLIENT(object));
     260
     261    g_assert_cmpfloat(fixture->progress, <, progress);
     262    fixture->progress = progress;
     263}
     264
     265static gboolean loadProgressLoadFinished(WebKitWebLoaderClient *client, WebLoadingFixture *fixture)
     266{
     267    g_assert_cmpfloat(fixture->progress, ==, 1.0);
     268    g_main_loop_quit(fixture->loop);
     269
     270    return TRUE;
     271}
     272
     273static void testLoadProgress(WebLoadingFixture *fixture, gconstpointer data)
     274{
     275    char *uriString;
     276    WebKitWebLoaderClient *client = webkit_web_view_get_loader_client(fixture->webView);
     277
     278    g_signal_connect(client, "load-finished", G_CALLBACK(loadProgressLoadFinished), fixture);
     279    g_signal_connect(client, "notify::estimated-progress", G_CALLBACK(loadProgressEstimatedProgressChanged), fixture);
     280
     281    uriString = getURIForPath("/");
     282    webkit_web_view_load_uri(fixture->webView, uriString);
    250283    g_free(uriString);
    251284
     
    286319               testLoadAlternateContent,
    287320               webLoadingFixtureTeardown);
     321    g_test_add("/webkit2/loading/progress",
     322               WebLoadingFixture, NULL,
     323               webLoadingFixtureSetup,
     324               testLoadProgress,
     325               webLoadingFixtureTeardown);
    288326
    289327    return g_test_run();
Note: See TracChangeset for help on using the changeset viewer.