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.

261 lines
7.5 KiB

  1. /******************************************************************************
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. HelpHost.cpp
  5. Abstract:
  6. This file contains the implementation of the CPCHHelpHost class,
  7. UI-side version of IHelpHost.
  8. Revision History:
  9. Davide Massarenti (Dmassare) 11/03/2000
  10. created
  11. ******************************************************************************/
  12. #include "stdafx.h"
  13. ////////////////////////////////////////////////////////////////////////////////
  14. #define GRANT_ACCESS_AND_CALL(ext,func,fail) \
  15. HRESULT hr; \
  16. \
  17. if(ext) \
  18. { \
  19. CPCHHelpCenterExternal::TLS* tlsOld = ext->GetTLS(); \
  20. CPCHHelpCenterExternal::TLS tlsNew; ext->SetTLS( &tlsNew ); \
  21. \
  22. tlsNew.m_fSystem = true; \
  23. tlsNew.m_fTrusted = true; \
  24. \
  25. hr = ext->func; \
  26. \
  27. ext->SetTLS( tlsOld ); \
  28. } \
  29. else \
  30. { \
  31. hr = fail; \
  32. } \
  33. \
  34. return hr
  35. ////////////////////////////////////////////////////////////////////////////////
  36. ////////////////////////////////////////////////////////////////////////////////
  37. HelpHost::Main::Main()
  38. {
  39. // CComPtr<IRunningObjectTable> m_rt;
  40. // CComPtr<IMoniker> m_moniker;
  41. m_dwRegister = 0; // DWORD m_dwRegister;
  42. //
  43. m_External = NULL; // CPCHHelpCenterExternal* m_External;
  44. //
  45. m_hEvent = NULL; // HANDLE m_hEvent;
  46. // bool m_comps[COMPID_MAX];
  47. ::ZeroMemory( m_comps, sizeof(m_comps) ); // Initialize to false...
  48. }
  49. HelpHost::Main::~Main()
  50. {
  51. Passivate();
  52. if(m_hEvent) ::CloseHandle( m_hEvent );
  53. }
  54. HRESULT HelpHost::Main::Initialize( /*[in]*/ CPCHHelpCenterExternal* external )
  55. {
  56. __HCP_FUNC_ENTRY( "HelpHost::Main::Initialize" );
  57. HRESULT hr;
  58. m_External = external;
  59. //
  60. // Get a pointer to the ROT and create a class moniker.
  61. //
  62. __MPC_EXIT_IF_METHOD_FAILS(hr, ::GetRunningObjectTable( 0, &m_rt ));
  63. __MPC_EXIT_IF_CALL_RETURNS_NULL(hr, (m_hEvent = ::CreateEvent( NULL, FALSE, TRUE, NULL )));
  64. hr = S_OK;
  65. __HCP_FUNC_CLEANUP;
  66. __HCP_FUNC_EXIT(hr);
  67. }
  68. void HelpHost::Main::Passivate()
  69. {
  70. if(m_rt)
  71. {
  72. if(m_dwRegister)
  73. {
  74. (void)m_rt->Revoke( m_dwRegister );
  75. m_dwRegister = NULL;
  76. }
  77. }
  78. m_rt .Release();
  79. m_moniker.Release();
  80. m_External = NULL;
  81. }
  82. HRESULT HelpHost::Main::Locate( /*[in]*/ CLSID& clsid, /*[out]*/ CComPtr<IPCHHelpHost>& pVal )
  83. {
  84. __HCP_FUNC_ENTRY( "HelpHost::Main::Locate" );
  85. HRESULT hr;
  86. CComPtr<IUnknown> obj;
  87. m_moniker.Release();
  88. __MPC_EXIT_IF_METHOD_FAILS(hr, ::CreateClassMoniker( clsid, &m_moniker ));
  89. if(SUCCEEDED(m_rt->GetObject( m_moniker, &obj )) && obj)
  90. {
  91. __MPC_EXIT_IF_METHOD_FAILS(hr, obj.QueryInterface( &pVal ));
  92. }
  93. else
  94. {
  95. __MPC_SET_ERROR_AND_EXIT(hr, E_NOINTERFACE);
  96. }
  97. hr = S_OK;
  98. __HCP_FUNC_CLEANUP;
  99. __HCP_FUNC_EXIT(hr);
  100. }
  101. HRESULT HelpHost::Main::Register( /*[in]*/ CLSID& clsid )
  102. {
  103. __HCP_FUNC_ENTRY( "HelpHost::Main::Register" );
  104. HRESULT hr;
  105. m_moniker.Release();
  106. __MPC_EXIT_IF_METHOD_FAILS(hr, ::CreateClassMoniker( clsid, &m_moniker ));
  107. __MPC_EXIT_IF_METHOD_FAILS(hr, m_rt->Register( ROTFLAGS_REGISTRATIONKEEPSALIVE, this, m_moniker, &m_dwRegister ));
  108. hr = S_OK;
  109. __HCP_FUNC_CLEANUP;
  110. __HCP_FUNC_EXIT(hr);
  111. }
  112. ////////////////////
  113. void HelpHost::Main::ChangeStatus( /*[in]*/ LPCWSTR szComp, /*[in]*/ bool fStatus )
  114. {
  115. static struct
  116. {
  117. LPCWSTR szName;
  118. CompId comp;
  119. } s_lookup[] =
  120. {
  121. { L"NAVBAR" , COMPID_NAVBAR },
  122. { L"MININAVBAR", COMPID_MININAVBAR },
  123. { L"CONTEXT" , COMPID_CONTEXT },
  124. { L"CONTENTS" , COMPID_CONTENTS },
  125. { L"HHWINDOW" , COMPID_HHWINDOW },
  126. { L"FIRSTPAGE" , COMPID_FIRSTPAGE },
  127. { L"HOMEPAGE" , COMPID_HOMEPAGE },
  128. { L"SUBSITE" , COMPID_SUBSITE },
  129. { L"SEARCH" , COMPID_SEARCH },
  130. { L"INDEX" , COMPID_INDEX },
  131. { L"FAVORITES" , COMPID_FAVORITES },
  132. { L"HISTORY" , COMPID_HISTORY },
  133. { L"CHANNELS" , COMPID_CHANNELS },
  134. { L"OPTIONS" , COMPID_OPTIONS }
  135. };
  136. if(szComp == NULL) return;
  137. for(int i=0; i<ARRAYSIZE(s_lookup); i++)
  138. {
  139. if(!_wcsicmp( szComp, s_lookup[i].szName ))
  140. {
  141. ChangeStatus( s_lookup[i].comp, fStatus );
  142. break;
  143. }
  144. }
  145. }
  146. void HelpHost::Main::ChangeStatus( /*[in]*/ CompId idComp, /*[in]*/ bool fStatus )
  147. {
  148. MPC::SmartLock<_ThreadModel> lock( this );
  149. if(idComp < COMPID_MAX)
  150. {
  151. m_comps[idComp] = fStatus;
  152. if(m_hEvent)
  153. {
  154. ::SetEvent( m_hEvent );
  155. }
  156. }
  157. }
  158. bool HelpHost::Main::GetStatus( /*[in]*/ CompId idComp )
  159. {
  160. MPC::SmartLock<_ThreadModel> lock( this );
  161. if(idComp >= COMPID_MAX) return false;
  162. return m_comps[idComp];
  163. }
  164. bool HelpHost::Main::WaitUntilLoaded( /*[in]*/ CompId idComp, /*[in]*/ DWORD dwTimeout )
  165. {
  166. MPC::SmartLock<_ThreadModel> lock( this );
  167. if(idComp >= COMPID_MAX) return false;
  168. //
  169. // On machine without enough RAM, increase the timeout.
  170. //
  171. {
  172. MEMORYSTATUSEX ms;
  173. ::ZeroMemory( &ms, sizeof(ms) ); ms.dwLength = sizeof(ms);
  174. if(::GlobalMemoryStatusEx( &ms ))
  175. {
  176. if(ms.ullAvailPhys < 32 * 1024 * 1024) dwTimeout *= 10;
  177. }
  178. }
  179. while(m_comps[idComp] == false)
  180. {
  181. //
  182. // Wait without holding a lock on the object.
  183. //
  184. lock = NULL;
  185. if(MPC::WaitForSingleObject( m_hEvent, dwTimeout ) != WAIT_OBJECT_0) return false;
  186. lock = this;
  187. }
  188. return true;
  189. }
  190. ////////////////////
  191. STDMETHODIMP HelpHost::Main::DisplayTopicFromURL( /*[in]*/ BSTR url, /*[in]*/ VARIANT options )
  192. {
  193. GRANT_ACCESS_AND_CALL(m_External, ChangeContext( HSCCONTEXT_CONTENT, NULL, url, /*fAlsoContent*/true ), S_FALSE);
  194. }