Getting the page URL in NPAPI plugin

  • Revision slug: Getting_the_page_URL_in_NPAPI_plugin
  • Revision title: Getting the page URL in NPAPI plugin
  • Revision id: 70917
  • Created:
  • Creator: El1T0v
  • Is current revision? No
  • Comment

Revision Content

Sometimes, you want to restrict an NPAPI plugin to be loadable only from a certain URL or domain or scheme. Or whenever you make network requests yourself, you almost always need to enforce same-origin policy.

There's unfortunately no trivial way to do that, but you can still do it, by asking the browser for the page URL during plugin initialization. Then you can just refuse to do anything, if you don't like the URL, or you can compare it with the other URL you want to contact.

So, how do we get at that page URL, i.e. the URL of the HTML which embeds the plugin, i.e. which caused the plugin to load?

There are at least 3 solutions (quoting newsgroup posts):

Via window location

From Robert Platt:

// Get the window object.
NPN_GetValue( m_pNPInstance, NPNVWindowNPObject,

Revision Source

<p>Sometimes, you want to restrict an <a href="en/Plugins">NPAPI plugin</a> to be loadable only from a certain URL or domain or scheme. Or whenever you make network requests yourself, you almost always need to enforce same-origin policy.
</p><p>There's unfortunately no trivial way to do that, but you can still do it, by asking the browser for the page URL during plugin initialization. Then you can just refuse to do anything, if you don't like the URL, or  you can compare it with the other URL you want to contact.
</p><p>So, how do we get at that page URL, i.e. the URL of the HTML which embeds the plugin, i.e. which caused the plugin to load?
</p><p>There are at least 3 solutions (quoting newsgroup posts):
</p>
<h2 name="Via_window_location"> Via window location </h2>
<p>From <a class="external" href="http://groups.google.com/group/netscape.public.mozilla.plugins/msg/93166efa554a191b">Robert Platt</a>:
</p>
<pre class="eval">// Get the window object.
NPN_GetValue( m_pNPInstance, NPNVWindowNPObject,
</pre>
Revert to this revision