Mozilla NPAPI (Part 3)

Source: Internet
Author: User
Tags types of functions

After a month of hard work, the Firefox plug-in was released ..

 

Now, let's think about the processes we 've experienced, and we don't even have a clear idea about the documents we wrote at the beginning. Come on again. Summary from practice.

 

1. Why plugins.

 

There are two reasons.

 

1. The NPAPI that supports plugins is supported by other browsers, such as chrome, opera, safari, and mozilla. (To see: Scripting_plugins) In addition, it is also supported by multiple systems, including Linux and Mac.

 

2. They said that implementing ActiveX plug-ins similar to IE in Firefox is Plugins. Instead of Extention. So I made it like this. When I sorted out the document today, I found that there is actually a very good article, Browser Plugins vs Extensions-the difference

.

 

2. What is NPAPI?

 

The simplest sentence is Netscape Plugins API.

 

Kaishan document: Plug-in Basics
.

 

Keywords:

@ 1. about: enter this command in the address bar of the plugins browser to obtain all the plugins installed in the browser;

@ 2. MIME Types: the MIME type must be specified so that JS Code can identify the plug-in. Note: After the plug-in is placed on the server, you must set this value for the server;

@ 3. plugins Step 4: Find mime ins that match the MIME type, load the plug-in code to the memory, initialize plugins, and create a plugins instance. Prerequisite: embed appears on the page ..

@ 4. Two types of functions: NPP (the method implemented by the plug-in) and PNP (implemented by the browser );

@ 5. runtime Model: NP_Initialize (Gecko callit, when the plug-in code is loaded for the first time), NPP_New (the browser calls this function when the instance is created), NPP_Destroy (Gecko calls it when the instance is destroyed ), NP_Shutdown (Gecko calls this function when the last instance is destroyed, and the memory will release the plug-in Code );

@ 6. Confirm the path,/plugins/npXX. dll. The standard mozilla structure path can be identified by Gecko. (xpi has strict path requirements)

 

3. How to Implement the NPAPI?

 

Reference: Plug-in
Development Overview
.

 

Reference instance: npruntime.

 

Key Path:

@ 1. Find the npruntime example, compile and run it, write a test.html page, and test its functions;

@ 2. Question: how to define the attribute Method for interaction with JS? Where is the entrance to the entire npapi? How do I define method attributes? Further, how does the browser identify the implementation of plug-ins?

@ 3. first of all, understand npp and (refer to @ 4 in entry 2). We can see that the functions to be implemented by the plug-in should start with npp, and then start with NPP_New, you can create an object instance in NPP_New, and this object is the function class of the plug-in you designed to implement. Of course, the most important thing is to put the created instance, the pdata sent to NPP. The Code is as follows:

 

/* <Br/> * NPP is a plug-in's opaque instance handle <br/> */<br/> typedef struct _ NPP <br/> {<br/> void * pdata; /* plug-in private data */<br/> void * ndata;/* netscape private data */<br/>} NPP_t; <br/> typedef NPP_t * NPP;

 

@ 4. How to define the attribute Method for interaction with JS? It can be seen that there are property and method methods in npnfunctions. We should consider implementing this method in the plugins object. You only need to place the method or attribute name you want to identify it. Example code:

 

// Define a method name or attribute name <br/> CWrapper: CWrapper (NPP npp): pluginObjectBase (npp) <br/>{< br/> sObject_id = NPN_GetStringIdentifier ("fObject "); <br/>}< br/> // if it is a method name <br/> bool <br/> CWrapper: HasMethod (NPIdentifier name) <br/>{< br/> return (name = sObject_id ); <br/>}< br/> // if it is an attribute name <br/> bool <br/> CWrapper: HasProperty (NPIdentifier name) <br/>{< br/> return (name = sObject_id); <br/>}

 

@ 5. How are these methods implemented and how are attributes assigned? The method uses the invoke callback function, while the property uses the GetProperty and SetProperty methods.

 

After these steps, you will have a basic understanding of the NPAPI. In the meantime, I got a lot of inspiration from teacher Jing. The npruntime is a good instance and can be rewritten ~ However, the problem persists: Can we use the NPAPI to encapsulate the ActiveX plug-in of IE.

 

Continue ..

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.