Ejemplo n.º 1
0
void vmsFlashHelper::GetFlashMoviesList(IHTMLDocument2Ptr spDoc, std::vector <fsString> *pslURLs, std::vector <fsString> *pslHTMLs)
{
	USES_CONVERSION;

	FLASHLIST vf;
	GetFlashMoviesObjList (spDoc, &vf, TRUE);

	IHTMLLocationPtr spLoc;
	spDoc->get_location (&spLoc);
	BSTR bstrHref = NULL;
	spLoc->get_href (&bstrHref);
	fsString strParent = W2A (bstrHref);
	SysFreeString (bstrHref);

	for (int i = 0; i < vf.size (); i++)
	{
		IDispatch* pTag = vf [i];
		fsString strMovieURL;
		fsString strMovieHTML;
		
		
		IHTMLObjectElementPtr spObject (pTag);
		if (spObject != NULL)
		{
			IDispatchPtr spObj;
			spObject->get_object (&spObj);
			IShockwaveFlashPtr spFlash (spObj);
			if (spFlash != NULL)
			{
				BSTR bstr;
				spFlash->get_Movie (&bstr);
				strMovieURL = W2A (bstr);
				SysFreeString (bstr);
			}
		}
		else
		{
			
			IHTMLEmbedElementPtr spObject(pTag);
			BSTR bstrSrc = NULL;
			spObject->get_src(&bstrSrc);
			strMovieURL = W2A (bstrSrc);
			SysFreeString (bstrSrc);
		}

		
		if (pslHTMLs != NULL)
		{
			IHTMLElementPtr spElement (pTag);
			BSTR bstr = NULL;
			spElement->get_outerHTML (&bstr);
			strMovieHTML = W2A (bstr);
			SysFreeString (bstr);
		}

		pslURLs->push_back (strMovieURL);
		if (pslHTMLs)
			pslHTMLs->push_back (strMovieHTML);
	}
}
Ejemplo n.º 2
0
void vmsFlashHelper::GetFlashInfo(IDispatchPtr spFlash, IHTMLDocument2Ptr spDoc, fsString *pstrMovieURL, fsString *pstrMovieHTML)
{
	USES_CONVERSION;

	IHTMLLocationPtr spLoc;
	spDoc->get_location (&spLoc);
	BSTR bstrHref = NULL;
	spLoc->get_href (&bstrHref);
	fsString strParent = W2A (bstrHref);
	SysFreeString (bstrHref);

	
	IHTMLObjectElementPtr spObject (spFlash);
	if (spObject != NULL)
	{
		IDispatchPtr spObj;
		spObject->get_object (&spObj);
		IShockwaveFlashPtr spFlash (spObj);
		if (spFlash != NULL)
		{
			BSTR bstr;
			spFlash->get_Movie (&bstr);
			*pstrMovieURL = W2A (bstr);
			SysFreeString (bstr);
		}
	}
	else
	{
		
		IHTMLEmbedElementPtr spObject (spFlash);
		BSTR bstrSrc = NULL;
		spObject->get_src(&bstrSrc);
		*pstrMovieURL = W2A (bstrSrc);
		SysFreeString (bstrSrc);
	}

	
	if (pstrMovieHTML != NULL)
	{
		IHTMLElementPtr spElement (spFlash);
		BSTR bstr = NULL;
		spElement->get_outerHTML (&bstr);
		*pstrMovieHTML = W2A (bstr);
		SysFreeString (bstr);
	}
}
HRESULT vmsDomHelper::InjectJSCode(IHTMLDocument2 *pDoc, BSTR bsCode)
{
	IHTMLElementPtr spBody;
	HRESULT hr = pDoc->get_body (&spBody);
	if (spBody == NULL)
		return hr;

	IHTMLElementPtr spScript;
	hr = pDoc->createElement (CComBSTR (L"script"), &spScript);
	if (spScript == NULL)
		return hr;

	spScript->setAttribute (CComBSTR (L"type"), CComVariant (L"text/javascript"));
	IHTMLScriptElementPtr spScriptEl (spScript);
	ATLASSERT (spScriptEl != NULL);
	spScriptEl->put_text (bsCode);

	IHTMLElement2Ptr spBodyEl (spBody);
	IHTMLElementPtr spTmp1;
	
	return spBodyEl->insertAdjacentElement (L"beforeEnd", spScript, &spTmp1);
}
Ejemplo n.º 4
0
void vmsFlashHelper::DisableFlashMovies(IHTMLDocument2Ptr spDoc, BOOL bIncludingFrames)
{
	FLASHLIST vf;
	GetFlashMoviesObjList (spDoc, &vf, bIncludingFrames);

	for (int i = 0; i < vf.size (); i++)
	{
		
		
		IHTMLElementPtr spElem (vf [i]);
		if (spElem)
		{
			IHTMLStylePtr spStyle;
			HRESULT hr = spElem->get_style (&spStyle);
			if (SUCCEEDED (hr) && spStyle != NULL)
			{
				spStyle->put_visibility  (L"hidden");
				spStyle->put_pixelHeight (0);
				spStyle->put_pixelWidth  (0);
			}
		}
	}
}
/******************************************************************************
*   Invoke -- Takes a dispid and uses it to call another of the methods of this 
*   class. Returns S_OK if the call was successful.
******************************************************************************/ 
STDMETHODIMP WebBrowserEventSinker::Invoke(DISPID dispIdMember, REFIID riid, LCID lcid,
	WORD wFlags, DISPPARAMS* pDispParams,
	VARIANT* pVarResult,
	EXCEPINFO* pExcepInfo,
	UINT* puArgErr)
{
	//Validate arguments.
	if ((riid != IID_NULL))
		return E_INVALIDARG;

	//if (dispIdMember != DISPID_STATUSTEXTCHANGE)//过于频繁的不显示了
	//{
	//	TCHAR buf[128] = {0};
	//	_stprintf(buf, _T("WebBrowserEventSinker::Invoke dispId = %d\n"), dispIdMember);
	//	TRACE(buf);
	//}

	HRESULT hr = S_OK;  // Initialize.

	switch (dispIdMember)
	{
		//注意:pDispParams的参数和MFC的参数顺序是相反的,MFC的第一个参数是WebBrowser的this指针
		//The last of pDispParams is an object that evaluates to the top-level or frame WebBrowser object corresponding to the event.

// 	case DISPID_NEWWINDOW3:
// 		// (IDispatch **ppDisp, VARIANT_BOOL *Cancel, DWORD dwFlags, BSTR bstrUrlContext, BSTR bstrUrl)
// 		return E_NOTIMPL;
// 		break;
// 
// 	case DISPID_NEWWINDOW2:
// 		// pDispParams->rgvarg[0]: BOOL*   Cancel
// 		// pDispParams->rgvarg[1]: LPDISPATCH*   ppDisp, dest app
// 		{
// 			int nCount = pDispParams->cArgs;
// 			_variant_t vVal = pDispParams->rgvarg[1];
// 			IWebBrowser2Ptr pWB = vVal.pdispVal;
// 			AdviseWebBrowser(pWB);
// 		}
// 		break;

//	case DISPID_BEFORENAVIGATE2:
		// pDispParams->rgvarg[6]: WebBrowser object
		// pDispParams->rgvarg[5 - 0]: 
		// (LPCTSTR lpszURL, DWORD nFlags, LPCTSTR lpszTargetFrameName, CByteArray& baPostedData, LPCTSTR lpszHeaders, BOOL* pbCancel)
//		{
//			int nCount = pDispParams->cArgs;
//			_variant_t vVal = pDispParams->rgvarg[nCount - 2];
//		}
//		break;

	case DISPID_NAVIGATECOMPLETE2:
		//(LPCTSTR lpszURL)
		// pDispParams->rgvarg[0]: URL to navigate to - VT_BYREF|VT_VARIANT
		// pDispParams->rgvarg[1]: An object that evaluates to the top-level or frame WebBrowser object corresponding to the event.
		if (pDispParams->cArgs >= 2 && pDispParams->rgvarg[1].vt == VT_DISPATCH)
			SetCustomDocUIHandler(pDispParams->rgvarg[1].pdispVal);
		break;


	case DISPID_DOCUMENTCOMPLETE:
		//(LPCTSTR lpszURL)
		// pDispParams->rgvarg[0]: URL to navigate to - VT_BYREF|VT_VARIANT
		// pDispParams->rgvarg[1]: An object that evaluates to the top-level or frame WebBrowser object corresponding to the event.
		if (pDispParams->cArgs >= 2 && pDispParams->rgvarg[1].vt == VT_DISPATCH)
		{
			IWebBrowser2Ptr pBrowser;
			(pDispParams->rgvarg[1].pdispVal)->QueryInterface(IID_IWebBrowser2,(void**)&pBrowser);
			if (pBrowser)
			{
				IHTMLDocument2Ptr pDocument;
				IDispatchPtr spDisp;
				pBrowser->get_Document(&spDisp);
				pDocument = spDisp;
				if (pDocument)
				{
					IHTMLElementPtr pElement;
					IHTMLBodyElementPtr pBody; //IID_IHTMLBodyElement
					pDocument->get_body(&pElement);
					pBody = pElement;
					if (pBody != NULL)
					{
						pBody->put_scroll((BSTR)L"auto");

						IHTMLStylePtr pStyle;
						pElement->get_style(&pStyle);
						pStyle->put_border((BSTR)L"none");
						pStyle->put_overflow((BSTR)L"auto");
					}
				}
			}
		}
		break;

	default:
		break;
	}

	return hr;
}