ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

factory.c
Go to the documentation of this file.
00001 /*
00002  * Implementation of class factory for IE Web Browser
00003  *
00004  * Copyright 2001 John R. Sheets (for CodeWeavers)
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00019  */
00020 
00021 #include <string.h>
00022 #include <stdio.h>
00023 
00024 #include "shdocvw.h"
00025 #include "winreg.h"
00026 #include "advpub.h"
00027 #include "isguids.h"
00028 
00029 #include "winver.h"
00030 
00031 #include "wine/debug.h"
00032 
00033 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
00034 
00035 /**********************************************************************
00036  * Implement the WebBrowser class factory
00037  *
00038  * (Based on implementation in ddraw/main.c)
00039  */
00040 
00041 #define FACTORY(x) ((IClassFactory*) &(x)->lpClassFactoryVtbl)
00042 
00043 typedef struct
00044 {
00045     /* IUnknown fields */
00046     const IClassFactoryVtbl *lpClassFactoryVtbl;
00047     HRESULT (*cf)(LPUNKNOWN, REFIID, LPVOID *);
00048     LONG ref;
00049 } IClassFactoryImpl;
00050 
00051 
00052 /**********************************************************************
00053  * WBCF_QueryInterface (IUnknown)
00054  */
00055 static HRESULT WINAPI WBCF_QueryInterface(LPCLASSFACTORY iface,
00056                                           REFIID riid, LPVOID *ppobj)
00057 {
00058     TRACE("(%s %p)\n", debugstr_guid(riid), ppobj);
00059 
00060     if (!ppobj)
00061         return E_POINTER;
00062 
00063     if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid)) {
00064         *ppobj = iface;
00065         IClassFactory_AddRef(iface);
00066         return S_OK;
00067     }
00068 
00069     WARN("Not supported interface %s\n", debugstr_guid(riid));
00070 
00071     *ppobj = NULL;
00072     return E_NOINTERFACE;
00073 }
00074 
00075 /************************************************************************
00076  * WBCF_AddRef (IUnknown)
00077  */
00078 static ULONG WINAPI WBCF_AddRef(LPCLASSFACTORY iface)
00079 {
00080     SHDOCVW_LockModule();
00081 
00082     return 2; /* non-heap based object */
00083 }
00084 
00085 /************************************************************************
00086  * WBCF_Release (IUnknown)
00087  */
00088 static ULONG WINAPI WBCF_Release(LPCLASSFACTORY iface)
00089 {
00090     SHDOCVW_UnlockModule();
00091 
00092     return 1; /* non-heap based object */
00093 }
00094 
00095 /************************************************************************
00096  * WBCF_CreateInstance (IClassFactory)
00097  */
00098 static HRESULT WINAPI WBCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter,
00099                                           REFIID riid, LPVOID *ppobj)
00100 {
00101     IClassFactoryImpl *This = (IClassFactoryImpl *) iface;
00102     return This->cf(pOuter, riid, ppobj);
00103 }
00104 
00105 /************************************************************************
00106  * WBCF_LockServer (IClassFactory)
00107  */
00108 static HRESULT WINAPI WBCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
00109 {
00110     TRACE("(%d)\n", dolock);
00111 
00112     if (dolock)
00113         SHDOCVW_LockModule();
00114     else
00115         SHDOCVW_UnlockModule();
00116     
00117     return S_OK;
00118 }
00119 
00120 static const IClassFactoryVtbl WBCF_Vtbl =
00121 {
00122     WBCF_QueryInterface,
00123     WBCF_AddRef,
00124     WBCF_Release,
00125     WBCF_CreateInstance,
00126     WBCF_LockServer
00127 };
00128 
00129 /*************************************************************************
00130  *              DllGetClassObject (SHDOCVW.@)
00131  */
00132 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
00133 {
00134     static IClassFactoryImpl WB1ClassFactory = {&WBCF_Vtbl, WebBrowserV1_Create};
00135     static IClassFactoryImpl WB2ClassFactory = {&WBCF_Vtbl, WebBrowserV2_Create};
00136     static IClassFactoryImpl CUHClassFactory = {&WBCF_Vtbl, CUrlHistory_Create};
00137     static IClassFactoryImpl ISCClassFactory = {&WBCF_Vtbl, InternetShortcut_Create};
00138     static IClassFactoryImpl TBLClassFactory = {&WBCF_Vtbl, TaskbarList_Create};
00139 
00140     TRACE("\n");
00141 
00142     if(IsEqualGUID(&CLSID_WebBrowser, rclsid))
00143         return IClassFactory_QueryInterface(FACTORY(&WB2ClassFactory), riid, ppv);
00144 
00145     if(IsEqualGUID(&CLSID_WebBrowser_V1, rclsid))
00146         return IClassFactory_QueryInterface(FACTORY(&WB1ClassFactory), riid, ppv);
00147 
00148     if(IsEqualGUID(&CLSID_CUrlHistory, rclsid))
00149         return IClassFactory_QueryInterface(FACTORY(&CUHClassFactory), riid, ppv);
00150 
00151     if(IsEqualGUID(&CLSID_InternetShortcut, rclsid))
00152         return IClassFactory_QueryInterface(FACTORY(&ISCClassFactory), riid, ppv);
00153 
00154     if(IsEqualGUID(&CLSID_TaskbarList, rclsid))
00155         return IClassFactory_QueryInterface(FACTORY(&TBLClassFactory), riid, ppv);
00156 
00157     /* As a last resort, figure if the CLSID belongs to a 'Shell Instance Object' */
00158     return SHDOCVW_GetShellInstanceObjectClassObject(rclsid, riid, ppv);
00159 }
00160 
00161 HRESULT register_class_object(BOOL do_reg)
00162 {
00163     HRESULT hres;
00164 
00165     static DWORD cookie;
00166     static IClassFactoryImpl IEClassFactory = {&WBCF_Vtbl, InternetExplorer_Create};
00167 
00168     if(do_reg) {
00169         hres = CoRegisterClassObject(&CLSID_InternetExplorer, (IUnknown*)FACTORY(&IEClassFactory),
00170                                      CLSCTX_SERVER, REGCLS_MULTIPLEUSE|REGCLS_SUSPENDED, &cookie);
00171         if (FAILED(hres)) {
00172             ERR("failed to register object %08x\n", hres);
00173             return hres;
00174         }
00175 
00176         hres = CoResumeClassObjects();
00177         if(SUCCEEDED(hres))
00178             return hres;
00179 
00180         ERR("failed to resume object %08x\n", hres);
00181     }
00182 
00183     return CoRevokeClassObject(cookie);
00184 }
00185 
00186 static HRESULT reg_install(LPCSTR section, STRTABLEA *strtable)
00187 {
00188     HRESULT (WINAPI *pRegInstall)(HMODULE hm, LPCSTR pszSection, const STRTABLEA* pstTable);
00189     HMODULE hadvpack;
00190     HRESULT hres;
00191 
00192     static const WCHAR advpackW[] = {'a','d','v','p','a','c','k','.','d','l','l',0};
00193 
00194     hadvpack = LoadLibraryW(advpackW);
00195     pRegInstall = (void *)GetProcAddress(hadvpack, "RegInstall");
00196 
00197     hres = pRegInstall(shdocvw_hinstance, section, strtable);
00198 
00199     FreeLibrary(hadvpack);
00200     return hres;
00201 }
00202 
00203 static const GUID CLSID_MicrosoftBrowserArchitecture =
00204     {0xa5e46e3a, 0x8849, 0x11d1, {0x9d, 0x8c, 0x00, 0xc0, 0x4f, 0xc9, 0x9d, 0x61}};
00205 static const GUID CLSID_MruLongList =
00206     {0x53bd6b4e, 0x3780, 0x4693, {0xaf, 0xc3, 0x71, 0x61, 0xc2, 0xf3, 0xee, 0x9c}};
00207 
00208 #define INF_SET_CLSID(clsid)                  \
00209     do                                        \
00210     {                                         \
00211         static CHAR name[] = "CLSID_" #clsid; \
00212                                               \
00213         pse[i].pszName = name;                \
00214         clsids[i++] = &CLSID_ ## clsid;       \
00215     } while (0)
00216 
00217 static HRESULT register_server(BOOL doregister)
00218 {
00219     STRTABLEA strtable;
00220     STRENTRYA pse[15];
00221     static CLSID const *clsids[15];
00222     unsigned int i = 0;
00223     HRESULT hres;
00224 
00225     INF_SET_CLSID(CUrlHistory);
00226     INF_SET_CLSID(Internet);
00227     INF_SET_CLSID(InternetExplorer);
00228     INF_SET_CLSID(InternetShortcut);
00229     INF_SET_CLSID(MicrosoftBrowserArchitecture);
00230     INF_SET_CLSID(MruLongList);
00231     INF_SET_CLSID(SearchAssistantOC);
00232     INF_SET_CLSID(ShellNameSpace);
00233     INF_SET_CLSID(ShellSearchAssistantOC);
00234     INF_SET_CLSID(ShellShellNameSpace);
00235     INF_SET_CLSID(ShellUIHelper);
00236     INF_SET_CLSID(ShellWindows);
00237     INF_SET_CLSID(TaskbarList);
00238     INF_SET_CLSID(WebBrowser);
00239     INF_SET_CLSID(WebBrowser_V1);
00240 
00241     for(i = 0; i < sizeof(pse)/sizeof(pse[0]); i++) {
00242         pse[i].pszValue = HeapAlloc(GetProcessHeap(), 0, 39);
00243         sprintf(pse[i].pszValue, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
00244                 clsids[i]->Data1, clsids[i]->Data2, clsids[i]->Data3, clsids[i]->Data4[0],
00245                 clsids[i]->Data4[1], clsids[i]->Data4[2], clsids[i]->Data4[3], clsids[i]->Data4[4],
00246                 clsids[i]->Data4[5], clsids[i]->Data4[6], clsids[i]->Data4[7]);
00247     }
00248 
00249     strtable.cEntries = sizeof(pse)/sizeof(pse[0]);
00250     strtable.pse = pse;
00251 
00252     hres = reg_install(doregister ? "RegisterDll" : "UnregisterDll", &strtable);
00253 
00254     for(i=0; i < sizeof(pse)/sizeof(pse[0]); i++)
00255         HeapFree(GetProcessHeap(), 0, pse[i].pszValue);
00256 
00257     return hres;
00258 }
00259 
00260 #undef INF_SET_CLSID
00261 
00262 /***********************************************************************
00263  *          DllRegisterServer (shdocvw.@)
00264  */
00265 HRESULT WINAPI DllRegisterServer(void)
00266 {
00267     ITypeLib *typelib;
00268     HRESULT hres;
00269 
00270     static const WCHAR shdocvwW[] = {'s','h','d','o','c','v','w','.','d','l','l',0};
00271 
00272     hres = register_server(TRUE);
00273     if(FAILED(hres))
00274         return hres;
00275 
00276     hres = LoadTypeLibEx(shdocvwW, REGKIND_REGISTER, &typelib);
00277     if(FAILED(hres)) {
00278         ERR("Could not load typelib: %08x\n", hres);
00279         return hres;
00280     }
00281 
00282     ITypeLib_Release(typelib);
00283 
00284     return hres;
00285 }
00286 
00287 /***********************************************************************
00288  *          DllUnregisterServer (shdocvw.@)
00289  */
00290 HRESULT WINAPI DllUnregisterServer(void)
00291 {
00292     HRESULT hres;
00293 
00294     hres = register_server(FALSE);
00295     if(FAILED(hres))
00296         return hres;
00297 
00298     return UnRegisterTypeLib(&LIBID_SHDocVw, 1, 1, LOCALE_SYSTEM_DEFAULT, SYS_WIN32);
00299 }
00300 
00301 static BOOL check_native_ie(void)
00302 {
00303     static const WCHAR cszPath[] = {'b','r','o','w','s','e','u','i','.','d','l','l',0};
00304     DWORD handle,size;
00305     BOOL ret = TRUE;
00306 
00307     size = GetFileVersionInfoSizeW(cszPath,&handle);
00308     if (size)
00309     {
00310         LPVOID buf;
00311         LPWSTR lpFileDescription;
00312         UINT dwBytes;
00313         static const WCHAR cszFD[] = {'\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o','\\','0','4','0','9','0','4','e','4','\\','F','i','l','e','D','e','s','c','r','i','p','t','i','o','n',0};
00314         static const WCHAR cszWine[] = {'W','i','n','e',0};
00315 
00316         buf = HeapAlloc(GetProcessHeap(),0,size);
00317         GetFileVersionInfoW(cszPath,0,size,buf);
00318 
00319         if (VerQueryValueW(buf, cszFD, (LPVOID*)&lpFileDescription, &dwBytes) &&
00320             strstrW(lpFileDescription,cszWine))
00321                 ret = FALSE;
00322 
00323         HeapFree(GetProcessHeap(), 0, buf);
00324     }
00325 
00326     return ret;
00327 }
00328 
00329 DWORD register_iexplore(BOOL doregister)
00330 {
00331     HRESULT hres;
00332     if (check_native_ie())
00333     {
00334         TRACE("Native IE detected, not doing registration\n");
00335         return S_OK;
00336     }
00337     hres = reg_install(doregister ? "RegisterIE" : "UnregisterIE", NULL);
00338     return FAILED(hres);
00339 }

Generated on Sat May 26 2012 04:20:01 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.