为 Windows Phone 8 App WebBrowser Control 注册自定义协议 [英] Registering Custom Protocol for Windows Phone 8 App WebBrowser Control

查看:21
本文介绍了为 Windows Phone 8 App WebBrowser Control 注册自定义协议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种为 Windows Phone 8 注册自定义协议的方法.我尝试使用 WebRequest.RegisterPrefix("xxx://", this) 注册自定义协议,但是这个不适用于 WebBrowser 控件.由于我们的协议方案没有有效的 uri,如果应用尝试导航(通过 location.url='xxx://this-is-no-valid-uri'),它就会崩溃.

I'm searching for a way to register a custom protocol for Windows Phone 8. I tried to register a custom protocol with WebRequest.RegisterPrefix("xxx://", this) but this will not work for the WebBrowser control. Since our protocol scheme is no valid uri the app will just crash if it try to navigate (via location.url='xxx://this-is-no-valid-uri').

我希望任何人都能在黑暗中传播光明;)

I hope anyone can spread light into the darkness ;)

这里是我的测试项目.我认为这是一个主要错误,因为您可以通过简单的 JavaScript 语句强制每个应用程序崩溃.

Here is my test project. I think this is a major bug because you can force every app to crash with just a simple JavaScript statement.

推荐答案

我的问题终于有了解决方案,您需要注册一个自己的 UriParser.

I finally got a Solution for my Problem, you need to register a own UriParser.

我的 UriParser:

public class MyUriParser : UriParser
{
    public MyUriParser()
    {

    }

    protected override string GetComponents(Uri uri, UriComponents components, UriFormat format)
    {
        return "";
    }
    protected override bool IsWellFormedOriginalString(Uri uri)
    {
        return true;
    }
    protected override void InitializeAndValidate(Uri uri, out UriFormatException parsingError)
    {
        parsingError = null;
    }
    protected override bool IsBaseOf(Uri baseUri, Uri relativeUri)
    {
        return false;
    }
    protected override string Resolve(Uri baseUri, Uri relativeUri, out UriFormatException parsingError)
    {
        parsingError = null;
        return "";
    }
}

注册方式:

if (!UriParser.IsKnownScheme(SCHEMENAME_0))
    UriParser.Register(new MyUriParser(), SCHEMENAME_0, 80);

这篇关于为 Windows Phone 8 App WebBrowser Control 注册自定义协议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