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.

1593 lines
52 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright(c) Microsoft Corp., 1995 **
  4. //*********************************************************************
  5. //
  6. // PRIVACY.cpp - "Privacy" Property Sheet and support dialogs
  7. //
  8. // HISTORY:
  9. //
  10. // 2/26/2001 darrenmi new code
  11. // 4/05/2001 jeffdav did per-site cookie dialog ui stuff
  12. #include "inetcplp.h"
  13. #include <urlmon.h>
  14. #include <mluisupp.h>
  15. #include <htmlhelp.h>
  16. BOOL DeleteCacheCookies();
  17. INT_PTR CALLBACK EmptyCacheCookiesDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,LPARAM lParam);
  18. #define REGSTR_PATH_SETTINGS TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings")
  19. #define REGSTR_VAL_PRIVADV TEXT("PrivacyAdvanced")
  20. #define REGSTR_PRIVACYPS_PATHEDIT TEXT("Software\\Policies\\Microsoft\\Internet Explorer")
  21. #define REGSTR_PRIVACYPS_VALUEDIT TEXT("PrivacyAddRemoveSites") // this key is duplicated in shdocvw\privacyui.cpp
  22. #define REGSTR_PRIVACYPS_PATHPANE TEXT("Software\\Policies\\Microsoft\\Internet Explorer\\Control Panel")
  23. #define REGSTR_PRIVACYPS_VALUPANE TEXT("Privacy Settings") // this key is duplicated in shdocvw\privacyui.cpp
  24. ///////////////////////////////////////////////////////////////////////////////////////
  25. //
  26. // Per-site list dialog
  27. //
  28. ///////////////////////////////////////////////////////////////////////////////////////
  29. ///////////////////////////////////////////////////////////////////////////////////////
  30. //
  31. // Per-site list utility function to minimize the domain name
  32. //
  33. WCHAR *GetMinCookieDomainFromUrl(WCHAR *bstrFullUrl)
  34. {
  35. WCHAR *pMinimizedDomain = NULL;
  36. if(bstrFullUrl == NULL)
  37. goto doneGetMinimizedCookieDomain;
  38. if(bstrFullUrl[0] == '\0')
  39. goto doneGetMinimizedCookieDomain;
  40. WCHAR *pBeginUrl = bstrFullUrl;
  41. WCHAR *pEndUrl = pBeginUrl; // pEndUrl will find the '/path/path..' and clip it from pBeginUrl
  42. while(*pEndUrl != L'\0' && *pEndUrl != L'/')
  43. pEndUrl++;
  44. *pEndUrl = L'\0';
  45. pMinimizedDomain = pEndUrl;
  46. do
  47. {
  48. pMinimizedDomain--;
  49. while(pBeginUrl < pMinimizedDomain
  50. && *(pMinimizedDomain-1) != L'.')
  51. {
  52. pMinimizedDomain--;
  53. }
  54. } while(!IsDomainLegalCookieDomain( pMinimizedDomain, pBeginUrl)
  55. && pBeginUrl < pMinimizedDomain);
  56. doneGetMinimizedCookieDomain:
  57. return pMinimizedDomain;
  58. }
  59. ///////////////////////////////////////////////////////////////////////////////////////
  60. //
  61. // Per-site list sorting function and data structure
  62. //
  63. struct LVCOMPAREINFO
  64. {
  65. HWND hwndLV; //hwnd for listview
  66. int iCol; //column (0 based)
  67. BOOL fAscending; //true if ascending, false if descending
  68. };
  69. int CALLBACK CompareByAlpha(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
  70. {
  71. struct LVCOMPAREINFO *plvci = (struct LVCOMPAREINFO *)lParamSort;
  72. WCHAR wz1[INTERNET_MAX_URL_LENGTH];
  73. WCHAR wz2[INTERNET_MAX_URL_LENGTH];
  74. ListView_GetItemText(plvci->hwndLV, lParam1, plvci->iCol, wz1, ARRAYSIZE(wz1));
  75. ListView_GetItemText(plvci->hwndLV, lParam2, plvci->iCol, wz2, ARRAYSIZE(wz2));
  76. int iVal = _wcsicmp(wz1, wz2);
  77. if (iVal < 0)
  78. return (plvci->fAscending ? -1 : 1);
  79. if (iVal == 0)
  80. return (0);
  81. // only thing left is if (iVal > 0)...
  82. return (plvci->fAscending ? 1 : -1);
  83. }
  84. ///////////////////////////////////////////////////////////////////////////////////////
  85. //
  86. // Per-site list defines and prototypes
  87. //
  88. #define PRIVACYPS_ACTION_ACCEPT 0
  89. #define PRIVACYPS_ACTION_REJECT 1
  90. #define PRIVACYPS_ACTION_NOACTION 2
  91. void OnContextMenu(HWND hDlg, LPARAM lParam);
  92. void OnInvalidDomain(HWND hDlg);
  93. void OnSiteSet(HWND hDlg);
  94. void OnSiteDelete(HWND hDlg);
  95. void OnSiteClear(HWND hDlg);
  96. void PerSiteInit(HWND hDlg);
  97. LRESULT CALLBACK PrivPerSiteEBProc(HWND hWnd, UINT uMsg, WPARAM wParam,LPARAM lParam);
  98. ///////////////////////////////////////////////////////////////////////////////////////
  99. //
  100. // Per-site list functions
  101. //
  102. void OnContextMenu(HWND hWnd, int iIndex, POINT pointClick)
  103. {
  104. HMENU hMenu0 = LoadMenu(MLGetHinst(), MAKEINTRESOURCE(IDR_PERSITE_CONTEXT_MENU));
  105. HMENU hMenu1 = GetSubMenu(hMenu0, 0);
  106. DWORD dwAction = PRIVACYPS_ACTION_NOACTION;
  107. WCHAR wzUrl[INTERNET_MAX_URL_LENGTH];
  108. WCHAR wzAction[32];
  109. LVITEM lvi;
  110. if(!hMenu1)
  111. return;
  112. if(pointClick.x == -1 && pointClick.y == -1)
  113. {
  114. RECT rectListRect;
  115. RECT rectSelectionRect;
  116. if( 0 != GetWindowRect(hWnd, &rectListRect) &&
  117. TRUE == ListView_GetItemRect(hWnd, iIndex, &rectSelectionRect, LVIR_LABEL))
  118. {
  119. pointClick.x = rectListRect.left + (rectSelectionRect.left + rectSelectionRect.right) / 2;
  120. pointClick.y = rectListRect.top + (rectSelectionRect.top + rectSelectionRect.bottom) / 2;
  121. }
  122. else
  123. return;
  124. }
  125. // display it, get choice (if any)
  126. int iPick = TrackPopupMenu(hMenu1,
  127. TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD,
  128. pointClick.x,
  129. pointClick.y,
  130. 0,
  131. hWnd,
  132. (RECT *)NULL);
  133. DestroyMenu(hMenu0);
  134. DestroyMenu(hMenu1);
  135. if (iPick)
  136. {
  137. switch(iPick)
  138. {
  139. case IDM_PRIVACYPS_CTXM_ACCEPT:
  140. // set the action...
  141. dwAction = PRIVACYPS_ACTION_ACCEPT;
  142. MLLoadString(IDS_PRIVACYPS_ACCEPT, wzAction, ARRAYSIZE(wzAction));
  143. // then fall-through...
  144. case IDM_PRIVACYPS_CTXM_REJECT:
  145. // set the action IFF its reject
  146. if (PRIVACYPS_ACTION_NOACTION == dwAction)
  147. {
  148. dwAction = PRIVACYPS_ACTION_REJECT;
  149. MLLoadString(IDS_PRIVACYPS_REJECT, wzAction, ARRAYSIZE(wzAction));
  150. }
  151. // update the ui...
  152. lvi.iItem = iIndex;
  153. lvi.iSubItem = 1;
  154. lvi.mask = LVIF_TEXT;
  155. lvi.pszText = wzAction;
  156. ListView_SetItem(hWnd, &lvi);
  157. // get the text...
  158. ListView_GetItemText(hWnd, iIndex, 0, wzUrl, ARRAYSIZE(wzUrl));
  159. // update the internal list...
  160. InternetSetPerSiteCookieDecisionW(
  161. wzUrl,
  162. ((PRIVACYPS_ACTION_ACCEPT == dwAction) ? COOKIE_STATE_ACCEPT : COOKIE_STATE_REJECT)
  163. );
  164. break;
  165. case IDM_PRIVACYPS_CTXM_DELETE:
  166. OnSiteDelete(GetParent(hWnd));
  167. break;
  168. default:
  169. break;
  170. }
  171. }
  172. }
  173. void OnInvalidDomain(HWND hDlg)
  174. {
  175. WCHAR szError[256];
  176. WCHAR szTitle[64];
  177. // error message here
  178. MLLoadString(IDS_PRIVACYPS_ERRORTTL, szTitle, ARRAYSIZE(szTitle));
  179. MLLoadString(IDS_PRIVACYPS_ERRORTXT, szError, ARRAYSIZE(szError));
  180. MessageBox(hDlg, szError, szTitle, MB_ICONEXCLAMATION | MB_OK);
  181. // select the editbox text so the user can try again...
  182. SendMessage(GetDlgItem(hDlg, IDC_PRIVACYPS_SITETOSET), EM_SETSEL, (WPARAM)0, (LPARAM)-1);
  183. }
  184. void AutosizeStatusColumnWidth(HWND hwndList)
  185. {
  186. int iColWidth = 0;
  187. RECT rc;
  188. if (0 == ListView_GetItemCount(hwndList))
  189. {
  190. // auto size it based on header text...
  191. ListView_SetColumnWidth(hwndList, 1, LVSCW_AUTOSIZE_USEHEADER);
  192. }
  193. else
  194. {
  195. // auto size it based on content...
  196. ListView_SetColumnWidth(hwndList, 1, LVSCW_AUTOSIZE);
  197. }
  198. // see how big that was...
  199. iColWidth = ListView_GetColumnWidth(hwndList, 1);
  200. // size the 1st col...
  201. GetClientRect(hwndList, &rc);
  202. ListView_SetColumnWidth(hwndList, 0, rc.right-rc.left-iColWidth-GetSystemMetrics(SM_CXVSCROLL));
  203. }
  204. void OnSiteSet(HWND hDlg, UINT uiChoice)
  205. {
  206. WCHAR wzUrl[INTERNET_MAX_URL_LENGTH];
  207. WCHAR wzUrlDomain[INTERNET_MAX_URL_LENGTH];
  208. WCHAR wzUrlMinimized[INTERNET_MAX_URL_LENGTH];
  209. WCHAR wzSchema[INTERNET_MAX_URL_LENGTH];
  210. WCHAR wzAction[32];
  211. LVFINDINFO lvfi;
  212. LVITEM lvi;
  213. DWORD dwAction = 0;
  214. DWORD dwCount = 0;
  215. int iIndex;
  216. HWND hwndList = GetDlgItem(hDlg, IDC_PRIVACYPS_LISTBOX);
  217. // the enter key and dbl click should do the same thing, so if the listbox has focus
  218. // and we got called, then they hit enter in the listbox, so let the listbox process
  219. // a WM_KEYDOWN/VK_RETURN message.
  220. if (GetFocus() == hwndList)
  221. {
  222. INT_PTR iIndx = ListView_GetSelectionMark(GetDlgItem(hDlg, IDC_PRIVACYPS_LISTBOX));
  223. if (-1 != iIndx)
  224. {
  225. SendMessage(hwndList, WM_KEYDOWN, VK_RETURN, NULL);
  226. return;
  227. }
  228. }
  229. // read url and setting from ui
  230. GetWindowText(GetDlgItem(hDlg, IDC_PRIVACYPS_SITETOSET), wzUrl, INTERNET_MAX_URL_LENGTH);
  231. // if it came from AutoComplete it'll have an http:// or https:// in it...
  232. if(wcsstr(_wcslwr(wzUrl), TEXT("http://")) ||
  233. wcsstr(_wcslwr(wzUrl), TEXT("https://")))
  234. {
  235. // ...and we found it, so get just the domain name...
  236. if(S_OK != CoInternetParseUrl(wzUrl, PARSE_DOMAIN, NULL, wzUrlDomain, ARRAYSIZE(wzUrlDomain), &dwCount, 0))
  237. {
  238. OnInvalidDomain(hDlg);
  239. return;
  240. }
  241. else if(wcslen(wzUrlDomain) < 2)
  242. {
  243. OnInvalidDomain(hDlg);
  244. return;
  245. }
  246. }
  247. else if (wcslen(wzUrl) < 2)
  248. {
  249. // we don't want null strings. in fact, the smallest a domain could theoretically be would be something like "f."
  250. // so, to avoid null strings and stuff we check...
  251. OnInvalidDomain(hDlg);
  252. return;
  253. }
  254. else
  255. {
  256. // ...otherwise just use it
  257. wcsncpy(wzUrlDomain, wzUrl, wcslen(wzUrl)+1);
  258. }
  259. // only http:// or https:// domains in the internet zone are valid, so if we still have a schema after asking for just
  260. // the domain (see above) then we must have something like file:/// or some junk like that.
  261. CoInternetParseUrl(wzUrlDomain, PARSE_SCHEMA, NULL, wzSchema, ARRAYSIZE(wzSchema), &dwCount, 0);
  262. if (wcslen(wzSchema) != 0)
  263. {
  264. OnInvalidDomain(hDlg);
  265. return;
  266. }
  267. // minimize the domain
  268. wcsncpy(wzUrlMinimized, GetMinCookieDomainFromUrl(wzUrlDomain), wcslen(wzUrlDomain)+1);
  269. for (unsigned int i=0;i<wcslen(wzUrlMinimized);i++)
  270. {
  271. if (iswalnum(wzUrlMinimized[i]))
  272. {
  273. continue;
  274. }
  275. else
  276. {
  277. switch(wzUrlMinimized[i])
  278. {
  279. case L'.':
  280. if (i >= 1)
  281. if (L'.' == wzUrlMinimized[i-1]) //prevent duplicate periods like "www..net"
  282. break;
  283. // (fallthrough)
  284. case L'-':
  285. if (i == 0) // first character cannot be a dash
  286. break;
  287. // (fallthrough)
  288. case L'/':
  289. continue;
  290. default:
  291. break;
  292. }
  293. OnInvalidDomain(hDlg);
  294. return;
  295. }
  296. }
  297. if (!wcschr(_wcslwr(wzUrlMinimized), L'.'))
  298. {
  299. OnInvalidDomain(hDlg);
  300. return;
  301. }
  302. // valid domain?
  303. if(FALSE == IsDomainLegalCookieDomainW(wzUrlMinimized, wzUrlMinimized))
  304. {
  305. OnInvalidDomain(hDlg);
  306. return;
  307. }
  308. // are we accepting or rejecting this site?
  309. if (IDC_PRIVACYPS_ACCEPTBTN == uiChoice)
  310. {
  311. dwAction = PRIVACYPS_ACTION_ACCEPT;
  312. MLLoadString(IDS_PRIVACYPS_ACCEPT, wzAction, ARRAYSIZE(wzAction));
  313. }
  314. else
  315. if (IDC_PRIVACYPS_REJECTBTN == uiChoice)
  316. {
  317. dwAction = PRIVACYPS_ACTION_REJECT;
  318. MLLoadString(IDS_PRIVACYPS_REJECT, wzAction, ARRAYSIZE(wzAction));
  319. }
  320. else
  321. {
  322. return;
  323. }
  324. // update UI...
  325. lvfi.flags = LVFI_STRING;
  326. lvfi.psz = wzUrlMinimized;
  327. iIndex = ListView_FindItem(hwndList, -1, &lvfi);
  328. if(iIndex != -1)
  329. {
  330. // found it, ensure correct subitem...
  331. lvi.iItem = iIndex;
  332. lvi.iSubItem = 1;
  333. lvi.pszText = wzAction;
  334. lvi.mask = LVIF_TEXT;
  335. ListView_SetItem(hwndList, &lvi);
  336. AutosizeStatusColumnWidth(hwndList);
  337. }
  338. else
  339. {
  340. // add a new item...
  341. lvi.iItem = 0;
  342. lvi.iSubItem = 0;
  343. lvi.mask = LVIF_TEXT;
  344. lvi.pszText = wzUrlMinimized;
  345. iIndex = ListView_InsertItem(hwndList, &lvi);
  346. lvi.iItem = iIndex;
  347. lvi.iSubItem = 1;
  348. lvi.mask = LVIF_TEXT;
  349. lvi.pszText = wzAction;
  350. ListView_SetItem(hwndList, &lvi);
  351. AutosizeStatusColumnWidth(hwndList);
  352. EnableWindow(GetDlgItem(hDlg, IDC_PRIVACYPS_REMOVEALLBTN), TRUE);
  353. }
  354. // update internal list...
  355. InternetSetPerSiteCookieDecisionW(
  356. wzUrlMinimized,
  357. ((PRIVACYPS_ACTION_ACCEPT == dwAction) ? COOKIE_STATE_ACCEPT : COOKIE_STATE_REJECT)
  358. );
  359. // clear the edit box...
  360. SetWindowText(GetDlgItem(hDlg, IDC_PRIVACYPS_SITETOSET), TEXT(""));
  361. SetFocus(GetDlgItem(hDlg, IDC_PRIVACYPS_SITETOSET));
  362. }
  363. void OnSiteDelete(HWND hDlg)
  364. {
  365. WCHAR wzUrl[INTERNET_MAX_URL_LENGTH];
  366. HWND hwndList = GetDlgItem(hDlg, IDC_PRIVACYPS_LISTBOX);
  367. INT_PTR iIndex;
  368. // get the current selection in the list view...
  369. iIndex = ListView_GetSelectionMark(hwndList);
  370. // if we got something get the URL and delete it...
  371. if(iIndex != -1)
  372. {
  373. // remove from listview...
  374. ListView_GetItemText(hwndList, iIndex, 0, wzUrl, ARRAYSIZE(wzUrl));
  375. ListView_DeleteItem(hwndList, iIndex);
  376. // disable buttons if the listbox is now empty...
  377. if(0 == ListView_GetItemCount(hwndList))
  378. {
  379. EnableWindow(GetDlgItem(hDlg, IDC_PRIVACYPS_REMOVEBTN), FALSE);
  380. EnableWindow(GetDlgItem(hDlg, IDC_PRIVACYPS_REMOVEALLBTN), FALSE);
  381. }
  382. InternetSetPerSiteCookieDecisionW(wzUrl, COOKIE_STATE_UNKNOWN);
  383. // clear selection
  384. SetFocus(GetDlgItem(hDlg, IDC_PRIVACYPS_LISTBOX));
  385. iIndex = ListView_GetSelectionMark(hwndList);
  386. ListView_SetItemState(hwndList, iIndex, NULL, LVIS_FOCUSED | LVIS_SELECTED);
  387. EnableWindow(GetDlgItem(hDlg, IDC_PRIVACYPS_REMOVEBTN), FALSE);
  388. }
  389. }
  390. void OnSiteClear(HWND hDlg)
  391. {
  392. // empty the list...
  393. ListView_DeleteAllItems(GetDlgItem(hDlg, IDC_PRIVACYPS_LISTBOX));
  394. InternetClearAllPerSiteCookieDecisions();
  395. // disable the remove buttons...
  396. EnableWindow(GetDlgItem(hDlg, IDC_PRIVACYPS_REMOVEBTN), FALSE);
  397. EnableWindow(GetDlgItem(hDlg, IDC_PRIVACYPS_REMOVEALLBTN), FALSE);
  398. // set focus back to the edit box so they can add more if they feel like it...
  399. SetFocus(GetDlgItem(hDlg, IDC_PRIVACYPS_SITETOSET));
  400. }
  401. void PerSiteInit(HWND hDlg)
  402. {
  403. HWND hwndList = GetDlgItem(hDlg, IDC_PRIVACYPS_LISTBOX);
  404. LVITEM lviEntry;
  405. DWORD dwSizeOfBuffer = 0; // in bytes
  406. DWORD dwDecision = 0;
  407. DWORD dwIndex = 0;
  408. WCHAR wzSiteNameBuffer[INTERNET_MAX_URL_LENGTH];
  409. LONG_PTR wndprocOld = NULL;
  410. WCHAR wzTitle[64];
  411. WCHAR wzAccept[32];
  412. WCHAR wzReject[32];
  413. int iItem;
  414. DWORD dwRet, dwType, dwValue, dwSize;
  415. // subclass the editbox
  416. wndprocOld = SetWindowLongPtr(GetDlgItem(hDlg, IDC_PRIVACYPS_SITETOSET), GWLP_WNDPROC, (LONG_PTR)PrivPerSiteEBProc);
  417. // put a pointer to the old proc in GWLP_USERDATA so we can call it...
  418. SetWindowLongPtr(GetDlgItem(hDlg, IDC_PRIVACYPS_SITETOSET), GWLP_USERDATA, wndprocOld);
  419. if (!hwndList)
  420. return;
  421. // empty the listview...
  422. ListView_DeleteAllItems(hwndList);
  423. // initialize domain column in the listview...
  424. LV_COLUMN lvColumn;
  425. RECT rc;
  426. // load the accept and reject strings...
  427. MLLoadString(IDS_PRIVACYPS_ACCEPT, wzAccept, ARRAYSIZE(wzAccept));
  428. MLLoadString(IDS_PRIVACYPS_REJECT, wzReject, ARRAYSIZE(wzReject));
  429. lvColumn.mask = LVCF_FMT | LVCF_TEXT;
  430. lvColumn.fmt = LVCFMT_LEFT;
  431. if( 0 != GetClientRect( hwndList, &rc))
  432. {
  433. lvColumn.cx = rc.right - rc.left - GetSystemMetrics(SM_CXVSCROLL) - 75;
  434. lvColumn.mask |= LVCF_WIDTH;
  435. }
  436. MLLoadString(IDS_PRIVACYPS_COLSITE, wzTitle, ARRAYSIZE(wzTitle));
  437. lvColumn.pszText = wzTitle;
  438. ListView_InsertColumn(hwndList, 0, &lvColumn);
  439. // initialize setting column
  440. lvColumn.mask = LVCF_FMT | LVCF_TEXT;
  441. lvColumn.fmt = LVCFMT_LEFT;
  442. if( 0 != GetClientRect( hwndList, &rc))
  443. {
  444. lvColumn.cx = 75;
  445. lvColumn.mask |= LVCF_WIDTH;
  446. }
  447. MLLoadString(IDS_PRIVACYPS_COLSET, wzTitle, ARRAYSIZE(wzTitle));
  448. lvColumn.pszText = wzTitle;
  449. ListView_InsertColumn(hwndList, 1, &lvColumn);
  450. // enumerate elements...
  451. while(InternetEnumPerSiteCookieDecision(wzSiteNameBuffer,
  452. (dwSizeOfBuffer = ARRAYSIZE(wzSiteNameBuffer), &dwSizeOfBuffer),
  453. &dwDecision,dwIndex))
  454. {
  455. lviEntry.iItem = dwIndex;
  456. lviEntry.iSubItem = 0;
  457. lviEntry.mask = LVIF_TEXT /*| LVIF_IMAGE*/;
  458. lviEntry.pszText = wzSiteNameBuffer;
  459. // don't display crap users may hack into the registry themselves, or hosed entries we may write :)
  460. if(FALSE == IsDomainLegalCookieDomainW(wzSiteNameBuffer, wzSiteNameBuffer))
  461. {
  462. dwIndex++;
  463. continue;
  464. }
  465. iItem = ListView_InsertItem(hwndList, &lviEntry);
  466. lviEntry.iItem = iItem;
  467. lviEntry.iSubItem = 1;
  468. lviEntry.mask = LVIF_TEXT;
  469. if (dwDecision == COOKIE_STATE_ACCEPT)
  470. lviEntry.pszText = wzAccept;
  471. else if (dwDecision == COOKIE_STATE_REJECT)
  472. lviEntry.pszText = wzReject;
  473. else
  474. {
  475. dwIndex++;
  476. continue;
  477. }
  478. ListView_SetItem(hwndList, &lviEntry);
  479. dwIndex++;
  480. }
  481. AutosizeStatusColumnWidth(hwndList);
  482. // enable the remove all button if we enumerated anything...
  483. if (dwIndex > 0)
  484. {
  485. ListView_SetItemState(hwndList, 0, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED);
  486. EnableWindow(GetDlgItem(hDlg, IDC_PRIVACYPS_REMOVEALLBTN), TRUE);
  487. }
  488. // enable autocomplete for the editbox...
  489. SHAutoComplete(GetDlgItem(hDlg, IDC_PRIVACYPS_SITETOSET), SHACF_DEFAULT);
  490. // check for policy to make this dialog read-only...
  491. dwSize = sizeof(dwValue);
  492. dwRet = SHGetValue(HKEY_CURRENT_USER, REGSTR_PRIVACYPS_PATHPANE, REGSTR_PRIVACYPS_VALUPANE, &dwType, &dwValue, &dwSize);
  493. if (ERROR_SUCCESS == dwRet && dwValue && REG_DWORD == dwType)
  494. {
  495. SetWindowLongPtr(hDlg, DWLP_USER, (LONG_PTR)TRUE);
  496. // disable all buttons and stuff...
  497. EnableWindow(GetDlgItem(hDlg, IDC_PRIVACYPS_SITETOSET), FALSE);
  498. EnableWindow(GetDlgItem(hDlg, IDC_PRIVACYPS_REJECTBTN), FALSE);
  499. EnableWindow(GetDlgItem(hDlg, IDC_PRIVACYPS_ACCEPTBTN), FALSE);
  500. EnableWindow(GetDlgItem(hDlg, IDC_PRIVACYPS_REMOVEBTN), FALSE);
  501. EnableWindow(GetDlgItem(hDlg, IDC_PRIVACYPS_REMOVEALLBTN), FALSE);
  502. }
  503. }
  504. void OnDoubleClick(HWND hWnd)
  505. {
  506. int iIndex = ListView_GetSelectionMark(hWnd);
  507. WCHAR wzUrl[INTERNET_MAX_URL_LENGTH];
  508. // on dbl clicks we want to enter the item in the edit box so the user can edit it, or cut & paste, or whatever
  509. // but only if we actually have a selected item...
  510. if (-1 == iIndex)
  511. return;
  512. // get the current selection...
  513. ListView_GetItemText(hWnd, iIndex, 0, wzUrl, ARRAYSIZE(wzUrl));
  514. // enter the text into the edit box...
  515. SetDlgItemText(GetParent(hWnd), IDC_PRIVACYPS_SITETOSET, wzUrl);
  516. // select it for the user...
  517. SendMessage(GetDlgItem(GetParent(hWnd), IDC_PRIVACYPS_SITETOSET), EM_SETSEL, (WPARAM)0, (LPARAM)-1);
  518. // set focus to the edit box...
  519. SetFocus(GetDlgItem(GetParent(hWnd), IDC_PRIVACYPS_SITETOSET));
  520. // unselect the listview item...
  521. ListView_SetItemState(hWnd, iIndex, NULL, LVIS_FOCUSED | LVIS_SELECTED);
  522. }
  523. ///////////////////////////////////////////////////////////////////////////////////////
  524. //
  525. // Per-site list window proc's
  526. //
  527. LRESULT CALLBACK PrivPerSiteEBProc(HWND hWnd, UINT uMsg, WPARAM wParam,LPARAM lParam)
  528. {
  529. HWND hDlg = GetParent(hWnd);
  530. HWND hwndList = GetDlgItem(hDlg, IDC_PRIVACYPS_LISTBOX);
  531. int iIndex = ListView_GetSelectionMark(hwndList);
  532. switch (uMsg)
  533. {
  534. case WM_SETFOCUS:
  535. // disable the remove button and unselect whatever in the listview...
  536. EnableWindow(GetDlgItem(GetParent(hWnd), IDC_PRIVACYPS_REMOVEBTN), FALSE);
  537. ListView_SetItemState(hwndList, iIndex, NULL, LVIS_FOCUSED | LVIS_SELECTED);
  538. break;
  539. default:
  540. break;
  541. }
  542. return (CallWindowProc((WNDPROC)GetWindowLongPtr(hWnd, GWLP_USERDATA), hWnd, uMsg, wParam, lParam));
  543. }
  544. INT_PTR CALLBACK PrivPerSiteDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  545. {
  546. HWND hwndList = GetDlgItem(hDlg, IDC_PRIVACYPS_LISTBOX);
  547. switch (uMsg)
  548. {
  549. case WM_INITDIALOG:
  550. PerSiteInit(hDlg);
  551. if( IsOS(OS_WHISTLERORGREATER))
  552. {
  553. HICON hIcon = LoadIcon(MLGetHinst(), MAKEINTRESOURCE(IDI_PRIVACY_XP));
  554. if( hIcon != NULL)
  555. SendDlgItemMessage(hDlg, IDC_PRIVACY_ICON, STM_SETICON, (WPARAM)hIcon, 0);
  556. // icons loaded with LoadIcon never need to be released
  557. }
  558. return TRUE;
  559. case WM_COMMAND:
  560. switch(LOWORD(wParam))
  561. {
  562. case IDCANCEL:
  563. case IDOK:
  564. return EndDialog(hDlg, 0);
  565. case IDC_PRIVACYPS_REMOVEALLBTN:
  566. OnSiteClear(hDlg);
  567. return TRUE;
  568. case IDC_PRIVACYPS_REMOVEBTN:
  569. OnSiteDelete(hDlg);
  570. return TRUE;
  571. case IDC_PRIVACYPS_ACCEPTBTN:
  572. OnSiteSet(hDlg, IDC_PRIVACYPS_ACCEPTBTN);
  573. return TRUE;
  574. case IDC_PRIVACYPS_REJECTBTN:
  575. OnSiteSet(hDlg, IDC_PRIVACYPS_REJECTBTN);
  576. return TRUE;
  577. }
  578. break;
  579. case WM_NOTIFY:
  580. if (IDC_PRIVACYPS_LISTBOX == ((LPNMHDR)lParam)->idFrom)
  581. {
  582. switch (((LPNMHDR)lParam)->code)
  583. {
  584. case NM_KILLFOCUS:
  585. // lost focus, turn off remove button
  586. if ((GetDlgItem(hDlg, IDC_PRIVACYPS_REMOVEBTN) != GetFocus()) ||
  587. (-1 == ListView_GetSelectionMark(hwndList)))
  588. {
  589. EnableWindow(GetDlgItem(hDlg, IDC_PRIVACYPS_REMOVEBTN), FALSE);
  590. }
  591. return TRUE;
  592. case NM_SETFOCUS:
  593. {
  594. // if there is nothing in the list we have nothing to do
  595. if (0 == ListView_GetItemCount(hwndList))
  596. break;
  597. // if this is true a policy has been set making per-site list read-only, so do nothing...
  598. if ((BOOL)GetWindowLongPtr(hDlg, DWLP_USER))
  599. break;
  600. int iIndex = ListView_GetSelectionMark(hwndList);
  601. if (-1 == iIndex)
  602. {
  603. iIndex = 0;
  604. }
  605. // select|focus the correct item...
  606. ListView_SetItemState(hwndList, iIndex, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED);
  607. EnableWindow(GetDlgItem(hDlg, IDC_PRIVACYPS_REMOVEBTN), TRUE);
  608. }
  609. return TRUE;
  610. case NM_CLICK:
  611. if (-1 != ListView_GetSelectionMark(hwndList) &&
  612. !((BOOL)GetWindowLongPtr(hDlg, DWLP_USER)))
  613. {
  614. EnableWindow(GetDlgItem(hDlg, IDC_PRIVACYPS_REMOVEBTN), TRUE);
  615. }
  616. else
  617. {
  618. EnableWindow(GetDlgItem(hDlg, IDC_PRIVACYPS_REMOVEBTN), FALSE);
  619. }
  620. return TRUE;
  621. case NM_DBLCLK:
  622. OnDoubleClick(hwndList);
  623. return TRUE;
  624. case NM_RCLICK:
  625. {
  626. // if this is true a policy has been set making per-site list read-only, so don't show the context menu,
  627. // since all it does is allow you to change or remove things...
  628. if ((BOOL)GetWindowLongPtr(hDlg, DWLP_USER))
  629. break;
  630. int iItem = ((LPNMITEMACTIVATE)lParam)->iItem;
  631. if (-1 != iItem)
  632. {
  633. POINT pointClick = ((LPNMITEMACTIVATE)lParam)->ptAction;
  634. RECT rc;
  635. if(0 != GetWindowRect(hwndList, &rc))
  636. {
  637. pointClick.x += rc.left;
  638. pointClick.y += rc.top;
  639. }
  640. else
  641. {
  642. pointClick.x = -1;
  643. pointClick.y = -1;
  644. }
  645. OnContextMenu(hwndList, iItem, pointClick);
  646. }
  647. return TRUE;
  648. }
  649. case LVN_KEYDOWN:
  650. switch (((LPNMLVKEYDOWN)lParam)->wVKey)
  651. {
  652. case VK_DELETE:
  653. OnSiteDelete(hDlg);
  654. return TRUE;
  655. case VK_RETURN:
  656. OnDoubleClick(hwndList);
  657. return TRUE;
  658. default:
  659. break;
  660. }
  661. break;
  662. case LVN_COLUMNCLICK:
  663. {
  664. struct LVCOMPAREINFO lvci;
  665. static BOOL fAscending = TRUE;
  666. fAscending = !fAscending;
  667. lvci.fAscending = fAscending;
  668. lvci.hwndLV = hwndList;
  669. lvci.iCol = ((LPNMLISTVIEW)lParam)->iSubItem;
  670. return ListView_SortItemsEx(hwndList, CompareByAlpha, &lvci);
  671. }
  672. default:
  673. break;
  674. }
  675. }
  676. break;
  677. case WM_HELP: // F1
  678. ResWinHelp((HWND)((LPHELPINFO)lParam)->hItemHandle, IDS_HELPFILE,
  679. HELP_WM_HELP, (DWORD_PTR)(LPSTR)mapIDCsToIDHs);
  680. break;
  681. case WM_CONTEXTMENU: // right mouse click
  682. if ((HWND)wParam != hwndList)
  683. {
  684. ResWinHelp((HWND) wParam, IDS_HELPFILE, HELP_CONTEXTMENU, (DWORD_PTR)(LPSTR)mapIDCsToIDHs);
  685. }
  686. else if (-1 == GET_X_LPARAM(lParam) && -1 == GET_Y_LPARAM(lParam))
  687. {
  688. POINT pointClick;
  689. pointClick.x = -1; pointClick.y = -1;
  690. OnContextMenu(hwndList, ListView_GetSelectionMark(hwndList), pointClick);
  691. }
  692. break;
  693. }
  694. return FALSE;
  695. }
  696. ///////////////////////////////////////////////////////////////////////////////////////
  697. //
  698. // Advanced privacy settings dialog
  699. //
  700. ///////////////////////////////////////////////////////////////////////////////////////
  701. BOOL IsAdvancedMode(void)
  702. {
  703. DWORD dwTemplate, dwError;
  704. BOOL fAdvanced = FALSE;
  705. dwError = PrivacyGetZonePreferenceW(
  706. URLZONE_INTERNET,
  707. PRIVACY_TYPE_FIRST_PARTY,
  708. &dwTemplate,
  709. NULL,
  710. NULL);
  711. if(ERROR_SUCCESS == dwError && PRIVACY_TEMPLATE_ADVANCED == dwTemplate)
  712. {
  713. fAdvanced = TRUE;
  714. }
  715. return fAdvanced;
  716. }
  717. DWORD MapPrefToIndex(WCHAR wcPref)
  718. {
  719. switch(wcPref)
  720. {
  721. case 'r': return 1; // reject
  722. case 'p': return 2; // prompt
  723. default: return 0; // default is accept
  724. }
  725. }
  726. WCHAR MapRadioToPref(HWND hDlg, DWORD dwResource)
  727. {
  728. if(IsDlgButtonChecked(hDlg, dwResource + 1)) // deny
  729. {
  730. return 'r';
  731. }
  732. if(IsDlgButtonChecked(hDlg, dwResource + 2)) // prompt
  733. {
  734. return 'p';
  735. }
  736. // deafult is accept
  737. return 'a';
  738. }
  739. void OnAdvancedInit(HWND hDlg)
  740. {
  741. BOOL fSession = FALSE;
  742. DWORD dwFirst = IDC_FIRST_ACCEPT;
  743. DWORD dwThird = IDC_THIRD_ACCEPT;
  744. if(IsAdvancedMode())
  745. {
  746. WCHAR szBuffer[MAX_PATH];
  747. // MAX_PATH is sufficent for advanced mode setting strings, MaxPrivacySettings is overkill.
  748. WCHAR *pszAlways;
  749. DWORD dwBufferSize, dwTemplate;
  750. DWORD dwError;
  751. //
  752. // turn on advanced check box
  753. //
  754. CheckDlgButton(hDlg, IDC_USE_ADVANCED, TRUE);
  755. //
  756. // Figure out first party setting and session
  757. //
  758. dwBufferSize = ARRAYSIZE( szBuffer);
  759. dwError = PrivacyGetZonePreferenceW(
  760. URLZONE_INTERNET,
  761. PRIVACY_TYPE_FIRST_PARTY,
  762. &dwTemplate,
  763. szBuffer,
  764. &dwBufferSize);
  765. if(ERROR_SUCCESS == dwError)
  766. {
  767. pszAlways = StrStrW(szBuffer, L"always=");
  768. if(pszAlways)
  769. {
  770. dwFirst = IDC_FIRST_ACCEPT + MapPrefToIndex(*(pszAlways + 7));
  771. }
  772. if(StrStrW(szBuffer, L"session"))
  773. {
  774. fSession = TRUE;
  775. }
  776. }
  777. //
  778. // Figure out third party setting
  779. //
  780. dwBufferSize = ARRAYSIZE( szBuffer);
  781. dwError = PrivacyGetZonePreferenceW(
  782. URLZONE_INTERNET,
  783. PRIVACY_TYPE_THIRD_PARTY,
  784. &dwTemplate,
  785. szBuffer,
  786. &dwBufferSize);
  787. if(ERROR_SUCCESS == dwError)
  788. {
  789. WCHAR *pszAlways;
  790. pszAlways = StrStrW(szBuffer, L"always=");
  791. if(pszAlways)
  792. {
  793. dwThird = IDC_THIRD_ACCEPT + MapPrefToIndex(*(pszAlways + 7));
  794. }
  795. }
  796. }
  797. CheckRadioButton(hDlg, IDC_FIRST_ACCEPT, IDC_FIRST_PROMPT, dwFirst);
  798. CheckRadioButton(hDlg, IDC_THIRD_ACCEPT, IDC_THIRD_PROMPT, dwThird);
  799. CheckDlgButton( hDlg, IDC_SESSION_OVERRIDE, fSession);
  800. }
  801. void OnAdvancedOk(HWND hDlg)
  802. {
  803. BOOL fWasAdvanced = IsAdvancedMode();
  804. BOOL fAdvanced = IsDlgButtonChecked(hDlg, IDC_USE_ADVANCED);
  805. // if advanced, build first and third party strings
  806. if(fAdvanced)
  807. {
  808. WCHAR szBuffer[MAX_PATH];
  809. wnsprintf(szBuffer, ARRAYSIZE( szBuffer), L"IE6-P3PV1/settings: always=%c%s",
  810. MapRadioToPref(hDlg, IDC_FIRST_ACCEPT),
  811. IsDlgButtonChecked(hDlg, IDC_SESSION_OVERRIDE) ? L" session=a" : L""
  812. );
  813. PrivacySetZonePreferenceW(
  814. URLZONE_INTERNET,
  815. PRIVACY_TYPE_FIRST_PARTY,
  816. PRIVACY_TEMPLATE_ADVANCED,
  817. szBuffer);
  818. wnsprintf(szBuffer, ARRAYSIZE( szBuffer), L"IE6-P3PV1/settings: always=%c%s",
  819. MapRadioToPref(hDlg, IDC_THIRD_ACCEPT),
  820. IsDlgButtonChecked(hDlg, IDC_SESSION_OVERRIDE) ? L" session=a" : L""
  821. );
  822. PrivacySetZonePreferenceW(
  823. URLZONE_INTERNET,
  824. PRIVACY_TYPE_THIRD_PARTY,
  825. PRIVACY_TEMPLATE_ADVANCED,
  826. szBuffer);
  827. // tell wininet to refresh itself
  828. InternetSetOption(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0);
  829. }
  830. else if ( fWasAdvanced && !fAdvanced)
  831. {
  832. PrivacySetZonePreferenceW(
  833. URLZONE_INTERNET,
  834. PRIVACY_TYPE_FIRST_PARTY,
  835. PRIVACY_TEMPLATE_MEDIUM, NULL);
  836. PrivacySetZonePreferenceW(
  837. URLZONE_INTERNET,
  838. PRIVACY_TYPE_THIRD_PARTY,
  839. PRIVACY_TEMPLATE_MEDIUM, NULL);
  840. // tell wininet to refresh itself
  841. InternetSetOption(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0);
  842. }
  843. }
  844. void OnAdvancedEnable(HWND hDlg)
  845. {
  846. BOOL fEnabled = IsDlgButtonChecked(hDlg, IDC_USE_ADVANCED);
  847. // if restricted, disable checkbox and force all others disabled
  848. if(g_restrict.fPrivacySettings)
  849. {
  850. EnableWindow(GetDlgItem(hDlg, IDC_USE_ADVANCED), FALSE);
  851. fEnabled = FALSE;
  852. }
  853. EnableWindow(GetDlgItem(hDlg, IDC_FIRST_ACCEPT), fEnabled);
  854. EnableWindow(GetDlgItem(hDlg, IDC_FIRST_DENY), fEnabled);
  855. EnableWindow(GetDlgItem(hDlg, IDC_FIRST_PROMPT), fEnabled);
  856. EnableWindow(GetDlgItem(hDlg, IDC_THIRD_ACCEPT), fEnabled);
  857. EnableWindow(GetDlgItem(hDlg, IDC_THIRD_DENY), fEnabled);
  858. EnableWindow(GetDlgItem(hDlg, IDC_THIRD_PROMPT), fEnabled);
  859. EnableWindow(GetDlgItem(hDlg, IDC_SESSION_OVERRIDE), fEnabled);
  860. EnableWindow(GetDlgItem(hDlg, IDC_TX_FIRST), fEnabled);
  861. EnableWindow(GetDlgItem(hDlg, IDC_TX_THIRD), fEnabled);
  862. }
  863. INT_PTR CALLBACK PrivAdvancedDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  864. {
  865. switch (uMsg)
  866. {
  867. case WM_INITDIALOG:
  868. OnAdvancedInit(hDlg);
  869. OnAdvancedEnable(hDlg);
  870. if( IsOS(OS_WHISTLERORGREATER))
  871. {
  872. HICON hIcon = LoadIcon(MLGetHinst(), MAKEINTRESOURCE(IDI_PRIVACY_XP));
  873. if( hIcon != NULL)
  874. SendDlgItemMessage(hDlg, IDC_PRIVACY_ICON, STM_SETICON, (WPARAM)hIcon, 0);
  875. // icons loaded with LoadIcon never need to be released
  876. }
  877. return TRUE;
  878. case WM_HELP: // F1
  879. ResWinHelp( (HWND)((LPHELPINFO)lParam)->hItemHandle, IDS_HELPFILE,
  880. HELP_WM_HELP, (DWORD_PTR)(LPSTR)mapIDCsToIDHs);
  881. break;
  882. case WM_CONTEXTMENU: // right mouse click
  883. ResWinHelp( (HWND) wParam, IDS_HELPFILE,
  884. HELP_CONTEXTMENU, (DWORD_PTR)(LPSTR)mapIDCsToIDHs);
  885. break;
  886. case WM_COMMAND:
  887. switch(LOWORD(wParam))
  888. {
  889. case IDOK:
  890. if(FALSE == g_restrict.fPrivacySettings)
  891. {
  892. OnAdvancedOk(hDlg);
  893. }
  894. // fall through
  895. case IDCANCEL:
  896. EndDialog(hDlg, IDOK == LOWORD(wParam));
  897. return 0;
  898. case IDC_FIRST_ACCEPT:
  899. case IDC_FIRST_PROMPT:
  900. case IDC_FIRST_DENY:
  901. CheckRadioButton(hDlg, IDC_FIRST_ACCEPT, IDC_FIRST_PROMPT, LOWORD(wParam));
  902. return 0;
  903. case IDC_THIRD_ACCEPT:
  904. case IDC_THIRD_PROMPT:
  905. case IDC_THIRD_DENY:
  906. CheckRadioButton(hDlg, IDC_THIRD_ACCEPT, IDC_THIRD_PROMPT, LOWORD(wParam));
  907. return 0;
  908. case IDC_USE_ADVANCED:
  909. OnAdvancedEnable(hDlg);
  910. return 0;
  911. case IDC_PRIVACY_EDIT:
  912. DialogBox(MLGetHinst(), MAKEINTRESOURCE(IDD_PRIVACY_PERSITE),
  913. hDlg, PrivPerSiteDlgProc);
  914. return 0;
  915. }
  916. break;
  917. }
  918. return FALSE;
  919. }
  920. ///////////////////////////////////////////////////////////////////////////////////////
  921. //
  922. // Privacy pane
  923. //
  924. ///////////////////////////////////////////////////////////////////////////////////////
  925. #define PRIVACY_LEVELS 6
  926. #define SLIDER_LEVEL_CUSTOM 6
  927. TCHAR szPrivacyLevel[PRIVACY_LEVELS + 1][30];
  928. TCHAR szPrivacyDescription[PRIVACY_LEVELS + 1][400];
  929. typedef struct _privslider {
  930. DWORD_PTR dwLevel;
  931. BOOL fAdvanced;
  932. BOOL fCustom;
  933. HFONT hfontBolded;
  934. BOOL fEditDisabled;
  935. } PRIVSLIDER, *PPRIVSLIDER;
  936. void EnablePrivacyControls(HWND hDlg, BOOL fCustom)
  937. {
  938. WCHAR szBuffer[256];
  939. if( fCustom)
  940. MLLoadString( IDS_PRIVACY_SLIDERCOMMANDDEF, szBuffer, ARRAYSIZE( szBuffer));
  941. else
  942. MLLoadString( IDS_PRIVACY_SLIDERCOMMANDSLIDE, szBuffer, ARRAYSIZE( szBuffer));
  943. SendMessage(GetDlgItem(hDlg, IDC_PRIVACY_SLIDERCOMMAND), WM_SETTEXT,
  944. 0, (LPARAM)szBuffer);
  945. // slider disabled when custom
  946. EnableWindow(GetDlgItem(hDlg, IDC_LEVEL_SLIDER), !fCustom);
  947. ShowWindow(GetDlgItem(hDlg, IDC_LEVEL_SLIDER), !fCustom);
  948. // default button enabled with custom
  949. EnableWindow(GetDlgItem(hDlg, IDC_PRIVACY_DEFAULT), fCustom);
  950. // if restricted, force slider and defaults disabled
  951. if(g_restrict.fPrivacySettings)
  952. {
  953. EnableWindow(GetDlgItem(hDlg, IDC_PRIVACY_DEFAULT), FALSE);
  954. EnableWindow(GetDlgItem(hDlg, IDC_LEVEL_SLIDER), FALSE);
  955. EnableWindow(GetDlgItem(hDlg, IDC_PRIVACY_IMPORT), FALSE);
  956. }
  957. }
  958. PPRIVSLIDER OnPrivacyInit(HWND hDlg)
  959. {
  960. DWORD i;
  961. PPRIVSLIDER pData;
  962. DWORD dwRet, dwType, dwSize, dwValue;
  963. // allocate storage for the font and current level
  964. pData = new PRIVSLIDER;
  965. if(NULL == pData)
  966. {
  967. // doh
  968. return NULL;
  969. }
  970. pData->dwLevel = -1;
  971. pData->hfontBolded = NULL;
  972. pData->fAdvanced = IsAdvancedMode();
  973. pData->fCustom = FALSE;
  974. pData->fEditDisabled = FALSE;
  975. //
  976. // Set the font of the name to the bold font
  977. //
  978. // find current font
  979. HFONT hfontOrig = (HFONT) SendDlgItemMessage(hDlg, IDC_LEVEL, WM_GETFONT, (WPARAM) 0, (LPARAM) 0);
  980. if(hfontOrig == NULL)
  981. hfontOrig = (HFONT) GetStockObject(SYSTEM_FONT);
  982. // build bold font
  983. if(hfontOrig)
  984. {
  985. LOGFONT lfData;
  986. if(GetObject(hfontOrig, SIZEOF(lfData), &lfData) != 0)
  987. {
  988. // The distance from 400 (normal) to 700 (bold)
  989. lfData.lfWeight += 300;
  990. if(lfData.lfWeight > 1000)
  991. lfData.lfWeight = 1000;
  992. pData->hfontBolded = CreateFontIndirect(&lfData);
  993. if(pData->hfontBolded)
  994. {
  995. // the zone level and zone name text boxes should have the same font, so this is okat
  996. SendDlgItemMessage(hDlg, IDC_LEVEL, WM_SETFONT, (WPARAM) pData->hfontBolded, (LPARAM) MAKELPARAM(FALSE, 0));
  997. }
  998. }
  999. }
  1000. // initialize slider
  1001. SendDlgItemMessage(hDlg, IDC_LEVEL_SLIDER, TBM_SETRANGE, (WPARAM) (BOOL) FALSE, (LPARAM) MAKELONG(0, PRIVACY_LEVELS - 1));
  1002. SendDlgItemMessage(hDlg, IDC_LEVEL_SLIDER, TBM_SETTICFREQ, (WPARAM) 1, (LPARAM) 0);
  1003. // initialize strings for levels and descriptions
  1004. for(i=0; i<PRIVACY_LEVELS + 1; i++)
  1005. {
  1006. MLLoadString(IDS_PRIVACY_LEVEL_NO_COOKIE + i, szPrivacyLevel[i], ARRAYSIZE(szPrivacyLevel[i]));
  1007. MLLoadString(IDS_PRIVACY_DESC_NO_COOKIE + i, szPrivacyDescription[i], ARRAYSIZE(szPrivacyDescription[i]));
  1008. }
  1009. //
  1010. // Get current internet privacy level
  1011. //
  1012. DWORD dwError, dwTemplateFirst, dwTemplateThird;
  1013. // read first party setting
  1014. dwError = PrivacyGetZonePreferenceW(
  1015. URLZONE_INTERNET,
  1016. PRIVACY_TYPE_FIRST_PARTY,
  1017. &dwTemplateFirst,
  1018. NULL,
  1019. NULL);
  1020. if(dwError != ERROR_SUCCESS)
  1021. {
  1022. dwTemplateFirst = PRIVACY_TEMPLATE_CUSTOM;
  1023. }
  1024. // read third party setting
  1025. dwError = PrivacyGetZonePreferenceW(
  1026. URLZONE_INTERNET,
  1027. PRIVACY_TYPE_THIRD_PARTY,
  1028. &dwTemplateThird,
  1029. NULL,
  1030. NULL);
  1031. if(dwError != ERROR_SUCCESS)
  1032. {
  1033. dwTemplateThird = PRIVACY_TEMPLATE_CUSTOM;
  1034. }
  1035. if(dwTemplateFirst == dwTemplateThird && dwTemplateFirst != PRIVACY_TEMPLATE_CUSTOM)
  1036. {
  1037. // matched template values, set slider to template level
  1038. pData->dwLevel = dwTemplateFirst;
  1039. if(dwTemplateFirst == PRIVACY_TEMPLATE_ADVANCED)
  1040. {
  1041. pData->fAdvanced = TRUE;
  1042. pData->dwLevel = SLIDER_LEVEL_CUSTOM;
  1043. }
  1044. }
  1045. else
  1046. {
  1047. // make custom end of list
  1048. pData->dwLevel = SLIDER_LEVEL_CUSTOM;
  1049. pData->fCustom = TRUE;
  1050. }
  1051. // move slider to right spot
  1052. SendDlgItemMessage(hDlg, IDC_LEVEL_SLIDER, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)pData->dwLevel);
  1053. // Enable stuff based on mode
  1054. EnablePrivacyControls(hDlg, ((pData->fAdvanced) || (pData->fCustom)));
  1055. // save off struct
  1056. SetWindowLongPtr(hDlg, DWLP_USER, (DWORD_PTR)pData);
  1057. dwSize = sizeof(dwValue);
  1058. dwRet = SHGetValue(HKEY_CURRENT_USER, REGSTR_PRIVACYPS_PATHEDIT, REGSTR_PRIVACYPS_VALUEDIT, &dwType, &dwValue, &dwSize);
  1059. if (ERROR_SUCCESS == dwRet && 1 == dwValue && REG_DWORD == dwType)
  1060. {
  1061. EnableWindow(GetDlgItem(hDlg, IDC_PRIVACY_EDIT), FALSE);
  1062. pData->fEditDisabled = TRUE;
  1063. }
  1064. return pData;
  1065. }
  1066. void OnPrivacyApply(HWND hDlg, PPRIVSLIDER pData)
  1067. {
  1068. if(pData->fCustom || pData->fAdvanced)
  1069. {
  1070. // nothing else to do
  1071. return;
  1072. }
  1073. DWORD_PTR dwPos = SendDlgItemMessage(hDlg, IDC_LEVEL_SLIDER, TBM_GETPOS, 0, 0);
  1074. if(pData->dwLevel != dwPos)
  1075. {
  1076. DWORD dwCookieAction = URLPOLICY_DISALLOW;
  1077. // Set privacy settings
  1078. PrivacySetZonePreferenceW(
  1079. URLZONE_INTERNET,
  1080. PRIVACY_TYPE_FIRST_PARTY,
  1081. (DWORD)dwPos,
  1082. NULL);
  1083. PrivacySetZonePreferenceW(
  1084. URLZONE_INTERNET,
  1085. PRIVACY_TYPE_THIRD_PARTY,
  1086. (DWORD)dwPos,
  1087. NULL);
  1088. // tell wininet to refresh itself
  1089. InternetSetOption(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0);
  1090. // save new level as "current"
  1091. pData->dwLevel = dwPos;
  1092. }
  1093. }
  1094. void OnPrivacySlider(HWND hDlg, PPRIVSLIDER pData)
  1095. {
  1096. DWORD dwPos;
  1097. if(pData->fCustom || pData->fAdvanced)
  1098. {
  1099. dwPos = SLIDER_LEVEL_CUSTOM;
  1100. }
  1101. else
  1102. {
  1103. dwPos = (DWORD)SendDlgItemMessage(hDlg, IDC_LEVEL_SLIDER, TBM_GETPOS, 0, 0);
  1104. if(dwPos != pData->dwLevel)
  1105. {
  1106. ENABLEAPPLY(hDlg);
  1107. }
  1108. // enable default button if slider moved off medium
  1109. BOOL fEnable = FALSE;
  1110. if(dwPos != PRIVACY_TEMPLATE_MEDIUM && FALSE == g_restrict.fPrivacySettings)
  1111. {
  1112. fEnable = TRUE;
  1113. }
  1114. EnableWindow(GetDlgItem(hDlg, IDC_PRIVACY_DEFAULT), fEnable);
  1115. }
  1116. if (PRIVACY_TEMPLATE_NO_COOKIES == dwPos || PRIVACY_TEMPLATE_LOW == dwPos || pData->fEditDisabled)
  1117. {
  1118. EnableWindow(GetDlgItem(hDlg, IDC_PRIVACY_EDIT), FALSE);
  1119. }
  1120. else
  1121. {
  1122. EnableWindow(GetDlgItem(hDlg, IDC_PRIVACY_EDIT), TRUE);
  1123. }
  1124. // on Mouse Move, change the level description only
  1125. SetDlgItemText(hDlg, IDC_LEVEL_DESCRIPTION, szPrivacyDescription[dwPos]);
  1126. SetDlgItemText(hDlg, IDC_LEVEL, szPrivacyLevel[dwPos]);
  1127. }
  1128. void OnPrivacyDefault( HWND hDlg, PPRIVSLIDER pData)
  1129. {
  1130. // enable controls correctly
  1131. pData->fAdvanced = FALSE;
  1132. pData->fCustom = FALSE;
  1133. EnablePrivacyControls(hDlg, FALSE);
  1134. // set slider to medium
  1135. SendDlgItemMessage(hDlg, IDC_LEVEL_SLIDER, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)PRIVACY_TEMPLATE_MEDIUM);
  1136. // update descriptions
  1137. pData->dwLevel = SLIDER_LEVEL_CUSTOM; // difference from medium so we get apply button
  1138. OnPrivacySlider(hDlg, pData);
  1139. // Give slider focus (if default button has focus and gets disabled,
  1140. // alt-key dialog control breaks)
  1141. SendMessage( hDlg, WM_NEXTDLGCTL,
  1142. (WPARAM)GetDlgItem( hDlg, IDC_LEVEL_SLIDER),
  1143. MAKELPARAM( TRUE, 0));
  1144. }
  1145. INT_PTR CALLBACK PrivacyDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  1146. {
  1147. PPRIVSLIDER pData = (PPRIVSLIDER)GetWindowLongPtr(hDlg, DWLP_USER);
  1148. switch (uMsg)
  1149. {
  1150. case WM_INITDIALOG:
  1151. // initialize slider
  1152. pData = OnPrivacyInit(hDlg);
  1153. if(pData)
  1154. {
  1155. OnPrivacySlider(hDlg, pData);
  1156. }
  1157. if( IsOS(OS_WHISTLERORGREATER))
  1158. {
  1159. HICON hIcon = LoadIcon(MLGetHinst(), MAKEINTRESOURCE(IDI_PRIVACY_XP));
  1160. if( hIcon != NULL)
  1161. SendDlgItemMessage(hDlg, IDC_PRIVACY_ICON, STM_SETICON, (WPARAM)hIcon, 0);
  1162. // icons loaded with LoadIcon never need to be released
  1163. }
  1164. return TRUE;
  1165. case WM_VSCROLL:
  1166. // Slider Messages
  1167. OnPrivacySlider(hDlg, pData);
  1168. return TRUE;
  1169. case WM_NOTIFY:
  1170. {
  1171. NMHDR *lpnm = (NMHDR *) lParam;
  1172. ASSERT(lpnm);
  1173. switch (lpnm->code)
  1174. {
  1175. case PSN_QUERYCANCEL:
  1176. case PSN_KILLACTIVE:
  1177. case PSN_RESET:
  1178. return TRUE;
  1179. case PSN_APPLY:
  1180. // Hitting the apply button runs this code
  1181. OnPrivacyApply(hDlg, pData);
  1182. break;
  1183. }
  1184. break;
  1185. }
  1186. case WM_DESTROY:
  1187. {
  1188. if(pData)
  1189. {
  1190. if(pData->hfontBolded)
  1191. DeleteObject(pData->hfontBolded);
  1192. delete pData;
  1193. }
  1194. break;
  1195. }
  1196. case WM_HELP: // F1
  1197. ResWinHelp( (HWND)((LPHELPINFO)lParam)->hItemHandle, IDS_HELPFILE,
  1198. HELP_WM_HELP, (DWORD_PTR)(LPSTR)mapIDCsToIDHs);
  1199. break;
  1200. case WM_CONTEXTMENU: // right mouse click
  1201. ResWinHelp( (HWND) wParam, IDS_HELPFILE,
  1202. HELP_CONTEXTMENU, (DWORD_PTR)(LPSTR)mapIDCsToIDHs);
  1203. break;
  1204. case WM_COMMAND:
  1205. switch(LOWORD(wParam))
  1206. {
  1207. case IDC_PRIVACY_DEFAULT:
  1208. OnPrivacyDefault( hDlg, pData);
  1209. return 0;
  1210. case IDC_PRIVACY_ADVANCED:
  1211. {
  1212. BOOL fWasAdvanced = IsAdvancedMode();
  1213. // show advanced
  1214. if( DialogBox(MLGetHinst(), MAKEINTRESOURCE(IDD_PRIVACY_ADVANCED),
  1215. hDlg, PrivAdvancedDlgProc))
  1216. {
  1217. // refresh advanced and reset slider/controls
  1218. pData->fAdvanced = IsAdvancedMode();
  1219. if(pData->fAdvanced)
  1220. {
  1221. // no longer have a slider template
  1222. pData->fCustom = FALSE;
  1223. pData->dwLevel = SLIDER_LEVEL_CUSTOM;
  1224. EnablePrivacyControls(hDlg, (pData->fCustom || pData->fAdvanced));
  1225. OnPrivacySlider(hDlg, pData);
  1226. // Give advanced button focus (if slider has focus and gets disabled,
  1227. // alt-key dialog control breaks)
  1228. SendMessage( hDlg, WM_NEXTDLGCTL,
  1229. (WPARAM)GetDlgItem( hDlg, IDC_PRIVACY_ADVANCED),
  1230. MAKELPARAM( TRUE, 0));
  1231. }
  1232. else if (!pData->fAdvanced && fWasAdvanced)
  1233. {
  1234. OnPrivacyDefault( hDlg, pData);
  1235. }
  1236. }
  1237. return 0;
  1238. }
  1239. case IDC_PRIVACY_IMPORT:
  1240. {
  1241. WCHAR szDialogTitle[INTERNET_MAX_URL_LENGTH];
  1242. WCHAR szFileExpr[INTERNET_MAX_URL_LENGTH];
  1243. MLLoadString( IDS_PRIVACYIMPORT_TITLE, szDialogTitle, ARRAYSIZE(szDialogTitle));
  1244. int iFileExprLength = MLLoadString( IDS_PRIVACYIMPORT_FILEEXPR, szFileExpr, ARRAYSIZE(szFileExpr));
  1245. szFileExpr[ iFileExprLength + 1] = L'\0'; // the extra \0 in the resource gets clipped.. replace it.
  1246. WCHAR szFile[INTERNET_MAX_URL_LENGTH];
  1247. szFile[0] = L'\0';
  1248. OPENFILENAME ofn;
  1249. memset((void*)&ofn, 0, sizeof(ofn));
  1250. ofn.lStructSize = sizeof( ofn);
  1251. ofn.hwndOwner = hDlg;
  1252. ofn.lpstrFilter = szFileExpr;
  1253. ofn.lpstrFile = szFile;
  1254. ofn.nMaxFile = ARRAYSIZE(szFile);
  1255. ofn.lpstrTitle = szDialogTitle;
  1256. ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY;
  1257. if( 0 != GetOpenFileName(&ofn))
  1258. {
  1259. BOOL fParsePrivacyPreferences = TRUE;
  1260. BOOL fParsePerSiteRules = TRUE;
  1261. BOOL fResults;
  1262. fResults = ImportPrivacySettings( ofn.lpstrFile,
  1263. &fParsePrivacyPreferences, &fParsePerSiteRules);
  1264. if( fResults == FALSE
  1265. || (fParsePrivacyPreferences == FALSE
  1266. && fParsePerSiteRules == FALSE))
  1267. {
  1268. MLShellMessageBox( hDlg, MAKEINTRESOURCE(IDS_PRIVACYIMPORT_FAILURE),
  1269. MAKEINTRESOURCE(IDS_PRIVACYIMPORT_TITLE),
  1270. MB_OK | MB_APPLMODAL | MB_ICONEXCLAMATION | MB_SETFOREGROUND);
  1271. }
  1272. else
  1273. {
  1274. if( fParsePrivacyPreferences)
  1275. {
  1276. pData->fCustom = TRUE;
  1277. pData->fAdvanced = FALSE;
  1278. EnablePrivacyControls( hDlg, pData->fCustom);
  1279. OnPrivacySlider(hDlg, pData);
  1280. }
  1281. MLShellMessageBox( hDlg, MAKEINTRESOURCE(IDS_PRIVACYIMPORT_SUCCESS),
  1282. MAKEINTRESOURCE(IDS_PRIVACYIMPORT_TITLE),
  1283. MB_OK | MB_APPLMODAL | MB_SETFOREGROUND);
  1284. }
  1285. }
  1286. return 0;
  1287. }
  1288. case IDC_PRIVACY_EDIT:
  1289. DialogBox(MLGetHinst(), MAKEINTRESOURCE(IDD_PRIVACY_PERSITE),
  1290. hDlg, PrivPerSiteDlgProc);
  1291. return 0;
  1292. }
  1293. break;
  1294. }
  1295. return FALSE;
  1296. }