Background
Since Chrome started discarding npapi, the plugin that we used to implement with NPAPI needs to be ported to NaCl (Native Client). NaCl is currently only supported in the Chrome browser, with the features of the native C + + program, cross-platform, security sandbox, high-performance, and more suitable for 3D games, multimedia players, CAD modeling and other types of plug-in development. Brief introduction
There is also a technique to replace npapi called native Messaging, which supports data communication between chrome and local programs, but not for our plugins, interested in knowing about it (here).
The development environment under the MAC is built
1. Download the SDK
Download the interface below, there are installation steps, quite detailed.
If the following error occurs, you can directly download the hint in the JSON file, there are various platforms and versions of the SDK download path, as necessary to download (recommended to download the latest stable version).
2.Demo Demo
Using the terminal, go to the examples directory and execute the make command to compile all of the demo's code.
The httpd.py file in the tools directory is then copied to the examples directory and executed using the terminal./httpd.py (need to install Python2.7), you can access the demo via http://localhost:5103 in the browser. (NaCl plug-in can not be directly loaded with local JS, so either use the server's JS to invoke, or virtual out of the server to perform local JS)
3. Create your own project
Use Xcode to manage and compile projects here
3.1 First create a bundle project under Mac OS
3.2 Adding the NaCl library in build settings-search paths
3.3 Add the Makefile file to the project (you can use the makefile in the Sdk-demo and make the appropriate modifications)
Target is the name of the generated plug-in, sources in this way can easily add and delete files. The other should not need to be modified
3.4 Add a target for the external build system to compile the NaCl code (this target must be selected to compile when the program needs to be compiled). Then in info, add the relative paths to the compilation parameters and makefile.
If the compilation parameter is empty, the default is to compile the PNACL,NEWLIB,GLIBC three release program. You can specify TOOLCHAING=PNACL/NEWLIB/GLIBC and Version=release/debug. Using VS2010 or later in Windows, you can debug your program with breakpoints, but Xcode is not supported.
If you are in the process of compiling the code, unused variables and common warnings appear in error, and you need to modify the Common.mk file in the SDK's Tools directory: Remove-werror from Nacl_cflags and Nacl_cxxflags, and add-wno-unused.
Development code
This part has nothing to say, as long as the code in the demo to see once, you can basically develop. The official website also has a very detailed API description: here
Here to mention, the NaCl SDK in version 39 added a JS side to send a message and wait for the return of the results of the mechanism (postmessageandawaitresponse, also need to modify the plug-in to receive the message code. Previously only postmessage, send not wait), suitable for the kind of non-time-consuming operation.
Refer to the Examples/api/messaging project in the SDK directory for details
Encounter the Pit
1.FileIO operations can only be asynchronous
Chrome should be afraid that this time-consuming operation will affect the response of the page, so it has to be executed asynchronously. This place has tried a lot of ways and it doesn't work. Later only the preloaded mode can be selected to manipulate the file data.
2.FileSystem according to the domain name to divide
Each call to the plug-in domain site, has a separate file system, which helps improve security, but the disadvantage is: even the same plug-in, not several domain names share local file data (unless using an IFRAME)
3. Using FileIO to store files locally, you need to request space
There are two types of application space:
The first is to add Unlimitedstorage permissions in the Manifest.json file, which applies to the Chrome Web Store application, and when the user installs the plugin, the following small yellow bar appears to request confirmation from the user.
The second is to use Navigator.webkitPersistentStorage.queryUsageAndQuota and Navigator.webkitPersistentStorage.requestQuota in JS (specific usage can Google) method, when the page executes Requestquota, there will also be a small yellow bar.
As long as the user does not click OK, then the FileIO related actions in your plugin will fail.
Advantages of NaCl
1. Using the message mechanism to realize the data communication between the plugin and chrome, making the code much simpler than NPAPI
2. Cross-platform, one copy of code, multiple use. But that means there are also a lot of limitations on NaCl.
Summarize
The process of transplanting from NPAPI to NaCl, and some other pits, are not listed here. This is a process that needs to stop and pits without a few steps. Perhaps this means that NaCl does not apply to our plugins at all-it's just that we haven't found a better solution yet.
NaCl, the exclusive Chrome API, increases the cost of developing WEB plugins, resulting in the need for IE kernel, WEB kit kernel, chrome Three set of code, and poor maintenance. Hopefully there's a common API that will unify them later.