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.

3544 lines
121 KiB

  1. #include "priv.h"
  2. #include "iehelpid.h"
  3. #include "bindcb.h"
  4. #include "winlist.h"
  5. #include "droptgt.h"
  6. #include <mshtml.h> // CLSID_HTMLDocument
  7. #include "resource.h"
  8. #include <htmlhelp.h>
  9. #include <prsht.h>
  10. #include <inetcpl.h>
  11. #include <optary.h>
  12. #include "shdocfl.h"
  13. #include "interned.h" // IHTMLPrivateWindow
  14. #ifdef FEATURE_PICS
  15. #include <shlwapi.h>
  16. #include <ratings.h>
  17. #endif
  18. #include "dochost.h"
  19. #include <mluisupp.h>
  20. #define THISCLASS CDocObjectHost
  21. #define SUPERCLASS CDocHostUIHandler
  22. #define BSCMSG(psz, i, j) TraceMsg(TF_SHDBINDING, "shd TR-BSC::%s %x %x", psz, i, j)
  23. #define BSCMSG3(psz, i, j, k) TraceMsg(0, "shd TR-BSC::%s %x %x %x", psz, i, j, k)
  24. #define BSCMSG4(psz, i, j, k, l) TraceMsg(0, "shd TR-BSC::%s %x %x %x %x", psz, i, j, k, l)
  25. #define BSCMSGS(psz, sz) TraceMsg(0, "shd TR-BSC::%s %s", psz, sz)
  26. #define CHAINMSG(psz, x) TraceMsg(0, "shd CHAIN::%s %x", psz, x)
  27. #define PERFMSG(psz, x) TraceMsg(TF_SHDPERF, "PERF::%s %d msec", psz, x)
  28. #define OPENMSG(psz) TraceMsg(TF_SHDBINDING, "shd OPENING %s", psz)
  29. #define DM_DOCCP 0
  30. #define DM_DEBUGTFRAME 0
  31. #define DM_SELFASC TF_SHDBINDING
  32. #define DM_SSL 0
  33. #define DM_PICS 0
  34. #define DO_SEARCH_ON_STATUSCODE(x) ((x == 0) || (x == HTTP_STATUS_BAD_GATEWAY) || (x == HTTP_STATUS_GATEWAY_TIMEOUT))
  35. const static c_aidRes[] = {
  36. IDI_STATE_NORMAL, // 0
  37. IDI_STATE_FINDINGRESOURCE, // BINDSTATUS_FINDINGRESOURCE
  38. IDI_STATE_FINDINGRESOURCE, // BINDSTATUS_CONNECTING
  39. IDI_STATE_FINDINGRESOURCE, // BINDSTATUS_REDIRECTING
  40. IDI_STATE_DOWNLOADINGDATA, // BINDSTATUS_BEGINDOWNLOADDATA
  41. IDI_STATE_DOWNLOADINGDATA, // BINDSTATUS_DOWNLOADINGDATA
  42. IDI_STATE_DOWNLOADINGDATA, // BINDSTATUS_ENDDOWNLOADDATA
  43. IDI_STATE_DOWNLOADINGDATA, // BINDSTATUS_BEGINDOWNLOADCOMPONENTS
  44. IDI_STATE_DOWNLOADINGDATA, // BINDSTATUS_INSTALLINGCOMPONENTS
  45. IDI_STATE_DOWNLOADINGDATA, // BINDSTATUS_ENDDOWNLOADCOMPONENTS
  46. IDI_STATE_SENDINGREQUEST, // BINDSTATUS_USINGCACHEDCOPY
  47. IDI_STATE_SENDINGREQUEST, // BINDSTATUS_SENDINGREQUEST
  48. IDI_STATE_DOWNLOADINGDATA, // BINDSTATUS_CLASSIDAVAILABLE
  49. };
  50. extern HICON g_ahiconState[IDI_STATE_LAST-IDI_STATE_FIRST+1];
  51. #define SEARCHPREFIX L"? "
  52. #define SEARCHPREFIXSIZE sizeof(SEARCHPREFIX)
  53. #define SEARCHPREFIXLENGTH 2
  54. // Put the most common errors first in c_aErrorUrls.
  55. //
  56. //========================================================
  57. //
  58. // WARNING - Thinking of changing the Table ?
  59. //
  60. // You also need to update the IsErrorHandled in mshtml
  61. // src\site\download\dwnbind.cxx
  62. //
  63. //========================================================
  64. ErrorUrls c_aErrorUrls[] =
  65. {
  66. {404, TEXT("http_404.htm")},
  67. {ERRORPAGE_DNS, TEXT("dnserror.htm")},
  68. {ERRORPAGE_NAVCANCEL, TEXT("navcancl.htm")},
  69. {ERRORPAGE_SYNTAX, TEXT("syntax.htm")},
  70. {400, TEXT("http_400.htm")},
  71. {403, TEXT("http_403.htm")},
  72. {405, TEXT("http_gen.htm")},
  73. {406, TEXT("http_406.htm")},
  74. {408, TEXT("servbusy.htm")},
  75. {409, TEXT("servbusy.htm")},
  76. {410, TEXT("http_410.htm")},
  77. {500, TEXT("http_500.htm")},
  78. {501, TEXT("http_501.htm")},
  79. {505, TEXT("http_501.htm")},
  80. {ERRORPAGE_OFFCANCEL, TEXT("offcancl.htm")},
  81. {ERRORPAGE_CHANNELNOTINCACHE, TEXT("cacheerr.htm")},
  82. };
  83. //
  84. // Determine if there is an internal error page for the given http error.
  85. //
  86. BOOL IsErrorHandled(DWORD dwError)
  87. {
  88. BOOL fRet = FALSE;
  89. for (int i = 0; i < ARRAYSIZE(c_aErrorUrls); i++)
  90. {
  91. if (dwError == c_aErrorUrls[i].dwError)
  92. {
  93. fRet = TRUE;
  94. break;
  95. }
  96. }
  97. return fRet;
  98. }
  99. const SA_BSTRGUID s_sstrSearchIndex = {
  100. 38 * SIZEOF(WCHAR),
  101. L"{265b75c0-4158-11d0-90f6-00c04fd497ea}"
  102. };
  103. //extern const SA_BSTRGUID s_sstrSearchFlags;
  104. const SA_BSTRGUID s_sstrSearchFlags = {
  105. 38 * SIZEOF(WCHAR),
  106. L"{265b75c1-4158-11d0-90f6-00c04fd497ea}"
  107. };
  108. EXTERN_C const SA_BSTRGUID s_sstrSearch = {
  109. 38 * SIZEOF(WCHAR),
  110. L"{118D6040-8494-11d2-BBFE-0060977B464C}"
  111. };
  112. EXTERN_C const SA_BSTRGUID s_sstrFailureUrl = {
  113. 38 * SIZEOF(WCHAR),
  114. L"{04AED800-8494-11d2-BBFE-0060977B464C}"
  115. };
  116. //
  117. // Clears that parameters set by window.external.AutoScan()
  118. //
  119. HRESULT _ClearSearchString(IServiceProvider* psp)
  120. {
  121. HRESULT hr = E_FAIL;
  122. if (psp == NULL)
  123. return hr;
  124. IWebBrowser2 *pWB2 = NULL;
  125. hr = psp->QueryService(SID_SHlinkFrame, IID_IWebBrowser2, (LPVOID*)&pWB2);
  126. if (pWB2 && SUCCEEDED(hr))
  127. {
  128. VARIANT v;
  129. VariantInit(&v);
  130. v.vt = VT_EMPTY;
  131. hr = pWB2->PutProperty((BSTR)s_sstrSearch.wsz, v);
  132. hr = pWB2->PutProperty((BSTR)s_sstrFailureUrl.wsz, v);
  133. pWB2->Release();
  134. }
  135. return hr;
  136. }
  137. //
  138. // Gets the string that was entered in the addressbar
  139. //
  140. HRESULT _GetSearchString(IServiceProvider* psp, VARIANT* pvarSearch)
  141. {
  142. HRESULT hr = E_FAIL;
  143. if (psp != NULL)
  144. {
  145. VariantInit(pvarSearch);
  146. IDockingWindow* psct = NULL;
  147. IOleCommandTarget* poct;
  148. // first see if there is an ISearchContext to get this information from
  149. ISearchContext * pSC = NULL;
  150. hr = psp->QueryService(SID_STopWindow, IID_ISearchContext, (void **) &pSC);
  151. if (SUCCEEDED(hr))
  152. {
  153. RIP(pSC != NULL);
  154. pvarSearch->vt = VT_BSTR;
  155. hr = pSC->GetSearchText(&(pvarSearch->bstrVal));
  156. pSC->Release();
  157. }
  158. else
  159. {
  160. // otherwise try to get the search string directly out of the address bar
  161. hr = psp->QueryService(SID_SExplorerToolbar, IID_IDockingWindow, (LPVOID*)&psct);
  162. if (SUCCEEDED(hr))
  163. {
  164. hr = psct->QueryInterface(IID_IOleCommandTarget, (LPVOID *)&poct);
  165. if (SUCCEEDED(hr))
  166. {
  167. // NULL is the first parameter so our ErrorMsgBox
  168. // doesn't call EnableModelessSB()
  169. // If we don't, our pdoh members may be freed
  170. // by the time we return.
  171. hr = poct->Exec(&CGID_Explorer, SBCMDID_GETUSERADDRESSBARTEXT, 0, NULL, pvarSearch);
  172. poct->Release();
  173. }
  174. psct->Release();
  175. }
  176. }
  177. }
  178. return hr;
  179. }
  180. //
  181. // Get page that should be displayed if the AutoScan fails
  182. //
  183. HRESULT _GetScanFailureUrl(IServiceProvider* psp, VARIANT* pvarFailureUrl)
  184. {
  185. HRESULT hr = E_FAIL;
  186. if (psp == NULL)
  187. return hr;
  188. //
  189. // See if a default failure page is stored as a property of the page
  190. //
  191. IWebBrowser2 *pWB2 = NULL;
  192. hr = psp->QueryService(SID_SHlinkFrame, IID_IWebBrowser2, (LPVOID*)&pWB2);
  193. if (pWB2 && SUCCEEDED(hr))
  194. {
  195. hr = pWB2->GetProperty((BSTR)s_sstrFailureUrl.wsz, pvarFailureUrl);
  196. pWB2->Release();
  197. }
  198. return hr;
  199. }
  200. HRESULT _GetSearchInfo(IServiceProvider *psp, LPDWORD pdwIndex, LPBOOL pfAllowSearch, LPBOOL pfContinueSearch, LPBOOL pfSentToEngine, VARIANT* pvarUrl)
  201. {
  202. HRESULT hr = E_FAIL;
  203. DWORD dwFlags = 0;
  204. if (psp) {
  205. IWebBrowser2 *pWB2 = NULL;
  206. hr = psp->QueryService(SID_SHlinkFrame, IID_IWebBrowser2, (LPVOID*)&pWB2);
  207. if (pWB2 && SUCCEEDED(hr)) {
  208. if (pdwIndex) {
  209. VARIANT v;
  210. if (SUCCEEDED(pWB2->GetProperty((BSTR)s_sstrSearchIndex.wsz, &v))) {
  211. if (v.vt == VT_I4)
  212. *pdwIndex = v.lVal;
  213. VariantClear(&v);
  214. }
  215. }
  216. if (pfAllowSearch || pfContinueSearch || pfSentToEngine) {
  217. VARIANT v;
  218. if (SUCCEEDED(pWB2->GetProperty((BSTR)s_sstrSearchFlags.wsz, &v))) {
  219. if (v.vt == VT_I4)
  220. dwFlags = v.lVal;
  221. VariantClear(&v);
  222. }
  223. }
  224. //
  225. // If we have a search string property, and the index is zero, we start
  226. // with the second autoscan index. This is because the first index should
  227. // have already been tried (see window.external.AutoScan()).
  228. //
  229. if (pvarUrl)
  230. {
  231. VariantInit(pvarUrl); // in case of failure
  232. if (SUCCEEDED(pWB2->GetProperty((BSTR)s_sstrSearch.wsz, pvarUrl)) &&
  233. pvarUrl->vt == VT_BSTR && pdwIndex && *pdwIndex == 0)
  234. {
  235. *pdwIndex = 2;
  236. }
  237. }
  238. if (pfAllowSearch)
  239. *pfAllowSearch = ((dwFlags & 0x01) ? TRUE : FALSE);
  240. if (pfContinueSearch)
  241. *pfContinueSearch = ((dwFlags & 0x02) ? TRUE : FALSE);
  242. if (pfSentToEngine)
  243. *pfSentToEngine = ((dwFlags & 0x04) ? TRUE : FALSE);
  244. pWB2->Release();
  245. }
  246. }
  247. return hr;
  248. }
  249. HRESULT CDocObjectHost::CDOHBindStatusCallback::_SetSearchInfo(CDocObjectHost *pdoh, DWORD dwIndex, BOOL fAllowSearch, BOOL fContinueSearch, BOOL fSentToEngine)
  250. {
  251. HRESULT hr = E_FAIL;
  252. DWORD dwFlags = 0;
  253. dwFlags = (fAllowSearch ? 0x01 : 0) +
  254. (fContinueSearch ? 0x02 : 0) +
  255. (fSentToEngine ? 0x04 : 0);
  256. if (pdoh->_psp)
  257. {
  258. IWebBrowser2 *pWB2 = NULL;
  259. hr = pdoh->_psp->QueryService(SID_SHlinkFrame, IID_IWebBrowser2, (LPVOID*)&pWB2);
  260. if (pWB2 && SUCCEEDED(hr))
  261. {
  262. VARIANT v;
  263. VariantInit (&v);
  264. v.vt = VT_I4;
  265. v.lVal = dwIndex;
  266. pWB2->PutProperty((BSTR)s_sstrSearchIndex.wsz, v);
  267. v.vt = VT_I4;
  268. v.lVal = dwFlags;
  269. pWB2->PutProperty((BSTR)s_sstrSearchFlags.wsz, v);
  270. pWB2->Release();
  271. }
  272. }
  273. // If we are done, clear any parameters set by window.external.AutoScan().
  274. if (!fContinueSearch)
  275. {
  276. _ClearSearchString(pdoh->_psp);
  277. }
  278. TraceMsg(TF_SHDNAVIGATE, "::HFNS_SetSearchInfo() hr = %X, index = %d, allow = %d, cont = %d, sent = %d", hr, dwIndex, fAllowSearch, fContinueSearch, fSentToEngine);
  279. return hr;
  280. }
  281. //
  282. // Gets the prefix/postfix to use for autoscanning (www.%s.com, etc)
  283. //
  284. LONG GetSearchFormatString(DWORD dwIndex, LPTSTR psz, DWORD cbpsz)
  285. {
  286. TCHAR szValue[11]; //Should be large enough to hold max dword 4294967295
  287. DWORD dwType;
  288. wnsprintf(szValue, ARRAYSIZE(szValue), TEXT("%d"), dwIndex);
  289. return SHRegGetUSValue(REGSTR_PATH_SEARCHSTRINGS, szValue, &dwType, (LPVOID)psz, &cbpsz, FALSE, NULL, 0);
  290. }
  291. // dwSearchForExtensions : 0 do not search
  292. // dwSearchForExtensions : 1 search through list of exts.
  293. // dwSearchForExtensions : 2 move on to autosearch
  294. // 0 = never ask, never search
  295. // 1 = always ask
  296. // 2 = never ask, always search
  297. HRESULT GetSearchKeys(IServiceProvider * psp, LPDWORD pdwSearchStyle, LPDWORD pdwSearchForExtensions, LPDWORD pdwDo404Search)
  298. {
  299. RIP(pdwSearchStyle != NULL);
  300. RIP(pdwSearchForExtensions != NULL);
  301. RIP(pdwDo404Search != NULL);
  302. GetSearchStyle(psp, pdwSearchStyle);
  303. if (*pdwSearchStyle == 0)
  304. {
  305. *pdwSearchForExtensions = NO_SUFFIXES;
  306. *pdwDo404Search = NEVERSEARCH;
  307. }
  308. else
  309. {
  310. *pdwSearchForExtensions = SCAN_SUFFIXES;
  311. *pdwDo404Search = ALWAYSSEARCH;
  312. }
  313. return S_OK;
  314. } // GetSearchKeys
  315. //
  316. // Map error codes to error urls.
  317. //
  318. int EUIndexFromError(DWORD dwError)
  319. {
  320. for (int i = 0; i < ARRAYSIZE(c_aErrorUrls); i++)
  321. {
  322. if (dwError == c_aErrorUrls[i].dwError)
  323. break;
  324. }
  325. ASSERT(i < ARRAYSIZE(c_aErrorUrls));
  326. return i;
  327. }
  328. //
  329. // IsErrorUrl determines if the given url is an internal error page url.
  330. //
  331. BOOL IsErrorUrl(LPCWSTR pwszDisplayName)
  332. {
  333. BOOL fRet = FALSE;
  334. TCHAR szDisplayName[MAX_URL_STRING];
  335. UnicodeToTChar(pwszDisplayName, szDisplayName, ARRAYSIZE(szDisplayName));
  336. //
  337. // First check if the prefix matches.
  338. //
  339. if (0 == StrCmpN(szDisplayName, TEXT("res://"), 6))
  340. {
  341. int iResStart;
  342. // find the resource name part of the URL
  343. // use the fact that the DLL path will be using
  344. // '\' as delimiters while the URL in general
  345. // uses '/'
  346. iResStart = 6;
  347. while (szDisplayName[iResStart] != TEXT('/'))
  348. {
  349. if (szDisplayName[iResStart] == TEXT('\0'))
  350. return fRet;
  351. iResStart++;
  352. }
  353. iResStart++; // get off the '/'
  354. //
  355. // Check each url in order.
  356. //
  357. for (int i = 0; i < ARRAYSIZE(c_aErrorUrls); i++)
  358. {
  359. if (0 == StrCmpN(szDisplayName + iResStart, c_aErrorUrls[i].pszUrl,
  360. lstrlen(c_aErrorUrls[i].pszUrl)))
  361. {
  362. fRet = TRUE;
  363. break;
  364. }
  365. }
  366. }
  367. return fRet;
  368. }
  369. //
  370. // When an http error occurs the server generally returns a page. The
  371. // threshold value this function returns is used to determine if the
  372. // server page is displayed (if the size of the returned page is greater than
  373. // the threshold) or if an internal error page is shown (if the returned page
  374. // is smaller than the threshold).
  375. //
  376. DWORD _GetErrorThreshold(DWORD dwError)
  377. {
  378. DWORD dwRet;
  379. TCHAR szValue[11]; //Should be large enough to hold max dword 4294967295
  380. DWORD cbValue = ARRAYSIZE(szValue);
  381. DWORD cbdwRet = sizeof(dwRet);
  382. DWORD dwType = REG_DWORD;
  383. wnsprintf(szValue, ARRAYSIZE(szValue), TEXT("%d"), dwError);
  384. if (ERROR_SUCCESS != SHRegGetUSValue(REGSTR_PATH_THRESHOLDS, szValue,
  385. &dwType, (LPVOID)&dwRet, &cbdwRet,
  386. FALSE, NULL, 0))
  387. {
  388. dwRet = 512; // hard coded default size if all else fails.
  389. }
  390. return dwRet;
  391. }
  392. void CDocObjectHost::CDOHBindStatusCallback::_RegisterObjectParam(IBindCtx* pbc)
  393. {
  394. // pbc->RegisterObjectParam(L"BindStatusCallback", this);
  395. _fAborted = FALSE;
  396. HRESULT hres = RegisterBindStatusCallback(pbc, this, 0, 0);
  397. BSCMSG3(TEXT("_RegisterObjectParam returned"), hres, this, pbc);
  398. }
  399. void CDocObjectHost::CDOHBindStatusCallback::_RevokeObjectParam(IBindCtx* pbc)
  400. {
  401. // pbc->RevokeObjectParam(L"BindStatusCallback");
  402. HRESULT hres = RevokeBindStatusCallback(pbc, this);
  403. AssertMsg(SUCCEEDED(hres), TEXT("URLMON bug??? RevokeBindStatusCallback failed %x"), hres);
  404. BSCMSG3(TEXT("_RevokeObjectParam returned"), hres, this, pbc);
  405. }
  406. CDocObjectHost::CDOHBindStatusCallback::~CDOHBindStatusCallback()
  407. {
  408. TraceMsg(DM_DEBUGTFRAME, "dtor CDocObjectHost::CBSC %x", this);
  409. if (_pib) {
  410. AssertMsg(0, TEXT("CBSC::~ _pib is %x (this=%x)"), _pib, this);
  411. }
  412. ATOMICRELEASE(_pib);
  413. if (_pbc) {
  414. AssertMsg(0, TEXT("CBSC::~ _pbc is %x (this=%x)"), _pbc, this);
  415. }
  416. ATOMICRELEASE(_pbc);
  417. if (_psvPrev) {
  418. AssertMsg(0, TEXT("CBSC::~ _psvPrev is %x (this=%x)"), _psvPrev, this);
  419. }
  420. ATOMICRELEASE(_psvPrev);
  421. ATOMICRELEASE(_pbscChained);
  422. ATOMICRELEASE(_pnegotiateChained);
  423. if (_hszPostData)
  424. {
  425. GlobalFree(_hszPostData);
  426. _hszPostData = NULL;
  427. }
  428. if (_pszHeaders)
  429. {
  430. LocalFree(_pszHeaders);
  431. _pszHeaders = NULL;
  432. }
  433. if (_pszRedirectedURL)
  434. {
  435. LocalFree(_pszRedirectedURL);
  436. _pszRedirectedURL = NULL;
  437. }
  438. if(_pszCacheFileName)
  439. {
  440. LocalFree(_pszCacheFileName);
  441. _pszCacheFileName = NULL;
  442. }
  443. if (_pszPolicyRefURL)
  444. {
  445. LocalFree(_pszPolicyRefURL);
  446. _pszPolicyRefURL = NULL;
  447. }
  448. if (_pszP3PHeader)
  449. {
  450. LocalFree(_pszP3PHeader);
  451. _pszP3PHeader = NULL;
  452. }
  453. }
  454. HRESULT CDocObjectHost::CDOHBindStatusCallback::QueryInterface(REFIID riid, LPVOID * ppvObj)
  455. {
  456. if (IsEqualIID(riid, IID_IBindStatusCallback) ||
  457. IsEqualIID(riid, IID_IUnknown))
  458. {
  459. *ppvObj = SAFECAST(this, IBindStatusCallback*);
  460. }
  461. else if (IsEqualIID(riid, IID_IHttpNegotiate))
  462. {
  463. *ppvObj = SAFECAST(this, IHttpNegotiate*);
  464. }
  465. else if (IsEqualIID(riid, IID_IAuthenticate))
  466. {
  467. *ppvObj = SAFECAST(this, IAuthenticate*);
  468. }
  469. else if (IsEqualIID(riid, IID_IServiceProvider))
  470. {
  471. *ppvObj = SAFECAST(this, IServiceProvider*);
  472. }
  473. else if (IsEqualIID(riid, IID_IHttpSecurity))
  474. {
  475. *ppvObj = SAFECAST(this, IHttpSecurity*);
  476. }
  477. else if (IsEqualIID(riid, IID_IWindowForBindingUI))
  478. {
  479. *ppvObj = SAFECAST(this, IWindowForBindingUI*);
  480. }
  481. else
  482. {
  483. *ppvObj = NULL;
  484. return E_NOINTERFACE;
  485. }
  486. AddRef();
  487. return NOERROR;
  488. }
  489. ULONG CDocObjectHost::CDOHBindStatusCallback::AddRef(void)
  490. {
  491. CDocObjectHost* pdoh = IToClass(CDocObjectHost, _bsc, this);
  492. return pdoh->AddRef();
  493. }
  494. ULONG CDocObjectHost::CDOHBindStatusCallback::Release(void)
  495. {
  496. CDocObjectHost* pdoh = IToClass(CDocObjectHost, _bsc, this);
  497. return pdoh->Release();
  498. }
  499. void SetBindfFlagsBasedOnAmbient(BOOL fAmbientOffline, DWORD *grfBindf);
  500. #define CP_UCS_2 1200 // Unicode, ISO 10646
  501. #define CP_UCS_2_BIGENDIAN 1201 // Unicode
  502. #define CP_UTF_8 65001
  503. UINT
  504. NavigatableCodePage(UINT cp)
  505. {
  506. return (cp == CP_UCS_2 || cp == CP_UCS_2_BIGENDIAN) ? CP_UTF_8 : cp;
  507. }
  508. HRESULT CDocObjectHost::CDOHBindStatusCallback::GetBindInfo(
  509. DWORD* grfBINDF,
  510. BINDINFO *pbindinfo)
  511. {
  512. if ( !grfBINDF || !pbindinfo || !pbindinfo->cbSize )
  513. return E_INVALIDARG;
  514. DWORD dwConnectedStateFlags = 0;
  515. CDocObjectHost* pdoh = IToClass(CDocObjectHost, _bsc, this);
  516. BSCMSG(TEXT("GetBindInfo"), 0, 0);
  517. *grfBINDF = BINDF_ASYNCHRONOUS;
  518. // Delegation is valid ONLY for the ::GetBindInfo() method
  519. if (_pbscChained) {
  520. CHAINMSG("GetBindInfo", grfBINDF);
  521. _pbscChained->GetBindInfo(grfBINDF, pbindinfo);
  522. DWORD dwFlags = 0;
  523. if (pdoh->_pwb)
  524. {
  525. pdoh->_pwb->GetFlags(&dwFlags);
  526. }
  527. pbindinfo->dwCodePage = (dwFlags & BSF_SETNAVIGATABLECODEPAGE)
  528. ? NavigatableCodePage(pdoh->_uiCP)
  529. : pdoh->_uiCP;
  530. // As far as offline mode is concerned, we want the latest
  531. // info. Over-rule what the delegated IBSC returned
  532. SetBindfFlagsBasedOnAmbient(_bFrameIsOffline, grfBINDF);
  533. if(_bFrameIsSilent)
  534. *grfBINDF |= BINDF_NO_UI;
  535. else
  536. *grfBINDF &= ~BINDF_NO_UI;
  537. }
  538. else
  539. {
  540. // fill out the BINDINFO struct
  541. *grfBINDF = 0;
  542. BuildBindInfo(grfBINDF,pbindinfo,_hszPostData,_cbPostData,
  543. _bFrameIsOffline, _bFrameIsSilent, FALSE, /* bHyperlink */
  544. (IBindStatusCallback *) this);
  545. // HTTP headers are added by the callback to our
  546. // IHttpNegotiate::BeginningTransaction() method
  547. }
  548. // Remember it to perform modeless download for POST case.
  549. _dwBindVerb = pbindinfo->dwBindVerb;
  550. // Remember this to use when populating the threadparams for CDownload.
  551. // (FerhanE): We are only remembering the restricted zone enforcement
  552. // to not break anything that depended on other flags being
  553. // not set before.
  554. _dwBindf = *grfBINDF & BINDF_ENFORCERESTRICTED;
  555. return S_OK;
  556. }
  557. // *** IAuthenticate ***
  558. HRESULT CDocObjectHost::CDOHBindStatusCallback::Authenticate(
  559. HWND *phwnd,
  560. LPWSTR *pszUsername,
  561. LPWSTR *pszPassword)
  562. {
  563. CDocObjectHost* pdoh = IToClass(CDocObjectHost, _bsc, this);
  564. if (!phwnd || !pszUsername || !pszPassword)
  565. return E_POINTER;
  566. if(!_bFrameIsSilent){
  567. if (pdoh->_psb) {
  568. pdoh->_psb->GetWindow(phwnd);
  569. } else {
  570. *phwnd = pdoh->_hwnd;
  571. }
  572. }else{
  573. *phwnd = NULL;
  574. }
  575. *pszUsername = NULL;
  576. *pszPassword = NULL;
  577. // If we're a frame in the active desktop, then find out
  578. // the user name and password are stored with the subscription
  579. // and use it
  580. if(_IsDesktopItem(pdoh))
  581. {
  582. // Get the URL
  583. LPOLESTR pszURL;
  584. HRESULT hres;
  585. hres = pdoh->_GetCurrentPageW(&pszURL, TRUE);
  586. if(SUCCEEDED(hres))
  587. {
  588. IActiveDesktop *pActiveDesk;
  589. hres = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER, IID_IActiveDesktop, (LPVOID*)&pActiveDesk);
  590. if(SUCCEEDED(hres))
  591. {
  592. // Get the subscribed URL for this
  593. COMPONENT Component;
  594. Component.dwSize = SIZEOF(Component);
  595. Component.wszSubscribedURL[0] = TEXT('\0');
  596. hres = pActiveDesk->GetDesktopItemBySource(pszURL, &Component, 0);
  597. if(SUCCEEDED(hres) && Component.wszSubscribedURL[0])
  598. {
  599. // We have a non null subscribed URL
  600. // Gotta find the user name and password
  601. // associated with this subscription
  602. ISubscriptionMgr *pSubsMgr;
  603. hres = CoCreateInstance(CLSID_SubscriptionMgr, NULL,
  604. CLSCTX_INPROC_SERVER,
  605. IID_ISubscriptionMgr, (LPVOID*)&pSubsMgr);
  606. if(SUCCEEDED(hres))
  607. {
  608. SUBSCRIPTIONINFO SubInfo;
  609. SubInfo.cbSize = sizeof(SUBSCRIPTIONINFO);
  610. SubInfo.fUpdateFlags = (SUBSINFO_NEEDPASSWORD | SUBSINFO_TYPE
  611. | SUBSINFO_USER | SUBSINFO_PASSWORD);
  612. SubInfo.bstrUserName = NULL;
  613. SubInfo.bstrPassword = NULL;
  614. hres = pSubsMgr->GetSubscriptionInfo(Component.wszSubscribedURL, &SubInfo);
  615. if(SUCCEEDED(hres) && SubInfo.bNeedPassword)
  616. {
  617. if((SubInfo.bstrUserName) && (SubInfo.bstrPassword))
  618. {
  619. // Copy user name and password
  620. SHStrDupW(SubInfo.bstrPassword, pszPassword);
  621. SHStrDupW(SubInfo.bstrUserName, pszUsername);
  622. }
  623. }
  624. if(SubInfo.bstrPassword)
  625. SysFreeString(SubInfo.bstrPassword);
  626. if(SubInfo.bstrUserName)
  627. SysFreeString(SubInfo.bstrUserName);
  628. pSubsMgr->Release();
  629. }
  630. }
  631. pActiveDesk->Release();
  632. }
  633. OleFree(pszURL);
  634. }
  635. }
  636. return S_OK;
  637. }
  638. // *** IServiceProvider ***
  639. HRESULT CDocObjectHost::CDOHBindStatusCallback::QueryService(REFGUID guidService,
  640. REFIID riid, void **ppvObj)
  641. {
  642. HRESULT hres = E_FAIL;
  643. *ppvObj = NULL;
  644. if (IsEqualGUID(guidService, IID_IAuthenticate)) {
  645. return QueryInterface(riid, ppvObj);
  646. }
  647. else if (IsEqualGUID(guidService, IID_ITargetFrame2))
  648. {
  649. return IToClass(CDocObjectHost, _bsc, this)->QueryService(
  650. guidService,
  651. riid,
  652. ppvObj);
  653. }
  654. else if (_pbscChained)
  655. {
  656. // Has a delegating IBindStatusCallback.
  657. IServiceProvider* psp;
  658. hres = _pbscChained->QueryInterface(IID_IServiceProvider, (LPVOID*)&psp);
  659. if (SUCCEEDED(hres)) {
  660. // It supports ServiceProvider, just delegate.
  661. hres = psp->QueryService(guidService, riid, ppvObj);
  662. psp->Release();
  663. } else if (IsEqualGUID(guidService, riid)) {
  664. // It does not supports ServiceProvide, try QI.
  665. hres = _pbscChained->QueryInterface(riid, ppvObj);
  666. }
  667. }
  668. return hres;
  669. }
  670. HRESULT CDocObjectHost::CDOHBindStatusCallback::OnStartBinding(
  671. DWORD grfBSCOption, IBinding *pib)
  672. {
  673. BSCMSG(TEXT("OnStartBinding"), _pib, pib);
  674. CDocObjectHost* pdoh = IToClass(CDocObjectHost, _bsc, this);
  675. _fBinding = TRUE;
  676. _fDocWriteAbort = FALSE;
  677. _fBoundToMSHTML = FALSE;
  678. ASSERT(pdoh->_pocthf);
  679. // ASSERT(_pib==NULL);
  680. ATOMICRELEASE(_pib);
  681. _pib = pib;
  682. if (_pib) {
  683. _pib->AddRef();
  684. }
  685. #ifndef NO_DELEGATION
  686. if (_pbscChained) {
  687. CHAINMSG("OnStartBinding", grfBSCOption);
  688. _pbscChained->OnStartBinding(grfBSCOption, pib);
  689. }
  690. #endif
  691. pdoh->_fShowProgressCtl = TRUE;
  692. pdoh->_PlaceProgressBar(TRUE);
  693. _privacyQueue.Reset();
  694. ResetPrivacyInfo();
  695. return S_OK;
  696. }
  697. HRESULT CDocObjectHost::CDOHBindStatusCallback::GetPriority(LONG *pnPriority)
  698. {
  699. BSCMSG(TEXT("GetPriority"), 0, 0);
  700. *pnPriority = NORMAL_PRIORITY_CLASS;
  701. #ifndef NO_DELEGATION
  702. if (_pbscChained) {
  703. _pbscChained->GetPriority(pnPriority);
  704. }
  705. #endif
  706. return S_OK;
  707. }
  708. void CDocObjectHost::CDOHBindStatusCallback::ResetPrivacyInfo()
  709. {
  710. _dwPrivacyFlags = 0;
  711. if (_pszPolicyRefURL)
  712. {
  713. LocalFree(_pszPolicyRefURL);
  714. _pszPolicyRefURL = NULL;
  715. }
  716. if (_pszP3PHeader)
  717. {
  718. LocalFree(_pszP3PHeader);
  719. _pszP3PHeader = NULL;
  720. }
  721. }
  722. HRESULT CDocObjectHost::CDOHBindStatusCallback::AddToPrivacyQueue(LPTSTR * ppszUrl,
  723. LPTSTR * ppszPolicyRef,
  724. LPTSTR * ppszP3PHeader,
  725. DWORD dwFlags)
  726. {
  727. CPrivacyRecord *pRecord = new CPrivacyRecord;
  728. if (!pRecord)
  729. {
  730. return E_OUTOFMEMORY;
  731. }
  732. HRESULT hRes = S_OK;
  733. hRes = pRecord->Init(ppszUrl, ppszPolicyRef, ppszP3PHeader, dwFlags);
  734. if (SUCCEEDED(hRes))
  735. _privacyQueue.Queue(pRecord);
  736. else
  737. delete pRecord;
  738. return hRes;
  739. }
  740. HRESULT CDocObjectHost::CDOHBindStatusCallback::BuildRecord()
  741. {
  742. HRESULT hRes = S_OK;
  743. CDocObjectHost* pdoh = NULL;
  744. TCHAR * pszUrl = NULL;
  745. if (_pszRedirectedURL)
  746. {
  747. hRes = AddToPrivacyQueue(&_pszRedirectedURL, &_pszPolicyRefURL, &_pszP3PHeader, _dwPrivacyFlags);
  748. goto cleanup;
  749. }
  750. pdoh = IToClass(CDocObjectHost, _bsc, this);
  751. // Get the current URL to add
  752. pszUrl = new TCHAR[MAX_URL_STRING];
  753. if (!pszUrl)
  754. {
  755. hRes = E_OUTOFMEMORY;
  756. goto cleanup;
  757. }
  758. pszUrl[0] = TEXT('\0');
  759. if (pdoh->_pidl)
  760. {
  761. hRes = IEGetDisplayName(pdoh->_pidl, pszUrl, SHGDN_FORPARSING);
  762. }
  763. else
  764. {
  765. LPOLESTR pwUrl = NULL;
  766. hRes = pdoh->_GetCurrentPageW(&pwUrl, TRUE);
  767. if (SUCCEEDED(hRes))
  768. {
  769. StrCpyN(pszUrl, pwUrl, MAX_URL_STRING);
  770. OleFree(pwUrl);
  771. }
  772. }
  773. hRes = AddToPrivacyQueue(&pszUrl, &_pszPolicyRefURL, &_pszP3PHeader, _dwPrivacyFlags);
  774. cleanup:
  775. if (!SUCCEEDED(hRes))
  776. {
  777. delete [] pszUrl;
  778. }
  779. return hRes;
  780. }
  781. void CDocObjectHost::CDOHBindStatusCallback::_Redirect(LPCWSTR pwzNew)
  782. {
  783. LPITEMIDLIST pidlNew;
  784. WCHAR wszPath[MAX_URL_STRING] = TEXT("");
  785. CDocObjectHost* pdoh = IToClass(CDocObjectHost, _bsc, this);
  786. LPOLESTR pwszCurrent = NULL;
  787. BOOL fAllow = FALSE;
  788. if (SUCCEEDED(IECreateFromPath(pwzNew, &pidlNew))) {
  789. TraceMsg(TF_SHDNAVIGATE, "CDOH::CBSC::_Redirect calling NotifyRedirect(%s)", pwzNew);
  790. if ( pdoh->_pwb )
  791. {
  792. pdoh->_pwb->NotifyRedirect(pdoh->_psv, pidlNew, NULL);
  793. }
  794. // Important - Do this before we destroy the old redirect url
  795. BuildRecord();
  796. ResetPrivacyInfo();
  797. // Save te redirected URL
  798. if (_pszRedirectedURL)
  799. LocalFree( _pszRedirectedURL );
  800. _pszRedirectedURL = StrDup(pwzNew);
  801. // We need to account for a bookmark that might appear
  802. // in the redirected URL.
  803. if(IEILGetFragment(pidlNew, wszPath, SIZECHARS(wszPath))) {
  804. LocalFree((LPVOID) pdoh->_pszLocation);
  805. pdoh->_pszLocation = StrDup(wszPath);
  806. }
  807. ILFree(pidlNew);
  808. }
  809. AddUrlToUrlHistoryStg(pwzNew, NULL, pdoh->_psb, FALSE,
  810. NULL, NULL, NULL);
  811. // Security: Release the pre-created object and start over for
  812. // server-side redirects. The only security check for the
  813. // document reference occurs when someone tries to obtain it.
  814. // Therefore, we want to orphan the reference if x-domain, so the
  815. // client will need to obtain a new reference to the redirected
  816. // document.
  817. if (SUCCEEDED(pdoh->_GetCurrentPageW(&pwszCurrent, TRUE)))
  818. {
  819. fAllow = AccessAllowed(pdoh->_psp, pwszCurrent, pwzNew);
  820. OleFree(pwszCurrent);
  821. }
  822. if (!fAllow)
  823. pdoh->_ReleasePendingObject(FALSE);
  824. }
  825. //
  826. // In this function, we get the codepage for the current URL. If that's not
  827. // CP_ACP, we pass it to Trident via IBindCtx*.
  828. //
  829. void CDocObjectHost::CDOHBindStatusCallback::_CheckForCodePageAndShortcut(void)
  830. {
  831. CDocObjectHost* pdoh = IToClass(CDocObjectHost, _bsc, this);
  832. LPWSTR pwszURL;
  833. HRESULT hres = pdoh->_GetCurrentPageW(&pwszURL, TRUE);
  834. if (SUCCEEDED(hres)) {
  835. UINT codepage = CP_ACP;
  836. IOleCommandTarget *pcmdt;
  837. VARIANT varShortCutPath = {0};
  838. BOOL fHasShortcut = FALSE;
  839. hres = pdoh->QueryService(SID_SHlinkFrame, IID_IOleCommandTarget, (void **)&pcmdt);
  840. if(S_OK == hres)
  841. {
  842. ASSERT(pcmdt);
  843. hres = pcmdt->Exec(&CGID_Explorer, SBCMDID_GETSHORTCUTPATH, 0, NULL, &varShortCutPath);
  844. //
  845. // App Compat: Imagineer Technical returns S_OK for the above Exec
  846. // but of course doesn't set the output parameter.
  847. //
  848. if((S_OK) == hres && VT_BSTR == varShortCutPath.vt && varShortCutPath.bstrVal)
  849. {
  850. fHasShortcut = TRUE;
  851. }
  852. pcmdt->Release();
  853. }
  854. if(UrlHitsNetW(pwszURL))
  855. {
  856. // Don't do this for File: files - we can live
  857. // with getting the code page late for file: even
  858. // if it slows down file: display somewhat if the
  859. // trident parser needs to restarted
  860. AddUrlToUrlHistoryStg(pwszURL, NULL, pdoh->_psb, FALSE,
  861. NULL, NULL, &codepage);
  862. }
  863. TraceMsg(DM_DOCCP, "CDOH::CBSC::_CheckForCodePageAndShortcut codepage=%d", codepage);
  864. if ((codepage != CP_ACP || fHasShortcut) && _pbc) {
  865. // Here is where we pass the codepage to Trident.
  866. // (Mars): Clients may have already registered HtmlLoadOptions with
  867. // the bind context in order to specify the shortcut path. In this case,
  868. // registering it again to set the codepage would fail. However, we should
  869. // first verify that this codepage stuff actually gets used.
  870. IHtmlLoadOptions *phlo;
  871. HRESULT hres = CoCreateInstance(CLSID_HTMLLoadOptions,
  872. NULL, CLSCTX_INPROC_SERVER,
  873. IID_IHtmlLoadOptions, (void**)&phlo);
  874. if (SUCCEEDED(hres) && phlo)
  875. {
  876. if(codepage != CP_ACP)
  877. {
  878. hres = phlo->SetOption(HTMLLOADOPTION_CODEPAGE, &codepage, sizeof(codepage));
  879. }
  880. if (SUCCEEDED(hres))
  881. {
  882. if(fHasShortcut)
  883. {
  884. // deliberately ignore failures here
  885. phlo->SetOption(HTMLLOADOPTION_INETSHORTCUTPATH, varShortCutPath.bstrVal,
  886. (lstrlenW(varShortCutPath.bstrVal) + 1)*sizeof(WCHAR));
  887. }
  888. _pbc->RegisterObjectParam(L"__HTMLLOADOPTIONS", phlo);
  889. }
  890. phlo->Release();
  891. } else {
  892. TraceMsg(DM_WARNING, "DOH::_CheckForCodePagecut CoCreateInst failed (%x)", hres);
  893. }
  894. }
  895. VariantClear(&varShortCutPath);
  896. OleFree(pwszURL);
  897. }
  898. }
  899. #ifdef BETA1_DIALMON_HACK
  900. extern void IndicateWinsockActivity();
  901. #endif // BETA1_DIALMON_HACK
  902. HRESULT CDocObjectHost::CDOHBindStatusCallback::OnProgress(
  903. ULONG ulProgress,
  904. ULONG ulProgressMax,
  905. ULONG ulStatusCode,
  906. LPCWSTR pwzStatusText)
  907. {
  908. HRESULT hr = S_OK;
  909. HRESULT hrPrivacy = S_OK;
  910. TCHAR * pszPrivacyURL = NULL;
  911. static TCHAR * pszNULL = NULL;
  912. TraceMsg(TF_SHDPROGRESS, "DOH::BSC::OnProgress (%d of %d) ulStatus=%x",
  913. ulProgress, ulProgressMax, ulStatusCode);
  914. // JEFFWE 4/15/96 Beta 1 Hack - every once in a while, send message
  915. // to the hidden window that detects inactivity so that it doesn't
  916. // think we are inactive during a long download
  917. #ifdef BETA1_DIALMON_HACK
  918. IndicateWinsockActivity();
  919. #endif
  920. CDocObjectHost * pdoh = IToClass(CDocObjectHost, _bsc, this);
  921. #ifdef DEBUG
  922. if (pwzStatusText)
  923. {
  924. char szStatusText[MAX_PATH]; // OK with MAX_PATH
  925. UnicodeToAnsi(pwzStatusText, szStatusText, ARRAYSIZE(szStatusText));
  926. TraceMsg(TF_SHDPROGRESS, "DOH::BSC::OnProgress pszStatus=%s", szStatusText);
  927. }
  928. #endif
  929. if (pdoh->_psb)
  930. {
  931. // we may be switching between multiple proxy/server hosts, so don't prevent
  932. // showing them when they change
  933. if (_bindst != ulStatusCode ||
  934. ulStatusCode == BINDSTATUS_FINDINGRESOURCE)
  935. {
  936. UINT idRes = IDI_STATE_NORMAL;
  937. _bindst = ulStatusCode;
  938. if (_bindst < ARRAYSIZE(c_aidRes))
  939. idRes = c_aidRes[_bindst];
  940. pdoh->_psb->SendControlMsg(FCW_STATUS, SB_SETICON, STATUS_PANE_NAVIGATION,
  941. (LPARAM)g_ahiconState[idRes-IDI_STATE_FIRST], NULL);
  942. TCHAR szStatusText[MAX_PATH]; // OK with MAX_PATH
  943. if (pwzStatusText)
  944. {
  945. StrCpyN(szStatusText, pwzStatusText, ARRAYSIZE(szStatusText));
  946. }
  947. else
  948. {
  949. szStatusText[0] = TEXT('\0');
  950. }
  951. //
  952. // This if-block will open the safe open dialog for OLE Object
  953. // and DocObject.
  954. //
  955. if (_bindst == BINDSTATUS_CLASSIDAVAILABLE)
  956. {
  957. TraceMsg(TF_SHDPROGRESS, "DOH::BSC::OnProgress got CLSID=%ws", szStatusText);
  958. CLSID clsid;
  959. // WORK-AROUND: CLSIDFromString does not take LPCOLESTR correctly.
  960. HRESULT hresT = CLSIDFromString((LPOLESTR)pwzStatusText, &clsid);
  961. if (SUCCEEDED(hresT))
  962. {
  963. #ifdef DEBUG
  964. if (IsEqualGUID(clsid, CLSID_NULL))
  965. {
  966. TraceMsg(DM_WARNING, "DOH::SBC::OnProgress Got CLSID_NULL");
  967. }
  968. #endif
  969. //
  970. // Notice that we don't want to use BROWSERFLAG_MSHTML,
  971. // which includes other types of MSHMTL CLSIDs.
  972. // In this case, we just want to deal with HTMLDocument.
  973. // (We allow XMLViewer docobj and *.MHT and *.MHTML too!)
  974. BOOL fIsHTML = (IsEqualGUID(clsid, CLSID_HTMLDocument) ||
  975. IsEqualGUID(clsid, CLSID_XMLViewerDocObj) ||
  976. IsEqualGUID(clsid, CLSID_MHTMLDocument));
  977. BOOL fAbortDesktopComponent = FALSE;
  978. if(!fIsHTML)
  979. {
  980. //Check if we are a desktop component.
  981. if (_IsDesktopItem(pdoh))
  982. {
  983. //Because this is NOT html, then don't show it!
  984. fAbortDesktopComponent = TRUE;
  985. }
  986. }
  987. if (fAbortDesktopComponent)
  988. {
  989. AbortBinding();
  990. hr = E_ABORT;
  991. }
  992. else
  993. {
  994. _fBoundToMSHTML = fIsHTML; // Remember this and suppress redundant
  995. // AddUrl to history
  996. // There is an interval of time between OnProgress and OnObjectAvailable
  997. // in which the om might be required.
  998. if (fIsHTML && pdoh->_punkPending == NULL)
  999. {
  1000. pdoh->_CreatePendingDocObject(FALSE);
  1001. }
  1002. if (pdoh->_punkPending)
  1003. {
  1004. IPersist *pip;
  1005. hresT = pdoh->_punkPending->QueryInterface(IID_IPersist, (LPVOID *) &pip);
  1006. if (SUCCEEDED(hresT))
  1007. {
  1008. CLSID clsidPending;
  1009. hresT = pip->GetClassID(&clsidPending);
  1010. if (SUCCEEDED(hresT) && IsEqualGUID(clsid, clsidPending))
  1011. {
  1012. _pbc->RegisterObjectParam(L"__PrecreatedObject", pdoh->_punkPending);
  1013. }
  1014. pip->Release();
  1015. }
  1016. }
  1017. hresT = pdoh->_MayHaveVirus(clsid);
  1018. if (hresT == HRESULT_FROM_WIN32(ERROR_CANCELLED))
  1019. {
  1020. hr = E_ABORT;
  1021. AbortBinding();
  1022. if (pdoh->_pmsoctBrowser && pdoh->_fWindowOpen)
  1023. {
  1024. pdoh->_pmsoctBrowser->Exec(&CGID_Explorer, SBCMDID_CANCELANDCLOSE, 0, NULL, NULL);
  1025. }
  1026. }
  1027. }
  1028. }
  1029. else
  1030. {
  1031. TraceMsg(DM_ERROR, "DOH::BSC::OnProgress CLSIDFromString failed %x", hresT);
  1032. }
  1033. //
  1034. // Notice that URLMON will call IPersistMoniker::Load right
  1035. // after we return from this notification. Therefore, this
  1036. // is the latest moment we have a chance to pass the code
  1037. // page to Trident.
  1038. //
  1039. _CheckForCodePageAndShortcut();
  1040. }
  1041. else if (_bindst == BINDSTATUS_CACHEFILENAMEAVAILABLE)
  1042. {
  1043. TraceMsg(DM_SELFASC, "DOH::OnProgress got BINDSTATUS_CACHEFILENAMEAVAILABLE");
  1044. _fSelfAssociated = IsAssociatedWithIE(pwzStatusText);
  1045. if(_pszCacheFileName)
  1046. LocalFree(_pszCacheFileName);
  1047. _pszCacheFileName = StrDup(pwzStatusText);
  1048. }
  1049. else if (_bindst == BINDSTATUS_CONTENTDISPOSITIONATTACH)
  1050. {
  1051. TCHAR szURL[MAX_URL_STRING];
  1052. TCHAR * pszURL = szURL;
  1053. HRESULT hresT;
  1054. hresT = pdoh->_GetCurrentPage(szURL, ARRAYSIZE(szURL), TRUE);
  1055. if (SUCCEEDED(hresT))
  1056. {
  1057. UINT uRet;
  1058. if (_pszRedirectedURL && lstrlen(_pszRedirectedURL))
  1059. {
  1060. pszURL = _pszRedirectedURL;
  1061. }
  1062. IUnknown * punk;
  1063. hresT = pdoh->QueryInterface(IID_IUnknown, (void**)&punk);
  1064. if (SUCCEEDED(hresT))
  1065. {
  1066. uRet = OpenSafeOpenDialog(pdoh->_hwnd, DLG_SAFEOPEN, NULL, pszURL, NULL, szStatusText, NULL, pdoh->_uiCP, punk);
  1067. switch(uRet)
  1068. {
  1069. case IDOK:
  1070. //
  1071. // Set this flag to avoid poppping this dialog box twice.
  1072. //
  1073. pdoh->_fConfirmed = TRUE;
  1074. break; // continue download
  1075. case IDD_SAVEAS:
  1076. CDownLoad_OpenUI(pdoh->_pmkCur, _pbc, FALSE, TRUE, NULL, NULL, NULL, NULL, NULL, _pszRedirectedURL, pdoh->_uiCP, punk);
  1077. ATOMICRELEASE(_pbc);
  1078. ATOMICRELEASE(_psvPrev);
  1079. // fall thru to AbortBinding
  1080. case IDCANCEL:
  1081. pdoh->_CancelPendingNavigation(FALSE);
  1082. AbortBinding();
  1083. if (uRet == IDCANCEL)
  1084. {
  1085. _fAborted = TRUE;
  1086. }
  1087. break;
  1088. }
  1089. punk->Release();
  1090. }
  1091. }
  1092. }
  1093. if ( ( _bindst >= BINDSTATUS_FINDINGRESOURCE
  1094. && _bindst <= BINDSTATUS_SENDINGREQUEST)
  1095. || _bindst == BINDSTATUS_PROXYDETECTING)
  1096. {
  1097. TCHAR szTemplate[MAX_PATH]; // OK with MAX_PATH
  1098. UINT idResource = IDS_BINDSTATUS+_bindst;
  1099. if ( _bindst == BINDSTATUS_PROXYDETECTING )
  1100. {
  1101. idResource = IDS_BINDSTATUS_PROXYDETECTING;
  1102. }
  1103. // If we are connecting over proxy, don't say "web site found".
  1104. //
  1105. if (fOnProxy() && idResource == IDS_BINDSTATUS_SEND)
  1106. {
  1107. idResource = IDS_BINDSTATUS_CON;
  1108. TCHAR szUrl[MAX_URL_STRING];
  1109. pdoh->_GetCurrentPage(szUrl, SIZECHARS(szUrl));
  1110. DWORD cchStatusText = SIZECHARS(szStatusText);
  1111. UrlGetPart(szUrl, szStatusText, &cchStatusText, URL_PART_HOSTNAME, 0);
  1112. }
  1113. if (MLLoadString(idResource, szTemplate, ARRAYSIZE(szTemplate)))
  1114. {
  1115. BSCMSGS("OnProgress szTemplate=", szTemplate);
  1116. TCHAR szMessage[MAX_PATH]; // OK with MAX_PATH
  1117. BOOL fSuccess = wnsprintf(szMessage, ARRAYSIZE(szMessage), szTemplate, szStatusText);
  1118. if (fSuccess)
  1119. {
  1120. BSCMSGS("OnProgress szMessage=", szMessage);
  1121. pdoh->_SetStatusText(szMessage);
  1122. }
  1123. }
  1124. }
  1125. }
  1126. DWORD dwState = 0;
  1127. switch (ulStatusCode)
  1128. {
  1129. case BINDSTATUS_REDIRECTING:
  1130. // they're redirecting. treat this as a rename.
  1131. _Redirect(pwzStatusText);
  1132. break;
  1133. case BINDSTATUS_FINDINGRESOURCE:
  1134. dwState = PROGRESS_FINDING;
  1135. ASSERT(!ulProgressMax);
  1136. break;
  1137. case BINDSTATUS_SENDINGREQUEST:
  1138. dwState = PROGRESS_SENDING;
  1139. ASSERT(!ulProgressMax);
  1140. break;
  1141. //Handle privacy notifications
  1142. case BINDSTATUS_COOKIE_SENT:
  1143. BSCMSG(TEXT("OnProgress - Received BINDSTATUS_COOKIE_SENT"), 0 ,0);
  1144. if (pwzStatusText && *pwzStatusText)
  1145. {
  1146. pszPrivacyURL = new TCHAR[MAX_URL_STRING];
  1147. if (!pszPrivacyURL)
  1148. break;
  1149. StrCpyN(pszPrivacyURL, pwzStatusText, MAX_URL_STRING);
  1150. hrPrivacy = AddToPrivacyQueue(&pszPrivacyURL, &pszNULL, &pszNULL, COOKIEACTION_READ);
  1151. if (!SUCCEEDED(hrPrivacy))
  1152. delete [] pszPrivacyURL;
  1153. }
  1154. else
  1155. {
  1156. _dwPrivacyFlags |= COOKIEACTION_READ;
  1157. }
  1158. break;
  1159. case BINDSTATUS_COOKIE_SUPPRESSED:
  1160. BSCMSG(TEXT("OnProgress - Received BINDSTATUS_COOKIE_SUPPRESSED"), 0, 0);
  1161. if (pwzStatusText && *pwzStatusText)
  1162. {
  1163. pszPrivacyURL = new TCHAR[MAX_URL_STRING];
  1164. if (!pszPrivacyURL)
  1165. break;
  1166. StrCpyN(pszPrivacyURL, pwzStatusText, MAX_URL_STRING);
  1167. hrPrivacy = AddToPrivacyQueue(&pszPrivacyURL, &pszNULL, &pszNULL, COOKIEACTION_SUPPRESS);
  1168. if (!SUCCEEDED(hrPrivacy))
  1169. delete [] pszPrivacyURL;
  1170. }
  1171. else
  1172. {
  1173. _dwPrivacyFlags |= COOKIEACTION_SUPPRESS;
  1174. }
  1175. break;
  1176. case BINDSTATUS_COOKIE_STATE_UNKNOWN:
  1177. BSCMSG(TEXT("Shdocvw should never BINDSTATUS_COOKIE_STATE_UNKNOWN from Wininet/Urlmon"), 0, 0);
  1178. break;
  1179. case BINDSTATUS_COOKIE_STATE_ACCEPT:
  1180. BSCMSG(TEXT("OnProgress - Received BINDSTATUS_COOKIE_STATE_ACCEPT"), 0, 0);
  1181. if (pwzStatusText && *pwzStatusText)
  1182. {
  1183. pszPrivacyURL = new TCHAR[MAX_URL_STRING];
  1184. if (!pszPrivacyURL)
  1185. break;
  1186. StrCpyN(pszPrivacyURL, pwzStatusText, MAX_URL_STRING);
  1187. hrPrivacy = AddToPrivacyQueue(&pszPrivacyURL, &pszNULL, &pszNULL, COOKIEACTION_ACCEPT);
  1188. if (!SUCCEEDED(hrPrivacy))
  1189. delete [] pszPrivacyURL;
  1190. }
  1191. else
  1192. {
  1193. _dwPrivacyFlags |= COOKIEACTION_ACCEPT;
  1194. }
  1195. break;
  1196. case BINDSTATUS_COOKIE_STATE_REJECT:
  1197. BSCMSG(TEXT("OnProgress - Received BINDSTATUS_COOKIE_STATE_REJECT"), 0, 0);
  1198. if (pwzStatusText && *pwzStatusText)
  1199. {
  1200. pszPrivacyURL = new TCHAR[MAX_URL_STRING];
  1201. if (!pszPrivacyURL)
  1202. break;
  1203. StrCpyN(pszPrivacyURL, pwzStatusText, MAX_URL_STRING);
  1204. hrPrivacy = AddToPrivacyQueue(&pszPrivacyURL, &pszNULL, &pszNULL, COOKIEACTION_REJECT);
  1205. if (!SUCCEEDED(hrPrivacy))
  1206. delete [] pszPrivacyURL;
  1207. }
  1208. else
  1209. {
  1210. _dwPrivacyFlags |= COOKIEACTION_REJECT;
  1211. }
  1212. break;
  1213. case BINDSTATUS_COOKIE_STATE_PROMPT:
  1214. BSCMSG(TEXT("Shdocvw should never BINDSTATUS_COOKIE_STATE_PROMPT from Wininet/Urlmon"), 0, 0);
  1215. break;
  1216. case BINDSTATUS_COOKIE_STATE_LEASH:
  1217. BSCMSG(TEXT("OnProgress - Received BINDSTATUS_COOKIE_STATE_LEASH"), 0, 0);
  1218. if (pwzStatusText && *pwzStatusText)
  1219. {
  1220. pszPrivacyURL = new TCHAR[MAX_URL_STRING];
  1221. if (!pszPrivacyURL)
  1222. break;
  1223. StrCpyN(pszPrivacyURL, pwzStatusText, MAX_URL_STRING);
  1224. hrPrivacy = AddToPrivacyQueue(&pszPrivacyURL, &pszNULL, &pszNULL, COOKIEACTION_LEASH);
  1225. if (!SUCCEEDED(hrPrivacy))
  1226. delete [] pszPrivacyURL;
  1227. }
  1228. else
  1229. {
  1230. _dwPrivacyFlags |= COOKIEACTION_LEASH;
  1231. }
  1232. break;
  1233. case BINDSTATUS_COOKIE_STATE_DOWNGRADE:
  1234. BSCMSG(TEXT("OnProgress - Received BINDSTATUS_COOKIE_STATE_DOWNGRADE"), 0, 0);
  1235. if (pwzStatusText && *pwzStatusText)
  1236. {
  1237. pszPrivacyURL = new TCHAR[MAX_URL_STRING];
  1238. if (!pszPrivacyURL)
  1239. break;
  1240. StrCpyN(pszPrivacyURL, pwzStatusText, MAX_URL_STRING);
  1241. hrPrivacy = AddToPrivacyQueue(&pszPrivacyURL, &pszNULL, &pszNULL, COOKIEACTION_DOWNGRADE);
  1242. if (!SUCCEEDED(hrPrivacy))
  1243. delete [] pszPrivacyURL;
  1244. }
  1245. else
  1246. {
  1247. _dwPrivacyFlags |= COOKIEACTION_DOWNGRADE;
  1248. }
  1249. break;
  1250. case BINDSTATUS_COMPACT_POLICY_RECEIVED:
  1251. _dwPrivacyFlags |= PRIVACY_URLHASCOMPACTPOLICY;
  1252. break;
  1253. case BINDSTATUS_POLICY_HREF:
  1254. BSCMSG(TEXT("OnProgress - Received BINDSTATUS_POLICY_HREF"), 0, 0);
  1255. ASSERT(pwzStatusText && *pwzStatusText);
  1256. // We are getting two notifications from urlmon, once that is fixed, need to uncomment this assert
  1257. //ASSERT(!_pszPolicyRefURL);
  1258. if (_pszPolicyRefURL)
  1259. {
  1260. LocalFree(_pszPolicyRefURL);
  1261. }
  1262. _pszPolicyRefURL = StrDup(pwzStatusText);
  1263. _dwPrivacyFlags |= PRIVACY_URLHASPOLICYREFHEADER;
  1264. break;
  1265. case BINDSTATUS_P3P_HEADER:
  1266. BSCMSG(TEXT("OnProgress - Received BINDSTATUS_P3P_HEADER"), 0, 0);
  1267. ASSERT(pwzStatusText && *pwzStatusText);
  1268. // We are getting two notifications from urlmon, once that is fixed, need to uncomment this assert
  1269. //ASSERT(!_pszP3PHeader);
  1270. if (_pszP3PHeader)
  1271. {
  1272. LocalFree(_pszP3PHeader);
  1273. }
  1274. _pszP3PHeader = StrDup(pwzStatusText);
  1275. _dwPrivacyFlags |= PRIVACY_URLHASP3PHEADER;
  1276. break;
  1277. }
  1278. if (dwState)
  1279. {
  1280. pdoh->_OnSetProgressPos(ulProgress, dwState);
  1281. }
  1282. if (BINDSTATUS_BEGINDOWNLOADDATA == ulStatusCode)
  1283. {
  1284. _cbContentLength = ulProgress;
  1285. }
  1286. else if (BINDSTATUS_MIMETYPEAVAILABLE == ulStatusCode)
  1287. {
  1288. // delegate to media bar if this is a media mime-type
  1289. if ( pwzStatusText
  1290. && ( !StrCmpNIW(pwzStatusText, _T("audio"), 5)
  1291. || !StrCmpNIW(pwzStatusText, _T("video"), 5)))
  1292. {
  1293. if (pdoh->_DelegateToMediaBar(NULL, pwzStatusText))
  1294. {
  1295. // Cancel the navigation
  1296. pdoh->_CancelPendingNavigation(FALSE);
  1297. AbortBinding();
  1298. _fAborted = TRUE;
  1299. if (pdoh->_pwb)
  1300. {
  1301. pdoh->_pwb->SetNavigateState(BNS_NORMAL);
  1302. }
  1303. }
  1304. }
  1305. }
  1306. }
  1307. #ifndef NO_DELEGATION
  1308. if (_pbscChained)
  1309. {
  1310. _pbscChained->OnProgress(ulProgress, ulProgressMax, ulStatusCode, pwzStatusText);
  1311. }
  1312. #endif
  1313. return hr;
  1314. }
  1315. HRESULT CDocObjectHost::CDOHBindStatusCallback::OnDataAvailable(
  1316. /* [in] */ DWORD grfBSC,
  1317. /* [in] */ DWORD dwSize,
  1318. /* [in] */ FORMATETC *pformatetc,
  1319. /* [in] */ STGMEDIUM *pstgmed)
  1320. {
  1321. BSCMSG(TEXT("OnDataAvailable (grf,pstg)"), grfBSC, pstgmed);
  1322. #ifndef NO_DELEGATION
  1323. if (_pbscChained)
  1324. {
  1325. _pbscChained->OnDataAvailable(grfBSC, dwSize, pformatetc, pstgmed);
  1326. }
  1327. #endif
  1328. return S_OK;
  1329. }
  1330. void CDocObjectHost::CDOHBindStatusCallback::_UpdateSSLIcon(void)
  1331. {
  1332. CDocObjectHost* pdoh = IToClass(CDocObjectHost, _bsc, this);
  1333. ASSERT(_pib);
  1334. //
  1335. // if we have already been set by our object, we dont
  1336. // want to override it.
  1337. if (_pib && !pdoh->_fSetSecureLock)
  1338. {
  1339. pdoh->_eSecureLock = SECURELOCK_SET_UNSECURE;
  1340. IWinInetInfo* pwinet;
  1341. HRESULT hresT = _pib->QueryInterface(IID_IWinInetInfo, (LPVOID*)&pwinet);
  1342. if (SUCCEEDED(hresT))
  1343. {
  1344. DWORD dwOptions = 0;
  1345. DWORD cbSize = SIZEOF(dwOptions);
  1346. hresT = pwinet->QueryOption(INTERNET_OPTION_SECURITY_FLAGS,
  1347. (LPVOID)&dwOptions, &cbSize);
  1348. TraceMsg(DM_SSL, "pwinet->QueryOptions hres=%x dwOptions=%x", hresT, dwOptions);
  1349. if (SUCCEEDED(hresT))
  1350. {
  1351. LPWSTR pwzUrl;
  1352. pdoh->_fSetSecureLock = TRUE;
  1353. if(dwOptions & SECURITY_FLAG_SECURE)
  1354. {
  1355. pdoh->_dwSecurityStatus = dwOptions;
  1356. if (pdoh->_dwSecurityStatus & SECURITY_FLAG_40BIT)
  1357. {
  1358. pdoh->_eSecureLock = SECURELOCK_SET_SECURE40BIT;
  1359. }
  1360. else if (pdoh->_dwSecurityStatus & SECURITY_FLAG_128BIT)
  1361. {
  1362. pdoh->_eSecureLock = SECURELOCK_SET_SECURE128BIT;
  1363. }
  1364. else if (pdoh->_dwSecurityStatus & SECURITY_FLAG_FORTEZZA)
  1365. {
  1366. pdoh->_eSecureLock = SECURELOCK_SET_FORTEZZA;
  1367. }
  1368. else if (pdoh->_dwSecurityStatus & SECURITY_FLAG_56BIT)
  1369. {
  1370. pdoh->_eSecureLock = SECURELOCK_SET_SECURE56BIT;
  1371. }
  1372. }
  1373. else if (SUCCEEDED(_GetRequestFlagFromPIB(_pib, &dwOptions)) &&
  1374. (dwOptions & INTERNET_REQFLAG_FROM_CACHE) &&
  1375. SUCCEEDED(pdoh->_GetCurrentPageW(&pwzUrl, TRUE)))
  1376. {
  1377. //
  1378. // when secure pages are cached, they lose their
  1379. // security context, but should still be displayed
  1380. // as secure. therefore we use the UnknownBit level
  1381. // of security.
  1382. //
  1383. if(URL_SCHEME_HTTPS == GetUrlSchemeW(pwzUrl))
  1384. pdoh->_eSecureLock = SECURELOCK_SET_SECUREUNKNOWNBIT;
  1385. OleFree(pwzUrl);
  1386. }
  1387. }
  1388. else
  1389. {
  1390. pdoh->_dwSecurityStatus = 0;
  1391. }
  1392. // we will update the browser when we are activated
  1393. pwinet->Release();
  1394. }
  1395. else
  1396. {
  1397. TraceMsg(DM_SSL, "QI to IWinInetInfo failed");
  1398. }
  1399. TraceMsg(DM_SSL, "[%X] UpdateSslIcon() setting _eSecureLock = %d", pdoh, pdoh->_eSecureLock);
  1400. }
  1401. else
  1402. {
  1403. TraceMsg(DM_SSL, "[%X] UpdateSslIcon() already set _eSecureLock = %d", pdoh, pdoh->_eSecureLock);
  1404. }
  1405. }
  1406. HRESULT CDocObjectHost::CDOHBindStatusCallback::OnObjectAvailable(
  1407. /* [in] */ REFIID riid,
  1408. /* [iid_is][in] */ IUnknown *punk)
  1409. {
  1410. BSCMSG(TEXT("OnObjectAvailable (riid,punk)"), riid, punk);
  1411. CDocObjectHost * pdoh = IToClass(CDocObjectHost, _bsc, this);
  1412. #ifdef DEBUG
  1413. extern DWORD g_dwPerf;
  1414. PERFMSG(TEXT("OnObjectAvailable called"), GetCurrentTime()-g_dwPerf);
  1415. g_dwPerf = GetCurrentTime();
  1416. #endif
  1417. // If we get this far, DocObject has been inited by UrlMon or
  1418. // in process of retrieving pending object via IOleCommandTarget::Exec()
  1419. if (pdoh->_punkPending)
  1420. {
  1421. pdoh->_fPendingNeedsInit = 0;
  1422. }
  1423. //
  1424. // When this notification is called first time, we should ask
  1425. // the browser to activate us (which causes BindToObject).
  1426. //
  1427. if (pdoh->_pole==NULL && punk)
  1428. {
  1429. HRESULT hresT = punk->QueryInterface(IID_IOleObject, (LPVOID*)&(pdoh->_pole));
  1430. if (SUCCEEDED(hresT))
  1431. {
  1432. IOleDocument * pmsod = NULL;
  1433. pdoh->_OnBound(S_OK);
  1434. hresT = (pdoh->_fDontInPlaceNavigate() ? E_NOINTERFACE : punk->QueryInterface(IID_IOleDocument, (LPVOID*)&pmsod));
  1435. if (SUCCEEDED(hresT))
  1436. {
  1437. pmsod->Release(); // We don't use it at this point.
  1438. // Case 1: DocObject
  1439. OPENMSG(TEXT("OnObjectAvailable ASYNC DocObject"));
  1440. ASSERT(pdoh->_psb);
  1441. if (pdoh->_pmsoctBrowser)
  1442. {
  1443. VARIANT var = {0};
  1444. VARIANT varOut = {0};
  1445. // Tell the host that we know this is a document object.
  1446. V_VT(&var) = VT_BOOL;
  1447. V_BOOL(&var) = VARIANT_TRUE;
  1448. pdoh->_pmsoctBrowser->Exec(&CGID_ShellDocView, SHDVID_FIREFILEDOWNLOAD, 0, &var, &varOut);
  1449. }
  1450. #ifdef FEATURE_PICS
  1451. BOOL fSupportsPICS = FALSE;
  1452. if (pdoh->_PicsProcBase._fbPicsWaitFlags)
  1453. {
  1454. VARIANTARG v;
  1455. v.vt = VT_UNKNOWN;
  1456. v.byref = (LPVOID)(IOleCommandTarget *)&pdoh->_PicsProcBase;
  1457. hresT = IUnknown_Exec(pdoh->_pole, &CGID_ShellDocView, SHDVID_CANSUPPORTPICS, 0, &v, NULL);
  1458. if (hresT == S_OK)
  1459. {
  1460. BSCMSG(TEXT("OnObjectAvailable - obj supports PICS"), 0, 0);
  1461. fSupportsPICS = TRUE;
  1462. }
  1463. else
  1464. {
  1465. BSCMSG(TEXT("OnObjectAvailable - obj either doesn't support IOleCommandTarget or doesn't support PICS"), hresT, 0);
  1466. }
  1467. }
  1468. #endif
  1469. BSCMSG(TEXT("OnObjectAvailable calling pdoh->_Navigate"), 0, 0);
  1470. pdoh->_SetUpTransitionCapability();
  1471. _UpdateSSLIcon();
  1472. #ifdef FEATURE_PICS
  1473. // If we can't get labels out of the document (or don't need
  1474. // to, because we already got one from a bureau or HTTP header),
  1475. // see if we can complete PICS checking now.
  1476. //
  1477. if (!fSupportsPICS)
  1478. {
  1479. pdoh->_PicsProcBase._fbPicsWaitFlags &= ~(PICS_WAIT_FOR_INDOC | PICS_WAIT_FOR_END); /* no indoc ratings */
  1480. if (!pdoh->_PicsProcBase._fbPicsWaitFlags)
  1481. {
  1482. TraceMsg(DM_PICS, "OnObjectAvailable calling _HandlePicsChecksComplete");
  1483. pdoh->_PicsProcBase._HandlePicsChecksComplete();
  1484. }
  1485. }
  1486. #endif
  1487. }
  1488. else
  1489. {
  1490. // Case 2: OLE object
  1491. OPENMSG(TEXT("OnDataAvailable ASYNC OLE Object"));
  1492. pdoh->_ActivateOleObject();
  1493. // We need to tell the browser not to add this one to the
  1494. // browse history.
  1495. // We also want to close the browser window if this is the first
  1496. // download - that's why we pass TRUE - to treat it like a code
  1497. // download
  1498. //
  1499. if (pdoh->_dwAppHack & BROWSERFLAG_DONTAUTOCLOSE)
  1500. {
  1501. pdoh->_CancelPendingNavigation(FALSE);
  1502. }
  1503. else
  1504. {
  1505. pdoh->_CancelPendingNavigation(TRUE, FALSE, FALSE, TRUE);
  1506. }
  1507. if (pdoh->_fDelegatedNavigation)
  1508. {
  1509. VARIANT varOut = {0};
  1510. IDocNavigate * pDocNavigate;
  1511. pdoh->_pmsoctBrowser->Exec(&CGID_ShellDocView,
  1512. SHDVID_FIREFILEDOWNLOAD,
  1513. 0, NULL, &varOut);
  1514. HRESULT hr = E_FAIL;
  1515. if ( pdoh->_pwb )
  1516. {
  1517. hr = pdoh->_pwb->QueryInterface(IID_PPV_ARG(IDocNavigate, &pDocNavigate));
  1518. }
  1519. if (S_OK == hr)
  1520. {
  1521. pDocNavigate->OnReadyStateChange(NULL, READYSTATE_COMPLETE);
  1522. pDocNavigate->Release();
  1523. }
  1524. }
  1525. //
  1526. // If this is the very first page, we should draw the background.
  1527. //
  1528. pdoh->_fDrawBackground = TRUE;
  1529. //If the following assert is hit, then that means that we are
  1530. // going to invalidate the desktop window (which is not
  1531. // intended here)
  1532. //
  1533. ASSERT(pdoh->_hwnd);
  1534. InvalidateRect(pdoh->_hwnd, NULL, TRUE);
  1535. }
  1536. }
  1537. else
  1538. {
  1539. _fBoundToNoOleObject = TRUE;
  1540. }
  1541. }
  1542. // Add privacy info to Trident's list if possible
  1543. if (_fBoundToMSHTML)
  1544. {
  1545. HRESULT hRes = E_FAIL;
  1546. IServiceProvider * pSP = NULL;
  1547. IPrivacyServices * pPrivacyServices = NULL;
  1548. DWORD dwTopLevelFlag = 0;
  1549. // QueryService the Trident for the IPrivacyServices interface
  1550. hRes = pdoh->_pole->QueryInterface(IID_IServiceProvider, (void**)&pSP);
  1551. if (SUCCEEDED(hRes) && pSP)
  1552. {
  1553. hRes = pSP->QueryService(IID_IPrivacyServices,IID_IPrivacyServices,(void**)&pPrivacyServices);
  1554. pSP->Release();
  1555. }
  1556. if (pPrivacyServices)
  1557. {
  1558. if (pdoh->_psp && pdoh->_psb && IsTopFrameBrowser(pdoh->_psp, pdoh->_psb))
  1559. {
  1560. dwTopLevelFlag |= PRIVACY_URLISTOPLEVEL;
  1561. }
  1562. // Add dummy marker since Trident would have added its records during the BindToStorage call
  1563. // initiated due to shdocvw's current bind only if we are top level
  1564. if (dwTopLevelFlag)
  1565. pPrivacyServices->AddPrivacyInfoToList( TEXT(""), NULL, NULL, 0, PRIVACY_URLISTOPLEVEL);
  1566. // Add each item in the privacy queue (accumulated from redirections) to Trident's list
  1567. CPrivacyRecord *pPrivacyRecord = _privacyQueue.Dequeue();
  1568. if (pPrivacyRecord)
  1569. {
  1570. while (pPrivacyRecord)
  1571. {
  1572. pPrivacyRecord->_dwPrivacyFlags |= dwTopLevelFlag;
  1573. pPrivacyServices->AddPrivacyInfoToList( pPrivacyRecord->_pszUrl, pPrivacyRecord->_pszPolicyRefUrl, pPrivacyRecord->_pszP3PHeader,
  1574. 0, pPrivacyRecord->_dwPrivacyFlags);
  1575. delete pPrivacyRecord;
  1576. // Add the dummy marker separating top level records if this is top level
  1577. if (dwTopLevelFlag)
  1578. pPrivacyServices->AddPrivacyInfoToList( TEXT(""), NULL, NULL, 0, PRIVACY_URLISTOPLEVEL);
  1579. pPrivacyRecord = _privacyQueue.Dequeue();
  1580. }
  1581. // Add the last one redirected url from the class itself since this was not added to the list
  1582. _dwPrivacyFlags |= dwTopLevelFlag;
  1583. pPrivacyServices->AddPrivacyInfoToList(_pszRedirectedURL, _pszPolicyRefURL, _pszP3PHeader, 0, _dwPrivacyFlags);
  1584. }
  1585. else
  1586. {
  1587. TCHAR szUrl[MAX_URL_STRING];
  1588. szUrl[0] = TEXT('\0');
  1589. // Get the url used for binding
  1590. if (pdoh->_pidl)
  1591. {
  1592. hRes = IEGetDisplayName(pdoh->_pidl, szUrl, SHGDN_FORPARSING);
  1593. }
  1594. else
  1595. {
  1596. LPOLESTR pwUrl = NULL;
  1597. hRes = pdoh->_GetCurrentPageW(&pwUrl, TRUE);
  1598. if (SUCCEEDED(hRes))
  1599. {
  1600. StrCpyN(szUrl, pwUrl, ARRAYSIZE(szUrl));
  1601. OleFree(pwUrl);
  1602. }
  1603. }
  1604. if (SUCCEEDED(hRes))
  1605. {
  1606. _dwPrivacyFlags |= dwTopLevelFlag;
  1607. pPrivacyServices->AddPrivacyInfoToList(szUrl, _pszPolicyRefURL, _pszP3PHeader, 0, _dwPrivacyFlags);
  1608. }
  1609. }
  1610. pPrivacyServices->Release();
  1611. }
  1612. }
  1613. #ifndef NO_DELEGATION
  1614. if (_pbscChained)
  1615. {
  1616. _pbscChained->OnObjectAvailable(riid, punk);
  1617. }
  1618. #endif
  1619. return S_OK;
  1620. }
  1621. HRESULT CDocObjectHost::CDOHBindStatusCallback::OnLowResource(DWORD reserved)
  1622. {
  1623. BSCMSG(TEXT("OnLowResource"), 0, 0);
  1624. #ifndef NO_DELEGATION
  1625. if (_pbscChained) {
  1626. _pbscChained->OnLowResource(reserved);
  1627. }
  1628. #endif
  1629. return S_OK;
  1630. }
  1631. HRESULT CDocObjectHost::CDOHBindStatusCallback::BeginningTransaction(LPCWSTR szURL, LPCWSTR szHeaders,
  1632. DWORD dwReserved, LPWSTR __RPC_FAR * ppwzAdditionalHeaders)
  1633. {
  1634. HRESULT hres;
  1635. #ifndef NO_DELEGATION
  1636. if (_pnegotiateChained) {
  1637. hres = _pnegotiateChained->BeginningTransaction(szURL, szHeaders, dwReserved, ppwzAdditionalHeaders);
  1638. }
  1639. else
  1640. {
  1641. #endif
  1642. // Here we pass headers to URLMon
  1643. hres=BuildAdditionalHeaders((LPCTSTR) _pszHeaders,(LPCWSTR *) ppwzAdditionalHeaders);
  1644. #ifndef NO_DELEGATION
  1645. }
  1646. #endif
  1647. return hres;
  1648. }
  1649. const WCHAR g_wszPicsLabel[] = L"\r\nPICS-Label:";
  1650. HRESULT CDocObjectHost::CDOHBindStatusCallback::OnResponse(DWORD dwResponseCode, LPCWSTR szResponseHeaders,
  1651. LPCWSTR szRequestHeaders,
  1652. LPWSTR *pszAdditionalRequestHeaders)
  1653. {
  1654. #ifndef NO_DELEGATION
  1655. if (_pnegotiateChained) {
  1656. _pnegotiateChained->OnResponse(dwResponseCode, szResponseHeaders, szRequestHeaders, pszAdditionalRequestHeaders);
  1657. }
  1658. else
  1659. {
  1660. #endif
  1661. #ifndef NO_DELEGATION
  1662. }
  1663. #endif
  1664. #ifdef FEATURE_PICS
  1665. /* CODEWORK: For next release, all response headers should be handled
  1666. * generically through _OnHttpEquiv, and rating labels should be
  1667. * processed there instead of through a private IOleCommandTarget
  1668. * interface with Trident.
  1669. */
  1670. /* NOTE: We still need to check for the PICS label header here, even
  1671. * if we chained to Trident or whoever above.
  1672. */
  1673. // (jbeda) this _dwPicsLabelSource stuff looks really screwy...
  1674. CDocObjectHost* pdoh = IToClass(CDocObjectHost, _bsc, this);
  1675. if (pdoh->_PicsProcBase._fbPicsWaitFlags & PICS_WAIT_FOR_INDOC) {
  1676. LPCWSTR pwszPicsLabel = StrStrW(szResponseHeaders, g_wszPicsLabel);
  1677. if (pwszPicsLabel != NULL) {
  1678. pdoh->_PicsProcBase._dwPicsLabelSource=PICS_LABEL_FROM_HEADER;
  1679. pwszPicsLabel += ARRAYSIZE(g_wszPicsLabel); /* skip \r\n and label name */
  1680. LPCWSTR pwszPicsLabelEnd = StrChrW(pwszPicsLabel, L'\r');
  1681. if (pwszPicsLabelEnd == NULL) {
  1682. // NOTE: lstrlenW doesn't work on Win95, so we do this manually.
  1683. for (pwszPicsLabelEnd = pwszPicsLabel;
  1684. *pwszPicsLabelEnd;
  1685. pwszPicsLabelEnd++)
  1686. ;
  1687. }
  1688. if (pwszPicsLabel && (pwszPicsLabelEnd > pwszPicsLabel))
  1689. {
  1690. WCHAR* pszLabel = new WCHAR[((int)(pwszPicsLabelEnd - pwszPicsLabel)) + 1];
  1691. if (pszLabel)
  1692. {
  1693. //
  1694. // pwszPicsLabel may not be NULL terminated so use memcpy to
  1695. // move it. Memory allocated by new is zero filled so
  1696. // pszLabel doesn't have to have L'\0' appeneded.
  1697. //
  1698. memcpy(pszLabel, pwszPicsLabel,
  1699. ((int)(pwszPicsLabelEnd - pwszPicsLabel)) * sizeof(WCHAR));
  1700. pdoh->_PicsProcBase._HandleInDocumentLabel(pszLabel);
  1701. delete pszLabel;
  1702. }
  1703. }
  1704. }
  1705. else
  1706. {
  1707. pdoh->_PicsProcBase._dwPicsLabelSource=PICS_LABEL_FROM_PAGE;
  1708. }
  1709. }
  1710. #endif
  1711. return S_OK;
  1712. }
  1713. HRESULT CDocObjectHost::CDOHBindStatusCallback::GetWindow(REFGUID rguidReason, HWND* phwnd)
  1714. {
  1715. CDocObjectHost* pdoh = IToClass(CDocObjectHost, _bsc, this);
  1716. if (!phwnd)
  1717. return E_POINTER;
  1718. if (pdoh->_psb) {
  1719. pdoh->_psb->GetWindow(phwnd);
  1720. } else {
  1721. *phwnd = pdoh->_hwnd;
  1722. }
  1723. return S_OK;
  1724. }
  1725. HRESULT CDocObjectHost::CDOHBindStatusCallback::OnSecurityProblem(DWORD dwProblem)
  1726. {
  1727. // force UI - return S_FALSE for all problems
  1728. return S_FALSE;
  1729. }
  1730. #define BUG_EXEC_ON_FAILURE //nash:31526
  1731. HRESULT CDocObjectHost::CDOHBindStatusCallback::OnStopBinding(HRESULT hrError,
  1732. LPCWSTR szError)
  1733. {
  1734. BSCMSG(TEXT("OnStopBinding"), this, hrError);
  1735. _fBinding = FALSE;
  1736. CDocObjectHost * pdoh = IToClass(CDocObjectHost, _bsc, this);
  1737. LPWSTR pwzHeaders = NULL;
  1738. BOOL fShouldDisplayError = TRUE;
  1739. DWORD dwStatusCode = 0; // We use 0 to mean no status yet
  1740. DWORD dwStatusCodeSize = sizeof(dwStatusCode);
  1741. BOOL bSuppressUI = FALSE;
  1742. BOOL fAsyncDownload = FALSE;
  1743. BOOL fAborted = _fAborted;
  1744. BOOL fCancelAutoSearch = FALSE;
  1745. BOOL fNavigateErrorFired = FALSE; // I cannot tell if _HandleHttpErrors are really mutually exclusive from the AutoSearching.
  1746. // Therefore I am adding a flag to make sure we don't fire NavigateError twice.
  1747. _fAborted = FALSE;
  1748. _privacyQueue.Reset();
  1749. ResetPrivacyInfo();
  1750. //
  1751. // this is to protect against urlmons behavior of returning
  1752. // an async error and sync error on the same call.
  1753. if (pdoh->_fSyncBindToObject && FAILED(hrError))
  1754. {
  1755. pdoh->_hrOnStopBinding = hrError;
  1756. return S_OK;
  1757. }
  1758. // if aborting to let Document.Write work...pretend everything is cool
  1759. if (_fDocWriteAbort && hrError == E_ABORT) hrError = S_OK;
  1760. // Why not use the cached value?
  1761. // pdoh->_GetOfflineSilent(0, &bSuppressUI);
  1762. bSuppressUI = (_bFrameIsSilent || _IsDesktopItem(pdoh)) ? TRUE : FALSE;
  1763. _bindst = 0; // go back to the normal state
  1764. if (_pbc && pdoh->_punkPending)
  1765. {
  1766. _pbc->RevokeObjectParam(L"__PrecreatedObject");
  1767. }
  1768. if (!_pbc)
  1769. {
  1770. ASSERT(0);
  1771. return S_OK;
  1772. }
  1773. // NOTES: Guard against last Release by _RevokeObjectParam
  1774. AddRef();
  1775. if (pdoh->_pwb)
  1776. {
  1777. pdoh->_pwb->SetNavigateState(BNS_NORMAL);
  1778. }
  1779. if (pdoh->_psb)
  1780. { // paranoia
  1781. pdoh->_psb->SetStatusTextSB(NULL);
  1782. }
  1783. BSCMSG("OnStopBinding calling _RevokeObjectParam", this, _pbc);
  1784. _RevokeObjectParam(_pbc);
  1785. _pbc->RevokeObjectParam(WSZGUID_OPID_DocObjClientSite);
  1786. //
  1787. // If the error code is a mapped error code (by URLMON), get the
  1788. // real error code from IBinding for display purpose.
  1789. //
  1790. HRESULT hrDisplay = hrError; // assume they are the same
  1791. #define ENABLE_WHEN_GETBINDRESULT_STARTS_WORKING
  1792. #ifdef ENABLE_WHEN_GETBINDRESULT_STARTS_WORKING
  1793. if (hrError>=INET_E_ERROR_FIRST && hrError<=INET_E_ERROR_LAST)
  1794. {
  1795. //
  1796. // We come here when _pib==NULL, if URLMON synchronously fails
  1797. // (such as a bad protocol).
  1798. //
  1799. // ASSERT(_pib);
  1800. //
  1801. if (_pib)
  1802. {
  1803. CLSID clsid;
  1804. LPWSTR pwszError = NULL;
  1805. HRESULT hresT=_pib->GetBindResult(&clsid, (DWORD *)&hrDisplay, &pwszError, NULL);
  1806. TraceMsg(TF_SHDBINDING, "DOH::OnStopBinding called GetBindResult %x->%x (%x)", hrError, hrDisplay, hresT);
  1807. if (SUCCEEDED(hresT))
  1808. {
  1809. //
  1810. // URLMON returns a native Win32 error.
  1811. //
  1812. if (hrDisplay && SUCCEEDED(hrDisplay))
  1813. {
  1814. hrDisplay = HRESULT_FROM_WIN32(hrDisplay);
  1815. }
  1816. //
  1817. // URLMON is not supposed to return 0 as the error code,
  1818. // which causes a "successfully done" error msgbox.
  1819. //
  1820. AssertMsg(hrDisplay != S_OK, TEXT("Call JohannP if you see this assert."));
  1821. if (pwszError)
  1822. {
  1823. OleFree(pwszError);
  1824. }
  1825. }
  1826. }
  1827. }
  1828. #endif
  1829. TraceMsg(TF_SHDBINDING, "DOH::BSC::OnStopBinding binding failed %x (hrDisplay=%x)", hrError, hrDisplay);
  1830. //
  1831. // HACK: If the object is associated with IE/Shell itself, but has
  1832. // no CLSID, we'll force MSHTML.
  1833. //
  1834. // if (_fSelfAssociated && (hrError==MK_E_INVALIDEXTENSION || hrError==REGDB_E_CLASSNOTREG)) {
  1835. // hrError = _HandleSelfAssociate();
  1836. // }
  1837. if (_pib)
  1838. {
  1839. // we dont need to do the expiry stuff here anymore.
  1840. // now mshtml should be doing it through the IPersistHistory
  1841. // get the expire info
  1842. // The HTTP rules for expiration are
  1843. // Expires: 0 expire immediately
  1844. // if Expires: <= Date: expire immediately
  1845. // if Expires: bad format expire immediately
  1846. IWinInetHttpInfo * phi;
  1847. if (SUCCEEDED(_pib->QueryInterface(IID_IWinInetHttpInfo, (LPVOID*)&phi)))
  1848. {
  1849. BYTE abBuffer[256]; // We don't care about this data, just
  1850. DWORD cbBuffer=sizeof(abBuffer); // whether it exists or not
  1851. if (phi->QueryInfo(HTTP_QUERY_LAST_MODIFIED, &abBuffer, &cbBuffer, NULL, 0) == S_OK)
  1852. pdoh->_fhasLastModified = TRUE;
  1853. if (phi->QueryInfo(HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &dwStatusCode, &dwStatusCodeSize, NULL, 0) != S_OK)
  1854. {
  1855. dwStatusCode = 0; // failed to get status code
  1856. dwStatusCodeSize = 0; // failed to get status code
  1857. }
  1858. // This code will decide if we should display a popup error;
  1859. // essentially, it detects if we can reasonably assume that
  1860. // HTML was returned in the error case; if so, we believe that
  1861. // it is an error page, so we let that display rather than a
  1862. // popup.
  1863. if (dwStatusCode)
  1864. {
  1865. // We got a status code; let's see if we have a
  1866. // content-type.
  1867. // HTTP retcode 204 is a "succeeded, do nothing" retcode
  1868. // So we should always suppress the popup; further, it is
  1869. // spec'd to NEVER have content, so we do this before checking
  1870. // for content-type.
  1871. // So is 100
  1872. // 100 is not in wininet.h
  1873. if (dwStatusCode == HTTP_STATUS_NO_CONTENT)
  1874. fShouldDisplayError = FALSE;
  1875. // what is max header size?
  1876. CHAR szContentType[1024];
  1877. DWORD dwContentTypeSize = sizeof(szContentType);
  1878. // This code handles a bug in URLMON where it tells us
  1879. // INET_E_DATA_NOT_AVAILABLE when in fact the
  1880. // data _was_ available. We don't want any future
  1881. // errors affected by this, so we restrict this
  1882. // hack to less than 600, and ONLY for the
  1883. // INET_E_DATA_NOT_AVAILABLE case.
  1884. if (hrError == INET_E_DATA_NOT_AVAILABLE &&
  1885. dwStatusCode < 600 &&
  1886. phi->QueryInfo(HTTP_QUERY_CONTENT_TYPE, &szContentType,
  1887. &dwContentTypeSize, NULL, 0) == S_OK)
  1888. {
  1889. fShouldDisplayError = FALSE;
  1890. }
  1891. //
  1892. // Handle http errors.
  1893. //
  1894. // Let's wrap the firing in case it is not the first attempt in future
  1895. if (dwStatusCode >= 400 && dwStatusCode <= 599)
  1896. {
  1897. if (!fNavigateErrorFired)
  1898. {
  1899. pdoh->_FireNavigateErrorHelper(NULL, dwStatusCode, &fCancelAutoSearch);
  1900. fNavigateErrorFired = TRUE;
  1901. }
  1902. if (!fCancelAutoSearch)
  1903. {
  1904. _HandleHttpErrors(dwStatusCode, _cbContentLength, pdoh);
  1905. }
  1906. else if (!pdoh->_fCanceledByBrowser)
  1907. {
  1908. pdoh->_CancelPendingNavigation(FALSE, FALSE);
  1909. }
  1910. }
  1911. }
  1912. phi->Release();
  1913. }
  1914. ATOMICRELEASE(_pib);
  1915. }
  1916. ATOMICRELEASE(_psvPrev);
  1917. //
  1918. // If the object does not support IOleObject, treat it as if we failed
  1919. // to bind.
  1920. //
  1921. if (_fBoundToNoOleObject)
  1922. {
  1923. ASSERT(SUCCEEDED(hrError));
  1924. hrError = MK_E_INVALIDEXTENSION;
  1925. }
  1926. // need to handle navigation in successful proxy response but w/
  1927. // 404 error. tonyci 13nov96. for autosearching & autosuffixing
  1928. if (FAILED(hrError))
  1929. {
  1930. BOOL fAddToMRU = FALSE;
  1931. pdoh->_fDrawBackground = TRUE;
  1932. TCHAR szURL[MAX_URL_STRING+1];
  1933. szURL[0] = TEXT('\0');
  1934. //
  1935. // It seems that in some of the case of hrError the code counts on dwStatusCode being set
  1936. // dwStatus is set exactly when the real error code was obtained from IBinding for display purpose
  1937. // For the other case I am going to use hrError
  1938. //
  1939. if (!fNavigateErrorFired)
  1940. {
  1941. if (dwStatusCode)
  1942. {
  1943. pdoh->_FireNavigateErrorHelper(NULL, dwStatusCode, &fCancelAutoSearch);
  1944. fNavigateErrorFired = TRUE;
  1945. }
  1946. else if (hrError>=INET_E_ERROR_FIRST && hrError<=INET_E_ERROR_LAST)
  1947. {
  1948. pdoh->_FireNavigateErrorHelper(NULL, hrError, &fCancelAutoSearch);
  1949. fNavigateErrorFired = TRUE;
  1950. }
  1951. }
  1952. if (pdoh->_pmkCur)
  1953. {
  1954. pdoh->_GetCurrentPage(szURL,ARRAYSIZE(szURL));
  1955. }
  1956. TraceMsg(TF_SHDBINDING, "DOH::OnStopBinding hrError=%x", hrError);
  1957. pdoh->_OnSetProgressPos(0, PROGRESS_RESET);
  1958. switch(hrError)
  1959. {
  1960. //
  1961. // If pmk->BindToObject is failed because of "binding", we should
  1962. // offer an option to download it as a file.
  1963. //
  1964. #ifdef BUG_EXEC_ON_FAILURE
  1965. case INET_E_CANNOT_INSTANTIATE_OBJECT:
  1966. TraceMsg(TF_SHDBINDING, "DOH::OnStopBinding IDS_ERR_OLESVR");
  1967. _SetSearchInfo(pdoh, 0, FALSE, FALSE, FALSE); // reset info
  1968. goto Lexec;
  1969. case INET_E_CANNOT_LOAD_DATA:
  1970. TraceMsg(TF_SHDBINDING, "DOH::OnStopBinding IDS_ERR_LOAD");
  1971. _SetSearchInfo(pdoh, 0, FALSE, FALSE, FALSE); // reset info
  1972. goto Lexec;
  1973. #else
  1974. case INET_E_CANNOT_INSTANTIATE_OBJECT:
  1975. _SetSearchInfo(pdoh, 0, FALSE, FALSE, FALSE); // reset info
  1976. if (MLShellMessageBox(pdoh->_hwnd,
  1977. MAKEINTRESOURCE(IDS_ERR_OLESVR),
  1978. MAKEINTRESOURCE(IDS_TITLE),
  1979. MB_YESNO|MB_ICONERROR,
  1980. szURL) == IDYES)
  1981. {
  1982. IUnknown * punk;
  1983. HRESULT hresT = pdoh->QueryInterface(IID_IUnknown, (void**)&punk);
  1984. if(SUCCEEDED(hresT))
  1985. {
  1986. if (!fAborted)
  1987. {
  1988. CDownLoad_OpenUI(pdoh->_pmkCur, _pbc, FALSE, TRUE, NULL, NULL, NULL, NULL, NULL, _pszRedirectedURL, pdoh->_uiCP, punk);
  1989. }
  1990. punk->Release();
  1991. }
  1992. }
  1993. break;
  1994. case INET_E_CANNOT_LOAD_DATA:
  1995. _SetSearchInfo(pdoh, 0, FALSE, FALSE, FALSE); // reset info
  1996. // e.g. click on .xls link when doc already open/modified/locked
  1997. // and say 'cancel'
  1998. //
  1999. if (MLShellMessageBox(pdoh->_hwnd,
  2000. MAKEINTRESOURCE(IDS_ERR_LOAD),
  2001. MAKEINTRESOURCE(IDS_TITLE),
  2002. MB_YESNO|MB_ICONERROR,
  2003. szURL) == IDYES)
  2004. {
  2005. IUnknown *punk;
  2006. HRESULT hresT = pdoh->QueryInterface(IID_IUnknown, (void**)&punk);
  2007. if(SUCCEEDED(hresT))
  2008. {
  2009. if (!fAborted)
  2010. {
  2011. CDownLoad_OpenUI(pdoh->_pmkCur, _pbc, FALSE, TRUE, NULL, NULL, NULL, NULL, _pszRedirectedURL, pdoh->_uiCP, punk);
  2012. }
  2013. punk->Release();
  2014. }
  2015. }
  2016. break;
  2017. #endif
  2018. //
  2019. // NOTES: According to JohannP, URLMON will give us
  2020. // REGDB_E_CLASSNOTREG. I'll leave MK_E_INVALIDEXTENSION
  2021. // to be compatible with old URLMON (which is harmless).
  2022. //
  2023. case MK_E_INVALIDEXTENSION:
  2024. case REGDB_E_CLASSNOTREG:
  2025. _SetSearchInfo(pdoh, 0, FALSE, FALSE, FALSE); // reset info
  2026. #ifdef BUG_EXEC_ON_FAILURE
  2027. Lexec: // nash:31526
  2028. // for various instantiation errors:
  2029. // - for ie3 we suppress messages and force a ShellExec as a
  2030. // 2nd try, pretty much always
  2031. // - for ie4 we should be more selective (nash:31526)
  2032. #endif
  2033. #ifdef FEATURE_PICS
  2034. // For data types that don't have a CLSID, we never get a chance
  2035. // to block in the CLASSIDAVAILABLE OnProgress notification, so
  2036. // we have to block here. However, avoid blocking documents such
  2037. // as HTML which we want to download completely so we can get
  2038. // ratings strings out of them.
  2039. //
  2040. if (!pdoh->_fPicsBlockLate && (pdoh->_PicsProcBase._fbPicsWaitFlags || !pdoh->_PicsProcBase._fPicsAccessAllowed))
  2041. {
  2042. pdoh->_PicsProcBase._fbPicsWaitFlags &= ~(PICS_WAIT_FOR_INDOC | PICS_WAIT_FOR_END); /* make sure we don't expect indoc ratings */
  2043. TraceMsg(DM_PICS, "OnStopBinding calling _PicsBlockingDialog, waitflags now %x", (DWORD)pdoh->_PicsProcBase._fbPicsWaitFlags);
  2044. if (pdoh->_PicsProcBase._PicsBlockingDialog() != IDOK)
  2045. {
  2046. TraceMsg(DM_PICS, "OnStopBinding, PICS canceled, calling _CancelPendingNavigation");
  2047. pdoh->_CancelPendingNavigation(FALSE);
  2048. break;
  2049. }
  2050. }
  2051. #endif
  2052. BeginningTransaction (NULL, NULL, 0, &pwzHeaders);
  2053. if (_dwBindVerb==BINDVERB_POST)
  2054. {
  2055. // This is a POST. Do it use the same moniker (modeless)
  2056. //
  2057. // Notes: The ownership of the data in pbinfo will be transfered
  2058. // to CDownLoad_OpenUIPost. Therefore, we should not call
  2059. // ReleaseBindInfo(pbinfo) here.
  2060. //
  2061. DWORD grfBINDF;
  2062. // The BINDINFO can not be on the stack since it will be freed by the
  2063. // download thread.
  2064. //
  2065. BINDINFO * pbinfo = (BINDINFO*)LocalAlloc(LPTR, SIZEOF(BINDINFO));
  2066. if (!pbinfo)
  2067. {
  2068. return E_OUTOFMEMORY;
  2069. }
  2070. pbinfo->cbSize = SIZEOF(BINDINFO);
  2071. GetBindInfo(&grfBINDF, pbinfo);
  2072. // If our POST was really a redirected POST, it will have
  2073. // turned into a GET. In this case, we need to release
  2074. // ownership of the data and pretend like the whole thing
  2075. // was a GET to start with.
  2076. if (pbinfo->dwBindVerb==BINDVERB_GET)
  2077. {
  2078. WCHAR wszUrl[INTERNET_MAX_URL_LENGTH];
  2079. ASSERT(_pszRedirectedURL);
  2080. SHTCharToUnicode(_pszRedirectedURL, wszUrl, ARRAYSIZE(wszUrl));
  2081. IUnknown * punk;
  2082. HRESULT hresT = pdoh->QueryInterface(IID_IUnknown, (void**)&punk);
  2083. if (SUCCEEDED(hresT))
  2084. {
  2085. VARIANT varOut = {0};
  2086. pdoh->_pmsoctBrowser->Exec(&CGID_ShellDocView, SHDVID_FIREFILEDOWNLOAD,
  2087. 0, NULL, &varOut);
  2088. if (V_VT(&varOut) != VT_BOOL || V_BOOL(&varOut) == VARIANT_FALSE)
  2089. {
  2090. if (!fAborted)
  2091. {
  2092. CDownLoad_OpenUIURL(wszUrl, NULL, pwzHeaders,
  2093. FALSE /* fSync */, FALSE /* fSaveAs */, pdoh->_fCalledMayOpenSafeDlg,
  2094. NULL, NULL, NULL, _pszRedirectedURL, pdoh->_uiCP, punk);
  2095. pwzHeaders = NULL; // ownership is to CDownload now
  2096. }
  2097. }
  2098. punk->Release();
  2099. }
  2100. ReleaseBindInfo(pbinfo); // This one is OK since we did not pass the pbinfo
  2101. LocalFree(pbinfo); // and we can free it
  2102. pbinfo = NULL;
  2103. }
  2104. else
  2105. {
  2106. ASSERT(pbinfo->dwBindVerb==BINDVERB_POST);
  2107. // Collect the headers associated with this xact
  2108. IUnknown * punk;
  2109. HRESULT hresT = pdoh->QueryInterface(IID_IUnknown, (void**)&punk);
  2110. if (SUCCEEDED(hresT))
  2111. {
  2112. VARIANT varOut = {0};
  2113. pdoh->_pmsoctBrowser->Exec(&CGID_ShellDocView, SHDVID_FIREFILEDOWNLOAD,
  2114. 0, NULL, &varOut);
  2115. if (V_VT(&varOut) != VT_BOOL || V_BOOL(&varOut) == VARIANT_FALSE)
  2116. {
  2117. if (!fAborted)
  2118. {
  2119. CDownLoad_OpenUI(pdoh->_pmkCur, _pbc, FALSE /* fSync */, FALSE /* fSaveAs */, pdoh->_fCalledMayOpenSafeDlg /* fSafe */, pwzHeaders, BINDVERB_POST, grfBINDF, pbinfo, _pszRedirectedURL, pdoh->_uiCP, punk);
  2120. pwzHeaders = NULL; // ownership is to CDownload now
  2121. }
  2122. }
  2123. punk->Release();
  2124. }
  2125. TraceMsg(TF_SHDBINDING, "DOH::OnStopBinding just called CDownLoad_OpenUIPost");
  2126. // NOTE: t-gpease 8-18-97
  2127. // Do not ReleaseBindInfo(pinfo) because it is used by the download thread.
  2128. // The thread is responsible for releasing it.
  2129. }
  2130. }
  2131. else
  2132. {
  2133. // Otherwise, spawn another thread and get it there.
  2134. // NOTE: If UnBind gets called then pdoh->_pmkCur will be NULL
  2135. // and URLMON is most likely returning a bogus error code. So
  2136. // we'll check the pointer and prevent from blowing up.
  2137. if (pdoh->_pmkCur)
  2138. {
  2139. BOOL fSafe = pdoh->_fCalledMayOpenSafeDlg;
  2140. IBrowserService * pbs;
  2141. if (PathIsFilePath(szURL) &&
  2142. SUCCEEDED(pdoh->QueryService(SID_STopFrameBrowser, IID_IBrowserService, (LPVOID *)&pbs)))
  2143. {
  2144. DWORD dwFlags;
  2145. if (SUCCEEDED(pbs->GetFlags(&dwFlags)) && (dwFlags & BSF_NOLOCALFILEWARNING))
  2146. {
  2147. fSafe = TRUE;
  2148. }
  2149. pbs->Release();
  2150. }
  2151. IUnknown *punk;
  2152. HRESULT hresT = pdoh->QueryInterface(IID_IUnknown, (void**)&punk);
  2153. if (SUCCEEDED(hresT))
  2154. {
  2155. VARIANT varOut = {0};
  2156. pdoh->_pmsoctBrowser->Exec(&CGID_ShellDocView, SHDVID_FIREFILEDOWNLOAD,
  2157. 0, NULL, &varOut);
  2158. if (V_VT(&varOut) != VT_BOOL || V_BOOL(&varOut) == VARIANT_FALSE)
  2159. {
  2160. if (pdoh->_pmsoctBrowser && pdoh->_fWindowOpen)
  2161. {
  2162. pdoh->_pmsoctBrowser->Exec(&CGID_Explorer, SBCMDID_CANCELANDCLOSE, 0, NULL, NULL);
  2163. }
  2164. if (!fAborted)
  2165. {
  2166. CDownLoad_OpenUI(pdoh->_pmkCur, pdoh->_pbcCur, FALSE, FALSE,
  2167. fSafe, pwzHeaders, NULL, pdoh->_bsc._dwBindf, NULL, _pszRedirectedURL,
  2168. pdoh->_uiCP, punk, pdoh->_fConfirmed);
  2169. pwzHeaders = NULL; // ownership is to CDownload now
  2170. }
  2171. }
  2172. punk->Release();
  2173. }
  2174. fAsyncDownload = TRUE;
  2175. }
  2176. }
  2177. if (pwzHeaders)
  2178. {
  2179. CoTaskMemFree(pwzHeaders);
  2180. }
  2181. break;
  2182. // URLMON failed to bind because it didn't know what to do with
  2183. // with this URL. Lets check and see if the Shell should handle
  2184. // it via a helper app (news:, mailto:, telnet:, etc.)
  2185. case INET_E_UNKNOWN_PROTOCOL:
  2186. _SetSearchInfo(pdoh, 0, FALSE, FALSE, FALSE); // reset info
  2187. {
  2188. // If we've been redirected, use that URL
  2189. //
  2190. if (_pszRedirectedURL)
  2191. {
  2192. StrCpyN(szURL, _pszRedirectedURL, ARRAYSIZE(szURL));
  2193. }
  2194. // Here we check to see if it is a URL we really want to shellexecute
  2195. // so it is handled by helper apps.....else it really is an error
  2196. if (ShouldShellExecURL(szURL))
  2197. {
  2198. // We can add this to the address bar MRU
  2199. fAddToMRU = TRUE;
  2200. // We need to decode this before passing it on to someone.
  2201. TCHAR szDecodedURL[INTERNET_MAX_URL_LENGTH];
  2202. DWORD cchDecodedURL = ARRAYSIZE(szDecodedURL);
  2203. // REVIEW: NT 319480 IE 54850 - need to append _pszLocation back to pszBadProtoURL...
  2204. //
  2205. // I assume the string was escaped when it came from urlmon, so we need
  2206. // to append it before PrepareURLForExternalApp.
  2207. //
  2208. // Note: if the url had been redirected above, _pszLocation has been updated
  2209. // to the new redirected URL, so we still want to append it.
  2210. //
  2211. if (pdoh->_pszLocation)
  2212. {
  2213. StrCatBuff(szURL, pdoh->_pszLocation, ARRAYSIZE(szURL));
  2214. }
  2215. PrepareURLForExternalApp(szURL, szDecodedURL, &cchDecodedURL);
  2216. // PathQuoteSpaces(szDecodedURL);
  2217. SHELLEXECUTEINFO sei = {0};
  2218. sei.cbSize = sizeof(sei);
  2219. sei.lpFile = szDecodedURL;
  2220. sei.nShow = SW_SHOWNORMAL;
  2221. if (!ShellExecuteEx(&sei))
  2222. {
  2223. if(!bSuppressUI)
  2224. {
  2225. IE_ErrorMsgBox(pdoh->_psb, pdoh->_hwnd, hrDisplay, szError,
  2226. szDecodedURL, IDS_CANTSHELLEX, MB_OK | MB_ICONSTOP );
  2227. }
  2228. }
  2229. //
  2230. // We want to close the browser window if this is the
  2231. // very first navigation.
  2232. //
  2233. fAsyncDownload = TRUE;
  2234. }
  2235. else if ((!bSuppressUI) && (!fCancelAutoSearch))
  2236. {
  2237. _NavigateToErrorPage(ERRORPAGE_SYNTAX, pdoh, FALSE);
  2238. }
  2239. break;
  2240. }
  2241. case E_ABORT:
  2242. case HRESULT_FROM_WIN32(ERROR_CANCELLED):
  2243. _SetSearchInfo(pdoh, 0, FALSE, FALSE, FALSE); // reset info
  2244. // If the binding was aborted or canceled and this is
  2245. // a navigation that was delegated from Trident, then
  2246. // we must fire the FileDownload event so Trident won't
  2247. // switch the markup.
  2248. //
  2249. if (pdoh->_fDelegatedNavigation && pdoh->_pmsoctBrowser)
  2250. {
  2251. VARIANT varOut = {0};
  2252. pdoh->_pmsoctBrowser->Exec(&CGID_ShellDocView, SHDVID_FIREFILEDOWNLOAD, 0, NULL, &varOut);
  2253. }
  2254. break;
  2255. #ifdef BUG_EXEC_ON_FAILURE
  2256. case E_NOINTERFACE: // nash:31526
  2257. TraceMsg(TF_SHDBINDING, "DOH::OnStopBinding E_NOINTERFACE");
  2258. goto Lexec;
  2259. #endif
  2260. case INET_E_RESOURCE_NOT_FOUND:
  2261. case INET_E_DATA_NOT_AVAILABLE:
  2262. if (!fCancelAutoSearch)
  2263. {
  2264. if (_HandleFailedNavigationSearch(&fShouldDisplayError, dwStatusCode, pdoh, hrDisplay, (LPTSTR) &szURL, szError, _pib) != S_OK)
  2265. {
  2266. fShouldDisplayError = TRUE;
  2267. }
  2268. }
  2269. else if (!pdoh->_fCanceledByBrowser)
  2270. {
  2271. pdoh->_CancelPendingNavigation(FALSE, FALSE);
  2272. }
  2273. // intentional fallthrough to default to popup if needed
  2274. case INET_E_DOWNLOAD_FAILURE:
  2275. if(IsGlobalOffline())
  2276. {
  2277. fShouldDisplayError = FALSE;
  2278. break;
  2279. }
  2280. // otherwise fall through to do default handling
  2281. default:
  2282. {
  2283. if (fShouldDisplayError)
  2284. {
  2285. _SetSearchInfo(pdoh, 0, FALSE, FALSE, FALSE); // reset info
  2286. if ((!bSuppressUI) && (!fCancelAutoSearch))
  2287. {
  2288. //
  2289. // If we're in a frame try to navigate in place. This
  2290. // won't work if we're in a synchronous call
  2291. // (_fSetTarget).
  2292. //
  2293. BOOL fNavigateInPlace = pdoh->_fHaveParentSite && !pdoh->_fSetTarget;
  2294. _NavigateToErrorPage(ERRORPAGE_DNS, pdoh, fNavigateInPlace);
  2295. }
  2296. }
  2297. }
  2298. break;
  2299. }
  2300. // Tell addressbar to not add this to its mru
  2301. if (!fAddToMRU)
  2302. {
  2303. _DontAddToMRU(pdoh);
  2304. }
  2305. //
  2306. // Prepare for the case where the container keep us visible
  2307. // after hitting this code (Explorer does, IE doesn't).
  2308. //
  2309. pdoh->_fDrawBackground = TRUE;
  2310. // In the case of quickly jumping to another link, we end up with
  2311. // a _hwnd being NULL and we were invalidating the desktop. So,
  2312. // I check for NULL here before calling InvalidateRect.
  2313. if (pdoh->_hwnd)
  2314. {
  2315. InvalidateRect(pdoh->_hwnd, NULL, TRUE);
  2316. }
  2317. // Tell the browser to cancel the pending navigation only
  2318. // if it has not been canceled by the browser itself.
  2319. // and if the navigation wasn't delegated from the document.
  2320. //
  2321. if (!pdoh->_fCanceledByBrowser)
  2322. {
  2323. pdoh->_CancelPendingNavigation(fAsyncDownload, FALSE, pdoh->_fDelegatedNavigation);
  2324. if (pdoh->_fDelegatedNavigation)
  2325. {
  2326. IDocNavigate * pDocNavigate;
  2327. HRESULT hr = E_FAIL;
  2328. if ( pdoh->_pwb )
  2329. {
  2330. hr = pdoh->_pwb->QueryInterface(IID_PPV_ARG(IDocNavigate, &pDocNavigate));
  2331. }
  2332. if (S_OK == hr)
  2333. {
  2334. pDocNavigate->OnReadyStateChange(NULL, READYSTATE_COMPLETE);
  2335. pDocNavigate->Release();
  2336. }
  2337. }
  2338. }
  2339. else
  2340. {
  2341. TraceMsg(TF_SHDNAVIGATE|TF_SHDPROGRESS,
  2342. "DOH::::OnStopBinding not calling _CancelPendingNav");
  2343. }
  2344. }
  2345. else
  2346. {
  2347. BOOL bDidNavigate = FALSE;
  2348. // Might have redirected to mailto: or some other protocol handled by
  2349. // plugable protocol that does some magic (eg launch mail program) and
  2350. // reports OnStopBinding w/o going through OnObjectAvailable!
  2351. if (NULL == pdoh->_pole && !pdoh->_fCanceledByBrowser)
  2352. {
  2353. pdoh->_CancelPendingNavigation(FALSE);
  2354. }
  2355. // It is still possible that our Proxy failed to find the server but
  2356. // gave us HTML. If this is the case, and the user has "find sites"
  2357. // set, we should go ahead and start trying to do our automatic
  2358. // navigation stuff.
  2359. if (dwStatusCode && DO_SEARCH_ON_STATUSCODE(dwStatusCode))
  2360. {
  2361. if (!fCancelAutoSearch)
  2362. {
  2363. if (_HandleFailedNavigationSearch(&fShouldDisplayError, dwStatusCode, pdoh, hrDisplay, NULL, szError, _pib) == S_OK)
  2364. {
  2365. bDidNavigate = TRUE;
  2366. }
  2367. }
  2368. else if (!pdoh->_fCanceledByBrowser)
  2369. {
  2370. pdoh->_CancelPendingNavigation(FALSE, FALSE);
  2371. }
  2372. // Note, since the Proxy will have given us HTML in this case,
  2373. // we will never display an error dialog.
  2374. }
  2375. if (!bDidNavigate && !pdoh->_fDocCanNavigate)
  2376. {
  2377. _SetSearchInfo(pdoh, 0, FALSE, FALSE, FALSE); // reset info
  2378. // We can suppress this redundant call to Add to History if DocObject
  2379. // is MSHTML, since it will report readystate
  2380. if (!_fBoundToMSHTML && pdoh->_pmkCur)
  2381. {
  2382. TCHAR szUrl[MAX_URL_STRING+1];
  2383. pdoh->_GetCurrentPage(szUrl,ARRAYSIZE(szUrl));
  2384. if (pdoh->_pszLocation)
  2385. {
  2386. StrCatBuff(szUrl, pdoh->_pszLocation, ARRAYSIZE(szUrl));
  2387. }
  2388. if (!bSuppressUI)
  2389. {
  2390. BOOL fWriteHistory = TRUE;
  2391. BOOL fSelectHistory = TRUE;
  2392. if (NULL != pdoh->_pocthf)
  2393. {
  2394. MSOCMD rgCmd[] = { { SBCMDID_WRITEHIST, 0 }, { SBCMDID_SELECTHISTPIDL, 0 } };
  2395. pdoh->_pocthf->QueryStatus(&CGID_Explorer, ARRAYSIZE(rgCmd), rgCmd, NULL);
  2396. fWriteHistory = BOOLIFY(rgCmd[0].cmdf & MSOCMDF_ENABLED);
  2397. fSelectHistory = BOOLIFY(rgCmd[1].cmdf & MSOCMDF_ENABLED);
  2398. }
  2399. AddUrlToUrlHistoryStg(szUrl,
  2400. NULL,
  2401. pdoh->_pwb,
  2402. fWriteHistory,
  2403. fSelectHistory ? pdoh->_pocthf : NULL,
  2404. pdoh->get_punkSFHistory(), NULL);
  2405. }
  2406. }
  2407. } // if !bDidNavigate
  2408. } // if failed(hrerror) ... else
  2409. // Released here because we may need it for OpenUI() w/ POST verb
  2410. ATOMICRELEASE(_pbc);
  2411. #ifndef NO_DELEGATION
  2412. if (_pbscChained)
  2413. {
  2414. CHAINMSG("OnStopBinding", hrError);
  2415. _pbscChained->OnStopBinding(hrError, szError);
  2416. }
  2417. #endif
  2418. ATOMICRELEASE(_pbscChained);
  2419. ATOMICRELEASE(_pnegotiateChained);
  2420. pdoh->_ResetStatusBar();
  2421. ATOMICRELEASE(pdoh->_pbcCur);
  2422. if (_pszHeaders)
  2423. {
  2424. LocalFree(_pszHeaders);
  2425. _pszHeaders = NULL;
  2426. }
  2427. if (_hszPostData)
  2428. {
  2429. GlobalFree(_hszPostData);
  2430. _hszPostData = NULL;
  2431. }
  2432. // NOTES: Guard against last Release by _RevokeObjectParam
  2433. Release();
  2434. return S_OK;
  2435. }
  2436. void CDocObjectHost::CDOHBindStatusCallback::AbortBinding(void)
  2437. {
  2438. TraceMsg(TF_SHDPROGRESS, "CDOH::CBSC::AbortBinding called _pib=%x", _pib);
  2439. if (_pib)
  2440. {
  2441. TraceMsg(0, "sdv TR AbortBinding Calling _pib->Abort");
  2442. //
  2443. // Notes: OnStopBinding(E_ABORT) will be called from _pib->Abort
  2444. //
  2445. HRESULT hresT = _pib->Abort();
  2446. TraceMsg(TF_SHDBINDING, "sdv TR AbortBinding Called _pib->Abort (%x)", hresT);
  2447. // URLMon may call our OnStopBinding asynchronously.
  2448. ATOMICRELEASE(_pib);
  2449. CDocObjectHost* pdoh = IToClass(CDocObjectHost, _bsc, this);
  2450. if(pdoh->_dwProgressPos)
  2451. {
  2452. pdoh->_ResetStatusBar();
  2453. pdoh->_OnSetProgressPos(0, PROGRESS_RESET);
  2454. }
  2455. }
  2456. }
  2457. //
  2458. // NavigatesToErrorPage cancels the pending navigation and and navigates to
  2459. // an internal error page.
  2460. //
  2461. void CDocObjectHost::CDOHBindStatusCallback::_NavigateToErrorPage(DWORD dwError, CDocObjectHost* pdoh, BOOL fInPlace)
  2462. {
  2463. ASSERT(IsErrorHandled(dwError));
  2464. ASSERT(pdoh);
  2465. // Security: Release the pre-created object because we don't want
  2466. // anyone to have access to the OM of the navigated error document
  2467. // if they obtained the reference before the error navigation.
  2468. // Releasing the reference prevents a parent window from getting keys
  2469. // to the My Computer zone.
  2470. pdoh->_ReleaseOleObject(FALSE);
  2471. pdoh->_ReleasePendingObject(FALSE);
  2472. //
  2473. // pdoh->_pmkCur can be NULL if this is a "DNS" error and Unbind has already
  2474. // been called.
  2475. //
  2476. if (pdoh->_pmkCur)
  2477. {
  2478. //
  2479. // Save the url the user attempted to navigate to. It will be used
  2480. // to refresh the page.
  2481. //
  2482. if (pdoh->_pwszRefreshUrl)
  2483. {
  2484. OleFree(pdoh->_pwszRefreshUrl);
  2485. pdoh->_pwszRefreshUrl = NULL;
  2486. }
  2487. pdoh->_pmkCur->GetDisplayName(pdoh->_pbcCur, NULL,
  2488. &pdoh->_pwszRefreshUrl);
  2489. }
  2490. if ((NULL == pdoh->_pwszRefreshUrl) || !IsErrorUrl(pdoh->_pwszRefreshUrl))
  2491. {
  2492. // Build the error page url.
  2493. //
  2494. TCHAR szErrorUrl[MAX_URL_STRING];
  2495. if (fInPlace)
  2496. {
  2497. HRESULT hr;
  2498. hr = MLBuildResURLWrap(TEXT("shdoclc.dll"),
  2499. HINST_THISDLL,
  2500. ML_CROSSCODEPAGE,
  2501. (TCHAR *)c_aErrorUrls[EUIndexFromError(dwError)].pszUrl,
  2502. szErrorUrl,
  2503. ARRAYSIZE(szErrorUrl),
  2504. TEXT("shdocvw.dll"));
  2505. if (SUCCEEDED(hr))
  2506. {
  2507. //
  2508. // Navigate to the error page.
  2509. //
  2510. IMoniker* pIMoniker;
  2511. if (SUCCEEDED(MonikerFromString(szErrorUrl, &pIMoniker)))
  2512. {
  2513. ASSERT(pIMoniker);
  2514. #ifdef DEBUG
  2515. pdoh->_fFriendlyError = TRUE;
  2516. #endif
  2517. pdoh->SetTarget(pIMoniker, pdoh->_uiCP, NULL, NULL, NULL, 0);
  2518. pIMoniker->Release();
  2519. }
  2520. }
  2521. }
  2522. else
  2523. {
  2524. const WCHAR* const pszFmt = L"#%s";
  2525. HRESULT hr;
  2526. hr = MLBuildResURLWrap(TEXT("shdoclc.dll"),
  2527. HINST_THISDLL,
  2528. ML_CROSSCODEPAGE,
  2529. (TCHAR *)c_aErrorUrls[EUIndexFromError(dwError)].pszUrl,
  2530. szErrorUrl,
  2531. ARRAYSIZE(szErrorUrl),
  2532. TEXT("shdocvw.dll"));
  2533. if (SUCCEEDED(hr))
  2534. {
  2535. int nLenWritten;
  2536. // append the #<refresh URL>
  2537. nLenWritten = lstrlen(szErrorUrl);
  2538. wnsprintf(szErrorUrl + nLenWritten,
  2539. ARRAYSIZE(szErrorUrl) - nLenWritten,
  2540. pszFmt,
  2541. pdoh->_pwszRefreshUrl ? pdoh->_pwszRefreshUrl : L"");
  2542. //
  2543. // Cancel the server page and display the internal page instead.
  2544. //
  2545. if (!pdoh->_fCanceledByBrowser)
  2546. pdoh->_CancelPendingNavigation(FALSE);
  2547. // Turn off the flag in the base browser that
  2548. // indicates that the view should be reused.
  2549. // We want a new view in this case.
  2550. //
  2551. if ( pdoh->_pwb )
  2552. {
  2553. pdoh->_pwb->SetFlags(NULL, BSF_HTMLNAVCANCELED);
  2554. }
  2555. pdoh->_DoAsyncNavigation(szErrorUrl);
  2556. pdoh->_fCanceledByBrowser = TRUE;
  2557. }
  2558. }
  2559. }
  2560. return;
  2561. }
  2562. //
  2563. // Check if the user turned off friendly http errors. Default is yes.
  2564. //
  2565. BOOL CDocObjectHost::CDOHBindStatusCallback::_DisplayFriendlyHttpErrors()
  2566. {
  2567. BOOL fRet;
  2568. DWORD dwType = REG_SZ;
  2569. TCHAR szYesOrNo[20];
  2570. DWORD cbSize = sizeof(szYesOrNo);
  2571. if (ERROR_SUCCESS == SHRegGetUSValue(REGSTR_PATH_MAIN,
  2572. REGSTR_VAL_HTTP_ERRORS, &dwType,
  2573. (LPVOID)szYesOrNo, &cbSize, FALSE,
  2574. NULL, 0))
  2575. {
  2576. fRet = StrCmpI(szYesOrNo, L"no");
  2577. }
  2578. else
  2579. {
  2580. fRet = TRUE;
  2581. }
  2582. return fRet;
  2583. }
  2584. //
  2585. // Error handler
  2586. //
  2587. void CDocObjectHost::CDOHBindStatusCallback::_HandleHttpErrors(DWORD dwError, DWORD cbContentLength, CDocObjectHost* pdoh)
  2588. {
  2589. // Tell addressbar to not add this to its mru
  2590. _DontAddToMRU(pdoh);
  2591. if (IsErrorHandled(dwError))
  2592. {
  2593. pdoh->_fErrorPage = TRUE;
  2594. //
  2595. // On a 4XX error display an internal page if the server returned a
  2596. // page smaller than the threshold value. If the page is larger than
  2597. // the threshold, display it.
  2598. //
  2599. // If the content length is zero assume the server didn't send the
  2600. // length. In this case take the conservative approach and don't
  2601. // show our page.
  2602. //
  2603. if (cbContentLength != 0 &&
  2604. cbContentLength <= _GetErrorThreshold(dwError))
  2605. {
  2606. if (_DisplayFriendlyHttpErrors())
  2607. _NavigateToErrorPage(dwError, pdoh, TRUE);
  2608. }
  2609. }
  2610. return;
  2611. }
  2612. //
  2613. // Informs the address bar to not put this page in its mru
  2614. //
  2615. void CDocObjectHost::CDOHBindStatusCallback::_DontAddToMRU(CDocObjectHost* pdoh)
  2616. {
  2617. IDockingWindow* pdw = NULL;
  2618. IOleCommandTarget* poct;
  2619. if (pdoh->_psp &&
  2620. SUCCEEDED(pdoh->_psp->QueryService(SID_SExplorerToolbar, IID_IDockingWindow, (LPVOID*)&pdw)))
  2621. {
  2622. if (SUCCEEDED(pdw->QueryInterface(IID_IOleCommandTarget, (LPVOID*)&poct)))
  2623. {
  2624. // Get the URL we were navigating to
  2625. LPWSTR pszUrl;
  2626. if (pdoh->_pmkCur &&
  2627. SUCCEEDED(pdoh->_pmkCur->GetDisplayName(pdoh->_pbcCur, NULL, &pszUrl)))
  2628. {
  2629. LBSTR::CString strDisplay( pszUrl );
  2630. VARIANT varURL = {0};
  2631. varURL.vt = VT_BSTR;
  2632. varURL.bstrVal = strDisplay;
  2633. poct->Exec(&CGID_Explorer, SBCMDID_ERRORPAGE, 0, &varURL, NULL);
  2634. OleFree(pszUrl);
  2635. }
  2636. poct->Release();
  2637. }
  2638. pdw->Release();
  2639. }
  2640. }
  2641. //
  2642. // Tells the addressbar that we are autosearching so that it can update
  2643. // the pending url in its mru
  2644. //
  2645. void CDocObjectHost::CDOHBindStatusCallback::_UpdateMRU(CDocObjectHost* pdoh, LPCWSTR pszUrl)
  2646. {
  2647. IDockingWindow* pdw = NULL;
  2648. IOleCommandTarget* poct;
  2649. if (pdoh->_psp &&
  2650. SUCCEEDED(pdoh->_psp->QueryService(SID_SExplorerToolbar, IID_IDockingWindow, (LPVOID*)&pdw)))
  2651. {
  2652. if (SUCCEEDED(pdw->QueryInterface(IID_IOleCommandTarget, (LPVOID*)&poct)))
  2653. {
  2654. // Copy url to stack allocated bstr
  2655. LBSTR::CString strDisplay( pszUrl );
  2656. VARIANT varURL = {0};
  2657. varURL.vt = VT_BSTR;
  2658. varURL.bstrVal = strDisplay;
  2659. poct->Exec(&CGID_Explorer, SBCMDID_AUTOSEARCHING, 0, &varURL, NULL);
  2660. poct->Release();
  2661. }
  2662. pdw->Release();
  2663. }
  2664. }
  2665. //
  2666. // S_OK means we successfully did a navigation
  2667. // S_FALSE means that we did everything ok, but did not navigate
  2668. // E_* means some internal api failed.
  2669. //
  2670. HRESULT CDocObjectHost::CDOHBindStatusCallback::_HandleFailedNavigationSearch(
  2671. LPBOOL pfShouldDisplayError,
  2672. DWORD dwStatusCode,
  2673. CDocObjectHost * pdoh,
  2674. HRESULT hrDisplay,
  2675. TCHAR * szURL,
  2676. LPCWSTR szError,
  2677. IBinding * pib,
  2678. BOOL fAddMRU, /* = TRUE */
  2679. BOOL fFromTrident /* = FALSE */)
  2680. {
  2681. DWORD dwSearchForExtensions = NO_SUFFIXES;
  2682. DWORD dwDo404Search = PROMPTSEARCH;
  2683. BOOL bAskUser = TRUE; // rely on init
  2684. BOOL bDoSearch = FALSE; // rely on init
  2685. HRESULT hres = S_FALSE;
  2686. BOOL bSuppressUI = FALSE;
  2687. BOOL bFrameIsOffline = FALSE;
  2688. BOOL bPrepareForSearch = FALSE;
  2689. DWORD dwSuffixIndex = 0;
  2690. BOOL bAllowSearch = FALSE;
  2691. BOOL bContinueSearch = FALSE;
  2692. BOOL bSentToEngine = FALSE;
  2693. BOOL bOnProxy = FALSE;
  2694. TCHAR szSearchFormatStr[MAX_SEARCH_FORMAT_STRING];
  2695. DWORD dwSearchStyle = 3; // "display search results and navigate to the most likely site"
  2696. ASSERT(pdoh);
  2697. #define SAFETRACE(psz) (psz ? psz : TEXT(""))
  2698. TraceMsg(TF_SHDNAVIGATE, "DOH::BSC::_HFNS() entered status = %d, url = %s, pib = %X", dwStatusCode, SAFETRACE(szURL) , pib);
  2699. if (FAILED(GetSearchKeys(pdoh->_psp, &dwSearchStyle, &dwSearchForExtensions, &dwDo404Search)))
  2700. {
  2701. return E_FAIL;
  2702. }
  2703. TraceMsg(TF_SHDNAVIGATE, "DOH::BSC::_HFNS() dwSearch = %d, do404 = %d", dwSearchForExtensions, dwDo404Search);
  2704. // Get any persistent information from the last request
  2705. VARIANT varURL = {0};
  2706. _GetSearchInfo(pdoh->_psp, &dwSuffixIndex, &bAllowSearch, &bContinueSearch, &bSentToEngine, &varURL);
  2707. // See if window.external.autoscan() was called
  2708. BOOL fAutoScan = (varURL.vt == VT_BSTR);
  2709. TraceMsg(TF_SHDNAVIGATE, "DOH::BSC::_HFNS() index = %d, allow = %d, cont = %d, sent = %d", dwSuffixIndex, bAllowSearch, bContinueSearch, bSentToEngine);
  2710. // Why not use the cached value?
  2711. // pdoh->_GetOfflineSilent(&bFrameIsOffline, &bSuppressUI);
  2712. bFrameIsOffline = _bFrameIsOffline ? TRUE : FALSE;
  2713. bSuppressUI = (_bFrameIsSilent || _IsDesktopItem(pdoh)) ? TRUE : FALSE;
  2714. // if we are at the end of the extension list, turn off extensions
  2715. BOOL fAutoSearching = FALSE;
  2716. if (dwSearchForExtensions)
  2717. {
  2718. if (dwSuffixIndex == 0 && dwSearchStyle != 0)
  2719. {
  2720. StrCpyN(szSearchFormatStr, L"? %s", ARRAYSIZE(szSearchFormatStr));
  2721. fAutoSearching = TRUE;
  2722. }
  2723. else if (GetSearchFormatString(dwSuffixIndex, szSearchFormatStr, sizeof(szSearchFormatStr)) != ERROR_SUCCESS)
  2724. {
  2725. dwSearchForExtensions = DONE_SUFFIXES;
  2726. StrCpyN(szSearchFormatStr, TEXT("%s"), ARRAYSIZE(szSearchFormatStr));
  2727. }
  2728. }
  2729. else
  2730. {
  2731. dwSearchForExtensions = DONE_SUFFIXES;
  2732. }
  2733. // don't try a 404 srch if we are still trying suffixes
  2734. if (dwSearchForExtensions == SCAN_SUFFIXES)
  2735. dwDo404Search = NEVERSEARCH;
  2736. {
  2737. DWORD dwOptions;
  2738. if (SUCCEEDED(_GetRequestFlagFromPIB(pib, &dwOptions)))
  2739. {
  2740. if (dwOptions & INTERNET_REQFLAG_VIA_PROXY)
  2741. {
  2742. bOnProxy = TRUE;
  2743. }
  2744. }
  2745. else
  2746. {
  2747. TraceMsg(TF_SHDNAVIGATE, "DOH::BSC::_HFNS() QI to IWinInetInfo failed");
  2748. }
  2749. }
  2750. TraceMsg(TF_SHDNAVIGATE, "DOH::BSC::_HFNS() search = %d, do404 = %d, onproxy = %d, szSearch = %s", dwSearchForExtensions, dwDo404Search, bOnProxy, SAFETRACE(szSearchFormatStr));
  2751. // Prepare to do an automatic search if the navigation failed
  2752. // and we think a search might be valuable.
  2753. // These cases are:
  2754. // (1) if the previous navigation was search-generated (bContinue)
  2755. // (2) the user allows searching (bAllow)
  2756. // (3) we are searching for extensions or autosearching
  2757. // (4) this is a status code we allow searching for
  2758. // (5) if over proxy, continue searching even on 404
  2759. // Note: 404 is special; it is the case that most servers return this if
  2760. // the documnet is not there, but Proxies also return this if the server
  2761. // was not found - a conditon which normally makes us search. This means
  2762. // that a 404 over proxy actually causes a search to occur, which is not
  2763. // what we want.
  2764. // Is there any way I can tell the difference?
  2765. bPrepareForSearch = ((bContinueSearch || (bAllowSearch)) &&
  2766. (fAutoScan || SHOULD_DO_SEARCH(dwSearchForExtensions, dwDo404Search)) &&
  2767. DO_SEARCH_ON_STATUSCODE(dwStatusCode) &&
  2768. (!bOnProxy || pdoh->_fDocCanNavigate || (dwStatusCode == HTTP_STATUS_NOT_FOUND)));
  2769. if (bPrepareForSearch)
  2770. {
  2771. TraceMsg(TF_SHDNAVIGATE, "DOH::BSC::_HFNS() Preparing for Search...");
  2772. HRESULT hr = S_OK;
  2773. // If we don't have the url we are searching, get it from the addressbar
  2774. if (!fAutoScan)
  2775. hr = _GetSearchString(pdoh->_psp, &varURL);
  2776. if (S_OK!=hr && pdoh->_fDocCanNavigate)
  2777. {
  2778. hr = VariantCopy(&varURL, &pdoh->_varUserEnteredUrl);
  2779. }
  2780. // If we have completed the autoscan, see if there is a special error page that
  2781. // we should display.
  2782. VARIANT varScanFailure = {0};
  2783. if (SUCCEEDED(hr) &&
  2784. dwSearchForExtensions == DONE_SUFFIXES &&
  2785. SUCCEEDED(_GetScanFailureUrl(pdoh->_psp, &varScanFailure)))
  2786. {
  2787. bDoSearch = TRUE;
  2788. }
  2789. else if (SUCCEEDED(hr) &&
  2790. (dwSearchForExtensions == SCAN_SUFFIXES || dwDo404Search == ALWAYSSEARCH))
  2791. {
  2792. bDoSearch = TRUE;
  2793. }
  2794. else
  2795. {
  2796. bDoSearch = FALSE;
  2797. }
  2798. bAskUser = FALSE;
  2799. TraceMsg(TF_SHDNAVIGATE, "DOH::BSC::_HFNS() typedurl = %s, ask = %d, dosearch = %d", varURL.bstrVal, bAskUser, bDoSearch);
  2800. // Don't prompt user if there is an extension, since we are going to
  2801. // not scan anyway.
  2802. if (bDoSearch)
  2803. {
  2804. PARSEDURL pu;
  2805. pu.cbSize = SIZEOF(PARSEDURL);
  2806. if (ParseURL(varURL.bstrVal, &pu) == URL_E_INVALID_SYNTAX)
  2807. {
  2808. // only if this is not a valid URL, should we try to do this searching
  2809. // but try to avoid the case of typos like http;//something.something.com
  2810. // The malformed URL case
  2811. if (!fAutoSearching &&
  2812. (//StrChrI(varURL.bstrVal, L'.') ||
  2813. StrChrI(varURL.bstrVal, L'/') ||
  2814. StrChrI(varURL.bstrVal, L' '))
  2815. )
  2816. {
  2817. bAskUser = FALSE;
  2818. bDoSearch = FALSE;
  2819. }
  2820. }
  2821. else
  2822. {
  2823. bAskUser = FALSE;
  2824. bDoSearch = FALSE;
  2825. }
  2826. }
  2827. TCHAR szT[MAX_URL_STRING + SEARCHPREFIXLENGTH];
  2828. DWORD cchT = SIZECHARS(szT);
  2829. // Bug 35354 has been resolved "not repro" because the dialog below
  2830. // currently cannot ever be displayed (there is no way for bAskUser to
  2831. // be true in the following conditional). If that changes, then that bug
  2832. // needs to get fixed.
  2833. if (bAskUser)
  2834. {
  2835. PrepareURLForDisplay(varURL.bstrVal, szT, &cchT);
  2836. // If we ask the user, make sure we don't display another
  2837. // error dialog.
  2838. *pfShouldDisplayError = FALSE;
  2839. // S_OK means we handled any popups; if we return an error,
  2840. // the caller may display an error dialog
  2841. hres = S_OK;
  2842. if (!bSuppressUI && IDYES == IE_ErrorMsgBox(NULL, pdoh->_hwnd, hrDisplay, szError, szT, IDS_CANTFINDURL, MB_YESNO|MB_ICONSTOP))
  2843. {
  2844. bDoSearch = TRUE;
  2845. }
  2846. else
  2847. {
  2848. _SetSearchInfo(pdoh, 0, FALSE, FALSE, FALSE); // reset info
  2849. bDoSearch = FALSE;
  2850. }
  2851. }
  2852. if (bDoSearch)
  2853. {
  2854. if (dwSearchForExtensions && dwSearchForExtensions != DONE_SUFFIXES)
  2855. {
  2856. wnsprintf(szT, ARRAYSIZE(szT), szSearchFormatStr, varURL.bstrVal);
  2857. if (!fAutoSearching)
  2858. {
  2859. _ValidateURL(szT, UQF_DEFAULT);
  2860. }
  2861. if (fAddMRU)
  2862. _UpdateMRU(pdoh, szT);
  2863. }
  2864. else if (VT_BSTR == varScanFailure.vt && NULL != varScanFailure.bstrVal)
  2865. {
  2866. StrCpyN(szT, varScanFailure.bstrVal, ARRAYSIZE(szT));
  2867. _ValidateURL(szT, UQF_DEFAULT);
  2868. _DontAddToMRU(pdoh);
  2869. }
  2870. else if (dwDo404Search)
  2871. {
  2872. // add the search prefix
  2873. StrCpyN(szT, TEXT("? "), ARRAYSIZE(szT));
  2874. StrCatBuff(szT, varURL.bstrVal, ARRAYSIZE(szT));
  2875. _DontAddToMRU(pdoh);
  2876. }
  2877. else
  2878. {
  2879. ASSERT(0);
  2880. }
  2881. if (dwSearchForExtensions && dwSearchForExtensions != DONE_SUFFIXES)
  2882. _SetSearchInfo(pdoh, ++dwSuffixIndex, FALSE, TRUE, FALSE);
  2883. else if (dwDo404Search)
  2884. _SetSearchInfo(pdoh, dwSuffixIndex, FALSE, FALSE, TRUE);
  2885. else
  2886. _SetSearchInfo(pdoh, 0, FALSE, FALSE, FALSE);
  2887. // If we're called from Trident (fFromTrident == TRUE), then we're going to call
  2888. // IHTMLPrivateWindow::SuperNavigate(). In that case, the call to _CancelPendingNavigation
  2889. // below needs to be synchronous. However, if we're going to call _DoAsyncNavigation,
  2890. // then the call to _CancelPendingNavigation needs to remain asynchronous.
  2891. //
  2892. if (!pdoh->_fCanceledByBrowser)
  2893. pdoh->_CancelPendingNavigation(FALSE, fFromTrident);
  2894. TraceMsg(TF_SHDNAVIGATE, "DOH::BSC::_HFNS() Doing search on %s", szT);
  2895. DWORD cchT = SIZECHARS(szT);
  2896. //
  2897. // if we can find a search context living in a host somewhere,
  2898. // then we need to pass that into ParseUrlFromOutsideSource
  2899. // because it'll use it to customize the behavior of
  2900. // the search hooks if a search ends up happening
  2901. //
  2902. ISearchContext * pSC = NULL;
  2903. pdoh->QueryService(SID_STopWindow, IID_ISearchContext, (void **)&pSC);
  2904. ParseURLFromOutsideSourceWithContextW(szT, szT, &cchT, NULL, pSC);
  2905. if (pSC != NULL)
  2906. {
  2907. pSC->Release();
  2908. }
  2909. if (fFromTrident)
  2910. {
  2911. BSTR bstrUrl = SysAllocString(szT);
  2912. IHTMLPrivateWindow * pPrivWindow = NULL;
  2913. ASSERT(pdoh->_fDocCanNavigate);
  2914. ASSERT(pdoh->_pHTMLWindow);
  2915. // The navigation state is already reset by cancelpending navigation
  2916. // causing either trident to cancel pending navigation or by OnStopBinding
  2917. /*
  2918. if (pdoh->_pwb)
  2919. pdoh->_pwb->SetNavigateState(BNS_NORMAL);
  2920. */
  2921. hres = pdoh->_pHTMLWindow->QueryInterface(IID_IHTMLPrivateWindow,
  2922. (void**)&pPrivWindow);
  2923. if (SUCCEEDED(hres))
  2924. {
  2925. hres = pPrivWindow->SuperNavigate(bstrUrl, NULL, NULL, NULL, NULL, NULL, 0);
  2926. pPrivWindow->Release();
  2927. }
  2928. SysFreeString(bstrUrl);
  2929. }
  2930. else
  2931. {
  2932. pdoh->_DoAsyncNavigation(szT);
  2933. }
  2934. pdoh->_fCanceledByBrowser = TRUE;
  2935. *pfShouldDisplayError = FALSE; // Don't display another dialog
  2936. hres = S_OK; // we did a navigate
  2937. }
  2938. VariantClear(&varScanFailure);
  2939. }
  2940. else if (bSentToEngine && !bSuppressUI)
  2941. {
  2942. *pfShouldDisplayError = FALSE;
  2943. _SetSearchInfo(pdoh, 0, FALSE, FALSE, FALSE);
  2944. IE_ErrorMsgBox(NULL, pdoh->_hwnd, hrDisplay, szError, szURL, IDS_CANTFINDSEARCH, MB_OK|MB_ICONSTOP);
  2945. hres = S_OK;
  2946. }
  2947. VariantClear(&varURL);
  2948. return hres;
  2949. } // _HandleFailedNavigationSearch()