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.

293 lines
9.2 KiB

  1. //+---------------------------------------------------------------------------
  2. /////////////////////////////////////////////////////////////////////////////////
  3. //
  4. // Microsoft Windows
  5. // Copyright (C) Microsoft Corporation, 2000-2001.
  6. //
  7. // File: SaferEntryInternetZonePropertyPage.cpp
  8. //
  9. // Contents: Implementation of CSaferEntryInternetZonePropertyPage
  10. //
  11. //----------------------------------------------------------------------------
  12. // SaferEntryInternetZonePropertyPage.cpp : implementation file
  13. //
  14. #include "stdafx.h"
  15. #include <gpedit.h>
  16. #include "certmgr.h"
  17. #include "compdata.h"
  18. #include "SaferEntryInternetZonePropertyPage.h"
  19. #include "SaferUtil.h"
  20. #ifdef _DEBUG
  21. #define new DEBUG_NEW
  22. #undef THIS_FILE
  23. static char THIS_FILE[] = __FILE__;
  24. #endif
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CSaferEntryInternetZonePropertyPage property page
  27. CSaferEntryInternetZonePropertyPage::CSaferEntryInternetZonePropertyPage(
  28. CSaferEntry& rSaferEntry,
  29. bool bNew,
  30. LONG_PTR lNotifyHandle,
  31. LPDATAOBJECT pDataObject,
  32. bool bReadOnly,
  33. CCertMgrComponentData* pCompData,
  34. bool bIsMachine)
  35. : CHelpPropertyPage(CSaferEntryInternetZonePropertyPage::IDD),
  36. m_rSaferEntry (rSaferEntry),
  37. m_bDirty (bNew),
  38. m_lNotifyHandle (lNotifyHandle),
  39. m_pDataObject (pDataObject),
  40. m_bReadOnly (bReadOnly),
  41. m_pCompData (pCompData),
  42. m_bIsMachine (bIsMachine)
  43. {
  44. //{{AFX_DATA_INIT(CSaferEntryInternetZonePropertyPage)
  45. // NOTE: the ClassWizard will add member initialization here
  46. //}}AFX_DATA_INIT
  47. m_rSaferEntry.AddRef ();
  48. m_rSaferEntry.IncrementOpenPageCount ();
  49. }
  50. CSaferEntryInternetZonePropertyPage::~CSaferEntryInternetZonePropertyPage()
  51. {
  52. if ( m_lNotifyHandle )
  53. MMCFreeNotifyHandle (m_lNotifyHandle);
  54. m_rSaferEntry.DecrementOpenPageCount ();
  55. m_rSaferEntry.Release ();
  56. }
  57. void CSaferEntryInternetZonePropertyPage::DoDataExchange(CDataExchange* pDX)
  58. {
  59. CHelpPropertyPage::DoDataExchange(pDX);
  60. //{{AFX_DATA_MAP(CSaferEntryInternetZonePropertyPage)
  61. DDX_Control(pDX, IDC_IZONE_ENTRY_ZONES, m_internetZoneCombo);
  62. DDX_Control(pDX, IDC_IZONE_ENTRY_SECURITY_LEVEL, m_securityLevelCombo);
  63. //}}AFX_DATA_MAP
  64. }
  65. BEGIN_MESSAGE_MAP(CSaferEntryInternetZonePropertyPage, CHelpPropertyPage)
  66. //{{AFX_MSG_MAP(CSaferEntryInternetZonePropertyPage)
  67. ON_CBN_SELCHANGE(IDC_IZONE_ENTRY_SECURITY_LEVEL, OnSelchangeIzoneEntrySecurityLevel)
  68. ON_CBN_SELCHANGE(IDC_IZONE_ENTRY_ZONES, OnSelchangeIzoneEntryZones)
  69. //}}AFX_MSG_MAP
  70. END_MESSAGE_MAP()
  71. /////////////////////////////////////////////////////////////////////////////
  72. // CSaferEntryInternetZonePropertyPage message handlers
  73. BOOL CSaferEntryInternetZonePropertyPage::OnInitDialog()
  74. {
  75. CHelpPropertyPage::OnInitDialog();
  76. // Set up User Notification combo box
  77. DWORD dwFlags = 0;
  78. m_rSaferEntry.GetFlags (dwFlags);
  79. ASSERT (m_pCompData);
  80. if ( m_pCompData )
  81. {
  82. CPolicyKey policyKey (m_pCompData->m_pGPEInformation,
  83. SAFER_HKLM_REGBASE,
  84. m_bIsMachine);
  85. InitializeSecurityLevelComboBox (m_securityLevelCombo, false,
  86. m_rSaferEntry.GetLevel (), policyKey.GetKey (),
  87. m_pCompData->m_pdwSaferLevels,
  88. m_bIsMachine);
  89. InitializeInternetZoneComboBox (m_rSaferEntry.GetURLZoneID ());
  90. SendDlgItemMessage (IDC_IZONE_ENTRY_DESCRIPTION, EM_LIMITTEXT, SAFER_MAX_DESCRIPTION_SIZE, 0);
  91. SetDlgItemText (IDC_IZONE_ENTRY_DESCRIPTION, m_rSaferEntry.GetDescription ());
  92. SetDlgItemText (IDC_IZONE_ENTRY_LAST_MODIFIED, m_rSaferEntry.GetLongLastModified ());
  93. if ( m_bReadOnly )
  94. {
  95. m_securityLevelCombo.EnableWindow (FALSE);
  96. m_internetZoneCombo.EnableWindow (FALSE);
  97. }
  98. if ( !m_bDirty )
  99. {
  100. CString szText;
  101. VERIFY (szText.LoadString (IDS_URLZONE_TITLE));
  102. SetDlgItemText (IDC_URLZONE_TITLE, szText);
  103. }
  104. else
  105. SetDlgItemText (IDC_DATE_LAST_MODIFIED_LABEL, L"");
  106. }
  107. return TRUE; // return TRUE unless you set the focus to a control
  108. // EXCEPTION: OCX Property Pages should return FALSE
  109. }
  110. void CSaferEntryInternetZonePropertyPage::InitializeInternetZoneComboBox (DWORD UrlZoneId)
  111. {
  112. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  113. CString szText;
  114. VERIFY (szText.LoadString (IDS_URLZONE_LOCAL_MACHINE));
  115. int nItem = m_internetZoneCombo.AddString (szText);
  116. ASSERT (nItem >= 0);
  117. if ( nItem >= 0 )
  118. {
  119. if ( URLZONE_LOCAL_MACHINE == UrlZoneId )
  120. VERIFY (CB_ERR != m_internetZoneCombo.SetCurSel (nItem));
  121. VERIFY (CB_ERR != m_internetZoneCombo.SetItemData (nItem, URLZONE_LOCAL_MACHINE));
  122. }
  123. VERIFY (szText.LoadString (IDS_URLZONE_INTRANET));
  124. nItem = m_internetZoneCombo.AddString (szText);
  125. ASSERT (nItem >= 0);
  126. if ( nItem >= 0 )
  127. {
  128. if ( URLZONE_INTRANET == UrlZoneId )
  129. VERIFY (CB_ERR != m_internetZoneCombo.SetCurSel (nItem));
  130. VERIFY (CB_ERR != m_internetZoneCombo.SetItemData (nItem, URLZONE_INTRANET));
  131. }
  132. VERIFY (szText.LoadString (IDS_URLZONE_TRUSTED));
  133. nItem = m_internetZoneCombo.AddString (szText);
  134. ASSERT (nItem >= 0);
  135. if ( nItem >= 0 )
  136. {
  137. if ( URLZONE_TRUSTED == UrlZoneId )
  138. VERIFY (CB_ERR != m_internetZoneCombo.SetCurSel (nItem));
  139. VERIFY (CB_ERR != m_internetZoneCombo.SetItemData (nItem, URLZONE_TRUSTED));
  140. }
  141. VERIFY (szText.LoadString (IDS_URLZONE_INTERNET));
  142. nItem = m_internetZoneCombo.AddString (szText);
  143. ASSERT (nItem >= 0);
  144. if ( nItem >= 0 )
  145. {
  146. if ( URLZONE_INTERNET == UrlZoneId )
  147. VERIFY (CB_ERR != m_internetZoneCombo.SetCurSel (nItem));
  148. VERIFY (CB_ERR != m_internetZoneCombo.SetItemData (nItem, URLZONE_INTERNET));
  149. }
  150. VERIFY (szText.LoadString (IDS_URLZONE_UNTRUSTED));
  151. nItem = m_internetZoneCombo.AddString (szText);
  152. ASSERT (nItem >= 0);
  153. if ( nItem >= 0 )
  154. {
  155. if ( URLZONE_UNTRUSTED == UrlZoneId )
  156. VERIFY (CB_ERR != m_internetZoneCombo.SetCurSel (nItem));
  157. VERIFY (CB_ERR != m_internetZoneCombo.SetItemData (nItem, URLZONE_UNTRUSTED));
  158. }
  159. }
  160. void CSaferEntryInternetZonePropertyPage::DoContextHelp (HWND hWndControl)
  161. {
  162. _TRACE (1, L"Entering CSaferEntryInternetZonePropertyPage::DoContextHelp\n");
  163. static const DWORD help_map[] =
  164. {
  165. IDC_IZONE_ENTRY_ZONES, IDH_IZONE_ENTRY_ZONES,
  166. IDC_IZONE_ENTRY_SECURITY_LEVEL, IDH_IZONE_ENTRY_SECURITY_LEVEL,
  167. IDC_IZONE_ENTRY_DESCRIPTION, IDH_IZONE_ENTRY_DESCRIPTION,
  168. IDC_IZONE_ENTRY_LAST_MODIFIED, IDH_IZONE_ENTRY_LAST_MODIFIED,
  169. 0, 0
  170. };
  171. switch (::GetDlgCtrlID (hWndControl))
  172. {
  173. case IDC_IZONE_ENTRY_ZONES:
  174. case IDC_IZONE_ENTRY_SECURITY_LEVEL:
  175. case IDC_IZONE_ENTRY_DESCRIPTION:
  176. case IDC_IZONE_ENTRY_LAST_MODIFIED:
  177. if ( !::WinHelp (
  178. hWndControl,
  179. GetF1HelpFilename(),
  180. HELP_WM_HELP,
  181. (DWORD_PTR) help_map) )
  182. {
  183. _TRACE (0, L"WinHelp () failed: 0x%x\n", GetLastError ());
  184. }
  185. break;
  186. default:
  187. break;
  188. }
  189. _TRACE (-1, L"Leaving CSaferEntryInternetZonePropertyPage::DoContextHelp\n");
  190. }
  191. BOOL CSaferEntryInternetZonePropertyPage::OnApply()
  192. {
  193. if ( m_bDirty && !m_bReadOnly )
  194. {
  195. // Set the level
  196. int nCurSel = m_securityLevelCombo.GetCurSel ();
  197. ASSERT (CB_ERR != nCurSel);
  198. m_rSaferEntry.SetLevel ((DWORD) m_securityLevelCombo.GetItemData (nCurSel));
  199. int nSel = m_internetZoneCombo.GetCurSel ();
  200. ASSERT (CB_ERR != nSel);
  201. if ( CB_ERR != nSel )
  202. {
  203. DWORD_PTR dwURLZoneID = m_internetZoneCombo.GetItemData (nSel);
  204. ASSERT (CB_ERR != dwURLZoneID);
  205. if ( CB_ERR != dwURLZoneID )
  206. m_rSaferEntry.SetURLZoneID ((DWORD) dwURLZoneID);
  207. }
  208. HRESULT hr = m_rSaferEntry.Save ();
  209. if ( SUCCEEDED (hr) )
  210. {
  211. if ( m_lNotifyHandle )
  212. MMCPropertyChangeNotify (
  213. m_lNotifyHandle, // handle to a notification
  214. (LPARAM) m_pDataObject); // unique identifier
  215. m_bDirty = false;
  216. }
  217. else
  218. {
  219. CString text;
  220. CString caption;
  221. CThemeContextActivator activator;
  222. VERIFY (caption.LoadString (IDS_SAFER_WINDOWS_NODE_NAME));
  223. text.FormatMessage (IDS_ERROR_SAVING_ENTRY, GetSystemMessage (hr));
  224. MessageBox (text, caption, MB_OK);
  225. return FALSE;
  226. }
  227. }
  228. return CHelpPropertyPage::OnApply();
  229. }
  230. void CSaferEntryInternetZonePropertyPage::OnSelchangeIzoneEntrySecurityLevel()
  231. {
  232. m_bDirty = true;
  233. SetModified ();
  234. }
  235. void CSaferEntryInternetZonePropertyPage::OnSelchangeIzoneEntryZones()
  236. {
  237. int nSel = m_internetZoneCombo.GetCurSel ();
  238. ASSERT (CB_ERR != nSel);
  239. if ( CB_ERR != nSel )
  240. {
  241. DWORD_PTR dwURLZoneID = m_internetZoneCombo.GetItemData (nSel);
  242. ASSERT (CB_ERR != dwURLZoneID);
  243. if ( CB_ERR != dwURLZoneID )
  244. m_rSaferEntry.SetURLZoneID ((DWORD) dwURLZoneID);
  245. }
  246. SetDlgItemText (IDC_IZONE_ENTRY_DESCRIPTION, m_rSaferEntry.GetDescription ());
  247. m_bDirty = true;
  248. SetModified ();
  249. }