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 BrowserInfo::GetDocument(IHTMLDocument2 **pDocument) { CIPtr(IWebBrowserApp) cpWebBrowser; if (FAILED(GetWebBrowser(&cpWebBrowser))) { return E_FAIL; } CIPtr(IDispatch) cpDispDocument; cpWebBrowser->get_Document(&cpDispDocument); if (cpDispDocument == NULL) { return E_FAIL; } return cpDispDocument->QueryInterface(IID_IHTMLDocument2, (void **) pDocument); }
//OLECMDID_PRINT = 6, HRESULT CWtlHtmlView::ExecCommand( OLECMDID nCmdID, OLECMDEXECOPT nCmdExecOpt, VARIANTARG* pvarargIn, VARIANTARG* pvarargOut) { HRESULT hr=S_OK; LPDISPATCH lpDispatch = NULL; LPOLECOMMANDTARGET lpOleCommandTarget = NULL; if(m_spWebBrowser2==NULL) { if((m_spWebBrowser2=GetWebBrowser())==NULL) { throw std::exception("Can't retrieve m_spWebBrowser2"); } } try { m_spWebBrowser2->get_Document(&lpDispatch); if(lpDispatch==NULL) throw; OLECMDF eQuery ; // 'return value type for QueryStatusWB if(FAILED( m_spWebBrowser2->QueryStatusWB(OLECMDID_PRINT, &eQuery))) // 'get print command status throw std::exception("Can't retrieve QueryStatusWB"); if(!( eQuery & OLECMDF_ENABLED) ) throw; lpDispatch->QueryInterface(IID_IOleCommandTarget, (void**)&lpOleCommandTarget); if(lpOleCommandTarget==NULL) throw; // Print contents of WebBrowser control. hr=lpOleCommandTarget->Exec(NULL, nCmdID, nCmdExecOpt, pvarargIn, pvarargOut); } catch(...) { hr=E_FAIL; } if(lpDispatch) lpDispatch->Release(); if(lpOleCommandTarget) lpOleCommandTarget->Release(); return hr; }
NS_IMETHODIMP nsUnknownContentTypeHandler::PromptForSaveToFile( nsIHelperAppLauncher* aLauncher, nsISupports *aWindowContext, const PRUnichar *aDefaultFile, const PRUnichar *aSuggestedFileExtension, PRBool aForcePrompt, nsILocalFile **_retval ) { ///* ATENTIE */ printf("PromptForSaveToFile!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n"); NS_ENSURE_ARG_POINTER(_retval); *_retval = nsnull; /* try to get the PtMozillawidget_t* pointer form the aContext - use the fact the the WebBrowserContainer is registering itself as nsIDocumentLoaderObserver ( SetDocLoaderObserver ) */ nsCOMPtr<nsIDOMWindow> domw( do_GetInterface( aWindowContext ) ); nsIDOMWindow *parent; domw->GetParent( &parent ); PtWidget_t *w = GetWebBrowser( parent ); PtMozillaWidget_t *moz = ( PtMozillaWidget_t * ) w; /* get the suggested filename */ NS_ConvertUTF16toUTF8 theUnicodeString( aDefaultFile ); const char *filename = theUnicodeString.get( ); /* get the url */ nsCOMPtr<nsIURI> aSourceUrl; aLauncher->GetSource( getter_AddRefs(aSourceUrl) ); const char *url; nsCAutoString specString; aSourceUrl->GetSpec(specString); url = specString.get(); /* get the mime type */ nsCOMPtr<nsIMIMEInfo> mimeInfo; aLauncher->GetMIMEInfo( getter_AddRefs(mimeInfo) ); nsCAutoString mimeType; mimeInfo->GetMIMEType( mimeType ); PtCallbackInfo_t cbinfo; PtWebUnknownWithNameCallback_t cb; memset( &cbinfo, 0, sizeof( cbinfo ) ); cbinfo.reason = Pt_CB_MOZ_UNKNOWN; cbinfo.cbdata = &cb; cb.action = Pt_WEB_ACTION_OK; cb.content_type = (char*)mimeType.get(); cb.url = (char *)url; cb.content_length = strlen( cb.url ); cb.suggested_filename = (char*)filename; PtInvokeCallbackList( moz->web_unknown_cb, (PtWidget_t *)moz, &cbinfo ); /* this will modal wait for a Pt_ARG_WEB_UNKNOWN_RESP, in mozserver */ /* we have the result in moz->moz_unknown_ctrl */ if( moz->moz_unknown_ctrl->response != Pt_WEB_RESPONSE_OK ) return NS_ERROR_ABORT; /* the user chosen filename is moz->moz_unknown_ctrl->filename */ nsCOMPtr<nsILocalFile> file(do_CreateInstance("@mozilla.org/file/local;1")); NS_ENSURE_TRUE(file, NS_ERROR_FAILURE); nsCString s ( moz->moz_unknown_ctrl->filename ); file->InitWithNativePath( s ); if( !file ) return NS_ERROR_FAILURE; *_retval = file; NS_ADDREF( *_retval ); /* add this download to our list */ EmbedDownload *download = new EmbedDownload( moz, moz->moz_unknown_ctrl->download_ticket, url ); download->mLauncher = aLauncher; aLauncher->SetWebProgressListener( download ); return NS_OK; }
HWND GetWindowHandle(IHTMLDocument2 *pIHTMLDocument2) { if(!pIHTMLDocument2) return NULL; return GetWindowHandle(GetWebBrowser(pIHTMLDocument2)); }