简体   繁体   English

XUL getNotificationBox

[英]XUL getNotificationBox

I have developed a small addon for firefox in which I save some http proxies since I work a lot with them. 我已经为firefox开发了一个小插件,因为我经常与他们合作,所以在其中保存了一些http代理。 All of the proxies, once loaded into ff, ask for a username and password in a popup window. 一旦将所有代理加载到ff中,它们就会在弹出窗口中询问用户名和密码。 My addon has this information saved so I need to figure out a way of setting the value of the input fields in that notification box which is displayed in order to authenticate to the proxy server and avoid having to manually enter those details every time I change my proxy. 我的插件已保存了此信息,因此我需要找出一种方法来设置显示在该通知框中的输入字段的值,以便对代理服务器进行身份验证,并且避免每次更改我的信息时都必须手动输入这些详细信息代理。

I must admit that I'm an absolute beginner with XUL and javascript as well. 我必须承认,我绝对是XUL和javascript的初学者。 I searched the web and tested all kinds of snippets but I can't get the notification content, decide if it's what I'm looking for and enter the right values. 我在网上搜索并测试了各种代码段,但无法获得通知内容,请确定它是否是我要查找的内容,然后输入正确的值。

I have a piece of code which probably gets near to what I want but it doesn't seem to work: 我有一段代码可能接近我想要的代码,但是似乎没有用:

function getNotificationBox() {
        const Ci = Components.interfaces;

        function getChromeWindow(aWindow) {
                var chromeWin = aWindow
                .QueryInterface(Ci.nsIInterfaceRequestor)
                .getInterface(Ci.nsIWebNavigation)
                .QueryInterface(Ci.nsIDocShellTreeItem)
                .rootTreeItem
                .QueryInterface(Ci.nsIInterfaceRequestor)
                .getInterface(Ci.nsIDOMWindow)
                .QueryInterface(Ci.nsIDOMChromeWindow);
                return chromeWin;
        }

        var notifyWindow = window.top;

        var chromeWin = getChromeWindow(notifyWindow);

        var notifyBox = chromeWin.getNotificationBox(notifyWindow);

        return notifyBox;
}

function clickNotificationButton() {
        netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

        var box = getNotificationBox();
        var bar = box.getNotificationWithValue("is requesting a username and password");
        var button = bar.getElementsByTagName("button").item("OK");
        button.doCommand();
}

window.addEventListener("DOMNodeInserted", function(e) { clickNotificationButton;
}, false);

The piece of string you see there "is requesting a username and password" is part of text that is shown on the notification window. 您在其中看到的“正在请求用户名和密码”字符串是通知窗口中显示的文本的一部分。 Can someone spot if I'm doing something wrong here? 如果我在这里做错了什么,可以发现吗?

Any help is much appreciated. 任何帮助深表感谢。 Thanks! 谢谢!

Are you getting the notification box correctly? 您是否正确收到通知框? You can simplify your getChromeWindow function to: 您可以将getChromeWindow函数简化为:

function getChromeWindow(aWindow) {
    var chromeWin = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
                           .getInterface(Ci.nsIWebNavigation)
                           .QueryInterface(Ci.nsIDocShell)
                           .chromeEventHandler.ownerDocument.defaultView;
    return chromeWin;
}

(http://mxr.mozilla.org/mozilla-central/source/toolkit/components/passwordmgr/src/nsLoginManagerPrompter.js#1208) (http://mxr.mozilla.org/mozilla-central/source/toolkit/components/passwordmgr/src/nsLoginManagerPrompter.js#1208)

You may also need an .wrappedJSObject to your chromeWin variable. 您可能还需要将.wrappedJSObject添加到chromeWin变量。

(http://mxr.mozilla.org/mozilla-central/source/toolkit/components/passwordmgr/src/nsLoginManagerPrompter.js#1295) (http://mxr.mozilla.org/mozilla-central/source/toolkit/components/passwordmgr/src/nsLoginManagerPrompter.js#1295)

From your description, it sounds like the dialog you're trying to intercept is actually the authentication dialog, rather than the notification bar (which appears after the password has been entered to confirm whether you want it saved/changed). 从您的描述中,听起来您要拦截的对话框实际上是身份验证对话框,而不是通知栏(在输入密码以确认是否要保存/更改后,它会出现)。 In other words, it sounds like you want to fix Mozilla bug 223636 (https://bugzilla.mozilla.org/show_bug.cgi?id=223636). 换句话说,听起来您想修复Mozilla错误223636(https://bugzilla.mozilla.org/show_bug.cgi?id=223636)。 Firefox 4 betas actually already have a fix for exactly this case (https://bugzilla.mozilla.org/show_bug.cgi?id=521467), but it's disabled by default (requires changing a hidden pref using about:config). Firefox 4 beta实际上已经针对这种情况进行了修复(https://bugzilla.mozilla.org/show_bug.cgi?id=521467),但默认情况下已禁用(需要使用about:config更改隐藏的首选项)。

The code you pasted isn't going to be very useful for that, unfortunately. 不幸的是,您粘贴的代码将不会非常有用。 To catch authentication dialogs from an extension in currently shipping versions, you probably want a combination of code that observes the "common-dialog-loaded" topic and the dialog handling logic from http://mxr.mozilla.org/mozilla-central/source/toolkit/components/passwordmgr/test/prompt_common.js . 为了从当前发布版本的扩展中捕获身份验证对话框,您可能需要遵循“ common-dialog-loaded”主题的代码与http://mxr.mozilla.org/mozilla-central/中的对话框处理逻辑的组合源/工具包/组件/密码mgr / test / prompt_common.js I can provide more detail if you find me on irc.mozilla.org/#extdev. 如果您在irc.mozilla.org/#extdev上找到我,可以提供更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM