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.

297 lines
10 KiB

  1. //This was alternative way to get to the internet host security manager (instead of using SID_SInternetHostSecurityManager)
  2. #if 0
  3. if(FAILED(hr = GetDocument(pUnkControl, &pDoc)))
  4. __leave;
  5. if(FAILED(hr = pDoc->QueryInterface(IID_IInternetHostSecurityManager, (void**)&pSecMan)))
  6. __leave;
  7. #endif
  8. // This function shows how to get to the IHTMLDocument2 that created an
  9. // arbitrary control represented by pUnk
  10. HRESULT GetDocument(IUnknown *pUnk, IHTMLDocument2 **ppDoc)
  11. {
  12. // If an ActiveX control is created in HTML, this function will return
  13. // a pointer to the IHTMLDocument2. To get to the IHTMLDocument2, controls
  14. // must implement IObjectWithSite. If controls also implement IOleObject,
  15. // the method used to get to the IHTMLDocument2 is slightly different.
  16. // This function abstracts the difference between controls that implement
  17. // just IObjectWithSite and controls that implement BOTH IOleObject AND
  18. // IObjectWithSite. This function also abstracts the different techniques
  19. // that need to be used depending on if the control was created through an
  20. // <OBJECT...> tag or if the control was created through JScript using
  21. // 'new ActiveXObject' or VBScript using 'CreateObject'
  22. HRESULT hr = E_FAIL;
  23. IOleObject *pOleObj = NULL;
  24. IObjectWithSite *pObjWithSite = NULL;
  25. IOleClientSite *pSite = NULL;
  26. IOleContainer *pContainer = NULL;
  27. IServiceProvider *pServProv = NULL;
  28. IWebBrowserApp *pWebApp = NULL;
  29. IDispatch *pDisp = NULL;
  30. __try
  31. {
  32. // Check if the ActiveX control supports IOleObject.
  33. if(SUCCEEDED(pUnk->QueryInterface(IID_IOleObject, (void**)&pOleObj)))
  34. {
  35. // If the control was created through an <OBJECT...> tag, IE will
  36. // have passed us an IOleClientSite. If we have not been passed
  37. // an IOleClientSite, GetClientSite will still SUCCEED, but pSite
  38. // will be NULL. In this case, we just go to the next section.
  39. if(SUCCEEDED(pOleObj->GetClientSite(&pSite)) && pSite)
  40. {
  41. // We were passed an IOleClientSite!!! We can call GetContainer
  42. // and QI for the IHTMLDocument2 that we need
  43. if(FAILED(hr = pSite->GetContainer(&pContainer)))
  44. __leave;
  45. hr = pContainer->QueryInterface(IID_IHTMLDocument2, (void**)ppDoc);
  46. // At this point, we are done and do not want to process the
  47. // code in the next seciont
  48. __leave;
  49. }
  50. }
  51. // At this point, one of two things has happened:
  52. // 1) We didn't support IOleObject
  53. // 2) We supported IOleObject, but we were never passed an IOleClientSite
  54. // In either case, we now need to look at IObjectWithSite to try to get
  55. // to our site
  56. if(FAILED(hr = pUnk->QueryInterface(IID_IObjectWithSite, (void**)&pObjWithSite)))
  57. __leave;
  58. // In case #1 above, we may have been passed an IOleClientSite to
  59. // IObjectWithSite::SetSite. This happens if we were created with
  60. // an <OBJECT...> tag
  61. if(SUCCEEDED(pObjWithSite->GetSite(IID_IOleClientSite, (void**)&pSite)))
  62. {
  63. // We can now call GetContainer and QI for the IHTMLDocument2
  64. if(FAILED(hr = pSite->GetContainer(&pContainer)))
  65. __leave;
  66. hr = pContainer->QueryInterface(IID_IHTMLDocument2, (void**)ppDoc);
  67. }
  68. else
  69. {
  70. // If we were not passed an IOleClientSite, it is possible that
  71. // we were created dynamically (with 'new ActiveXObject' in JScript,
  72. // or 'CreateObject' in VBScript). We can use the following steps
  73. // to get to the IHTMLDocument2 that created the control:
  74. // 1) QI for IServiceProvider
  75. // 2) Call QueryService to get an IWebBrowserApp
  76. // 3) Call get_Document to get the IDispatch of the document
  77. // 4) QI for the IHTMLDocument2 interface.
  78. if(FAILED(hr = pObjWithSite->GetSite(IID_IServiceProvider, (void**)&pServProv)))
  79. __leave;
  80. #if 0
  81. if(FAILED(hr = pServProv->QueryService(SID_SWebBrowserApp, IID_IWebBrowserApp, (void**)&pWebApp)))
  82. __leave;
  83. if(FAILED(hr = pWebApp->get_Document(&pDisp)))
  84. __leave;
  85. hr = pDisp->QueryInterface(IID_IHTMLDocument2, (void**)ppDoc);
  86. #endif
  87. // hr = pServProv->QueryService(SID_SContainerDispatch, IID_IHTMLDocument2, (void**)ppDoc);
  88. if(FAILED(hr = pServProv->QueryService(SID_SContainerDispatch, IID_IDispatch, (void**)&pDisp)))
  89. __leave;
  90. hr = pDisp->QueryInterface(IID_IHTMLDocument2, (void**)ppDoc);
  91. }
  92. }
  93. __finally
  94. {
  95. // Release any interfaces we used along the way
  96. if(pOleObj)
  97. pOleObj->Release();
  98. if(pObjWithSite)
  99. pObjWithSite->Release();
  100. if(pSite)
  101. pSite->Release();
  102. if(pContainer)
  103. pContainer->Release();
  104. if(pServProv)
  105. pServProv->Release();
  106. if(pWebApp)
  107. pWebApp->Release();
  108. if(pDisp)
  109. pDisp->Release();
  110. }
  111. return hr;
  112. }
  113. #if 0
  114. // This function shows how to get to the IHTMLDocument2 that created a control
  115. // in either situation (an <OBJECT...> tag or dynamically created controls in
  116. // script). It assumes that the control has just implement IObjectWithSite
  117. // and NOT IOleObject. If IOleObject is implemented, IE will NOT call
  118. // IObjectWithSite::SetSite.
  119. HRESULT GetDocumentFromObjectWithSite(IObjectWithSite *pObject, IHTMLDocument2 **ppDoc)
  120. {
  121. // If an ActiveX control implements IObjectWithSite, this function will
  122. // return a pointer to the IHTMLDocument2 that is hosting the control
  123. // (assuming that the control was created in an HTML page).
  124. // NOTE: If the ActiveX control has also implemented IOleObject, this
  125. // function cannot be used. In that case, IE calls
  126. // IOleObject::SetClientSite instead of IObjectWithSite::SetSite to pass
  127. // the control an IOleClientSite object when the control is created in an
  128. // <OBJECT...> tag. If the control is created dynamically in JScript with
  129. // 'new ActiveXObject' or VBScript with 'CreateObject', then
  130. // IObjectWithSite::SetSite is called. If the ActiveXControl does not
  131. // implement IOleObject (but implements IObjectWithSite), IE will always
  132. // call IObjectWithSite::SetSite. However, the object passed to SetSite
  133. // will still vary depending on if the control was created dynamically or
  134. // statically in an <OBJECT...> tag. This function abstracts the
  135. // difference between the two situations.
  136. HRESULT hr = S_OK;
  137. IOleClientSite *pSite = NULL;
  138. IOleContainer *pContainer = NULL;
  139. IServiceProvider *pServProv = NULL;
  140. IWebBrowserApp *pWebApp = NULL;
  141. IDispatch *pDisp = NULL;
  142. __try
  143. {
  144. if(SUCCEEDED(pObject->GetSite(IID_IOleClientSite, (void**)&pSite)))
  145. {
  146. // If the ActiveX control that implemented IObjectWithSite was
  147. // created on an HTML page using the <OBJECT...> tag, IE will call
  148. // SetSite with an IID_IOleClientSite. We can call GetContainer
  149. // and the QI for the IHTMLDocument2.
  150. if(FAILED(hr = pSite->GetContainer(&pContainer)))
  151. __leave;
  152. hr = pContainer->QueryInterface(IID_IHTMLDocument2, (void**)ppDoc);
  153. }
  154. else
  155. {
  156. // If the ActiveX control that implement IObjectWithSite was
  157. // created dynamically (with 'new ActiveXObject' in JScript, or
  158. // CreateObject in VBScript), we are passed a ??? object. We can
  159. // QI for IServiceProvider, and get to an IWebBrowserApp through
  160. // QueryService. Then, we can get IDispatch pointer of the
  161. // document through get_Document, and finally QI for the
  162. // IHTMLDocument2 interface.
  163. if(FAILED(hr = pObject->GetSite(IID_IServiceProvider, (void**)&psp)))
  164. __leave;
  165. if(FAILED(hr = psp->QueryService(SID_SWebBrowserApp, IID_IWebBrowserApp, (void**)&pApp)))
  166. __leave;
  167. if(FAILED(hr = pApp->get_Document(&pDisp)))
  168. __leave;
  169. hr = pDisp->QueryInterface(IID_IHTMLDocument2, (void**)ppDoc);
  170. }
  171. }
  172. __finally
  173. {
  174. if(pSite)
  175. pSite->Release();
  176. if(pContainer)
  177. pContainer->Release();
  178. if(pServProv)
  179. pServProv->Release();
  180. if(pWebApp)
  181. pWebApp->Release();
  182. if(pDisp)
  183. pDisp->Release();
  184. }
  185. return hr;
  186. }
  187. #endif
  188. #if 0
  189. HRESULT CWMIObjectBroker::GetDocument(IHTMLDocument2 **ppDoc)
  190. {
  191. HRESULT hr = S_OK;
  192. IOleClientSite *pSite = NULL;
  193. // if(SUCCEEDED(GetClientSite(&pSite)) && pSite)
  194. if(FALSE)
  195. {
  196. IOleContainer *pContainer;
  197. if(SUCCEEDED(hr = pSite->GetContainer(&pContainer)))
  198. {
  199. hr = pContainer->QueryInterface(IID_IHTMLDocument2, (void**)ppDoc);
  200. pContainer->Release();
  201. }
  202. pSite->Release();
  203. }
  204. else
  205. {
  206. IServiceProvider *psp = NULL;
  207. if(SUCCEEDED(hr = GetSite(IID_IServiceProvider, (void**)&psp)))
  208. {
  209. IWebBrowserApp *pApp = NULL;
  210. if(SUCCEEDED(hr = psp->QueryService(SID_SWebBrowserApp, IID_IWebBrowserApp, (void**)&pApp)))
  211. {
  212. IDispatch *pDisp;
  213. if(SUCCEEDED(hr = pApp->get_Document(&pDisp)))
  214. {
  215. hr = pDisp->QueryInterface(IID_IHTMLDocument2, (void**)ppDoc);
  216. pDisp->Release();
  217. }
  218. pApp->Release();
  219. }
  220. psp->Release();
  221. }
  222. }
  223. return hr;
  224. }
  225. #endif
  226. #if 0
  227. IHTMLDocument2 *pDoc2 = NULL;
  228. GetDocument(&pDoc2);
  229. IOleClientSite *pSite = NULL;
  230. // GetClientSite(&pSite);
  231. if(!pSite)
  232. {
  233. HRESULT hr = S_OK;
  234. hr = GetSite(IID_IOleClientSite, (void**)&pSite);
  235. hr = GetSite(IID_IServiceProvider, (void**)&pSite);
  236. // hr = GetSite(IID_IActiveScript, (void**)&pSite);
  237. hr = GetSite(IID_IOleContainer, (void**)&pSite);
  238. IServiceProvider *psp = NULL;
  239. hr = GetSite(IID_IServiceProvider, (void**)&psp);
  240. IWebBrowserApp *pApp = NULL;
  241. hr = psp->QueryService(SID_SWebBrowserApp, IID_IWebBrowserApp, (void**)&pApp);
  242. BSTR bstr;
  243. // pApp->get_LocationURL(&bstr);
  244. IHTMLDocument2 *pDoc;
  245. IDispatch *pDisp;
  246. pApp->get_Document(&pDisp);
  247. pDisp->QueryInterface(IID_IHTMLDocument2, (void**)&pDoc);
  248. pDoc->get_URL(&bstr);
  249. bstr = NULL;
  250. }
  251. IOleContainer *pContainer;
  252. pSite->GetContainer(&pContainer);
  253. pSite->Release();
  254. IHTMLDocument2 *pDoc;
  255. pContainer->QueryInterface(IID_IHTMLDocument2, (void**)&pDoc);
  256. BSTR bstrURL = NULL;
  257. pDoc->get_URL(&bstrURL);
  258. SysFreeString(bstrURL);
  259. IHTMLDocument2 *pDocParent = NULL;
  260. IHTMLWindow2 *pWndParent = NULL;
  261. pDoc->get_parentWindow(&pWndParent);
  262. pWndParent->get_document(&pDocParent);
  263. pDocParent->get_URL(&bstrURL);
  264. SysFreeString(bstrURL);
  265. pDocParent->Release();
  266. IHTMLWindow2 *pWnd2 = NULL;
  267. pWndParent->get_top(&pWnd2);
  268. pWnd2->get_document(&pDocParent);
  269. pDocParent->get_URL(&bstrURL);
  270. SysFreeString(bstrURL);
  271. #endif