Reviewed by Adam.
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 27 Nov 2007 23:57:43 +0000 (23:57 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 27 Nov 2007 23:57:43 +0000 (23:57 +0000)
        Implement the rest of the WebDatabaseManager API.

        * COMEnumVariant.h:
        * Interfaces/IWebDatabaseManager.idl:
        * WebDatabaseManager.cpp:
        (isEqual):
        (DatabaseDetailsPropertyBag::DatabaseDetailsPropertyBag):
        (DatabaseDetailsPropertyBag::~DatabaseDetailsPropertyBag):
        (DatabaseDetailsPropertyBag::createInstance):
        (DatabaseDetailsPropertyBag::AddRef):
        (DatabaseDetailsPropertyBag::Release):
        (DatabaseDetailsPropertyBag::QueryInterface):
        (DatabaseDetailsPropertyBag::Read):
        (DatabaseDetailsPropertyBag::Write):
        (WebDatabaseManager::detailsForDatabaseWithOrigin):
        (WebDatabaseManager::deleteAllDatabases):
        (WebDatabaseManager::deleteDatabasesWithOrigin):
        (WebDatabaseManager::deleteDatabaseWithOrigin):
        * WebDatabaseManager.h:

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

WebKit/win/COMEnumVariant.h
WebKit/win/ChangeLog
WebKit/win/Interfaces/IWebDatabaseManager.idl
WebKit/win/WebDatabaseManager.cpp
WebKit/win/WebDatabaseManager.h

index 318a77e598b3a4bf5fc28c8183e0b4b54287c8d2..4e46bf20634594efd4e1b98b6d370f3b29cd9701 100644 (file)
@@ -53,6 +53,17 @@ template<> struct COMVariantSetter<WebCore::String>
     }\r
 };\r
 \r
+template<> struct COMVariantSetter<unsigned long long>\r
+{\r
+    static void setVariant(VARIANT* variant, unsigned long long value)\r
+    {\r
+        ASSERT(V_VT(variant) == VT_EMPTY);\r
+\r
+        V_VT(variant) = VT_UI8;\r
+        V_UI8(variant) = value;\r
+    }\r
+};\r
+\r
 template<typename COMType, typename UnderlyingType>\r
 struct COMIUnknownVariantSetter\r
 {\r
index 7db8d32e9e996aa882db283abf3c695a8903ea1a..615e4cde76cc59e77dd5cda0d45a965349956036 100644 (file)
@@ -1,3 +1,27 @@
+2007-11-27  Anders Carlsson  <andersca@apple.com>
+
+        Reviewed by Adam.
+
+        Implement the rest of the WebDatabaseManager API.
+
+        * COMEnumVariant.h:
+        * Interfaces/IWebDatabaseManager.idl:
+        * WebDatabaseManager.cpp:
+        (isEqual):
+        (DatabaseDetailsPropertyBag::DatabaseDetailsPropertyBag):
+        (DatabaseDetailsPropertyBag::~DatabaseDetailsPropertyBag):
+        (DatabaseDetailsPropertyBag::createInstance):
+        (DatabaseDetailsPropertyBag::AddRef):
+        (DatabaseDetailsPropertyBag::Release):
+        (DatabaseDetailsPropertyBag::QueryInterface):
+        (DatabaseDetailsPropertyBag::Read):
+        (DatabaseDetailsPropertyBag::Write):
+        (WebDatabaseManager::detailsForDatabaseWithOrigin):
+        (WebDatabaseManager::deleteAllDatabases):
+        (WebDatabaseManager::deleteDatabasesWithOrigin):
+        (WebDatabaseManager::deleteDatabaseWithOrigin):
+        * WebDatabaseManager.h:
+
 2007-11-27  Ada Chan  <adachan@apple.com>
 
         <rdar://problem/5616098> The BSTR returned by WebHistoryItem::alternateTitle
index 62a0ef904e959582e3221d69a34713c810535237..fd1f793ba746afbfe3630fffd1f2c482214ccea6 100644 (file)
@@ -72,9 +72,9 @@ interface IWebDatabaseManager : IUnknown
 
     HRESULT origins([out, retval] IEnumVARIANT** result);
     HRESULT databasesWithOrigin([in] IWebSecurityOrigin* origin, [out, retval] IEnumVARIANT** result);
-    HRESULT detailsForDatabaseWithOrigin([in] BSTR* database, [in] IWebSecurityOrigin* origin, [out, retval] IPropertyBag **result);
+    HRESULT detailsForDatabaseWithOrigin([in] BSTR databaseName, [in] IWebSecurityOrigin* origin, [out, retval] IPropertyBag **result);
 
     HRESULT deleteAllDatabases();
     HRESULT deleteDatabasesWithOrigin([in] IWebSecurityOrigin* origin);
-    HRESULT deleteDatabaseWithOrigin([in] BSTR* databaseName, [in] IWebSecurityOrigin* origin);
+    HRESULT deleteDatabaseWithOrigin([in] BSTR databaseName, [in] IWebSecurityOrigin* origin);
 }
