2 * Copyright (C) 2007 Apple Inc. All rights reserved.
\r
4 * Redistribution and use in source and binary forms, with or without
\r
5 * modification, are permitted provided that the following conditions
\r
8 * 1. Redistributions of source code must retain the above copyright
\r
9 * notice, this list of conditions and the following disclaimer.
\r
10 * 2. Redistributions in binary form must reproduce the above copyright
\r
11 * notice, this list of conditions and the following disclaimer in the
\r
12 * documentation and/or other materials provided with the distribution.
\r
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
\r
14 * its contributors may be used to endorse or promote products derived
\r
15 * from this software without specific prior written permission.
\r
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
\r
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
\r
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
\r
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
\r
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
\r
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
\r
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
\r
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
\r
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
\r
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
29 #include "WebDatabaseManager.h"
\r
30 #include "WebKitDLL.h"
\r
32 #include "COMEnumVariant.h"
\r
33 #include "WebSecurityOrigin.h"
\r
35 #include <WebCore/BString.h>
\r
36 #include <WebCore/COMPtr.h>
\r
37 #include <WebCore/DatabaseTracker.h>
\r
38 #include <WebCore/FileSystem.h>
\r
39 #include <WebCore/SecurityOriginData.h>
\r
41 using namespace WebCore;
\r
43 static COMPtr<WebDatabaseManager> s_sharedWebDatabaseManager;
\r
45 // WebDatabaseManager --------------------------------------------------------------
\r
46 WebDatabaseManager* WebDatabaseManager::createInstance()
\r
48 WebDatabaseManager* manager = new WebDatabaseManager();
\r
53 WebDatabaseManager::WebDatabaseManager()
\r
59 WebDatabaseManager::~WebDatabaseManager()
\r
64 // IUnknown ------------------------------------------------------------------------
\r
65 HRESULT STDMETHODCALLTYPE WebDatabaseManager::QueryInterface(REFIID riid, void** ppvObject)
\r
68 if (IsEqualGUID(riid, IID_IUnknown))
\r
69 *ppvObject = static_cast<WebDatabaseManager*>(this);
\r
70 else if (IsEqualGUID(riid, IID_IWebDatabaseManager))
\r
71 *ppvObject = static_cast<WebDatabaseManager*>(this);
\r
73 return E_NOINTERFACE;
\r
79 ULONG STDMETHODCALLTYPE WebDatabaseManager::AddRef()
\r
81 return ++m_refCount;
\r
84 ULONG STDMETHODCALLTYPE WebDatabaseManager::Release()
\r
86 ULONG newRef = --m_refCount;
\r
93 template<> struct COMVariantSetter<SecurityOriginData> : COMIUnknownVariantSetter<WebSecurityOrigin, SecurityOriginData> {};
\r
95 // IWebDatabaseManager -------------------------------------------------------------
\r
96 HRESULT STDMETHODCALLTYPE WebDatabaseManager::sharedWebDatabaseManager(
\r
97 /* [retval][out] */ IWebDatabaseManager** result)
\r
99 if (!s_sharedWebDatabaseManager)
\r
100 s_sharedWebDatabaseManager.adoptRef(WebDatabaseManager::createInstance());
\r
102 return s_sharedWebDatabaseManager.copyRefTo(result);
\r
105 HRESULT STDMETHODCALLTYPE WebDatabaseManager::origins(
\r
106 /* [retval][out] */ IEnumVARIANT** result)
\r
113 if (this != s_sharedWebDatabaseManager)
\r
116 Vector<SecurityOriginData> origins;
\r
117 DatabaseTracker::tracker().origins(origins);
\r
118 COMPtr<COMEnumVariant<Vector<SecurityOriginData> > > enumVariant(AdoptCOM, COMEnumVariant<Vector<SecurityOriginData> >::adopt(origins));
\r
120 *result = enumVariant.releaseRef();
\r
124 HRESULT STDMETHODCALLTYPE WebDatabaseManager::databasesWithOrigin(
\r
125 /* [in] */ IWebSecurityOrigin* origin,
\r
126 /* [retval][out] */ IEnumVARIANT** result)
\r
128 if (!origin || !result)
\r
133 if (this != s_sharedWebDatabaseManager)
\r
136 COMPtr<WebSecurityOrigin> webSecurityOrigin(Query, origin);
\r
137 if (!webSecurityOrigin)
\r
140 Vector<String> databaseNames;
\r
141 DatabaseTracker::tracker().databaseNamesForOrigin(webSecurityOrigin->securityOriginData(), databaseNames);
\r
143 COMPtr<COMEnumVariant<Vector<String> > > enumVariant(AdoptCOM, COMEnumVariant<Vector<String> >::adopt(databaseNames));
\r
145 *result = enumVariant.releaseRef();
\r
149 HRESULT STDMETHODCALLTYPE WebDatabaseManager::detailsForDatabaseWithOrigin(
\r
150 /* [in] */ BSTR* database,
\r
151 /* [in] */ IWebSecurityOrigin* origin,
\r
152 /* [retval][out] */ IPropertyBag** result)
\r
154 if (!database || !origin || !result)
\r
159 if (this != s_sharedWebDatabaseManager)
\r
165 HRESULT STDMETHODCALLTYPE WebDatabaseManager::deleteAllDatabases()
\r
167 if (this != s_sharedWebDatabaseManager)
\r
173 HRESULT STDMETHODCALLTYPE WebDatabaseManager::deleteDatabasesWithOrigin(
\r
174 /* [in] */ IWebSecurityOrigin* origin)
\r
179 if (this != s_sharedWebDatabaseManager)
\r
185 HRESULT STDMETHODCALLTYPE WebDatabaseManager::deleteDatabaseWithOrigin(
\r
186 /* [in] */ BSTR* databaseName,
\r
187 /* [in] */ IWebSecurityOrigin* origin)
\r
189 if (!databaseName || !origin)
\r
192 if (this != s_sharedWebDatabaseManager)
\r
198 void WebKitSetWebDatabasesPathIfNecessary()
\r
200 static bool pathSet = false;
\r
204 WebCore::String databasesDirectory = WebCore::pathByAppendingComponent(WebCore::localUserSpecificStorageDirectory(), "Databases");
\r
205 WebCore::DatabaseTracker::tracker().setDatabasePath(databasesDirectory);
\r