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.

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