问题
I am developing a Browser Helper Object (BHO) for Internet Explorer written in C#. I use the BeforeNavigate
event to get a called URL and save it into a local variable. For every tab a new BHO instance is spawned. This means that every tab has it's own BHO which in turn have own local variables. I have checked this by displaying a MessageBox with the previous called URL (the value of the local variable) before it is overwritten with the new URL.
string myUrl = "";
void BeforeNavigate( string URL, ... )
{
System.Windows.Forms.MessageBox.Show( myUrl );
myUrl = URL.ToString();
}
But in some cases the local variable is empty although a URL was called before. I investigated the IE settings and found out that this behavior is caused by the zone elevation protection of IE. For the zones local intranet
and trusted sites
the protected mode is disabled while it is enabled for zones internet
and restricted sites
.
E.g., when intranet.com
is called and then internet.com
in the same tab, I would expect that the MessageBox displays intranet.com
when internet.com
is called. But an empty string is displayed instead. I guess that calling internet.com
activates the protected mode for this tab which spawns a new instance of the BHO. The MessageBox will now display the value of the variable of the new BHO instance. The value of the variable of the old BHO gets lost.
If protected mode is enabled for zones local intranet
and trusted sites
the BHO behaves correctly. I guess that the protected mode is disabled in this zones for compatibility reasons. There may exists websites in the intranet that do not work with protected mode. Thus, I am looking for a solution that works with protected mode disabled for this zones.
Since IE manages the loading of the BHO I doubt that this problem can be solved from within the BHO.
Does anybody have deeper knowledge about this topic to confirm my guess?
Is it possible to keep the variable's value with protected mode disabled for zones local intranet
and trusted sites
?
Any help will be appreciated, thanks!
回答1:
I found the following link: http://jimevansmusic.blogspot.com/2012/08/youre-doing-it-wrong-protected-mode-and.html
There is said:
When you cross into or out of Protected Mode by, say, navigating from an internal intranet website to one on the internet, IE has to create a new process, because it can't change the Mandatory Integrity Control level of the existing process. Moreover, in IE versions after 7, it's not always obvious that a Protected Mode boundary has been crossed, since IE tries to present a better user experience by seamlessly merging the browser window of the new process with the already opened browser window. This under-the-covers process switching also means that any references pointing to IE's COM objects before the Protected Mode boundary crossing are left pointing to objects that are no longer used by IE after the boundary crossing.
Based on this, my guess seems to be right. The BHO which is a COM object of IE is no longer used and thus it's value gets lost. The only solution that remains is to enable or disable protected mode for all zones.
来源:https://stackoverflow.com/questions/52777207/ies-zone-elevation-protection-interferences-functionality-of-bho