Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

355 lines
9.9 KiB

  1. #include "priv.h"
  2. #include <iethread.h>
  3. #include "winlist.h"
  4. #include "htregmng.h"
  5. #include "resource.h"
  6. #include "inetnot.h"
  7. #include <mluisupp.h>
  8. // Inststub uses kernel string funcions and unbounded buffer functions
  9. #undef lstrcmp
  10. #undef lstrcmpi
  11. #define lstrcmp StrCmpW
  12. #define lstrcmpi StrCmpIW
  13. // need these defined before including <runonce.c> which is included by <inststub.h>
  14. BOOL g_fCleanBoot = FALSE;
  15. BOOL g_fEndSession = FALSE;
  16. #include <inststub.h>
  17. #undef lstrcmp
  18. #undef lstrcmpi
  19. #define lstrcmp Do_not_use_lstrcmp_use_StrCmp
  20. #define lstrcmpi Do_not_use_lstrcmpi_use_StrCmpI
  21. /* Old install stub API (no parameters) for compatibility for a few builds */
  22. EXTERN_C void RunInstallUninstallStubs(void)
  23. {
  24. RunInstallUninstallStubs2(NULL);
  25. }
  26. void IERevokeClassFactoryObject(void);
  27. #ifndef POSTPOSTSPLIT
  28. // This value will be initialized to 0 only when we are under IExplorer.exe
  29. UINT g_tidParking = 0;
  30. #endif
  31. #define DM_FAVORITES 0
  32. #ifdef BETA_WARNING
  33. #pragma message("buidling with time bomb enabled")
  34. void DoTimebomb(HWND hwnd)
  35. {
  36. SYSTEMTIME st;
  37. GetSystemTime(&st);
  38. //
  39. // Revision History:
  40. // End of October, 1996
  41. // April, 1997
  42. // September, 1997 (for beta-1)
  43. // November 15th, 1997 (for beta-2)
  44. //
  45. if (st.wYear > 1997 || (st.wYear==1997 && st.wMonth > 11) ||
  46. (st.wYear==1997 && st.wMonth == 11 && st.wDay > 15))
  47. {
  48. TCHAR szTitle[128];
  49. TCHAR szBeta[512];
  50. MLLoadShellLangString(IDS_CABINET, szTitle, ARRAYSIZE(szTitle));
  51. MLLoadShellLangString(IDS_BETAEXPIRED, szBeta, ARRAYSIZE(szBeta));
  52. MessageBox(hwnd, szBeta, szTitle, MB_OK);
  53. }
  54. }
  55. #else
  56. #define DoTimebomb(hwnd)
  57. #endif
  58. /*----------------------------------------------------------
  59. Purpose: Initialize the favorites folder if it doesn't exist.
  60. Returns: --
  61. Cond: As a side-effect, SHGetSpecialFolderPath calls Ole
  62. functions. So this function must be called after
  63. OleInitialize has been called.
  64. Note: This is only really required on win95 / NT4 in
  65. browser only mode. The shell32.dll that ships
  66. with IE4 can handle CSIDL_FAVORITES with fCreate=TRUE.
  67. */
  68. void InitFavoritesDir()
  69. {
  70. TCHAR szPath[MAX_PATH];
  71. if (!SHGetSpecialFolderPath(NULL, szPath, CSIDL_FAVORITES, TRUE))
  72. {
  73. TCHAR szFavorites[80];
  74. TraceMsg(DM_FAVORITES, "InitFavoritesDir -- no favorites");
  75. // if this failed, that means we need to create it ourselves
  76. GetWindowsDirectory(szPath, ARRAYSIZE(szPath));
  77. MLLoadString(IDS_FAVORITES, szFavorites, ARRAYSIZE(szFavorites));
  78. PathCombine(szPath, szPath, szFavorites);
  79. SHCreateDirectory(NULL, szPath);
  80. HKEY hkExplorer;
  81. if (RegCreateKey(HKEY_CURRENT_USER, REGSTR_PATH_EXPLORER, &hkExplorer) == ERROR_SUCCESS)
  82. {
  83. HKEY hkUSF;
  84. if (RegCreateKey(hkExplorer, TEXT("User Shell Folders"), &hkUSF) == ERROR_SUCCESS)
  85. {
  86. BOOL f;
  87. TraceMsg(DM_FAVORITES, "InitFavoritesDir -- created in %s", szPath);
  88. RegSetValueEx(hkUSF, TEXT("Favorites"), 0, REG_SZ, (LPBYTE)szPath, (1 + lstrlen(szPath)) * SIZEOF(TCHAR));
  89. f = SHGetSpecialFolderPath(NULL, szPath, CSIDL_FAVORITES, TRUE);
  90. TraceMsg(DM_FAVORITES, "InitFavoritesDir -- cached at %d %s", f, szPath);
  91. ASSERT(f);
  92. RegCloseKey(hkUSF);
  93. }
  94. RegCloseKey(hkExplorer);
  95. }
  96. }
  97. }
  98. #ifdef ENABLE_CHANNELS
  99. //
  100. // Copy ChanBarSetAutoLaunchRegValue from browseui.
  101. //
  102. //extern void ChanBarSetAutoLaunchRegValue(BOOL fAutoLaunch);
  103. void ChanBarSetAutoLaunchRegValue(BOOL fAutoLaunch)
  104. {
  105. SHRegSetUSValue(TEXT("Software\\Microsoft\\Internet Explorer\\Main"),
  106. TEXT("Show_ChannelBand"), REG_SZ,
  107. fAutoLaunch ? TEXT("yes") : TEXT("no"),
  108. sizeof(fAutoLaunch ? TEXT("yes") : TEXT("no")),
  109. SHREGSET_HKCU | SHREGSET_FORCE_HKCU);
  110. }
  111. #endif // ENABLE_CHANNELS
  112. STDAPI SHCreateSplashScreen(ISplashScreen ** pSplash);
  113. typedef BOOL (*PFNISDEBUGGERPRESENT)(void);
  114. void CUrlHistory_CleanUp();
  115. //
  116. // Mean Time To Failure check routines
  117. //
  118. void _TweakCurrentDirectory()
  119. {
  120. TCHAR szPath[MAX_PATH];
  121. if (SHGetSpecialFolderPath(NULL, szPath, CSIDL_DESKTOPDIRECTORY, FALSE))
  122. SetCurrentDirectory(szPath);
  123. }
  124. BOOL _IsDebuggerPresent()
  125. {
  126. static BOOL bDebugger = -1;
  127. if (bDebugger == -1)
  128. {
  129. bDebugger = FALSE;
  130. // See if a debugger is present and bail on splash screen
  131. // so we don't get in the way of people... This api is only
  132. // present on NT...
  133. if (g_fRunningOnNT)
  134. {
  135. PFNISDEBUGGERPRESENT pfndebugger = (PFNISDEBUGGERPRESENT)GetProcAddress(GetModuleHandle(TEXT("KERNEL32")), "IsDebuggerPresent");
  136. if (pfndebugger)
  137. bDebugger = pfndebugger();
  138. }
  139. }
  140. return bDebugger;
  141. }
  142. PCWSTR IEGetArgs(PCWSTR pszCmd)
  143. {
  144. if (*pszCmd == TEXT('\"'))
  145. {
  146. // just strip the first quoted string
  147. while (*++pszCmd)
  148. {
  149. if (*pszCmd == L'\"')
  150. {
  151. pszCmd++;
  152. break;
  153. }
  154. }
  155. }
  156. else
  157. {
  158. while (*pszCmd > TEXT(' '))
  159. pszCmd++;
  160. }
  161. // strip the leading spaces
  162. while (*pszCmd && *pszCmd <= L' ')
  163. pszCmd++;
  164. return pszCmd;
  165. }
  166. PCWSTR EatIExploreArgs(PCWSTR pszArgs)
  167. {
  168. // this switches match the switches that are conumed/checked
  169. // in iexplore\mainloop.cpp. most params are in SHParseIECommandLine
  170. // but these few apply only to IExplore.exe
  171. static const PCWSTR s_pszEatArgs[] =
  172. {
  173. L"-eval",
  174. L"-new",
  175. L"-nowait"
  176. };
  177. pszArgs = IEGetArgs(pszArgs);
  178. for (int i = 0; i < ARRAYSIZE(s_pszEatArgs); i++)
  179. {
  180. int cch = lstrlenW(s_pszEatArgs[i]);
  181. if (0 == StrCmpNIW(s_pszEatArgs[i], pszArgs, cch))
  182. {
  183. if (!pszArgs[cch] || pszArgs[cch] == L' ')
  184. pszArgs += cch;
  185. // strip the spaces
  186. while (pszArgs[0] == L' ')
  187. pszArgs++;
  188. // start over, we need to go through this list until we get them all
  189. i = -1;
  190. }
  191. }
  192. return pszArgs;
  193. }
  194. BOOL g_fBrowserOnlyProcess = FALSE;
  195. // this entry is used by IEXPLORE.EXE to run the browser in a separate process. this is the
  196. // standard setting, but browsers (IE) can also be run in the same process if BrowseInSeparateProcess
  197. // is turned off (for better perf, worse stability)
  198. STDAPI_(int) IEWinMain(LPSTR pszCmdLine, int nCmdShow)
  199. {
  200. // this flag indicates that this
  201. // browser is running in its own process
  202. // and is not integrated with the shell
  203. // even if it is running on an intgrated shell
  204. g_fBrowserOnlyProcess = TRUE;
  205. _TweakCurrentDirectory();
  206. if (g_dwProfileCAP & 0x00000001)
  207. StartCAP();
  208. #ifdef FULL_DEBUG
  209. // Turn off GDI batching so that paints are performed immediately
  210. GdiSetBatchLimit(1);
  211. #endif
  212. ASSERT(g_tidParking == 0);
  213. g_tidParking = GetCurrentThreadId();
  214. ISplashScreen *pSplash = NULL;
  215. // Show splash screen, be simple for beta 1...
  216. if (!_IsDebuggerPresent())
  217. {
  218. if (SUCCEEDED(SHCreateSplashScreen(&pSplash)))
  219. {
  220. HWND hSplash;
  221. pSplash->Show( HINST_THISDLL, -1, -1, &hSplash );
  222. }
  223. }
  224. if (SUCCEEDED(OleInitialize(NULL)))
  225. {
  226. BOOL fWeOwnWinList = WinList_Init();
  227. IETHREADPARAM* piei = SHCreateIETHREADPARAM(NULL, nCmdShow, NULL, NULL);
  228. if (piei)
  229. {
  230. //
  231. // Create favorites dir (by hand if necessary).
  232. //
  233. InitFavoritesDir();
  234. //
  235. // If we are opening IE with no parameter, check if this is
  236. // the very first open.
  237. //
  238. piei->pSplash = pSplash;
  239. if (pszCmdLine && pszCmdLine[0])
  240. {
  241. USES_CONVERSION;
  242. // we are passed the an ANSI cmd line from IExplore.exe
  243. // this is lame on NT when we can have UNICODE file names.
  244. // on win9x, of course, GetCommandLineW() will return NULL
  245. // so we use the one passed to use from IExplore.exe
  246. LPCWSTR pwszCmdLine;
  247. if (IsOS(OS_NT))
  248. pwszCmdLine = EatIExploreArgs(GetCommandLineW());
  249. else
  250. pwszCmdLine = A2W(pszCmdLine);
  251. SHParseIECommandLine(&pwszCmdLine, piei);
  252. // If the "-channelband" option is selected, turn it ON by default
  253. #ifdef ENABLE_CHANNELS
  254. if (piei->fDesktopChannel)
  255. ChanBarSetAutoLaunchRegValue(TRUE);
  256. #endif // ENABLE_CHANNELS
  257. piei->pszCmdLine = StrDupW(pwszCmdLine);
  258. }
  259. else
  260. {
  261. piei->fCheckFirstOpen = TRUE;
  262. }
  263. DoTimebomb(NULL);
  264. piei->uFlags |= (COF_CREATENEWWINDOW | COF_NOFINDWINDOW | COF_INPROC | COF_IEXPLORE);
  265. SHOpenFolderWindow(piei);
  266. }
  267. IERevokeClassFactoryObject();
  268. CUrlHistory_CleanUp();
  269. if (fWeOwnWinList)
  270. WinList_Terminate();
  271. CWinInetNotify::GlobalDisable();
  272. InternetSetOption(NULL, INTERNET_OPTION_DIGEST_AUTH_UNLOAD, NULL, 0);
  273. OleUninitialize();
  274. }
  275. ATOMICRELEASE(g_psfInternet);
  276. #ifdef DEBUG
  277. CoFreeUnusedLibraries();
  278. #endif
  279. TraceMsg(TF_SHDTHREAD, "IEWinMain about to call ExitProcess");
  280. if (g_dwProfileCAP & 0x00020000)
  281. StopCAP();
  282. ExitProcess(0);
  283. return TRUE;
  284. }