Source code of Windows XP (NT5)
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.

297 lines
9.4 KiB

  1. #include "stdafx.h"
  2. #pragma hdrstop
  3. #include <mshtml.h>
  4. // let the shell dispatch objects know where to get their type lib
  5. // (this stuff lives here for no better reason than it must be in some cpp file)
  6. EXTERN_C GUID g_guidLibSdspatch = LIBID_Shell32;
  7. EXTERN_C USHORT g_wMajorVerSdspatch = 1;
  8. EXTERN_C USHORT g_wMinorVerSdspatch = 0;
  9. // This isn't a typical delay load since it's called only if wininet
  10. // is already loaded in memory. Otherwise the call is dropped on the floor.
  11. // Defview did it this way I assume to keep WININET out of first boot time.
  12. BOOL MyInternetSetOption(HANDLE h, DWORD dw1, LPVOID lpv, DWORD dw2)
  13. {
  14. BOOL bRet = FALSE;
  15. HMODULE hmod = GetModuleHandle(TEXT("wininet.dll"));
  16. if (hmod)
  17. {
  18. typedef BOOL (*PFNINTERNETSETOPTIONA)(HANDLE h, DWORD dw1, LPVOID lpv, DWORD dw2);
  19. PFNINTERNETSETOPTIONA fp = (PFNINTERNETSETOPTIONA)GetProcAddress(hmod, "InternetSetOptionA");
  20. if (fp)
  21. {
  22. bRet = fp(h, dw1, lpv, dw2);
  23. }
  24. }
  25. return bRet;
  26. }
  27. // REVIEW: maybe just check (hwnd == GetShellWindow())
  28. STDAPI_(BOOL) IsDesktopWindow(HWND hwnd)
  29. {
  30. TCHAR szName[80];
  31. GetClassName(hwnd, szName, ARRAYSIZE(szName));
  32. if (!lstrcmp(szName, TEXT(STR_DESKTOPCLASS)))
  33. {
  34. return hwnd == GetShellWindow();
  35. }
  36. return FALSE;
  37. }
  38. // returns:
  39. // S_OK returned if the .htt (web view template) file associated with the folder we're viewing is trusted
  40. // S_FALSE or
  41. // E_ACCESSDENIED bad... don't expose local machine access
  42. STDAPI IsSafePage(IUnknown *punkSite)
  43. {
  44. // Return S_FALSE if we don't have a host site since we have no way of doing a
  45. // security check. This is as far as VB 5.0 apps get.
  46. if (!punkSite)
  47. return S_FALSE;
  48. HRESULT hr = E_ACCESSDENIED;
  49. WCHAR wszPath[MAX_PATH];
  50. wszPath[0] = 0;
  51. // There are two safe cases:
  52. // 1) we are contained by a signed MD5 hashed defview template.
  53. // 2) we are contained by a .html file that's on the Local Zone
  54. //
  55. // Case 1) find the template path from webview...
  56. VARIANT vPath = {0};
  57. hr = IUnknown_QueryServiceExec(punkSite, SID_DefView, &CGID_DefView, DVCMDID_GETTEMPLATEDIRNAME, 0, NULL, &vPath);
  58. if (SUCCEEDED(hr))
  59. {
  60. if (vPath.vt == VT_BSTR && vPath.bstrVal)
  61. {
  62. DWORD cchPath = ARRAYSIZE(wszPath);
  63. if (S_OK != PathCreateFromUrlW(vPath.bstrVal, wszPath, &cchPath, 0))
  64. {
  65. // it might not be an URL, in this case it is a file path
  66. StrCpyNW(wszPath, vPath.bstrVal, ARRAYSIZE(wszPath));
  67. }
  68. // it might not be an URL, in this case it is a file path
  69. // allow intranet if this is hosted under defview
  70. hr = SHRegisterValidateTemplate(wszPath, SHRVT_VALIDATE | SHRVT_ALLOW_INTRANET | SHRVT_PROMPTUSER | SHRVT_REGISTERIFPROMPTOK);
  71. }
  72. VariantClear(&vPath);
  73. }
  74. else
  75. {
  76. IUnknown* punkToFree = NULL;
  77. // ask the browser, for example we are in a .HTM doc
  78. BOOL fFound = FALSE;
  79. do
  80. {
  81. IBrowserService* pbs;
  82. hr = IUnknown_QueryService(punkSite, SID_SShellBrowser, IID_PPV_ARG(IBrowserService, &pbs));
  83. if (SUCCEEDED(hr))
  84. {
  85. LPITEMIDLIST pidl;
  86. hr = pbs->GetPidl(&pidl);
  87. if (SUCCEEDED(hr))
  88. {
  89. DWORD dwAttribs = SFGAO_FOLDER;
  90. hr = SHGetNameAndFlagsW(pidl, SHGDN_FORPARSING, wszPath, ARRAYSIZE(wszPath), &dwAttribs);
  91. if (dwAttribs & SFGAO_FOLDER)
  92. {
  93. // A folder is not a .HTM file, so continue on up...
  94. wszPath[0] = 0;
  95. ATOMICRELEASE(punkToFree);
  96. hr = IUnknown_GetSite(pbs, IID_PPV_ARG(IUnknown, &punkToFree)); // gotta start with pbs's parent (otherwise you'll get the same pbs again)
  97. if (FAILED(hr)) // to get by the weboc you need to explicitly ask for the oc's parent:
  98. {
  99. hr = IUnknown_QueryService(pbs, SID_QIClientSite, IID_PPV_ARG(IUnknown, &punkToFree));
  100. }
  101. punkSite = punkToFree;
  102. }
  103. else
  104. {
  105. // Found the nearest containing non-folder object.
  106. fFound = TRUE;
  107. hr = LocalZoneCheckPath(wszPath, punkSite); // check for local zone
  108. }
  109. ILFree(pidl);
  110. }
  111. pbs->Release();
  112. }
  113. } while (SUCCEEDED(hr) && !fFound);
  114. ATOMICRELEASE(punkToFree);
  115. }
  116. if (S_OK != hr)
  117. {
  118. hr = E_ACCESSDENIED;
  119. }
  120. return hr;
  121. }
  122. HRESULT HrSHGetValue(IN HKEY hKey, IN LPCTSTR pszSubKey, OPTIONAL IN LPCTSTR pszValue, OPTIONAL OUT LPDWORD pdwType,
  123. OPTIONAL OUT LPVOID pvData, OPTIONAL OUT LPDWORD pcbData)
  124. {
  125. DWORD dwError = SHGetValue(hKey, pszSubKey, pszValue, pdwType, pvData, pcbData);
  126. return HRESULT_FROM_WIN32(dwError);
  127. }
  128. STDAPI SHPropertyBag_WritePunk(IN IPropertyBag * pPropertyPage, IN LPCWSTR pwzPropName, IN IUnknown * punk)
  129. {
  130. HRESULT hr = E_INVALIDARG;
  131. if (pPropertyPage && pwzPropName)
  132. {
  133. VARIANT va;
  134. va.vt = VT_UNKNOWN;
  135. va.punkVal = punk;
  136. hr = pPropertyPage->Write(pwzPropName, &va);
  137. }
  138. return hr;
  139. }
  140. BOOL _GetRegValueString(HKEY hKey, LPCTSTR pszValName, LPTSTR pszString, int cchSize)
  141. {
  142. DWORD cbSize = sizeof(pszString[0]) * cchSize;
  143. DWORD dwType;
  144. DWORD dwError = RegQueryValueEx(hKey, pszValName, NULL, &dwType, (LPBYTE)pszString, &cbSize);
  145. return (ERROR_SUCCESS == dwError);
  146. }
  147. //------------------------------------------------------------------------------------
  148. // SetRegValueString()
  149. //
  150. // Just a little helper routine that takes string and writes it to the registry.
  151. // Returns: success writing to Registry, should be always TRUE.
  152. //------------------------------------------------------------------------------------
  153. BOOL SetRegValueString(HKEY hMainKey, LPCTSTR pszSubKey, LPCTSTR pszRegValue, LPCTSTR pszString)
  154. {
  155. HKEY hKey;
  156. DWORD dwDisposition;
  157. BOOL fSucceeded = FALSE;
  158. DWORD dwError = RegCreateKeyEx(hMainKey, pszSubKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &hKey, &dwDisposition);
  159. if (ERROR_SUCCESS == dwError)
  160. {
  161. dwError = SHRegSetPath(hKey, NULL, pszRegValue, pszString, 0);
  162. if (ERROR_SUCCESS == dwError)
  163. {
  164. fSucceeded = TRUE;
  165. }
  166. RegCloseKey(hKey);
  167. }
  168. return fSucceeded;
  169. }
  170. //------------------------------------------------------------------------------------
  171. //
  172. // SetRegValueInt()
  173. //
  174. // Just a little helper routine that takes an int and writes it as a string to the
  175. // registry.
  176. //
  177. // Returns: success writing to Registry, should be always TRUE.
  178. //
  179. //------------------------------------------------------------------------------------
  180. BOOL SetRegValueInt( HKEY hMainKey, LPCTSTR lpszSubKey, LPCTSTR lpszValName, int iValue )
  181. {
  182. TCHAR szValue[16];
  183. wnsprintf(szValue, ARRAYSIZE(szValue), TEXT("%d"), iValue);
  184. return SetRegValueString( hMainKey, lpszSubKey, lpszValName, szValue );
  185. }
  186. //------------------------------------------------------------------------------------
  187. //
  188. // IconSet/GetRegValueString()
  189. //
  190. // Versions of Get/SetRegValueString that go to the user classes section.
  191. //
  192. // Returns: success of string setting / retrieval
  193. //
  194. //------------------------------------------------------------------------------------
  195. BOOL IconSetRegValueString(const CLSID* pclsid, LPCTSTR lpszSubKey, LPCTSTR lpszValName, LPCTSTR lpszValue)
  196. {
  197. HKEY hkey;
  198. if (SUCCEEDED(SHRegGetCLSIDKey(*pclsid, lpszSubKey, TRUE, TRUE, &hkey)))
  199. {
  200. DWORD dwRet = SHRegSetPath(hkey, NULL, lpszValName, lpszValue, 0);
  201. RegCloseKey(hkey);
  202. return (dwRet == ERROR_SUCCESS);
  203. }
  204. return FALSE;
  205. }
  206. BOOL IconGetRegValueString(const CLSID* pclsid, LPCTSTR lpszSubKey, LPCTSTR lpszValName, LPTSTR lpszValue, int cchValue)
  207. {
  208. HKEY hkey;
  209. if (SUCCEEDED(SHRegGetCLSIDKey(*pclsid, lpszSubKey, TRUE, FALSE, &hkey)) ||
  210. SUCCEEDED(SHRegGetCLSIDKey(*pclsid, lpszSubKey, FALSE, FALSE, &hkey)))
  211. {
  212. BOOL fRet = _GetRegValueString(hkey, lpszValName, lpszValue, cchValue);
  213. RegCloseKey(hkey);
  214. return fRet;
  215. }
  216. return FALSE;
  217. }
  218. BOOL CALLBACK Cabinet_RefreshEnum(HWND hwnd, LPARAM lParam)
  219. {
  220. if (IsFolderWindow(hwnd) || IsExplorerWindow(hwnd))
  221. {
  222. PostMessage(hwnd, WM_COMMAND, FCIDM_REFRESH, lParam);
  223. }
  224. return(TRUE);
  225. }
  226. BOOL CALLBACK Cabinet_UpdateWebViewEnum(HWND hwnd, LPARAM lParam)
  227. {
  228. if (IsFolderWindow(hwnd) || IsExplorerWindow(hwnd))
  229. {
  230. // A value of -1L for lParam will force a refresh by loading the View window
  231. // with the new VID as specified in the global DefFolderSettings.
  232. PostMessage(hwnd, WM_COMMAND, SFVIDM_MISC_SETWEBVIEW, lParam);
  233. }
  234. return(TRUE);
  235. }
  236. void Cabinet_RefreshAll(WNDENUMPROC lpEnumFunc, LPARAM lParam)
  237. {
  238. HWND hwnd = FindWindowEx(NULL, NULL, TEXT(STR_DESKTOPCLASS), NULL);
  239. if (hwnd)
  240. PostMessage(hwnd, WM_COMMAND, FCIDM_REFRESH, 0L);
  241. hwnd = FindWindowEx(NULL, NULL, TEXT("Shell_TrayWnd"), NULL);
  242. if (hwnd)
  243. PostMessage(hwnd, TM_REFRESH, 0, 0L);
  244. EnumWindows(lpEnumFunc, lParam);
  245. }