Bug 112782

Summary: [WK2] Remove repeating code in declaration of WK2 API classes
Product: WebKit Reporter: Mikhail Pozdnyakov <mikhail.pozdnyakov>
Component: WebKit2Assignee: Mikhail Pozdnyakov <mikhail.pozdnyakov>
Status: RESOLVED FIXED    
Severity: Normal CC: andersca, ap, benjamin, cmarcelo, eric.carlson, feature-media-reviews, gyuyoung.kim, jer.noble, kenneth, rakuco, webkit.review.bot
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
WIP patch
eflews.bot: commit-queue-
patch none

Description Mikhail Pozdnyakov 2013-03-20 01:19:49 PDT
The following two lines of code are repeated in every class inheriting WebKit::APIObject.

1) static const Type APIType = SomeAPIType;
2) virtual Type type() const { return APIType; }

This code copy/paste could be avoided.
Comment 1 Mikhail Pozdnyakov 2013-03-20 01:54:20 PDT
Created attachment 194002 [details]
WIP patch

This proposal patch introduces template class 

template <APIObject::Type ArgumentType>
class TypedAPIObject : public APIObject

which contains the common functionality.
Comment 2 EFL EWS Bot 2013-03-20 02:16:38 PDT
Comment on attachment 194002 [details]
WIP patch

Attachment 194002 [details] did not pass efl-ews (efl):
Output: http://webkit-commit-queue.appspot.com/results/17140413
Comment 3 Mikhail Pozdnyakov 2013-03-20 02:25:53 PDT
Comment on attachment 194002 [details]
WIP patch

View in context: https://bugs.webkit.org/attachment.cgi?id=194002&action=review

> Source/WebKit2/UIProcess/efl/WebPopupItemEfl.h:35
> +class WebPopupItemEfl : TypedAPIObject<APIObject::TypePopupMenuItem> {

argh, missed 'public' here :(
Comment 4 Benjamin Poulain 2013-03-20 14:23:41 PDT
Comment on attachment 194002 [details]
WIP patch

View in context: https://bugs.webkit.org/attachment.cgi?id=194002&action=review

This looks like a great idea but if you plan to only fix the ELF types, I am gonna stab you :)

> Source/WebKit2/Shared/APIObject.h:165
> +    virtual Type type() const { return APIType; }

Shouldn't it be private?
Comment 5 Mikhail Pozdnyakov 2013-03-21 06:33:35 PDT
(In reply to comment #4)
> (From update of attachment 194002 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=194002&action=review
> 
> This looks like a great idea but if you plan to only fix the ELF types, I am gonna stab you :)
> 
No no, it was just an illustration patch, I am planning to deploy it to every object :)

> > Source/WebKit2/Shared/APIObject.h:165
> > +    virtual Type type() const { return APIType; }
> 
> Shouldn't it be private?

It could, but this would mean that the object cannot invoke it's own type() method, so would keep it protected.
Comment 6 Mikhail Pozdnyakov 2013-03-21 08:36:49 PDT
Created attachment 194269 [details]
patch
Comment 7 Benjamin Poulain 2013-03-25 14:27:37 PDT
Comment on attachment 194269 [details]
patch

Great change!
Can you deploy it to all APIObject? (WebFrameListenerProxy's subclass as you mentioned on IRC)
Comment 8 Mikhail Pozdnyakov 2013-03-26 02:13:44 PDT
(In reply to comment #7)
> (From update of attachment 194269 [details])
> Great change!
> Can you deploy it to all APIObject? (WebFrameListenerProxy's subclass as you mentioned on IRC)

Unfortunately it's not that easy to deploy to WebFrameListenerProxy's subclasses because WebFrameProxy contains RefPtr<WebFrameListenerProxy> m_activeListener; hence WebFrameListenerProxy has to inherit ThreadSafeRefCounted directly.
The only solution that I see is virtual inheritance, would you like it?
Comment 9 Benjamin Poulain 2013-03-26 18:00:15 PDT
Comment on attachment 194269 [details]
patch

> Unfortunately it's not that easy to deploy to WebFrameListenerProxy's subclasses because WebFrameProxy contains RefPtr<WebFrameListenerProxy> m_activeListener; hence WebFrameListenerProxy has to inherit ThreadSafeRefCounted directly.
> The only solution that I see is virtual inheritance, would you like it?

Nope, screw that :)
Comment 10 WebKit Review Bot 2013-04-02 01:31:13 PDT
Comment on attachment 194269 [details]
patch

Clearing flags on attachment: 194269

Committed r147403: <http://trac.webkit.org/changeset/147403>
Comment 11 WebKit Review Bot 2013-04-02 01:31:17 PDT
All reviewed patches have been landed.  Closing bug.