﻿{"id":63,"date":"2010-05-21T09:43:16","date_gmt":"2010-05-21T01:43:16","guid":{"rendered":"http:\/\/nick.workao.org\/?p=63"},"modified":"2010-05-21T09:43:16","modified_gmt":"2010-05-21T01:43:16","slug":"%e5%a6%82%e4%bd%95%e7%82%ba%e4%bd%a0%e7%9a%84-firefox-plugin-%e5%8a%a0%e4%b8%8a%e6%96%b0%e7%9a%84-method","status":"publish","type":"post","link":"http:\/\/nick.txtcc.com\/index.php\/other\/63","title":{"rendered":"\u5982\u4f55\u70ba\u4f60\u7684 firefox plugin \u52a0\u4e0a\u65b0\u7684 method"},"content":{"rendered":"<p>\u6700\u7c21\u55ae<span style=\"color: #ff0000;\">\u6700\u7b28\u7684\u64cd\u4f5c\u6b65\u9a5f<\/span>\u5982\u4e0b:<\/p>\n<p><strong>Step 1: \u52a0\u5165 method \u540d\u7a31\u6a19\u8a18<\/strong>\n\u00a0\u00a0\u00a0 \u5728 plugin.cpp \u4e2d\u7684 CPlugin method \u4e2d\u52a0\u5165 method \u7684\u6a19\u8a18<\/p>\n<p>ex:\n\u00a0\u00a0\u00a0 <span style=\"color: #008000;\">CPlugin::CPlugin(NPP pNPInstance) ..{ <\/span><\/p>\n<p><span style=\"color: #008000;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <span style=\"color: #ff0000;\">MYfunction_id<\/span>=NPN_GetStringIdentifier(&#8220;MYfunction&#8221;);\n\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><strong>Step 2: \u5ba3\u544a method \u540d\u7a31\u6a19\u8a18<\/strong>\u00a0<\/p>\n<p>ex:\n\u00a0\u00a0\u00a0 <span style=\"color: #008000;\">static NPIdentifier <span style=\"color: #ff0000;\">MYfunction_id<\/span>; <\/span><\/p>\n<p><strong>Step 3: \u544a\u8a34\u5225\u4eba\u4f60\u7684\u5143\u4ef6\u6709\u9019\u500b method<\/strong>\nex:\n<span style=\"color: #008000;\">\u00a0\u00a0\u00a0 bool ScriptablePluginObject::HasMethod(NPIdentifier name){\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if(name == <span style=\"color: #ff0000;\">MYfunction_id<\/span>)\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return true;\n\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><strong>Step 4: \u7576 script \u547c\u53eb\u4f60\u7684 method \u6642, \u63d0\u4f9b\u4f60 method \u7684\u5be6\u505a<\/strong><\/p>\n<p>ex:\n\u00a0\u00a0\u00a0 <span style=\"color: #008000;\">bool ScriptablePluginObject::Invoke(NPIdentifier name, const NPVariant <em>args,uint32_t argCount, NPVariant <\/em>result) {\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DWORD dwThreadID; <\/span><\/p>\n<p><span style=\"color: #008000;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if(name == <span style=\"color: #ff0000;\">MYfunction_id<\/span> ){\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 MessageBox(NULL,L&#8221;\u547c\u53eb MYfunction_id&#8221;,L&#8221;Java Script \u547c\u53eb\u7bc4\u4f8b&#8221;,MB_OK);\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return PR_TRUE;\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 } <\/span><\/p>\n<p><span style=\"color: #008000;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return PR_FALSE;\n\u00a0\u00a0\u00a0 }<\/span><\/p>\n<p><strong>\u5982\u4f55\u8b93 JavaScript \u50b3\u53c3\u6578\u7d66\u4f60\u7684 plugin method \u5462?<\/strong><\/p>\n<p>\u5982\u679c Java Script \u547c\u53eb\u7684 method \u6709\u53c3\u6578, \u6211\u5011\u8981\u5982\u4f55\u53d6\u51fa\u53c3\u6578\u8cc7\u6599\u5462\n\u4f8b\u5982:\n\u00a0\u00a0\u00a0 Myfunction(&#8220;192.168.0.1&#8221;,1234);<\/p>\n<p>=== in Invoke method ===\n<span style=\"color: #0000ff;\">\/\/ \u7b2c\u4e00\u500b\u53c3\u6578: &#8220;192.168.0.1&#8221;\n<\/span>\u00a0\u00a0\u00a0 NPVariant varIP=args[0];\n\u00a0\u00a0\u00a0 NPString npstrIP=<span style=\"color: #ff0000;\">NPVARIANT_TO_STRING<\/span>(varIP); \/\/ \u53d6\u51fa &#8220;192.168.0.1&#8221;\n\u00a0\u00a0\u00a0 <span style=\"color: #0000ff;\">\/\/ \u5370\u51fa\u4f86\u770b\u770b: \u5c07 utf8 \u5b57\u4e32 \u8f49\u6210 Wide Char\n<\/span>\u00a0\u00a0\u00a0 int\u00a0\u00a0 length=MultiByteToWideChar(CP_UTF8,0,(char<em>)npstrIP.utf8characters,-1,NULL,0);\n\u00a0\u00a0\u00a0 TCHAR <\/em>strIP=new TCHAR[length];\n\u00a0\u00a0\u00a0 MultiByteToWideChar(CP_UTF8,0,(char*)npstrIP.utf8characters,-1,strIP,length);\n\u00a0\u00a0\u00a0 MessageBox(NULL,strIP,_T(&#8220;\u547c\u53eb funPassVar_id: \u7b2c\u4e00\u500b\u53c3\u6578n&#8221;),MB_OK);\n\u00a0\u00a0\u00a0 delete[] strIP;<\/p>\n<p>\u00a0\u00a0\u00a0 <span style=\"color: #0000ff;\">\/\/ \u7b2c\u4e8c\u500b\u53c3\u6578: 1234\n<\/span>\u00a0\u00a0\u00a0 NPVariant varValue=args[1];\n\u00a0\u00a0\u00a0 int32_t value=<span style=\"color: #ff0000;\">NPVARIANT_TO_INT32<\/span>(varValue);<\/p>\n<h1>\u00a0\u00a0\u00a0 <span style=\"color: #0000ff;\">\/\/\u5370\u51fa\u4f86\u770b\u770b: \u5370\u51fa int32 \u7684\u5167\u5bb9<\/span>\n\u00a0\u00a0\u00a0 TCHAR msg[100];\n\u00a0\u00a0\u00a0 _stprintf(msg,_T(&#8220;value=%d&#8221;),value);\n\u00a0\u00a0\u00a0 MessageBox(NULL,msg,_T(&#8220;\u547c\u53eb funPassVar_id: \u7b2c\u4e8c\u500b\u53c3\u6578n&#8221;),MB_OK);<\/h1>\n<p><span style=\"color: #404040;\">\u5e0c\u671b\u5c0d\u4f60\u6709\u5e6b\u52a9. <\/span><\/p>\n<p><span style=\"color: #404040;\">by Jing<\/span><\/p>","protected":false},"excerpt":{"rendered":"<p>\u6700\u7c21\u55ae\u6700\u7b28\u7684\u64cd\u4f5c\u6b65\u9a5f\u5982\u4e0b: Step 1: \u52a0\u5165 method \u540d\u7a31\u6a19\u8a18 \u00a0\u00a0\u00a0 \u5728 plugin.cpp \u4e2d\u7684 CPlugin method \u4e2d\u52a0\u5165 method \u7684\u6a19\u8a18 ex: \u00a0\u00a0\u00a0 CPlug&#46;&#46;&#46;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[33,38,36],"class_list":["post-63","post","type-post","status-publish","format-standard","hentry","category-other","tag-firefox","tag-method","tag-plugin"],"_links":{"self":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/63","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/comments?post=63"}],"version-history":[{"count":1,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/63\/revisions"}],"predecessor-version":[{"id":64,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/63\/revisions\/64"}],"wp:attachment":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/media?parent=63"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/categories?post=63"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/tags?post=63"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}