1
0

browserRegistry.cpp 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. #include "main.h"
  2. #include "./browserRegistry.h"
  3. #include "./obj_ombrowser.h"
  4. #include "./ifc_wasabihelper.h"
  5. #include "./ifc_skinhelper.h"
  6. #include "./ifc_skinnedbrowser.h"
  7. #include "./ifc_ombrowserclass.h"
  8. #include "./ifc_omconfig.h"
  9. #include "./ifc_omdebugconfig.h"
  10. #include "../Plugins/General/gen_ml/colors.h"
  11. #include <shlwapi.h>
  12. #include <strsafe.h>
  13. #define YES L"yes"
  14. #define NO L"no"
  15. #define REGVAL_DWORD(__regKey, __valueName, __data) { DWORD __iVal = (__data); RegSetValueExW((__regKey), (__valueName), NULL, REG_DWORD, (LPCBYTE)&__iVal, sizeof(DWORD)); }
  16. #define REGVAL_STR(__regKey, __valueName, __data, __cbData) RegSetValueExW((__regKey), (__valueName), NULL, REG_SZ, (LPCBYTE)(__data), (__cbData))
  17. #define REGVAL_ONE(__regKey, __valueName) REGVAL_DWORD(__regKey, __valueName, 1)
  18. #define REGVAL_ZERO(__regKey, __valueName) REGVAL_DWORD(__regKey, __valueName, 0)
  19. #define REGVAL_YES(__regKey, __valueName) REGVAL_STR(__regKey, __valueName, YES, sizeof(YES))
  20. #define REGVAL_NO(__regKey, __valueName) REGVAL_STR(__regKey, __valueName, NO, sizeof(NO))
  21. #define REGVAL_YESNO(__regKey, __valueName, __condition) ((0 != (__condition)) ? REGVAL_YES(__regKey, __valueName) : REGVAL_NO(__regKey, __valueName))
  22. #define REGVAL_RGB(__regKey, __valueName, __rgb)\
  23. { WCHAR szRGB[64] = {0}; COLORREF c = (__rgb);\
  24. StringCchPrintfW(szRGB, ARRAYSIZE(szRGB), L"%d,%d,%d", GetRValue(c), GetGValue(c), GetBValue(c));\
  25. INT cbLen = lstrlenW(szRGB) * sizeof(WCHAR);\
  26. REGVAL_STR(__regKey, __valueName, szRGB, cbLen);}
  27. OmBrowserRegistry::OmBrowserRegistry(LPCWSTR pszName)
  28. : ref(1), name(NULL), path(NULL)
  29. {
  30. name = Plugin_CopyString(pszName);
  31. }
  32. OmBrowserRegistry::~OmBrowserRegistry()
  33. {
  34. Plugin_FreeString(name);
  35. Plugin_FreeString(path);
  36. }
  37. HRESULT OmBrowserRegistry::CreateInstance(LPCWSTR pszName, OmBrowserRegistry **instance)
  38. {
  39. if (NULL == instance) return E_POINTER;
  40. *instance = NULL;
  41. if (NULL == pszName || L'\0' == *pszName)
  42. pszName = OMBROWSER_NAME;
  43. *instance = new OmBrowserRegistry(pszName);
  44. if (NULL == *instance) return E_OUTOFMEMORY;
  45. return S_OK;
  46. }
  47. size_t OmBrowserRegistry::AddRef()
  48. {
  49. return InterlockedIncrement((LONG*)&ref);
  50. }
  51. size_t OmBrowserRegistry::Release()
  52. {
  53. if (0 == ref)
  54. return ref;
  55. LONG r = InterlockedDecrement((LONG*)&ref);
  56. if (0 == r)
  57. delete(this);
  58. return r;
  59. }
  60. int OmBrowserRegistry::QueryInterface(GUID interface_guid, void **object)
  61. {
  62. if (NULL == object) return E_POINTER;
  63. if (IsEqualIID(interface_guid, IFC_OmBrowserRegistry))
  64. *object = static_cast<ifc_ombrowserregistry*>(this);
  65. else
  66. {
  67. *object = NULL;
  68. return E_NOINTERFACE;
  69. }
  70. if (NULL == *object)
  71. return E_UNEXPECTED;
  72. AddRef();
  73. return S_OK;
  74. }
  75. HRESULT OmBrowserRegistry::Write()
  76. {
  77. HKEY hKey = NULL;
  78. HKEY hKey2 = NULL;
  79. LONG result;
  80. DWORD disposition;
  81. if (FAILED(CreateRoot(&hKey, NULL)))
  82. return E_FAIL;
  83. result = RegCreateKeyExW(hKey, L"Main", NULL, NULL, REG_OPTION_VOLATILE, KEY_SET_VALUE, NULL, &hKey2, &disposition);
  84. if (ERROR_SUCCESS == result)
  85. {
  86. REGVAL_ONE(hKey2, L"AllowWindowReuse");
  87. HRESULT hr(S_FALSE);
  88. ifc_ombrowserclass *browserClass;
  89. if (SUCCEEDED(Plugin_GetBrowserClass(name, &browserClass)))
  90. {
  91. ifc_omconfig *config;
  92. if (SUCCEEDED(browserClass->GetConfig(&config)))
  93. {
  94. ifc_omdebugconfig *debugConfig;
  95. if (SUCCEEDED(config->QueryInterface(IFC_OmDebugConfig, (void**)&debugConfig)))
  96. {
  97. hr = debugConfig->GetScriptDebuggerEnabled();
  98. debugConfig->Release();
  99. }
  100. config->Release();
  101. }
  102. browserClass->Release();
  103. }
  104. REGVAL_YESNO(hKey2, L"Disable Script Debugger", (S_FALSE == hr));
  105. REGVAL_NO(hKey2, L"Check_Associations");
  106. REGVAL_ZERO(hKey2, L"EnableSearchPane");
  107. REGVAL_NO(hKey2, L"Friendly http errors");
  108. REGVAL_NO(hKey2, L"FullScreen");
  109. REGVAL_NO(hKey2, L"Save_Session_History_On_Exit");
  110. REGVAL_NO(hKey2, L"Use_DlgBox_Colors");
  111. REGVAL_YES(hKey2, L"ShowedCheckBrowser");
  112. REGVAL_STR(hKey2, L"Start Page", L"", sizeof(L""));
  113. REGVAL_STR(hKey2, L"Default_Page_URL", L"about:blank", sizeof(L"about:blank"));
  114. REGVAL_STR(hKey2, L"Default_Search_URL", L"about:blank", sizeof(L"about:blank"));
  115. REGVAL_NO(hKey2, L"Enable Browser Extensions");
  116. REGVAL_NO(hKey2, L"Error Dlg Details Pane Open");
  117. REGVAL_NO(hKey2, L"Error Dlg Displayed On Every Error");
  118. REGVAL_ONE(hKey2, L"NoUpdateCheck");
  119. REGVAL_NO(hKey2, L"Save_Session_History_On_Exit");
  120. REGVAL_ONE(hKey2, L"NoJITSetup");
  121. REGVAL_ONE(hKey2, L"NoWebJITSetup");
  122. REGVAL_ONE(hKey2, L"RunOnceComplete");
  123. REGVAL_ONE(hKey2, L"RunOnceHasShown");
  124. REGVAL_ONE(hKey2, L"SearchMigrated");
  125. RegCloseKey(hKey2);
  126. }
  127. result = RegCreateKeyExW(hKey, L"MenuExt", NULL, NULL, REG_OPTION_VOLATILE, KEY_SET_VALUE, NULL, &hKey2, &disposition);
  128. if (ERROR_SUCCESS == result)
  129. {
  130. RegCloseKey(hKey2);
  131. }
  132. result = RegCreateKeyExW(hKey, L"New Windows", NULL, NULL, REG_OPTION_VOLATILE, KEY_SET_VALUE, NULL, &hKey2, &disposition);
  133. if (ERROR_SUCCESS == result)
  134. {
  135. REGVAL_ZERO(hKey2, L"PlaySound");
  136. REGVAL_ONE(hKey2, L"PopupMgr");
  137. RegCloseKey(hKey2);
  138. }
  139. result = RegCreateKeyExW(hKey, L"SearchScopes", NULL, NULL, REG_OPTION_VOLATILE, KEY_SET_VALUE, NULL, &hKey2, &disposition);
  140. if (ERROR_SUCCESS == result)
  141. {
  142. RegCloseKey(hKey2);
  143. }
  144. result = RegCreateKeyExW(hKey, L"SearchUrl", NULL, NULL, REG_OPTION_VOLATILE, KEY_SET_VALUE, NULL, &hKey2, &disposition);
  145. if (ERROR_SUCCESS == result)
  146. {
  147. RegCloseKey(hKey2);
  148. }
  149. result = RegCreateKeyExW(hKey, L"URLSearchHooks", NULL, NULL, REG_OPTION_VOLATILE, KEY_SET_VALUE, NULL, &hKey2, &disposition);
  150. if (ERROR_SUCCESS == result)
  151. {
  152. RegCloseKey(hKey2);
  153. }
  154. HRESULT hr = WriteColors(hKey);
  155. RegCloseKey(hKey);
  156. return hr;
  157. }
  158. HRESULT OmBrowserRegistry::Delete()
  159. {
  160. HRESULT hr;
  161. WCHAR szBuffer[512] = {0};
  162. hr = GetPath(szBuffer, ARRAYSIZE(szBuffer));
  163. if (FAILED(hr)) return hr;
  164. LONG result = SHDeleteKey(HKEY_CURRENT_USER, szBuffer);
  165. hr = (ERROR_SUCCESS != result) ? E_FAIL : S_OK;
  166. return hr;
  167. }
  168. HRESULT OmBrowserRegistry::UpdateColors()
  169. {
  170. HKEY hKey;
  171. HRESULT hr = CreateRoot(&hKey, NULL);
  172. if (FAILED(hr)) return hr;
  173. hr = WriteColors(hKey);
  174. RegCloseKey(hKey);
  175. return hr;
  176. }
  177. HRESULT OmBrowserRegistry::GetPath(LPWSTR pszBuffer, INT cchBufferMax)
  178. {
  179. if (NULL == pszBuffer)
  180. return E_POINTER;
  181. if (NULL == path)
  182. {
  183. HRESULT hr = CreatePath(pszBuffer, cchBufferMax);
  184. if (FAILED(hr)) return hr;
  185. path = Plugin_CopyString(pszBuffer);
  186. }
  187. return StringCchPrintfW(pszBuffer, cchBufferMax, path);
  188. }
  189. HRESULT OmBrowserRegistry::CreatePath(LPWSTR pszBuffer, INT cchBufferMax)
  190. {
  191. if (NULL == pszBuffer) return E_POINTER;
  192. if (NULL == name || L'\0' == *name) return E_INVALIDARG;
  193. HRESULT hr;
  194. WCHAR szApp[128] = {0}, szSessionId[128] = {0};
  195. ifc_wasabihelper *wasabi;
  196. hr = Plugin_GetWasabiHelper(&wasabi);
  197. if (SUCCEEDED(hr))
  198. {
  199. api_application *app;
  200. hr = wasabi->GetApplicationApi(&app);
  201. if (SUCCEEDED(hr))
  202. {
  203. if (FAILED(StringCchCopyEx(szApp, ARRAYSIZE(szApp), app->main_getAppName(), NULL, NULL, STRSAFE_IGNORE_NULLS)))
  204. szApp[0] = L'\0';
  205. UUID uid;
  206. if (API_APPLICATION_SUCCESS == app->GetSessionID(&uid))
  207. {
  208. RPC_WSTR pszUid;
  209. if (RPC_S_OK == UuidToString(&uid, &pszUid))
  210. {
  211. if(FAILED(StringCchCopy(szSessionId, ARRAYSIZE(szSessionId), (LPCWSTR)pszUid)))
  212. szSessionId[0] = L'\0';
  213. RpcStringFree(&pszUid);
  214. }
  215. }
  216. app->Release();
  217. }
  218. wasabi->Release();
  219. }
  220. if (L'\0' == szApp[0])
  221. hr = StringCchCopy(szApp, ARRAYSIZE(szApp), L"Winamp");
  222. if (L'\0' == szSessionId[0])
  223. hr = StringCchPrintf(szSessionId, ARRAYSIZE(szSessionId), L"%u", GetCurrentProcessId());
  224. if (SUCCEEDED(hr))
  225. hr = StringCchPrintfW(pszBuffer, cchBufferMax, L"Software\\%s\\%s\\%s", szApp, name, szSessionId);
  226. if (FAILED(hr))
  227. *pszBuffer = L'\0';
  228. return hr;
  229. }
  230. HRESULT OmBrowserRegistry::CreateRoot(HKEY *hKey, DWORD *pDisposition)
  231. {
  232. if (NULL == path)
  233. {
  234. WCHAR szBuffer[2048] = {0};
  235. HRESULT hr = CreatePath(szBuffer, ARRAYSIZE(szBuffer));
  236. if (FAILED(hr)) return hr;
  237. path = Plugin_CopyString(szBuffer);
  238. if (NULL == path) return E_OUTOFMEMORY;
  239. }
  240. if (NULL == path || L'\0' == *path)
  241. return E_UNEXPECTED;
  242. DWORD disposition;
  243. LONG result = RegCreateKeyExW(HKEY_CURRENT_USER, path, NULL, NULL, REG_OPTION_VOLATILE, KEY_SET_VALUE, NULL, hKey, &disposition);
  244. if (ERROR_SUCCESS != result)
  245. {
  246. return E_FAIL;
  247. }
  248. if (NULL != pDisposition)
  249. *pDisposition = disposition;
  250. return S_OK;
  251. }
  252. HRESULT OmBrowserRegistry::WriteColors(HKEY hKey)
  253. {
  254. return S_OK;
  255. ifc_skinnedbrowser *skinnedBrowser;
  256. HRESULT hr = Plugin_GetBrowserSkin(&skinnedBrowser);
  257. if (FAILED(hr)) return E_FAIL;
  258. LONG result;
  259. DWORD disposition;
  260. HKEY hKey2 = NULL;
  261. result = RegCreateKeyExW(hKey, L"Settings", NULL, NULL, REG_OPTION_VOLATILE, KEY_SET_VALUE, NULL, &hKey2, &disposition);
  262. if (ERROR_SUCCESS == result)
  263. {
  264. REGVAL_RGB(hKey2, L"Text Color", skinnedBrowser->GetTextColor());
  265. REGVAL_RGB(hKey2, L"Background Color", skinnedBrowser->GetBackColor());
  266. REGVAL_RGB(hKey2, L"Anchor Color", skinnedBrowser->GetLinkColor());
  267. REGVAL_RGB(hKey2, L"Anchor Color Hover", skinnedBrowser->GetHoveredLinkColor());
  268. REGVAL_YES(hKey2, L"Use Anchor Hover Color");
  269. REGVAL_RGB(hKey2, L"Anchor Color Visited", skinnedBrowser->GetVisitedLinkColor());
  270. RegCloseKey(hKey2);
  271. }
  272. skinnedBrowser->Release();
  273. return hr;
  274. }
  275. #define CBCLASS OmBrowserRegistry
  276. START_DISPATCH;
  277. CB(ADDREF, AddRef)
  278. CB(RELEASE, Release)
  279. CB(QUERYINTERFACE, QueryInterface)
  280. CB(API_GETPATH, GetPath)
  281. CB(API_WRITE, Write)
  282. CB(API_DELETE, Delete)
  283. CB(API_UPDATECOLORS, UpdateColors)
  284. END_DISPATCH;
  285. #undef CBCLASS