Changeset 129134 in webkit


Ignore:
Timestamp:
Sep 20, 2012 7:39:23 AM (12 years ago)
Author:
commit-queue@webkit.org
Message:

[EFL][WK2] Add APIs to create, delete and get ewk_context.
https://bugs.webkit.org/show_bug.cgi?id=89186

Patch by Eunmi Lee <eunmi15.lee@samsung.com> on 2012-09-20
Reviewed by Kenneth Rohde Christiansen.

Provide APIs to create ewk_context with or without injected bundle path
and delete created ewk_context.
Additionally, the ewk_view can be created with ewk_context which is not
default context, so we have to get ewk_context from ewk_view.

  • PlatformEfl.cmake:
  • UIProcess/API/efl/PageClientImpl.cpp:

(WebKit::PageClientImpl::handleDownloadRequest):

  • UIProcess/API/efl/ewk_context.cpp:

(_Ewk_Context):
(_Ewk_Context::_Ewk_Context):
(ewk_context_ref):
(ewk_context_unref):
(ewk_context_new):
(ewk_context_new_with_injected_bundle_path):

  • UIProcess/API/efl/ewk_context.h:
  • UIProcess/API/efl/ewk_view.cpp:

(_Ewk_View_Private_Data):
(_Ewk_View_Private_Data::_Ewk_View_Private_Data):
(_ewk_view_priv_del):
(_ewk_view_initialize):
(ewk_view_context_get):

  • UIProcess/API/efl/ewk_view.h:
  • UIProcess/API/efl/tests/InjectedBundle/injected_bundle_sample.cpp: Added.
  • UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestEnvironment.cpp:

(EWK2UnitTest::EWK2UnitTestEnvironment::injectedBundleSample):
(EWK2UnitTest):

  • UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestEnvironment.h:

(EWK2UnitTestEnvironment):

  • UIProcess/API/efl/tests/test_ewk2_context.cpp:

(TEST_F):

  • UIProcess/API/efl/tests/test_ewk2_cookie_manager.cpp:

(TEST_F):

  • UIProcess/API/efl/tests/test_ewk2_view.cpp:

(TEST_F):

