Title: [131298] trunk/Source/WebKit2
Revision
131298
Author
[email protected]
Date
2012-10-15 06:19:36 -0700 (Mon, 15 Oct 2012)

Log Message

[EFL][WK2] Encapsulate ref counting for Ewk objects in a parent class
https://bugs.webkit.org/show_bug.cgi?id=99174

Patch by Mikhail Pozdnyakov <[email protected]> on 2012-10-15
Reviewed by Kenneth Rohde Christiansen.

Ewk objects can be inherited from RefCounted class, so that ref counting is encapsulated and RefPtr can be used.
Applied the new approach for Ewk_Navigation_Data and Ewk_Url_Request objects as an example.
The requirement of adoption can be satisfied as long as we keep dealing with smart pointers only. 
In case external client provides an already referenced object as a raw pointer, relaxAdoptionRequirement() can be set
explicitly in this specific place.

* UIProcess/API/efl/ewk_context_history_client.cpp:
(didNavigateWithNavigationData):
* UIProcess/API/efl/ewk_download_job.cpp:
(_Ewk_Download_Job):
(_Ewk_Download_Job::_Ewk_Download_Job):
(_Ewk_Download_Job::~_Ewk_Download_Job):
(ewk_download_job_request_get):
* UIProcess/API/efl/ewk_navigation_data.cpp:
(ewk_navigation_data_ref):
(ewk_navigation_data_unref):
(ewk_navigation_data_original_request_get):
* UIProcess/API/efl/ewk_navigation_data_private.h:
(_Ewk_Navigation_Data):
(_Ewk_Navigation_Data::_Ewk_Navigation_Data):
* UIProcess/API/efl/ewk_navigation_policy_decision.cpp:
(_Ewk_Navigation_Policy_Decision):
(_Ewk_Navigation_Policy_Decision::_Ewk_Navigation_Policy_Decision):
(_Ewk_Navigation_Policy_Decision::~_Ewk_Navigation_Policy_Decision):
(ewk_navigation_policy_request_get):
(ewk_navigation_policy_decision_new):
* UIProcess/API/efl/ewk_url_request.cpp:
(ewk_url_request_ref):
(ewk_url_request_unref):
* UIProcess/API/efl/ewk_url_request_private.h:
(_Ewk_Url_Request):
(_Ewk_Url_Request::_Ewk_Url_Request):
* UIProcess/API/efl/ewk_view_resource_load_client.cpp:
(didInitiateLoadForResource):
(didSendRequestForResource):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (131297 => 131298)


--- trunk/Source/WebKit2/ChangeLog	2012-10-15 12:45:04 UTC (rev 131297)
+++ trunk/Source/WebKit2/ChangeLog	2012-10-15 13:19:36 UTC (rev 131298)
@@ -1,3 +1,46 @@
+2012-10-15  Mikhail Pozdnyakov  <[email protected]>
+
+        [EFL][WK2] Encapsulate ref counting for Ewk objects in a parent class
+        https://bugs.webkit.org/show_bug.cgi?id=99174
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        Ewk objects can be inherited from RefCounted class, so that ref counting is encapsulated and RefPtr can be used.
+        Applied the new approach for Ewk_Navigation_Data and Ewk_Url_Request objects as an example.
+        The requirement of adoption can be satisfied as long as we keep dealing with smart pointers only. 
+        In case external client provides an already referenced object as a raw pointer, relaxAdoptionRequirement() can be set
+        explicitly in this specific place.
+
+        * UIProcess/API/efl/ewk_context_history_client.cpp:
+        (didNavigateWithNavigationData):
+        * UIProcess/API/efl/ewk_download_job.cpp:
+        (_Ewk_Download_Job):
+        (_Ewk_Download_Job::_Ewk_Download_Job):
+        (_Ewk_Download_Job::~_Ewk_Download_Job):
+        (ewk_download_job_request_get):
+        * UIProcess/API/efl/ewk_navigation_data.cpp:
+        (ewk_navigation_data_ref):
+        (ewk_navigation_data_unref):
+        (ewk_navigation_data_original_request_get):
+        * UIProcess/API/efl/ewk_navigation_data_private.h:
+        (_Ewk_Navigation_Data):
+        (_Ewk_Navigation_Data::_Ewk_Navigation_Data):
+        * UIProcess/API/efl/ewk_navigation_policy_decision.cpp:
+        (_Ewk_Navigation_Policy_Decision):
+        (_Ewk_Navigation_Policy_Decision::_Ewk_Navigation_Policy_Decision):
+        (_Ewk_Navigation_Policy_Decision::~_Ewk_Navigation_Policy_Decision):
+        (ewk_navigation_policy_request_get):
+        (ewk_navigation_policy_decision_new):
+        * UIProcess/API/efl/ewk_url_request.cpp:
+        (ewk_url_request_ref):
+        (ewk_url_request_unref):
+        * UIProcess/API/efl/ewk_url_request_private.h:
+        (_Ewk_Url_Request):
+        (_Ewk_Url_Request::_Ewk_Url_Request):
+        * UIProcess/API/efl/ewk_view_resource_load_client.cpp:
+        (didInitiateLoadForResource):
+        (didSendRequestForResource):
+
 2012-10-15  Allan Sandfeld Jensen  <[email protected]>
 
         [Qt] Regression(r130031) coverRect is used in wrong coordinates.

