Changeset 162928 in webkit


Ignore:
Timestamp:
Jan 28, 2014 2:22:47 AM (10 years ago)
Author:
commit-queue@webkit.org
Message:

[GTK] Add API to allow setting the process model in WebKitWebContext
https://bugs.webkit.org/show_bug.cgi?id=125463

Patch by Adrian Perez de Castro <Adrian Perez de Castro> on 2014-01-28
Reviewed by Carlos Garcia Campos.

Implements accessors in WebKitWebContext for the process model.
The default behavior is unchanged, and a single web process is
used. Using WEBKIT_PROCESS_MODEL_ONE_SECONDARY_PROCESS_PER_WEB_VIEW
as the process model will make use one web process for each
WebKitWebView. This also enables the network process. Setting
the process model must be done as early as possible, before the
very first web process is spawned.

Source/WebKit2:

  • UIProcess/API/gtk/WebKitWebContext.cpp:

Add accessors in the API to get/set the process model.
(webkit_web_context_set_process_model):
(webkit_web_context_get_process_model):

  • UIProcess/API/gtk/WebKitWebContext.h:

Define the WebKitProcessModel enum.

  • UIProcess/API/gtk/docs/webkit2gtk-sections.txt:

Add new public API bits to the documentation.

Tools:

  • MiniBrowser/gtk/main.c:

(main):
Enable multiple process mode if the MINIBROWSER_MULTIPROCESS
environment variable is defined and not empty.

  • TestWebKitAPI/GNUmakefile.am:

Add new TestMultiprocess test case.

  • TestWebKitAPI/Tests/WebKit2Gtk/CMakeLists.txt:

Add new TestMultiprocess test case.

  • TestWebKitAPI/Tests/WebKit2Gtk/TestMultiprocess.cpp: Added.

(loadChanged):
(testMultipleSecondaryProcesses):
(initializeWebExtensions):
(beforeAll):
(afterAll):

  • TestWebKitAPI/Tests/WebKit2Gtk/WebExtensionTest.cpp:

(methodCallCallback):
Implement the GetProcessIdentifier D-Bus method.
(makeBusName):
Choose a different bus name when the web extension is used
from TestMultiprocess.
(webkit_web_extension_initialize_with_user_data):
Use makeBusName() to choose the bus name.

