HRESULT vmsDomHelper::GetWindowDocument(IHTMLWindow2* pWnd, IHTMLDocument2** ppDoc) { assert (pWnd != NULL && ppDoc != NULL); if (!ppDoc) return E_INVALIDARG; *ppDoc = NULL; if (!pWnd) return E_INVALIDARG; HRESULT hr = pWnd->get_document (ppDoc); if (*ppDoc) return hr; IWebBrowser2Ptr spWB; GetWebBrowser (pWnd, &spWB); if (spWB != NULL) { IDispatchPtr spdDoc; spWB->get_Document (&spdDoc); if (spdDoc != NULL) { spdDoc->QueryInterface (IID_IHTMLDocument2, (void**)ppDoc); if (*ppDoc) hr = S_OK; } } return hr; }
HRESULT vmsDomHelper::GetParentDocument(IHTMLDocument2 *pDoc, IHTMLDocument2 **ppParentDoc) { *ppParentDoc = NULL; ATLASSERT (pDoc != NULL); if (!pDoc) return E_INVALIDARG; IHTMLWindow2Ptr spWnd; HRESULT hr = pDoc->get_parentWindow (&spWnd); if (FAILED (hr)) return hr; IHTMLWindow2Ptr spWndParent; hr = spWnd->get_parent (&spWndParent); if (FAILED (hr)) return hr; hr = spWndParent->get_document (ppParentDoc); if (hr == E_ACCESSDENIED) { IWebBrowser2Ptr spWB; hr = GetWebBrowser (spWndParent, &spWB); if (FAILED (hr)) return E_ACCESSDENIED; IDispatchPtr spdDoc; hr = spWB->get_Document (&spdDoc); if (FAILED (hr)) return hr; hr = spdDoc->QueryInterface (IID_IHTMLDocument2, (void**)ppParentDoc); } if (FAILED (hr)) return hr; IUnknownPtr spUnk1 (pDoc); IUnknownPtr spUnk2 (*ppParentDoc); if (pDoc == *ppParentDoc || spUnk1 == spUnk2) { (*ppParentDoc)->Release (); *ppParentDoc = NULL; } return S_OK; }
HRESULT STDMETHODCALLTYPE BrowserEvents2::Invoke( /* [in] */ DISPID dispId, /* [in] */ REFIID riid, /* [in] */ LCID lcid, /* [in] */ WORD wFlags, /* [out][in] */ DISPPARAMS *pDispParams, /* [out] */ VARIANT *pVarResult, /* [out] */ EXCEPINFO *pExcepInfo, /* [out] */ UINT *puArgErr) { // When returning a result, you must check whether pVarResult // is not NULL and initialize it using VariantInit(). If it's // NULL then it doesn't expect a result. if (riid != IID_NULL) return DISP_E_UNKNOWNINTERFACE; pExcepInfo = 0; puArgErr = 0; HRESULT hr; json_value* settings = GetApplicationSettings(); if (dispId == DISPID_NEWWINDOW3) { /* When calling window.open() you get an error "Class not registered". Before this error appears DWebBrowserEvents2::NewWindow3 event is dispatched, you need to create the popup window in this event and assign the dispatch interface of the new popup browser to the first parameter of NewWindow3. */ LOG_DEBUG << "BrowserEvents2::NewWindow3()"; if (pDispParams->cArgs != 5) { LOG_WARNING << "BrowserEvents2::NewWindow3() failed: " "Expected 5 arguments"; _ASSERT(false); return DISP_E_BADPARAMCOUNT; } // ppDisp _ASSERT(pDispParams->rgvarg[4].vt == (VT_DISPATCH | VT_BYREF)); // Cancel _ASSERT(pDispParams->rgvarg[3].vt == (VT_BOOL | VT_BYREF)); // dwFlags _ASSERT(pDispParams->rgvarg[2].vt == VT_I4); // bstrUrlContext _ASSERT(pDispParams->rgvarg[1].vt == VT_BSTR); // bstrUrl _ASSERT(pDispParams->rgvarg[0].vt == VT_BSTR); HWND popupHandle = CreatePopupWindow( browserWindow_->GetWindowHandle()); _ASSERT(popupHandle); BrowserWindow* browserWindow = GetBrowserWindow(popupHandle); if (!browserWindow) { LOG_WARNING << "BrowserEvents2::NewWindow3() failed: " "CreatePopupWindow() failed"; // Cancel parameter. Current navigation should be cancelled. *pDispParams->rgvarg[3].pboolVal = VARIANT_TRUE; return S_OK; } const IWebBrowser2Ptr webBrowser2 = browserWindow->GetWebBrowser2(); IDispatchPtr dispatch; hr = webBrowser2->get_Application(&dispatch); if (FAILED(hr) || !dispatch) { LOG_WARNING << "BrowserEvents2::NewWindow3() failed: " "webBrowser2->get_Application() failed"; return S_OK; } *pDispParams->rgvarg[4].ppdispVal = dispatch.Detach(); *pDispParams->rgvarg[3].pboolVal = VARIANT_FALSE; // Following events (DWebBrowserEvents2) will appear // after popup creation, they inform about "features" // passed to "window.open", such as width, height and others: // DISPID_ONTOOLBAR // DISPID_ONADDRESSBAR // DISPID_WINDOWSETRESIZABLE // DISPID_ONMENUBAR // DISPID_ONSTATUSBAR // DISPID_ONFULLSCREEN // DISPID_CLIENTTOHOSTWINDOW // DISPID_WINDOWSETWIDTH // DISPID_WINDOWSETHEIGHT // DISPID_WINDOWSETTOP // DISPID_WINDOWSETLEFT // DISPID_NAVIGATECOMPLETE2 return S_OK; } else if (dispId == DISPID_WINDOWSETWIDTH) { _ASSERT(pDispParams->cArgs == 1); _ASSERT(pDispParams->rgvarg[0].vt == VT_I4); // nWidth long width = pDispParams->rgvarg[0].lVal; // LOG_DEBUG << "BrowserEvents2::WindowSetWidth(): width = " // << width; browserWindow_->SetWidth(width); } else if (dispId == DISPID_WINDOWSETHEIGHT) { _ASSERT(pDispParams->cArgs == 1); _ASSERT(pDispParams->rgvarg[0].vt == VT_I4); // nHeight long height = pDispParams->rgvarg[0].lVal; // LOG_DEBUG << "BrowserEvents2::WindowSetHeight(): height = " // << height; browserWindow_->SetHeight(height); } else if (dispId == DISPID_WINDOWSETTOP) { _ASSERT(pDispParams->cArgs == 1); _ASSERT(pDispParams->rgvarg[0].vt == VT_I4); // nTop long top = pDispParams->rgvarg[0].lVal; // LOG_DEBUG << "BrowserEvents2::WindowSetTop(): top = " // << top; browserWindow_->SetTop(top); } else if (dispId == DISPID_WINDOWSETLEFT) { _ASSERT(pDispParams->cArgs == 1); _ASSERT(pDispParams->rgvarg[0].vt == VT_I4); // nLeft long left = pDispParams->rgvarg[0].lVal; // LOG_DEBUG << "BrowserEvents2::WindowSetLeft(): left = " // << left; browserWindow_->SetLeft(left); } else if (dispId == DISPID_TITLECHANGE) { if (browserWindow_->IsPopup() && browserWindow_->IsUsingMetaTitle()) { _ASSERT(pDispParams->cArgs == 1); _ASSERT(pDispParams->rgvarg[0].vt == VT_BSTR); // Text BSTR title = pDispParams->rgvarg[0].bstrVal; // LOG_DEBUG << "BrowserEvents2::TitleChange(): " // "setting popup title = " << WideToUtf8(title); browserWindow_->SetTitle(title); } } else if (dispId == DISPID_NAVIGATEERROR) { LOG_DEBUG << "BrowserEvents2::NavigateError()"; if (pDispParams->cArgs != 5) { LOG_WARNING << "BrowserEvents2::NavigateError() failed: " "Expected 5 arguments"; _ASSERT(false); return DISP_E_BADPARAMCOUNT; } // pDisp _ASSERT(pDispParams->rgvarg[4].vt == VT_DISPATCH); // URL _ASSERT(pDispParams->rgvarg[3].vt == (VT_VARIANT | VT_BYREF)); _ASSERT(pDispParams->rgvarg[3].pvarVal->vt == VT_BSTR); // TargetFrameName _ASSERT(pDispParams->rgvarg[2].vt == (VT_VARIANT | VT_BYREF)); _ASSERT(pDispParams->rgvarg[2].pvarVal->vt == VT_BSTR); // StatusCode _ASSERT(pDispParams->rgvarg[1].vt == (VT_VARIANT | VT_BYREF)); _ASSERT(pDispParams->rgvarg[1].pvarVal->vt == VT_I4); // Cancel _ASSERT(pDispParams->rgvarg[0].vt == (VT_BOOL | VT_BYREF)); const wchar_t* navigateUrl = pDispParams->rgvarg[3].pvarVal->bstrVal; int statusCode = pDispParams->rgvarg[1].pvarVal->lVal; if (browserWindow_->DisplayErrorPage(navigateUrl, statusCode)) { *pDispParams->rgvarg[0].pboolVal = VARIANT_TRUE; return S_OK; } else { *pDispParams->rgvarg[0].pboolVal = VARIANT_FALSE; return S_OK; } } else if (dispId == DISPID_WINDOWCLOSING) { // Seems like this event is never being called, it should be // called when executing "window.close()", but it's not. // Use WM_PARENTNOTIFY instead to be notified when window is closing. LOG_DEBUG << "BrowserEvents2::WindowClosing()"; return S_OK; /* if (pDispParams->cArgs != 2) { LOG_WARNING << "BrowserEvents2::WindowClosing() failed: " "Expected 2 arguments"; _ASSERT(false); return DISP_E_BADPARAMCOUNT; } // bIsChildWindow _ASSERT(pDispParams->rgvarg[1].vt == VT_BOOL); // Cancel _ASSERT(pDispParams->rgvarg[0].vt == (VT_BOOL | VT_BYREF)); // VARIANT_FALSE - window is allowed to close.. *pDispParams->rgvarg[0].pboolVal = VARIANT_FALSE; return S_OK; */ } return S_OK; }
HRESULT STDMETHODCALLTYPE OleInPlaceSite::OnPosRectChange( LPCRECT lprcPosRect) { if (!lprcPosRect) return E_INVALIDARG; HRESULT hr; IOleObjectPtr oleObject; const IWebBrowser2Ptr webBrowser2 = browserWindow_->GetWebBrowser2(); hr = webBrowser2->QueryInterface(IID_IOleObject, (void**)&oleObject); if (FAILED(hr) || !oleObject) { LOG_WARNING << "OleInPlaceSite::OnPosRectChange() failed: " "QueryInterface(IOleObject) failed"; return E_UNEXPECTED; } IOleInPlaceObjectPtr oleInPlaceObject; hr = oleObject->QueryInterface(IID_IOleInPlaceObject, (void**)&oleInPlaceObject); if (FAILED(hr) || !oleInPlaceObject) { LOG_WARNING << "OleInPlaceSite::OnPosRectChange() failed: " "QueryInterface(IOleInPlaceObject) failed"; return E_UNEXPECTED; } hr = oleInPlaceObject->SetObjectRects(lprcPosRect, lprcPosRect); if (FAILED(hr)) { LOG_WARNING << "OleInPlaceSite::OnPosRectChange() failed: " "IOleInPlaceObject->SetObjectRects() failed"; return E_UNEXPECTED; } return S_OK; }
bool IEToolbar::onShareCmd() { // if not logged on then dont allow to do the action if (!UserDataObserver::getInstance().isLoggedIn(false)) { UserDataObserver::getInstance().login(); } else { const unsigned int shareWindowWidth = 626; const unsigned int shareWindowHeight = 436; const IWebBrowser2Ptr browser = getWebBrowser(); BSTR locationAsBSTR; const HRESULT getLocationUrl = browser->get_LocationURL(&locationAsBSTR); if (SUCCEEDED(getLocationUrl)) { _bstr_t bstrLocationHolder(locationAsBSTR); SysFreeString(locationAsBSTR); String locationUrl = bstrLocationHolder; BSTR nameAsBSTR; //get the title if possible String locationName; const HRESULT getLocationName = browser->get_LocationName(&nameAsBSTR); if (SUCCEEDED(getLocationName)) { _bstr_t bstrNameHolder(nameAsBSTR); SysFreeString(nameAsBSTR); locationName = bstrNameHolder; } locationUrl = buildShareContentURL(locationUrl, locationName); BrowserUtils::IEPopup(locationUrl, shareWindowWidth, shareWindowHeight); } } return true; }
bool IEToolbar::onSidebarCmd() { const String friendsSidebarClassID = toString(CLSID_IESidebar); variant_t friendsSideBarGuid = toBSTR(friendsSidebarClassID); const BOOL sideBarIsOpen = RuntimeContext::isSidebarOpened(); variant_t showFlag(sideBarIsOpen ? VARIANT_FALSE : VARIANT_TRUE, VT_BOOL); IWebBrowser2Ptr browser = getWebBrowser(); const HRESULT showSidebarReas = browser->ShowBrowserBar(&friendsSideBarGuid, &showFlag, 0); if (FAILED(showSidebarReas)) { _com_raise_error(showSidebarReas); } // Update the filter on sidebar if we are opening the sidebar, // if it was opened and we are closing it - no if (!sideBarIsOpen) { String filterText = searchEdit_.getEnteredText(); if (filterText == searchEdit_.getPromptText()) { filterText = _T(""); } HWND sideBarHwnd = RuntimeContext::getSidebarHwnd(); if (sideBarHwnd) { String* filterMessageParam = new String(filterText); ::PostMessage(sideBarHwnd, TBM_FILTER_CHANGED, 0, (LPARAM)filterMessageParam); } } return true; }
void vmsWebBrowserEvents::OnDocumentComplete(LPDISPATCH pdWB, VARIANT *URL) { if (m_spUIHandler != NULL) { IWebBrowser2Ptr spWB (pdWB); if (spWB == NULL) return; IDispatchPtr spdDoc; spWB->get_Document (&spdDoc); IHTMLDocumentPtr spDoc (spdDoc); if (spDoc == NULL) return; ICustomDocPtr spCD (spDoc); if (spCD != NULL) spCD->SetUIHandler (m_spUIHandler); } }
void CDownloads_Opinions_WBEvents::OnDocumentComplete(LPDISPATCH pdWB, VARIANT *URL) { IWebBrowser2Ptr spWB (pdWB); if (spWB == NULL) return; IDispatchPtr spdDoc; spWB->get_Document (&spdDoc); IHTMLDocumentPtr spDoc (spdDoc); if (spDoc == NULL) return; ICustomDocPtr spCD (spDoc); if (spCD != NULL) spCD->SetUIHandler (&m_wbUIHandler); bool bSetTab = false; if (m_pwndOpinions->m_cSetAsCurrentTabAfterLoadComplete) { InterlockedDecrement (&m_pwndOpinions->m_cSetAsCurrentTabAfterLoadComplete); bSetTab = true; } if (m_pwndOpinions->m_dld == NULL) return; if (bSetTab) _pwndDownloads->m_wndDownloads.m_info.set_CurTab (DIT_OPINIONS); IDispatch *pdScript; spDoc->get_Script (&pdScript); if (pdScript == NULL) return; DISPID didFun; OLECHAR* pwszFunName = L"processform"; HRESULT hr; hr = pdScript->GetIDsOfNames (IID_NULL, &pwszFunName, 1, LOCALE_SYSTEM_DEFAULT, &didFun); if (FAILED (hr)) return; COleVariant vtResult; BYTE params [] = {VTS_BSTR VTS_BSTR VTS_BSTR VTS_BSTR VTS_BSTR}; CString strVersion; CMainFrame* pFrm = (CMainFrame*)AfxGetApp ()->m_pMainWnd; strVersion.Format ("%s_%d", vmsFdmAppMgr::getBuildNumberAsString (), pFrm->m_Customizations.get_AffiliateID ()); CString strState; if (m_pwndOpinions->m_dld->pMgr->IsDone ()) strState = "Downloaded"; else if (m_pwndOpinions->m_dld->pMgr->IsRunning ()) strState = "Downloading"; else strState = "Paused"; CString strSize; UINT64 u = m_pwndOpinions->m_dld->pMgr->GetSSFileSize (); if (u != _UI64_MAX) { char sz [100]; _i64toa ((__int64)u, sz, 10); strSize = sz; } else strSize = "Unknown"; CString strComment = m_pwndOpinions->m_dld->strComment; strComment.Replace ("\r\n", " "); strComment.Replace ("\r", " "); strComment.Replace ("\n", " "); CString strUrl; if (m_pwndOpinions->m_dld->pMgr->IsBittorrent ()) strUrl = m_pwndOpinions->m_dld->pMgr->GetBtDownloadMgr ()->get_InfoHash (); else strUrl = m_pwndOpinions->m_dld->pMgr->get_URL (); COleDispatchDriver ddr (pdScript); ddr.InvokeHelper (didFun, DISPATCH_METHOD, VT_VARIANT, (void*)&vtResult, params, strVersion, strUrl, strComment, strState, strSize); RetrieveLinkToUsText (spdDoc); }
/****************************************************************************** * 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; }