Mozilla NPAPI (Part 1)

Source: Internet
Author: User

After reading this part of content over the past few days, I finally got a little eye off. Sort it out.

 

1. Implement something similar to ActiveX plug-in IE. I started to think that I could continue to play with XPCOM, but later I found that Extention is not the same thing as what I want to implement. The emergence of NPAPI.

 

2. Can Extention implement the functions I want? Can I interact with the Web Server through JS? In the past, Extention was used for client operations, but it was not easy to bend. It is understood that plugins
It is to enhance the browser's own particularity, for example, to help browser display multimedia files; Extention can change FF and so on. However, I still don't seem to understand.

 

I was persuaded to use the NPAPI mainly because of 3rd ..

 

3. On the other hand, napi is selected because browsers other than IE are currently common
. Currently, we can see from the document that Chrome supports the NPAPI. Therefore, we use the NPAPI.

 

This means that I want to learn about NPAPI from the beginning ..

 

4. Through the npruntime example, we can basically understand how NPAPI is introduced to pages in a browser. ActiveX similar to IE, You need to insert <embed>/<object> in HTML code, and find and register the plug-in through MIME Type, but how can I identify whether the plug-in is in the latest version? Do you also need to change the Version in the rc file? Further verification is required. But the interaction between JS and NPAPI is completely different from the interaction between XPCOM and JS. It can be done with an IDL file. NPAPI seems more complicated.

 

In this section, if npruntime is tested, you need to download and compile this part of the code. Of course, you need to download the Gecko SDK (or Xulrunner SDK) based on the Compilation documentation.
During compilation, problems may occur. Note that the settings, Preprocessor settings, and def files in the def file and configuration options are linked to the module definition in the linker, in addition, you may need. add <stdio. h> file. In this way, there is basically no problem. The source code I got is FF 3.6.11. The SDK is also the latest.

 

Example
Yes. Next, let's take a look ..

 

5. Register plugins in detail. Find the plug-in through the MIME type. The browser finds that the plug-in file is loaded when it supports the plug-in MIME type. The name of plugin must be np-typed. dll is the extension and complies with the 8.3 standard.

 

6. Interaction between Plugin and browser: accordingMOZ_PLUGIN_PATH is used to find plugin.
MOZ_PLUGIN_PATH is different in different systems, but both are browser installation paths.

 

When the browser opens a page containing the embed tag, the browser checks whether the plug-in matches a MIME type; 2) loads the plug-in code to the cache; 3) initialize the plug-in. 4) Create an instance of the plug-in. The browser can load the same plug-in multiple times on a page.

 

When the plug-in is loaded for the first time, Gecko will call NP_Initialize
Method. Once the plug-in is loaded, the browser calls the NPP_New method of the plug-in to create an instance of the plug-in. When the page is closed, the instance is destroyed, gecko will call NPP_Destroy to notify the plug-in to delete the instance. When all the instances are destroyed, Gecko will call NP_Shutdown. In this case, the plug-in will be requested to go out of the cache.

 

To verify whether the plug-in is installed, you can use the MIME type to determine whether the plug-in is installed. The following is an example of using the enabledPlugin attribute:

 

// Can we display Adobe Flash movies? <Br/> var mimetype = navigator. mimetypes ["application/X-Shockwave-flash"]; <br/> If (mimetype) {<br/> // yes, so can we display with a plug-in? <Br/> var plugin = mimetype. enabledplugin; <br/> If (plugin) {<br/> // yes, so show the data in-line <br/> document. writeln ("here/'s a movie: <object data='mymovie.swf 'Height = '000000' width = '000000'> </Object> "); <br/>} else {<br/> // No, so provide a link to the data <br/> document. writeln ("<a href =" mymovie.swf "mce_href =" mymovie.swf "> click here </a> to see a movie. "); <br/>}< br/>}else {<br/> // No, so tell them so <br/> document. writeln ("Sorry, can't show you this movie. "); <br/>}

 

To learn more .. 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.