GeckoFx (6)替换、禁用系统弹窗警告
来源:互联网 发布:大数据融合技术 kettle 编辑:程序博客网 时间:2024/06/08 07:44
定义:
browser:Gecko.GeckoWebBrowser 控件;
目标:
屏蔽在输入的域名为无效域名,或者断网等情况下,弹出的默认提示窗口。
域名写错时,弹出的提示如下:
Alert “test.csdn.net could not be found. Please check the name and try again.”
解决方案:
//设置浏览器弹窗是否可用
PromptFactory.PromptServiceCreator = () => new FilteredPromptService((title, text) =>
{
//Msg(string.Format("{0}:{1}", title, text));
return false;
});
var browser = new Gecko.GeckoWebBrowser();
1.使用 PromptFactory.PromptServiceCreator 属性,替换默认的推送服务类//源码public class PromptFactory:nsIPromptFactory{/// <summary>/// Allow injecting different PromptService implementations into PromptFactory./// Custom PromptService may implement some or all of nsIPrompt, nsIAuthPrompt2, and nsIAuthPrompt./// </summary>public static Func<object> PromptServiceCreator { get; set; }}2.定义自己的推送服务类 FilteredPromptServiceusing System;using System.Collections.Generic;using System.Linq;using System.Text;using Gecko;namespace MyTest{ /// <summary> /// Used to prevent from displaying certain firefox alerts about unknown protocols. /// </summary> internal class FilteredPromptService : nsIPromptService2, nsIPrompt { /// <summary> /// 消息推送服务 /// </summary> /// <param name="onPromptBefor">系统弹窗前事件,返回false 将不弹窗系统警示框</param> public FilteredPromptService(Func<string,string,bool> onPromptBefor) { _onPromptBefor = onPromptBefor; } private Func<string, string, bool> _onPromptBefor = null; /// <summary> /// 弹窗前事件 /// </summary> /// <param name="aDialogTitle"></param> /// <param name="aText"></param> /// <returns></returns> private bool PromptBefor(string aDialogTitle, string aText) { if (_onPromptBefor == null)return true; return _onPromptBefor(aDialogTitle, aText); } public void Alert(nsIDOMWindow aParent, string aDialogTitle, string aText) { if (!PromptBefor(aDialogTitle ?? "Alert", aDialogTitle)) return; _promptService.Alert(aDialogTitle, aText); } public void AlertCheck(nsIDOMWindow aParent, string aDialogTitle, string aText, string aCheckMsg, ref bool aCheckState) { _promptService.AlertCheck(aDialogTitle, aText, aCheckMsg, ref aCheckState); } public bool Confirm(nsIDOMWindow aParent, string aDialogTitle, string aText) { return _promptService.Confirm(aDialogTitle, aText); } public bool ConfirmCheck(nsIDOMWindow aParent, string aDialogTitle, string aText, string aCheckMsg, ref bool aCheckState) { return _promptService.ConfirmCheck(aDialogTitle, aText, aCheckMsg, ref aCheckState); } public int ConfirmEx(nsIDOMWindow aParent, string aDialogTitle, string aText, uint aButtonFlags, string aButton0Title, string aButton1Title, string aButton2Title, string aCheckMsg, ref bool aCheckState) { return _promptService.ConfirmEx(aDialogTitle, aText, aButtonFlags, aButton0Title, aButton1Title, aButton2Title, aCheckMsg, ref aCheckState); } public bool Prompt(nsIDOMWindow aParent, string aDialogTitle, string aText, ref string aValue, string aCheckMsg, ref bool aCheckState) { return _promptService.Prompt(aDialogTitle, aText, ref aValue, aCheckMsg, ref aCheckState); } public bool PromptUsernameAndPassword(nsIDOMWindow aParent, string aDialogTitle, string aText, ref string aUsername, ref string aPassword, string aCheckMsg, ref bool aCheckState) { return _promptService.PromptUsernameAndPassword(aDialogTitle, aText, ref aUsername, ref aPassword, aCheckMsg, ref aCheckState); } public bool PromptPassword(nsIDOMWindow aParent, string aDialogTitle, string aText, ref string aPassword, string aCheckMsg, ref bool aCheckState) { return _promptService.PromptPassword(aDialogTitle, aText, ref aPassword, aCheckMsg, ref aCheckState); } public bool Select(nsIDOMWindow aParent, string aDialogTitle, string aText, uint aCount, IntPtr[] aSelectList, ref int aOutSelection) { return _promptService.Select(aDialogTitle, aText, aCount, aSelectList, ref aOutSelection); } public bool PromptAuth(nsIDOMWindow aParent, nsIChannel aChannel, uint level, nsIAuthInformation authInfo, string checkboxLabel, ref bool checkValue) { return _promptService.PromptAuth(aChannel, level, authInfo); } public nsICancelable AsyncPromptAuth(nsIDOMWindow aParent, nsIChannel aChannel, nsIAuthPromptCallback aCallback, nsISupports aContext, uint level, nsIAuthInformation authInfo, string checkboxLabel, ref bool checkValue) { return _promptService.AsyncPromptAuth(aChannel, aCallback, aContext, level, authInfo); } public void Alert(string dialogTitle, string text) { if (text.Contains(_unknownProtocolFilterString)) return; if (text.Contains(_proxyErrorFilterString)) return; if (!PromptBefor(dialogTitle ?? "Alert", text)) return; _promptService.Alert(dialogTitle, text); } public void AlertCheck(string dialogTitle, string text, string checkMsg, ref bool checkValue) { _promptService.AlertCheck(dialogTitle, text, checkMsg, ref checkValue); } public bool Confirm(string dialogTitle, string text) { return _promptService.Confirm(dialogTitle, text); } public bool ConfirmCheck(string dialogTitle, string text, string checkMsg, ref bool checkValue) { return _promptService.ConfirmCheck(dialogTitle, text, checkMsg, ref checkValue); } public int ConfirmEx(string dialogTitle, string text, uint buttonFlags, string button0Title, string button1Title, string button2Title, string checkMsg, ref bool checkValue) { return _promptService.ConfirmEx(dialogTitle, text, buttonFlags, button0Title, button1Title, button2Title, checkMsg, ref checkValue); } public bool Prompt(string dialogTitle, string text, ref string value, string checkMsg, ref bool checkValue) { return _promptService.Prompt(dialogTitle, text, ref value, checkMsg, ref checkValue); } public bool PromptPassword(string dialogTitle, string text, ref string password, string checkMsg, ref bool checkValue) { return _promptService.PromptPassword(dialogTitle, text, ref password, checkMsg, ref checkValue); } public bool PromptUsernameAndPassword(string dialogTitle, string text, ref string username, ref string password, string checkMsg, ref bool checkValue) { return _promptService.PromptUsernameAndPassword(dialogTitle, text, ref username, ref password, checkMsg, ref checkValue); } public bool Select(string dialogTitle, string text, uint count, IntPtr[] selectList, ref int outSelection) { return _promptService.Select(dialogTitle, text, count, selectList, ref outSelection); } #region Non COM methods private static PromptService _promptService = new PromptService(); #endregion #region Filter strings. private const string _unknownProtocolFilterString = "Firefox doesn't know how to open this address, because the protocol"; private const string _proxyErrorFilterString = "Firefox is configured to use a proxy server that can't be found."; #endregion }}
0 1
- GeckoFx (6)替换、禁用系统弹窗警告
- 禁用第三方库警告
- 禁用第三方库警告
- Excel操作——禁用警告提示
- EXCEL 宏打不开 安全警告 宏被禁用
- Excel操作——禁用警告提示
- 禁用系统错误调试
- 禁用系统休眠
- 禁用系统键盘
- flyme5禁用系统应用
- js 弹窗是否禁用
- sweetAlert替换JsBOM Alert警告框
- OS X禁用NSTextView的引号替换
- WebBrowser控件: GeckoFX
- GeckoFx (5)调用js
- xcode禁用代码分析的警告和内存泄漏
- Xcode禁用代码分析的警告和内存泄漏
- request请求https时禁用安全请求警告
- Nagios系统监控指标扩展
- 绘制点、线、面
- 线段树内容详解
- http post上传数据
- Caffe傻瓜系列(10):draw_net.py绘制caffe net结构
- GeckoFx (6)替换、禁用系统弹窗警告
- redis扩展ibatis缓存
- Caffe傻瓜系列(11):caffe中的lr_policy选择
- perl的hello world
- Android资源文件中颜色使用的总结
- Spring 动态管理定时任务(使用quartz) 只是管理启动时间 不能做启动和暂停
- Garbage Collection | Mark-Sweep算法
- 全选与反选_购物车
- 用php实现计算两人名字之间的缘分