<?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>techno.blog(&#34;Dion&#34;) &#187; xssinterface</title>
	<atom:link href="http://almaer.com/blog/tag/xssinterface/feed" rel="self" type="application/rss+xml" />
	<link>http://almaer.com/blog</link>
	<description>blogging about life, the universe, and everything tech</description>
	<lastBuildDate>Tue, 03 Jan 2012 19:27:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>xssinterface and Google Gears</title>
		<link>http://almaer.com/blog/xssinterface-and-google-gears</link>
		<comments>http://almaer.com/blog/xssinterface-and-google-gears#comments</comments>
		<pubDate>Mon, 03 Mar 2008 15:30:29 +0000</pubDate>
		<dc:creator>dion</dc:creator>
				<category><![CDATA[Gears]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[xssinterface]]></category>

		<guid isPermaLink="false">http://almaer.com/blog/xssinterface-and-google-gears</guid>
		<description><![CDATA[I mentioned the cross domain library, xssinterface, created by Malte Ubl on Ajaxian the other day.
His library abstracts on top of postMessage() and browser hacks to give you cross domain work. No sooner than I say &#8220;It would be nice if the library used cross domain workers if Gears is installed.&#8221; than Melde comments &#8220;Thanks [...]]]></description>
			<content:encoded><![CDATA[<p>I mentioned the cross domain library, <a href="http://code.google.com/p/xssinterface/">xssinterface</a>, created by Malte Ubl <a href="http://ajaxian.com/archives/xssinterface-cross-domain-access-using-postmessage-and-more">on Ajaxian</a> the other day.</p>
<p>His library abstracts on top of postMessage() and browser hacks to give you cross domain work. No sooner than I say &#8220;It would be nice if the library used <a href="http://code.google.com/apis/gears/api_workerpool.html">cross domain workers</a> if Gears is installed.&#8221; than Melde comments &#8220;Thanks for the hint to google gears. It is now implemented in trunk :)&#8221;. How about that for service!</p>
<p>Below is his first version that uses cross domain workerpools and the database to keep a message queue going. Very nice!</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> wp       <span style="color: #339933;">=</span> google.<span style="color: #660066;">gears</span>.<span style="color: #660066;">workerPool</span><span style="color: #339933;">;</span>
wp.<span style="color: #660066;">allowCrossOrigin</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
wp.<span style="color: #660066;">onmessage</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span> b<span style="color: #339933;">,</span> message<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>  
  <span style="color: #003366; font-weight: bold;">var</span> origin <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> String<span style="color: #009900;">&#40;</span>message.<span style="color: #660066;">origin</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> parts  <span style="color: #339933;">=</span> origin.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;/&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> domain <span style="color: #339933;">=</span> parts<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  parts      <span style="color: #339933;">=</span> domain.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;:&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// remove port</span>
  domain     <span style="color: #339933;">=</span> parts<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #003366; font-weight: bold;">var</span> recipient <span style="color: #339933;">=</span> domain<span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> channelId <span style="color: #339933;">=</span> message.<span style="color: #660066;">text</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
  <span style="color: #003366; font-weight: bold;">var</span> db <span style="color: #339933;">=</span> google.<span style="color: #660066;">gears</span>.<span style="color: #660066;">factory</span>.<span style="color: #660066;">create</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'beta.database'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  db.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'database-xssinterface'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  db.<span style="color: #660066;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'create table if not exists XSSMessageQueue'</span> <span style="color: #339933;">+</span>
     <span style="color: #3366CC;">' (id INTEGER PRIMARY KEY AUTOINCREMENT, recipient_domain TEXT, channel_id TEXT, message TEXT, insert_time INTEGER)'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// delete (and thus ignore) old messages</span>
  <span style="color: #003366; font-weight: bold;">var</span> maxAge <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #CC0000;">2000</span><span style="color: #339933;">;</span>
  db.<span style="color: #660066;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'delete from XSSMessageQueue where insert_time &lt; ?'</span><span style="color: #339933;">,</span><span style="color: #009900;">&#91;</span>maxAge<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// find new messages for me</span>
  <span style="color: #003366; font-weight: bold;">var</span> rs <span style="color: #339933;">=</span> db.<span style="color: #660066;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'select id, message from XSSMessageQueue where recipient_domain = ? and channel_id = ?'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span>recipient<span style="color: #339933;">,</span> channelId<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// there is a new message for the recipient</span>
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>rs.<span style="color: #660066;">isValidRow</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #003366; font-weight: bold;">var</span> id   <span style="color: #339933;">=</span> rs.<span style="color: #660066;">field</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #003366; font-weight: bold;">var</span> text <span style="color: #339933;">=</span> rs.<span style="color: #660066;">field</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          db.<span style="color: #660066;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;DELETE from XSSMessageQueue where id=?&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span>id<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// unqueue message</span>
          wp.<span style="color: #660066;">sendMessage</span><span style="color: #009900;">&#40;</span>text<span style="color: #339933;">,</span> message.<span style="color: #660066;">sender</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  rs.<span style="color: #000066;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://almaer.com/blog/xssinterface-and-google-gears/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

