﻿<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>学习日记 &#187; plugin</title>
	<atom:link href="https://www.softwareace.cn/?feed=rss2&#038;tag=plugin" rel="self" type="application/rss+xml" />
	<link>https://www.softwareace.cn</link>
	<description>时刻想着为自己的产品多做一些对他好的事情</description>
	<lastBuildDate>Fri, 20 Mar 2026 06:58:28 +0000</lastBuildDate>
	<language>zh-CN</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>我的Firefox插件开发之旅（8）——插件的安装与更新</title>
		<link>https://www.softwareace.cn/?p=152</link>
		<comments>https://www.softwareace.cn/?p=152#comments</comments>
		<pubDate>Wed, 30 Jan 2013 03:19:42 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[firefox 插件]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://www.softwareace.cn/?p=152</guid>
		<description><![CDATA[插件写好了，下面就该做一个安装包了。最好再提供更新功能，以便在插件有更新的时候，及时通知用户进行插件更新。 我 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	插件写好了，下面就该做一个安装包了。最好再提供更新功能，以便在插件有更新的时候，及时通知用户进行插件更新。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	我们开发的时候，直接将生成的dll丢到Firefox安装目录下的plugins目录就可以工作了，但是你如何说服让用户来手动完成这件事情？估计很难。因此，提供一个安装包，可能是最好的选择。用户只需要点几下鼠标就可以完成插件的安装了。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	不过到写这篇文章的时候，我还不清楚怎么让安装包经过Mozilla的验证，因为没有经过验证的插件，在安装的时候会出现&ldquo;仅安装信任作者的附加组件&rdquo;提示对话框，提示用户仅安装受信任作者的插件。如果有人知道怎么去掉这个警告对话框，还望不吝赐教。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	最最简单的插件安装包在这篇文章中开头处写的很清楚了：<a href="https://developer.mozilla.org/en/Shipping_a_plugin_as_an_extension" style="color: rgb(0, 102, 170); text-decoration: initial;" title="https://developer.mozilla.org/en/Shipping_a_plugin_as_an_extension">https://developer.mozilla.org/en/Shipping_a_plugin_as_an_extension</a></p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	安装包的目录结构：</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	install.rdf<br />
	plugins/<br />
	&nbsp;&nbsp;&nbsp; pluginlib.dll<br />
	&nbsp;&nbsp;&nbsp; plugintypes.xpt</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	其中xpt文件可选。install.rdf的内容为：</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	&lt;RDF xmlns=&quot;<a href="http://www.w3.org/1999/02/22-rdf-syntax-ns#%22" style="color: rgb(0, 102, 170); text-decoration: initial;">http://www.w3.org/1999/02/22-rdf-syntax-ns#&quot;</a>&nbsp;xmlns:em=&quot;<a href="http://www.mozilla.org/2004/em-rdf#%22" style="color: rgb(0, 102, 170); text-decoration: initial;">http://www.mozilla.org/2004/em-rdf#&quot;</a>&gt;<br />
	&nbsp; &lt;Description about=&quot;urn:mozilla:install-manifest&quot;&gt;<br />
	&nbsp;&nbsp;&nbsp; &lt;em:id&gt;mypluginid@myplugin.com&lt;/em:id&gt;<br />
	&nbsp;&nbsp;&nbsp; &lt;em:name&gt;My Plugin&lt;/em:name&gt;<br />
	&nbsp;&nbsp;&nbsp; &lt;em:version&gt;1.0&lt;/em:version&gt;<br />
	&nbsp;&nbsp;&nbsp; &lt;em:targetApplication&gt;<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Description&gt;<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;em:id&gt;{ec8030f7-c20a-464f-9b0e-13a3a9e97384}&lt;/em:id&gt;<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;em:minVersion&gt;1.5&lt;/em:minVersion&gt;<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;em:maxVersion&gt;3.0.*&lt;/em:maxVersion&gt;<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/Description&gt;<br />
	&nbsp;&nbsp;&nbsp; &lt;/em:targetApplication&gt;<br />
	&nbsp; &lt;/Description&gt;<br />
	&lt;/RDF&gt;</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	将上面内容安装目录结构用zip格式压缩，将后缀名改为xpi就OK了。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	但是我们要做得事情远不止这些：</p>
<ul style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
<li>
		如何提供插件的更新自动通知？</li>
<li>
		如何将扩展和插件捆绑在一起让用户安装？（因为可能你不仅仅要安装插件，还希望在用户的FF工具栏或菜单上添加一些扩展功能）</li>
<li>
		如何对插件进行签名？</li>
<li>
		如何发布你的插件和扩展，以便让更多人知晓？</li>
</ul>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	要做的事情还很多。那么我们就一个个来研究吧。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	<strong>一、如何提供插件的更新自动通知？</strong></p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	关于Install manifest（即install.rdf）文件内容，Mozilla有篇很详细的文章：<a href="https://developer.mozilla.org/en/Install.rdf" style="color: rgb(0, 102, 170); text-decoration: initial;" title="https://developer.mozilla.org/en/Install.rdf">https://developer.mozilla.org/en/Install.rdf</a>，可以进行参考。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	其中有个节点名称是：updateURL。用这个标签包含一个可查询更新信息的URL连接，今后当FF在查询插件是否有更新时，会到你指定的这个URL上去查询。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	这个URL可以是一个cgi程序、servlet、asp(x)，也可以是一个固定的rdf文件链接。另外文章中也提到了另外一种办法：如果你没有提供updateURL，FF的附加组件管理器会向addons.mozilla.org发送请求，当你上传了一个新版本的插件或者通过作者接口（author interface）更改了兼容性参数，一个更新的manifest文件将会被自动产生。另外，Mozilla建议updateURL使用https而非http，否则你应该提供updateKey（可以用<a href="https://developer.mozilla.org/en/McCoy" style="color: rgb(0, 102, 170); text-decoration: initial;" target="_blank">McCoy</a>生成）。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	那么，负责更新的rdf怎么编写呢？你可以参考这篇文章：<a href="https://developer.mozilla.org/en/Extension_Versioning%2c_Update_and_Compatibility#Update_RDF_Format" style="color: rgb(0, 102, 170); text-decoration: initial;" title="https://developer.mozilla.org/en/Extension_Versioning%2c_Update_and_Compatibility#Update_RDF_Format">https://developer.mozilla.org/en/Extension_Versioning%2c_Update_and_Compatibility#Update_RDF_Format</a>。由于文章中写的很清晰，并且提供了详细的例子代码，这里我就不废话了。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	<strong>二、如何将扩展和插件捆绑在一起让用户安装？</strong></p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	这个很简单。之前的章节我们已经做过一个简单的Extension安装包，如果想附加一个插件的话，只需要和chrome的同级目录下新建一个plugins目录，然后将dll及相关文件放在里面，最后一起打包即可。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	当在FF中安装此xpi时，FF会将Extension和Plugin解压到FF的Profiles目录下。插件和扩展即可生效。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	注意这里与我们之前将插件dll放在FF安装目录下的plugins目录下有些不同（至少位置不同），FF同样能够正确地识别我们的插件。另外Mozilla也推荐做成安装包，这样，在用户卸载组件的时候，可以同时将Extension和Plugin都卸载掉。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	<strong>三、如何对插件进行签名？</strong></p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	很抱歉，还没找到答案&hellip;&hellip;</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	<strong>四、 如何发布你的插件和扩展，以便让更多人知晓？</strong></p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	首先需要在Mozilla网站上注册一个账号（需要提供合法E-mail，因为要激活）。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	登录后，在Mozilla 附加组件首页上你会看到一个&ldquo;开发者工具&rdquo;的链接。进入后，会有明显的导航链接，如&ldquo;提交附加组件&rdquo;。通过这个页面，按照向导，你就可以将你的插件发布出来了。剩下的事，就是宣传咯，呵呵。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	OK，《我的Firefox插件开发之旅》系列文章就先到这里。将来我也许还会写一些关于编写FF的Extension和Plugin方面的技术细节文章。看心情吧，呵呵。</p>
]]></content:encoded>
			<wfw:commentRss>https://www.softwareace.cn/?feed=rss2&#038;p=152</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>我的Firefox插件开发之旅（7）——为插件添加和脚本交互的能力</title>
		<link>https://www.softwareace.cn/?p=151</link>
		<comments>https://www.softwareace.cn/?p=151#comments</comments>
		<pubDate>Wed, 30 Jan 2013 03:18:51 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[firefox 插件]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://www.softwareace.cn/?p=151</guid>
		<description><![CDATA[先说一句题外话，上一节一开始我提到了由于.rc导致我自己写的插件不能被FF识别的问题，今天终于找到答案了。在这 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	先说一句题外话，上一节一开始我提到了由于.rc导致我自己写的插件不能被FF识别的问题，今天终于找到答案了。在这篇文章中：<a href="https://developer.mozilla.org/en/Gecko_Plugin_API_Reference/Plug-in_Development_Overview" style="color: rgb(0, 102, 170); text-decoration: initial;" title="https://developer.mozilla.org/en/Gecko_Plugin_API_Reference/Plug-in_Development_Overview">https://developer.mozilla.org/en/Gecko_Plugin_API_Reference/Plug-in_Development_Overview</a>，有这么一段话：In your development environment, make sure your language is set to &quot;US English&quot; and the character set to &quot;Windows Multilingual.&quot; The resource code for this language and character set combination is 040904E4. 看来这FF还只能使用英文。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	OK，步入正题。这一小节我来简单说一下如何为插件添加和脚本语言（如Javascript）交互的能力。我会为插件添加几个函数，供Javascript调用。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	前面我们提到过浏览器调用插件的方法的顺序，基本上为：NP_GetEntryPoints、NP_Initialize、NPP_New、NPP_SetWindow、NPP_GetValue。在NPP_New中，我们需要创建插件对象的实例，NPP_SetWindow中，浏览器会传入插件窗口的信息，最后一个NPP_GetValue，是浏览器来获取一些插件信息的。NPP_GetValue函数的结构是这样的：</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	<strong>NPError&nbsp; NPP_GetValue(NPP instance, NPPVariable variable, void *value);</strong></p>
<ul style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
<li>
		instance包含着插件对象实例；</li>
<li>
		variable表示浏览器要获取的信息的类型;</li>
<li>
		value表示返回给浏览器的值</li>
</ul>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	<strong>浏览器会传入NPPVpluginScriptableNPObject（作为variable参数）来查询插件是否支持Scriptable功能（即和脚本语言交互的功能），在这里，我们可以利用NPN_CreateObject方法来创建一个NPObject对象，并且作为value返回给浏览器。这样，浏览器就通过这个NPObject对象和我们的插件建立了连接。当页面上Javascript调用了我们插件对象的某个方法时，浏览器会调用该NPObject对象的HasMethod方法来查询是否支持这个方法，如果支持，则会调用NPObject对象的Invoke方法，传入方法名、参数等信息。这样，我们就可以让网页上的脚本语言来执行我们编写的函数了。在Windows上，我们编写的函数就如同编写普通的应用程序一样，可以使用很多Windows API来完成许多复杂的工作。</strong></p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	上面有个问题：如何创建我们自己的NPObject对象？NPN_CreateObject方法如何使用？好在Mozilla给我们提供了npruntime这个例子程序，可以让我们得以参考。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	先来看看NPN_CreateObject方法的定义：</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	NPObject *NPN_CreateObject(NPP npp, NPClass *aClass);</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	关键在第二个参数上，我们需要提供一个NPClass指针。npruntime例子程序中是这么做的：</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	定义了一个宏DECLARE_NPOBJECT_CLASS_WITH_BASE，其作用就是定义了一个静态的NPClass对象，并且NPClass要求的所有基础方法，都由一个ScriptablePluginObjectBase类来提供。我们根据需要，来创建不同的继承于ScriptablePluginObjectBase的类（比如支持方法的类和支持属性的类），传给DECLARE_NPOBJECT_CLASS_WITH_BASE宏，这样，当浏览器管我们&ldquo;要&rdquo;的时候，我们就可以按照它的需要&ldquo;给&rdquo;它对应的对象。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	npruntime例子中，ScriptablePluginObject是用来处理方法的，而ConstructablePluginObject是用来处理属性的。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	&nbsp;</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	<strong>如何定义一个方法（或属性）？</strong></p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	1、添加一个方法（或属性）很简单，先定义一个静态NPIdentifier类型的变量，例如：</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	static NPIdentifier s_idSetArgs;</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	2、在插件对象构造函数中，使用NPN_GetStringIdentifier方法来设置该方法的名称，例如：</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	s_idSetArgs = NPN_GetStringIdentifier(&quot;SetArgs&quot;);</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	其中，SetArgs就是我们提供给脚本语言调用的方法名称。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	3、在ScriptablePluginObject的HasMethod方法中，判断传入的方法名：</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	bool ScriptablePluginObject::HasMethod(NPIdentifier name)<br />
	{<br />
	&nbsp;&nbsp;&nbsp; if(name == s_idSetArgs)<br />
	&nbsp;&nbsp;&nbsp; {<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(&quot;method name = SetArgsn&quot;);<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return true;<br />
	&nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	&nbsp;&nbsp;&nbsp; return false;<br />
	}</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	4、在ScriptablePluginObject的Invoke方法中，判断如果传入的方法名称等于我们定义的方法名，则做你想要做得事情：</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	//////////////////////////////////////////////////////////////////////////<br />
	///<br />
	/// @brief&nbsp;&nbsp;&nbsp; 如果某个方法支持（使用HasMethod检测），当页面上Javascript代码调用该方法时，会执行本函数<br />
	///<br />
	/// @param [in] name&nbsp;&nbsp;&nbsp; 方法名<br />
	/// @param [in] args&nbsp;&nbsp;&nbsp; 参数值（数组）<br />
	/// @param [in] argCount&nbsp;&nbsp;&nbsp; 参数个数<br />
	/// @param [in] result&nbsp;&nbsp;&nbsp; 执行后返回给调用者的结果<br />
	///<br />
	/// @return PR_TRUE表示执行成功，PR_FALSE表示失败<br />
	///<br />
	//////////////////////////////////////////////////////////////////////////</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	bool ScriptablePluginObject::Invoke(NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result)</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	{<br />
	&nbsp;&nbsp;&nbsp; if(name == s_idSetArgs)</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	&nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这里做你想要做得事情</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return PR_TRUE;</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	&nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	&nbsp;&nbsp;&nbsp; return PR_FALSE;</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	}</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	关于方法参数的接收，这里举个例子。比如网页上这么调用：</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	embedobj.SetArgs(&quot;name&quot;, &quot;value&quot;);</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	在我们的方法中，就可以这么接收：</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	if(args != NULL &amp;&amp; argCount &gt;= 2)<br />
	{<br />
	&nbsp;&nbsp;&nbsp; NPVariant npvName = args[0]; //第一个参数<br />
	&nbsp;&nbsp;&nbsp; NPVariant npvValue = args[1]; //第二个参数<br />
	&nbsp;&nbsp;&nbsp; if(NPVARIANT_IS_STRING(npvName) &amp;&amp; NPVARIANT_IS_STRING(npvValue))&nbsp; //如果两者都是字符串类型（当然你还可以判断是否是其他类型）<br />
	&nbsp;&nbsp;&nbsp; {<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NPString npsName = NPVARIANT_TO_STRING(npvName); //转成NPString<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NPString npsValue = NPVARIANT_TO_STRING(npvValue);</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(npsName.utf8characters &amp;&amp; strlen(npsName.utf8characters) &gt; 0) //限定条件，可以根据需要进行修改。这里限定第一个参数内容不能为空<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int nLenName = strlen(npsName.utf8characters) + 1;<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int nLenValue = strlen(npsValue.utf8characters) + 1;</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PARAMPAIR paramPair;<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; paramPair.pName = new char[nLenName];<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; memset(paramPair.pName, 0, nLenName);<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; paramPair.pValue = new char[nLenValue];<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; memset(paramPair.pValue, 0, nLenValue);</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strcpy(paramPair.pName, npsName.utf8characters); //将参数内存存储到我们熟悉的C<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strcpy(paramPair.pValue, npsValue.utf8characters);</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_vecParamPair.push_back(paramPair);<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
	&nbsp;&nbsp;&nbsp; }<br />
	}</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	上面的代码中，PARAMPAIR就是一个简单的结构体：</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	typedef struct tagPARAMPAIR<br />
	{<br />
	&nbsp;&nbsp;&nbsp; LPTSTR pName;<br />
	&nbsp;&nbsp;&nbsp; LPTSTR pValue;<br />
	}PARAMPAIR, *PPARAMPAIR;</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	m_vecParamPair是一个vector：vector&lt;PARAMPAIR&gt; m_vecParamPair;</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	顺便说一句，上面只是代码片段，关于内存释放、vector清空等操作，由于不是这里要说的关键部分，所以没有列出。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	OK，现在我们的插件已经可以顺利和网页进行交互工作了。</p>
]]></content:encoded>
			<wfw:commentRss>https://www.softwareace.cn/?feed=rss2&#038;p=151</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>我的Firefox插件开发之旅（6）——FF插件的一些基础知识</title>
		<link>https://www.softwareace.cn/?p=150</link>
		<comments>https://www.softwareace.cn/?p=150#comments</comments>
		<pubDate>Wed, 30 Jan 2013 03:18:13 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[firefox 插件]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://www.softwareace.cn/?p=150</guid>
		<description><![CDATA[上篇文章学习了npruntime的例子程序，接下来迫不及待地想实现自己的一个插件了。我决定使用VS 2005来 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	上篇文章学习了npruntime的例子程序，接下来迫不及待地想实现自己的一个插件了。我决定使用VS 2005来做。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	新建了一个名为npgnet的工程，按照npruntime例子，新建了np_entry.cpp、npn_gate.cpp、npp_gate.cpp、npgnet.def四个文件，然后新建了一个类CGnetFFPlugin，并且把例子中的关键代码添加了进来（我删除了一些cplugin类中的函数实体代码，因为我实现的功能和例子中的无关）。编译后，将生成的npgnet.dll放到FF的plugins目录下，然后在地址栏键入about:plugins，我靠，竟然没有我的插件！怎么回事？三个导出函数我都按照标准写了啊？比较了一下文件，我的工程没有添加.rc和resource.h，可能是这个原因。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	回到VS 2005，在资源面板添加了一个VERSION资源项，修改ProductName等资源项以后，和npruntime例子比较了一下，还差MIMEType。这个东东很重要，这个给我的感觉就是FF插件的身份证，FF就是靠这个东东来匹配和识别你的插件的。但是我不知道VS 2005中怎么添加一个VERSION的键值，所以我只好用EditPlus打开npgnet.rc，手动添加了MIMEType：application/mozilla-npgnet-scriptable-plugin。OK，现在.rc和resource.h都欧了，再编译，将生成的npgnet.dll放到FF的plugins目录下，然后在地址栏键入about:plugins，我靠，竟然还是没有我的插件！真费解啊！</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	头大&hellip;&hellip;接下来我进行了一系列的代码比较和尝试，失败了N多次，这里就省略不说了。最后发现原因原来在这个.rc上面。我的这个.rc是在VS 2005中使用菜单命令添加的，默认语言是简体中文，而npruntime例子是英文，用文件比较工具比较了一下，codepage和部分代码的位置都不太一样。其实只要把npruntime的这个.rc文件替换我的这个，然后编译输出的dll，FF就可以识别了！究竟是什么原因呢？是我的.rc缺少了些什么东西？还是FF只能识别英文的.rc？先不打算研究那么多了，至少我的插件的关键点不在这个上面，后面我还有很多事情需要去做。只要能让FF认出来，那就好。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	既然决定要写插件，就要先理解插件的概念，在这个页面上有很详细的介绍：<a href="https://developer.mozilla.org/en/Gecko_Plugin_API_Reference/Plug-in_Basics" style="color: rgb(0, 102, 170); text-decoration: initial;" title="https://developer.mozilla.org/en/Gecko_Plugin_API_Reference/Plug-in_Basics">https://developer.mozilla.org/en/Gecko_Plugin_API_Reference/Plug-in_Basics</a></p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	下面的文字是我的一些阅读笔记和体会：</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	<strong>一、插件的加载过程</strong></p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	当一个页面打开时，如果该页面上有嵌入一个插件，浏览器将会做以下事情：</p>
<ul style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
<li>
		通过MIMEType检查是否有匹配插件</li>
<li>
		加载插件代码到内存</li>
<li>
		初始化插件</li>
<li>
		创建一个新的插件实例</li>
</ul>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	插件可以在一个页面上被实例多个对象，也可以在同一时刻在不同的窗口中被实例化。当页面被关闭时，插件的实例就会被销毁。当最后一个实例被删除后，插件代码就会从内存中被卸载掉。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	下面是插件内的函数调用过程：</p>
<ul style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
<li>
		如果插件是首次被载入内存，浏览器会调用插件的<strong>NP_Initialize</strong>方法。为了方便起见，所有的插件定义函数以&ldquo;NPP&rdquo;开头，所有的浏览器定义函数以&ldquo;NPN&rdquo;开头。</li>
<li>
		当浏览器创建插件实例时，会调用<strong>NPP_New</strong>方法。</li>
<li>
		当插件实例被删除时（如关闭页面、关闭窗口），会调用<strong>NPP_Destroy</strong>方法。</li>
<li>
		当最后一个实例被删除，插件从内存中卸载时，会调用<strong>NP_Shutdown</strong>方法。</li>
</ul>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	<strong>二、插件检测</strong></p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	可以使用Javascript来检测一个插件是不是已经安装了，下面是测试代码：<br />
	function DetectFFPlugin()<br />
	{<br />
	&nbsp;&nbsp;&nbsp; var mimetype = navigator.mimeTypes[&quot;application/mozilla-npgnet-scriptable-plugin&quot;];<br />
	&nbsp;&nbsp;&nbsp; if(mimetype)<br />
	&nbsp;&nbsp;&nbsp; {<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var plugin = mimetype.enabledPlugin;<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(plugin)<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.writeln(&quot;Plugin had been installed and be enabled.&quot;);<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
	&nbsp;&nbsp;&nbsp; }<br />
	&nbsp;&nbsp;&nbsp; else<br />
	&nbsp;&nbsp;&nbsp; {<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.writeln(&quot;Sorry, Plugin has NOT been installed.&quot;);<br />
	&nbsp;&nbsp;&nbsp; }<br />
	}</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	嗯，看到这里，觉得这个检测很有用。当检测用户尚未安装时，可以指导用户到哪哪哪去下载安装（转向一个漂亮点儿的页面），当检测已经安装了，就动态加载插件代码。不错。：）</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	<strong>三、插件结构概述</strong></p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	一个插件中的方法分为插件方法（Plug-in Methods）和浏览器方法（Browser Methods）。插件方法是你在插件中自己去执行的那些方法，以NPP为前缀命名。浏览器方法是被Gecko所执行的那些方法，以NPN为前缀命名。数据结构（Data Structures）以NP开头。</p>
<p><span style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">插件可分为有窗口和无窗口两种，不过文章中建议使用有窗口的，说这样会更稳定和易于控制。另外文中提到了可以将插件作为页面的一部分，并且可以使用HTML代码来控制插件的显示与否。</span><br style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);" /><br />
<br style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);" /><br />
<span style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">有两种方式可以使一个插件不可见：</span><br style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);" /><br />
<br style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);" /><br />
<span style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">1、如果你使用embed标签，可以使用其hidden属性，例如：&lt;embed src=&quot;audiplay.aiff&quot; type=&quot;audio/x-aiff&quot; hidden=&quot;true&quot;&gt;</span><br style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);" /><br />
<span style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">2、如果你是用object标签，由于它没有hidden属性，你可以用CSS来完成隐藏：</span><br style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);" /><br />
<br style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);" /><br />
<span style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">object&nbsp;</span><br style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);" /><br />
<span style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">{&nbsp;</span><br style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);" /><br />
<span style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">&nbsp;&nbsp;&nbsp; visibility: visible;&nbsp;</span><br style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);" /><br />
<span style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">}&nbsp;</span><br style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);" /><br />
<span style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">object.hiddenObject&nbsp;</span><br style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);" /><br />
<span style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">{&nbsp;</span><br style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);" /><br />
<span style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">&nbsp;&nbsp;&nbsp; visibility: hidden !important;&nbsp;</span><br style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);" /><br />
<span style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">&nbsp;&nbsp;&nbsp; width: 0px&nbsp; !important;&nbsp;</span><br style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);" /><br />
<span style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">&nbsp;&nbsp;&nbsp; height: 0px&nbsp; !important;&nbsp;</span><br style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);" /><br />
<span style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">&nbsp;&nbsp;&nbsp; margin: 0px&nbsp; !important;&nbsp;</span><br style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);" /><br />
<span style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">&nbsp;&nbsp;&nbsp; padding: 0px&nbsp; !important;&nbsp;</span><br style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);" /><br />
<span style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">&nbsp;&nbsp;&nbsp; border-style: none&nbsp; !important;&nbsp;</span><br style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);" /><br />
<span style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">&nbsp;&nbsp;&nbsp; border-width: 0px&nbsp; !important;&nbsp;</span><br style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);" /><br />
<span style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">&nbsp;&nbsp;&nbsp; max-width: 0px&nbsp; !important;&nbsp;</span><br style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);" /><br />
<span style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">&nbsp;&nbsp;&nbsp; max-height: 0px&nbsp; !important;&nbsp;</span><br style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);" /><br />
<span style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">}&nbsp;</span><br style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);" /><br />
<br style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);" /></p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	&lt;object data=&quot;audiplay.aiff&quot; type=&quot;audio/x-aiff&quot;&nbsp;<strong>class=&quot;hiddenObject&quot;</strong>&gt;&lt;/object&gt;</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	接下来文中介绍了object这个标签的使用。并且给了一个例子来说明ActiveX和插件如何融为一体来使用。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	最后面的部分是对object和embed两种标签的各种属性的说明和举例。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	值得一提的是，对于object和embed两种标签都可以在页面上嵌入一个插件。如何取舍呢？文章中有这么一段话：</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	Though the&nbsp;<code>object</code>&nbsp;element is the preferred way to invoke plug-ins, the&nbsp;<code>embed</code>&nbsp;element can be used for backward compatibility with Netscape 4.x browsers, and in cases where you specifically want to prompt the user to install a plug-in, because the default plug-in is only automatically invoked when you use the&nbsp;<code>embed</code>&nbsp;element.</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	意思是说：尽管object是推荐使用的调用插件的方式，embed也可嵌入插件（Netscape 4.x以上的浏览器），但如果你想在用户没有安装插件时，提示他进行安装，那么就应该选择用embed，因为FF的默认插件系统仅仅在你使用embed标签的时候，才会自动帮助你完成这种提示用户安装的效果。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	我看过以后的感觉是，object使用起来似乎比embed要复杂，起码针对FF这个浏览器是这样，虽然他是HTML W3C的标准。多数情况下使用embed就可以了，何况现在谁还在用Netscape 4.x以下版本的浏览器啊，您说是不是？：）</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	OK，通过这几天的学习，终于对FF的插件编写有了一个初步的感性认识。到目前为之一切还比较顺利。</p>
]]></content:encoded>
			<wfw:commentRss>https://www.softwareace.cn/?feed=rss2&#038;p=150</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>我的Firefox插件开发之旅（5）——编译和测试第一个Plugin例子：npruntime</title>
		<link>https://www.softwareace.cn/?p=149</link>
		<comments>https://www.softwareace.cn/?p=149#comments</comments>
		<pubDate>Wed, 30 Jan 2013 03:17:22 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[firefox 插件]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://www.softwareace.cn/?p=149</guid>
		<description><![CDATA[前几天一直在忙乎着研究和阅读XUL和FF的Extension相关资料，今天突然发现，我要做得事情似乎不是用Ex [&#8230;]]]></description>
				<content:encoded><![CDATA[<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	前几天一直在忙乎着研究和阅读XUL和FF的Extension相关资料，今天突然发现，我要做得事情似乎不是用Extension来实现的。因为原来的应用是一个ActiveX，网页会将一些参数通过ActiveX控件传递进来，而ActiveX接到这些参数以后，会和服务器进行一些数据交互，最后调起本地的执行程序。似乎我走了一些弯路，方向不对。我要做得事情应该是编写一个Plugin，而非Extension。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	及时修正了下一步的研究计划，那么就让我们先来编译和测试Mozilla提供的一个小例子吧。原文连接在这里：</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	<a href="https://developer.mozilla.org/En/Compiling_The_npruntime_Sample_Plugin_in_Visual_Studio" style="color: rgb(0, 102, 170); text-decoration: initial;" title="https://developer.mozilla.org/En/Compiling_The_npruntime_Sample_Plugin_in_Visual_Studio">https://developer.mozilla.org/En/Compiling_The_npruntime_Sample_Plugin_in_Visual_Studio</a>。文章中是以VS2003举例，我这里以VC6来进行测试，并且将步骤中需要注意的地方特别说明了一下。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	1、先到这里下载相关源码：<a href="http://mxr.mozilla.org/seamonkey/source/modules/plugin/samples/npruntime/" style="color: rgb(0, 102, 170); text-decoration: initial;" title="http://mxr.mozilla.org/seamonkey/source/modules/plugin/samples/npruntime/">http://mxr.mozilla.org/seamonkey/source/modules/plugin/samples/npruntime/</a>。不知道为什么Mozilla只提供了页面形式，没有打个包，害得我得一个个文件下载和保存，郁闷。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	2、在VC6中新建一个Win32 Dynamic-Link Library工程，取名&ldquo;nprt&rdquo;。注意：建议工程以小写np开头，并且长度不超过8个字符，这样以后就会省事很多。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	3、下一步，选择&ldquo;An empty DLL project&rdquo;，然后&ldquo;Finish&rdquo;。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	4、将刚才下载的源码添加到工程中来。test.html不用添加，nprt.def建议也添加进来。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	5、现在还不能编译，否则会出很多错误。打开Project Settings，转到C/C++标签页，在Category中选择Preprocessor，在Preprocessor Definitions中最后面添加：,XP_WIN32,MOZILLA_STRICT_API,XPCOM_GLUE,XP_WIN,_X86_。注：如果你使用VS 2005，需要添加全部的定义：WIN32;_WINDOWS;NPRT_EXPORTS;XP_WIN32;MOZILLA_STRICT_API;XPCOM_GLUE;XP_WIN;_X86_</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	6、在Additional include directories下面添加XULRunner SDK的include路径，可以是绝对路径，也可以是相对路径，看你当初怎么解压的了。例如：&#8230;.xulrunner-sdkinclude</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	7、在Category中选择Precompiled Headers，选择Not using precompiled headers，OK，关闭Project Settings对话框。打开npp_gate.cpp，将下面的代码注释掉：<br />
	jref NPP_GetJavaClass (void)<br />
	{<br />
	&nbsp; return NULL;<br />
	}</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	8、编译！&hellip;&hellip;我靠，有错：Fatal error C1083: Cannot open include file: &#39;npapi.h&#39;: No such file or directory。我可是严格按照教程上面写的去做得啊。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	9、在xulrunner-sdk目录下搜索了一下npapi.h，原来在xulrunner-sdksdkinclude下面，这好办，多加一条包含路径不就欧了？仿照第6步，添加该目录；</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	10、编译！OK，过了。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	11、到输出目录下将nprt.dll复制到FF安装目录的plugins目录下，例如：C:Program FilesMozilla Firefoxplugins</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	12、如果此时FF开着也没关系，不用关（这点很不错）。在地址栏键入about:plugins，看看是不是有一个npruntime scriptable example plugin，如果有，那就表示欧了，FF认出了我们的插件；</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	13、在FF中打开test.html，嗯？怎么还提示安装缺失插件？用EditPlus打开test.html，噢，原来有这么一句：&lt;embed type=&quot;application/x-java-mozilla-npruntime-scriptable-plugin&quot; style=&quot;display: block; width: 50%; height: 100px;&quot;&gt;。因为我们刚才没有添加名字为x-java-mozilla-npruntime-scriptable-plugin的插件，所以当然认不出来啦。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	14、随便点一下页面上的按钮，看看简单的交互行为。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	&nbsp;</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	OK，第一个例子还算顺利，比想象中的要顺利。下面就该研究一下代码了，看看FF的插件和ActiveX的区别到底有多大。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	附一些参考资料：<br />
	<a href="http://xinsync.xju.edu.cn/index.php/archives/2124" style="color: rgb(0, 102, 170);" title="http://xinsync.xju.edu.cn/index.php/archives/2124">http://xinsync.xju.edu.cn/index.php/archives/2124</a><br />
	<a href="http://mqjing.blogspot.com/2008/09/plugin-firefox-plugin.html" style="color: rgb(0, 102, 170); text-decoration: initial;" title="http://mqjing.blogspot.com/2008/09/plugin-firefox-plugin.html">http://mqjing.blogspot.com/2008/09/plugin-firefox-plugin.html</a></p>
]]></content:encoded>
			<wfw:commentRss>https://www.softwareace.cn/?feed=rss2&#038;p=149</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>我的Firefox插件开发之旅（4）——XULRunner的一个例子</title>
		<link>https://www.softwareace.cn/?p=148</link>
		<comments>https://www.softwareace.cn/?p=148#comments</comments>
		<pubDate>Wed, 30 Jan 2013 03:16:28 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[firefox 插件]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://www.softwareace.cn/?p=148</guid>
		<description><![CDATA[上一节写了一个Extension，添加了一个按钮在FF3的工具栏上。接下来我准备在这个基础上添加一个功能，点击 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	上一节写了一个Extension，添加了一个按钮在FF3的工具栏上。接下来我准备在这个基础上添加一个功能，点击按钮，读取本地磁盘上一个文件的内容，并显示出来。怎么做呢？用Javascript吗？因为我最终的目标是从服务器上下载文件，也可能会传输本地文件到服务器上，用Javascript访问本地文件有诸多限制，而且也无法完成复杂的功能。所以最好是能够调用我编写的 DLL那就最好不过了。怎么做呢？还是在Mozilla网站上找找看吧。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	在Mozilla网站上看到，可以自己编写Component来完成一些自定义操作。需要首先安装Gecko SDK（现在叫XULRunner SDK），Windows上有两个版本，1.8是for FF1.5/2.0的，1.9是for FF3.0的，由于我机器上安装的是FF3.0，那么就先下载1.9吧，与FF1.5/2.0兼容的问题以后再说。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	下载了XULRunner SDK 1.9，解压到本地后，在环境变量里配置了PATH到xulrunner-sdk的bin目录，以便可以在command prompt下直接运行xulrunner.exe。OK，环境配置完毕，下面来个写个小例子吧。Mozilla提供了一个短小精悍的例子程序，在这里：<a href="https://developer.mozilla.org/en/Getting_started_with_XULRunner" style="color: rgb(0, 102, 170); text-decoration: initial;" title="https://developer.mozilla.org/en/Getting_started_with_XULRunner">https://developer.mozilla.org/en/Getting_started_with_XULRunner</a></p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	这篇文章一步一步教我们编写一个HelloWorld程序，写的很清楚。不过做完这个例子，我有几个疑问：<br />
	1、在上一节我们写的Extension中，chrome.manifest这个文件是放在根目录的（与chrome目录同级），为什么这里把它放在了chrome目录里面呢？能否保持和Extension相同？我简单尝试了一下，并修改了chrome.manifest里面content所指向的目录，然后运行了一下，什么都没发生，没有看到正常运行时所弹出的对话框，看来还是解析不正确，是不是xulrunner必须要求chrome.manifest在chrome目录下面呢？<br />
	2、application.ini中App节的ID，和Extension的ID（通常是一个GUID）有无关联呢？<br />
	3、调用xulrunner.exe以后，会产生两个目录：extensions和updates，这两个目录是干什么用的呢？</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	另外这里需要特别说明一点：在运行xulrunner去执行application.ini时，千万不能丢掉.exe，即不能写/&gt;xulrunner application.ini，必须是/&gt;xulrunner.exe application.ini，否则会弹出couldn&#39;t parse的错误提示，具体是什么原因我也不清楚。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	另外，这里还有一篇关于xulrunner的教程，解释了一些概念性的东西：<a href="http://blogs.acceleration.net/ryan/archive/2005/05/06/1073.aspx" style="color: rgb(0, 102, 170); text-decoration: initial;" title="http://blogs.acceleration.net/ryan/archive/2005/05/06/1073.aspx">http://blogs.acceleration.net/ryan/archive/2005/05/06/1073.aspx</a></p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	写完这个例子，感觉方向好像不太对，xulrunner好像主要还是做界面，怎么做组件呢？怎么访问本地磁盘文件、甚至系统注册表？在Mozilla的开发者页面上又看到一个东东：XPCOM，开头的一段介绍文字是这样的：</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	XPCOM is a cross platform component object model, similar to Microsoft COM. It has multiple language bindings, letting the XPCOM components be used and implemented in JavaScript, Java, and Python in addition to C++. Interfaces in XPCOM are defined in a dialect of IDL called XPIDL.</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	XPCOM itself provides a set of core components and classes, e.g. file and memory management, threads, basic data structures (strings, arrays, variants), etc. The majority of XPCOM components is not part of this core set and is provided by other parts of the platform (e.g. Gecko or Necko) or by an application or even by an extension.</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	大概的意思是说XPCOM类似于微软的COM组件概念，它可以定义一些接口，可以在JS、Java、Python以及C++中使用。哈哈，看来这个才是我想要的东西。OK，那接下来我就来研究一下这个东东吧。下一节争取能完成我一开始提到的功能。</p>
]]></content:encoded>
			<wfw:commentRss>https://www.softwareace.cn/?feed=rss2&#038;p=148</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>我的Firefox插件开发之旅（3）——我的第一个扩展</title>
		<link>https://www.softwareace.cn/?p=147</link>
		<comments>https://www.softwareace.cn/?p=147#comments</comments>
		<pubDate>Wed, 30 Jan 2013 03:15:38 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[firefox 插件]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://www.softwareace.cn/?p=147</guid>
		<description><![CDATA[简单知道了XUL，迫不及待地想立即编写一个插件，哪怕什么事情都不做也好。O(&#8745;_&#8745;)O 通过这 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	简单知道了XUL，迫不及待地想立即编写一个插件，哪怕什么事情都不做也好。O(&cap;_&cap;)O</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	通过这个页面<a href="https://developer.mozilla.org/en/Building_an_Extension" style="color: rgb(0, 102, 170); text-decoration: initial;" title="https://developer.mozilla.org/en/Building_an_Extension">https://developer.mozilla.org/en/Building_an_Extension</a>，可以找到编写一个插件必须要做得一些事情，写的很清楚。最后产生的目录和文件结构是这个样子：<br />
	install.rdf<br />
	chrome.manifest<br />
	chrome<br />
	&nbsp; |&#8211;content<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&#8211;overlay.xul （我准备在这里编写代码，在FF的工具栏上添加一个按钮）<br />
	&nbsp; |&#8211;locale<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&#8211;en-US<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&#8211;sample.dtd<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&#8211;zh-CN<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&#8211;sample.dtd<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&#8211;zh-TW<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&#8211;sample.dtd<br />
	&nbsp; |&#8211;skin<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&#8211;classic<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&#8211;sampleicon.png<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&#8211;smallicon.png<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&#8211;default.css （界面显示的样式表，今后可能会用到）</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	<br />
	上面文件中的install.rdf、chrome.manifest基本上用例子中的就好了，dtd文件里面是界面文字，这个可以模仿其他插件编写。<br />
	overlay.xul我准备添加一段代码，用来在FF工具栏上添加一个按钮。skin下面的png是准备在工具栏上添加的按钮的图标。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	OK，把上面整个目录用zip打个包，改后缀名为xpi，拖放到FF3中，提示尚未验证作者、是否继续安装。这个先不管它，以后再研究。安装以后，重启FF3，哈哈，写的第一个Extension成功安装了！只不过overlay.xul里面什么都没写，所以还没有视觉上的成就感。下面开始添加overlay.xul中的代码。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	怎么在工具栏上添加按钮呢？感谢Mozilla提供的文档，专门有一篇文章是讲这个地：<a href="https://developer.mozilla.org/en/Creating_toolbar_buttons" style="color: rgb(0, 102, 170); text-decoration: initial;" title="https://developer.mozilla.org/en/Creating_toolbar_buttons">https://developer.mozilla.org/en/Creating_toolbar_buttons</a>。文章里面讲的非常清楚，我这里就不废话了。不过有两点需要注意一下：<br />
	1、样式表中的ID和toolbarbutton的id一定要保持一致；<br />
	2、按钮的label和tooltiptext可以直接添加文字，但如果使用了中文，有可能会显示乱码（至少在我的FF3上是这样）；<br />
	3、按钮的图标一定要大小两种（24&#215;24、16&#215;16）都提供；<br />
	4、label和tooltiptext可以使用dtd中定义的文字，但必须注意：dtd文件必须存为UTF-8编码，否则会导致按钮显示不出来！</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	在FF3的定制工具栏中，有图标，但下方没有文字，好像是我哪里忘记添加文字了，一会儿看看去&hellip;&hellip;</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	好了，我的第一个FF插件就写好了，不过现在只是在工具栏上添加了一个按钮而已，什么事情都没做，下一次我们添加一些行为给它。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	以下附上几个关键文件的内容：</p>
<h5 style="margin: 0px; padding: 0px; font-size: 0.9em; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; line-height: 19px; background-color: rgb(255, 255, 255);">
	<strong>一、install.rdf</strong></h5>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	<br />
	&lt;?xml version=&quot;1.0&quot;?&gt;<br />
	&lt;RDF xmlns=&quot;<a href="http://www.w3.org/1999/02/22-rdf-syntax-ns#%22" style="color: rgb(0, 102, 170); text-decoration: initial;">http://www.w3.org/1999/02/22-rdf-syntax-ns#&quot;</a>&nbsp;xmlns:em=&quot;<a href="http://www.mozilla.org/2004/em-rdf#%22" style="color: rgb(0, 102, 170); text-decoration: initial;">http://www.mozilla.org/2004/em-rdf#&quot;</a>&gt;<br />
	&nbsp;&nbsp;&nbsp; &lt;Description about=&quot;urn:mozilla:install-manifest&quot;&gt;<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;em:id&gt;{859606AC-AFFE-4691-82C5-FA0148A7E2D4}&lt;/em:id&gt;<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;em:version&gt;1.0&lt;/em:version&gt;<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;em:type&gt;2&lt;/em:type&gt;<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;em:name&gt;MeetMePlus&lt;/em:name&gt;<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;em:description&gt;Anywhere, anytime to starting a conferencing&lt;/em:description&gt;<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;em:creator&gt;G-NET&lt;/em:creator&gt;<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;em:iconURL&gt;chrome://meetmeplus/skin/gnet_32.png&lt;/em:iconURL&gt;<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;em:homepageURL&gt;<a href="http://www.meetmeplus.com/" style="color: rgb(0, 102, 170); text-decoration: initial;">http://www.meetmeplus.com/</a>&lt;/em:homepageURL&gt;<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;em:targetApplication&gt;<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Description&gt;<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;em:id&gt;{ec8030f7-c20a-464f-9b0e-13a3a9e97384}&lt;/em:id&gt;<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;em:minVersion&gt;1.5&lt;/em:minVersion&gt;<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;em:maxVersion&gt;3.0.*&lt;/em:maxVersion&gt;<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/Description&gt;<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/em:targetApplication&gt;<br />
	&nbsp;&nbsp;&nbsp; &lt;/Description&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
	&lt;/RDF&gt;</p>
<h5 style="margin: 0px; padding: 0px; font-size: 0.9em; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; line-height: 19px; background-color: rgb(255, 255, 255);">
	<strong>二、chrome.manifest</strong></h5>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	overlay&nbsp;&nbsp;&nbsp; chrome://browser/content/browser.xul&nbsp;&nbsp;&nbsp; chrome://meetmeplus/content/overlay.xul<br />
	content&nbsp;&nbsp;&nbsp; meetmeplus&nbsp;&nbsp;&nbsp; chrome/content/<br />
	style&nbsp;&nbsp;&nbsp; chrome://global/content/customizeToolbar.xul&nbsp;&nbsp;&nbsp; chrome://meetmeplus/skin/default.css<br />
	skin&nbsp;&nbsp;&nbsp; meetmeplus&nbsp;&nbsp;&nbsp; classic/1.0&nbsp;&nbsp;&nbsp; chrome/skin/classic/<br />
	locale&nbsp;&nbsp;&nbsp; meetmeplus&nbsp;&nbsp;&nbsp; zh-CN&nbsp;&nbsp;&nbsp; chrome/locale/zh-CN/</p>
<h5 style="margin: 0px; padding: 0px; font-size: 0.9em; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; line-height: 19px; background-color: rgb(255, 255, 255);">
	<strong>三、overlay.xul</strong></h5>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	&lt;?xml version=&quot;1.0&quot;?&gt;<br />
	&lt;!DOCTYPE overlay SYSTEM &quot;chrome://meetmeplus/locale/overlay.dtd&quot;&gt;<br />
	&lt;?xml-stylesheet href=&quot;chrome://meetmeplus/skin/default.css&quot; type=&quot;text/css&quot;?&gt;</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	&lt;overlay id=&quot;mmp-overlay&quot; xmlns=&quot;<a href="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul%22" style="color: rgb(0, 102, 170); text-decoration: initial;">http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul&quot;</a>&gt;<br />
	&nbsp;&nbsp;&nbsp; &lt;!&#8211; Firefox toolbar &#8211;&gt;<br />
	&nbsp;&nbsp;&nbsp; &lt;toolbarpalette id=&quot;BrowserToolbarPalette&quot;&gt;<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;toolbarbutton id=&quot;meetmeplus-button&quot; type=&quot;menu-button&quot;&nbsp;<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; class=&quot;toolbarbutton-1 chromeclass-toolbar-additional&quot;&gt;<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;menupopup&gt;<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;menuitem label=&quot;&amp;mmp.gotohome;&quot; tooltiptext=&quot;&amp;mmp.gotohome.tooltip;&quot; image=&quot;chrome://meetmeplus/skin/option_16.png&quot; class=&quot;menuitem-iconic&quot;/&gt;<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;menuseparator/&gt;<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;menuitem label=&quot;&amp;mmp.option;&quot; tooltiptext=&quot;&amp;mmp.option.tooltip;&quot; image=&quot;chrome://meetmeplus/skin/option_16.png&quot; class=&quot;menuitem-iconic&quot;/&gt;<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/menupopup&gt;<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/toolbarbutton&gt;<br />
	&nbsp;&nbsp;&nbsp; &lt;/toolbarpalette&gt;<br />
	&lt;/overlay&gt;</p>
<h5 style="margin: 0px; padding: 0px; font-size: 0.9em; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; line-height: 19px; background-color: rgb(255, 255, 255);">
	<strong>四、overlay.dtd</strong></h5>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	&lt;!ENTITY mmp.gotohome &quot;访问G-NET MeetMePlus&quot;&gt;<br />
	&lt;!ENTITY mmp.gotohome.tooltip &quot;访问G-NET MeetMePlus网站&quot;&gt;<br />
	&lt;!ENTITY mmp.option &quot;选项&quot;&gt;<br />
	&lt;!ENTITY mmp.option.tooltip &quot;自定义G-NET MeetMePlus的工作方式&quot;&gt;</p>
]]></content:encoded>
			<wfw:commentRss>https://www.softwareace.cn/?feed=rss2&#038;p=147</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>我的Firefox插件开发之旅（2）——XUL是什么？</title>
		<link>https://www.softwareace.cn/?p=146</link>
		<comments>https://www.softwareace.cn/?p=146#comments</comments>
		<pubDate>Wed, 30 Jan 2013 03:14:46 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[firefox 插件]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://www.softwareace.cn/?p=146</guid>
		<description><![CDATA[What is XUL？这个页面给出了详细的介绍：http://www.xulplanet.com/tutor [&#8230;]]]></description>
				<content:encoded><![CDATA[<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	What is XUL？这个页面给出了详细的介绍：<a href="http://www.xulplanet.com/tutorials/whyxul.html" style="color: rgb(0, 102, 170); text-decoration: initial;" title="http://www.xulplanet.com/tutorials/whyxul.html">http://www.xulplanet.com/tutorials/whyxul.html</a>。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	看完后，了解了XUL原来是一个支持多种WEB技术的、基于XML的界面开发语言。它既可以在远程执行，也可以安装到本地执行。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	在XUL中内置了很多界面元素，如菜单、按钮、分页等等，这样就不需要自己编写很多JS来维护和控制很多界面元素了。而且，这些界面是按照当时的OS外观来展现的，比如同一个按钮，在MacOS上和Windows上看起来就不一样。另外XUL也允许自己使用JS和CSS来定制自己的个性化界面。总之一句话，XUL的主要作用就是用来展现Extension的用户交互界面的。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	OK，知道了XUL是什么以后，那么怎么学习它的用法呢？文章最下方适时地给出了一个连接：begin the XUL tutorial，还挺人性化:) 我点~~~</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	教程很多，很强大。看来一时半会儿全搞清楚是不可能的了。慢慢来吧。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	哦对了，还发现一个在线的XUL编辑器，把XUL代码粘进去，下面可以实时地显示界面。不过不能引用外部脚本，否则就出错。链接是：<a href="http://ted.mielczarek.org/code/mozilla/xuledit/xuledit.xul" style="color: rgb(0, 102, 170); text-decoration: initial;" title="http://ted.mielczarek.org/code/mozilla/xuledit/xuledit.xul">http://ted.mielczarek.org/code/mozilla/xuledit/xuledit.xul</a>。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	&nbsp;</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	先写这些，准备开始阅读XUL教程了&hellip;&hellip;</p>
]]></content:encoded>
			<wfw:commentRss>https://www.softwareace.cn/?feed=rss2&#038;p=146</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>我的Firefox插件开发之旅（1）——从零开始</title>
		<link>https://www.softwareace.cn/?p=145</link>
		<comments>https://www.softwareace.cn/?p=145#comments</comments>
		<pubDate>Wed, 30 Jan 2013 03:12:17 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[firefox 插件]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://www.softwareace.cn/?p=145</guid>
		<description><![CDATA[准备做一个Firefox插件，用来接收从WEB页面传递的参数，根据这些参数从服务器上下载一些文件到本地，并调起 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	准备做一个Firefox插件，用来接收从WEB页面传递的参数，根据这些参数从服务器上下载一些文件到本地，并调起本地的一个应用程序。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	以前在IE中是使用一个ActiveX来实现的。FF的插件从来没有做过，不知道将来会遇到多少困难。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	&nbsp;</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	在网上发现一个页面：<a href="http://ted.mielczarek.org/code/mozilla/extensionwiz/" style="color: rgb(0, 102, 170); text-decoration: initial;" title="http://ted.mielczarek.org/code/mozilla/extensionwiz/">http://ted.mielczarek.org/code/mozilla/extensionwiz/</a>，它提供了一个FF扩展的生成向导，填写完必要信息后，会生成一个zip文件。之后我改名为xpi后，丢到我的FF 3.0中，提示不正确的安装包。看来这个向导针对FF3还有些问题。具体问题是什么？现在还不清楚。让我来继续寻找资料&hellip;&hellip;</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	&nbsp;</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	在Mozilla网站上了解到，FF的Extension和Plugin是两种概念的东西：</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	Extension就是一个zip包，里面有规定的一些必要文件。这个可以下载几个插件看一下他们的目录结构就好了。我下载了一个 QuickNote，看了一下，主要包括一个install.rdf（安装包相关信息和文件资源路径等配置）、chrome.manifest（设置各种XUL文件路径以及其他的一些资源文件路径）、chrome文件夹（里面放着插件的所有源文件），不过chrome文件夹里面的文件我还没有过多研究。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	Plugin好像是另外一码事了，在Mozilla Developer Center的Plugin开发介绍文中有这么一句：Plugins are different from extensions, which modify or enhance the functionality of the browser itself. Plugins are also different from search plugins, which plug additional search engines in the search bar. （插件与扩展不同，它更改或者改善了浏览器自身的功能。插件与搜索插件又不同，搜索插件在搜索工具栏上添加了额外的搜索引擎。）</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	我的理解，插件可以让你在FF中使用自己的View来展示、用自己编写的二进制文件来做某些事情，不仅仅是利用FF自身支持的一些特性和功能。而扩展相对来说就不需要这些东西，只利用FF的开发API就好了。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	&nbsp;</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	这样看来，要实现我开始提到的需求，似乎可以开发一个Extension就可以了。Foxmarks Bookmark Synchronizer（FBS）也差不多是我的需求这种感觉：将本地某些数据上传至服务器，从服务器同步下载一些数据到本地。FBS既然是一个扩展能够实现，那么看来我暂时不用研究Plugin了，呵呵。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	&nbsp;</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	OK，有了大概的目标。下面开始制订学习计划！</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	通过研究别人写的Extension，里面有很多js、css、images、html，这些应该还好理解，但是多了一些后缀名为xul的文件。这是什么东西？看来想开发Extension，这个文件需要好好研究一下。</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	因此，我的第一个学习计划就是搞清楚XUL是什么，什么地方要用XUL，以及怎么写XUL？</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	&nbsp;</p>
<p style="margin: 10px 0px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(255, 255, 255);">
	先说到这里，下一小节我来写一些XUL的学习历程。</p>
]]></content:encoded>
			<wfw:commentRss>https://www.softwareace.cn/?feed=rss2&#038;p=145</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>NPAPI插件开发详细记录：用VS2010开发NPAPI插件步骤</title>
		<link>https://www.softwareace.cn/?p=122</link>
		<comments>https://www.softwareace.cn/?p=122#comments</comments>
		<pubDate>Tue, 22 Jan 2013 09:19:20 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[浏览器插件开发]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://www.softwareace.cn/?p=122</guid>
		<description><![CDATA[from&#160;http://blog.csdn.net/z6482/article/details/76 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>
	<span style="font-size:10px;">from&nbsp;http://blog.csdn.net/z6482/article/details/7660748</span></p>
<div>
<div class="article_content" id="article_content" style="margin: 20px 0px 0px; font-size: 14px; line-height: 26px; font-family: Arial; background-color: rgb(255, 255, 255);">
		<span style="font-size:10px;">前面一段时间关注了用firebreath开发插件，但是感觉用起来不是那么得心应手，还是回到NPAPI开发插件上来。</span></p>
<p>
			&nbsp;</p>
<p>
			<span style="font-size:10px;">本文根据<a href="http://mozilla.com.cn/post/21666/" style="color: rgb(255, 153, 0); text-decoration: initial;">NPAPI开发详解，Windows版</a>进行开发，其中以VS2008为例进行开发，在VS2010中基本上是相同的。<br />
			必须的plugin sdk，将其解压到某个目录下，我这里是：D:UserszcfDocumentsMy Program2012。下面是创建插件的步骤：</span></p>
<h1 style="margin: 0px; padding: 0px;">
			<span style="font-size:10px;"><a name="t0" style="color: rgb(255, 153, 0);"></a>1、创建项目</span></h1>
<p>
			<span style="font-size:10px;"><img alt="" src="http://my.csdn.net/uploads/201206/13/1339588986_1697.jpg" style="border: none;" /><br />
			名称一定要以np开头，为了将来适应不同操作系统，最好全小写，不要太长，尽量控制在8字符内。本例定义为npmedia<br />
			位置指定到~pluginsdksamples<br />
			点击确定、下一步。选择dll、空项目：<br />
			<img alt="" src="http://my.csdn.net/uploads/201206/13/1339588990_6169.jpg" style="border: none;" /><br />
			点击完成，即建立好了一个空项目。如下图：<br />
			<img alt="" src="http://my.csdn.net/uploads/201206/13/1339589056_4623.jpg" style="border: none;" /></span></p>
<h1 style="margin: 0px; padding: 0px;">
			<span style="font-size:10px;"><a name="t1" style="color: rgb(255, 153, 0);"></a>2、添加必要文件</span></h1>
<p>
			<span style="font-size:10px;">首先，添加NPAPI SDK中的Common文件，共三个：<br />
			<img alt="" src="http://my.csdn.net/uploads/201206/13/1339589099_9371.jpg" style="border: none;" /><br />
			<img alt="" src="http://my.csdn.net/uploads/201206/13/1339589104_1379.jpg" style="border: none;" /><br />
			然后添加def文件：<br />
			<img alt="" src="http://my.csdn.net/uploads/201206/13/1339589163_5493.jpg" style="border: none;" /><br />
			<img alt="" src="http://my.csdn.net/uploads/201206/13/1339589186_9119.jpg" style="border: none;" /><br />
			编辑npdemo.def为：</span></p>
<div class="dp-highlighter bg_cpp" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: rgb(231, 229, 220); width: 942.46875px; overflow: auto; padding-top: 1px; margin: 18px 0px !important;">
<div class="bar" style="padding-left: 45px;">
<div class="tools" style="padding: 3px 8px 10px 10px; font-size: 9px; line-height: normal; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; background-color: rgb(248, 248, 248); border-left-width: 3px; border-left-style: solid; border-left-color: rgb(153, 153, 153);">
					<span style="font-size:10px;"><b>[cpp]</b>&nbsp;<a class="ViewSource" href="http://blog.csdn.net/z6482/article/details/7660748#" style="color: rgb(160, 160, 160); text-decoration: initial; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;" title="view plain">view plain</a><a class="CopyToClipboard" href="http://blog.csdn.net/z6482/article/details/7660748#" style="color: rgb(160, 160, 160); text-decoration: initial; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;" title="copy">copy</a><a class="PrintSource" href="http://blog.csdn.net/z6482/article/details/7660748#" style="color: rgb(160, 160, 160); text-decoration: initial; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;" title="print">print</a><a class="About" href="http://blog.csdn.net/z6482/article/details/7660748#" style="color: rgb(160, 160, 160); text-decoration: initial; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;" title="?">?</a></span></p>
<p>
						&nbsp;</p>
<div style="position: absolute; left: 422px; top: 3757px; width: 29px; height: 14px; z-index: 99;">
						<span style="font-size:10px;"><embed align="middle" allowfullscreen="false" allowscriptaccess="always" bgcolor="#ffffff" flashvars="id=1&amp;width=29&amp;height=14" height="14" id="ZeroClipboardMovie_1" loop="false" menu="false" name="ZeroClipboardMovie_1" pluginspage="http://www.macromedia.com/go/getflashplayer" quality="best" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" type="application/x-shockwave-flash" width="29" wmode="transparent"></embed></span></div>
<p>
						&nbsp;</p>
</p></div>
<p>
					&nbsp;</p>
</p></div>
<ol class="dp-cpp" start="1" style="padding: 0px; border: none; list-style-position: initial; list-style-image: initial; background-color: rgb(255, 255, 255); color: rgb(92, 92, 92); margin: 0px 0px 1px 45px !important;">
<li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">LIBRARY&nbsp;</span><span class="string" style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">&quot;npmedia&quot;</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;&nbsp;</span></span></span></li>
<li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 18px;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">&nbsp;&nbsp;</span></span></li>
<li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">EXPORTS&nbsp;&nbsp;</span></span></li>
<li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 18px;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">NP_GetEntryPoints&nbsp;@1&nbsp;&nbsp;</span></span></li>
<li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">NP_Initialize&nbsp;@2&nbsp;&nbsp;</span></span></li>
<li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 18px;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">NP_Shutdown&nbsp;@3&nbsp;&nbsp;</span></span></li>
</ol></div>
<p>
			<span style="font-size:10px;">接着添加资源文件：<br />
			<img alt="" src="http://my.csdn.net/uploads/201206/13/1339589499_3448.jpg" style="border: none;" /><br />
			<img alt="" src="http://my.csdn.net/uploads/201206/13/1339589517_5268.jpg" style="border: none;" /><br />
			自动生成了resource.h和npdemo.rc。接着修改rc文件：<br />
			<img alt="" src="http://my.csdn.net/uploads/201206/13/1339589569_4811.jpg" style="border: none;" /><br />
			<img alt="" src="http://my.csdn.net/uploads/201206/13/1339596971_7111.jpg" style="border: none;" /><br />
			<img alt="" src="http://my.csdn.net/uploads/201206/13/1339596977_4832.jpg" style="border: none;" /><br />
			在图中的BLOCK内添加。注意！BLOCK 一定要是&quot;040904e4&quot;&nbsp;<br />
			VALUE &quot;MIMEType&quot;, &quot;application/media-plugin&quot;</span></p>
<p style="margin: 0px; padding: 0px;">
			<span style="font-size:10px;"><img alt="" src="http://my.csdn.net/uploads/201206/13/1339597013_8622.jpg" style="border: none;" /></span></p>
<p style="margin: 0px; padding: 0px;">
			<span style="font-size:10px;">注意：有很多朋友反映按照本文的方法做出的 插件在chrome中无法识别，问题就在于此处，将下一个字段改为如下形式就可以了：</span></p>
<p style="margin: 0px; padding: 0px;">
			<span style="font-size:10px;">BLOCK &quot;VarFileInfo&quot;<br />
			BEGIN<br />
			VALUE &quot;Translation&quot;, 0&#215;409, 1252<br />
			END</span></p>
<h1 style="margin: 0px; padding: 0px;">
			<span style="font-size:10px;"><a name="t2" style="color: rgb(255, 153, 0);"></a>3、添加Plugin实现类</span></h1>
<p>
			<span style="font-size:10px;"><img alt="" src="http://my.csdn.net/uploads/201206/13/1339597043_7561.jpg" style="border: none;" /><br />
			<img alt="" src="http://my.csdn.net/uploads/201206/13/1339597055_2761.jpg" style="border: none;" /><br />
			<img alt="" src="http://my.csdn.net/uploads/201206/13/1339597091_8104.jpg" style="border: none;" /><br />
			类名可以随便命名，但是必须继承自nsPluginInstanceBase。<br />
			编辑Plugin.h：</span></p>
<div class="dp-highlighter bg_cpp" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: rgb(231, 229, 220); width: 942.46875px; overflow: auto; padding-top: 1px; margin: 18px 0px !important;">
<div class="bar" style="padding-left: 45px;">
<div class="tools" style="padding: 3px 8px 10px 10px; font-size: 9px; line-height: normal; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; background-color: rgb(248, 248, 248); border-left-width: 3px; border-left-style: solid; border-left-color: rgb(153, 153, 153);">
					<span style="font-size:10px;"><b>[cpp]</b>&nbsp;<a class="ViewSource" href="http://blog.csdn.net/z6482/article/details/7660748#" style="color: rgb(160, 160, 160); text-decoration: initial; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;" title="view plain">view plain</a><a class="CopyToClipboard" href="http://blog.csdn.net/z6482/article/details/7660748#" style="color: rgb(160, 160, 160); text-decoration: initial; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;" title="copy">copy</a><a class="PrintSource" href="http://blog.csdn.net/z6482/article/details/7660748#" style="color: rgb(160, 160, 160); text-decoration: initial; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;" title="print">print</a><a class="About" href="http://blog.csdn.net/z6482/article/details/7660748#" style="color: rgb(160, 160, 160); text-decoration: initial; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;" title="?">?</a></span></p>
<p>
						&nbsp;</p>
<div style="position: absolute; left: 422px; top: 7197px; width: 29px; height: 14px; z-index: 99;">
						<span style="font-size:10px;"><embed align="middle" allowfullscreen="false" allowscriptaccess="always" bgcolor="#ffffff" flashvars="id=2&amp;width=29&amp;height=14" height="14" id="ZeroClipboardMovie_2" loop="false" menu="false" name="ZeroClipboardMovie_2" pluginspage="http://www.macromedia.com/go/getflashplayer" quality="best" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" type="application/x-shockwave-flash" width="29" wmode="transparent"></embed></span></div>
<p>
						&nbsp;</p>
</p></div>
<p>
					&nbsp;</p>
</p></div>
<ol class="dp-cpp" start="1" style="padding: 0px; border: none; list-style-position: initial; list-style-image: initial; background-color: rgb(255, 255, 255); color: rgb(92, 92, 92); margin: 0px 0px 1px 45px !important;">
<li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="preprocessor" style="margin: 0px; padding: 0px; border: none; color: gray; background-color: inherit;">#pragma&nbsp;once</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;&nbsp;</span></span></span></li>
<li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 18px;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="preprocessor" style="margin: 0px; padding: 0px; border: none; color: gray; background-color: inherit;">#include&nbsp;&quot;pluginbase.h&quot;</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;&nbsp;</span></span></span></li>
<li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">&nbsp;&nbsp;</span></span></li>
<li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 18px;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">class</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;Plugin&nbsp;:&nbsp;&nbsp;</span></span></span></li>
<li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">public</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;nsPluginInstanceBase&nbsp;&nbsp;</span></span></span></li>
<li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 18px;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">{&nbsp;&nbsp;</span></span></li>
<li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">private</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">:&nbsp;&nbsp;</span></span></span></li>
<li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 18px;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">NPP&nbsp;m_pNPInstance;&nbsp;&nbsp;</span></span></li>
<li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">NPBool&nbsp;m_bInitialized;&nbsp;&nbsp;</span></span></li>
<li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 18px;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">public</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">:&nbsp;&nbsp;</span></span></span></li>
<li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">Plugin(NPP&nbsp;pNPInstance);&nbsp;&nbsp;</span></span></li>
<li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 18px;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">~Plugin();&nbsp;&nbsp;</span></span></li>
<li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">&nbsp;&nbsp;</span></span></li>
<li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 18px;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">NPBool&nbsp;init(NPWindow*&nbsp;pNPWindow)&nbsp;{&nbsp;m_bInitialized&nbsp;=&nbsp;TRUE;&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">return</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;TRUE;}&nbsp;&nbsp;</span></span></span></li>
<li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">void</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;shut()&nbsp;{&nbsp;m_bInitialized&nbsp;=&nbsp;FALSE;&nbsp;}&nbsp;&nbsp;</span></span></span></li>
<li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 18px;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">NPBool&nbsp;isInitialized()&nbsp;{&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">return</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;m_bInitialized;&nbsp;}&nbsp;&nbsp;</span></span></span></li>
<li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">};&nbsp;&nbsp;</span></span></li>
</ol></div>
<p style="margin: 0px; padding: 0px;">
			<span style="font-size:10px;">&nbsp;</span></p>
<p style="margin: 0px; padding: 0px;">
			<span style="font-size:10px;">编辑Plugin.cpp：</span></p>
<p style="margin: 0px; padding: 0px;">
			<span style="font-size:10px;">&nbsp;</span></p>
<div class="dp-highlighter bg_cpp" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: rgb(231, 229, 220); width: 942.46875px; overflow: auto; padding-top: 1px; margin: 18px 0px !important;">
<div class="bar" style="padding-left: 45px;">
<div class="tools" style="padding: 3px 8px 10px 10px; font-size: 9px; line-height: normal; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; background-color: rgb(248, 248, 248); border-left-width: 3px; border-left-style: solid; border-left-color: rgb(153, 153, 153);">
					<span style="font-size:10px;"><b>[cpp]</b>&nbsp;<a class="ViewSource" href="http://blog.csdn.net/z6482/article/details/7660748#" style="color: rgb(160, 160, 160); text-decoration: initial; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;" title="view plain">view plain</a><a class="CopyToClipboard" href="http://blog.csdn.net/z6482/article/details/7660748#" style="color: rgb(160, 160, 160); text-decoration: initial; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;" title="copy">copy</a><a class="PrintSource" href="http://blog.csdn.net/z6482/article/details/7660748#" style="color: rgb(160, 160, 160); text-decoration: initial; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;" title="print">print</a><a class="About" href="http://blog.csdn.net/z6482/article/details/7660748#" style="color: rgb(160, 160, 160); text-decoration: initial; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;" title="?">?</a></span></p>
<p>
						&nbsp;</p>
<div style="position: absolute; left: 422px; top: 7646px; width: 29px; height: 14px; z-index: 99;">
						<span style="font-size:10px;"><embed align="middle" allowfullscreen="false" allowscriptaccess="always" bgcolor="#ffffff" flashvars="id=3&amp;width=29&amp;height=14" height="14" id="ZeroClipboardMovie_3" loop="false" menu="false" name="ZeroClipboardMovie_3" pluginspage="http://www.macromedia.com/go/getflashplayer" quality="best" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" type="application/x-shockwave-flash" width="29" wmode="transparent"></embed></span></div>
<p>
						&nbsp;</p>
</p></div>
<p>
					&nbsp;</p>
</p></div>
<ol class="dp-cpp" start="1" style="padding: 0px; border: none; list-style-position: initial; list-style-image: initial; background-color: rgb(255, 255, 255); color: rgb(92, 92, 92); margin: 0px 0px 1px 45px !important;">
<li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="preprocessor" style="margin: 0px; padding: 0px; border: none; color: gray; background-color: inherit;">#include&nbsp;&quot;Plugin.h&quot;</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;&nbsp;</span></span></span></li>
<li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 18px;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">&nbsp;&nbsp;</span></span></li>
<li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//////&nbsp;functions&nbsp;/////////</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;&nbsp;</span></span></span></li>
<li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 18px;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">NPError&nbsp;NS_PluginInitialize()&nbsp;&nbsp;</span></span></li>
<li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">{&nbsp;&nbsp;</span></span></li>
<li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 18px;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">return</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;NPERR_NO_ERROR;&nbsp;&nbsp;</span></span></span></li>
<li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">}&nbsp;&nbsp;</span></span></li>
<li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 18px;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">&nbsp;&nbsp;</span></span></li>
<li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">void</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;NS_PluginShutdown()&nbsp;&nbsp;</span></span></span></li>
<li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 18px;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">{&nbsp;&nbsp;</span></span></li>
<li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">}&nbsp;&nbsp;</span></span></li>
<li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 18px;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">&nbsp;&nbsp;</span></span></li>
<li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">nsPluginInstanceBase&nbsp;*&nbsp;NS_NewPluginInstance(nsPluginCreateData&nbsp;*&nbsp;aCreateDataStruct)&nbsp;&nbsp;</span></span></li>
<li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 18px;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">{&nbsp;&nbsp;</span></span></li>
<li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">if</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">(!aCreateDataStruct)&nbsp;&nbsp;</span></span></span></li>
<li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 18px;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">return</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;NULL;&nbsp;&nbsp;</span></span></span></li>
<li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">&nbsp;&nbsp;</span></span></li>
<li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 18px;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">Plugin&nbsp;*&nbsp;plugin&nbsp;=&nbsp;<span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">new</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;Plugin(aCreateDataStruct-&gt;instance);&nbsp;&nbsp;</span></span></span></li>
<li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">return</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;plugin;&nbsp;&nbsp;</span></span></span></li>
<li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 18px;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">}&nbsp;&nbsp;</span></span></li>
<li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">&nbsp;&nbsp;</span></span></li>
<li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 18px;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">void</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;NS_DestroyPluginInstance(nsPluginInstanceBase&nbsp;*&nbsp;aPlugin)&nbsp;&nbsp;</span></span></span></li>
<li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">{&nbsp;&nbsp;</span></span></li>
<li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 18px;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">if</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">(aPlugin)&nbsp;&nbsp;</span></span></span></li>
<li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">delete</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;(Plugin&nbsp;*)aPlugin;&nbsp;&nbsp;</span></span></span></li>
<li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 18px;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">}&nbsp;&nbsp;</span></span></li>
<li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">&nbsp;&nbsp;</span></span></li>
<li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 18px;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); background-color: inherit;">//////&nbsp;Plugin&nbsp;/////////</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;&nbsp;</span></span></span></li>
<li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">Plugin::Plugin(NPP&nbsp;pNPInstance):nsPluginInstanceBase(),&nbsp;&nbsp;</span></span></li>
<li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 18px;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">m_pNPInstance(pNPInstance),&nbsp;&nbsp;</span></span></li>
<li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">m_bInitialized(FALSE)&nbsp;&nbsp;</span></span></li>
<li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 18px;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">{&nbsp;&nbsp;</span></span></li>
<li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">}&nbsp;&nbsp;</span></span></li>
<li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 18px;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">&nbsp;&nbsp;</span></span></li>
<li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">&nbsp;&nbsp;</span></span></li>
<li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 18px;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">Plugin::~Plugin(<span class="keyword" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">void</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">)&nbsp;&nbsp;</span></span></span></li>
<li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">{&nbsp;&nbsp;</span></span></li>
<li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 18px;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">}&nbsp;&nbsp;</span></span></li>
</ol></div>
<p>
			&nbsp;</p>
<h1 style="margin: 0px; padding: 0px;">
			<span style="font-size:10px;"><a name="t3" style="color: rgb(255, 153, 0);"></a>4、修改项目属性</span></h1>
<p>
			<span style="font-size:10px;"><img alt="" src="http://my.csdn.net/uploads/201206/13/1339597239_5240.jpg" style="border: none;" /><br />
			<img alt="" src="http://my.csdn.net/uploads/201206/13/1339597246_8235.jpg" style="border: none;" /><br />
			字符集选择为多字节字符，下面添加包含文件：<br />
			<img alt="" src="http://my.csdn.net/uploads/201206/13/1339597253_4019.jpg" style="border: none;" /><br />
			<img alt="" src="http://my.csdn.net/uploads/201206/13/1339597324_6648.jpg" style="border: none;" /><br />
			<img alt="" src="http://my.csdn.net/uploads/201206/13/1339597333_1190.jpg" style="border: none;" /></span></p>
<h1 style="margin: 0px; padding: 0px;">
			<span style="font-size:10px;"><a name="t4" style="color: rgb(255, 153, 0);"></a>5、编译调试</span></h1>
<p>
			<span style="font-size:10px;">完成了上述设置就可以进行编译调试了。<br />
			这是整个项目的结构：<br />
			<img alt="" src="http://my.csdn.net/uploads/201206/13/1339597342_9543.jpg" style="border: none;" /><br />
			生成该项目之后，可以在项目的Debug目录下找到dll文件，这里是npmedia.dll。可以写注册表注册这个dll，也可以将这个dll复制到用来测试插件的Firefox的profile目录下的plugins（没有则自行创建）文件夹中。<br />
			写注册表的方式：运行regedit，在HKEY_LOCAL_MACHINESOFTWAREMozillaPlugins下建立一个子项，可随意命名：这里以@zcf.com/media为例，新建字符串项Path，其值为生成的dll的路径：</span></p>
<p style="margin: 0px; padding: 0px;">
			<span style="font-size:10px;"><img alt="" src="http://my.csdn.net/uploads/201206/13/1339597560_5774.jpg" style="border: none;" /></span></p>
<p style="margin: 0px; padding: 0px;">
			<span style="font-size:10px;">注意，这种方式在XP系统下测试通过，在WIN7系统下没有成功（注意：win7 64位应运行 %windir%SysWOW64Register.exe，打开的就是64注册表，可以在HKEY_LOCAL_MACHINESOFTWAREMozillaPlugins下看到很多64位版本的插件，多谢网友 Jearol 告知）。还有一种方式就是设置项目属性，将输出目录指定为用来调试的Firefox相应profile目录下的plugins目录。这样就不用每次生成之后来回复制dll。如下图：</span></p>
<p>
			<span style="font-size:10px;"><img alt="" src="http://my.csdn.net/uploads/201206/13/1339597572_8283.jpg" style="border: none;" /><br />
			然后在Firefox地址栏中输入about:plugins就可以看到我们的插件了。<br />
			测试页面可以如下：<br />
			测试文件mediatest.html：</span></p>
<div class="dp-highlighter bg_html" style="font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; background-color: rgb(231, 229, 220); width: 942.46875px; overflow: auto; padding-top: 1px; margin: 18px 0px !important;">
<div class="bar" style="padding-left: 45px;">
<div class="tools" style="padding: 3px 8px 10px 10px; font-size: 9px; line-height: normal; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; background-color: rgb(248, 248, 248); border-left-width: 3px; border-left-style: solid; border-left-color: rgb(153, 153, 153);">
					<span style="font-size:10px;"><b>[html]</b>&nbsp;<a class="ViewSource" href="http://blog.csdn.net/z6482/article/details/7660748#" style="color: rgb(160, 160, 160); text-decoration: initial; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;" title="view plain">view plain</a><a class="CopyToClipboard" href="http://blog.csdn.net/z6482/article/details/7660748#" style="color: rgb(160, 160, 160); text-decoration: initial; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;" title="copy">copy</a><a class="PrintSource" href="http://blog.csdn.net/z6482/article/details/7660748#" style="color: rgb(160, 160, 160); text-decoration: initial; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;" title="print">print</a><a class="About" href="http://blog.csdn.net/z6482/article/details/7660748#" style="color: rgb(160, 160, 160); text-decoration: initial; background-image: none; background-color: inherit; border: none; padding: 0px; margin: 0px 10px 0px 0px; font-size: 9px; background-position: initial initial; background-repeat: initial initial;" title="?">?</a></span></p>
<p>
						&nbsp;</p>
<div style="position: absolute; left: 428px; top: 11625px; width: 29px; height: 14px; z-index: 99;">
						<span style="font-size:10px;"><embed align="middle" allowfullscreen="false" allowscriptaccess="always" bgcolor="#ffffff" flashvars="id=4&amp;width=29&amp;height=14" height="14" id="ZeroClipboardMovie_4" loop="false" menu="false" name="ZeroClipboardMovie_4" pluginspage="http://www.macromedia.com/go/getflashplayer" quality="best" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" type="application/x-shockwave-flash" width="29" wmode="transparent"></embed></span></div>
<p>
						&nbsp;</p>
</p></div>
<p>
					&nbsp;</p>
</p></div>
<ol class="dp-xml" start="1" style="padding: 0px; border: none; list-style-position: initial; list-style-image: initial; background-color: rgb(255, 255, 255); color: rgb(92, 92, 92); margin: 0px 0px 1px 45px !important;">
<li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&lt;!doctype&nbsp;html</span><span class="tag" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">&gt;</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;&nbsp;</span></span></span></li>
<li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 18px;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="tag" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">&lt;</span><span class="tag-name" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">html</span><span class="tag" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">&gt;</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;&nbsp;</span></span></span></li>
<li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="tag" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">&lt;</span><span class="tag-name" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">title</span><span class="tag" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">&gt;</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">TEST&nbsp;WEB&nbsp;PAGE&nbsp;for&nbsp;media&nbsp;plugin</span><span class="tag" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">&lt;/</span><span class="tag-name" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">title</span><span class="tag" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">&gt;</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;&nbsp;</span></span></span></li>
<li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 18px;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="tag" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">&lt;</span><span class="tag-name" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">body</span><span class="tag" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">&gt;</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;&nbsp;</span></span></span></li>
<li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="tag" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">&lt;</span><span class="tag-name" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">object</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;</span><span class="attribute" style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">type</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span class="attribute-value" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">&quot;application/media-plugin&quot;</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;</span><span class="attribute" style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">width</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span class="attribute-value" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">200</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;</span><span class="attribute" style="margin: 0px; padding: 0px; border: none; color: red; background-color: inherit;">height</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">=</span><span class="attribute-value" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">150</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;</span><span class="tag" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">&gt;</span><span class="tag" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">&lt;/</span><span class="tag-name" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">object</span><span class="tag" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">&gt;</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;&nbsp;</span></span></span></li>
<li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 18px;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="tag" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">&lt;</span><span class="tag-name" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">br</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;</span><span class="tag" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">/&gt;</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;&nbsp;</span></span></span></li>
<li class="alt" style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; color: inherit; line-height: 18px; margin: 0px !important; padding: 0px 3px 0px 10px !important;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="tag" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">&lt;/</span><span class="tag-name" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">body</span><span class="tag" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">&gt;</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;&nbsp;</span></span></span></li>
<li style="margin: 0px !important; padding: 0px 3px 0px 10px !important; border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(153, 153, 153); list-style: decimal-leading-zero outside; background-color: rgb(248, 248, 248); color: rgb(85, 85, 85); line-height: 18px;">
					<span style="font-size:10px;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span class="tag" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">&lt;/</span><span class="tag-name" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">html</span><span class="tag" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit; font-weight: bold;">&gt;</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">&nbsp;&nbsp;</span></span></span></li>
</ol></div>
<p>
			<span style="font-size:10px;">关于调试插件：首先用Firefox打开测试页面，然后在VS2010中需要的地方设置断点，接着选择调试/附加到进程在弹出的对话框中选择plugin-container.exe，可能不止一个，注意根据其路径选择正确的那个。最后刷新测试页面就可以在你设置的断点的地方断下，进行调试。下一篇文章会有一个简单的实例展示这个调试过程。</span></p>
</p></div>
</div>
]]></content:encoded>
			<wfw:commentRss>https://www.softwareace.cn/?feed=rss2&#038;p=122</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>自行设计NPAPI开发框架</title>
		<link>https://www.softwareace.cn/?p=104</link>
		<comments>https://www.softwareace.cn/?p=104#comments</comments>
		<pubDate>Sat, 19 Jan 2013 07:49:23 +0000</pubDate>
		<dc:creator><![CDATA[littlesu]]></dc:creator>
				<category><![CDATA[浏览器插件开发]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://www.softwareace.cn/?p=104</guid>
		<description><![CDATA[经历了一年有余的插件开发，对插件的工作机制也比较熟悉了，在开发插件的过程中使用sdk中的np_entry.cp [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><span style="color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">经历了一年有余的插件开发，对插件的工作机制也比较熟悉了，在开发插件的过程中使用sdk中的np_entry.cpp、npn_gate.cpp、npp_gate.cpp以及pluginbase.h这几个文件，极大的提高了插件开发的效率，使开发过程变得简单高效，但是在使用的过程中也发现了一些不足之处以及一些细微的bug。在开发过程中我已经对这几个文件进行了不同程度的修改以满足我的开发需求。虽然修改了能满足我的需求，但总有一个重写该框架的想法。前面因为排除一个bug在Firefox源代码中寻找到了一份非常有价值的测试插件实例代码，并进行了研究，结合上述提及的几个sdk中的文件以及为scriptable插件准备的npruntime实例。综合起来写就了一份自己的插件开发框架代码。</span></p>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">    本文以我写这个插件开发框架的过程为基本线索，介绍我是如何来写这个框架的，同时介绍NPAPI插件的工作机制，希望插件开发初学者看完本文之后对NPAPI插件一个清晰的认识；也希望熟悉插件开发的朋友看到此文之后能够对插件有新的感悟，体验到新的东西；更希望所有看到本文之后对插件开发或对本文提出的框架有任何意见和建议的朋友能与我交流。</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">    本文主要依据windows平台下开发可用于Firefox浏览器的NPAPI插件来阐述，一般来讲对于windows平台其他支持NPAPI插件机制的浏览器也是适用的，并且与其他平台的NPAPI插件开发基本原理也应该是等同的。但本文不保证其他平台或其他浏览器中是完全一样的。下面言归正传。</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;"></div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">插件的本质</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">    插件的本质，就是一个供浏览器调用的动态链接库，在windows平台是一个dll文件，在unix平台是so文件。只不过NPAPI插件规范了这个动态库的接口，规定了接口需要实现哪些最基本的功能。既然是动态库，就从定义接口之处对插件进行寻根探源，不管哪个插件代码中相信都可以找到.def文件中如下描述：</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">EXPORTS</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">NP_GetEntryPoints @1</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">NP_Initialize @2</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">NP_Shutdown @3</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">可能有的还有另外一个：</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">NP_GetMIMEDescription @4</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">    因此有必要看看这几个接口实现了什么功能， NP_GetEntryPoints的代码如下：</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">
<pre class="crayon-plain-tag">[cce_cpp]
NPError OSCALL NP_GetEntryPoints(NPPluginFuncs* pFuncs)  
{  
	if (!fillPluginFunctionTable(pFuncs)) {  
		return NPERR_INVALID_FUNCTABLE_ERROR;  
	}  
	return NPERR_NO_ERROR;  
}  

NPError OSCALL NP_GetEntryPoints(NPPluginFuncs* pFuncs)

{
	if (!fillPluginFunctionTable(pFuncs)) {
		return NPERR_INVALID_FUNCTABLE_ERROR;
	}
	return NPERR_NO_ERROR;

}
[/cce_cpp]</pre>
</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">    很简单，所调用的函数名已经说明了这个接口的功能：填充插件函数表。接下来看看NP_Initialize，代码如下：</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">
<pre class="crayon-plain-tag">[cce_cpp]
NPError OSCALL NP_Initialize(NPNetscapeFuncs* aNPNFuncs)  
{  
	NPError rv = fillNetscapeFunctionTable(aNPNFuncs);  
	if (rv != NPERR_NO_ERROR)  
		return rv;  
	return NS_PluginInitialize();  
}  

NPError OSCALL NP_Initialize(NPNetscapeFuncs* aNPNFuncs)
{
	NPError rv = fillNetscapeFunctionTable(aNPNFuncs);
	if (rv != NPERR_NO_ERROR)
		return rv;
	return NS_PluginInitialize();
}


[/cce_cpp]</pre>
</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">    同样的，所调用的函数名已经说明了该接口的功能：填充浏览器端函数表。NP_Shutdown这个接口的功能不言自明，结尾的工作由这个接口来做。另外，NP_GetMIMEDescription是浏览器获取该插件所支持的MIME类型描述的接口，可有可无（至少，我是这么认为的）。</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">     另外在NP_Initialize函数中，宏定义</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">#if defined(XP_UNIX) &amp;&amp; !defined(XP_MACOSX)</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">#endif</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">包含的部分直接调用了填充插件函数表的函数，说明在UNIX或MAC上NP_Initialize一个函数实现了windows平台NP_Initialize和NP_GetEntryPoints的功能。</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">       于是可以推断出，浏览器与插件直接建立关系的一个过程，首先浏览器利用插件端提供的函数填充一个函数指针表（浏览器调用插件端的函数实现我们开发的功能），接着浏览器将浏览器端提供给插件调用的函数填充一个函数指针表，并将这个表告知插件（插件由这个函数指针表来调用浏览器提供的功能）。</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">        fillPluginFunctionTable函数的参数是一个NPPluginFuncs结构的指针，fillNetscapeFunctionTable的参数是一个NPNetscapeFuncs结构的指针，我们开发插件主要是想让浏览器实现我们指定的功能，因此开发插件的主要工作也就集中在了实现用来填充NPPluginFuncs结构的函数的功能上。用来填充NPNetscapeFuncs结构的函数的功能已经由浏览器实现好了，我们可以在插件中使用。为了方便我们调用浏览器端实现的函数，定义了一堆NPN_开头的全局函数供我们使用，为了方便我们清晰的知道要实现哪些函数接口提供给浏览器，定义了一堆NPP_开头的全局函数。开发插件的工作现在就是实现这堆NPP_开头的函数，并且将这些NPP_和NPN_的函数与前面两个结构NPPluginFuncs和NPNetscapeFuncs联系起来。</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">        如何进行联系呢，看看代码就明了：fillPluginFunctionTable函数中很多类似如下的语句：</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">[cpp]</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">pFuncs-&gt;newp = NPP_New;</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">pFuncs-&gt;destroy = NPP_Destroy;</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;"></div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">pFuncs-&gt;newp = NPP_New;</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">pFuncs-&gt;destroy = NPP_Destroy;</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">其中pFuncs 就是NPPluginFuncs结构的指针，上面这两条语句就将NPP_New和 NPP_Destroy(这些是需要我们插件开发者来实现的函数)与NPPluginFuncs结构中的newp和destroy联系起来了。浏览器调用NPPluginFuncs结构的newp指针就是在调用我们实现的NPP_New。</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">          再来看看NPN_函数的实现，以NPN_GetValue为例，代码如下：</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">
<pre class="crayon-plain-tag">[cce_cpp]
NPError NPN_GetValue(NPP instance, NPNVariable variable, void* value)  
{  
	return sBrowserFuncs-&amp;gt;getvalue(instance, variable, value);  
}  

NPError NPN_GetValue(NPP instance, NPNVariable variable, void* value)
{
	return sBrowserFuncs-&amp;gt;getvalue(instance, variable, value);
}
[/cce_cpp]</pre>
</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">直接调用了NPNetscapeFuncs结构中的相应函数，因此我们调用NPN_GetValue其实就是在调用NPNetscapeFuncs结构中的getvalue。</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">        其实将这些NPP_和NPN_的函数结构NPPluginFuncs和NPNetscapeFuncs联系起来的工作都是几乎一样的，于是就有了NPAPI插件开发的各种框架，这些框架的最基本作用就是干这事儿。有了框架我们开发插件就可以集中精力在实现这些NPP开头的函数的功能上。</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">        以此为指导思想，写出一个插件，只有一个头文件和一个cpp文件(当然还有rc文件和def文件)，编译生成dll在Firefox中about:plugins页面可以看到我们的插件。该代码请参考本文提供的附件。我将其命名为aemo，就当是alpha版的demo吧！<a class="keylink" style="color: #333333;" href="http://www.2cto.com/soft" target="_blank">下载</a>地址：http://download.csdn.net/detail/z6482/4913874</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;"></div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">面向对象开发插件</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">         相信绝大多数插件开发者都是选择C++来开发插件的吧，利用C++面向对象对插件开发进行一定的封装，可以让我们在开发插件的过程中更加专注于插件的实际功能。为了达到这个目的，我们最直接的想法就是将前面提到的NPP_开头的函数封装到一个类中，当我们开发插件的时候就只需要根据我们实际的功能需求来实现类中的相应函数就可以了。来看看sdk中是如何做的：</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">
<pre class="crayon-plain-tag">[cce_cpp]
NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16_t* stype)  
{  
	if (!instance)  
		return NPERR_INVALID_INSTANCE_ERROR;  
	nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance-&amp;gt;pdata;  
	if (!plugin)   
		return NPERR_GENERIC_ERROR;  
	return plugin-&amp;gt;NewStream(type, stream, seekable, stype);  
}  

NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16_t* stype)
{
	if (!instance)
		return NPERR_INVALID_INSTANCE_ERROR;
	nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance-&amp;gt;pdata;
	if (!plugin) 
		return NPERR_GENERIC_ERROR;
	return plugin-&amp;gt;NewStream(type, stream, seekable, stype);
}
[/cce_cpp]</pre>
</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">函数代码比较简单，功能就是将instance的pdata转换为类，然后调用该类的NewStream成员函数。因此我们要实现NPP_NewStream的功能，就只需要实现nsPluginInstanceBase类的NewStream函数的功能即可。简要叙述一下如何将instance的pdata与nsPluginInstanceBase联系起来。请看NPP_New中的代码片段：</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">
<pre class="crayon-plain-tag">[cce_cpp]
nsPluginInstanceBase * plugin = NS_NewPluginInstance(&amp;amp;ds);  
if (!plugin)  
return NPERR_OUT_OF_MEMORY_ERROR;  
instance-&amp;gt;pdata = (void *)plugin;  
nsPluginInstanceBase * plugin = NS_NewPluginInstance(&amp;amp;ds);
if (!plugin)
return NPERR_OUT_OF_MEMORY_ERROR;
instance-&amp;gt;pdata = (void *)plugin;
[/cce_cpp]</pre>
</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">这里NS_NewPluginInstance创建了一个nsPluginInstanceBase类的对象（准确的说是其子类的对象），然后将这个对象指针转换为void类型的指针，赋值给instance的pdata。这样就建立了instance与我们创建的对象之间的关系。完成了上述操作，就完成了NPP_函数的封装，</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">        这里还有一点非常美妙的东西需要指出，instance是一个NPP结构，NS_NewPluginInstance中，用这个instance创建了一个插件实例对象，即该对象包含了一个指向instance的指针，而后面instance的pdata又指向了我们创建的这个对象，这样就达到了既可以通过instance访问plugin对象又可以通过plugin对象访问instance的目的。可能你觉得这没什么稀罕的，但是如果在开发插件的过程中需要创建多个类。而这些类又需要与plugin对象共享一些数据，那么就可以为这些类都添加一个NPP的成员，指向这个instance，然后，共享数据就变得非常有意思了。当然你也可以用C++固有的数据共享的方式（如：友元等）来共享数据，但我更喜欢这种方式！</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">        nsPluginInstanceBase是一个插件实例的基类，该基类定义了几个纯虚函数，我们在创建插件的时候只需要以该类为基类派生一个子类并实现这几个定义为纯虚函数的函数即可生成一个最简单的插件，如果有其他需求则可以根据实际功能对其他虚函数进行覆写即可。如果没有这个基类的其他函数的实现那么我们每次写的时候都要将所有与NPP有关的函数都进行实现，即使没有功能，也至少需要一个空函数体，比如：一般NPP_Print这个打印功能，我们一般是不需要的。如果没有nsPluginInstanceBase，那么每次我们都要写一段这样的代码void NPP_Print(NPPrint* printInfo) { return; }，即使是每次都复制，也显得不舒服，而有了nsPluginInstanceBase的封装，我们只需要在派生子类的时候不覆写这个虚函数即可。因此nsPluginInstanceBase可以说完美的封装了NPP_函数，让我们开发插件从如此繁琐的工作转化为仅仅只关注功能的实现。</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">        添加了类的实现方式，我做了一个与前面类似的插件，是的bemo，beta版的demo。代码请参考本文提供的附件。下载地址：http://download.csdn.net/detail/z6482/4913883</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;"></div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">插件接口脚本化</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">          Scriptable plugin，完整的表述应该叫具有脚本化<a class="keylink" style="color: #333333;" href="http://www.2cto.com/kf" target="_blank">编程</a>接口的插件（cross-browser NPAPI extensions, commonly called npruntime，跨<a class="keylink" style="color: #333333;" href="http://www.2cto.com/os/liulanqi/" target="_blank">浏览器</a>NPAPI扩展功能，通常称为npruntime。总之就是为普通的插件增加了可以在JS脚本中访问的接口和属性）。</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">          简单描述一下整个过程，当浏览器发现JS中在调用插件对象的某些接口或属性的时候，就会调用NPP_GetValue来获取一个NPObject的对象，而这样一个对象我们是通过调用NPN_CreateObject来创建，并调用NPN_RetainObject来获取并返回给浏览器。浏览器根据得到的这个对象，调用该对象的HasProperty、GetProperty、SetProperty等等来进行相关的操作。当然不需要了的时候我们需要调用NPN_ReleaseObject来通知浏览器释放该对象，该操作一遍在实例的析构函数中进行。</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">          添加脚本化接口也不难，创建一个类似于nsPluginInstanceBase的类nsScriptObjectBase类，该类需要派生自NPObject类，还需要有一个NPP对象来保存其对应的插件实例。仿照npruntime实例代码写出来，在文件中做了一些修改：将所有全局变量全部做完类的static成员变量。并进行一些简单的测试，最终生成一个可用的既能够用于开发一般插件又可以开发具有脚本化接口插件的框架，主要有三个文件：npfrmwk.h、npfrmwkbase.h和npfrmwk_entry.cpp。一切尽在代码中。下一小节结合本小节生成脚本化接口插件简要介绍如何利用本框架来开发NPAPI插件。本小节与下一小节的代码为同一个：demo_frmwk</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;"></div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">框架使用说明</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">        手动创建文件（rc文件），也可以在项目创建好之后在VS中添加新建文件，demo太多了，故将本demo命名为fdemo，生成dll命名为npfdemo.dll，</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">创建文件npfdemo.rc。内容如下：</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">
<pre class="crayon-plain-tag">[cce_cpp]
#include&amp;lt;winver.h&amp;gt;   
VS_VERSION_INFO VERSIONINFO  
FILEVERSION    1,0,0,0  
PRODUCTVERSION 1,0,0,0  
FILEFLAGSMASK 0x3fL  
#ifdef _DEBUG   
FILEFLAGS 0x1L  
#else   
FILEFLAGS 0x0L  
#endif   
FILEOS VOS__WINDOWS32  
FILETYPE VFT_DLL  
FILESUBTYPE 0x0L  
BEGIN  
BLOCK &quot;StringFileInfo&quot;  
BEGIN  
BLOCK &quot;040904e4&quot;  
BEGIN  
VALUE &quot;CompanyName&quot;, &quot;JumuFENG.zcf.org&quot;  
VALUE &quot;FileDescription&quot;, &quot;demo plugin for our own NPAPI framework&quot;  
VALUE &quot;FileVersion&quot;, &quot;1.0.0.1&quot;  
VALUE &quot;InternalName&quot;, &quot;npfdemo.dll&quot;  
VALUE &quot;LegalCopyright&quot;, &quot;Copyright (C) 2012&quot;  
VALUE &quot;MIMEType&quot;, &quot;application/x-frmwk-demo&quot;  
VALUE &quot;OriginalFilename&quot;, &quot;npfdemo.dll&quot;  
VALUE &quot;ProductName&quot;, &quot;Test Plug-in&quot;  
VALUE &quot;ProductVersion&quot;, &quot;1.0.0.1&quot;  
END  
END  
BLOCK &quot;VarFileInfo&quot;  
BEGIN  
VALUE &quot;Translation&quot;, 0x409, 1252  
END  
END  


#include&amp;lt;winver.h&amp;gt;


VS_VERSION_INFO VERSIONINFO
FILEVERSION    1,0,0,0
PRODUCTVERSION 1,0,0,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS VOS__WINDOWS32
FILETYPE VFT_DLL
FILESUBTYPE 0x0L
BEGIN
BLOCK &quot;StringFileInfo&quot;
BEGIN
BLOCK &quot;040904e4&quot;
BEGIN
VALUE &quot;CompanyName&quot;, &quot;JumuFENG.zcf.org&quot;
VALUE &quot;FileDescription&quot;, &quot;demo plugin for our own NPAPI framework&quot;
VALUE &quot;FileVersion&quot;, &quot;1.0.0.1&quot;
VALUE &quot;InternalName&quot;, &quot;npfdemo.dll&quot;
VALUE &quot;LegalCopyright&quot;, &quot;Copyright (C) 2012&quot;
VALUE &quot;MIMEType&quot;, &quot;application/x-frmwk-demo&quot;
VALUE &quot;OriginalFilename&quot;, &quot;npfdemo.dll&quot;
VALUE &quot;ProductName&quot;, &quot;Test Plug-in&quot;
VALUE &quot;ProductVersion&quot;, &quot;1.0.0.1&quot;
END
END
BLOCK &quot;VarFileInfo&quot;
BEGIN
VALUE &quot;Translation&quot;, 0x409, 1252
END
END
[/cce_cpp]</pre>
</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">该文件可以由VS新建，但需要修改相应块描述中的值为上述内容，当然CompanyName等条目需根据实际情况修改为你想设定的值。</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">         创建好上述文件之后，打开VS(我用的是VS2010)创建一个win32应用程序，设置中选择创建dll。注意勾选上空项目。创建好项目之后。即可向该项目添加现有项，选择添加本文提供的三个框架文件：npfrmwk.h、npfrmwkbase.h、npfrmwk_entry.cpp以及前面创建的文件npfdemo.rc。接着添加新建项，添加def文件。npfdemo.def文件内容如下：</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">LIBRARY NPFDEMO</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;"></div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">EXPORTS</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">NP_GetEntryPoints @1</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">NP_Initialize @2</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">NP_Shutdown @3</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">NP_GetMIMEDescription @4</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">        添加完毕之后，为该项目添加一个新的派生自nsPluginInstanceBase的类：CFrmwkPlugin，已经自动将头文件命名为FrmwkPlugin.h实现文件命名为FrmwkPlugin.cpp了，我们要在这里新建两个类，一个是CFrmwkPlugin类另一个是派生自nsScriptObjectBase的 CScriptPluginObject类。设置项目属性，添加npapi的头文件包含目录，在属性-&gt;C/C++-&gt;附加包含目录中添加，当然你也可以将npapi.h、npruntime.h、npfunctions.h这些文件直接复制到项目中如上述一样添加到项目中，而不添加附加包含目录。</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">接下来将刚才创建的FrmwkPlugin.h文件和FrmwkPlugin.cpp文件进行修改，主要就是实现两个类中必须实现的函数以及几个相当于全局函数的静态成员函数，代码就不复制到这里来了，请参考本文提供的代码进行实现吧！</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">        文件中采用预编译指令区分是否编译脚本化接口，如果需要编译支持脚本化接口则需要设置属性-&gt;预处理器-&gt;预处理定义中添加ENABLE_SCRIPT_OBJECT，当然也可以在源文件中适当位置添加#define ENABLE_SCRIPT_OBJECT达到同样的效果。不需要编译脚本化接口则不需要这些操作，直接编译生成即可。</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">        为了方便开发插件，减少重复劳动，我用C#开发了一个小工具来完成上述操作，进行必要的设置之后可以自动生成def文件、rc文件以及类FrmwkPlugin.h和FrmwkPlugin.cpp文件，当然这些文件的名称都可以进行指定，如果没有下载我提供的框架也可以用该工具生成并导出该框架的三个文件npfrmwk.h、npfrmwkbase.h、npfrmwk_entry.cpp。更进一步的，如果你连开发插件的最基本头文件npapi.h、npruntime.h之类的文件都没有下载，也可以用这个小工具直接导出。总之我希望这个小工具能让你做尽量少的工作来完成插件的开发，have fun！</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">        如图是该工具的一个截图：</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">   <img style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; width: 435px; height: 299px;" alt="" src="http://www.2cto.com/uploadfile/2012/1222/20121222013205609.jpg" /></div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">        需要填写的信息包括文件名，mimetype类型，以及插件实例类名称，其他各项都有预设默认值，或者会根据填写这几项信息时自动填写相关信息。自动填写或预设默认值都可以手动修改。</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">        最上面一行可以选择生成的文件类型，选择第一项则生成的文件中不包含scriptable的接口，文件非常简洁。选择第二项则生成包含scriptable相关的内容，而且没有添加ENABLE_SCRIPT_OBJECT预编译宏；选择第三项则会生成带 ENABLE_SCRIPT_OBJECT预编译宏的文件，默认是不支持脚本化接口的。要使其支持只需要在项目属性中设置预编译宏ENABLE_SCRIPT_OBJECT即可。 www.2cto.com</div>
<div style="border-width: 0px; list-style: none; margin: 0px; padding: 0px; color: #333333; line-height: 28px; font-family: 宋体; font-size: 14px; background-color: #ffffff;">        复选框生成VS工程选项可选择是否生成VS2010版的项目文件，若选择该项则自动选择将框架文件同时生成在项目文件中，生成的项目文件可以直接用VS2010打开，设置好包含目录之后即可生成最简单的插件dll。也可以在VS中将该项目添加到其他解决方案中。若不选择该项，则生成必要的文件，自行创建新的项目，这种方式可以用于其他版本的VS，但需要注意def文件不能直接在新建的项目中添加现有项来完成，否则生成的dll在测试页面中会有问题，正确的做法是用VS添加新建项，添加一个空白的def文件，然后将本工具生成的def文件内容复制到空白def文件中；其他文件则可以直接在VS中添加现有项来进行。建议不要用本工具生成VS项目，因为每个项目文件都有不同的GUID，而本工具没有自动生成GUID的功能，其中使用的GUID是试验的时候创建项目所采用的GUID。</div>
]]></content:encoded>
			<wfw:commentRss>https://www.softwareace.cn/?feed=rss2&#038;p=104</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
