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.

175 lines
4.8 KiB

  1. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Microsoft Windows, Copyright (C) Microsoft Corporation, 2000
  3. File: DialogUI.h
  4. Content: Declaration of DialogUI.
  5. History: 11-15-99 dsie created
  6. ------------------------------------------------------------------------------*/
  7. #ifndef __DIALOGUI_H_
  8. #define __DIALOGUI_H_
  9. #include "Resource.h"
  10. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  11. Function : UserApprovedOperation
  12. Synopsis : Pop UI to prompt user to approve an operation.
  13. Parameter: DWORD iddDialog - ID of dialog to display.
  14. LPWSTR pwszDomain - DNS name.
  15. Remark :
  16. ------------------------------------------------------------------------------*/
  17. HRESULT UserApprovedOperation (DWORD iddDialog, LPWSTR pwszDomain);
  18. //
  19. // IPromptUser
  20. //
  21. template <class T>
  22. class ATL_NO_VTABLE IPromptUser : public IObjectWithSiteImpl<T>
  23. {
  24. public:
  25. STDMETHODIMP OperationApproved(DWORD iddDialog)
  26. {
  27. HRESULT hr = S_OK;
  28. CComBSTR bstrUrl;
  29. CComBSTR bstrDomain;
  30. INTERNET_SCHEME nScheme;
  31. DebugTrace("Entering IPromptUser::OperationApproved().\n");
  32. if (FAILED(hr = GetCurrentUrl(&bstrUrl)))
  33. {
  34. DebugTrace("Error [%#x]: IPromptUser::GetCurrentUrl() failed.\n", hr);
  35. goto CommonExit;
  36. }
  37. DebugTrace("Info: Site URL = %ls.\n", bstrUrl);
  38. if (FAILED(hr = GetDomainAndScheme(bstrUrl, &bstrDomain, &nScheme)))
  39. {
  40. DebugTrace("Error [%#x]: IPromptUser::GetDomainAndScheme() failed.\n", hr);
  41. goto CommonExit;
  42. }
  43. DebugTrace("Info: DNS = %ls, Scheme = %#x.\n", bstrDomain, nScheme);
  44. if (INTERNET_SCHEME_HTTP == nScheme || INTERNET_SCHEME_HTTPS == nScheme)
  45. {
  46. if (FAILED(hr = ::UserApprovedOperation(iddDialog, bstrDomain)))
  47. {
  48. DebugTrace("Error [%#x]: UserApprovedOperation() failed.\n", hr);
  49. goto CommonExit;
  50. }
  51. }
  52. CommonExit:
  53. DebugTrace("Leaving IPromptUser::OperationApproved().\n");
  54. return hr;
  55. }
  56. private:
  57. STDMETHODIMP GetDomainAndScheme (LPWSTR wszUrl, BSTR * pbstrDomain, INTERNET_SCHEME * pScheme)
  58. {
  59. HRESULT hr = S_OK;
  60. OLECHAR wszDomain[INTERNET_MAX_HOST_NAME_LENGTH];
  61. OLECHAR wszDecodedUrl[INTERNET_MAX_URL_LENGTH];
  62. URL_COMPONENTSW uc = {0};
  63. DWORD cchDomain = ARRAYSIZE(wszDomain);
  64. DWORD cchDecodedUrl = ARRAYSIZE(wszDecodedUrl);
  65. //
  66. // CanonicalizeUrl will change "/foo/../bar" into "/bar".
  67. //
  68. if (!::InternetCanonicalizeUrlW(wszUrl, wszDecodedUrl, &cchDecodedUrl, ICU_DECODE))
  69. {
  70. hr = HRESULT_FROM_WIN32(::GetLastError());
  71. DebugTrace("Error [%#x]: InternetCanonicalizeUrlW() failed.\n", hr);
  72. return hr;
  73. }
  74. //
  75. // Crack will break it down into components.
  76. //
  77. uc.dwStructSize = sizeof(uc);
  78. uc.lpszHostName = wszDomain;
  79. uc.dwHostNameLength = cchDomain;
  80. if (!InternetCrackUrlW(wszDecodedUrl, cchDecodedUrl, ICU_DECODE, &uc))
  81. {
  82. hr = HRESULT_FROM_WIN32(::GetLastError());
  83. DebugTrace("Error [%#x]: InternetCrackUrlW() failed.\n", hr);
  84. return hr;
  85. }
  86. //
  87. // Return domain name.
  88. //
  89. if (NULL == (*pbstrDomain = ::SysAllocString(wszDomain)))
  90. {
  91. hr = E_OUTOFMEMORY;
  92. DebugTrace("Error {%#x]: SysAllocString() failed.\n", hr);
  93. return hr;
  94. }
  95. *pScheme = uc.nScheme;
  96. return hr;
  97. }
  98. STDMETHODIMP GetCurrentUrl (BSTR * pbstrUrl)
  99. {
  100. HRESULT hr = S_OK;
  101. CComBSTR bstrUrl;
  102. CComPtr<IServiceProvider> spSrvProv;
  103. CComPtr<IWebBrowser2> spWebBrowser;
  104. ATLASSERT(pbstrUrl);
  105. *pbstrUrl = NULL;
  106. if (FAILED(hr = GetSite(IID_IServiceProvider, (void **) &spSrvProv)))
  107. {
  108. DebugTrace("Error [%#x]: IPromptUser::GetSite() failed.\n", hr);
  109. return hr;
  110. }
  111. if (FAILED(hr = spSrvProv->QueryService(SID_SWebBrowserApp,
  112. IID_IWebBrowser2,
  113. (void**) &spWebBrowser)))
  114. {
  115. DebugTrace("Error [%#x]: spSrvProv->QueryService() failed.\n", hr);
  116. return hr;
  117. }
  118. if (FAILED(hr = spWebBrowser->get_LocationURL(&bstrUrl)))
  119. {
  120. DebugTrace("Error [%#x]: spWebBrowser->get_LocationURL() failed.\n", hr);
  121. return hr;
  122. }
  123. *pbstrUrl = bstrUrl.Detach();
  124. return hr;
  125. };
  126. };
  127. #endif //__DIALOGUI_H_