Use FOR_EACH_COCLASS in WebKitClassFactory
authoraroben <aroben@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 25 Oct 2007 05:22:30 +0000 (05:22 +0000)
committeraroben <aroben@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 25 Oct 2007 05:22:30 +0000 (05:22 +0000)
         Reviewed by Ada.

         * WebError.cpp:
         (WebError::createInstance): Added an overload that takes no arguments
         to make the macro used in WebKitClassFactory work.
         * WebError.h:
         * WebKitClassFactory.cpp:
         (WebKitClassFactory::CreateInstance): Use FOR_EACH_COCLASS.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@27018 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKit/win/ChangeLog
WebKit/win/WebError.cpp
WebKit/win/WebError.h
WebKit/win/WebKitClassFactory.cpp

index e53bf456be2d6bbdbdc9cbad9cf3593117b1fb98..91ce6b38d41ca32ba50095ce809ead3510f78da7 100644 (file)
@@ -1,3 +1,16 @@
+2007-10-24  Adam Roben  <aroben@apple.com>
+
+        Use FOR_EACH_COCLASS in WebKitClassFactory
+
+        Reviewed by Ada.
+
+        * WebError.cpp:
+        (WebError::createInstance): Added an overload that takes no arguments
+        to make the macro used in WebKitClassFactory work.
+        * WebError.h:
+        * WebKitClassFactory.cpp:
+        (WebKitClassFactory::CreateInstance): Use FOR_EACH_COCLASS.
+
 2007-10-24  Adam Roben  <aroben@apple.com>
 
         Put FOR_EACH_COCLASS macro into its own file and export it
index 1b6a660f03b197e71c913eeb9a164aa74f6ee7ec..9c080f634506579c73bbe61732b36a9ca249b2b5 100644 (file)
@@ -57,6 +57,11 @@ WebError* WebError::createInstance(const ResourceError& error, IPropertyBag* use
     return instance;
 }
 
+WebError* WebError::createInstance()
+{
+    return createInstance(ResourceError());
+}
+
 // IUnknown -------------------------------------------------------------------
 
 HRESULT STDMETHODCALLTYPE WebError::QueryInterface(REFIID riid, void** ppvObject)