index 16653406aa2bd845be9eba77bca13c58c43d44fa..6ba632c1902e639108000bbb56e04f6c22c70160 100644 (file)
 \r
 using namespace WebCore;\r
 \r
+static inline bool isEqual(LPCWSTR s1, LPCWSTR s2)
+{
+    return !wcscmp(s1, s2);
+}
+\r
+class DatabaseDetailsPropertyBag : public IPropertyBag, Noncopyable {\r
+public:\r
+    static DatabaseDetailsPropertyBag* createInstance(const DatabaseDetails&);\r
+\r
+    // IUnknown\r
+    virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject);\r
+    virtual ULONG STDMETHODCALLTYPE AddRef();\r
+    virtual ULONG STDMETHODCALLTYPE Release();\r
+\r
+    // IPropertyBag\r
+    virtual HRESULT STDMETHODCALLTYPE Read(LPCOLESTR pszPropName, VARIANT* pVar, IErrorLog* pErrorLog);\r
+    virtual HRESULT STDMETHODCALLTYPE Write(LPCOLESTR pszPropName, VARIANT* pVar);\r
+private:\r
+    DatabaseDetailsPropertyBag(const DatabaseDetails& details) \r
+        : m_refCount(0)\r
+        , m_details(details) { }\r
+    ~DatabaseDetailsPropertyBag() { }\r
+\r
+    ULONG m_refCount;\r
+    DatabaseDetails m_details;\r
+};\r
+\r
+// DatabaseDetailsPropertyBag ------------------------------------------------------\r
+DatabaseDetailsPropertyBag* DatabaseDetailsPropertyBag::createInstance(const DatabaseDetails& details)\r
+{\r
+    DatabaseDetailsPropertyBag* instance = new DatabaseDetailsPropertyBag(details);\r
+    instance->AddRef();\r
+    return instance;\r
+}\r
+\r
+// IUnknown ------------------------------------------------------------------------\r
+ULONG STDMETHODCALLTYPE DatabaseDetailsPropertyBag::AddRef()\r
+{\r
+    return ++m_refCount;\r
+}\r
+\r
+ULONG STDMETHODCALLTYPE DatabaseDetailsPropertyBag::Release()\r
+{\r
+    ULONG newRef = --m_refCount;\r
+    if (!newRef)\r
+        delete this;\r
+\r
+    return newRef;\r
+}\r
+\r
+HRESULT STDMETHODCALLTYPE DatabaseDetailsPropertyBag::QueryInterface(REFIID riid, void** ppvObject)\r
+{\r
+    *ppvObject = 0;\r
+    if (IsEqualGUID(riid, IID_IUnknown))\r
+        *ppvObject = static_cast<DatabaseDetailsPropertyBag*>(this);\r
+    else if (IsEqualGUID(riid, IID_IPropertyBag))\r
+        *ppvObject = static_cast<DatabaseDetailsPropertyBag*>(this);\r
+    else\r
+        return E_NOINTERFACE;\r
+\r
+    AddRef();\r
+    return S_OK;\r
+}\r
+\r
+// IPropertyBag --------------------------------------------------------------------\r
+HRESULT STDMETHODCALLTYPE DatabaseDetailsPropertyBag::Read(LPCOLESTR pszPropName, VARIANT* pVar, IErrorLog*)\r
+{\r
+    if (!pszPropName || !pVar)\r
+        return E_POINTER;\r
+\r
+    VariantInit(pVar);\r
+\r
+    if (isEqual(pszPropName, WebDatabaseDisplayNameKey)) {\r
+        COMVariantSetter<String>::setVariant(pVar, m_details.displayName());\r
+        return S_OK;\r
+    } else if (isEqual(pszPropName, WebDatabaseExpectedSizeKey)) {\r
+        COMVariantSetter<unsigned long long>::setVariant(pVar, m_details.expectedUsage());\r
+        return S_OK;\r
+    } else if (isEqual(pszPropName, WebDatabaseUsageKey)) {\r
+        COMVariantSetter<unsigned long long>::setVariant(pVar, m_details.currentUsage());\r
+        return S_OK;\r
+    }\r
+\r
+    return E_INVALIDARG;\r
+}\r
+\r
+HRESULT STDMETHODCALLTYPE DatabaseDetailsPropertyBag::Write(LPCOLESTR pszPropName, VARIANT* pVar)\r
+{\r
+    if (!pszPropName || !pVar)\r
+        return E_POINTER;\r
+\r
+    return E_FAIL;\r
+}\r
+\r
 static COMPtr<WebDatabaseManager> s_sharedWebDatabaseManager;\r
 \r
 // WebDatabaseManager --------------------------------------------------------------\r
