Reviewed by Darin.
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 27 Nov 2007 21:43:18 +0000 (21:43 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 27 Nov 2007 21:43:18 +0000 (21:43 +0000)
        Add COMEnumVariant, a templatized class with implements IEnumVARIANT and lets
        you enumerate over a C++ container, be it WTF or STL.

        * COMEnumVariant.h: Added.

        * WebDatabaseManager.cpp:
        (WebDatabaseManager::origins):
        (WebDatabaseManager::databasesWithOrigin):
        Implement these using COMEnumVariant.

        * WebSecurityOrigin.cpp:
        (WebSecurityOrigin::QueryInterface):
        * WebSecurityOrigin.h:
        Add a UUID for the implementation so that other parts of WebKit can access
        the WebCore::SecurityOriginData object.

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

WebKit/win/COMEnumVariant.h [new file with mode: 0644]
WebKit/win/ChangeLog
WebKit/win/WebDatabaseManager.cpp
WebKit/win/WebSecurityOrigin.cpp
WebKit/win/WebSecurityOrigin.h

diff --git a/WebKit/win/COMEnumVariant.h b/WebKit/win/COMEnumVariant.h
new file mode 100644 (file)
index 0000000..84a4966
--- /dev/null
@@ -0,0 +1,208 @@
+/*\r
+ * Copyright (C) 2007 Apple Inc. All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ * 1.  Redistributions of source code must retain the above copyright\r
+ *     notice, this list of conditions and the following disclaimer.\r
+ * 2.  Redistributions in binary form must reproduce the above copyright\r
+ *     notice, this list of conditions and the following disclaimer in the\r
+ *     documentation and/or other materials provided with the distribution.\r
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of\r
+ *     its contributors may be used to endorse or promote products derived\r
+ *     from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY\r
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY\r
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\r
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+#ifndef COMEnumVariant_h\r
+#define COMEnumVariant_h\r
+\r
+#define NOMINMAX\r
+#include <unknwn.h>\r
+\r
+#include <WebCore/BString.h>\r
+#include <WTF/Assertions.h>\r
+#include <WTF/Noncopyable.h>\r
+\r
+namespace WebCore {\r
+    class String;\r
+}\r
+\r
+template<typename T> struct COMVariantSetter {};\r
+\r
+template<> struct COMVariantSetter<WebCore::String>\r
+{\r
+    static void setVariant(VARIANT* variant, const WebCore::String& value)\r
+    {\r
+        ASSERT(V_VT(variant) == VT_EMPTY);\r
+\r
+        V_VT(variant) = VT_BSTR;\r
+        V_BSTR(variant) = WebCore::BString(value).release();\r
+    }\r
+};\r
+\r
+template<typename COMType, typename UnderlyingType>\r
+struct COMIUnknownVariantSetter\r
+{\r
+    static void setVariant(VARIANT* variant, const UnderlyingType& value)\r
+    {\r
+        ASSERT(V_VT(variant) == VT_EMPTY);\r
+\r
+        V_VT(variant) = VT_UNKNOWN;\r
+        V_UNKNOWN(variant) = COMType::createInstance(value);\r
+    }\r
+};\r
+\r
+template<typename ContainerType>\r
+class COMEnumVariant : public IEnumVARIANT, Noncopyable {\r
+public:\r
+    static COMEnumVariant* adopt(ContainerType&);\r
+    static COMEnumVariant* createInstance(const ContainerType&);\r
+\r
+    // IUnknown\r
+    virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject);\r
+    virtual ULONG STDMETHODCALLTYPE AddRef();\r
+    virtual ULONG STDMETHODCALLTYPE Release();\r
+\r
+    // IEnumVARIANT\r
+    virtual HRESULT STDMETHODCALLTYPE Next(ULONG celt, VARIANT* rgVar, ULONG* pCeltFetched);\r
+    virtual HRESULT STDMETHODCALLTYPE Skip(ULONG celt);\r
+    virtual HRESULT STDMETHODCALLTYPE Reset();\r
+    virtual HRESULT STDMETHODCALLTYPE Clone(IEnumVARIANT** ppEnum);\r
+\r
+private:\r
+    COMEnumVariant()\r
+        : m_refCount(0)\r
+    {\r
+    }\r
+\r
+    COMEnumVariant(const ContainerType& container)\r
+        : m_refCount(0)\r
+        , m_container(container)       \r
+        , m_currentPos(m_container.begin())\r
+    {\r
+    }\r
+\r
+    ~COMEnumVariant() {}\r
+\r
+    ULONG m_refCount;\r
+\r
+    ContainerType m_container;\r
+    typename ContainerType::const_iterator m_currentPos;\r
+};\r
+\r
+// COMEnumVariant ------------------------------------------------------------------\r
+template<typename ContainerType>\r
+COMEnumVariant<typename ContainerType>* COMEnumVariant<ContainerType>::adopt(ContainerType& container) \r
+{\r
+    COMEnumVariant* instance = new COMEnumVariant;\r
+    instance->m_container.swap(container);\r
+    instance->m_currentPos = instance->m_container.begin();\r
+    instance->AddRef();\r
+    return instance;\r
+}\r
+\r
+template<typename ContainerType>\r
+COMEnumVariant<typename ContainerType>* COMEnumVariant<ContainerType>::createInstance(const ContainerType& container)\r
+{\r
+    COMEnumVariant* instance = new COMEnumVariant(container);\r
+    instance->AddRef();\r
+    return instance;\r
+}\r
+\r
+// IUnknown ------------------------------------------------------------------------\r
+template<typename ContainerType>\r
+HRESULT STDMETHODCALLTYPE COMEnumVariant<ContainerType>::QueryInterface(REFIID riid, void** ppvObject)\r
+{\r
+    *ppvObject = 0;\r
+    if (IsEqualGUID(riid, IID_IUnknown))\r
+        *ppvObject = static_cast<COMEnumVariant*>(this);\r
+    else if (IsEqualGUID(riid, IID_IEnumVARIANT))\r
+        *ppvObject = static_cast<COMEnumVariant*>(this);\r
+    else\r
+        return E_NOINTERFACE;\r
+\r
+    AddRef();\r
+    return S_OK;\r
+}\r
+\r
+template<typename ContainerType>\r
+ULONG STDMETHODCALLTYPE COMEnumVariant<ContainerType>::AddRef()\r
+{\r
+    return ++m_refCount;\r
+}\r
+\r
+template<typename ContainerType>\r
+ULONG STDMETHODCALLTYPE COMEnumVariant<ContainerType>::Release()\r
+{\r
+    ULONG newRef = --m_refCount;\r
+    if (!newRef)\r
+        delete this;\r
+\r
+    return newRef;\r
+}\r
+\r
+// IEnumVARIANT --------------------------------------------------------------------\r
+template<typename ContainerType>\r
+HRESULT STDMETHODCALLTYPE COMEnumVariant<ContainerType>::Next(ULONG celt, VARIANT* rgVar, ULONG* pCeltFetched)\r
+{\r
+    if (pCeltFetched)\r
+        *pCeltFetched = 0;\r
+    if (!rgVar)\r
+        return E_POINTER;\r
+    for (unsigned i = 0 ; i < celt; i++)\r
+        VariantInit(&rgVar[i]);\r
+\r
+    for (unsigned i = 0; i < celt; i++) {\r
+        if (m_currentPos == m_container.end())\r
+            return S_FALSE;\r
+\r
+        COMVariantSetter<ContainerType::ValueType>::setVariant(&rgVar[i], *m_currentPos);\r
+        ++m_currentPos;\r
+    }\r
+\r
+    return S_OK;\r
+}\r
+\r
+template<typename ContainerType>\r
+HRESULT STDMETHODCALLTYPE COMEnumVariant<ContainerType>::Skip(ULONG celt) \r
+{\r
+    for (unsigned i = 0; i < celt; i++) {\r
+        if (m_currentPos == m_container.end())\r
+            return S_FALSE;\r
+\r
+        ++m_currentPos;\r
+    }\r
+    return S_OK;\r
+}\r
+    \r
+template<typename ContainerType>\r
+HRESULT STDMETHODCALLTYPE COMEnumVariant<ContainerType>::Reset() \r
+{\r
+    m_currentPos = m_container.begin();\r
+    return S_OK;\r
+}\r
+    \r
+template<typename ContainerType>\r
+HRESULT STDMETHODCALLTYPE COMEnumVariant<ContainerType>::Clone(IEnumVARIANT** ppEnum)\r
+{\r
+    if (!ppEnum)\r
+        return E_POINTER;\r
+\r
+    *ppEnum = 0;\r
+    return E_NOTIMPL;\r
+}\r
+\r
+#endif\r
index 924cadca654c8dfb3401ac2b52523ad14941bfd9..a6bd551fdad0954da75d0ae4f99d489fff065267 100644 (file)
@@ -1,3 +1,23 @@
+2007-11-27  Anders Carlsson  <andersca@apple.com>
+
+        Reviewed by Darin.
+   
+        Add COMEnumVariant, a templatized class with implements IEnumVARIANT and lets
+        you enumerate over a C++ container, be it WTF or STL.
+        
+        * COMEnumVariant.h: Added.
+        
+        * WebDatabaseManager.cpp:
+        (WebDatabaseManager::origins):
+        (WebDatabaseManager::databasesWithOrigin):
+        Implement these using COMEnumVariant.
+        
+        * WebSecurityOrigin.cpp:
+        (WebSecurityOrigin::QueryInterface):
+        * WebSecurityOrigin.h:
+        Add a UUID for the implementation so that other parts of WebKit can access
+        the WebCore::SecurityOriginData object.
+        
 2007-11-26  Adam Roben  <aroben@apple.com>
 
         Take advantage of the new Color constructor that takes a CGColorRef
index d6e77b891e72a8b1df04e24f76d12ab15a499231..16653406aa2bd845be9eba77bca13c58c43d44fa 100644 (file)
 #include "WebDatabaseManager.h"\r
 #include "WebKitDLL.h"\r
 \r
+#include "COMEnumVariant.h"\r
+#include "WebSecurityOrigin.h"\r
+\r
+#include <WebCore/BString.h>\r
+#include <WebCore/COMPtr.h>\r
 #include <WebCore/DatabaseTracker.h>\r
 #include <WebCore/FileSystem.h>\r
-#include <WebCore/COMPtr.h>\r
+#include <WebCore/SecurityOriginData.h>\r
 \r
 using namespace WebCore;\r
 \r
-static COMPtr<WebDatabaseManager> s_sharedWebDatabaseManager;
+static COMPtr<WebDatabaseManager> s_sharedWebDatabaseManager;\r
 \r
 // WebDatabaseManager --------------------------------------------------------------\r
 WebDatabaseManager* WebDatabaseManager::createInstance()\r
@@ -85,6 +90,8 @@ ULONG STDMETHODCALLTYPE WebDatabaseManager::Release()
     return newRef;\r
 }\r
 \r
+template<> struct COMVariantSetter<SecurityOriginData> : COMIUnknownVariantSetter<WebSecurityOrigin, SecurityOriginData> {};\r
+\r
 // IWebDatabaseManager -------------------------------------------------------------\r
 HRESULT STDMETHODCALLTYPE WebDatabaseManager::sharedWebDatabaseManager( \r
     /* [retval][out] */ IWebDatabaseManager** result)\r