Modified: trunk/Source/WebKit2/UIProcess/API/efl/ewk_context_history_client.cpp (131297 => 131298)


--- trunk/Source/WebKit2/UIProcess/API/efl/ewk_context_history_client.cpp	2012-10-15 12:45:04 UTC (rev 131297)
+++ trunk/Source/WebKit2/UIProcess/API/efl/ewk_context_history_client.cpp	2012-10-15 13:19:36 UTC (rev 131298)
@@ -55,9 +55,8 @@
     if (!historyDelegate->navigate_func)
         return;
 
-    Ewk_Navigation_Data* navigationDataEwk = ewk_navigation_data_new(navigationData);
-    historyDelegate->navigate_func(ewk_view_from_page_get(toImpl(page)), navigationDataEwk, historyDelegate->user_data);
-    ewk_navigation_data_unref(navigationDataEwk);
+    RefPtr<Ewk_Navigation_Data> navigationDataEwk = adoptRef(ewk_navigation_data_new(navigationData));
+    historyDelegate->navigate_func(ewk_view_from_page_get(toImpl(page)), navigationDataEwk.get(), historyDelegate->user_data);
 }
 
 static void didPerformClientRedirect(WKContextRef, WKPageRef page, WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef, const void* clientInfo)

Modified: trunk/Source/WebKit2/UIProcess/API/efl/ewk_download_job.cpp (131297 => 131298)


--- trunk/Source/WebKit2/UIProcess/API/efl/ewk_download_job.cpp	2012-10-15 12:45:04 UTC (rev 131297)
+++ trunk/Source/WebKit2/UIProcess/API/efl/ewk_download_job.cpp	2012-10-15 13:19:36 UTC (rev 131298)
@@ -46,7 +46,7 @@
     DownloadProxy* downloadProxy;
     Evas_Object* view;
     Ewk_Download_Job_State state;
-    Ewk_Url_Request* request;
+    RefPtr<Ewk_Url_Request> request;
     Ewk_Url_Response* response;
     double startTime;
     double endTime;
@@ -59,7 +59,6 @@
         , downloadProxy(download)
         , view(ewkView)
         , state(EWK_DOWNLOAD_JOB_STATE_NOT_STARTED)
-        , request(0)
         , response(0)
         , startTime(-1)
         , endTime(-1)
@@ -69,8 +68,6 @@
     ~_Ewk_Download_Job()
     {
         ASSERT(!__ref);
-        if (request)
-            ewk_url_request_unref(request);
         if (response)
             ewk_url_response_unref(response);
     }
@@ -133,10 +130,10 @@
     if (!download->request) {
         EINA_SAFETY_ON_NULL_RETURN_VAL(download->downloadProxy, 0);
         WKRetainPtr<WKURLRequestRef> wkURLRequest(AdoptWK, toAPI(WebURLRequest::create(download->downloadProxy->request()).leakRef()));
-        const_cast<Ewk_Download_Job*>(download)->request = ewk_url_request_new(wkURLRequest.get());
+        const_cast<Ewk_Download_Job*>(download)->request = adoptRef(ewk_url_request_new(wkURLRequest.get()));
     }
 
-    return download->request;
+    return download->request.get();
 }
 
 Ewk_Url_Response* ewk_download_job_response_get(const Ewk_Download_Job* download)

Modified: trunk/Source/WebKit2/UIProcess/API/efl/ewk_navigation_data.cpp (131297 => 131298)


