此JavaScript如何在Firefox中打开Windows设置? [英] How does this JavaScript open Windows Settings in Firefox?

查看:50
本文介绍了此JavaScript如何在Firefox中打开Windows设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在重新安装Firefox 45 Developer Edition之后,我看到了此页面.它具有一个按钮(让我们来做"),单击该按钮后,将以某种方式在Windows 10中打开选择默认应用设置页面.

解决方案

页面在文档上触发类型为 mozUITour 的自定义事件.此事件在浏览器中由 content-UITour.js ,它将大部分实际处理都铲除到 UITour-lib.js .

通过所有客户端抽象,这是正在发生的事情:

  document.dispatchEvent(new CustomEvent('mozUITour',{气泡:是的,细节: {动作:"setConfiguration",数据: {配置:'defaultBrowser'}}})); 

然后在浏览器中,它处理事件,将事件分派到另一个内部事件队列中,在其中将通过调用 ="https实现的 nsIShellService :: setDefaultBrowser ://hg.mozilla.org/mozilla-central/file/22f51211915b/browser/components/shell/nsWindowsShellService.cpp#l926"rel =" nofollow> nsWindowsShellService.cpp .在当前的943行上,我们有:

  if(IsWin10OrLater()){rv = LaunchModernSettingsDialogDefaultApps();} 别的 {rv = LaunchControlPanelDefaultsSelectionUI();} 

我认为

LaunchModernSettingsDialogDefaultApps 是一个漂亮的描述性函数名称.

现在,根据您的评论,例如,一种可以在自己的页面上使用它的方式"?不太可能. content-UITour.js 检查页面是否具有 uitour 权限.来自 browser/app/permissions ,我们有:

 #UITour原始资料1 https://www.mozilla.org原始资料1 https://self-repair.mozilla.org原始资料1 https://support.mozilla.org来源uitour 1关于:首页 

因此,除非您是 www.mozilla.org self-repair.mozilla.org support.mozilla.org about:home ,您不能这样做,至少默认情况下不能这样做.在Firefox 15(具有手动设置的17)更改之前,请参见此错误以获取更多信息),则可以使用 netscape.security.PrivilegeManager.enablePrivilege 来请求浏览器的额外权限,但这已经不复存在了,而且我不确定是否触及相同的权限机制.

After a new install of Firefox 45 Developer Edition, I saw this page. It has a button ("Let's do it") that when clicked, somehow opens up the Choose default apps settings page in Windows 10.

https://www.mozilla.org/en-US/firefox/windows-10/welcome/?utm_source=firefox-browser&utm_medium=firefox-browser

How is this done? I couldn't find anything through the Developer Console in the labyrinthine code on that page. Besides, I would have thought browsers don't allow JavaScript to open something as sensitive as the Settings app.

解决方案

The page fires a custom event of type mozUITour on the document. This event is handled in the browser by content-UITour.js, which shovels out most of the actual processing to UITour.jsm. The unobfuscated client-side code can be viewed in UITour-lib.js.

Cutting through all the client-side abstraction, this is what’s happening:

document.dispatchEvent(new CustomEvent('mozUITour', {
    bubbles: true,
    detail: {
        action: 'setConfiguration',
        data: {
            configuration: 'defaultBrowser'
        }
    }
}));

Then in the browser, it handles the event, dispatches the event in another internal event queue, where it will be processed by calling into nsIShellService::setDefaultBrowser, implemented by nsWindowsShellService.cpp. On what’s currently line 943, we have:

if (IsWin10OrLater()) {
  rv = LaunchModernSettingsDialogDefaultApps();
} else {
  rv = LaunchControlPanelDefaultsSelectionUI();
}

And LaunchModernSettingsDialogDefaultApps, I think, is a pretty descriptive function name.

Now, from your comment, "in a way that one could use it on their own page, for example"? Not so likely. content-UITour.js checks that the page has the uitour permission. From browser/app/permissions, we have:

# UITour
origin  uitour  1   https://www.mozilla.org
origin  uitour  1   https://self-repair.mozilla.org
origin  uitour  1   https://support.mozilla.org
origin  uitour  1   about:home

So unless you’re www.mozilla.org, self-repair.mozilla.org, support.mozilla.org, or about:home, you can’t do it, at least not by default. Before Firefox 15 (17 with a manual settings change, see this bug for more information), you might be able to use netscape.security.PrivilegeManager.enablePrivilege to request extra permissions from the browser, but that’s not around any more, and I’m not sure that even touches the same permission mechanism.

这篇关于此JavaScript如何在Firefox中打开Windows设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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