Location:
trunk/Source/WebKit2
Files:
2 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r129121 r129134  
     12012-09-20  Eunmi Lee  <eunmi15.lee@samsung.com>
     2
     3        [EFL][WK2] Add APIs to create, delete and get ewk_context.
     4        https://bugs.webkit.org/show_bug.cgi?id=89186
     5
     6        Reviewed by Kenneth Rohde Christiansen.
     7
     8        Provide APIs to create ewk_context with or without injected bundle path
     9        and delete created ewk_context.
     10        Additionally, the ewk_view can be created with ewk_context which is not
     11        default context, so we have to get ewk_context from ewk_view.
     12
     13        * PlatformEfl.cmake:
     14        * UIProcess/API/efl/PageClientImpl.cpp:
     15        (WebKit::PageClientImpl::handleDownloadRequest):
     16        * UIProcess/API/efl/ewk_context.cpp:
     17        (_Ewk_Context):
     18        (_Ewk_Context::_Ewk_Context):
     19        (ewk_context_ref):
     20        (ewk_context_unref):
     21        (ewk_context_new):
     22        (ewk_context_new_with_injected_bundle_path):
     23        * UIProcess/API/efl/ewk_context.h:
     24        * UIProcess/API/efl/ewk_view.cpp:
     25        (_Ewk_View_Private_Data):
     26        (_Ewk_View_Private_Data::_Ewk_View_Private_Data):
     27        (_ewk_view_priv_del):
     28        (_ewk_view_initialize):
     29        (ewk_view_context_get):
     30        * UIProcess/API/efl/ewk_view.h:
     31        * UIProcess/API/efl/tests/InjectedBundle/injected_bundle_sample.cpp: Added.
     32        * UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestEnvironment.cpp:
     33        (EWK2UnitTest::EWK2UnitTestEnvironment::injectedBundleSample):
     34        (EWK2UnitTest):
     35        * UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestEnvironment.h:
     36        (EWK2UnitTestEnvironment):
     37        * UIProcess/API/efl/tests/test_ewk2_context.cpp:
     38        (TEST_F):
     39        * UIProcess/API/efl/tests/test_ewk2_cookie_manager.cpp:
     40        (TEST_F):
     41        * UIProcess/API/efl/tests/test_ewk2_view.cpp:
     42        (TEST_F):
     43
    1442012-09-20  KwangYong Choi  <ky0.choi@samsung.com>
    245
  • trunk/Source/WebKit2/PlatformEfl.cmake

    r128853 r129134  
    262262SET(WEBKIT2_EFL_TEST_DIR "${WEBKIT2_DIR}/UIProcess/API/efl/tests")
    263263SET(TEST_RESOURCES_DIR ${WEBKIT2_EFL_TEST_DIR}/resources)
     264SET(TEST_INJECTED_BUNDLE_DIR ${WEBKIT2_EFL_TEST_DIR}/InjectedBundle)
    264265
    265266ADD_DEFINITIONS(-DTEST_RESOURCES_DIR=\"${TEST_RESOURCES_DIR}\"
     
    301302        TARGET_LINK_LIBRARIES(${testName} ${EWK2UnitTests_LIBRARIES} ewk2UnitTestUtils)
    302303    ENDFOREACH ()
     304
     305    ADD_LIBRARY(ewk2UnitTestInjectedBundleSample SHARED ${TEST_INJECTED_BUNDLE_DIR}/injected_bundle_sample.cpp)
     306    SET_TARGET_PROPERTIES(ewk2UnitTestInjectedBundleSample PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${TEST_RESOURCES_DIR}")
    303307ENDIF ()
    304308
  • trunk/Source/WebKit2/UIProcess/API/efl/PageClientImpl.cpp

    r129096 r129134  
    286286{
    287287    Ewk_Download_Job* ewkDownload = ewk_download_job_new(download, m_viewWidget);
    288     // For now we only support one default context, but once we support
    289     // multiple contexts, we will need to retrieve the context from the
    290     // view.
    291     ewk_context_download_job_add(ewk_context_default_get(), ewkDownload);
     288    ewk_context_download_job_add(ewk_view_context_get(m_viewWidget), ewkDownload);
    292289    ewk_download_job_unref(ewkDownload);
    293290}
  • trunk/Source/WebKit2/UIProcess/API/efl/ewk_context.cpp

    r128413 r129134  
    2929#include "WKRetainPtr.h"
    3030#include "WKString.h"
     31#include "WebContext.h"
    3132#include "ewk_context_download_client_private.h"
    3233#include "ewk_context_private.h"
     
    3536#include "ewk_download_job.h"
    3637#include "ewk_download_job_private.h"
     38#include <WebCore/FileSystem.h>
    3739#include <wtf/HashMap.h>
    3840#include <wtf/text/WTFString.h>
    3941
     42using namespace WebCore;
    4043using namespace WebKit;
    4144
     
    5861
    5962struct _Ewk_Context {
     63    unsigned __ref; /**< the reference count of the object */
    6064    WKRetainPtr<WKContextRef> context;
    6165
     
    7377
    7478    _Ewk_Context(WKRetainPtr<WKContextRef> contextRef)
    75         : context(contextRef)
     79        : __ref(1)
     80        , context(contextRef)
    7681        , cookieManager(0)
    7782        , requestManager(WKContextGetSoupRequestManager(contextRef.get()))
     
    113118};
    114119
     120Ewk_Context* ewk_context_ref(Ewk_Context* ewkContext)
     121{
     122    EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, 0);
     123    ++ewkContext->__ref;
     124
     125    return ewkContext;
     126}
     127
     128void ewk_context_unref(Ewk_Context* ewkContext)
     129{
     130    EINA_SAFETY_ON_NULL_RETURN(ewkContext);
     131    EINA_SAFETY_ON_FALSE_RETURN(ewkContext->__ref > 0);
     132
     133    if (--ewkContext->__ref)
     134        return;
     135
     136    delete ewkContext;
     137}
     138
    115139Ewk_Cookie_Manager* ewk_context_cookie_manager_get(const Ewk_Context* ewkContext)
    116140{
     
    216240}
    217241
     242Ewk_Context* ewk_context_new()
     243{
     244    return new Ewk_Context(adoptWK(WKContextCreate()));
     245}
     246
     247Ewk_Context* ewk_context_new_with_injected_bundle_path(const char* path)
     248{
     249    EINA_SAFETY_ON_NULL_RETURN_VAL(path, 0);
     250
     251    WKRetainPtr<WKStringRef> pathRef(AdoptWK, WKStringCreateWithUTF8CString(path));
     252    if (!fileExists(toImpl(pathRef.get())->string()))
     253        return 0;
     254
     255    return new Ewk_Context(adoptWK(WKContextCreateWithInjectedBundlePath(pathRef.get())));
     256}
     257
    218258Eina_Bool ewk_context_uri_scheme_register(Ewk_Context* ewkContext, const char* scheme, Ewk_Url_Scheme_Request_Cb callback, void* userData)
    219259{
  • trunk/Source/WebKit2/UIProcess/API/efl/ewk_context.h

    r123482 r129134  
    2323 *
    2424 * @note ewk_context encapsulates all pages related to specific use of WebKit.
    25  * All pages in this context share the same visited link set,
    26  * local storage set, and preferences.
     25 *
     26 * Applications have the option of creating a context different than the default one
     27 * and use it for a group of pages. All pages in the same context share the same
     28 * preferences, visited link set, local storage, etc.
     29 *
     30 * A process model can be specified per context. The default one is the shared model
     31 * where the web-engine process is shared among the pages in the context. The second
     32 * model allows each page to use a separate web-engine process. This latter model is
     33 * currently not supported by WebKit2/EFL.
     34 *
    2735 */
    2836
     
    6270
    6371/**
     72 * Increases the reference count of the given object.
     73 *
     74 * @param context context object to increase the reference count
     75 *
     76 * @return Ewk_Context object on success or @c NULL on failure
     77 */
     78EAPI Ewk_Context *ewk_context_ref(Ewk_Context *context);
     79
     80/**
     81 * Decreases the reference count of the given object, possibly freeing it.
     82 *
     83 * When the reference count it's reached 0, the Ewk_Context is freed.
     84 *
     85 * @param context context object to decrease the reference count
     86 */
     87EAPI void ewk_context_unref(Ewk_Context *context);
     88
     89/**
    6490 * Gets default Ewk_Context instance.
     91 *
     92 * The returned Ewk_Context object @b should not be unref'ed if application
     93 * does not call ewk_context_ref() for that.
    6594 *
    6695 * @return Ewk_Context object.
    6796 */
    68 EAPI Ewk_Context *ewk_context_default_get();
     97EAPI Ewk_Context *ewk_context_default_get(void);
     98
     99/**
     100 * Creates a new Ewk_Context.
     101 *
     102 * The returned Ewk_Context object @b should be unref'ed after use.
     103 *
     104 * @return Ewk_Context object on success or @c NULL on failure
     105 *
     106 * @see ewk_context_unref
     107 * @see ewk_context_new_with_injected_bundle_path
     108 */
     109EAPI Ewk_Context *ewk_context_new(void);
     110
     111/**
     112 * Creates a new Ewk_Context.
     113 *
     114 * The returned Ewk_Context object @b should be unref'ed after use.
     115 *
     116 * @param path path of injected bundle library
     117 *
     118 * @return Ewk_Context object on success or @c NULL on failure
     119 *
     120 * @see ewk_context_unref
     121 * @see ewk_context_new
     122 */
     123EAPI Ewk_Context *ewk_context_new_with_injected_bundle_path(const char *path);
    69124
    70125/**
  • trunk/Source/WebKit2/UIProcess/API/efl/ewk_view.cpp

    r129121 r129134  
    101101    bool areMouseEventsEnabled;
    102102    WKColorPickerResultListenerRef colorPickerResultListener;
     103    Ewk_Context* context;
    103104
    104105    WebPopupMenuProxyEfl* popupMenuProxy;
     
    120121        , areMouseEventsEnabled(false)
    121122        , colorPickerResultListener(0)
     123        , context(0)
    122124        , popupMenuProxy(0)
    123125        , popupMenuItems(0)
     
    385387static void _ewk_view_priv_del(Ewk_View_Private_Data* priv)
    386388{
     389    ewk_context_unref(priv->context);
    387390    delete priv;
    388391}
     
    715718    priv->backForwardList = ewk_back_forward_list_new(toAPI(priv->pageProxy->backForwardList()));
    716719    priv->settings = adoptPtr(new Ewk_Settings(WKPageGroupGetPreferences(WKPageGetPageGroup(toAPI(priv->pageProxy.get())))));
     720    priv->context = ewk_context_ref(context);
    717721
    718722#if USE(COORDINATED_GRAPHICS)
     
    799803}
    800804
     805Ewk_Context* ewk_view_context_get(const Evas_Object* ewkView)
     806{
     807    EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
     808    EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, 0);
     809
     810    return priv->context;
     811}
     812
    801813/**
    802814 * @internal
  • trunk/Source/WebKit2/UIProcess/API/efl/ewk_view.h

    r129121 r129134  
    320320
    321321/**
     322 * Gets the Ewk_Context of this view.
     323 *
     324 * @param o the view object to get the Ewk_Context
     325 *
     326 * @return the Ewk_Context of this view or @c NULL on failure
     327 */
     328EAPI Ewk_Context *ewk_view_context_get(const Evas_Object *o);
     329
     330/**
    322331 * Asks the object to load the given URI.
    323332 *
  • trunk/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestEnvironment.cpp

    r127823 r129134  
    4444}
    4545
     46const char* EWK2UnitTestEnvironment::injectedBundleSample() const
     47{
     48    return TEST_RESOURCES_DIR "/libewk2UnitTestInjectedBundleSample.so";
     49}
     50
    4651CString EWK2UnitTestEnvironment::urlForResource(const char* resource)
    4752{
  • trunk/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestEnvironment.h

    r127823 r129134  
    3333    const char* defaultTestPageUrl() const;
    3434    const char* defaultTheme() const;
     35    const char* injectedBundleSample() const;
    3536    CString urlForResource(const char* resource);
    3637    CString pathForResource(const char* resource);
  • trunk/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_context.cpp

    r129111 r129134  
    11/*
    22 * Copyright (C) 2012 Intel Corporation. All rights reserved.
     3 * Copyright (C) 2012 Samsung Electronics
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    4748TEST_F(EWK2UnitTestBase, ewk_context_cookie_manager_get)
    4849{
    49     Ewk_Cookie_Manager* cookieManager = ewk_context_cookie_manager_get(ewk_context_default_get());
     50    Ewk_Context* context = ewk_view_context_get(webView());
     51    Ewk_Cookie_Manager* cookieManager = ewk_context_cookie_manager_get(context);
    5052    ASSERT_TRUE(cookieManager);
    51     ASSERT_EQ(cookieManager, ewk_context_cookie_manager_get(ewk_context_default_get()));
     53    ASSERT_EQ(cookieManager, ewk_context_cookie_manager_get(context));
    5254}
    5355
     
    6567TEST_F(EWK2UnitTestBase, ewk_context_uri_scheme_register)
    6668{
    67     ewk_context_uri_scheme_register(ewk_context_default_get(), "fooscheme", schemeRequestCallback, 0);
     69    ewk_context_uri_scheme_register(ewk_view_context_get(webView()), "fooscheme", schemeRequestCallback, 0);
    6870    loadUrlSync("fooscheme:MyPath");
    6971    ASSERT_STREQ(ewk_view_title_get(webView()), "Foo");
     
    115117{
    116118    VibrationCbData data = { false, false, 0, 5000 };
    117     ewk_context_vibration_client_callbacks_set(ewk_context_default_get(), vibrateCallback, cancelVibrationCallback, &data);
     119    ewk_context_vibration_client_callbacks_set(ewk_view_context_get(webView()), vibrateCallback, cancelVibrationCallback, &data);
    118120
    119121    // Vibrate for 5 seconds.
     
    135137
    136138    // Stop listening for vibration events, by calling the function with null for the callbacks.
    137     ewk_context_vibration_client_callbacks_set(ewk_context_default_get(), 0, 0, &data);
     139    ewk_context_vibration_client_callbacks_set(ewk_view_context_get(webView()), 0, 0, &data);
    138140
    139141    // Make sure we don't receive vibration event.
     
    149151    ASSERT_FALSE(data.didReceiveCancelVibrationCallback);
    150152}
     153
     154TEST_F(EWK2UnitTestBase, ewk_context_new)
     155{
     156    Ewk_Context* context = ewk_context_new();
     157    ASSERT_TRUE(context);
     158    ewk_context_unref(context);
     159}
     160
     161TEST_F(EWK2UnitTestBase, ewk_context_new_with_injected_bundle_path)
     162{
     163    Ewk_Context* context = ewk_context_new_with_injected_bundle_path(environment->injectedBundleSample());
     164    ASSERT_TRUE(context);
     165    ewk_context_unref(context);
     166}
     167
     168TEST_F(EWK2UnitTestBase, ewk_context_ref)
     169{
     170    Ewk_Context* context = ewk_context_new();
     171    ASSERT_EQ(context, ewk_context_ref(context));
     172    ewk_context_unref(context);
     173    ewk_context_unref(context);
     174}
  • trunk/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_cookie_manager.cpp

    r127405 r129134  
    122122    httpServer->run(serverCallback);
    123123
    124     Ewk_Cookie_Manager* cookieManager = ewk_context_cookie_manager_get(ewk_context_default_get());
     124    Ewk_Cookie_Manager* cookieManager = ewk_context_cookie_manager_get(ewk_view_context_get(webView()));
    125125    ASSERT_TRUE(cookieManager);
    126126
     
    165165    httpServer->run(serverCallback);
    166166
    167     Ewk_Cookie_Manager* cookieManager = ewk_context_cookie_manager_get(ewk_context_default_get());
     167    Ewk_Cookie_Manager* cookieManager = ewk_context_cookie_manager_get(ewk_view_context_get(webView()));
    168168    ASSERT_TRUE(cookieManager);
    169169
     
    228228    httpServer->run(serverCallback);
    229229
    230     Ewk_Cookie_Manager* cookieManager = ewk_context_cookie_manager_get(ewk_context_default_get());
     230    Ewk_Cookie_Manager* cookieManager = ewk_context_cookie_manager_get(ewk_view_context_get(webView()));
    231231    ASSERT_TRUE(cookieManager);
    232232
     
    270270    ASSERT_TRUE(mktemp(sqliteStorage));
    271271
    272     Ewk_Cookie_Manager* cookieManager = ewk_context_cookie_manager_get(ewk_context_default_get());
     272    Ewk_Cookie_Manager* cookieManager = ewk_context_cookie_manager_get(ewk_view_context_get(webView()));
    273273    ASSERT_TRUE(cookieManager);
    274274
  • trunk/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_view.cpp

    r129121 r129134  
    715715    evas_object_smart_callback_del(webView(), "input,type,color,request", onColorPickerDone);
    716716}
     717
     718TEST_F(EWK2UnitTestBase, ewk_view_context_get)
     719{
     720    Ewk_Context* context = ewk_view_context_get(webView());
     721    ASSERT_TRUE(context);
     722    ASSERT_EQ(context, ewk_view_context_get(webView()));
     723}
    717724#endif // ENABLE(INPUT_TYPE_COLOR)
Note: See TracChangeset for help on using the changeset viewer.