--- trunk/Source/WebKit2/UIProcess/API/efl/ewk_navigation_data.cpp	2012-10-15 12:45:04 UTC (rev 131297)
+++ trunk/Source/WebKit2/UIProcess/API/efl/ewk_navigation_data.cpp	2012-10-15 13:19:36 UTC (rev 131298)
@@ -26,47 +26,15 @@
 #include "config.h"
 #include "ewk_navigation_data.h"
 
-#include "WKAPICast.h"
-#include "WKEinaSharedString.h"
-#include "WKRetainPtr.h"
 #include "ewk_navigation_data_private.h"
-#include "ewk_private.h"
-#include "ewk_url_request_private.h"
 
 using namespace WebKit;
 
-/**
- * \struct  _Ewk_Navigation_Data
- * @brief   Contains the navigation data details.
- */
-struct _Ewk_Navigation_Data {
-    unsigned __ref; /**< the reference count of the object */
-    WKEinaSharedString title;
-    WKEinaSharedString url;
-    Ewk_Url_Request* request;
-
-    _Ewk_Navigation_Data(WKNavigationDataRef dataRef)
-        : __ref(1)
-        , title(AdoptWK, WKNavigationDataCopyTitle(dataRef))
-        , url(AdoptWK, WKNavigationDataCopyURL(dataRef))
-        , request(0)
-    {
-        WKRetainPtr<WKURLRequestRef> requestWK(AdoptWK, WKNavigationDataCopyOriginalRequest(dataRef));
-        request = ewk_url_request_new(requestWK.get());
-    }
-
-    ~_Ewk_Navigation_Data()
-    {
-        ASSERT(!__ref);
-        ewk_url_request_unref(request);
-    }
-};
-
 Ewk_Navigation_Data* ewk_navigation_data_ref(Ewk_Navigation_Data* data)
 {
     EINA_SAFETY_ON_NULL_RETURN_VAL(data, 0);
 
-    ++data->__ref;
+    data->ref();
 
     return data;
 }
@@ -75,10 +43,7 @@
 {
     EINA_SAFETY_ON_NULL_RETURN(data);
 
-    if (--data->__ref)
-        return;
-
-    delete data;
+    data->deref();
 }
 
 const char* ewk_navigation_data_title_get(const Ewk_Navigation_Data* data)
@@ -92,7 +57,7 @@
 {
     EINA_SAFETY_ON_NULL_RETURN_VAL(data, 0);
 
-    return data->request;
+    return data->request.get();
 }
 
 const char* ewk_navigation_data_url_get(const Ewk_Navigation_Data* data)

Modified: trunk/Source/WebKit2/UIProcess/API/efl/ewk_navigation_data_private.h (131297 => 131298)


--- trunk/Source/WebKit2/UIProcess/API/efl/ewk_navigation_data_private.h	2012-10-15 12:45:04 UTC (rev 131297)
+++ trunk/Source/WebKit2/UIProcess/API/efl/ewk_navigation_data_private.h	2012-10-15 13:19:36 UTC (rev 131298)
@@ -26,8 +26,31 @@
 #ifndef ewk_navigation_data_private_h
 #define ewk_navigation_data_private_h
 
+#include "WKAPICast.h"
+#include "WKEinaSharedString.h"
 #include "WKNavigationData.h"
+#include "WKRetainPtr.h"
+#include "ewk_private.h"
+#include "ewk_url_request_private.h"
 
+/**
+ * \struct  _Ewk_Navigation_Data
+ * @brief   Contains the navigation data details.
+ */
+struct _Ewk_Navigation_Data : public RefCounted<_Ewk_Navigation_Data> {
+    WKEinaSharedString title;
+    WKEinaSharedString url;
+    RefPtr<Ewk_Url_Request> request;
+
+    _Ewk_Navigation_Data(WKNavigationDataRef dataRef)
+        : title(AdoptWK, WKNavigationDataCopyTitle(dataRef))
+        , url(AdoptWK, WKNavigationDataCopyURL(dataRef))
+    {
+        WKRetainPtr<WKURLRequestRef> requestWK(AdoptWK, WKNavigationDataCopyOriginalRequest(dataRef));
+        request = adoptRef(ewk_url_request_new(requestWK.get()));
+    }
+};
+
 typedef struct _Ewk_Navigation_Data Ewk_Navigation_Data;
 
 Ewk_Navigation_Data* ewk_navigation_data_new(WKNavigationDataRef dataRef);

Modified: trunk/Source/WebKit2/UIProcess/API/efl/ewk_navigation_policy_decision.cpp (131297 => 131298)


