STDMETHODIMP CFDMFlashVideoDownloads::ProcessIeDocument(IDispatch *pDispatch) { IHTMLDocument2Ptr spDoc (pDispatch); if (spDoc == NULL) return E_INVALIDARG; IPersistFilePtr spFile (pDispatch); if (spFile == NULL) return E_INVALIDARG; USES_CONVERSION; BSTR bstrHost = NULL; spDoc->get_URL (&bstrHost); fsURL url; if (url.Crack (W2A (bstrHost)) != IR_SUCCESS) return E_FAIL; SysFreeString (bstrHost); char szPath [MY_MAX_PATH]; GetTempPath (sizeof (szPath), szPath); char szFile [MY_MAX_PATH]; GetTempFileName (szPath, "fdm", 0, szFile); COleVariant vaFile (szFile); if (FAILED (spFile->Save (vaFile.bstrVal, FALSE))) return E_FAIL; HANDLE hFile = CreateFile (szFile, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); if (hFile == INVALID_HANDLE_VALUE) return E_FAIL; DWORD dw = GetFileSize (hFile, NULL); LPSTR pszHtml = new char [dw + 1]; ReadFile (hFile, pszHtml, dw, &dw, NULL); pszHtml [dw] = 0; CloseHandle (hFile); DeleteFile (szFile); ProcessHtml (url.GetHostName (), pszHtml); delete [] pszHtml; return S_OK; }
STDMETHODIMP CWgBHO::BeforeNavigate2(IDispatch *, VARIANT *url, VARIANT *flags, VARIANT *tfn, VARIANT *pd, VARIANT *headers, VARIANT_BOOL *bCancel) { USES_CONVERSION; if (fsIsMonitoringTurnedOn () == FALSE) return S_OK; _bstr_t bstrUrl = url->bstrVal; LPCSTR pszUrl = W2A (bstrUrl); if (fsIsOKUrl (pszUrl) == FALSE) return S_OK; *bCancel = VARIANT_FALSE; if (FALSE == fsOnNavigateUrl (pszUrl)) return S_OK; fsString strCookies, strPostData, strReferer; IDispatchPtr spdDoc; m_spWebBrowser2->get_Document (&spdDoc); IHTMLDocument2Ptr spDoc; if (spdDoc) spDoc = spdDoc; if (spDoc) { BSTR bstr = NULL; spDoc->get_cookie (&bstr); if (bstr) { strCookies = W2A (bstr); SysFreeString (bstr); } bstr = NULL; spDoc->get_URL (&bstr); if (bstr) { strReferer = W2A (bstr); SysFreeString (bstr); } IHTMLElementCollectionPtr spForms; spDoc->get_forms (&spForms); long cForms = 0; if (spForms) spForms->get_length (&cForms); bool bFound = false; for (long i = 0; bFound == false && i < cForms; i++) { IDispatchPtr spd; spForms->item (CComVariant (i), CComVariant (i), &spd); IHTMLFormElementPtr spForm (spd); if (spForm == NULL) continue; BSTR bstr = NULL; spForm->get_action (&bstr); bFound = bstr != NULL && wcscmp (url->bstrVal, bstr) == 0; SysFreeString (bstr); if (bFound == false) continue; bstr = NULL; spForm->get_method (&bstr); if (bstr == NULL || wcsicmp (bstr, L"post")) break; SysFreeString (bstr); IHTMLElementPtr spFormElem (spForm); if (spFormElem == NULL) { bFound = false; continue; } WalkThroughForm (spFormElem, strPostData); if (strPostData != "" && strPostData [strPostData.GetLength ()-1] == '&') strPostData [strPostData.GetLength ()-1] = 0; } } if (fsUrlToFdm (pszUrl, strReferer, strCookies != "" ? strCookies : NULL, strPostData != "" ? strPostData : NULL, FALSE)) *bCancel = VARIANT_TRUE; return S_OK; }