Location:
trunk
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r162920 r162928  
     12014-01-28  Adrian Perez de Castro  <aperez@igalia.com>
     2
     3        [GTK] Add API to allow setting the process model in WebKitWebContext
     4        https://bugs.webkit.org/show_bug.cgi?id=125463
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        Implements accessors in WebKitWebContext for the process model.
     9        The default behavior is unchanged, and a single web process is
     10        used. Using WEBKIT_PROCESS_MODEL_ONE_SECONDARY_PROCESS_PER_WEB_VIEW
     11        as the process model will make use one web process for each
     12        WebKitWebView. This also enables the network process. Setting
     13        the process model must be done as early as possible, before the
     14        very first web process is spawned.
     15
     16        * UIProcess/API/gtk/WebKitWebContext.cpp:
     17        Add accessors in the API to get/set the process model.
     18        (webkit_web_context_set_process_model):
     19        (webkit_web_context_get_process_model):
     20        * UIProcess/API/gtk/WebKitWebContext.h:
     21        Define the WebKitProcessModel enum.
     22        * UIProcess/API/gtk/docs/webkit2gtk-sections.txt:
     23        Add new public API bits to the documentation.
     24
    1252014-01-27  Carlos Garcia Campos  <cgarcia@igalia.com>
    226
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp

    r162920 r162928  
    6565 * #WebKitWebView<!-- -->s.
    6666 *
    67  * You can define the #WebKitCacheModel with
    68  * webkit_web_context_set_cache_model(), depending on the needs of
     67 * You can define the #WebKitCacheModel and #WebKitProcessModel with
     68 * webkit_web_context_set_cache_model() and
     69 * webkit_web_context_set_process_model(), depending on the needs of
    6970 * your application. You can access the #WebKitCookieManager or the
    7071 * #WebKitSecurityManager to specify the behaviour of your application
     
    161162
    162163static guint signals[LAST_SIGNAL] = { 0, };
     164
     165COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_PROCESS_MODEL_SHARED_SECONDARY_PROCESS, ProcessModelSharedSecondaryProcess);
     166COMPILE_ASSERT_MATCHING_ENUM(WEBKIT_PROCESS_MODEL_ONE_SECONDARY_PROCESS_PER_WEB_VIEW, ProcessModelMultipleSecondaryProcesses);
    163167
    164168WEBKIT_DEFINE_TYPE(WebKitWebContext, webkit_web_context, G_TYPE_OBJECT)
     
    229233    priv->requestManager = webContext->priv->context->supplement<WebSoupCustomProtocolRequestManager>();
    230234    priv->context->setCacheModel(CacheModelPrimaryWebBrowser);
    231 #if ENABLE(NETWORK_PROCESS)
    232     // FIXME: Temporary use an env var until we have API to set the process model. See https://bugs.webkit.org/show_bug.cgi?id=125463.
    233     priv->context->setUsesNetworkProcess(g_getenv("WEBKIT_USE_NETWORK_PROCESS"));
    234 #endif
    235235    priv->tlsErrorsPolicy = WEBKIT_TLS_ERRORS_POLICY_IGNORE;
    236236
     
    889889}
    890890
     891/**
     892 * webkit_web_context_set_process_model:
     893 * @context: the #WebKitWebContext
     894 * @process_model: a #WebKitProcessModel
     895 *
     896 * Specifies a process model for WebViews, which WebKit will use to
     897 * determine how auxiliary processes are handled. The default setting
     898 * (%WEBKIT_PROCESS_MODEL_SHARED_SECONDARY_PROCESS) is suitable for most
     899 * applications which embed a small amount of WebViews, or are used to
     900 * display documents which are considered safe -- like local files.
     901 *
     902 * Applications which may potentially use a large amount of WebViews --for
     903 * example a multi-tabbed web browser-- may want to use
     904 * %WEBKIT_PROCESS_MODEL_ONE_SECONDARY_PROCESS_PER_WEB_VIEW to use one
     905 * process per view. Using this model, when a WebView hangs or crashes,
     906 * the rest of the WebViews in the application will still work normally.
     907 *
     908 * This method <strong>must be called before any other functions</strong>,
     909 * as early as possible in your application. Calling it later will make
     910 * your application crash.
     911 *
     912 * Since: 2.4
     913 */
     914void webkit_web_context_set_process_model(WebKitWebContext* context, WebKitProcessModel processModel)
     915{
     916    g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context));
     917
     918    if (processModel != context->priv->context->processModel()) {
     919        context->priv->context->setUsesNetworkProcess(processModel == ProcessModelMultipleSecondaryProcesses);
     920        context->priv->context->setProcessModel(static_cast<ProcessModel>(processModel));
     921    }
     922}
     923
     924/**
     925 * webkit_web_context_get_process_model:
     926 * @context: the #WebKitWebContext
     927 *
     928 * Returns the current process model. For more information about this value
     929 * see webkit_web_context_set_process_model().
     930 *
     931 * Returns: the current #WebKitProcessModel
     932 *
     933 * Since: 2.4
     934 */
     935WebKitProcessModel webkit_web_context_get_process_model(WebKitWebContext* context)
     936{
     937    g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), WEBKIT_PROCESS_MODEL_SHARED_SECONDARY_PROCESS);
     938    return static_cast<WebKitProcessModel>(context->priv->context->processModel());
     939}
     940
    891941WebKitDownload* webkitWebContextGetOrCreateDownload(DownloadProxy* downloadProxy)
    892942{
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h

    r162441 r162928  
    6464
    6565/**
     66 * WebKitProcessModel:
     67 * @WEBKIT_PROCESS_MODEL_SHARED_SECONDARY_PROCESS: Use a single process to
     68 *   perform content rendering. The process is shared among all the
     69 *   #WebKitWebView instances created by the application: if the process
     70 *   hangs or crashes all the web views in the application will be affected.
     71 *   This is the default process model, and it should suffice for most cases.
     72 * @WEBKIT_PROCESS_MODEL_ONE_SECONDARY_PROCESS_PER_WEB_VIEW: Use one process
     73 *   for each #WebKitWebView. The main advantage of this process model is that
     74 *   the rendering process for a web view can crash while the rest of the
     75 *   views keep working normally. This process model is indicated for
     76 *   applications which may use a number of web views and the content of
     77 *   in each must not interfere with the rest -- for example a full-fledged
     78 *   web browser with support for multiple tabs.
     79 *
     80 * Enum values used for determining the #WebKitWebContext process model.
     81 *
     82 * Since: 2.4
     83 */
     84typedef enum {
     85    WEBKIT_PROCESS_MODEL_SHARED_SECONDARY_PROCESS,
     86    WEBKIT_PROCESS_MODEL_ONE_SECONDARY_PROCESS_PER_WEB_VIEW,
     87} WebKitProcessModel;
     88
     89/**
    6690 * WebKitTLSErrorsPolicy:
    6791 * @WEBKIT_TLS_ERRORS_POLICY_IGNORE: Ignore TLS errors.
     
    214238                                                     const gchar                   *host);
    215239
     240WEBKIT_API void
     241webkit_web_context_set_process_model                (WebKitWebContext              *context,
     242                                                     WebKitProcessModel             process_model);
     243
     244WEBKIT_API WebKitProcessModel
     245webkit_web_context_get_process_model                (WebKitWebContext              *context);
     246
    216247G_END_DECLS
    217248
  • trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt

    r162441 r162928  
    2525WebKitWebContext
    2626WebKitCacheModel
     27WebKitProcessModel
    2728WebKitTLSErrorsPolicy
    2829webkit_web_context_get_default
     
    5152webkit_web_context_set_disk_cache_directory
    5253webkit_web_context_allow_tls_certificate_for_host
     54webkit_web_context_get_process_model
     55webkit_web_context_set_process_model
    5356
    5457<SUBSECTION URI Scheme>
  • trunk/Tools/ChangeLog

    r162922 r162928  
     12014-01-28  Adrian Perez de Castro  <aperez@igalia.com>
     2
     3        [GTK] Add API to allow setting the process model in WebKitWebContext
     4        https://bugs.webkit.org/show_bug.cgi?id=125463
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        Implements accessors in WebKitWebContext for the process model.
     9        The default behavior is unchanged, and a single web process is
     10        used. Using WEBKIT_PROCESS_MODEL_ONE_SECONDARY_PROCESS_PER_WEB_VIEW
     11        as the process model will make use one web process for each
     12        WebKitWebView. This also enables the network process. Setting
     13        the process model must be done as early as possible, before the
     14        very first web process is spawned.
     15
     16        * MiniBrowser/gtk/main.c:
     17        (main):
     18        Enable multiple process mode if the MINIBROWSER_MULTIPROCESS
     19        environment variable is defined and not empty.
     20        * TestWebKitAPI/GNUmakefile.am:
     21        Add new TestMultiprocess test case.
     22        * TestWebKitAPI/Tests/WebKit2Gtk/CMakeLists.txt:
     23        Add new TestMultiprocess test case.
     24        * TestWebKitAPI/Tests/WebKit2Gtk/TestMultiprocess.cpp: Added.
     25        (loadChanged):
     26        (testMultipleSecondaryProcesses):
     27        (initializeWebExtensions):
     28        (beforeAll):
     29        (afterAll):
     30        * TestWebKitAPI/Tests/WebKit2Gtk/WebExtensionTest.cpp:
     31        (methodCallCallback):
     32        Implement the GetProcessIdentifier D-Bus method.
     33        (makeBusName):
     34        Choose a different bus name when the web extension is used
     35        from TestMultiprocess.
     36        (webkit_web_extension_initialize_with_user_data):
     37        Use makeBusName() to choose the bus name.
     38
    1392014-01-28  Carlos Garcia Campos  <cgarcia@igalia.com>
    240
  • trunk/Tools/MiniBrowser/gtk/main.c

    r155714 r162928  
    242242    gtk_init(&argc, &argv);
    243243
     244    const gchar *multiprocess = g_getenv("MINIBROWSER_MULTIPROCESS");
     245    if (multiprocess && *multiprocess) {
     246        webkit_web_context_set_process_model(webkit_web_context_get_default(),
     247            WEBKIT_PROCESS_MODEL_ONE_SECONDARY_PROCESS_PER_WEB_VIEW);
     248    }
     249
    244250    GOptionContext *context = g_option_context_new(NULL);
    245251    g_option_context_add_main_entries(context, commandLineOptions, 0);
  • trunk/Tools/TestWebKitAPI/GNUmakefile.am

    r162922 r162928  
    162162        Programs/TestWebKitAPI/WebKit2Gtk/TestInspectorServer \
    163163        Programs/TestWebKitAPI/WebKit2Gtk/TestLoaderClient \
     164        Programs/TestWebKitAPI/WebKit2Gtk/TestMultiprocess \
    164165        Programs/TestWebKitAPI/WebKit2Gtk/TestPrinting \
    165166        Programs/TestWebKitAPI/WebKit2Gtk/TestResources \
     
    770771Programs_TestWebKitAPI_WebKit2Gtk_TestLoaderClient_LDFLAGS = $(webkit2gtk_tests_ldflags)
    771772
     773Programs_TestWebKitAPI_WebKit2Gtk_TestMultiprocess_SOURCES = \
     774        Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestMultiprocess.cpp
     775Programs_TestWebKitAPI_WebKit2Gtk_TestMultiprocess_CPPFLAGS = $(webkit2gtk_tests_cppflags)
     776Programs_TestWebKitAPI_WebKit2Gtk_TestMultiprocess_LDADD = $(webkit2gtk_tests_ldadd)
     777Programs_TestWebKitAPI_WebKit2Gtk_TestMultiprocess_LDFLAGS = $(webkit2gtk_tests_ldflags)
     778
    772779Programs_TestWebKitAPI_WebKit2Gtk_TestWebKitSettings_SOURCES = \
    773780        Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitSettings.cpp
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/CMakeLists.txt

    r161366 r162928  
    9393ADD_WK2_TEST(TestInspectorServer TestInspectorServer.cpp)
    9494ADD_WK2_TEST(TestLoaderClient TestLoaderClient.cpp)
     95ADD_WK2_TEST(TestMultiprocess TestMultiprocess.cpp)
    9596ADD_WK2_TEST(TestPrinting TestPrinting.cpp)
    9697ADD_WK2_TEST(TestSSL TestSSL.cpp)
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/WebExtensionTest.cpp

    r162599 r162928  
    2929#include <wtf/OwnPtr.h>
    3030#include <wtf/PassOwnPtr.h>
     31#include <wtf/ProcessID.h>
    3132#include <wtf/gobject/GOwnPtr.h>
    3233#include <wtf/gobject/GRefPtr.h>
     
    4950    "  <method name='GetInitializationUserData'>"
    5051    "   <arg type='s' name='userData' direction='out'/>"
     52    "  </method>"
     53    "  <method name='GetProcessIdentifier'>"
     54    "   <arg type='u' name='identifier' direction='out'/>"
    5155    "  </method>"
    5256    "  <signal name='DocumentLoaded'/>"
     
    225229        g_dbus_method_invocation_return_value(invocation, g_variant_new("(s)",
    226230            g_variant_get_string(initializationUserData.get(), nullptr)));
     231    } else if (!g_strcmp0(methodName, "GetProcessIdentifier")) {
     232        g_dbus_method_invocation_return_value(invocation,
     233            g_variant_new("(u)", static_cast<guint32>(getCurrentProcessID())));
    227234    }
    228235}
     
    264271}
    265272
     273static GUniquePtr<char> makeBusName(GVariant* userData)
     274{
     275    // When the web extension is used by TestMultiprocess, an uint32
     276    // identifier is passed as user data. It uniquely identifies
     277    // the web process, and the UI side expects it added as suffix to
     278    // the bus name.
     279    if (userData && g_variant_is_of_type(userData, G_VARIANT_TYPE_UINT32))
     280        return GUniquePtr<char>(g_strdup_printf("org.webkit.gtk.WebExtensionTest%u", g_variant_get_uint32(userData)));
     281
     282    return GUniquePtr<char>(g_strdup("org.webkit.gtk.WebExtensionTest"));
     283}
     284
    266285extern "C" void webkit_web_extension_initialize_with_user_data(WebKitWebExtension* extension, GVariant* userData)
    267286{
     
    271290    g_signal_connect(webkit_script_world_get_default(), "window-object-cleared", G_CALLBACK(windowObjectCleared), 0);
    272291
     292    GUniquePtr<char> busName(makeBusName(userData));
    273293    g_bus_own_name(
    274294        G_BUS_TYPE_SESSION,
    275         "org.webkit.gtk.WebExtensionTest",
     295        busName.get(),
    276296        G_BUS_NAME_OWNER_FLAGS_NONE,
    277297        busAcquiredCallback,
Note: See TracChangeset for help on using the changeset viewer.