2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "WebKitDLL.h"
28 #include "WebKitClassFactory.h"
30 #include "CFDictionaryPropertyBag.h"
31 #include "ForEachCoClass.h"
32 #include "WebArchive.h"
34 #include "WebCookieManager.h"
35 #include "WebCoreStatistics.h"
36 #include "WebDatabaseManager.h"
37 #include "WebDownload.h"
40 #include "WebGeolocationPosition.h"
41 #include "WebHistory.h"
42 #include "WebHistoryItem.h"
43 #include "WebIconDatabase.h"
44 #include "WebJavaScriptCollector.h"
46 #include "WebKitStatistics.h"
47 #include "WebMutableURLRequest.h"
48 #include "WebNotificationCenter.h"
49 #include "WebPreferences.h"
50 #include "WebScriptWorld.h"
51 #include "WebScrollBar.h"
52 #include "WebSerializedJSValue.h"
53 #include "WebTextRenderer.h"
54 #include "WebURLCredential.h"
55 #include "WebURLProtectionSpace.h"
56 #include "WebURLResponse.h"
57 #include "WebUserContentURLPattern.h"
59 #include "WebWorkersPrivate.h"
60 #include <JavaScriptCore/InitializeThreading.h>
61 #include <WebCore/SoftLinking.h>
62 #include <wtf/MainThread.h>
64 // WebKitClassFactory ---------------------------------------------------------
67 SOFT_LINK_DEBUG_LIBRARY(SafariTheme)
69 SOFT_LINK_LIBRARY(SafariTheme)
72 SOFT_LINK(SafariTheme, STInitialize, void, APIENTRY, (), ())
75 WebKitClassFactory::WebKitClassFactory(CLSID targetClass)
76 : m_targetClass(targetClass)
80 static bool didInitializeSafariTheme;
81 if (!didInitializeSafariTheme) {
82 if (SafariThemeLibrary())
84 didInitializeSafariTheme = true;
88 JSC::initializeThreading();
89 WTF::initializeMainThread();
92 gClassNameCount.add("WebKitClassFactory");
95 WebKitClassFactory::~WebKitClassFactory()
98 gClassNameCount.remove("WebKitClassFactory");
101 // IUnknown -------------------------------------------------------------------
103 HRESULT STDMETHODCALLTYPE WebKitClassFactory::QueryInterface(REFIID riid, void** ppvObject)
106 if (IsEqualGUID(riid, IID_IUnknown))
107 *ppvObject = static_cast<IUnknown*>(this);
108 else if (IsEqualGUID(riid, IID_IClassFactory))
109 *ppvObject = static_cast<IClassFactory*>(this);
111 return E_NOINTERFACE;
117 ULONG STDMETHODCALLTYPE WebKitClassFactory::AddRef(void)
122 ULONG STDMETHODCALLTYPE WebKitClassFactory::Release(void)
124 ULONG newRef = --m_refCount;
125 if (!newRef && !gLockCount)
131 // FIXME: Remove these functions once all createInstance() functions return COMPtr.
132 template <typename T>
133 static T* releaseRefFromCreateInstance(T* object)
138 template <typename T>
139 static T* releaseRefFromCreateInstance(COMPtr<T> object)
141 return object.releaseRef();
144 // IClassFactory --------------------------------------------------------------
146 HRESULT STDMETHODCALLTYPE WebKitClassFactory::CreateInstance(IUnknown* pUnkOuter, REFIID riid, void** ppvObject)
148 IUnknown* unknown = 0;
152 return CLASS_E_NOAGGREGATION;
154 #define INITIALIZE_IF_CLASS(cls) \
155 if (IsEqualGUID(m_targetClass, CLSID_##cls)) \
156 unknown = static_cast<I##cls*>(releaseRefFromCreateInstance(cls::createInstance())); \
160 // These #defines are needed to appease the INITIALIZE_IF_CLASS macro.
161 // There is no ICFDictionaryPropertyBag, we use IPropertyBag instead.
162 #define ICFDictionaryPropertyBag IPropertyBag
163 // There is no IWebScrollBar, we only have IWebScrollBarPrivate.
164 #define IWebScrollBar IWebScrollBarPrivate
165 // There is no class called WebURLRequest -- WebMutableURLRequest implements it for us.
166 #define WebURLRequest WebMutableURLRequest
168 FOR_EACH_COCLASS(INITIALIZE_IF_CLASS)
169 // This is the final else case
170 return CLASS_E_CLASSNOTAVAILABLE;
172 #undef ICFDictionaryPropertyBag
175 #undef INITIALIZE_IF_CLASS
178 return E_OUTOFMEMORY;
180 HRESULT hr = unknown->QueryInterface(riid, ppvObject);
184 unknown->Release(); // both createInstance() and QueryInterface() added refs
189 HRESULT STDMETHODCALLTYPE WebKitClassFactory::LockServer(BOOL fLock)