CDHtmlDialog crashes while navigating to pdf after navigating to google - html

Navigate from www.google.com page to pdf file causes exception in CDHtmlDialog.
This exception is not present while navigating from pages other than google (e.g. www.wikipedia.org).
Overridden "OnBeforeNavigate", "OnNavigateComplete" and "OnDocumentComplete" events. Then found that, in issue scenario, while loading pdf file "OnNavigateComplete" is called twice.
The calling sequence is as follows: OnBeforeNavigate=>OnNavigateComplete=>OnNavigateComplete
As "OnNavigateComplete" is called without calling "OnBeforeNavigate", "m_spHtmlDoc" in CDHtmlDialog does not become NULL and validation causes assertion in "CDHtmlDialog::OnNavigateComplete".
ASSERT(m_spHtmlDoc==NULL);
Header:
class CClientAppDlg : public CDHtmlDialog
cpp:
CClientAppDlg::CClientAppDlg(CWnd* pParent /*=nullptr*/)
: CDHtmlDialog(IDD_CLIENTAPP_DIALOG, 0, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CClientAppDlg::OnBnClickedNavigate()
{
UpdateData(TRUE);
Navigate(m_csNavURL); // Get URL from edit box and navigate
UpdateData (FALSE);
}
void CClientAppDlg::OnBeforeNavigate( LPDISPATCH pDisp, LPCTSTR szUrl)
{
CDHtmlDialog::OnBeforeNavigate(pDisp, szUrl);
}
void CClientAppDlg::OnNavigateComplete( LPDISPATCH pDisp, LPCTSTR szUrl)
{
CDHtmlDialog::OnNavigateComplete(pDisp, szUrl);
}
void CClientAppDlg::OnDocumentComplete(LPDISPATCH pDisp, LPCTSTR szUrl)
{
CDHtmlDialog::OnDocumentComplete(pDisp, szUrl);
}
Why "OnNavigateComplete" is called twice and causing exception?
Why does it happen only while navigating from google page?

Related

Handling exceptions from a Method in a dialog that can be model and modeless

This is an extract of a method in CDialog class:
void CDialog1::Method()
{
try
{
// Snip
}
catch (CException* e_)
{
const gsl::not_null<CException*> e{ e_ };
e->ReportError();
e->Delete();
}
catch (const _com_error& e)
{
AfxMessageBox(e.ErrorMessage(), MB_OK | MB_ICONERROR);
}
}
There is no issue with this function when it is ran from an instance of the modal dialog.
But, in another part of my application I load the same dialog as a hidden modeless dialog. And I call the same function. Eg:
void CDialog2::SomeTask()
{
if (m_pDialog1 != nullptr)
{
m_pDialog1->Method();
}
}
In this second scenario there is an issue with Method when an error is encountered. CDialog2 needs to handle the display of the errors from what I understand, because the hidden instance will appear if it shows a messagebox.
How do I get around this? Note that CDialog1 has a boolean method IsHiddenMode so we know if we are running it as a model or not.
What is the easy way to change my methods to cater for both scenarios:
When CDialog1 calls the method in it's modal dialog.
When CDialog2 calls the method using the modeless member variable of CDialog1.
I tend to overcomplicate my explanations so I hope it makes sense.
I adjusted the Method to detect if the dialog was in hidden mode and throw the exception, eg:
catch (const _com_error& e)
{
if (IsHiddenMode())
{
throw;
}
else
{
AfxMessageBox(e.ErrorMessage(), MB_OK | MB_ICONERROR);
}
}
That way, the calling dialog could catch and handle with a try / catch block.

p:dialog show message or reload

In a jsf 2.2 primefaces application, I have a link that opens a dialog that has a form. On submission of the form, I want to close the dialog and reload the current page or show an error on the dialog itself.
The managedbean method is a void method that sets the status using RequestContext - addcallbackparam.
As the dialog submission happens using actionlistener and the remainder of the operation happens in javascript, I can’t quite handle this.
I followed the example provided on primefaces website.
https://www.primefaces.org/showcase/ui/overlay/dialog/loginDemo.xhtml
Can anyone provide any information.
Here is something you can try without using addcallbackparam and javascript..
On validation success, hide the dialog & reload page or on failure, set a warning message as below from managed bean:
public void login(ActionEvent event) {
if(username != null && username.equals("admin") && password != null && password.equals("admin")) {
RequestContext requestContext = RequestContext.getCurrentInstance();
requestContext.execute("PF('dlg').hide()");
pageReload();
} else {
dialogWarning = "Validation failed";
}
}
public void pageReload() {
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
try {
ec.redirect(((HttpServletRequest) ec.getRequest()).getRequestURI());
} catch (IOException ex) {
//catch and log IO exception here
}
}
In the xhtml dialog set dynamic=true and display the warning message as below and add this id to the update attribute in the Login component.
<h:outputLabel id="warnMsgLabel" value="#userLoginView.dialogWarning" />

UWP: Xamarin Forms Tabbed Page changing page doesn't call OnAppearing

In a Xamarin Forms project, I have created a TabbedPage inside which I have added 5 child navigation pages.
{
Children.Add(new NavigationPage(new A()));
Children.Add(new NavigationPage(new B()));
Children.Add(new NavigationPage(new C()));
Children.Add(new NavigationPage(new D()));
Children.Add(new NavigationPage(new E()));
}
When I click manually on a tab B from Tab A; B's OnAppearing method is called as expected. However when I programmatically change the tab using
tabbedPage.CurrentPage = tabbedPage.Children[index]
Then B's OnAppearing method is called never. This is happening on UWP.
As of Xamarin Forms 3.4.0.1008975 and UWP 6.1.5 this still appears to be an issue. I solved it like this:
Make an interface called IAppearable:
internal interface IAppearable
{
void HandleAppearing();
}
Have your content page implement this interface:
public partial class MyContentPage : ContentPage, IAppearable
In HandleAppearing do what you would have done in OnAppearing:
public void HandleAppearing()
{
// do appearing stuff here
}
After you programmatically set your tab page use this code:
CurrentPage = Children[pageIndex];
if (Device.RuntimePlatform == Device.UWP)
{
if (CurrentPage is IAppearable appearablePage)
{
appearablePage.HandleAppearing();
}
}

Redirect after Login MyWSAT

I've been testing the example code here http://mywsat.codeplex.com/
In their example they have different buttons to login to either the admin pages or members page using seperate links
However, I'm trying to use a single link to a landing page and after the user logs in redirect to the relevant page using codebehind. The landingpage requires login but all roles can view this page set in the rules.
landingpage.aspx:
protected void Page_Load(object sender, EventArgs e)
{
string redirectPath;
string pagePath = Request.AppRelativeCurrentExecutionFilePath;
if (Page.User.IsInRole("Administrator"))
{
//Admin
redirectPath = "~/admin/Default.aspx";
if (redirectPath != pagePath)
{
Response.Redirect(redirectPath);
}
}
else if (Page.User.IsInRole("Member"))
{
//Members
redirectPath = "~/members/Default.aspx";
if (redirectPath != pagePath)
{
Response.Redirect(redirectPath);
}
}
else if (Page.User.IsInRole("Trial"))
{
//Trial
redirectPath = "~/trial/Default.aspx";
if (redirectPath != pagePath)
{
Response.Redirect(redirectPath);
}
}
else
{
//Non member
redirectPath = "~/Default.aspx";
if (redirectPath != pagePath)
{
Response.Redirect(redirectPath);
}
}
}
The problem is the Page_Load event fires straight away and then launches login-with-captcha.ascx after the event has fired.
So then I moved the code to the login form login-with-captcha.ascx.cs to redirect after e.Authenticated = true; but it just redirects back to login-with-captcha.ascx in an endless loop
login-with-captcha.ascx.cs:
// Next, determine if the user's username/password are valid
if (Membership.ValidateUser(loginUsername, loginPassword))
{
e.Authenticated = true;
//tried redirecting from here based on role!
}
else
//............
How can I redirect from the landing page after the user is validated? I suspect it may have something to do with postback but need some help
Can you try adding the following as the first line within your Page_Load to see if it helps? This will likely prevent the endless loop issue if it's being caused by something that triggers a postback event, like a button click.
if (IsPostBack) return;

NPAPI Plugin[FireFox]: Invoke() / HasProperty() / HasMethod() not getting called

I am developing NPAPI Plugin for Firefox on windows. here is the my java script:
document.addEventListener('load', documentLoad, true);
function loadPlugin(doc)
{
var objWebMon = doc.getElementById("my_firefox");
if(!objWebMon)
{
var objWebMonEmbed = doc.createElement('embed');
objWebMonEmbed.setAttribute('id', 'my_firefox');
objWebMonEmbed.setAttribute('type', 'application/npplugin');
objWebMonEmbed.setAttribute('style', 'height: 10px; width:10px; display:block;');
if(doc.body)
{
doc.body.insertBefore(objWebMonEmbed, doc.body.firstChild);
}
}
}
function documentLoad(event) {
try
{
var doc = event.originalTarget; // doc is document that triggered "onload" event
loadPlugin(doc);
var myplugin = doc.getElementById('my_firefox');
if(myplugin)
{
myplugin();
myplugin.myAction();
}
} catch(err)
{
}
}
as I am calling myplugin()
bool ScriptablePluginObject::InvokeDefault(const NPVariant *args, uint32_t argCount, NPVariant *result)
gets called sucessfully but on calling function myplugin.myAction()
bool ScriptablePluginObject::Invoke(NPIdentifier name, const NPVariant *args,
uint32_t argCount, NPVariant *result)
function doesn't called. I have declared myAction inside ScriptablePluginObject::HasProperty(NPIdentifier name) even HasProperty method is not getting called.
Inside catch block i am getting this error. TypeError: fasso.myAction is not a function.
Here are a couple of things to try:
Use an object tag instead of an embed -- I've had more consistent success with object tags, despite the wide popularity of using embed
Never ever ever set the type of an object or embed tag before you add it to the DOM -- doing so causes it to instantiate the plugin and then puts it in a kinda weird state when it gets moved. I don't think this is causing your issue this time, but it's worth trying.
You may need a slight delay between inserting hte plugin into the DOM and using it. Try adding a setTimeout with a delay of 50ms and accessing the plugin in the callback function.
Honestly, #3 is the one I think most likely will make a difference, but I present the other two as they have bitten me on weird things in the past. Good luck!