@@ -106,7 +113,12 @@ HRESULT STDMETHODCALLTYPE WebDatabaseManager::origins(
     if (this != s_sharedWebDatabaseManager)\r
         return E_FAIL;\r
 \r
-    return E_NOTIMPL;\r
+    Vector<SecurityOriginData> origins;\r
+    DatabaseTracker::tracker().origins(origins);\r
+    COMPtr<COMEnumVariant<Vector<SecurityOriginData> > > enumVariant(AdoptCOM, COMEnumVariant<Vector<SecurityOriginData> >::adopt(origins));\r
+\r
+    *result = enumVariant.releaseRef();\r
+    return S_OK;\r
 }\r
     \r
 HRESULT STDMETHODCALLTYPE WebDatabaseManager::databasesWithOrigin( \r
@@ -121,9 +133,19 @@ HRESULT STDMETHODCALLTYPE WebDatabaseManager::databasesWithOrigin(
     if (this != s_sharedWebDatabaseManager)\r
         return E_FAIL;\r
 \r
-    return E_NOTIMPL;\r
+    COMPtr<WebSecurityOrigin> webSecurityOrigin(Query, origin);\r
+    if (!webSecurityOrigin)\r
+        return E_FAIL;\r
+\r
+    Vector<String> databaseNames;\r
+    DatabaseTracker::tracker().databaseNamesForOrigin(webSecurityOrigin->securityOriginData(), databaseNames);\r
+\r
+    COMPtr<COMEnumVariant<Vector<String> > > enumVariant(AdoptCOM, COMEnumVariant<Vector<String> >::adopt(databaseNames));\r
+\r
+    *result = enumVariant.releaseRef();\r
+    return S_OK;\r
 }\r
-    \r
+\r
 HRESULT STDMETHODCALLTYPE WebDatabaseManager::detailsForDatabaseWithOrigin( \r
     /* [in] */ BSTR* database,\r
     /* [in] */ IWebSecurityOrigin* origin,\r
index 9c22ce51566c4675dedf490676819b1d150e9ece..3c3d05299edf3e476e8c3c0be2f63e6e270a4a0d 100644 (file)
@@ -63,6 +63,8 @@ HRESULT STDMETHODCALLTYPE WebSecurityOrigin::QueryInterface(REFIID riid, void**
         *ppvObject = static_cast<IWebSecurityOrigin*>(this);\r
     else if (IsEqualGUID(riid, IID_IWebSecurityOrigin))\r
         *ppvObject = static_cast<IWebSecurityOrigin*>(this);\r
+    else if (IsEqualGUID(riid, __uuidof(this)))\r
+        *ppvObject = this;\r
     else\r
         return E_NOINTERFACE;\r
 \r
index d68a7a66d4abdfa79b1f719bb2ecec4933b66c05..b07dc7639169e5c64f4e2cd94d42324784c9167e 100644 (file)
 #include "IWebSecurityOrigin.h"\r
 #include <WebCore/SecurityOriginData.h>\r
 \r
-class WebSecurityOrigin : public IWebSecurityOrigin {\r
+class DECLSPEC_UUID("6EB8D98F-2723-4472-88D3-5936F9D6E631") WebSecurityOrigin : public IWebSecurityOrigin {\r
 public:\r
+    // WebSecurityOrigin\r
     static WebSecurityOrigin* createInstance(const WebCore::SecurityOriginData& securityOriginData);\r
+    const WebCore::SecurityOriginData& securityOriginData() const { return m_securityOriginData; }\r
 \r
     // IUnknown\r
     virtual HRESULT STDMETHODCALLTYPE QueryInterface( \r