Skip to content

Documenting the sample NPAPI plugin provided by Overwolf to help anyone get oriented

Notifications You must be signed in to change notification settings

dyanarose/overwolf-sample-plugin-documentation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 

Repository files navigation

overwolf-sample-plugin-documentation

This is meant as a companion to the Overwolf Sample Plugin, providing a bit more information on the structure of the plugin and links to further information

What is NPAPI

NPAPI is a cross-browser API for creating plugins. A wealth of information on NPAPI development is available from MDN.

What is the purpose of the XULRunner SDK / Gecko SDK

The Gecko SDK, also known as the XULRunner SDK, is a set of XPIDL files, headers and tools to develop XPCOM components which can then in turn e.g. be accessed from XUL using JavaScript. https://developer.mozilla.org/en/docs/Gecko_SDK

Using the XULRunner SDK you are able to interact with your c/c++ code through javascript.

You can explore the full API at https://developer.mozilla.org/en-US/Add-ons/Plugins/Gecko_Plugin_API_Reference.

The main file notes that the sample app was tested against a specific version of the SDK. Make sure you use the version listed.

How is the sample app structured

The meat of the plugin is provided by a Scriptable Object which defines and exposes the functions that are available to javascript.

In the sample plugin, an abstraction layer over the NPObject API has already been implemented in nsScriptableObjectBase with default method implementations that can be overriden as necessary.

nsScriptableObjectBase then serves as the base of the class nsScriptableObjectOverwolfSample. It's this class, nsScriptableObjectOverwolfSample, that provides the actual "echo" and "add" implementations.

Along with the registration of the javascript methods and the code implementation, nsScriptableObjectOverwolfSample also includes an example of running the code on a new background thread to prevent blocking on the UI thread.

Mapping Javascript methods to c/c++ methods

The scriptable object nsScriptableObjectOverwolfSample includes a map, methods_, which is used to hold the available public methods, and a REGISTER_METHOD function-like macro that handles adding functions to the map by name.

By calling REGISTER_METHOD in the Init() function, you map the desired javascript method name to the implementation and make it available to be called in javascript.

Registering the Scriptable Object

Now that there is a scriptable object with functions that are able to be called in javascript, the scriptable object must be registered with the plugin instance.

In the sample app, this happens in the nsPluginInstanceOverwolfSample class. In the GetValue function, the nsScriptableObjectOverwolfSample is created, initialized, and assigned if it doesn't already exist. (plugin threading model)

nsPluginInstanceOverwolfSample includes a note about the upcoming drop of NPAPI support from Chromium, which you can read more about at https://www.chromium.org/developers/npapi-deprecation. I don't believe Overwolf has made any public announcement about their plans, other than the warning in the sample app.

Registering the Plugin

Now that the functions have been registered with the scriptable object and the scriptable object has been registered with the plugin instance, the plugin instance must be created (and destroyed). For this we get to the main method (main).

The plugin is created in NS_NewPluginInstance and destroyed via NS_DestroyPluginInstance.

Now that the plugin is ready to go, there's still another few cleanup steps that are noted in the main file. If you look at the top of the main file, you'll see a mimeType being set. You need to change this to your own type.

You also need to go to the .rc file and update the resource info.

About

Documenting the sample NPAPI plugin provided by Overwolf to help anyone get oriented

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •