Mono and window.external

2019-06-14 12:11发布

问题:

This will be a Windows Forms application deployed through ClickOnce. The plan is to use the WebBrowser control to expose a web application that makes use of Active-X controls. Using window.external and InvokeScript, the objects will be replaced with references to Reg-Free COM objects (SXS). I know this sounds like a mess, but it's a lesser evil, and I'm on a tight schedule. Eventually, the SXS part can be replaced, and hopefully the server-side code can be updated with something better. Will there be serious performance problems with this? How much trouble am I asking for with this?

Will targetting .NET 2.0 make it easier to have code that is portable between Mono and .NET? Is VB.NET code troublesome to port to Mono? I'm assuming it shouldn't be? (I am working with VB6 programmers).

The docs say that window.external is not available under Mono. It sounds like there are plans to implement this. Is it safe to just use window.external now and wait for Mono to implement it? Or, is there a way to emulate this?

I have other plans to slowly make the code more portable, and I'm hoping I can use this as a sort of method (read: loophole) to make it possible.

If you have suggestions on attitudes and states of mind, I'd be happy to hear them too. But please try to answer my main concerns first. Thank you.

回答1:

I don't understand exactly what you are trying to do, but I see specific words I can respond to:

  • Mono does not support ClickOnce.
  • Mono does not support ActiveX. There is some COM stuff, but I do not know how complete it is.
  • Mono's WebBrowser control supports basic operations, however window.external is very advanced functionality that is very IE specific. There is currently no work being put into the WebBrowser control, and I do not see that changing any time soon, unless someone contributes what you need.

Will targeting .NET 2.0 make it easier to have code that is portable between Mono and .NET?

I assume this is opposed to targeting .NET 3.5, and not .NET 1.1. The .NET 2.0 class libraries are much more complete than the .NET 3.0/3.5 ones (no WPF, no WF, limited WCF). However, if you just want C# 3 features like LINQ, all of C# 3 should work fine.

Is VB.NET code troublesome to port to Mono?

C# is definitely better supported than VB.Net on Mono. The VB.Net compiler is currently version version 8.0 (2005). The VB.Net runtime class library is also not complete. (Though you can completely avoid that and still use VB.Net.)



回答2:

Here's a hack to simulate windows.external in a .NET WebBrowser control:

In your javascript code you've put in the webbrowser control, encapsulate your calls to window.external (for example):

function wex() { window.external.WBEvent(arguments[0], arguments[1]); return false; }

Change the function to navigate, but with your own protocol:

function wex() { location.href = 'wex://DOMAIN//' + arguments[0] + '//' + arguments[1]; return false; }

Intercept and cancel the navigation in your Visual Basic code:

  Private Sub WebBrowser_Navigating(ByVal sender As Object, _
             ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs) _
             Handles WebBrowser.Navigating

    With e
        If .Url.AbsoluteUri.StartsWith("wex://") Then
            Dim str As String = HttpUtility.UrlDecode(.Url.AbsoluteUri)
            Dim pos As Integer = InStr(14, str, "//")
            WBEvent(Mid(str, 15, pos - 15), Mid(str, pos + 2))
            'Debug.Print("wex " & Mid(str, 15, pos - 15) & " " & Mid(str, pos + 2))
            e.Cancel = True
        End If
    End With
End Sub

DOMAIN will be converted to lowercase. That's why it's ignored.

If you had more than one function, then let that be the first part of the uri and do a select statement in the navigating event code.