允许内容文件(网页)检测我的Firefox插件 [英] Allow content documents (web pages) to detect my Firefox addon

查看:91
本文介绍了允许内容文件(网页)检测我的Firefox插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Firefox插件中,我正在寻找一种安全的方式来让内容代码检测到插件本身的存在。
理想情况下,我想要的是允许内容代码通过执行以下方式查询我的插件的存在:

In my Firefox addon I'm looking for a secure way to let content code detect the presence of the addon itself. Ideally what I'd like to end up with is allowing content code to query the presence of my addon by executing:

if (window.navigator.my_addon) {
  // the addon is present
} else {
  // the addon is not present
}

任何建议/指针?

推荐答案

改编自这里(但使用getter来使my_addon值为只读)

Adapted from here (but using a getter to make the my_addon value read-only)

// contentWindow is the window object of a contentDocument being displayed
var s = new Components.utils.Sandbox(contentWindow);
s.window = contentWindow;
Components.utils.evalInSandbox("
  window.wrappedJSObject.navigator.__defineGetter__('my_addon', function(){ 
    return true; // or whatever we want its value to be
                 // (note: this is unprivileged code!)
  });", 
  s
);

这篇关于允许内容文件(网页)检测我的Firefox插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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