Reviewed by Adam.
[WebKit-https.git] / WebKit / win / WebDatabaseManager.cpp
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