index 189d998cd7a32edc2787b85be96fc012cb67615a..65c0f2e03edcf8194cb280d90534c86e118e8026 100644 (file)
@@ -37,6 +37,7 @@
 class WebError : public IWebError, IWebErrorPrivate {
 public:
     static WebError* createInstance(const WebCore::ResourceError&, IPropertyBag* userInfo = 0);
+    static WebError* createInstance();
 protected:
     WebError(const WebCore::ResourceError&, IPropertyBag* userInfo);
     ~WebError();
index 1555ce648bd838002b9696561b29c1ba3d620e78..d589b6ff20a6dd5da8c606a1c6037abcbb5d2a62 100644 (file)
@@ -27,6 +27,7 @@
 #include "WebKitDLL.h"
 #include "WebKitClassFactory.h"
 
+#include "ForEachCoClass.h"
 #include "CFDictionaryPropertyBag.h"
 #include "WebCache.h"
 #include "WebDownload.h"
@@ -113,47 +114,29 @@ HRESULT STDMETHODCALLTYPE WebKitClassFactory::CreateInstance(IUnknown* pUnkOuter
     if (pUnkOuter)
         return CLASS_E_NOAGGREGATION;
 
-    if (IsEqualGUID(m_targetClass, CLSID_WebView))
-        unknown = static_cast<IWebView*>(WebView::createInstance());
-    else if (IsEqualGUID(m_targetClass, CLSID_WebIconDatabase))
-        unknown = static_cast<IWebIconDatabase*>(WebIconDatabase::createInstance());
-    else if (IsEqualGUID(m_targetClass, CLSID_WebMutableURLRequest))
-        unknown = static_cast<IWebMutableURLRequest*>(WebMutableURLRequest::createInstance());
-    else if (IsEqualGUID(m_targetClass, CLSID_WebNotificationCenter))
-        unknown = static_cast<IWebNotificationCenter*>(WebNotificationCenter::createInstance());
-    else if (IsEqualGUID(m_targetClass, CLSID_WebHistory))
-        unknown = static_cast<IWebHistory*>(WebHistory::createInstance());
-    else if (IsEqualGUID(m_targetClass, CLSID_CFDictionaryPropertyBag))
-        unknown = static_cast<IPropertyBag*>(CFDictionaryPropertyBag::createInstance());
-    else if (IsEqualGUID(m_targetClass, CLSID_WebHistoryItem))
-        unknown = static_cast<IWebHistoryItem*>(WebHistoryItem::createInstance());
-    else if (IsEqualGUID(m_targetClass, CLSID_WebCache))
-        unknown = static_cast<IWebCache*>(WebCache::createInstance());
-    else if (IsEqualGUID(m_targetClass, CLSID_WebJavaScriptCollector))
-        unknown = static_cast<IWebJavaScriptCollector*>(WebJavaScriptCollector::createInstance());
-    else if (IsEqualGUID(m_targetClass, CLSID_WebPreferences))
-        unknown = static_cast<IWebPreferences*>(WebPreferences::createInstance());
-    else if (IsEqualGUID(m_targetClass, CLSID_WebScrollBar))
-        unknown = static_cast<IWebScrollBarPrivate*>(WebScrollBar::createInstance());
-    else if (IsEqualGUID(m_targetClass, CLSID_WebKitStatistics))
-        unknown = static_cast<IWebKitStatistics*>(WebKitStatistics::createInstance());
-    else if (IsEqualGUID(m_targetClass, CLSID_WebError))
-        unknown = static_cast<IWebError*>(WebError::createInstance(ResourceError()));
-    else if (IsEqualGUID(m_targetClass, CLSID_WebURLCredential))
-        unknown = static_cast<IWebURLCredential*>(WebURLCredential::createInstance());
-    else if (IsEqualGUID(m_targetClass, CLSID_WebDownload))
-        unknown = static_cast<IWebDownload*>(WebDownload::createInstance());
-    else if (IsEqualGUID(m_targetClass, CLSID_WebURLRequest))
-        unknown = static_cast<IWebURLRequest*>(WebMutableURLRequest::createImmutableInstance());
-    else if (IsEqualGUID(m_targetClass, CLSID_WebURLProtectionSpace))
-        unknown = static_cast<IWebURLProtectionSpace*>(WebURLProtectionSpace::createInstance());
-    else if (IsEqualGUID(m_targetClass, CLSID_WebDebugProgram))
-        unknown = static_cast<IWebDebugProgram*>(WebDebugProgram::createInstance());
-    else if (IsEqualGUID(m_targetClass, CLSID_WebURLResponse))
-        unknown = static_cast<IWebURLResponse*>(WebURLResponse::createInstance());
-    else
+#define INITIALIZE_IF_CLASS(cls) \
+    if (IsEqualGUID(m_targetClass, CLSID_##cls)) \
+        unknown = static_cast<I##cls*>(cls::createInstance()); \
+    else \
+    // end of macro
+
+    // These #defines are needed to appease the INITIALIZE_IF_CLASS macro.
+    // There is no ICFDictionaryPropertyBag, we use IPropertyBag instead.
+#define ICFDictionaryPropertyBag IPropertyBag
+    // There is no IWebScrollBar, we only have IWebScrollBarPrivate.
+#define IWebScrollBar IWebScrollBarPrivate
+    // There is no class called WebURLRequest -- WebMutableURLRequest implements it for us.
+#define WebURLRequest WebMutableURLRequest
+
+    FOR_EACH_COCLASS(INITIALIZE_IF_CLASS)
+        // This is the final else case
         return CLASS_E_CLASSNOTAVAILABLE;
 
+#undef ICFDictionaryPropertyBag
+#undef IWebScrollBar
+#undef WebURLRequest
+#undef INITIALIZE_IF_CLASS
+
     if (!unknown)
         return E_OUTOFMEMORY;