<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ColonelPanic &#187; ActiveX</title>
	<atom:link href="http://colonelpanic.net/category/plugindev/activex-plugindev/feed/" rel="self" type="application/rss+xml" />
	<link>http://colonelpanic.net</link>
	<description>Dumping our corps so you don&#039;t have to</description>
	<lastBuildDate>Mon, 30 Jan 2012 17:50:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Browser Plugins vs Extensions – the difference</title>
		<link>http://colonelpanic.net/2010/08/browser-plugins-vs-extensions-the-difference/</link>
		<comments>http://colonelpanic.net/2010/08/browser-plugins-vs-extensions-the-difference/#comments</comments>
		<pubDate>Tue, 10 Aug 2010 13:42:01 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[ActiveX]]></category>
		<category><![CDATA[Browser Plugin Development]]></category>
		<category><![CDATA[FireBreath]]></category>
		<category><![CDATA[NPAPI]]></category>
		<category><![CDATA[bho]]></category>
		<category><![CDATA[browser plugin]]></category>
		<category><![CDATA[extension]]></category>

		<guid isPermaLink="false">http://colonelpanic.net/?p=312</guid>
		<description><![CDATA[Overloaded terms One of the least understood concepts in the Browser Plugin world is &#8212; browser plugins.  What they are, and even more: what they are not.  Probably at least once a week I answer a question somewhere on a forum or on the comments on this blog and say &#8220;You can&#8217;t do that with [...]]]></description>
			<content:encoded><![CDATA[<h2>Overloaded terms</h2>
<p>One of the least understood concepts in the Browser Plugin world is &#8212; browser plugins.  What they are, and even more: what they are not.  Probably at least once a week I answer a question somewhere on a forum or on the comments on this blog and say &#8220;You can&#8217;t do that with a plugin; you need an extension&#8221;.</p>
<p>Many people confuse plugins and extensions in the browser world. They sound like they should be the same thing, but in fact they are very different.</p>
<h2>What you can do with a plugin</h2>
<p>A plugin is, quite simply, a third party library that &#8220;plugs in&#8221; to the browser that can be embedded inside a web page using an &lt;embed&gt; tag or a &lt;object&gt; tag.  Many of them then draw pretty pictures or animations, though that&#8217;s not required.  Many allow you to talk to them through javascript, though that&#8217;s not required.  In short, a plugin affects only a specific page in which it is placed.</p>
<p>Examples of common plugins include:</p>
<ul>
<li><span id="more-312"></span>Macromedia Flash</li>
<li>Microsoft Silverlight</li>
<li>Apple Quicktime</li>
<li>Adobe Reader (at least this includes a plugin in addition to the rest of the application)</li>
</ul>
<p>Some plugins respond to a mime type and can run in place of the page, such as Adobe Reader, which allows you to view PDF files in your web browser.  Again, however, it affects only that page, and no others.  In Firefox, Chrome, Opera, and Safari, these plugins are usually called &#8220;NPAPI plugins&#8221;, since they are written using the <a title="NPAPI on wikipedia" href="http://en.wikipedia.org/wiki/NPAPI">NPAPI</a>.  In Safari, you could also use a <a href="http://developer.apple.com/mac/library/documentation/InternetWeb/Conceptual/WebKit_PluginProgTopic/WebKitPluginTopics.html">Webkit Plugin</a>.  In Internet Explorer you would do this with an ActiveX Control.</p>
<h2>What a plugin cannot do</h2>
<p>Plugins have to either handle a mime type or be embedded into a web page.  They don&#8217;t get put there automatically. They don&#8217;t create toolbars.  They don&#8217;t affect browser menus.  They don&#8217;t know about tabs, or even about other pages in the same browser process.  They don&#8217;t make coffee, tea, or hot chocolate, though they could be written to control an external appliance to do so if you really wanted.  They don&#8217;t automatically process the content of every web page loaded.</p>
<p>&#8220;But wait!&#8221; I hear you all cry.  &#8220;We have seen these magical things done! (well, except the hot chocolate machine)&#8221;</p>
<p>&#8220;Yes,&#8221; I reply.  &#8220;Those are extensions.&#8221;</p>
<h2>Extensions</h2>
<p>Extensions, or &#8220;add-ons&#8221;, can often do these magical things.  They can add onto the browser UI, process pages that the browser loads.  They do all sorts of things.  However, they are not the same thing as plugins; they affect the web browser itself, not really the page.  They may affect a page as well, of course.  In fact, you can even put a plugin inside an extension, at least in Firefox.  However, if you write an extension for Firefox, you&#8217;ll probably have to write it again for Chrome, Safari, and IE&#8230; one for each.  Perhaps there is a framework out there for writing portable extensions, though.  It&#8217;s not really my area of expertise, so I don&#8217;t know.</p>
<p>Examples of extensions / add-ons:</p>
<ul>
<li><a href="http://www.downthemall.net/">DownThemAll</a> for Firefox</li>
<li><a href="http://getfirebug.com/" target="_blank">Firebug</a> for Firefox</li>
<li><a href="https://chrome.google.com/extensions/detail/kcnhkahnjcbndmmehfkdnkjomaanaooo" target="_blank">Google Voice extension</a> for Chrome</li>
<li><a href="http://kanab.hys.cz/let-there-be-comic-sans/">Let there be Comic Sans</a> for Safari</li>
</ul>
<p>And many, many, many more.  Extensions can be written in different languages depending on the browser.  In Firefox you can write them in C++ or javascript, and on Internet Explorer you write them as special ActiveX controls called <a href="http://en.wikipedia.org/wiki/Browser_Helper_Object">Browser Helper Objects</a>, or BHOs.</p>
<h2>An extension could contain a plugin, but a plugin can&#8217;t contain an extension</h2>
<p>One very common way to install a plugin in Firefox is to use a .xpi file.  <strong><em>This is an extension</em></strong>.  It may have a NPAPI plugin inside of it, but it is still an extension.  It will not work on other web browsers, even though your NPAPI plugin may work perfectly fine on Chrome and Safari if installed in another way.</p>
<p>Conversely, a plugin by nature does not include an extension.</p>
<h2>FireBreath</h2>
<p>Nearly a year ago now I began a project called FireBreath, which is a cross-platform browser plugin architecture.  FireBreath is, frankly, awesome. You can literally get a plugin up and going in under 10 minutes if you already have everything installed.  That means you can spend your time doing other more important things, like actually developing your functionality, rather than spending all your time figuring out how to deal with the plugin APIs.</p>
<p>That said, FireBreath is a cross-platform browser <span style="text-decoration: underline;"><em><strong>PLUGIN</strong></em></span> framework.  It does not create extensions.  It will never be able to create extensions.  If you need an extension, you need something else.</p>
<h2>When not to use a plugin</h2>
<p>Finally, and this is a topic that people seem to think is a little strange coming from me, there are many cases when it is not a good idea to use a browser plugin.  In fact, a good rule of thumb is that if you can do what you need to do without one, don&#8217;t use one.</p>
<p>Why?</p>
<ul>
<li>There are no really good ways to install browser plugins that will work 100% of the time
<ul>
<li>XPI install only works on one profile in firefox</li>
<li>CAB install only works in Internet Explorer and is sometimes a little unreliable</li>
<li>ClickOnce works only in Windows and only if .Net is installed</li>
<li>Java installers only work reliably and consistently on Mac OS</li>
<li>MSI or EXE installers while being the best method IMHO require a little more work on the part of the user, and the average user is&#8230; less savvy than you are, shall we say.</li>
</ul>
</li>
<li>Plugins have to take into account a large range of hardware types
<ul>
<li>If you use graphics libraries such as OpenGL or DirectX keep in mind that every graphics card works a little differently with these technologies.  You will run into weird cases where your plugin doesn&#8217;t work on someone&#8217;s computer.  If your luck is like mine, that computer will belong to an executive at a fortune 500 company (yes, that happened to me.  no, it wasn&#8217;t fun)</li>
</ul>
</li>
<li>Plugins don&#8217;t work until they have been installed
<ul>
<li>This is a major limiting factor to uptake of your site.  Many users don&#8217;t want to install yet another plugin on their machine, and many get lost in the incredibly complicated task of downloading and running the installer.</li>
</ul>
</li>
</ul>
<h2>Moving on</h2>
<p>If all of those things haven&#8217;t convinced you that what you want isn&#8217;t actually a browser plugin &#8212; great!  That&#8217;s why I&#8217;m still posting about this stuff.  Despite all the reasons not to use a plugin, there are also a lot of cases where it&#8217;s a good idea. Browesr plugin development can be a lot of fun!  Good luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://colonelpanic.net/2010/08/browser-plugins-vs-extensions-the-difference/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Firefox 3.6 has removed support for XPCOM plugins!</title>
		<link>http://colonelpanic.net/2010/01/firefox-3-6-has-removed-support-for-xpcom-plugins/</link>
		<comments>http://colonelpanic.net/2010/01/firefox-3-6-has-removed-support-for-xpcom-plugins/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 16:19:02 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[ActiveX]]></category>
		<category><![CDATA[Browser Plugin Development]]></category>
		<category><![CDATA[NPAPI]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[mozilla]]></category>
		<category><![CDATA[npruntime]]></category>
		<category><![CDATA[xpcom]]></category>

		<guid isPermaLink="false">http://colonelpanic.net/2010/01/firefox-3-6-has-removed-support-for-xpcom-plugins/</guid>
		<description><![CDATA[Most who are deep in the plugin world already know this, but I will repeat it quickly for those who only dabble: Firefox 3.6 has removed support for XPCOM plugins. This means that if you use XPCOM for your javascript interface (i.e. you have an IDL file on your npapi plugin, you us nsScriptablePeer, etc) [...]]]></description>
			<content:encoded><![CDATA[<p>Most who are deep in the plugin world already know this, but I will repeat it quickly for those who only dabble:</p>
<p>Firefox 3.6 has removed support for XPCOM plugins.</p>
<p>This means that if you use XPCOM for your javascript interface (i.e. you have an IDL file on your npapi plugin, you us nsScriptablePeer, etc) your plugin will no longer be able to communicate with javascript in Firefox 3.6.</p>
<p>Thus I repeat advice that I have given in the past:  Never, never, *never*, *ever* use XPCOM for your javascript interface in your plugin.</p>
<p>There might conceivably be reasons to use other aspects of XPCOM in a plugin, that might even work in other browsers.  At present, I don&#8217;t know of them.  Please enlighten me if there are (cookies?).</p>
<p>Oh, yeah, and FireBreath now has linux and mac support (experimental) as well as windows support (stable).  Come join the fun.  http://firebreath.googlecode.com</p>
<p>Thank you. :-P</p>
]]></content:encoded>
			<wfw:commentRss>http://colonelpanic.net/2010/01/firefox-3-6-has-removed-support-for-xpcom-plugins/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>Cross-Browser Scripting – Part one</title>
		<link>http://colonelpanic.net/2009/12/cross-browser-scripting-part-one/</link>
		<comments>http://colonelpanic.net/2009/12/cross-browser-scripting-part-one/#comments</comments>
		<pubDate>Mon, 28 Dec 2009 05:31:04 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[ActiveX]]></category>
		<category><![CDATA[Browser Plugin Development]]></category>
		<category><![CDATA[FireBreath]]></category>
		<category><![CDATA[NPAPI]]></category>
		<category><![CDATA[browser plugin]]></category>
		<category><![CDATA[Common Scripting Interface]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[IDispatch]]></category>
		<category><![CDATA[IDispatchEx]]></category>
		<category><![CDATA[npobject]]></category>
		<category><![CDATA[npruntime]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://colonelpanic.net/?p=117</guid>
		<description><![CDATA[The Problem: I&#8217;ll be up-front about something here; I don&#8217;t particularly like ActiveX.  I understand a lot of the reasons for creating it, and I won&#8217;t go so far as to claim that it shouldn&#8217;t exist or anything like that; in fact, it does very well for certain types of things.  The main thing I [...]]]></description>
			<content:encoded><![CDATA[<h1>The Problem:</h1>
<p>I&#8217;ll be up-front about something here; I don&#8217;t particularly like ActiveX.  I understand a lot of the reasons for creating it, and I won&#8217;t go so far as to claim that it shouldn&#8217;t exist or anything like that; in fact, it does very well for certain types of things.  The main thing I don&#8217;t like about it is the complexity; it&#8217;s not something that you just pick up and start using one day.  You have to do a lot of research to understand what is happening, and though I&#8217;ve been working on ActiveX Controls hosted in Internet Explorer for over a year now, there is still a lot I don&#8217;t understand about what is really happening under the covers.</p>
<p>Because of this, I am a big fan of NPAPI.  I think it&#8217;s a great technology.  It&#8217;s simple.  It&#8217;s straightforward.  It provides an interface for one purpose, and that is to allow 3rd party developers to write browser plugins.  It&#8217;s great.  But, there is a problem: in my world, you can&#8217;t just say &#8220;I like Firefox better than IE, so I&#8217;m not going to support IE.&#8221;  Why?  I will make no claims here about security, usability, viability, or even disability of any browsers.  I will simply refer to one statistic: according to the <a title="W3Schools browser stats" href="http://www.w3schools.com/browsers/browsers_stats.asp" target="_blank">w3schools browser statistics</a>, Internet Explorer accounted for over 25% of the total web traffic every month last year.</p>
<p>So we find the classic challenge of all browser plugin developers: Internet Explorer only supports ActiveX controls, other browsers support NPAPI, and a plugin written for one isn&#8217;t neccesarily going to be easy to just port to the other.  Thus was born <a title="Firebreath overview" href="http://colonelpanic.net/2009/12/firebreath-ready-for-testing/">FireBreath</a>, in an attempt to solve this issue.  Today, however, I want to address only one piece of the solution that we use in FireBreath:  How to create a scripting interface that will be &#8220;write once, run anywhere&#8221; on web browsers.</p>
<h1><span id="more-117"></span>Common Scripting Interface</h1>
<p>When I first began working on plugins, I worked on a project that had 3 seperate defintions of the javascript interface to the plugin.  One was for Mac, one for Internet Explorer on Windows, and one for Firefox on Windows.  The IE version was defined in an ActiveX .idl file and implemented in an ActiveX object.  The Firefox/win one was defined in an &#8220;XPCOM&#8221; .idl file and implemented in a nsScriptablePeer object (copied from a sample plugin from the mozilla source), and the Mac one was defined using NPRuntime and wrapped the XPCOM class.</p>
<p>This was, in short, a nightmare.</p>
<p>The problem I was initially trying to solve is that we had some APIs that had to be used differently on Mac and Windows, and they differed in less noticeable ways between Firefox and IE on Windows.  Don&#8217;t get me wrong &#8212; it all worked just fine.  However, from a maintenance point of view, this was certainly not optimal.  I could give a lot of meaningless history here, but eventually I came up with an idea that I dubbed (at that company) the Common Scripting Interface &#8212; a class that contained all the aspects that a good javascript object would need, but was not specific to any one browser.</p>
<h1>Down with the IDL</h1>
<p>Okay, this is where I&#8217;m going to start raising a lot of eyebrows.  I respectfully submit that using an IDL, as it is defined by Internet Explorer, is generally a bad idea on a control intended to be used from Javascript.  Why?  Simply put, Javascript is a dynamic language; when you pass parameters around, they are not type constrained.  Most javascript functions don&#8217;t care if you give them an integer, a string, a bool, or something else; they just use the parameters they are given.  Of course it&#8217;s a bit more complicated than that, but Javascript inherently is dynamic.  Thus, it can be important to have the ability to use a dynamic interface on a plugin that interfaces with it.</p>
<p>I hasten to remind you at this point that making an interface dynamic just for the sake of it being dynamic is a bad idea.  However, there are many use cases where you may have members (particularly properties that expose other javascript objects) that may only be named and become accessible at runtime; it&#8217;s too late to add something to the IDL.  I believe this is part of the reason that we have settled on NPRuntime on Gecko-based browsers, and Microsoft created an IDispatchEx interface to better support it on ActiveX.  Thus, we have all the tools we need to create a dynamic interface, and I have loosely patterned it after the NPAPI/NPRuntime interface, which I consider to be a fairly good interface for browser plugins.</p>
<h1>What is JSAPI?</h1>
<p>If you have looked at all at the FireBreath project that I have been working on for the last several months, you may have looked at or seen reference to the JSAPI class.  JSAPI stands for Javascript API.  JSAPI is intended to be a Javascript compatible object written in C++.  It relies heavily on the FB::variant class, which essentially is a class that you can put any datatype in.  If there is enough interest, I can blog more about that type later, but suffice it to say it&#8217;s very similar to boost::any but with data conversion tools built in.  A JSAPI object (an object that extends FB::JSAPI) provides all functionality that a Javascript object should, whether it is used or not.</p>
<h2>What does a Javascript object do?</h2>
<p>Let&#8217;s take a big step backwards now.  Forget anything you know about Browser Plugins or ActiveX Controls.  Forget anything you even know about C++, Java, C#, Logo, or any other language, even, except Javascript, HTML, DHTML, and CSS.  Those are the tools of the browser.  When we design the interface for a Browser Plugin, we shouldn&#8217;t be thinking like a C++ developer.  We should be looking at it the way we would if we were writing an object in Javascript; we should provide the interfaces that we would expect to find, and use the tools and syntax that we would expect to find in Javascript.</p>
<p>So, let&#8217;s look at what a Javascript object can do:</p>
<ul>
<li>Javascript objects can have methods that accept parameters and return a value
<ul>
<li>
<div class="wp_syntax">
<div class="code">
<pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> coolData <span style="color: #339933;">=</span> plugin.<span style="color: #660066;">doSomething</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">5</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;right now&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre>
</div>
</div>
</li>
</ul>
</li>
<li>Javascript objects can expose properties that a caller can get or set:
<ul>
<li>
<div class="wp_syntax">
<div class="code">
<pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> oldName <span style="color: #339933;">=</span> plugin.<span style="color: #000066;">name</span><span style="color: #339933;">;</span></pre>
</div>
</div>
</li>
<li>
<div class="wp_syntax">
<div class="code">
<pre class="javascript" style="font-family:monospace;">plugin.<span style="color: #000066;">name</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Some cool name&quot;</span><span style="color: #339933;">;</span></pre>
</div>
</div>
</li>
</ul>
</li>
<li>Javascript objects can provide events, to which a caller can attach an event handler in the syntax of their browser:
<ul>
<li>
<div class="wp_syntax">
<div class="code">
<pre class="javascript" style="font-family:monospace;">plugin.<span style="color: #660066;">addEventHandler</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;click&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;The user clicked on me! Ouch!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre>
</div>
</div>
</li>
<li>
<div class="wp_syntax">
<div class="code">
<pre class="javascript" style="font-family:monospace;">plugin.<span style="color: #660066;">attachEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;onclick&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;The user clicked on me! Ouch!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre>
</div>
</div>
</li>
</ul>
</li>
</ul>
<p>When you write it out like this, it doesn&#8217;t seem like much; remember, though, that a property of a javascript object could return any primitive datatype, an array, or even another javascript object, itself containing methods, properties, and events.</p>
<h2>The JSAPI Interface</h2>
<p>One additional thing to remember about a Javascript Object (now taking into account what we know about C++ as well) is that we don&#8217;t control the lifecycle of a javascript object.  What that means is that your plugin may go away before Javascript is done with the object that you gave it.  So, if that object uses any references to your plugin, (And what plugin javascript object wouldn&#8217;t? It&#8217;s the interface to the page, right?) you need to have a way to deal with not only cleaning up your object even after the plugin goes away, but making sure that the javascript object somehow finds out that the object it depends on is gone and invalidates itself in some way.  One way to do that is by using Shared pointers and Weak pointers, but that&#8217;s a topic for another day.</p>
<p>Like the NPObject and IDispatch types that provide its interface with the browser, JSAPI is reference counted, so that it will get destroyed whenever the browser.  Here are the method prototypes from JSAPI.h to satisfy the requirements mentioned above.  You can also look at <a title="JSAPI.h source" href="http://code.google.com/p/firebreath/source/browse/src/ScriptingCore/JSAPI.h" target="_blank">the full source of JSAPI.h</a> if you want.</p>
<h3>Methods</h3>
<div class="wp_syntax">
<div class="code">
<pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// ...</span>
    <span style="color: #0000ff;">virtual</span> <span style="color: #0000ff;">bool</span> HasMethod<span style="color: #008000;">&#40;</span>std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> methodName<span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">virtual</span> variant Invoke<span style="color: #008000;">&#40;</span>std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> methodName, std<span style="color: #008080;">::</span><span style="color: #007788;">vector</span><span style="color: #000040;">&amp;</span>lt<span style="color: #008080;">;</span>variant<span style="color: #000040;">&amp;</span>gt<span style="color: #008080;">;</span><span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span> args<span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #666666;">// ...</span></pre>
</div>
</div>
<p>Not much is required; one call to find out if the method exists, one to invoke the method.  Notice that the arguments is passed in a STL vector of type variant; you can pass any datatypes in here, but that will be limited by the Browser-level wrapper that converts the arguments from the browser datatype (VARIANT on IE, NPVariant on firefox) to the JSAPI variant datatype.  I&#8217;ll discuss this in more detail in a later post.</p>
<h3>Properties</h3>
<div class="wp_syntax">
<div class="code">
<pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// ...</span>
    <span style="color: #0000ff;">virtual</span> <span style="color: #0000ff;">bool</span> HasProperty<span style="color: #008000;">&#40;</span>std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> propertyName<span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">virtual</span> <span style="color: #0000ff;">bool</span> HasProperty<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> idx<span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">virtual</span> variant GetProperty<span style="color: #008000;">&#40;</span>std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> propertyName<span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">virtual</span> variant GetProperty<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> idx<span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">virtual</span> <span style="color: #0000ff;">void</span> SetProperty<span style="color: #008000;">&#40;</span>std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> propertyName, <span style="color: #0000ff;">const</span> variant value<span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">virtual</span> <span style="color: #0000ff;">void</span> SetProperty<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> idx, <span style="color: #0000ff;">const</span> variant value<span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #666666;">// ...</span></pre>
</div>
</div>
<p>You&#8217;ll notice one strange thing right off the bat here; there are two of each method.  One takes a std::string for the first parameter, one takes an int.  Any thoughts on why?</p>
<p>Imagine the following code:</p>
<div class="wp_syntax">
<div class="code">
<pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> plugin.<span style="color: #660066;">files</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>plugin.<span style="color: #660066;">files</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre>
</div>
</div>
<p>This is a pretty standard piece of javascript code, right?  Array access notation is pretty common in Javascript.  Javascript, however, treats everything as an object of one kind or another. An array to javascript is really just an object with numeric properties.  Similarly, we need to be able to support numeric properties for array style access.  That is why we have extra property methods for a property identified by an &#8220;int&#8221;.</p>
<h3>Events</h3>
<div class="wp_syntax">
<div class="code">
<pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// ...</span>
    <span style="color: #0000ff;">virtual</span> <span style="color: #0000ff;">void</span> registerEventMethod<span style="color: #008000;">&#40;</span>std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> name, BrowserObjectAPI <span style="color: #000040;">*</span>event<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">virtual</span> <span style="color: #0000ff;">void</span> unregisterEventMethod<span style="color: #008000;">&#40;</span>std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> name, BrowserObjectAPI <span style="color: #000040;">*</span>event<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">virtual</span> <span style="color: #0000ff;">void</span> registerEventInterface<span style="color: #008000;">&#40;</span>BrowserObjectAPI <span style="color: #000040;">*</span>event<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">virtual</span> <span style="color: #0000ff;">void</span> unregisterEventInterface<span style="color: #008000;">&#40;</span>BrowserObjectAPI <span style="color: #000040;">*</span>event<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">virtual</span> BrowserObjectAPI <span style="color: #000040;">*</span>getDefaultEventMethod<span style="color: #008000;">&#40;</span>std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> name<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">virtual</span> <span style="color: #0000ff;">void</span> setDefaultEventMethod<span style="color: #008000;">&#40;</span>std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> name, BrowserObjectAPI <span style="color: #000040;">*</span>event<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">protected</span><span style="color: #008080;">:</span>
    <span style="color: #666666;">// Used to fire an event to the listeners attached to this JSAPI</span>
    <span style="color: #0000ff;">virtual</span> <span style="color: #0000ff;">void</span> FireEvent<span style="color: #008000;">&#40;</span>std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> eventName, std<span style="color: #008080;">::</span><span style="color: #007788;">vector</span><span style="color: #000040;">&amp;</span>lt<span style="color: #008080;">;</span>variant<span style="color: #000040;">&amp;</span>gt<span style="color: #008080;">;</span><span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #666666;">// ...</span></pre>
</div>
</div>
<p>Events are by far the most difficult piece of this whole class; we have to make allowances for multiple methods of registering events and multiple browsers&#8217; methods for keeping track of the handlers. The BrowserObjectAPI type that you see used here is also a JSAPI object, but one that wraps a browser object (an NPObject or a IDispatch object, depending on the browser).</p>
<p>There are three different ways an event can be registered (at this point in time):</p>
<ol>
<li>Through a &#8220;user-defined&#8221; event registering method implemented by our browser scripting object wrapper (this is used by all objects on firefox and all but the root object on IE).
<ul>
<li>The BrowserObjectAPI object will essentially be a method that we can invoke by calling InvokeAsync with empty string (&#8220;&#8221;) as the method name</li>
</ul>
</li>
<li>Through the Connection Point interface on an ActiveX Control (obviously used on the root object in IE)
<ul>
<li>The BrowserObjectAPI object will be an object on which we can invoke a method of the same name as the event it is attached to</li>
</ul>
</li>
<li>Through a property of the same name as the event (old-style javascript events, as in &#8220;document.onload = &#8230;.&#8221;
<ol>
<li>The BrowserObjectAPI object will essentially be a method that we can invoke by calling InvokeAsync with empty string (&#8220;&#8221;) as the method name</li>
</ol>
</li>
</ol>
<p>These three types are the reason that we have three different register/unregister methods on the browser for events.  When FireEvent is called by the JSAPI child object (that you write), it iterates through all possible event handlers and invokes them asynchronously.  (Events have to be invoked on the main UI thread of the plugin, so the InvokeAsync call on BrowserObjectAPI automatically makes sure that is where it gets called; hence it&#8217;s async).</p>
<h1>Next time</h1>
<p>We have discussed and looked at the basic needs of the JSAPI object.  Part two will discuss the <a title="COMJavascriptObject.h source" href="http://code.google.com/p/firebreath/source/browse/src/ActiveXPlugin/COMJavascriptObject.h">COMJavascriptObject</a> class and the <a title="JSAPI_IDispatch.h source" href="http://code.google.com/p/firebreath/source/browse/src/ActiveXPlugin/JSAPI_IDispatchEx.h">JSAPI_IDispatch</a> helper class that constitute the interface between ActiveX and our JSAPI interfaces.  Part three will cover the <a title="NPJavascriptObject.h source" href="http://code.google.com/p/firebreath/source/browse/src/NpapiPlugin/NPJavascriptObject.h">NPJavascriptObject</a> that provides the interface between NPRuntime and JSAPI.  Feel free to read ahead in the source =]</p>
<p>In the mean time, if you like where this is going and want to play with FireBreath and see JSAPI in action for yourself, there are some <a title="Creating a new Plugin Project with FireBreath" href="http://code.google.com/p/firebreath/wiki/CreatingANewPluginProject">really easy getting started instructions</a> on the <a title="Firebreath project home page" href="http://code.google.com/p/firebreath/" target="_blank">FireBreath project page</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://colonelpanic.net/2009/12/cross-browser-scripting-part-one/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Firebreath ready for testing</title>
		<link>http://colonelpanic.net/2009/12/firebreath-ready-for-testing/</link>
		<comments>http://colonelpanic.net/2009/12/firebreath-ready-for-testing/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 07:24:11 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[ActiveX]]></category>
		<category><![CDATA[Browser Plugin Development]]></category>
		<category><![CDATA[NPAPI]]></category>

		<guid isPermaLink="false">http://colonelpanic.net/?p=105</guid>
		<description><![CDATA[While I'm not ready to release a "beta" version of Firebreath yet, we are getting really close.  In fact, it's close enough that anyone feeling a little adventuresome shouldn't have any trouble setting up a test plugin and testing the limits.  We only support Windows so far (sorry guys, it's the platform I know best, and it's the one my client needed first), but we support both Internet Explorer and NPAPI (Firefox, probably Chrome and Safari as well).

A brief list of supported features:]]></description>
			<content:encoded><![CDATA[<h1>The Firebreath project</h1>
<p>Update: <a href="http://colonelpanic.net/2010/09/a-year-in-the-life-of-a-plugin-project/">See what is happening with FireBreath a year later</a></p>
<p>It&#8217;s been awhile since my last post!  Rest assured, that isn&#8217;t because I have lost interest, or because there was nothing to write about; rather, I was occupied with what I considered to be more important things.  If you&#8217;re reading this, you likely have already read my previous post, &#8220;<a title="Call for Plugin Developers" href="http://colonelpanic.net/2009/09/call-for-plugin-developers/" target="_blank">Call for plugin Developers</a>.&#8221;  If you haven&#8217;t, you might want to glance over it so that you know what I&#8217;m talking about =]</p>
<p>Firebreath has been sponsored by PacketPass, Inc.  I don&#8217;t have a web address for them, but I&#8217;ll post one later if they want me to do so.  The good news about that is that it means that unlike the vast majority of new open source projects, development of Firebreath is not going to halt before there is at least some sort of a usable project.</p>
<h1><span id="more-105"></span>Who is working on it?</h1>
<p>As you might guess, despite a lot of readers and comments on my last post, relatively few people have joined our mailing list and started helping.  I want to make particular mention of Georg Fritzsche of Germany who has been invaluable to me as a sounding board, as well as come up with some really cool ideas for improving Firebreath even more.  Aside from Georg, there are several others (Don, Jarom, Ben, &#8230; ya&#8217;ll know who you are) on the mailing list who have been a bit quieter, but nonetheless have been assisting with the brainstorming, planning, and in some small ways development of the project.  This may not sound like a lot, but for a special interest project such as this, I think it&#8217;s pretty good.  Of course, we can always use more help =]</p>
<h1>Where we&#8217;re at:</h1>
<p>While I&#8217;m not ready to release a &#8220;beta&#8221; version of Firebreath yet, we are getting really close.  In fact, it&#8217;s close enough that anyone feeling a little adventuresome shouldn&#8217;t have any trouble setting up a test plugin and testing the limits.  We only support Windows so far (sorry guys, it&#8217;s the platform I know best, and it&#8217;s the one my client needed first), but we support both Internet Explorer and NPAPI (Firefox, probably Chrome and Safari as well).</p>
<p>A brief list of supported features:</p>
<ul>
<li>NPAPI (Firefox, Chrome, Safari) support</li>
<li>ActiveX/IE support</li>
<li>Unified scripting API (define your objects for javascript use in one place, they work on all browsers)</li>
<li>Easy manipulation of the DOM</li>
<li>Event firing from the plugin into Javascript</li>
<li>System event handling (mouse events wired, keyboard events can be easily)</li>
<li>Basic framework for getting the HWND so you can do your drawing (needs to be fleshed out, but usable)</li>
<li>Easy configuration of all plugin properties (such as Mime type, description, GUIDs, etc)</li>
</ul>
<h1>How to create a plugin with Firebreath</h1>
<p>If you want to play with it (and please, please, please play with it and tell us what you think), it&#8217;s not too hard to get started.  On <a title="Firebreath google code project" href="http://code.google.com/p/firebreath/">the firebreath google code page</a> we have <a title="Building Firebreath" href="http://code.google.com/p/firebreath/wiki/BuildingFireBreath">instructions on how to build it</a>, including downloading of the source.  You can find it here: <a title="Building Firebreath" href="http://code.google.com/p/firebreath/wiki/BuildingFireBreath">http://code.google.com/p/firebreath/wiki/BuildingFireBreath</a></p>
<h2>Basic steps to build:</h2>
<ul>
<li>Use Mercurial to download the source</li>
<li>Use CMake to generate the project for either VS2005 or VS2008 (prep2005.cmd or prep2008.cmd)</li>
<li>Open the generated solution file (build/Firebreath.sln) in Visual Studio and build it</li>
<li>Run regsvr32.exe on the generated .dll (build/bin/Debug/)</li>
<li>open build/projects/PluginTemplate/gen/FBControl.htm and play with it with firebug or jash</li>
</ul>
<h2>Basic steps to create your own Plugin:</h2>
<ul>
<li>Copy projects/PluginTemplate to projects/YourPlugin</li>
<li>Update pluginConfig.cmake &#8212; <em><strong>REPLACE ALL 6 GUIDs WITH YOUR OWN!</strong></em> &#8212; and set the mime type, plugin name, etc</li>
<li>Rename TemplatePlugin.cpp and .h however you want and update the files so that it is your plugin</li>
<li>Update factoryMain.cpp to create your plugin instead of TemplatePlugin</li>
<li>Update your &#8220;PluginCore&#8221; implementation (TemplatePlugin extends PluginCore) to return the correct API type by editing createJSAPI() and copying MathAPI.h and .cpp to whatever you like.</li>
<li>Update your JSAPI object (copied from MathAPI.h/.cpp) to have the methods, properties, and optionally events that you want</li>
<li>Update CMakeLists.txt to make sure it includes any files that you need</li>
<li>run prep200(?).cmd to regenerate the solution and project files</li>
<li>build your plugin, run regsvr32.exe on it, and use build/projects/YourPlugin/gen/FBControl.h for testing</li>
</ul>
<h1>How to get more involved</h1>
<p>We can use all the help we can get!  The porting effort to linux and mac shouldn&#8217;t be astronomical, but currently we have nobody to put on it at least until after 1.0 is out (RC1 planned for end of the year 2009, 1.0 planned for end of January, 2010).  There are a lot of little things that can be done by developers without a lot of plugin experience, as well as some real complex bugs and challenges that will require a bit more experience.</p>
<p>If you are interested in helping, even if just by making suggestions, asking questions, and making comments, please join the development list:</p>
<p><a title="Firebreath-dev maling list" href="http://groups.google.com/group/firebreath-dev">http://groups.google.com/group/firebreath-dev</a></p>
]]></content:encoded>
			<wfw:commentRss>http://colonelpanic.net/2009/12/firebreath-ready-for-testing/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Call for plugin Developers</title>
		<link>http://colonelpanic.net/2009/09/call-for-plugin-developers/</link>
		<comments>http://colonelpanic.net/2009/09/call-for-plugin-developers/#comments</comments>
		<pubDate>Fri, 18 Sep 2009 04:01:15 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[ActiveX]]></category>
		<category><![CDATA[Browser Plugin Development]]></category>
		<category><![CDATA[NPAPI]]></category>
		<category><![CDATA[cross-platform]]></category>
		<category><![CDATA[firebreath]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://colonelpanic.net/?p=94</guid>
		<description><![CDATA[Call for help Update: See what is happening with FireBreath a year later I hereby issue a &#8220;Call for Plugin Developers&#8221; to the readers of the site. I know we are as of yet few, but I hope that some of you may be willing to help me. I am quickly realizing that I need a [...]]]></description>
			<content:encoded><![CDATA[<h2>Call for help</h2>
<p>Update: <a href="http://colonelpanic.net/2010/09/a-year-in-the-life-of-a-plugin-project/"><strong>See what is happening with FireBreath a year later</strong></a></p>
<p>I hereby issue a &#8220;Call for Plugin Developers&#8221; to the readers of the site.  I know we are as of yet few, but I hope that some of you may be willing to help me.</p>
<p>I am quickly realizing that I need a plugin project from which I can quote source code; one that does the things that I am attempting to explain, and one that is not made up of code that is owned  by a specific company or project.</p>
<p>Thus, I introduce to you all: <a href="http://code.google.com/p/firebreath/">FireBreath</a>.</p>
<h2>FireBreath</h2>
<p>FireBreath is intended to be a cross platform browser plugin.  Currently, I plant to license this under the new BSD license.  This way, it can be used for commercial projects.  The targetted browsers are:</p>
<p><span id="more-94"></span>On windows:</p>
<ul>
<li>Microsoft Internet Explorer</li>
<li>Mozilla Firefox (3 and up; we may add support for 2.x as well)</li>
<li>Google Chrome</li>
<li>Opera</li>
<li>Apple Safari</li>
</ul>
<p>On mac:</p>
<ul>
<li>Mozilla Firefox (see above note on versions)</li>
<li>Google Chrome (when it is released)</li>
<li>Apple Safari (3.x and up, intel only for now)</li>
</ul>
<p>On linux:</p>
<ul>
<li>Anything that supports NPAPI plugins and Gecko SDK 1.9 or above (no firefox 2 for now)</li>
</ul>
<h2>What needs to be done</h2>
<p>This is an ambitious project; I can help with development, and I can coordinate tasks.  I don&#8217;t have time to do it all myself, however, unless a company sponsers me; there is one that has shown interest so far, but nothing is certain.  Even if that happens, and a company wants this project enough to pay me to develop it, it will be far more successful if there are other contributors &#8212; you see, I don&#8217;t know everything.</p>
<p>In particular, I could really use a &#8220;strong right hand&#8221; who would be willing to head up the linux-specific part of the development, which despite 10+ years of linux experience is still my weakest point.  If there are others who wish to take ownership of other parts, that would also be great; for now, I will retain the final say on what goes in, because, well, I can.</p>
<p>If you look, you&#8217;ll find that there is no code up on the repository as of yet (at least, as of the time of this writing.)  I just started an ActiveX control this evening with the intent to implement FBControl, the ActiveX control portion of FireBreath.  As soon as I have a rough skeleton ActiveX control project done (which will happen sooner if I get a lot of developers wanting to help), I will start on the NPAPI portion of the DLL.  Even before I have that done, there are several small, relatively simple tasks that I could use help with.  In particular, I will not be using any code directly from the mozilla source tree and the plugin samples, so I need someone to write from scratch the NPN_ wrappers for all of the browser functions.</p>
<h2>How you can help</h2>
<p>For this project to succeed, we need all the help we can get.  If you would like to help, please send me an email at taxilian@gmail.com and introduce yourself.  Tell me:</p>
<ul>
<li>Who you are</li>
<li>What you consider your strengths in this area are</li>
<li>What interests you most about this project</li>
<li>How you want to use FireBreath yourself (if at all)</li>
<li>How much time you may be able to put in</li>
</ul>
<p>I&#8217;ll take nearly anyone right now, though I will be carefully monitoring the code submissions to start out with; my project goals are:</p>
<ul>
<li>Reusable and modular</li>
<li>Cross-platform (both in the browser sense and the operating system sense)</li>
<li>Cleanly written</li>
<li>Free and useful</li>
</ul>
<p>I by no means want to be a dictator on this; I welcome help and suggestions from everyone.</p>
<p>Thanks!</p>
]]></content:encoded>
			<wfw:commentRss>http://colonelpanic.net/2009/09/call-for-plugin-developers/feed/</wfw:commentRss>
		<slash:comments>53</slash:comments>
		</item>
		<item>
		<title>Detecting the version of an ActiveX IE Browser plugin – Part Two</title>
		<link>http://colonelpanic.net/2009/01/detecting-the-version-of-an-activex-ie-browser-plugin-part-two/</link>
		<comments>http://colonelpanic.net/2009/01/detecting-the-version-of-an-activex-ie-browser-plugin-part-two/#comments</comments>
		<pubDate>Thu, 08 Jan 2009 02:30:40 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[ActiveX]]></category>
		<category><![CDATA[Browser Plugin Development]]></category>
		<category><![CDATA[internet explorer]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://colonelpanic.net/?p=33</guid>
		<description><![CDATA[Note: if you haven&#8217;t already, please read up on FireBreath, the open source cross-platform plugin framework, and consider contributing. Update Last time, in Detecting the version of an ActiveX IE Browser plugin part one, I discussed the ToString() method of an ActiveX object, and how it is called when an ActiveX object is instantiated from [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Note: </strong>if you haven&#8217;t already, please read up on <a title="FireBreath explanation" href="../2009/09/call-for-plugin-developers/" target="_blank">FireBreath, the open source cross-platform plugin framework</a>, and consider contributing.</p>
<h4>Update</h4>
<p>Last time, in <a title="Detecting the version of an ActiveX IE Browser plugin" href="http://colonelpanic.net/2009/01/detecting-the-version-of-an-activex-ie-browser-plugin/" target="_blank">Detecting the version of an ActiveX IE Browser plugin part one</a>, I discussed the ToString() method of an ActiveX object, and how it is called when an ActiveX object is instantiated from javascript with the syntax:</p>
<pre>var object = new ActiveXObject("PART1.PART2");</pre>
<p>If you read my <a title="Detecting the version of an ActiveX IE Browser plugin" href="http://colonelpanic.net/2009/01/detecting-the-version-of-an-activex-ie-browser-plugin/" target="_blank">last post</a>, then you will remember that if you don&#8217;t implement this function, you get the following message:</p>
<pre>Object doesn't support this property or method</pre>
<p><span id="more-33"></span><br />
During my testing before, I had incorrectly assumed that this prevented the object from being instantiated.  However, all it really does is instantiates the object and then throws an exception.  So, you actually could, if you wanted, catch that exception and then check the error message.</p>
<h4>Writing the code</h4>
<p>So, if we wanted to write a function that would notify us when the plugin was installed, all we need to do is try this repeatedly until it works; however, we don&#8217;t want to overload the browser, so a <span style="color: #800080;">setInterval</span> or <span style="color: #800080;">setTimeout</span> would probably be appropriate.</p>
<p>Here is a function that I threw together that is similar to the one that I wrote for work.  I haven&#8217;t tested it, but I have tested the one I use at work, and they are pretty similar in all functional aspects, so it&#8217;ll probably work.</p>
<div class="wp_syntax">
<div class="code">
<pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>ColonelPanic<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> ColonelPanic <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
ColonelPanic.<span style="color: #660066;">ActiveXIdentifier</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;ColonelPanic.AwesomePlugin&quot;</span><span style="color: #339933;">;</span>
&nbsp;
ColonelPanic.<span style="color: #660066;">WaitForActiveXPlugin</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>callback<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> plugin<span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> ActiveXObject<span style="color: #009900;">&#40;</span>ColonelPanic.<span style="color: #660066;">ActiveXIdentifier</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            callback<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// You could change this to pass back a version number</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">message</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;Object doesn't support this property or method&quot;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            callback<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// it created it, but doesn't support .ToString()</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    setTimeout<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> ColonelPanic.<span style="color: #660066;">WaitForActiveXPlugin</span><span style="color: #009900;">&#40;</span>callback<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">300</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre>
</div>
</div>
<h4>Making it cross-platform</h4>
<p>Now, if you are like me, you don&#8217;t want your plugin to work on just one browser; so, we&#8217;ll make another function that will detect what plugin type is supported and call the correct function.  We&#8217;ll save the plugin detection function for NPAPI (firefox) type plugins for another post &#8212; I have a lot to write about NPAPI plugins.</p>
<div class="wp_syntax">
<div class="code">
<pre class="javascript" style="font-family:monospace;">ColonelPanic.<span style="color: #660066;">WaitForPluginInstall</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>callback<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span><span style="color: #009900;">&#40;</span>ActiveXObject<span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #3366CC;">&quot;undefined&quot;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">// Internet Explorer</span>
        ColonelPanic.<span style="color: #660066;">WaitForActiveXPlugin</span><span style="color: #009900;">&#40;</span>callback<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">else</span>
    <span style="color: #009900;">&#123;</span>   <span style="color: #006600; font-style: italic;">// other (firefox, safari, opera, chrome, etc)</span>
        ColonelPanic.<span style="color: #660066;">WaitForNPAPIPlugin</span><span style="color: #009900;">&#40;</span>callback<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre>
</div>
</div>
<p>Now, there is still one last task &#8212; we need a way of determining the actual version in case the plugin has updated since we last restarted the browser, to facilitate background updates.  That will probably be my next topic =]</p>
]]></content:encoded>
			<wfw:commentRss>http://colonelpanic.net/2009/01/detecting-the-version-of-an-activex-ie-browser-plugin-part-two/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Detecting the version of an ActiveX IE Browser plugin</title>
		<link>http://colonelpanic.net/2009/01/detecting-the-version-of-an-activex-ie-browser-plugin/</link>
		<comments>http://colonelpanic.net/2009/01/detecting-the-version-of-an-activex-ie-browser-plugin/#comments</comments>
		<pubDate>Tue, 06 Jan 2009 23:19:13 +0000</pubDate>
		<dc:creator>Richard</dc:creator>
				<category><![CDATA[ActiveX]]></category>
		<category><![CDATA[Browser Plugin Development]]></category>
		<category><![CDATA[browser plugin]]></category>
		<category><![CDATA[internet explorer]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://colonelpanic.net/?p=4</guid>
		<description><![CDATA[One of the trickiest tasks with any browser plugin is to detect if the installed plugin is the version that you need.  This is made particularly difficult because there are multiple browsers and multiple browser types.  During my research I looked over the default installer that Microsoft ships with Silverlight and found a very simple solution to the Internet Explorer half of this problem.]]></description>
			<content:encoded><![CDATA[<p><strong>Update: </strong>if you haven&#8217;t already, please read up on <a title="FireBreath explanation" href="../2009/09/call-for-plugin-developers/" target="_blank">FireBreath, the open source cross-platform plugin framework</a>, and consider contributing.</p>
<h4>Blog site up</h4>
<p>Well, ColonelPanic.net is up and running, and I guess that means it&#8217;s time to start posting!  The primary intent of this blog is to provide a place to post solutions to development and technical problems that we have been able to find only after a lot of research and testing on our own.  <a title="Google" href="http://www.google.com" target="_blank">Google</a> is a wonderfully useful tool for developers, but it doesn&#8217;t seem to do very well at producing information that hasn&#8217;t been written.  So, while we wait for the google engineers to correct this oversight, we decided we needed to take action to at least make sure that our hard-earned knowledge isn&#8217;t totally lost.</p>
<h4>What got me started</h4>
<p>So, as part of my gainful employment this week I have been working at improving our browser plugin install methods.  <a title="Move Networks" href="http://www.movenetworks.com" target="_blank">Move Networks</a> has the most impressive online video player that I have ever come across (which is basically why I decided to work for them), but there are always things that can be improved with any system.  Recently my task has been to streamline our install process.</p>
<p>One of these days I will post details on how we have combined our (IE) ActiveX control with our (firefox) NPAPI plugin in the same DLL, but that will need to be the topic of a different post.</p>
<h4>Finding a solution to a problem</h4>
<p><span id="more-4"></span>One of the trickiest tasks with any browser plugin is to detect if the installed plugin is the version that you need.  This is made particularly difficult because there are multiple browsers and multiple browser types.  During my research I looked over the default installer that Microsoft ships with <a title="Microsoft Silverlight" href="http://www.silverlight.net" target="_blank">Silverlight</a> and found a very simple solution to the Internet Explorer half of this problem.  Essentially, the packaged <a title="silverlight.js" href="http://go.microsoft.com/fwlink/?LinkId=128160" target="_blank">silverlight.js</a> file instantiates the ActiveX control using javascript and then calls a method to verify the version:</p>
<div class="wp_syntax">
<div class="code">
<pre class="javascript" style="font-family:monospace;">control <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> ActiveXObject<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'AgControl.AgControl'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> version <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    isVersionSupported <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> control.<span style="color: #660066;">IsVersionSupported</span><span style="color: #009900;">&#40;</span>version<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    isVersionSupported <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
control <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span></pre>
</div>
</div>
<p>In this example, version is passed into the function and indicates the lowest allowed version of Silverlight.  In our plugin, we want to do something similar &#8212; except in our case, we wanted to be able to just get the actual version.</p>
<h4>How it works</h4>
<p>So, the first question that we need to answer is: How does internet explorer know which ActiveX control we&#8217;re referring to with<strong> &#8220;<span style="color: #000080;">new</span></strong> <strong>ActiveXObject</strong>(&#8216;<span style="color: #008080;">AgControl.AgControl</span>&#8216;);&#8221;?  Well, as it turns out, this can be configured in the system registry.  <a title="How to Register an ActiveX Object as the Player for a Media Type" href="http://msdn.microsoft.com/en-us/library/aa751976(VS.85).aspx" target="_blank">I found some documentation in the MSDN</a> that covered several topics, including this one.  Essentially, there are two locations in the registry where an ActiveX control can be assigned to a &#8220;&lt;Major&gt;.&lt;Minor&gt;&#8221; name:</p>
<ol>
<li>[HKEY_CURRENT_USER\Software\Classes]</li>
<li>[HKEY_LOCAL_MACHINE\Software\Classes]</li>
</ol>
<p>If you want to register this for the whole system, then put it in <strong>HKEY_LOCAL_MACHINE</strong>.  Otherwise, put it in <strong>HKEY_CURRENT_USER</strong>, which can be written to without having administrator privileges.  The <strong>HKEY_CLASSES_ROOT </strong>key shows a combination of the two; a key that exists in both will be taken from <strong>HKEY_CURRENT_USER</strong>.  <a title="HKEY_CLASSES_ROOT" href="http://technet.microsoft.com/en-us/library/cc739822.aspx" target="_blank">See this explanation from the MSDN for more info.</a></p>
<h4>Implementation problems</h4>
<p>Armed with this understanding, I set out to make it work with our ActiveX plugin.  I set up the registry keys, opened <a title="Javascript Shell" href="http://billyreisinger.com/jash/">Jash</a>, my favorate javascript debugging tool, and tried creating my plugin:</p>
<div class="wp_syntax">
<div class="code">
<pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;&amp;</span>gt<span style="color: #339933;">;</span> control <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> ActiveXObject<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;QSP2IE.QSP2IE&quot;</span><span style="color: #009900;">&#41;</span>
Object doesn`t support <span style="color: #000066; font-weight: bold;">this</span> property or method</pre>
</div>
</div>
<p>That&#8217;s not real helpful!  ActiveXObject patently does support creating instances of an activeX object; my plugin is, indeed, registered under that name!  Why isn&#8217;t it working?  Well, that took some debugging.  I ended up creating my own method for the <strong>GetIDsOfNames</strong> method of the <a title="IDispatch" href="http://msdn.microsoft.com/en-us/library/ms221608.aspx" target="_blank">IDispatch Interface</a> that ActiveX uses to expose members to the browser.  As it turns out, creating an ActiveX Object instance in this way calls the <strong>ToString()</strong> method on the plugin.  <strong>Gah! </strong>I haven&#8217;t found this documented anywhere (if you find it, please post a link), but I added it to the IDL of my plugin anyway.</p>
<div class="wp_syntax">
<div class="code">
<pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;&amp;</span>gt<span style="color: #339933;">;</span> control <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> ActiveXObject<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;QSP2IE.QSP2IE&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #3366CC;">&quot;071300000030&quot;</span></pre>
</div>
</div>
<p>Success! It works!  Since my implementation of the ToString() method simply returns the version string, <a title="Javascript Shell" href="http://billyreisinger.com/jash/">Jash</a> shows me the output when it first creates the object.</p>
<p>The one downside so far is that if you update the DLL file while IE is still open, calling new ActiveXObject() again doesn&#8217;t get the new plugin version. This might end up being a showstopper for me!  We&#8217;ll see how it turns out.</p>
]]></content:encoded>
			<wfw:commentRss>http://colonelpanic.net/2009/01/detecting-the-version-of-an-activex-ie-browser-plugin/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
	</channel>
</rss>

