Bug 17220

Summary: Illogical dependency between PluginView and PluginDatabase
Product: WebKit Reporter: Rodney Dawes <dobey>
Component: Plug-insAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: mrowe
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: PC   
OS: All   
Attachments:
Description Flags
Patch to move createPluginView method to PluginView class
none
Update to rename to PluginView::create
andersca: review+
Updated patch that compiles on Windows
none
Updated patch with Jon's suggestions
aroben: review+
Updated to revert the KURL.h change in PluginDatabase.h dobey: review+

Description Rodney Dawes 2008-02-08 13:41:01 PST
Currently createPluginView is a class method in PluginDatabase, presumably because findPlugin was a private class method there. This is unnecessary and causes an unneeded dependency between the two classes. The attached patch makes findPlugin a public method, and moves createPluginView to the PluginView class, as well as updates the instances where it is called, to reflect this change.
Comment 1 Rodney Dawes 2008-02-08 13:42:08 PST
Created attachment 19007 [details]
Patch to move createPluginView method to PluginView class
Comment 2 Adam Roben (:aroben) 2008-02-08 14:38:39 PST
Comment on attachment 19007 [details]
Patch to move createPluginView method to PluginView class

If this method is moving to the PluginView class then the method should be named simply "create" instead of "createPluginView".
Comment 3 Rodney Dawes 2008-02-08 16:35:16 PST
Created attachment 19010 [details]
Update to rename to PluginView::create

Oops. Also forgot to change PluginDatabase:: when copying the method over. Renamed the method to PluginView::create and updated the ChangeLog entries to reflect that.
Comment 4 Anders Carlsson 2008-02-08 16:41:21 PST
Comment on attachment 19010 [details]
Update to rename to PluginView::create

r=me
Comment 5 Jon Honeycutt 2008-02-08 17:25:50 PST
Comment on attachment 19010 [details]
Update to rename to PluginView::create

The call to PluginDatabase::installedPlugins() in PluginView::create() can't be made without making PluginView aware of PluginDatabase. Doesn't that just move the dependency around?

I think the change is still OK to make, but this needs some work:

+        PluginView* create(Frame* parentFrame, const IntSize&, Element* element, const KURL& url, const Vector<String>& paramNames, const Vector<String>& paramValues, const String& mimeType, bool loadManually);

This needs to be static.

PluginView should include PluginDatabase.h.

PluginDatabase.h shouldn't include PluginView.h, but will then require KURL.h. You can then remove the "class KURL;" declaration.

The ChangeLog entry should be updated.
Comment 6 Mark Rowe (bdash) 2008-02-08 18:41:48 PST
Created attachment 19012 [details]
Updated patch that compiles on Windows
Comment 7 Mark Rowe (bdash) 2008-02-08 18:42:40 PST
> The call to PluginDatabase::installedPlugins() in PluginView::create() can't be
> made without making PluginView aware of PluginDatabase. Doesn't that just move
> the dependency around?

I'm not landing this yet as I think this question still needs to be addressed.
Comment 8 Rodney Dawes 2008-02-11 08:16:54 PST
(In reply to comment #7)
> > The call to PluginDatabase::installedPlugins() in PluginView::create() can't be
> > made without making PluginView aware of PluginDatabase. Doesn't that just move
> > the dependency around?

Ah, unnecessary/unneeded was the wrong term to use. Illogical is more accurate. Yes, this makes the dependency logical. PluginDatabase should only manage the PluginPackage instances, and PluginView then requests the appropriate PluginPackage from PluginDatabase, to use in the PluginView creation.
Comment 9 Rodney Dawes 2008-02-11 08:20:23 PST
Created attachment 19067 [details]
Updated patch with Jon's suggestions
Comment 10 Darin Adler 2008-02-11 09:20:47 PST
Comment on attachment 19067 [details]
Updated patch with Jon's suggestions

r=me, although I'm not entirely happy with these changes.

 79         static PluginView* create(Frame* parentFrame, const IntSize&, Element* element, const KURL& url, const Vector<String>& paramNames, const Vector<String>& paramValues, const String& mimeType, bool loadManually);

We'd normally omit the name for the Element* and const KURL& parameters, because the type names make it clear what they are.

 141         PluginView(Frame* parentFrame, const IntSize&, PluginPackage* plugin, Element*, const KURL&, const Vector<String>& paramNames, const Vector<String>& paramValues, const String& mimeType, bool loadManually);

We'd normally omit the name for the PluginPackage* parameter, because the type name makes it clear what it is.

 32 #include "KURL.h"

It does not seem good to add KURL.h to the PluginDatabase.h header. Why are you doing that? Please don't add more includes if you can avoid it!

 55         PluginPackage* findPlugin(const KURL& url, String& mimeType);
5556     private:

Please leave a blank line before the private: line.

I don't think it's clear what you mean by "illogical dependency". I don't see anything illogical here. It'll be easier to understand your changes if you use more-precise language.
Comment 11 Rodney Dawes 2008-02-11 11:02:58 PST
(In reply to comment #10)
> (From update of attachment 19067 [details] [edit])
> r=me, although I'm not entirely happy with these changes.

I presume you meant to set review+ instead of clearing the review flag? Seems odd to say r=me, and clear the flag. :)

> We'd normally omit the name for the Element* and const KURL& parameters,
> because the type names make it clear what they are.
> We'd normally omit the name for the PluginPackage* parameter, because the type
> name makes it clear what it is.

These can easily be removed. They were already there however, and I merely just
copied the API between files, and changed the method name. :)

>  32 #include "KURL.h"
> 
> It does not seem good to add KURL.h to the PluginDatabase.h header. Why are you
> doing that? Please don't add more includes if you can avoid it!

PluginDatabase.h still uses KURL in findPlugin().

As per comment #5 from Jon:
PluginDatabase.h shouldn't include PluginView.h, but will then require KURL.h.
You can then remove the "class KURL;" declaration.

> I don't think it's clear what you mean by "illogical dependency". I don't see
> anything illogical here. It'll be easier to understand your changes if you use
> more-precise language.

PluginDatabase does not manage a database of PluginViews. It manages a database of PluginPackages. Asking it for a PluginView is therefore illogical, as explained in comment #8. It lacks the logical hierarchy of a well-designed API. This change makes PluginView API consistent with the PluginPackage API, where we call PluginPackage::createPackage.
Comment 12 Adam Roben (:aroben) 2008-02-13 08:14:59 PST
Comment on attachment 19067 [details]
Updated patch with Jon's suggestions

+#include "KURL.h"
 #include "PlatformString.h"
 #include "PluginPackage.h"
 #include "StringHash.h"
@@ -37,7 +38,6 @@ namespace WebCore {
     class Element;
     class Frame;
     class IntSize;
-    class KURL;

I know Jon said to include KURL.h, but I think he was mistaken and it's not really needed. Everything should compile fine with just a forward declaration, so you should be able to undo this change.

r=me
Comment 13 Rodney Dawes 2008-02-13 09:19:54 PST
Created attachment 19114 [details]
Updated to revert the KURL.h change in PluginDatabase.h
Comment 14 Adam Roben (:aroben) 2008-02-13 09:29:08 PST
Landed in r30203