--- trunk/Source/WebKit2/UIProcess/API/efl/ewk_navigation_policy_decision.cpp	2012-10-15 12:45:04 UTC (rev 131297)
+++ trunk/Source/WebKit2/UIProcess/API/efl/ewk_navigation_policy_decision.cpp	2012-10-15 13:19:36 UTC (rev 131298)
@@ -47,10 +47,10 @@
     Ewk_Navigation_Type navigationType;
     Event_Mouse_Button mouseButton;
     Event_Modifier_Keys modifiers;
-    Ewk_Url_Request* request;
+    RefPtr<Ewk_Url_Request> request;
     WKEinaSharedString frameName;
 
-    _Ewk_Navigation_Policy_Decision(WKFramePolicyListenerRef _listener, Ewk_Navigation_Type _navigationType, Event_Mouse_Button _mouseButton, Event_Modifier_Keys _modifiers, Ewk_Url_Request* _request, const char* _frameName)
+    _Ewk_Navigation_Policy_Decision(WKFramePolicyListenerRef _listener, Ewk_Navigation_Type _navigationType, Event_Mouse_Button _mouseButton, Event_Modifier_Keys _modifiers, PassRefPtr<Ewk_Url_Request> _request, const char* _frameName)
         : __ref(1)
         , listener(_listener)
         , actedUponByClient(false)
@@ -68,8 +68,6 @@
         // This is the default choice for all policy decisions in WebPageProxy.cpp.
         if (!actedUponByClient)
             WKFramePolicyListenerUse(listener.get());
-
-        ewk_url_request_unref(request);
     }
 };
 
@@ -124,7 +122,7 @@
 {
     EINA_SAFETY_ON_NULL_RETURN_VAL(decision, 0);
 
-    return decision->request;
+    return decision->request.get();
 }
 
 void ewk_navigation_policy_decision_accept(Ewk_Navigation_Policy_Decision* decision)
@@ -177,6 +175,6 @@
                                               static_cast<Ewk_Navigation_Type>(navigationType),
                                               static_cast<Event_Mouse_Button>(mouseButton),
                                               static_cast<Event_Modifier_Keys>(modifiers),
-                                              ewk_url_request_new(request),
+                                              adoptRef(ewk_url_request_new(request)),
                                               frameName);
 }

Modified: trunk/Source/WebKit2/UIProcess/API/efl/ewk_url_request.cpp (131297 => 131298)


--- trunk/Source/WebKit2/UIProcess/API/efl/ewk_url_request.cpp	2012-10-15 12:45:04 UTC (rev 131297)
+++ trunk/Source/WebKit2/UIProcess/API/efl/ewk_url_request.cpp	2012-10-15 13:19:36 UTC (rev 131298)
@@ -26,44 +26,14 @@
 #include "config.h"
 #include "ewk_url_request.h"
 
-#include "WKAPICast.h"
-#include "WKEinaSharedString.h"
-#include "WKURL.h"
-#include "WKURLRequest.h"
-#include "WebURLRequest.h"
 #include "ewk_url_request_private.h"
-#include <wtf/text/CString.h>
 
 using namespace WebKit;
 
-/**
- * \struct  _Ewk_Url_Request
- * @brief   Contains the URL request data.
- */
-struct _Ewk_Url_Request {
-    unsigned int __ref; /**< the reference count of the object */
-
-    WKEinaSharedString url;
-    WKEinaSharedString first_party;
-    WKEinaSharedString http_method;
-
-    _Ewk_Url_Request(WKURLRequestRef requestRef)
-        : __ref(1)
-        , url(AdoptWK, WKURLRequestCopyURL(requestRef))
-        , first_party(AdoptWK, WKURLRequestCopyFirstPartyForCookies(requestRef))
-        , http_method(AdoptWK, WKURLRequestCopyHTTPMethod(requestRef))
-    { }
-
-    ~_Ewk_Url_Request()
-    {
-        ASSERT(!__ref);
-    }
-};
-
 Ewk_Url_Request* ewk_url_request_ref(Ewk_Url_Request* request)
 {
     EINA_SAFETY_ON_NULL_RETURN_VAL(request, 0);
-    ++request->__ref;
+    request->ref();
 
     return request;
 }
@@ -72,10 +42,7 @@
 {
     EINA_SAFETY_ON_NULL_RETURN(request);
 
-    if (--request->__ref)
-        return;
-
-    delete request;
+    request->deref();
 }
 
 const char* ewk_url_request_url_get(const Ewk_Url_Request* request)
