PlanetSquires Forums

Support Forums => José Roca Software => Topic started by: Paul Squires on October 27, 2018, 11:49:16 AM

Title: CWebCtx and timeout on navigate
Post by: Paul Squires on October 27, 2018, 11:49:16 AM
Hi Jose,

I may not be using the control correctly so please forgive me if my understanding is wrong. I implemented the code into WinFBE and everything seemed to work well except that the first page loads would time out (returns a value of 1 indicating object failed to initialize until the timeout of 10 seconds). The second page load seemed to load after about 8 seconds or so. Subsequent pages loaded almost instantly until eventually I would click on another page to load and it would hang for a while again. Strange.

I ripped the code out of WinFBE and created a bare minimum test program in order to show you. Hopefully the same problem will show on your computer as well. The program is basically a Treeview that recursively loads HTML versions of all of your Markdown help files. Clicking on the Treeview nodes will load the name of the specified HTML file.

Can you shed some light on this? Should I be checking other properties of the browser control (busy state, initialization, etc).

(Code and exe attached in rar archive).

Thanks!
 
Title: Re: CWebCtx and timeout on navigate
Post by: José Roca on October 27, 2018, 12:40:37 PM
I suspect that it is caused by the antivirus software (in my case Windows Defender).

Title: Re: CWebCtx and timeout on navigate
Post by: Paul Squires on October 27, 2018, 03:18:30 PM
Quote from: José Roca on October 27, 2018, 12:40:37 PM
I suspect that it is caused by the antivirus software (in my case Windows Defender).

I also only use Windows Defender. I turned off all virus protect (real time, cloud based, etc) and the problem was still there. I'll try a few other things to see if it makes any difference.
Title: Re: CWebCtx and timeout on navigate
Post by: José Roca on October 27, 2018, 03:45:10 PM
I don't know. If I save a web page, like this one, there is no delay.
Title: Re: CWebCtx and timeout on navigate
Post by: Joerg B. on October 28, 2018, 12:26:15 PM
Hello Paul
I can confirm the problem.
I am using Kaspersky Internet Security.  Whether I quit the software or have it active makes no difference to me.
I wait up to 17 seconds for the content to be displayed.
Title: Re: CWebCtx and timeout on navigate
Post by: Paul Squires on October 28, 2018, 01:24:37 PM
Thanks Joerg, I appreciate you confirming the problem. I wonder if it is something in the generated HTML that is causing the slowdown because Jose points out that other HTML seems to work okay. Obviously I won't implement this type of help system into WinFBE if the wait times are this long.
Title: Re: CWebCtx and timeout on navigate
Post by: SeaVipe on October 28, 2018, 03:44:32 PM
Hi Paul,
Similar delay on my Windows 10, BitDefender machine.


Interesting that rapid, multiple clicks on the tree will eventually work and display the correct page but with an initial delay. To your code I added ? "a", ? "b" before every line of code (a through m). With multiple clicks on the tree, once the initial delay expired and all the pages rapidly displayed, the Console displayed as per the attached image.


It turns out the delay is at the end of the rapid clicks.


This is the line of code just after ? "k"

pwb->SetFocus
Title: Re: CWebCtx and timeout on navigate
Post by: SeaVipe on October 28, 2018, 05:21:30 PM
Hi Paul,


Using different code (example code in WinFBX) I see that this HTML code has an impact on file load time:




  <!--[if lt IE 9]>
  <script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
  <![endif]-->



The browser is being interpreted as IE9
Title: Re: CWebCtx and timeout on navigate
Post by: Paul Squires on October 28, 2018, 05:54:11 PM
Hi Clive, great catch there buddy - thanks! Yes, it certainly does appear that could be the bottleneck. I downloaded the javascript code directly from https://github.com/aFarkas/html5shiv and put it in the same folder as the html file. I then modified the html file as follows and the loads were almost instantaneous.

  <!--[if lt IE 9]>
    <script src="html5shiv-printshiv.min.js"></script>
  <![endif]-->
