阅读理解FireFox浏览器插件开发文档(一)

昨天白天用官方示例在主机安装了FF插件,然而晚上回寝室用VS2013并没有成功,不禁想起了那句话“程序员都是好男人,他们每天都会反省自己,我又错在哪了”。

言归正传,今天的目标是阅读理解FF插件官方文档,我这菜鸡一般的英语水平勉强能应付。

一、Initialization
当一个插件加载了,在创建第一个实例之前就会调用NPError NP_Initialize(void) {};分配内存资源给所有实例使用。
对应的NP_Shutdown函数是在最后一个实例销毁糊调用,用来释放NP_Initialize分配的内存资源

/* Define global variable to hold the user agent string. */
static char* userAgent = NULL;

/* Initialize function. */
NPError NP_Initialize(void)
{
  /* Get the user agent from the browser. */
  char* result = NPN_UserAgent();
  if (result == NULL) return NPERR_OUT_OF_MEMORY_ERROR;

  /* Allocate some memory so that you can keep a copy of it. */
  userAgent = (char*) NPN_MemAlloc(strlen(result) + 1);
  if (userAgent == NULL) return NPERR_OUT_OF_MEMORY_ERROR;

  /* Copy the string to your memory. */
  strcpy(userAgent, result);

  return NPERR_NO_ERROR;
}

/* Shutdown function */
NPError NP_Shutdown(void)
{
  /* Delete the memory you allocated. */
  if (userAgent != NULL)
    NPN_MemFree(userAgent);

  return NPERR_NO_ERROR;
}

userAgent 是什么,“用户代理”?算了暂时不管了,反正它是个全局静态指针变量。指的是NPN_UserAgent()得到的资源。

二、MIMEType
在初始化的时候,浏览器会去数MIMEType类型的已被注册的插件。接着看看怎么注册插件吧。
“A MIME type is made up of a major type (such as application or image) and a minor type, for example, image/jpeg.If you define a new MIME type for a plug-in, you must register it with IETF (Internet Engineering Task Force). Until your new MIME type is registered, preface its name with “x-“, for example, image/x-nwim.”
IETF看不懂。我的FF浏览器application已经存在,所以我昨天修改的MIMEType没有加“x-”。

紧接着往后看我就炸了!
When a Gecko-based browser starts up, it checks certain directories for plug-ins, in this order:

Windows
1、Directory pointed to by MOZ_PLUGIN_PATH environment variable.
2、%APPDATA%\Mozilla\plugins, where %APPDATA% denotes per-user Application Data directory.
3、Plug-ins within toolkit bundles.
4、Profile directory\plugins, where Profile directory is a user profile directory.
5、Directories pointed to by HKEY_CURRENT_USER\Software\MozillaPlugins*\Path registry value, where * can be replaced by any name.
6、Directories pointed to by HKEY_LOCAL_MACHINE\Software\MozillaPlugins*\Path registry value, where * can be replaced by any name.

奇怪啊,最开始我在
HKEY_LOCAL_MACHINE\Software\MozillaPlugins\添加@mozilla.com.cn/test可是浏览器并没有检测到我的插件啊,反而在HKEY_CURRENT_USER\Software\MozillaPlugins\添加时才有效果。现在再试一次,还是如此!
算了不较真了,除了最后一条,其他的在我电脑上都好用。

Mac OS X
1、~/Library/Internet Plug-Ins.
2、/Library/Internet Plug-Ins.
3、/System/Library/Frameworks/JavaVM.framework/Versions/Current/Resources.
4、Plug-ins within toolkit bundles.
5、Profile directory/plugins, where Profile directory is a user profile directory.

Linux
1、 Directory pointed to by MOZ_PLUGIN_PATH environment variable. For example:

#!/bin/bash
export MOZ_PLUGIN_PATH=/usr/lib64/mozilla/plugins
exec /usr/lib64/firefox/firefox

Which /usr/lib64/mozilla/plugins this is path for folder with plugins,  /usr/lib64/firefox/firefox  this is path for firefox (binary file). 

2、 ~/.mozilla/plugins.
3、 /usr/lib/mozilla/plugins (on 64-bit systems, /usr/lib64/mozilla/plugins is used instead).

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值