Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1579 lines
49 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright(c) Microsoft Corp., 1999 **
  4. //*********************************************************************
  5. //
  6. // MAINPANE.CPP - Implementation of CObShellMainPane
  7. //
  8. // HISTORY:
  9. //
  10. // 1/27/99 a-jaswed Created.
  11. //
  12. // Class which will create a window, attach and instance of ObWebBrowser,
  13. // and then provide several specialized interfaces to alter the content of the doc
  14. #include "mainpane.h"
  15. #include "appdefs.h"
  16. #include "commerr.h"
  17. #include "dispids.h"
  18. #include "shlobj.h"
  19. #include "util.h"
  20. #include <assert.h>
  21. #include <shlwapi.h>
  22. #include <wininet.h>
  23. // From MSOBMAIN.DLL
  24. BOOL WINAPI IsOemVer();
  25. //Dialing error callbacks
  26. #define SCRIPTFN_ONDIALINGERROR L"OnDialingError(%i)"
  27. #define SCRIPTFN_ONSERVERERROR L"OnServerError(%i)"
  28. #define SCRIPTFN_ONDIALING L"OnDialing()"
  29. #define SCRIPTFN_ONCONNECTING L"OnConnecting()"
  30. #define SCRIPTFN_ONCONNECTED L"OnConnected()"
  31. #define SCRIPTFN_ONDOWNLOADING L"OnDownloading()"
  32. #define SCRIPTFN_ONDISCONNECT L"OnDisconnect()"
  33. //ICS error callback(s)
  34. #define SCRIPTFN_ONICSCONNECTIONSTATUS _T("OnIcsConnectionStatus(%i)")
  35. // Dialing error callbacks for Migration
  36. #define SCRIPTFN_ONDIALINGERROREX L"OnDialingErrorEx(%i)"
  37. #define SCRIPTFN_ONSERVERERROREX L"OnServerErrorEx(%i)"
  38. #define SCRIPTFN_ONDIALINGEX L"OnDialingEx()"
  39. #define SCRIPTFN_ONCONNECTINGEX L"OnConnectingEx()"
  40. #define SCRIPTFN_ONCONNECTEDEX L"OnConnectedEx()"
  41. #define SCRIPTFN_ONDOWNLOADINGEX L"OnDownloadingEx()"
  42. #define SCRIPTFN_ONDISCONNECTEX L"OnDisconnectEx()"
  43. #define SCRIPTFN_ONISPDOWNLOADCOMPLETEEX L"OnISPDownloadCompleteEx(\"%s\")"
  44. #define SCRIPTFN_ONREFDOWNLOADCOMPLETEEX L"OnRefDownloadCompleteEx(%i)"
  45. #define SCRIPTFN_ONREFDOWNLOADPROGRESSEX L"OnRefDownloadProgressEx(%i)"
  46. // USB device arrival
  47. #define SCRIPTFN_ONDEVICEARRIVAL L"OnDeviceArrival(%i)"
  48. //Statuspane callbacks
  49. #define SCRIPTFN_ADDSTATUSITEM L"AddStatusItem(\"%s\", %i)"
  50. #define SCRIPTFN_REMOVESTATUSITEM L"RemoveStatusItem(%i)"
  51. #define SCRIPTFN_SELECTSTATUSITEM L"SelectStatusItem(%i)"
  52. // Agent help
  53. #define SCRIPTFN_ONHELP L"OnHelp()"
  54. #define USES_EX(t) (CONNECTED_REGISTRATION != t)
  55. BOOL ConvertToScript(const WCHAR* pSz, WCHAR* pszUrlOut, INT uSize)
  56. {
  57. WCHAR sztemp[INTERNET_MAX_URL_LENGTH] = L"\0";//L"file://";
  58. WCHAR* szOut = sztemp;
  59. BOOL bRet = FALSE;
  60. if (!pszUrlOut || !pSz)
  61. return bRet;
  62. szOut += lstrlen(sztemp);
  63. while (*pSz )
  64. {
  65. *szOut++ = *pSz++;
  66. if(*pSz == L'\\')
  67. {
  68. *szOut++ = L'\\';
  69. }
  70. }
  71. if (uSize >= lstrlen(pSz))
  72. {
  73. lstrcpy(pszUrlOut, sztemp);
  74. bRet = TRUE;
  75. }
  76. return bRet;
  77. }
  78. ///////////////////////////////////////////////////////////
  79. //
  80. // Creation function used by CFactory.
  81. //
  82. HRESULT CObShellMainPane::CreateInstance (IUnknown* pOuterUnknown,
  83. CUnknown** ppNewComponent)
  84. {
  85. if (pOuterUnknown != NULL)
  86. {
  87. // Don't allow aggregation. Just for the heck of it.
  88. return CLASS_E_NOAGGREGATION;
  89. }
  90. *ppNewComponent = new CObShellMainPane(pOuterUnknown);
  91. return S_OK;
  92. }
  93. ///////////////////////////////////////////////////////////
  94. //
  95. // NondelegatingQueryInterface
  96. //
  97. HRESULT __stdcall
  98. CObShellMainPane::NondelegatingQueryInterface(const IID& iid, void** ppv)
  99. {
  100. if (iid == IID_IObShellMainPane)
  101. {
  102. return FinishQI(static_cast<IObShellMainPane*>(this), ppv);
  103. }
  104. if( (iid == DIID_DWebBrowserEvents2) ||
  105. (iid == IID_IDispatch))
  106. {
  107. return FinishQI(static_cast<DWebBrowserEvents2*>(this), ppv);
  108. }
  109. else
  110. {
  111. return CUnknown::NondelegatingQueryInterface(iid, ppv);
  112. }
  113. }
  114. ///////////////////////////////////////////////////////////
  115. //
  116. // Constructor
  117. //
  118. CObShellMainPane::CObShellMainPane(IUnknown* pOuterUnknown)
  119. : CUnknown(pOuterUnknown)
  120. {
  121. IUnknown* pUnk = NULL;
  122. m_cStatusItems = 0;
  123. m_dwAppMode = 0;
  124. m_hMainWnd = NULL;
  125. m_pObWebBrowser = NULL;
  126. m_pDispEvent = NULL;
  127. m_bstrBaseUrl = SysAllocString(L"\0");
  128. m_pIFrmStatPn = NULL;
  129. m_pPageIDForm = NULL;
  130. m_pBackForm = NULL;
  131. m_pPageTypeForm = NULL;
  132. m_pNextForm = NULL;
  133. m_pPageFlagForm = NULL;
  134. //Try to CoCreate ObWebBrowser
  135. if(FAILED(CoCreateInstance(CLSID_ObWebBrowser,
  136. NULL,
  137. CLSCTX_INPROC_SERVER,
  138. IID_IObWebBrowser,
  139. (LPVOID*)&m_pObWebBrowser)))
  140. {
  141. m_pObWebBrowser = NULL;
  142. }
  143. //Let's try to register us as a listener for WebBrowserEvents
  144. if(SUCCEEDED(QueryInterface(IID_IUnknown, (LPVOID*)&pUnk)) && pUnk)
  145. {
  146. HRESULT hr = m_pObWebBrowser->ListenToWebBrowserEvents(pUnk);
  147. pUnk->Release();
  148. pUnk = NULL;
  149. }
  150. }
  151. ///////////////////////////////////////////////////////////
  152. //
  153. // Destructor
  154. //
  155. CObShellMainPane::~CObShellMainPane()
  156. {
  157. if(m_pObWebBrowser)
  158. {
  159. m_pObWebBrowser->Release();
  160. m_pObWebBrowser = NULL;
  161. }
  162. if (m_pIFrmStatPn)
  163. {
  164. delete m_pIFrmStatPn;
  165. }
  166. }
  167. ///////////////////////////////////////////////////////////
  168. //
  169. // FinalRelease -- Clean up the aggreated objects.
  170. //
  171. void CObShellMainPane::FinalRelease()
  172. {
  173. CUnknown::FinalRelease();
  174. }
  175. ///////////////////////////////////////////////////////////
  176. // IObShellMainPane Implementation
  177. ///////////////////////////////////////////////////////////
  178. ///////////////////////////////////////////////////////////
  179. // CreatePane
  180. //
  181. HRESULT CObShellMainPane::CreateMainPane(HANDLE_PTR hInstance, HWND hwndParent, RECT* prectWindowSize, BSTR bstrStartPage)
  182. {
  183. WNDCLASS wc;
  184. //If we don't have an ObWebBrowser, we are seriously messed up,
  185. //fail so the caller will know what's up.
  186. assert(m_pObWebBrowser);
  187. if(!m_pObWebBrowser)
  188. return E_FAIL;
  189. ZeroMemory((PVOID)&wc, sizeof(WNDCLASS));
  190. wc.style = CS_HREDRAW | CS_VREDRAW;
  191. wc.lpszClassName = OBSHEL_MAINPANE_CLASSNAME;
  192. wc.lpfnWndProc = (WNDPROC)&MainPaneWndProc;
  193. wc.hInstance = (HINSTANCE)hInstance;
  194. wc.hCursor = LoadCursor(NULL,IDC_ARROW);
  195. // Millen Bug 134831 03/03/00 OOBE2: Trident Does not Repaint in Mouse Tutorial
  196. // Fixed: setting the brush to Null let trident repaint the grey area
  197. // Removed: wc.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
  198. wc.hbrBackground = NULL;
  199. RegisterClass(&wc);
  200. m_hMainWnd = CreateWindow(OBSHEL_MAINPANE_CLASSNAME,
  201. OBSHEL_MAINPANE_WINDOWNAME,
  202. WS_CHILD,
  203. prectWindowSize->left,
  204. prectWindowSize->top,
  205. prectWindowSize->right,
  206. prectWindowSize->bottom,
  207. hwndParent,
  208. NULL,
  209. wc.hInstance,
  210. NULL);
  211. m_hwndParent = hwndParent;
  212. m_hInstance = (HINSTANCE)hInstance;
  213. //If we don't have an hwnd, once again we are seriously messed up,
  214. //fail so the caller will know what's up.
  215. assert(m_pObWebBrowser);
  216. if(!m_hMainWnd)
  217. return E_FAIL;
  218. //Hook the WebOC up to the window
  219. m_pObWebBrowser->AttachToWindow(m_hMainWnd);
  220. HINSTANCE hInst = LoadLibrary(OOBE_SHELL_DLL);
  221. if (hInst)
  222. {
  223. BOOL bRet;
  224. WCHAR szUrl [MAX_PATH*3] = L"file://";
  225. int cchUrl = lstrlen(szUrl);
  226. // Bail out if we can't find the directory with our files. Should be
  227. // %windir%\system32\oobe.
  228. //
  229. if ((APMD_ACT == m_dwAppMode) ||
  230. (APMD_MSN == m_dwAppMode) && !IsOemVer())
  231. {
  232. bRet = GetOOBEMUIPath(szUrl + cchUrl);
  233. } else {
  234. bRet = GetOOBEPath(szUrl + cchUrl);
  235. }
  236. if (! bRet)
  237. {
  238. return E_FAIL;
  239. }
  240. // append trailing backslash and appropriate file name
  241. //
  242. lstrcat(szUrl, L"\\");
  243. lstrcat(szUrl, bstrStartPage);
  244. FreeLibrary(hInst);
  245. m_pObWebBrowser->Navigate(szUrl, NULL);
  246. }
  247. // Create the status pane obj
  248. if(APMD_OOBE == m_dwAppMode)
  249. {
  250. if (NULL != (m_pIFrmStatPn = new CIFrmStatusPane()))
  251. m_pIFrmStatPn->InitStatusPane(m_pObWebBrowser);
  252. }
  253. return S_OK;
  254. }
  255. ///////////////////////////////////////////////////////////
  256. // DestroyMainPane
  257. //
  258. HRESULT CObShellMainPane::DestroyMainPane()
  259. {
  260. IUnknown* pUnk = NULL;
  261. if (m_pPageIDForm)
  262. {
  263. m_pPageIDForm->Release();
  264. m_pPageIDForm = NULL;
  265. }
  266. if (m_pBackForm)
  267. {
  268. m_pBackForm->Release();
  269. m_pBackForm = NULL;
  270. }
  271. if (m_pPageTypeForm)
  272. {
  273. m_pPageTypeForm->Release();
  274. m_pPageTypeForm = NULL;
  275. }
  276. if (m_pNextForm)
  277. {
  278. m_pNextForm->Release();
  279. m_pNextForm = NULL;
  280. }
  281. if (m_pPageFlagForm)
  282. {
  283. m_pPageFlagForm->Release();
  284. m_pPageFlagForm = NULL;
  285. }
  286. if(m_pDispEvent)
  287. {
  288. m_pDispEvent->Release();
  289. m_pDispEvent = NULL;
  290. }
  291. //Let's try to unregister us as a listener for WebBrowserEvents
  292. if(SUCCEEDED(QueryInterface(IID_IUnknown, (LPVOID*)&pUnk)) && pUnk)
  293. {
  294. HRESULT hr = m_pObWebBrowser->StopListeningToWebBrowserEvents(pUnk);
  295. pUnk->Release();
  296. pUnk = NULL;
  297. }
  298. return S_OK;
  299. }
  300. ///////////////////////////////////////////////////////////
  301. // SetAppMode
  302. //
  303. HRESULT CObShellMainPane::SetAppMode(DWORD dwAppMode)
  304. {
  305. m_dwAppMode = dwAppMode;
  306. return S_OK;
  307. }
  308. ///////////////////////////////////////////////////////////
  309. // MainPaneShowWindow
  310. //
  311. HRESULT CObShellMainPane::MainPaneShowWindow()
  312. {
  313. ShowWindow(m_hMainWnd, SW_SHOW);
  314. if(m_pObWebBrowser)
  315. m_pObWebBrowser->ObWebShowWindow();
  316. return S_OK;
  317. }
  318. ///////////////////////////////////////////////////////////
  319. // PreTranslateMessage
  320. //
  321. HRESULT CObShellMainPane::PreTranslateMessage(LPMSG lpMsg)
  322. {
  323. if(m_pObWebBrowser)
  324. return m_pObWebBrowser->PreTranslateMessage(lpMsg);
  325. return S_FALSE;
  326. }
  327. ///////////////////////////////////////////////////////////
  328. // Navigate
  329. //
  330. HRESULT CObShellMainPane::Navigate(WCHAR* pszUrl)
  331. {
  332. TRACE1(L"Attempting to navigate to %s\n", pszUrl);
  333. if(m_pObWebBrowser)
  334. {
  335. m_pObWebBrowser->Navigate(pszUrl, DEFAULT_FRAME_NAME);
  336. }
  337. return S_OK;
  338. }
  339. HRESULT CObShellMainPane::AddStatusItem(BSTR bstrText,int iIndex)
  340. {
  341. m_cStatusItems++;
  342. return m_pIFrmStatPn->AddItem(bstrText, iIndex + 1);
  343. }
  344. HRESULT CObShellMainPane::RemoveStatusItem(int iIndex)
  345. {
  346. return S_OK;
  347. }
  348. HRESULT CObShellMainPane::SelectStatusItem(int iIndex)
  349. {
  350. m_pIFrmStatPn->SelectItem(iIndex + 1);
  351. return S_OK;
  352. }
  353. HRESULT CObShellMainPane::ExtractUnHiddenText(BSTR* pbstrText)
  354. {
  355. VARIANT vIndex;
  356. LPDISPATCH pDisp;
  357. IHTMLInputHiddenElement* pHidden;
  358. IHTMLElement* pElement;
  359. BSTR bstrValue;
  360. VARIANT var2 = { 0 };
  361. long lLen = 0;
  362. vIndex.vt = VT_UINT;
  363. bstrValue = SysAllocString(L"\0");
  364. //Walk();
  365. if (!m_pNextForm)
  366. return E_UNEXPECTED;
  367. m_pNextForm->get_length(&lLen);
  368. for (int i = 0; i < lLen; i++)
  369. {
  370. vIndex.lVal = i;
  371. pDisp = NULL;
  372. if(SUCCEEDED(m_pNextForm->item(vIndex, var2, &pDisp)) && pDisp)
  373. {
  374. pHidden = NULL;
  375. if(SUCCEEDED(pDisp->QueryInterface(IID_IHTMLInputHiddenElement, (LPVOID*)&pHidden)) && pHidden)
  376. {
  377. pHidden->put_value(bstrValue);
  378. pHidden->Release();
  379. }
  380. pDisp->Release();
  381. }
  382. }
  383. if (SUCCEEDED(m_pNextForm->QueryInterface(IID_IHTMLElement, (LPVOID*)&pElement)) && pElement)
  384. pElement->get_innerHTML(pbstrText);
  385. SysFreeString(bstrValue);
  386. return S_OK;
  387. }
  388. HRESULT CObShellMainPane::get_IsQuickFinish(BOOL* pbIsQuickFinish)
  389. {
  390. if (!m_pPageTypeForm)
  391. return (E_FAIL);
  392. IHTMLElement* pElement = NULL;
  393. VARIANT varValue;
  394. VariantInit(&varValue);
  395. V_VT(&varValue) = VT_BSTR;
  396. *pbIsQuickFinish = FALSE;
  397. if (SUCCEEDED(m_pPageTypeForm->QueryInterface(IID_IHTMLElement, (void**)&pElement)))
  398. {
  399. if (SUCCEEDED(pElement->getAttribute(L"QUICKFINISH", FALSE, &varValue)))
  400. {
  401. if (VT_NULL != varValue.vt)
  402. {
  403. if(lstrcmpi(varValue.bstrVal, L"TRUE") == 0)
  404. *pbIsQuickFinish = TRUE;
  405. }
  406. }
  407. pElement->Release();
  408. }
  409. return S_OK;
  410. }
  411. HRESULT CObShellMainPane::get_PageType(LPDWORD pdwPageType)
  412. {
  413. BSTR bstrType;
  414. HRESULT hr;
  415. if (!m_pPageTypeForm)
  416. return (E_FAIL);
  417. *pdwPageType = PAGETYPE_UNDEFINED;
  418. // Get the Action for the PageType Form
  419. hr = m_pPageTypeForm->get_action(&bstrType);
  420. if (SUCCEEDED(hr))
  421. {
  422. // See what kind it is
  423. if (lstrcmpi(bstrType, cszPageTypeTERMS) == 0)
  424. *pdwPageType = PAGETYPE_ISP_TOS;
  425. else if (lstrcmpi(bstrType, cszPageTypeCUSTOMFINISH) == 0)
  426. *pdwPageType = PAGETYPE_ISP_CUSTOMFINISH;
  427. else if (lstrcmpi(bstrType, cszPageTypeFINISH) == 0)
  428. *pdwPageType = PAGETYPE_ISP_FINISH;
  429. else if (lstrcmpi(bstrType, cszPageTypeNORMAL) == 0)
  430. *pdwPageType = PAGETYPE_ISP_NORMAL;
  431. else
  432. *pdwPageType = PAGETYPE_UNDEFINED;
  433. SysFreeString(bstrType);
  434. }
  435. return (hr);
  436. }
  437. HRESULT CObShellMainPane::get_PageFlag(LPDWORD pdwPageFlag)
  438. {
  439. BSTR bstrFlag;
  440. HRESULT hr;
  441. *pdwPageFlag = 0;
  442. if (!m_pPageFlagForm)
  443. return (E_FAIL);
  444. // Get the Action for the PageFlag Form
  445. hr = m_pPageFlagForm->get_action(&bstrFlag);
  446. if (SUCCEEDED(hr))
  447. {
  448. // See what kind it is
  449. *pdwPageFlag = _wtol(bstrFlag);
  450. SysFreeString(bstrFlag);
  451. }
  452. return S_OK;
  453. }
  454. HRESULT CObShellMainPane::get_PageID(BSTR *pbstrPageID)
  455. {
  456. HRESULT hr;
  457. if (!m_pPageIDForm)
  458. return (E_FAIL);
  459. if (!pbstrPageID)
  460. return (E_FAIL);
  461. // Get the Action for the PageType Form
  462. hr = m_pPageIDForm->get_action(pbstrPageID);
  463. return (hr);
  464. }
  465. HRESULT CObShellMainPane::getQueryString
  466. (
  467. IHTMLFormElement *pForm,
  468. LPWSTR lpszQuery
  469. )
  470. {
  471. HRESULT hr;
  472. long lFormLength;
  473. if (SUCCEEDED(pForm->get_length(&lFormLength)))
  474. {
  475. for (int i = 0; i < lFormLength; i++)
  476. {
  477. VARIANT vIndex;
  478. vIndex.vt = VT_UINT;
  479. vIndex.lVal = i;
  480. VARIANT var2 = { 0 };
  481. LPDISPATCH pDisp;
  482. if (SUCCEEDED(hr = pForm->item( vIndex, var2, &pDisp )))
  483. {
  484. // See if the Item is a Input button
  485. IHTMLButtonElement* pButton = NULL;
  486. IHTMLInputButtonElement* pInputButton = NULL;
  487. IHTMLInputFileElement* pInputFile = NULL;
  488. IHTMLInputHiddenElement* pInputHidden = NULL;
  489. IHTMLInputTextElement* pInputText = NULL;
  490. IHTMLSelectElement* pSelect = NULL;
  491. IHTMLTextAreaElement* pTextArea = NULL;
  492. IHTMLOptionButtonElement* pOptionButton = NULL;
  493. // First check to see if this is an OptionButton.
  494. if (SUCCEEDED(hr = pDisp->QueryInterface( IID_IHTMLOptionButtonElement, (LPVOID*)&pOptionButton )))
  495. {
  496. BSTR bstrType = NULL;
  497. // See if it is a Radio or a CheckBox
  498. if (SUCCEEDED(pOptionButton->get_type(&bstrType)))
  499. {
  500. if ((lstrcmpi(bstrType, L"radio") == 0) || (lstrcmpi(bstrType, L"checkbox") == 0))
  501. {
  502. short bChecked;
  503. // See if the button is checked. If it is, then it needs to be
  504. // added to the query string
  505. if (SUCCEEDED(pOptionButton->get_checked(&bChecked)))
  506. {
  507. if(bChecked)
  508. {
  509. BSTR bstrName;
  510. BSTR bstrValue;
  511. if ( SUCCEEDED(pOptionButton->get_name(&bstrName)) &&
  512. SUCCEEDED(pOptionButton->get_value(&bstrValue)) )
  513. {
  514. if (bstrValue)
  515. {
  516. size_t size = BYTES_REQUIRED_BY_SZ(bstrValue);
  517. WCHAR* szVal = (WCHAR*)malloc(size * 3);
  518. if (szVal)
  519. {
  520. memcpy(szVal, bstrValue, size);
  521. URLEncode(szVal, size * 3);
  522. URLAppendQueryPair(lpszQuery, bstrName, szVal);
  523. // Cleanup
  524. free(szVal);
  525. }
  526. SysFreeString(bstrName);
  527. SysFreeString(bstrValue);
  528. }
  529. }
  530. }
  531. }
  532. }
  533. SysFreeString(bstrType);
  534. }
  535. // Release the interface
  536. pOptionButton->Release();
  537. continue;
  538. }
  539. // For the rest we need to form Name=Value pairs
  540. if (SUCCEEDED(hr = pDisp->QueryInterface( IID_IHTMLButtonElement, (LPVOID*)&pButton )))
  541. {
  542. BSTR bstrName;
  543. BSTR bstrValue;
  544. if (SUCCEEDED(pButton->get_name(&bstrName)) &&
  545. SUCCEEDED(pButton->get_value(&bstrValue)) )
  546. {
  547. if (bstrValue)
  548. {
  549. size_t size = BYTES_REQUIRED_BY_SZ(bstrValue);
  550. WCHAR* szVal = (WCHAR*)malloc(size * 3);
  551. if (szVal)
  552. {
  553. memcpy(szVal, bstrValue, size);
  554. URLEncode(szVal, size * 3);
  555. URLAppendQueryPair(lpszQuery, bstrName, szVal);
  556. // Cleanup
  557. free(szVal);
  558. }
  559. SysFreeString(bstrName);
  560. SysFreeString(bstrValue);
  561. }
  562. }
  563. // Release the interface pointer
  564. pButton->Release();
  565. continue;
  566. }
  567. if (SUCCEEDED(hr = pDisp->QueryInterface( IID_IHTMLInputFileElement, (LPVOID*)&pInputFile )))
  568. {
  569. BSTR bstrName;
  570. BSTR bstrValue;
  571. if (SUCCEEDED(pInputFile->get_name(&bstrName)) &&
  572. SUCCEEDED(pInputFile->get_value(&bstrValue)) )
  573. {
  574. if (bstrValue)
  575. {
  576. size_t size = BYTES_REQUIRED_BY_SZ(bstrValue);
  577. WCHAR* szVal = (WCHAR*)malloc(size * 3);
  578. if (szVal)
  579. {
  580. memcpy(szVal, bstrValue, size);
  581. URLEncode(szVal, size * 3);
  582. URLAppendQueryPair(lpszQuery, bstrName, szVal);
  583. // Cleanup
  584. free(szVal);
  585. }
  586. SysFreeString(bstrName);
  587. SysFreeString(bstrValue);
  588. }
  589. }
  590. // Release the interface pointer
  591. pInputFile->Release();
  592. continue;
  593. }
  594. if (SUCCEEDED(hr = pDisp->QueryInterface( IID_IHTMLInputHiddenElement, (LPVOID*)&pInputHidden )))
  595. {
  596. BSTR bstrName;
  597. BSTR bstrValue;
  598. if (SUCCEEDED(pInputHidden->get_name(&bstrName)) &&
  599. SUCCEEDED(pInputHidden->get_value(&bstrValue)) )
  600. {
  601. if (bstrValue)
  602. {
  603. size_t size = BYTES_REQUIRED_BY_SZ(bstrValue);
  604. WCHAR* szVal = (WCHAR*)malloc(size * 3);
  605. if (szVal)
  606. {
  607. memcpy(szVal, bstrValue, size);
  608. URLEncode(szVal, size * 3);
  609. URLAppendQueryPair(lpszQuery, bstrName, szVal);
  610. // Cleanup
  611. free(szVal);
  612. }
  613. SysFreeString(bstrName);
  614. SysFreeString(bstrValue);
  615. }
  616. }
  617. // Release the interface pointer
  618. pInputHidden->Release();
  619. continue;
  620. }
  621. if (SUCCEEDED(hr = pDisp->QueryInterface( IID_IHTMLInputTextElement, (LPVOID*)&pInputText )))
  622. {
  623. BSTR bstrName;
  624. BSTR bstrValue;
  625. if (SUCCEEDED(pInputText->get_name(&bstrName)) &&
  626. SUCCEEDED(pInputText->get_value(&bstrValue)) )
  627. {
  628. if (bstrValue)
  629. {
  630. size_t size = BYTES_REQUIRED_BY_SZ(bstrValue);
  631. WCHAR* szVal = (WCHAR*)malloc(size * 3);
  632. if (szVal)
  633. {
  634. memcpy(szVal, bstrValue, size);
  635. URLEncode(szVal, size * 3);
  636. URLAppendQueryPair(lpszQuery, bstrName, szVal);
  637. // Cleanup
  638. free(szVal);
  639. }
  640. SysFreeString(bstrName);
  641. SysFreeString(bstrValue);
  642. }
  643. }
  644. // Release the interface pointer
  645. pInputText->Release();
  646. continue;
  647. }
  648. if (SUCCEEDED(hr = pDisp->QueryInterface( IID_IHTMLSelectElement, (LPVOID*)&pSelect )))
  649. {
  650. BSTR bstrName;
  651. BSTR bstrValue;
  652. if (SUCCEEDED(pSelect->get_name(&bstrName)) &&
  653. SUCCEEDED(pSelect->get_value(&bstrValue)) )
  654. {
  655. if (bstrValue)
  656. {
  657. size_t size = BYTES_REQUIRED_BY_SZ(bstrValue);
  658. WCHAR* szVal= (WCHAR*)malloc(size * 3);
  659. if (szVal)
  660. {
  661. memcpy(szVal, bstrValue, size);
  662. URLEncode(szVal, size * 3);
  663. URLAppendQueryPair(lpszQuery, bstrName, szVal);
  664. // Cleanup
  665. free(szVal);
  666. }
  667. SysFreeString(bstrName);
  668. SysFreeString(bstrValue);
  669. }
  670. }
  671. // Release the interface pointer
  672. pSelect->Release();
  673. continue;
  674. }
  675. if (SUCCEEDED(hr = pDisp->QueryInterface( IID_IHTMLTextAreaElement, (LPVOID*)&pTextArea )))
  676. {
  677. BSTR bstrName;
  678. BSTR bstrValue;
  679. if (SUCCEEDED(pTextArea->get_name(&bstrName)) &&
  680. SUCCEEDED(pTextArea->get_value(&bstrValue)) )
  681. {
  682. if (bstrValue)
  683. {
  684. size_t size = BYTES_REQUIRED_BY_SZ(bstrValue);
  685. WCHAR* szVal= (WCHAR*)malloc(size * 3);
  686. if (szVal)
  687. {
  688. memcpy(szVal, bstrValue, size);
  689. URLEncode(szVal, size * 3);
  690. URLAppendQueryPair(lpszQuery, bstrName, szVal);
  691. // Cleanup
  692. free(szVal);
  693. }
  694. SysFreeString(bstrName);
  695. SysFreeString(bstrValue);
  696. }
  697. }
  698. // Release the interface pointer
  699. pTextArea->Release();
  700. }
  701. pDisp->Release();
  702. }
  703. }
  704. }
  705. // Null out the last Ampersand, since we don't know when we added the last pair, so we got
  706. // a trailing ampersand
  707. lpszQuery[lstrlen(lpszQuery)-1] = L'\0';
  708. return S_OK;
  709. }
  710. // For the URL for the next page
  711. HRESULT CObShellMainPane::get_URL
  712. (
  713. BOOL bForward,
  714. BSTR *pbstrReturnURL
  715. )
  716. {
  717. HRESULT hr = S_OK;
  718. BSTR bstrURL;
  719. WCHAR szQuery[INTERNET_MAX_URL_LENGTH];
  720. WCHAR szURL[INTERNET_MAX_URL_LENGTH];
  721. IHTMLFormElement * pForm = bForward ? get_pNextForm() : get_pBackForm();
  722. if (!pForm || !pbstrReturnURL)
  723. return (E_FAIL);
  724. // Get the Action for the Next Form
  725. hr = pForm->get_action(&bstrURL);
  726. if (SUCCEEDED(hr))
  727. {
  728. memset(szQuery, 0, sizeof(szQuery));
  729. lstrcpy(szQuery, cszQuestion);
  730. // Get the Query String
  731. if (SUCCEEDED(getQueryString(pForm, szQuery)))
  732. {
  733. // Catenate the two together into the dest buffer
  734. lstrcpy(szURL, bstrURL);
  735. lstrcat(szURL, szQuery);
  736. }
  737. SysFreeString(bstrURL);
  738. *pbstrReturnURL = SysAllocString(szURL);
  739. }
  740. return hr;
  741. }
  742. HRESULT CObShellMainPane::Walk(BOOL* pbRet)
  743. {
  744. IHTMLElement* pElement = NULL;
  745. IHTMLImgElement* pImage = NULL;
  746. HRESULT hr = E_FAIL;
  747. IDispatch* pDisp = NULL;
  748. IHTMLDocument2* pDoc = NULL;
  749. IHTMLDocument2* pParentDoc = NULL;
  750. IHTMLFramesCollection2* pFrColl = NULL;
  751. IHTMLWindow2* pParentWin = NULL;
  752. IHTMLDocument2* pFrDoc = NULL;
  753. IHTMLWindow2* pFrWin = NULL;
  754. IHTMLElementCollection* pColl = NULL;
  755. if (m_pPageIDForm)
  756. {
  757. m_pPageIDForm->Release();
  758. m_pPageIDForm = NULL;
  759. }
  760. if (m_pBackForm)
  761. {
  762. m_pBackForm->Release();
  763. m_pBackForm = NULL;
  764. }
  765. if (m_pPageTypeForm)
  766. {
  767. m_pPageTypeForm->Release();
  768. m_pPageTypeForm = NULL;
  769. }
  770. if (m_pNextForm)
  771. {
  772. m_pNextForm->Release();
  773. m_pNextForm = NULL;
  774. }
  775. if (m_pObWebBrowser)
  776. {
  777. if(SUCCEEDED(m_pObWebBrowser->get_WebBrowserDoc(&pDisp)) && pDisp)
  778. {
  779. if(SUCCEEDED(pDisp->QueryInterface(IID_IHTMLDocument2, (void**)&pDoc)) && pDoc)
  780. {
  781. if(SUCCEEDED(pDoc->get_parentWindow(&pParentWin)) && pParentWin)
  782. {
  783. if(SUCCEEDED(pParentWin->get_document(&pParentDoc))&& pParentDoc)
  784. {
  785. if(SUCCEEDED(pParentDoc->get_frames(&pFrColl)) && pFrColl)
  786. {
  787. VARIANT varRet;
  788. VARIANTARG varg;
  789. VariantInit(&varg);
  790. V_VT(&varg) = VT_BSTR;
  791. varg.bstrVal= SysAllocString(L"ifrmMainFrame");
  792. if(SUCCEEDED(pFrColl->item(&varg, &varRet)) && varRet.pdispVal)
  793. {
  794. if(SUCCEEDED(varRet.pdispVal->QueryInterface(IID_IHTMLWindow2, (LPVOID*)&pFrWin)) && pFrWin)
  795. {
  796. VARIANT varExec;
  797. VariantInit(&varExec);
  798. if(SUCCEEDED(pFrWin->get_document(&pFrDoc)) && pFrDoc)
  799. {
  800. if(SUCCEEDED(pFrDoc->get_all(&pColl)) && pColl)
  801. {
  802. long cElems;
  803. assert(pColl);
  804. // retrieve the count of elements in the collection
  805. if (SUCCEEDED(hr = pColl->get_length( &cElems )))
  806. {
  807. // for each element retrieve properties such as TAGNAME and HREF
  808. for ( int i=0; i<cElems; i++ )
  809. {
  810. VARIANT vIndex;
  811. vIndex.vt = VT_UINT;
  812. vIndex.lVal = i;
  813. VARIANT var2 = { 0 };
  814. LPDISPATCH pDisp;
  815. if (SUCCEEDED(hr = pColl->item( vIndex, var2, &pDisp )))
  816. {
  817. // Look for <FORM> tags
  818. IHTMLFormElement* pForm = NULL;
  819. if (SUCCEEDED(hr = pDisp->QueryInterface( IID_IHTMLFormElement, (LPVOID*)&pForm )))
  820. {
  821. BSTR bstrName;
  822. assert(pForm);
  823. // Get the Name
  824. hr = pForm->get_name(&bstrName);
  825. if (SUCCEEDED(hr))
  826. {
  827. LPWSTR lpszName = bstrName;
  828. // See what kind it is
  829. if (lstrcmpi(lpszName, cszFormNamePAGEID) == 0)
  830. {
  831. m_pPageIDForm = pForm;
  832. m_pPageIDForm->AddRef();
  833. }
  834. else if (lstrcmpi(lpszName, cszFormNameBACK) == 0)
  835. {
  836. m_pBackForm = pForm;
  837. m_pBackForm->AddRef();
  838. }
  839. else if (lstrcmpi(lpszName, cszFormNamePAGETYPE) == 0)
  840. {
  841. m_pPageTypeForm = pForm;
  842. m_pPageTypeForm->AddRef();
  843. }
  844. else if (lstrcmpi(lpszName, cszFormNameNEXT) == 0)
  845. {
  846. m_pNextForm = pForm;
  847. m_pNextForm->AddRef();
  848. }
  849. else if (lstrcmpi(lpszName, cszFormNamePAGEFLAG) == 0)
  850. {
  851. m_pPageFlagForm = pForm;
  852. m_pPageFlagForm->AddRef();
  853. }
  854. SysFreeString(bstrName);
  855. }
  856. pForm->Release();
  857. }
  858. pDisp->Release();
  859. } // item
  860. } // for
  861. } // get_length
  862. pColl->Release();
  863. pColl->Release();
  864. pColl = NULL;
  865. } // get_all
  866. pFrDoc->Release();
  867. pFrDoc = NULL;
  868. } // get_document
  869. pFrWin->Release();
  870. pFrWin = NULL;
  871. hr = S_OK;
  872. }// QI
  873. varRet.pdispVal->Release();
  874. varRet.pdispVal = NULL;
  875. } //->item
  876. pFrColl->Release();
  877. pFrColl = NULL;
  878. }
  879. pParentDoc->Release();
  880. pParentDoc = NULL;
  881. }
  882. pParentWin->Release();
  883. pParentWin = NULL;
  884. }
  885. pDoc->Release();
  886. pDoc = NULL;
  887. }
  888. pDisp->Release();
  889. pDisp = NULL;
  890. }
  891. }
  892. return hr;
  893. }
  894. HRESULT CObShellMainPane::SaveISPFile(BSTR bstrSrcFileName, BSTR bstrDestFileName)
  895. {
  896. WCHAR szNewFileBuff [MAX_PATH + 1];
  897. WCHAR szWorkingDir [MAX_PATH + 1];
  898. WCHAR szDesktopPath [MAX_PATH + 1];
  899. WCHAR szLocalFile [MAX_PATH + 1];
  900. WCHAR szISPName [1024];
  901. WCHAR szFmt [1024];
  902. WCHAR szNumber [1024];
  903. WCHAR *args [2];
  904. LPWSTR pszInvalideChars = L"\\/:*?\"<>|";
  905. LPVOID pszIntro = NULL;
  906. LPITEMIDLIST lpItemDList = NULL;
  907. HRESULT hr = E_FAIL; //don't assume success
  908. IMalloc *pMalloc = NULL;
  909. BOOL ret = FALSE;
  910. GetCurrentDirectory(MAX_PATH, szWorkingDir);
  911. hr = SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOP,&lpItemDList);
  912. //Get the "DESKTOP" dir
  913. if (SUCCEEDED(hr))
  914. {
  915. SHGetPathFromIDList(lpItemDList, szDesktopPath);
  916. // Free up the memory allocated for LPITEMIDLIST
  917. if (SUCCEEDED (SHGetMalloc (&pMalloc)))
  918. {
  919. pMalloc->Free (lpItemDList);
  920. pMalloc->Release ();
  921. }
  922. }
  923. // Replace invalid file name char in ISP name with underscore
  924. lstrcpy(szISPName, bstrDestFileName);
  925. for( int i = 0; szISPName[i]; i++ )
  926. {
  927. if(wcschr(pszInvalideChars, szISPName[i]))
  928. {
  929. szISPName[i] = L'_';
  930. }
  931. }
  932. // Load the default file name
  933. args[0] = (LPWSTR) szISPName;
  934. args[1] = NULL;
  935. LoadString(m_hInstance, 0, szFmt, MAX_CHARS_IN_BUFFER(szFmt));
  936. FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY,
  937. szFmt,
  938. 0,
  939. 0,
  940. (LPWSTR)&pszIntro,
  941. 0,
  942. (va_list*)args);
  943. lstrcat(szDesktopPath, L"\\");
  944. wsprintf(szLocalFile, L"\"%s\"", (LPWSTR)pszIntro);
  945. lstrcpy(szNewFileBuff, szDesktopPath);
  946. lstrcat(szNewFileBuff, (LPWSTR)pszIntro);
  947. LocalFree(pszIntro);
  948. // Check if file already exists
  949. if (0xFFFFFFFF != GetFileAttributes(szNewFileBuff))
  950. {
  951. // If file exists, create new filename with paranthesis
  952. int nCurr = 1;
  953. do
  954. {
  955. wsprintf(szNumber, L"%d", nCurr++);
  956. args[1] = (LPWSTR) szNumber;
  957. LoadString(m_hInstance, 0, szFmt, MAX_CHARS_IN_BUFFER(szFmt));
  958. FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY,
  959. szFmt,
  960. 0,
  961. 0,
  962. (LPWSTR)&pszIntro,
  963. 0,
  964. (va_list*)args);
  965. lstrcpy(szNewFileBuff, szDesktopPath);
  966. wsprintf(szLocalFile, L"\"%s\"", (LPWSTR)pszIntro);
  967. lstrcat(szNewFileBuff, (LPWSTR)pszIntro);
  968. LocalFree(pszIntro);
  969. } while ((0xFFFFFFFF != GetFileAttributes(szNewFileBuff)) && (nCurr <= 100));
  970. }
  971. // Copy the file to permanent location
  972. HANDLE hFile = CreateFile(szNewFileBuff, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  973. if (hFile != INVALID_HANDLE_VALUE)
  974. {
  975. BSTR bstrText = NULL;
  976. DWORD dwByte = 0;
  977. if (SUCCEEDED(ExtractUnHiddenText(&bstrText)) && bstrText)
  978. {
  979. ret = WriteFile(hFile, bstrText, BYTES_REQUIRED_BY_SZ(bstrText), &dwByte, NULL);
  980. SysFreeString(bstrText);
  981. }
  982. CloseHandle(hFile);
  983. }
  984. return S_OK;
  985. }
  986. HRESULT CObShellMainPane::SetStatusLogo(BSTR bstrPath)
  987. {
  988. return S_OK;
  989. }
  990. HRESULT CObShellMainPane::GetNumberOfStatusItems(int* piTotal)
  991. {
  992. *piTotal = m_cStatusItems;
  993. return S_OK;
  994. }
  995. ///////////////////////////////////////////////////////////
  996. // ListenToMainPaneEvents
  997. //
  998. HRESULT CObShellMainPane::ListenToMainPaneEvents(IUnknown* pUnk)
  999. {
  1000. if (FAILED(pUnk->QueryInterface(IID_IDispatch, (LPVOID*)&m_pDispEvent)) || !m_pDispEvent)
  1001. return E_UNEXPECTED;
  1002. return S_OK;
  1003. }
  1004. ///////////////////////////////////////////////////////////
  1005. // SetExternalInterface
  1006. //
  1007. HRESULT CObShellMainPane::SetExternalInterface(IUnknown* pUnk)
  1008. {
  1009. if(m_pObWebBrowser)
  1010. m_pObWebBrowser->SetExternalInterface(pUnk);
  1011. return S_OK;
  1012. }
  1013. ///////////////////////////////////////////////////////////
  1014. // FireObShellDocumentComplete
  1015. //
  1016. HRESULT CObShellMainPane::FireObShellDocumentComplete()
  1017. {
  1018. VARIANTARG varg;
  1019. VariantInit(&varg);
  1020. varg.vt = VT_I4;
  1021. varg.lVal= S_OK;
  1022. DISPPARAMS disp = { &varg, NULL, 1, 0 };
  1023. if (m_pDispEvent)
  1024. m_pDispEvent->Invoke(DISPID_MAINPANE_NAVCOMPLETE, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, NULL, NULL, NULL);
  1025. return S_OK;
  1026. }
  1027. HRESULT CObShellMainPane::OnDialing(UINT uiType)
  1028. {
  1029. VARIANT varRet;
  1030. if (USES_EX(uiType))
  1031. ExecScriptFn(SysAllocString(SCRIPTFN_ONDIALINGEX), &varRet);
  1032. else
  1033. ExecScriptFn(SysAllocString(SCRIPTFN_ONDIALING), &varRet);
  1034. return S_OK;
  1035. }
  1036. HRESULT CObShellMainPane::OnConnecting(UINT uiType)
  1037. {
  1038. VARIANT varRet;
  1039. if (USES_EX(uiType))
  1040. ExecScriptFn(SysAllocString(SCRIPTFN_ONCONNECTINGEX), &varRet);
  1041. else
  1042. ExecScriptFn(SysAllocString(SCRIPTFN_ONCONNECTING), &varRet);
  1043. return S_OK;
  1044. }
  1045. HRESULT CObShellMainPane::OnDownloading(UINT uiType)
  1046. {
  1047. VARIANT varRet;
  1048. if (USES_EX(uiType))
  1049. ExecScriptFn(SysAllocString(SCRIPTFN_ONDOWNLOADINGEX), &varRet);
  1050. else
  1051. ExecScriptFn(SysAllocString(SCRIPTFN_ONDOWNLOADING), &varRet);
  1052. return S_OK;
  1053. }
  1054. HRESULT CObShellMainPane::OnConnected(UINT uiType)
  1055. {
  1056. VARIANT varRet;
  1057. if (USES_EX(uiType))
  1058. ExecScriptFn(SysAllocString(SCRIPTFN_ONCONNECTEDEX), &varRet);
  1059. else
  1060. ExecScriptFn(SysAllocString(SCRIPTFN_ONCONNECTED), &varRet);
  1061. return S_OK;
  1062. }
  1063. HRESULT CObShellMainPane::OnDisconnect(UINT uiType)
  1064. {
  1065. VARIANT varRet;
  1066. if (USES_EX(uiType))
  1067. ExecScriptFn(SysAllocString(SCRIPTFN_ONDISCONNECTEX), &varRet);
  1068. else
  1069. ExecScriptFn(SysAllocString(SCRIPTFN_ONDISCONNECT), &varRet);
  1070. return S_OK;
  1071. }
  1072. HRESULT CObShellMainPane::OnServerError(UINT uiType, UINT uiErrorCode)
  1073. {
  1074. VARIANT varRet;
  1075. WCHAR szScriptFn [MAX_PATH] = L"\0";
  1076. if (USES_EX(uiType))
  1077. wsprintf(szScriptFn, SCRIPTFN_ONSERVERERROREX ,uiErrorCode);
  1078. else
  1079. wsprintf(szScriptFn, SCRIPTFN_ONSERVERERROR ,uiErrorCode);
  1080. ExecScriptFn(SysAllocString(szScriptFn), &varRet);
  1081. return S_OK;
  1082. }
  1083. HRESULT CObShellMainPane::OnDialingError(UINT uiType, UINT uiErrorCode)
  1084. {
  1085. VARIANT varRet;
  1086. WCHAR szScriptFn [MAX_PATH] = L"\0";
  1087. if (USES_EX(uiType))
  1088. wsprintf(szScriptFn, SCRIPTFN_ONDIALINGERROREX ,uiErrorCode);
  1089. else
  1090. wsprintf(szScriptFn, SCRIPTFN_ONDIALINGERROR ,uiErrorCode);
  1091. ExecScriptFn(SysAllocString(szScriptFn), &varRet);
  1092. return S_OK;
  1093. }
  1094. HRESULT CObShellMainPane::OnRefDownloadProgress(UINT uiType, UINT uiPercentDone)
  1095. {
  1096. VARIANT varRet;
  1097. WCHAR szScriptFn [MAX_PATH] = L"\0";
  1098. wsprintf(szScriptFn, SCRIPTFN_ONREFDOWNLOADPROGRESSEX ,uiPercentDone);
  1099. ExecScriptFn(SysAllocString(szScriptFn), &varRet);
  1100. return S_OK;
  1101. }
  1102. HRESULT CObShellMainPane::OnRefDownloadComplete(UINT uiType, UINT uiErrorCode)
  1103. {
  1104. VARIANT varRet;
  1105. WCHAR szScriptFn [MAX_PATH] = L"\0";
  1106. wsprintf(szScriptFn, SCRIPTFN_ONREFDOWNLOADCOMPLETEEX ,uiErrorCode);
  1107. ExecScriptFn(SysAllocString(szScriptFn), &varRet);
  1108. return S_OK;
  1109. }
  1110. HRESULT CObShellMainPane::OnISPDownloadComplete(UINT uiType, BSTR bstrURL)
  1111. {
  1112. VARIANT varRet;
  1113. WCHAR szScriptFn [MAX_PATH] = L"\0";
  1114. WCHAR szLocalURL [MAX_PATH] = L"\0";
  1115. ConvertToScript(bstrURL, szLocalURL, MAX_PATH);
  1116. wsprintf(szScriptFn, SCRIPTFN_ONISPDOWNLOADCOMPLETEEX ,szLocalURL);
  1117. ExecScriptFn(SysAllocString(szScriptFn), &varRet);
  1118. return S_OK;
  1119. }
  1120. HRESULT CObShellMainPane::OnDeviceArrival(UINT uiDeviceType)
  1121. {
  1122. USES_CONVERSION;
  1123. VARIANT varRet;
  1124. WCHAR szScriptFn [MAX_PATH] = L"\0";
  1125. wsprintf(szScriptFn, SCRIPTFN_ONDEVICEARRIVAL ,uiDeviceType);
  1126. ExecScriptFn(SysAllocString(szScriptFn), &varRet);
  1127. return S_OK;
  1128. }
  1129. HRESULT CObShellMainPane::OnHelp()
  1130. {
  1131. USES_CONVERSION;
  1132. VARIANT varRet;
  1133. ExecScriptFn(SysAllocString(SCRIPTFN_ONHELP), &varRet);
  1134. return S_OK;
  1135. }
  1136. HRESULT CObShellMainPane::OnIcsConnectionStatus(UINT uiType)
  1137. {
  1138. USES_CONVERSION;
  1139. VARIANT varRet;
  1140. WCHAR szScriptFn [MAX_PATH] = L"\0";
  1141. wsprintf(szScriptFn, SCRIPTFN_ONICSCONNECTIONSTATUS, uiType);
  1142. ExecScriptFn(SysAllocString(szScriptFn), &varRet);
  1143. return S_OK;
  1144. }
  1145. HRESULT CObShellMainPane::ExecScriptFn(BSTR bstrScriptFn, VARIANT* pvarRet)
  1146. {
  1147. IDispatch* pDisp = NULL;
  1148. IHTMLDocument2* pDoc = NULL;
  1149. IHTMLWindow2* pWin = NULL;
  1150. VariantInit(pvarRet);
  1151. if(SUCCEEDED(m_pObWebBrowser->get_WebBrowserDoc(&pDisp)) && pDisp)
  1152. {
  1153. if(SUCCEEDED(pDisp->QueryInterface(IID_IHTMLDocument2, (void**)&pDoc)) && pDoc)
  1154. {
  1155. if(SUCCEEDED(pDoc->get_parentWindow(&pWin)) && pWin)
  1156. {
  1157. pWin->execScript(bstrScriptFn, NULL, pvarRet);
  1158. pWin->Release();
  1159. pWin = NULL;
  1160. }
  1161. pDoc->Release();
  1162. pDoc = NULL;
  1163. }
  1164. pDisp->Release();
  1165. pDisp = NULL;
  1166. }
  1167. return S_OK;
  1168. }
  1169. ///////////////////////////////////////////////////////////
  1170. // DWebBrowserEvents2 / IDispatch implementation
  1171. ///////////////////////////////////////////////////////////
  1172. STDMETHODIMP CObShellMainPane::GetTypeInfoCount(UINT* pcInfo)
  1173. {
  1174. return E_NOTIMPL;
  1175. }
  1176. STDMETHODIMP CObShellMainPane::GetTypeInfo(UINT, LCID, ITypeInfo** )
  1177. {
  1178. return E_NOTIMPL;
  1179. }
  1180. /////////////////////////////////////////////////////////////
  1181. // CObShellMainPane::GetIDsOfNames
  1182. STDMETHODIMP CObShellMainPane::GetIDsOfNames(
  1183. /* [in] */ REFIID riid,
  1184. /* [size_is][in] */ OLECHAR** rgszNames,
  1185. /* [in] */ UINT cNames,
  1186. /* [in] */ LCID lcid,
  1187. /* [size_is][out] */ DISPID* rgDispId)
  1188. {
  1189. return DISP_E_UNKNOWNNAME;
  1190. }
  1191. /////////////////////////////////////////////////////////////
  1192. // CObShellMainPane::Invoke
  1193. HRESULT CObShellMainPane::Invoke
  1194. (
  1195. DISPID dispidMember,
  1196. REFIID riid,
  1197. LCID lcid,
  1198. WORD wFlags,
  1199. DISPPARAMS* pdispparams,
  1200. VARIANT* pvarResult,
  1201. EXCEPINFO* pexcepinfo,
  1202. UINT* puArgErr
  1203. )
  1204. {
  1205. HRESULT hr = S_OK;
  1206. switch(dispidMember)
  1207. {
  1208. case DISPID_DOCUMENTCOMPLETE:
  1209. {
  1210. FireObShellDocumentComplete();
  1211. break;
  1212. }
  1213. case DISPID_NAVIGATECOMPLETE:
  1214. {
  1215. break;
  1216. }
  1217. case DISPID_BEFORENAVIGATE2:
  1218. {
  1219. WCHAR szStatus [INTERNET_MAX_URL_LENGTH*2] = L"\0";
  1220. WCHAR* pszError = NULL;
  1221. if(pdispparams &&
  1222. &(pdispparams[0].rgvarg[5]) &&
  1223. pdispparams[0].rgvarg[5].pvarVal &&
  1224. pdispparams[0].rgvarg[5].pvarVal->bstrVal)
  1225. {
  1226. // BUGBUG: WE should really check the size of URL before copy
  1227. // Bug This url is from IE, we should be ok here
  1228. lstrcpy(szStatus, pdispparams[0].rgvarg[5].pvarVal->bstrVal);
  1229. //We make an assumption here that if we are going to shdocvw for our html something is fishy
  1230. if((pszError = StrStrI(szStatus, L"SHDOCLC.DLL")) && pszError)
  1231. {
  1232. if(&(pdispparams[0].rgvarg[0]) && pdispparams[0].rgvarg[0].pboolVal)
  1233. *pdispparams[0].rgvarg[0].pboolVal = TRUE;
  1234. ProcessServerError(pszError);
  1235. }
  1236. }
  1237. break;
  1238. }
  1239. case DISPID_STATUSTEXTCHANGE:
  1240. {
  1241. WCHAR szStatus [INTERNET_MAX_URL_LENGTH*2] = L"\0";
  1242. WCHAR* pszError = NULL;
  1243. if(pdispparams &&
  1244. &(pdispparams[0].rgvarg[0]) &&
  1245. pdispparams[0].rgvarg[0].bstrVal)
  1246. {
  1247. lstrcpy(szStatus, pdispparams[0].rgvarg[0].bstrVal);
  1248. //We make an assumption here that if we are going to shdocvw for our html something is fishy
  1249. if((pszError = StrStrI(szStatus, L"SHDOCLC.DLL")) && (StrCmpNI(szStatus, L"Start", 5) == 0) && pszError) //BUGBUG: is Start localized?
  1250. {
  1251. m_pObWebBrowser->Stop();
  1252. ProcessServerError(pszError);
  1253. }
  1254. }
  1255. break;
  1256. }
  1257. default:
  1258. {
  1259. hr = DISP_E_MEMBERNOTFOUND;
  1260. break;
  1261. }
  1262. }
  1263. return hr;
  1264. }
  1265. void CObShellMainPane::ProcessServerError(WCHAR* pszError)
  1266. {
  1267. LPARAM lParam = NULL;
  1268. pszError += lstrlen(L"SHDOCLC.DLL/");
  1269. if(StrCmpNI(pszError, L"DNSERROR", 8) == 0)
  1270. {
  1271. lParam = ERR_SERVER_DNS;
  1272. }
  1273. else if(StrCmpNI(pszError, L"SYNTAX", 6) == 0)
  1274. {
  1275. lParam = ERR_SERVER_SYNTAX;
  1276. }
  1277. else if(StrCmpNI(pszError, L"SERVBUSY", 8) == 0)
  1278. {
  1279. lParam = ERR_SERVER_HTTP_408;
  1280. }
  1281. else if(StrCmpNI(pszError, L"HTTP_GEN", 8) == 0)
  1282. {
  1283. lParam = ERR_SERVER_HTTP_405;
  1284. }
  1285. else if(StrCmpNI(pszError, L"HTTP_400", 8) == 0)
  1286. {
  1287. lParam = ERR_SERVER_HTTP_400;
  1288. }
  1289. else if(StrCmpNI(pszError, L"HTTP_403", 8) == 0)
  1290. {
  1291. lParam = ERR_SERVER_HTTP_403;
  1292. }
  1293. else if(StrCmpNI(pszError, L"HTTP_404", 8) == 0)
  1294. {
  1295. lParam = ERR_SERVER_HTTP_404;
  1296. }
  1297. else if(StrCmpNI(pszError, L"HTTP_406", 8) == 0)
  1298. {
  1299. lParam = ERR_SERVER_HTTP_406;
  1300. }
  1301. else if(StrCmpNI(pszError, L"HTTP_410", 8) == 0)
  1302. {
  1303. lParam = ERR_SERVER_HTTP_410;
  1304. }
  1305. else if(StrCmpNI(pszError, L"HTTP_500", 8) == 0)
  1306. {
  1307. lParam = ERR_SERVER_HTTP_500;
  1308. }
  1309. else if(StrCmpNI(pszError, L"HTTP_501", 8) == 0)
  1310. {
  1311. lParam = ERR_SERVER_HTTP_501;
  1312. }
  1313. SendMessage(m_hwndParent, WM_OBCOMM_ONSERVERERROR, (WPARAM)0, (LPARAM)lParam);
  1314. }
  1315. LRESULT WINAPI MainPaneWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  1316. {
  1317. switch (msg)
  1318. {
  1319. case WM_CLOSE:
  1320. DestroyWindow(hwnd);
  1321. return TRUE;
  1322. case WM_DESTROY:
  1323. PostQuitMessage(0);
  1324. return TRUE;
  1325. }
  1326. return DefWindowProc(hwnd, msg, wParam, lParam);
  1327. }