Title: Re: CWebCtx and timeout on navigate
Post by: Paul Squires on October 28, 2018, 06:34:13 PM
I updated my conversion tools to modify the html code to point to a local copy of the javascript file. I have attached a new rar archive with all of the new files. It appears to load very quickly now. Please let me know if it is also fast for you. Thanks!
Title: Re: CWebCtx and timeout on navigate
Post by: José Roca on October 28, 2018, 06:57:53 PM
The solution seems to be:

To add

  <meta http-equiv='X-UA-Compatible' content='IE=edge' />
  <meta http-equiv='MSThemeCompatible' content='Yes'>

in the head section

and remove

  <!--[if lt IE 9]>
    <script src="html5shiv-printshiv.min.js"></script>
  <![endif]-->

Thanks to Microsofot infinite wisdom, the embedded WebBrowser control emulates IE 7.

Adding

  <meta http-equiv='X-UA-Compatible' content='IE=edge' />

to the web page forces to use the latest IE installed without emulating IE 7.

The purpose of the html5shiv-printshiv.min.js script is to add support for HMTL5 to older versions of IE by parsing the DOM and modifying it.
Title: Re: CWebCtx and timeout on navigate
Post by: Paul Squires on October 28, 2018, 07:05:42 PM
Wow, thanks Jose! I will pivot my course and update the html's using your code. That will be faster and cleaner than loading the javascript, etc.
:)
Title: Re: CWebCtx and timeout on navigate
Post by: SeaVipe on October 28, 2018, 07:14:41 PM
Paul, Your current version works very fast.

I'll look again after the next update.
Title: Re: CWebCtx and timeout on navigate
Post by: Paul Squires on October 28, 2018, 11:14:48 PM
I have updated my tools to create html files based on Jose's suggestion to add the "X-UA-Compatible" meta tag. Seems to work very well and fast. I have attached the new files.
Title: Re: CWebCtx and timeout on navigate
Post by: José Roca on October 29, 2018, 07:02:10 AM
It is very annoying that now that HTML5 is mainstream, the embedded WebBroser control still emulates IE 7. If we build the web page, we can use the meta tag workaround, but we are powerless when we load a web page from internet. In this case, the only thing that we can do is to modify a registry setting.
Title: Re: CWebCtx and timeout on navigate
Post by: José Roca on October 29, 2018, 07:17:36 AM
This meta tag

<meta http-equiv='MSThemeCompatible' content='Yes'>

makes the WebBrowser control to become themed if the application uses visual styles.

And there is also the DPI awareness question, but fortunately you don't have to bother about it because the CWebCtx class creates automatically a custom implementation of the IDocHostUIHandler interface, that is the only way to achieve it.

This class has an overridable method called GetHostInfo that by default sets the following flags: DOCHOSTUIFLAG_NO3DBORDER OR DOCHOSTUIFLAG_THEME OR DOCHOSTUIFLAG_DPI_AWARE


