- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / common / extensions / docs / templates / articles / npapi.html
1 <h1>NPAPI Plugins</h1>
2
3 <p>
4 Leveraging HTML and JavaScript
5 makes developing new extensions really easy,
6 but what if you have existing legacy or proprietary code
7 that you want to reuse in your extension?
8 You can bundle an NPAPI plugin with your extension,
9 allowing you to call into native binary code from JavaScript.
10 </p>
11
12 <h2 id="warning">Warning</h2>
13
14 <p align="center"><b><a href="http://blog.chromium.org/2013/09/saying-goodbye-to-our-old-friend-npapi.html">NPAPI is being phased out.</a>
15 Consider using alternatives.</b></p>
16
17 <p align="center"><b>NPAPI is a really big hammer that should only be used when no other approach will work.</b>
18
19 <p>Code running in an NPAPI plugin has the full permissions of the current user and is not sandboxed or shielded from malicious input by Google Chrome in any way. You should be especially cautious when processing input from untrusted sources, such as when working with <a href="content_scripts.html#security-considerations">content scripts</a> or XMLHttpRequest.
20
21 <p>Because of the additional security risks NPAPI poses to users, extensions that use it will require manual review before being accepted in the
22 <a href="https://chrome.google.com/webstore">Chrome Web Store</a>.</p>
23
24 <h2 id="details">Details</h2>
25
26 <p>
27 How to develop an NPAPI plugin is outside the scope of this document.
28 See <a href="https://developer.mozilla.org/en/Plugins">Mozilla's
29 NPAPI plugin reference</a> for information on how to do that.
30 </p>
31
32 <p>
33 Once you have an NPAPI plugin,
34 follow these steps to get your extension using it.
35 </p>
36
37 <ol>
38   <li>
39     Add a section to your extension's <code>manifest.json</code>
40     that describes where to find the plugin,
41     along with other properties about it:
42
43 <pre data-filename="manifest.json">
44 {
45   "name": "My extension",
46   ...
47   <b>"plugins": [
48     { "path": "extension_plugin.dll" }
49   ]</b>,
50   ...
51 }
52 </pre>
53
54     <p>
55     The "path" property specifies the path to your plugin,
56     relative to the manifest file.
57     The "public" property specifies whether
58     your plugin can be accessed by regular web pages;
59     the default is false,
60     meaning only your extension can load the plugin. Add
61     <code>"public": true</code> to make your plugin accessible on
62     regular web pages and content scripts. But
63     <a href="#security-considerations">be careful</a> - any
64     web page will then be able to call into your plugin.
65     </p>
66    </li>
67
68    <li>
69      Create an HTML file that loads your plugin by mime-type.
70      Assuming your mime-type is "application/x-my-extension":
71
72 <pre>
73 &lt;embed type="application/x-my-extension" id="pluginId"></embed>
74 &lt;script>
75   var plugin = document.getElementById("pluginId");
76   var result = plugin.myPluginMethod();  // call a method in your plugin
77   console.log("my plugin returned: " + result);
78 &lt;/script></pre>
79
80      <p>
81      This can be inside a background page
82      or any other HTML page used by your extension.
83      If your plugin is "public",
84      you can even use a content script to programmatically
85      insert your plugin into a web page.
86      </p>
87    </li>
88 </ol>
89
90 <h2 id="security-considerations">Security considerations</h2>
91
92 <p>
93 Including an NPAPI plugin in your extension is dangerous because plugins
94 have unrestricted access to the local machine.  If your plugin contains
95 a vulnerability, an attacker might be able to exploit that vulnerability
96 to install malicious software on the user's machine.  Instead, avoid
97 including an NPAPI plugin whenever possible.
98 </p>
99
100 <p>
101 Marking your NPAPI plugin "public" increase the attack surface of your
102 extension because the plugin is exposed directly to web content, making
103 it easier for a malicious web site to manipulate your plugin.  Instead,
104 avoid making your NPAPI plugin public whenever possible.
105 </p>