@@ -89,14 +56,14 @@
 {
     EINA_SAFETY_ON_NULL_RETURN_VAL(request, 0);
 
-    return request->first_party;
+    return request->firstParty;
 }
 
 const char* ewk_url_request_http_method_get(const Ewk_Url_Request* request)
 {
     EINA_SAFETY_ON_NULL_RETURN_VAL(request, 0);
 
-    return request->http_method;
+    return request->httpMethod;
 }
 
 /**

Modified: trunk/Source/WebKit2/UIProcess/API/efl/ewk_url_request_private.h (131297 => 131298)


--- trunk/Source/WebKit2/UIProcess/API/efl/ewk_url_request_private.h	2012-10-15 12:45:04 UTC (rev 131297)
+++ trunk/Source/WebKit2/UIProcess/API/efl/ewk_url_request_private.h	2012-10-15 13:19:36 UTC (rev 131298)
@@ -26,6 +26,29 @@
 #ifndef ewk_url_request_private_h
 #define ewk_url_request_private_h
 
+#include "WKEinaSharedString.h"
+#include "WKURL.h"
+#include "WKURLRequest.h"
+#include "WebURLRequest.h"
+
+/**
+ * \struct  _Ewk_Url_Request
+ * @brief   Contains the URL request data.
+ */
+struct _Ewk_Url_Request : public RefCounted<_Ewk_Url_Request> {
+    WKEinaSharedString url;
+    WKEinaSharedString firstParty;
+    WKEinaSharedString httpMethod;
+
+    _Ewk_Url_Request(WKURLRequestRef requestRef)
+        : url(AdoptWK, WKURLRequestCopyURL(requestRef))
+        , firstParty(AdoptWK, WKURLRequestCopyFirstPartyForCookies(requestRef))
+        , httpMethod(AdoptWK, WKURLRequestCopyHTTPMethod(requestRef))
+    { }
+};
+
+typedef struct _Ewk_Url_Request Ewk_Url_Request;
+
 Ewk_Url_Request* ewk_url_request_new(WKURLRequestRef);
 
 #endif // ewk_url_request_private_h

Modified: trunk/Source/WebKit2/UIProcess/API/efl/ewk_view_resource_load_client.cpp (131297 => 131298)


--- trunk/Source/WebKit2/UIProcess/API/efl/ewk_view_resource_load_client.cpp	2012-10-15 12:45:04 UTC (rev 131297)
+++ trunk/Source/WebKit2/UIProcess/API/efl/ewk_view_resource_load_client.cpp	2012-10-15 13:19:36 UTC (rev 131298)
@@ -57,18 +57,16 @@
     WKRetainPtr<WKURLRef> wkUrl(AdoptWK, WKURLRequestCopyURL(wkRequest));
 
     Ewk_Resource* resource = ewk_resource_new(toImpl(wkUrl.get())->string().utf8().data(), isMainResource);
-    Ewk_Url_Request* request = ewk_url_request_new(wkRequest);
-    ewk_view_resource_load_initiated(toEwkView(clientInfo), resourceIdentifier, resource, request);
+    RefPtr<Ewk_Url_Request> request = adoptRef(ewk_url_request_new(wkRequest));
+    ewk_view_resource_load_initiated(toEwkView(clientInfo), resourceIdentifier, resource, request.get());
     ewk_resource_unref(resource);
-    ewk_url_request_unref(request);
 }
 
 static void didSendRequestForResource(WKPageRef, WKFrameRef, uint64_t resourceIdentifier, WKURLRequestRef wkRequest, WKURLResponseRef wkRedirectResponse, const void* clientInfo)
 {
-    Ewk_Url_Request* request = ewk_url_request_new(wkRequest);
+    RefPtr<Ewk_Url_Request> request = adoptRef(ewk_url_request_new(wkRequest));
     Ewk_Url_Response* redirectResponse = wkRedirectResponse ? ewk_url_response_new(toImpl(wkRedirectResponse)->resourceResponse()) : 0;
-    ewk_view_resource_request_sent(toEwkView(clientInfo), resourceIdentifier, request, redirectResponse);
-    ewk_url_request_unref(request);
+    ewk_view_resource_request_sent(toEwkView(clientInfo), resourceIdentifier, request.get(), redirectResponse);
     if (redirectResponse)
         ewk_url_response_unref(redirectResponse);
 }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to