-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnpapi.html
159 lines (151 loc) · 7.48 KB
/
npapi.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title> npapi - write browser plugins in Lua </title>
<script src="jquery.js"></script>
<script src="jquery-cookie.js"></script>
<script src="jquery-tablesorter.js"></script>
<script src="strftime.js"></script>
<script src="mustache.js"></script>
<script src="config.js"></script>
<script src="main.js"></script>
<link rel="stylesheet" type="text/css" href="templates/reset.css" />
<link rel="stylesheet" type="text/css" href="templates/hack.css" />
<link rel="stylesheet" type="text/css" id="lights_css" />
<script>
var DOCNAME = 'npapi'
var PROJECT = 'npapi'
//set the lights before rendering starts
set_lights()
</script>
</head>
<body>
<header>
<div class="container">
<div class="btn-container btn-lights-container">
<a href="#" class="btn btn-lights" id="lights">lights</a>
</div>
<div class="btn-container btn-home-container">
<a href="/" class="btn btn-home">luapower</a>
</div>
<table id="header_table">
<tr>
<td style="vertical-align: middle;" width="100%">
<h1> npapi </h1>
<h2> write browser plugins in Lua </h2>
</td>
<td style="vertical-align: middle;" align="right" style="height: 150px">
<table><tr><td>
<div class="doc" id="package_info_container">
<div id="package_info"> </div>
<div id="commit_log"> </div>
</div>
<a href="https://github.com/luapower/npapi" class="btn btn-rightside btn-github"><span class="icon"></span>View on GitHub</a>
</td></tr><tr><td>
<a href="https://github.com/luapower/npapi/tarball/master" class="btn btn-rightside">Download as .tar.gz</a>
</td></tr><tr><td>
<a href="https://github.com/luapower/npapi/zipball/master" class="btn btn-rightside">Download as .zip</a>
</td></tr></table>
</td>
</tr>
</table>
<div class="btn-container btn-discuss-container">
<a href="https://github.com/luapower/npapi/issues/new" target="_blank"
class="btn btn-rightside btn-discuss"><span class="icon"></span>Discuss</a>
</div>
</div>
</header>
<div class="bg-container">
<div class="bg-center-container">
<div class="bg bg-npapi" style="background-image: url('bg/npapi.png');"></div>
</div>
</div>
<div class="under-header">
<div class="container">
<div id="toc_container" class="toc_container doc"></div>
<button id=tab1_button class=tab_button>Documentation</button>
<button id=tab2_button class=tab_button>Package Info</button>
<div id="tabs_cointainer">
<div id="tab1_container">
<section class="doc">
<span id="module_info"></span>
<h2 id="overview">Overview</h2>
<p>A framework for writing NPAPI-based browser plugins in Lua.</p>
<p><strong>This is only an experiment.</strong> It was only superficially tested with Chrome and Firefox on Windows XP SP3. It is also a futile exercise, as both Google and Mozilla will remove NPAPI from their browsers after 2014.</p>
<h2 id="get-started">Get started</h2>
<ol style="list-style-type: decimal">
<li>Edit <code>csrc/npapi/mozilla_install.reg</code> and change the <code>Path</code> key in there to <code><your-luapower-dir>/bin/mingw32/npcplayer.dll</code> so that the browser can find and load the npapi "bootstrap" plugin.</li>
</ol>
<blockquote>
<p>This allows you to develop plugins directly from your luapower work tree, without any deployment step necessary, so that you can have the usual edit-save-refresh iteration cycle.</p>
</blockquote>
<ol start="2" style="list-style-type: decimal">
<li>Get <a href="color.html">color</a> and refresh this page. The demo below should load.</li>
</ol>
<embed type="application/x-npcplayer" width="800" height="400" demo="color_demo"></embed>
<ol start="3" style="list-style-type: decimal">
<li>Check <code>npapi-log*.txt</code> for errors.</li>
</ol>
<h2 id="how-its-put-together">How it's put together</h2>
<p>The bootstrap plugin (npcplayer.dll) is driven by the browser which calls the plugin's <code>NP_*</code> functions whenever it needs to create or destroy a plugin instance. Upon the first call to <code>NP_Initialize</code>, the plugin finds its own directory, and then it makes a Lua state and loads <code>../../npapi.lua</code> relative to that directory. <code>npapi.lua</code> returns a "forwarder" function. The plugin then forwards the <code>NP_Initialize</code> call through that function. Further <code>NP_</code> calls will go through that same Lua state and "forwarder" function. That's where the C part ends. The rest is done in Lua. The <code>npapi</code> module creates and destroys <code>npapi_instance</code> objects for each plugin instance that the browser wants to create. The npapi instance object uses <a href="lanes.html">lanes</a> and <a href="winapi.html">winapi</a> to create a thread and a message loop, and then it creates a <a href="cplayer.html">cplayer</a> window as a child of the browser-provided window for the plugin.</p>
<h2 id="npapi-tips">NPAPI Tips</h2>
<ul>
<li>get NPAPI headers from https://code.google.com/p/npapi-sdk/
<ul>
<li>I stripped them of cruft (they were mostly cruft)</li>
</ul></li>
<li>dll exported functions must be __stdcall
<ul>
<li>gcc mangles __stdcall names
<ul>
<li>pass -Wl,--kill-at to demangle</li>
</ul></li>
</ul></li>
<li>firefox loads a plugin either from a xpi package or from known locations.
<ul>
<li>known locations are either %APPDATA%or they are specified in the registry
<ul>
<li>for loading from %APPDATA%, link the .rc file that declares the name and the mime type in dll's VERSIONINFO.
<ul>
<li>BLOCK "040904E4" and "Translation" 0x0409, 0x04E4 must be hardcoded like that or the plugin won't install.</li>
<li>the dll must be named np*.dll or it won't be found.</li>
<li>the "MIMEType" value must be declared or the plugin won't install.</li>
</ul></li>
<li>for loading via registry, run the .reg file that declares the name, location and the mime types for the plugin.</li>
</ul></li>
<li>for xpi loading see the xpi dir and the build script that creates the xpi file.</li>
<li>to check if plugin loads use:
<ul>
<li>about:plugins</li>
<li><p>use javascript:</p>
<pre class="sourceCode javascript"><code class="sourceCode javascript"><span class="kw">var</span> mimetype = <span class="ot">navigator</span>.<span class="fu">mimeTypes</span>[<span class="st">"application/x-npcplayer"</span>]
<span class="kw">var</span> plugin = <span class="ot">mimetype</span>.<span class="fu">enabledPlugin</span>
<span class="ot">console</span>.<span class="fu">log</span>(<span class="ot">plugin</span>.<span class="fu">name</span>)
<span class="ot">console</span>.<span class="fu">log</span>(<span class="ot">plugin</span>.<span class="fu">description</span>)</code></pre></li>
<li><p>use html: <code><embed type="application/x-npcplayer" width="1300" height="700" demo="color_demo"></embed></code></p></li>
</ul></li>
</ul></li>
</ul>
</section>
</div>
<div id="tab2_container" class="doc"></div>
</div>
</div>
<div class="container">
<footer>
<div id="disqus_thread"></div>
<div class="faint">cosmin.apreutesei@gmail.com | <a href="http://unlicense.org/">public domain</a></div>
</footer>
</div>
</div>
<script type="text/x-mustache" id=info_tab_template>
<h3>Modules</h3>
<ul>
{{#module_array}}
<li>{{name}}</li>
{{/module_array}}
</ul>
</script>
</body>
</html>