@@ -147,11 +241,11 @@ HRESULT STDMETHODCALLTYPE WebDatabaseManager::databasesWithOrigin(
 }\r
 \r
 HRESULT STDMETHODCALLTYPE WebDatabaseManager::detailsForDatabaseWithOrigin( \r
-    /* [in] */ BSTR* database,\r
+    /* [in] */ BSTR databaseName,\r
     /* [in] */ IWebSecurityOrigin* origin,\r
     /* [retval][out] */ IPropertyBag** result)\r
 {\r
-    if (!database || !origin || !result)\r
+    if (!databaseName || !origin || !result)\r
         return E_POINTER;\r
 \r
     *result = 0;\r
@@ -159,7 +253,18 @@ HRESULT STDMETHODCALLTYPE WebDatabaseManager::detailsForDatabaseWithOrigin(
     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
+    DatabaseDetails details = DatabaseTracker::tracker().detailsForNameAndOrigin(String(databaseName, SysStringLen(databaseName)),\r
+        webSecurityOrigin->securityOriginData());\r
+\r
+    if (!details.isValid())\r
+        return E_INVALIDARG;\r
+\r
+    *result = DatabaseDetailsPropertyBag::createInstance(details);\r
+    return S_OK;\r
 }\r
     \r
 HRESULT STDMETHODCALLTYPE WebDatabaseManager::deleteAllDatabases()\r
@@ -167,7 +272,9 @@ HRESULT STDMETHODCALLTYPE WebDatabaseManager::deleteAllDatabases()
     if (this != s_sharedWebDatabaseManager)\r
         return E_FAIL;\r
 \r
-    return E_NOTIMPL;\r
+    DatabaseTracker::tracker().deleteAllDatabases();\r
+\r
+    return S_OK;\r
 }\r
    \r
 HRESULT STDMETHODCALLTYPE WebDatabaseManager::deleteDatabasesWithOrigin( \r
@@ -179,11 +286,17 @@ HRESULT STDMETHODCALLTYPE WebDatabaseManager::deleteDatabasesWithOrigin(
     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
+    DatabaseTracker::tracker().deleteDatabasesWithOrigin(webSecurityOrigin->securityOriginData());\r
+\r
+    return S_OK;\r
 }\r
     \r
 HRESULT STDMETHODCALLTYPE WebDatabaseManager::deleteDatabaseWithOrigin( \r
-    /* [in] */ BSTR* databaseName,\r
+    /* [in] */ BSTR databaseName,\r
     /* [in] */ IWebSecurityOrigin* origin)\r
 {\r
     if (!databaseName || !origin)\r
@@ -192,7 +305,13 @@ HRESULT STDMETHODCALLTYPE WebDatabaseManager::deleteDatabaseWithOrigin(
     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
+    DatabaseTracker::tracker().deleteDatabase(webSecurityOrigin->securityOriginData(), String(databaseName, SysStringLen(databaseName)));\r
+\r
+    return S_OK;\r
 }\r
 \r
 void WebKitSetWebDatabasesPathIfNecessary()\r
index 1d4229a57d95253f098410eb4d3259ae6033d6c2..fdc9fb0fec13af2e04f1cae386c2fc56d15fcbd6 100644 (file)
@@ -55,7 +55,7 @@ public:
         /* [retval][out] */ IEnumVARIANT** result);\r
         \r
     virtual HRESULT STDMETHODCALLTYPE detailsForDatabaseWithOrigin( \r
-        /* [in] */ BSTR* database,\r
+        /* [in] */ BSTR databaseName,\r
         /* [in] */ IWebSecurityOrigin* origin,\r
         /* [retval][out] */ IPropertyBag** result);\r
         \r
@@ -65,7 +65,7 @@ public:
         /* [in] */ IWebSecurityOrigin* origin);\r
         \r
     virtual HRESULT STDMETHODCALLTYPE deleteDatabaseWithOrigin( \r
-        /* [in] */ BSTR* databaseName,\r
+        /* [in] */ BSTR databaseName,\r
         /* [in] */ IWebSecurityOrigin* origin);\r
 private:\r
     WebDatabaseManager();\r