' =====================================================================================
' Gets the UI capabilities of the application that is hosting MSHTML.
' DOCHOSTUIFLAG_DIALOG
'     MSHTML does not enable selection of the text in the form.
' DOCHOSTUIFLAG_DISABLE_HELP_MENU
'     MSHTML does not add the Help menu item to the container's menu.
' DOCHOSTUIFLAG_NO3DBORDER
'     MSHTML does not use 3-D borders on any frames or framesets. To turn the border off
'     on only the outer frameset use DOCHOSTUIFLAG_NO3DOUTERBORDER
' DOCHOSTUIFLAG_SCROLL_NO
'     MSHTML does not have scroll bars.
' DOCHOSTUIFLAG_DISABLE_SCRIPT_INACTIVE
'     MSHTML does not execute any script until fully activated. This flag is used to
'     postpone script execution until the host is active and, therefore, ready for script
'     to be executed.
' DOCHOSTUIFLAG_OPENNEWWIN
'     MSHTML opens a site in a new window when a link is clicked rather than browse to
'     the new site using the same browser window.
' DOCHOSTUIFLAG_DISABLE_OFFSCREEN
'     Not implemented.
' DOCHOSTUIFLAG_FLAT_SCROLLBAR
'     MSHTML uses flat scroll bars for any UI it displays.
' DOCHOSTUIFLAG_DIV_BLOCKDEFAULT
'     MSHTML inserts the div tag if a return is entered in edit mode. Without this flag,
'     MSHTML will use the p tag.
' DOCHOSTUIFLAG_ACTIVATE_CLIENTHIT_ONLY
'     MSHTML only becomes UI active if the mouse is clicked in the client area of the
'     window. It does not become UI active if the mouse is clicked on a non-client area,
'     such as a scroll bar.
' DOCHOSTUIFLAG_OVERRIDEBEHAVIORFACTORY
'     MSHTML consults the host before retrieving a behavior from the URL specified on
'     the page. If the host does not support the behavior, MSHTML does not proceed to
'     query other hosts or instantiate the behavior itself, even for behaviors developed
'     in script (HTML Components (HTCs)).
' DOCHOSTUIFLAG_CODEPAGELINKEDFONTS
'     Microsoft Internet Explorer 5 and later. Provides font selection compatibility
'     for Microsoft Outlook Express. If the flag is enabled, the displayed characters
'     are inspected to determine whether the current font supports the code page. If
'     disabled, the current font is used, even if it does not contain a glyph for the
'     character. This flag assumes that the user is using Internet Explorer 5 and
'     Outlook Express 4.0.
' DOCHOSTUIFLAG_URL_ENCODING_DISABLE_UTF8
'     Internet Explorer 5 and later. Controls how nonnative URLs are transmitted over
'     the Internet. Nonnative refers to characters outside the multibyte encoding of
'     the URL. If this flag is set, the URL is not submitted to the server in UTF-8 encoding.
' DOCHOSTUIFLAG_URL_ENCODING_ENABLE_UTF8
'     Internet Explorer 5 and later. Controls how nonnative URLs are transmitted over
'     the Internet. Nonnative refers to characters outside the multibyte encoding of
'     the URL. If this flag is set, the URL is submitted to the server in UTF-8 encoding.
' DOCHOSTUIFLAG_ENABLE_FORMS_AUTOCOMPLETE
'     Internet Explorer 5 and later. Enables the AutoComplete feature for forms in the
'     hosted browser. The Intelliforms feature is only turned on if the user has
'     previously enabled it. If the user has turned the AutoComplete feature off for
'     forms, it is off whether this flag is specified or not.
' DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION
'     Internet Explorer 5 and later. Enables the host to specify that navigation should
'     happen in place. This means that applications hosting MSHTML directly can specify
'     that navigation happen in the application's window. For instance, if this flag is
'     set, you can click a link in HTML mail and navigate in the mail instead of opening
'     a new Windows Internet Explorer window.
' DOCHOSTUIFLAG_IME_ENABLE_RECONVERSION
'     Internet Explorer 5 and later. During initialization, the host can set this flag
'     to enable Input Method Editor (IME) reconversion, allowing computer users to employ
'     IME reconversion while browsing Web pages. An input method editor is a program that
'     allows users to enter complex characters and symbols, such as Japanese Kanji
'     characters, using a standard keyboard. For more information, see the International
'     Features reference in the Base Services section of the Windows Software Development
'     Kit (SDK).
' DOCHOSTUIFLAG_THEME
'     Internet Explorer 6 and later. Specifies that the hosted browser should use themes
'     for pages it displays.
' DOCHOSTUIFLAG_NOTHEME
'     Internet Explorer 6 and later. Specifies that the hosted browser should not use
'     themes for pages it displays.
' DOCHOSTUIFLAG_NOPICS
'     Internet Explorer 6 and later. Disables PICS ratings for the hosted browser.
' DOCHOSTUIFLAG_NO3DOUTERBORDER
'     Internet Explorer 6 and later. Turns off any 3-D border on the outermost frame or
'     frameset only. To turn borders off on all frame sets, use DOCHOSTUIFLAG_NO3DBORDER
' DOCHOSTUIFLAG_DISABLE_EDIT_NS_FIXUP
'     Internet Explorer 6 and later. Disables the automatic correction of namespaces when
'     editing HTML elements.
' DOCHOSTUIFLAG_LOCAL_MACHINE_ACCESS_CHECK
'     Internet Explorer 6 and later. Prevents Web sites in the Internet zone from accessing
'     files in the Local Machine zone.
' DOCHOSTUIFLAG_DISABLE_UNTRUSTEDPROTOCOL
'     Internet Explorer 6 and later. Turns off untrusted protocols. Untrusted protocols
'     include ms-its, ms-itss, its, and mk:@msitstore.
' DOCHOSTUIFLAG_HOST_NAVIGATES
'     Internet Explorer 7. Indicates that navigation is delegated to the host; otherwise,
'     MSHTML will perform navigation. This flag is used primarily for non-HTML document types.
' DOCHOSTUIFLAG_ENABLE_REDIRECT_NOTIFICATION
'     Internet Explorer 7. Causes MSHTML to fire an additional DWebBrowserEvents2::BeforeNavigate2
'     event when redirect navigations occur. Applications hosting the WebBrowser Control
'     can choose to cancel or continue the redirect by returning an appropriate value in
'     the Cancel parameter of the event.
' DOCHOSTUIFLAG_USE_WINDOWLESS_SELECTCONTROL
'     Internet Explorer 7. Causes MSHTML to use the Document Object Model (DOM) to create
'     native "windowless" select controls that can be visually layered under other elements.
' DOCHOSTUIFLAG_USE_WINDOWED_SELECTCONTROL
'     Internet Explorer 7. Causes MSHTML to create standard Microsoft Win32 "windowed"
'     select and drop-down controls.
' DOCHOSTUIFLAG_ENABLE_ACTIVEX_INACTIVATE_MODE
'     Internet Explorer 6 for Windows XP Service Pack 2 (SP2) and later. Requires user
'     activation for Microsoft ActiveX controls and Java Applets embedded within a web page.
'     This flag enables interactive control blocking, which provisionally disallows direct
'     interaction with ActiveX controls loaded by the APPLET, EMBED, or OBJECT elements.
'     When a control is inactive, it does not respond to user input; however, it can perform
'     operations that do not involve interaction.
' DOCHOSTUIFLAG_DPI_AWARE
'     Internet Explorer 8. Causes layout engine to calculate document pixels as 96 dots
'     per inch (dpi). Normally, a document pixel is the same size as a screen pixel. This
'     flag is equivalent to setting the FEATURE_96DPI_PIXEL feature control key on a
'     per-host basis.
' Remarks
'     The DOCHOSTUIFLAG_BROWSER flag, a supplementary defined constant (not technically
'     a part of this enumeration), combines the values of DOCHOSTUIFLAG_DISABLE_HELP_MENU
'     and DOCHOSTUIFLAG_DISABLE_SCRIPT_INACTIVE.
' =====================================================================================
FUNCTION CDocHostUIHandler2.GetHostInfo (BYVAL pInfo AS DOCHOSTUIINFO PTR) AS HRESULT
   CWBX_DP("*** CDocHostUIHandler2.GetHostInfo pInfo = " & WSTR(pInfo))
   IF m_GetHostInfoProc THEN RETURN m_GetHostInfoProc(m_pWebCtx, pInfo)
   ' // Default behavior if the user does not processes this event...
   IF pInfo THEN
      pInfo->cbSize = SIZEOF(DOCHOSTUIINFO)
      pInfo->dwFlags = DOCHOSTUIFLAG_NO3DBORDER OR DOCHOSTUIFLAG_THEME OR DOCHOSTUIFLAG_DPI_AWARE
      pInfo->dwDoubleClick = DOCHOSTUIDBLCLK_DEFAULT
      pInfo->pchHostCss = NULL
      pInfo->pchHostNS = NULL
   END IF
   RETURN S_OK
END FUNCTION
' =====================================================================================

Title: Re: CWebCtx and timeout on navigate
Post by: Paul Squires on October 29, 2018, 09:19:56 AM
Hi José, I guarantee you that if it wasn't for your involvement in FreeBASIC, then I suspect that I would have migrated to a different programming language long ago. I had flirted with C++ and C#, but once you built WinFBX the decision to stay in the BASIC sphere was an easy one. The amount of tools that your WinFBX library gives us makes FB programming a breeze.

On my longer term radar is cross platform programming. I retire within 5 years so by then I want to be able to write commercial grade applications that will run across all platforms. Not ready to go down that path yet because technology will change so much by then but I'll start at it in a couple/three years from now. Tech like Electron or .Net Core certainly looks promising based on today's tools.