1 /* 2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 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. 12 * 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. 24 */ 25 26 #include "config.h" 27 #include "WebKitDLL.h" 28 29 #include "ForEachCoClass.h" 30 #include "resource.h" 31 #include "WebKit.h" 32 #include "WebKitClassFactory.h" 33 #include <WebCore/COMPtr.h> 34 #include <WebCore/IconDatabase.h> 35 #include <WebCore/Page.h> 36 #include <WebCore/PageGroup.h> 37 #include <WebCore/RenderThemeWin.h> 38 #include <WebCore/SharedBuffer.h> 39 #include <WebCore/Widget.h> 40 #include <wtf/Vector.h> 41 #include <tchar.h> 42 #include <olectl.h> 43 44 using namespace WebCore; 45 46 ULONG gLockCount; 47 ULONG gClassCount; 48 HashCountedSet<String> gClassNameCount; 49 HINSTANCE gInstance; 50 51 #define CLSID_FOR_CLASS(cls) CLSID_##cls, 52 CLSID gRegCLSIDs[] = { 53 FOR_EACH_COCLASS(CLSID_FOR_CLASS) 54 }; 55 #undef CLSID_FOR_CLASS 56 57 STDAPI_(BOOL) DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID /*lpReserved*/) 58 { 59 switch (ul_reason_for_call) { 60 case DLL_PROCESS_ATTACH: 61 gLockCount = gClassCount = 0; 62 gInstance = hModule; 63 WebCore::Page::setInstanceHandle(hModule); 64 return TRUE; 65 66 case DLL_PROCESS_DETACH: 67 WebCore::RenderThemeWin::setWebKitIsBeingUnloaded(); 68 break; 69 70 case DLL_THREAD_ATTACH: 71 case DLL_THREAD_DETACH: 72 break; 73 } 74 return FALSE; 75 } 76 77 STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv) 78 { 79 bool found = false; 80 for (int i = 0; i < ARRAYSIZE(gRegCLSIDs); i++) { 81 if (IsEqualGUID(rclsid, gRegCLSIDs[i])) { 82 found = true; 83 break; 84 } 85 } 86 if (!found) 87 return E_FAIL; 88 89 if (!IsEqualGUID(riid, IID_IUnknown) && !IsEqualGUID(riid, IID_IClassFactory)) 90 return E_NOINTERFACE; 91 92 WebKitClassFactory* factory = new WebKitClassFactory(rclsid); 93 *ppv = reinterpret_cast<LPVOID>(factory); 94 if (!factory) 95 return E_OUTOFMEMORY; 96 97 factory->AddRef(); 98 return S_OK; 99 } 100 101 STDAPI DllCanUnloadNow(void) 102 { 103 if (!gClassCount && !gLockCount) 104 return S_OK; 105 106 return S_FALSE; 107 } 108 109 // deprecated - do not use 110 STDAPI DllUnregisterServer(void) 111 { 112 return 0; 113 } 114 115 // deprecated - do not use 116 STDAPI DllRegisterServer(void) 117 { 118 return 0; 119 } 120 121 // deprecated - do not use 122 STDAPI RunAsLocalServer() 123 { 124 return 0; 125 } 126 127 // deprecated - do not use 128 STDAPI LocalServerDidDie() 129 { 130 return 0; 131 } 132 133 void shutDownWebKit() 134 { 135 WebCore::iconDatabase()->close(); 136 WebCore::PageGroup::closeLocalStorage(); 137 } 138 139 //FIXME: We should consider moving this to a new file for cross-project functionality 140 PassRefPtr<WebCore::SharedBuffer> loadResourceIntoBuffer(const char* name) 141 { 142 int idr; 143 // temporary hack to get resource id 144 if (!strcmp(name, "textAreaResizeCorner")) 145 idr = IDR_RESIZE_CORNER; 146 else if (!strcmp(name, "missingImage")) 147 idr = IDR_MISSING_IMAGE; 148 else if (!strcmp(name, "nullPlugin")) 149 idr = IDR_NULL_PLUGIN; 150 else if (!strcmp(name, "panIcon")) 151 idr = IDR_PAN_SCROLL_ICON; 152 else if (!strcmp(name, "panSouthCursor")) 153 idr = IDR_PAN_SOUTH_CURSOR; 154 else if (!strcmp(name, "panNorthCursor")) 155 idr = IDR_PAN_NORTH_CURSOR; 156 else if (!strcmp(name, "panEastCursor")) 157 idr = IDR_PAN_EAST_CURSOR; 158 else if (!strcmp(name, "panWestCursor")) 159 idr = IDR_PAN_WEST_CURSOR; 160 else if (!strcmp(name, "panSouthEastCursor")) 161 idr = IDR_PAN_SOUTH_EAST_CURSOR; 162 else if (!strcmp(name, "panSouthWestCursor")) 163 idr = IDR_PAN_SOUTH_WEST_CURSOR; 164 else if (!strcmp(name, "panNorthEastCursor")) 165 idr = IDR_PAN_NORTH_EAST_CURSOR; 166 else if (!strcmp(name, "panNorthWestCursor")) 167 idr = IDR_PAN_NORTH_WEST_CURSOR; 168 else if (!strcmp(name, "searchMagnifier")) 169 idr = IDR_SEARCH_MAGNIFIER; 170 else if (!strcmp(name, "searchMagnifierResults")) 171 idr = IDR_SEARCH_MAGNIFIER_RESULTS; 172 else if (!strcmp(name, "searchCancel")) 173 idr = IDR_SEARCH_CANCEL; 174 else if (!strcmp(name, "searchCancelPressed")) 175 idr = IDR_SEARCH_CANCEL_PRESSED; 176 else if (!strcmp(name, "zoomInCursor")) 177 idr = IDR_ZOOM_IN_CURSOR; 178 else if (!strcmp(name, "zoomOutCursor")) 179 idr = IDR_ZOOM_OUT_CURSOR; 180 else if (!strcmp(name, "verticalTextCursor")) 181 idr = IDR_VERTICAL_TEXT_CURSOR; 182 else if (!strcmp(name, "fsVideoAudioVolumeHigh")) 183 idr = IDR_FS_VIDEO_AUDIO_VOLUME_HIGH; 184 else if (!strcmp(name, "fsVideoAudioVolumeLow")) 185 idr = IDR_FS_VIDEO_AUDIO_VOLUME_LOW; 186 else if (!strcmp(name, "fsVideoExitFullscreen")) 187 idr = IDR_FS_VIDEO_EXIT_FULLSCREEN; 188 else if (!strcmp(name, "fsVideoPause")) 189 idr = IDR_FS_VIDEO_PAUSE; 190 else if (!strcmp(name, "fsVideoPlay")) 191 idr = IDR_FS_VIDEO_PLAY; 192 else 193 return 0; 194 195 HRSRC resInfo = FindResource(gInstance, MAKEINTRESOURCE(idr), L"PNG"); 196 if (!resInfo) 197 return 0; 198 HANDLE res = LoadResource(gInstance, resInfo); 199 if (!res) 200 return 0; 201 void* resource = LockResource(res); 202 if (!resource) 203 return 0; 204 int size = SizeofResource(gInstance, resInfo); 205 206 return WebCore::SharedBuffer::create(reinterpret_cast<const char*>(resource), size); 207 } 208