Qondio
Front
Intel
IntelMart
Shares
My Qondio
Account
frenstemichele > Intel > xssinterface and Google Gears

qondio.com/WCuG PRINT EMAIL

xssinterface and Google Gears

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 “It would be nice if the library used cross domain workers if Gears is installed.” than Melde comments “Thanks for the hint to google gears.


It is now implemented in trunk :)”. How about that for service!
Below is his first version that uses cross domain workerpools and the database to keep a message queue going. Very nice!

var wp = google.gears.workerPool;
wp.allowCrossOrigin();
wp.onmessage = function(a, b, message) {
var origin = new String(message.origin);
var parts = origin.split("/");
var domain = parts[2];
parts = domain.split(":"); // remove port
domain = parts[0];

var recipient = domain;
var channelId = message.text;


var db = google.gears.factory.create('beta.database');
db.open('database-xssinterface');
db.execute('create table if not exists XSSMessageQueue' +
' (id INTEGER PRIMARY KEY AUTOINCREMENT, recipient_domain TEXT, channel_id TEXT, message TEXT, insert_time INTEGER)');

// delete (and thus ignore) old messages
var maxAge = new Date().getTime() - 2000;
db.execute('delete from XSSMessageQueue where insert_time < ?',[maxAge]);

// find new messages for me
var rs = db.execute('select id, message from XSSMessageQueue where recipient_domain = ? and channel_id = ?', [recipient, channelId]);

// there is a new message for the recipient
if (rs.isValidRow()) {
var id = rs.field(0);
var text = rs.field(1);
db.execute("DELETE from XSSMessageQueue where id=?", [id]); // unqueue message
wp.sendMessage(text, message.sender)
}

rs.close();
}

Contributed by frenstemichele on April 3, 2008, at 3:34 AM UTC.

Reactions

No reactions yet.

Rate This Intel

Please login or sign up to rate this intel.

Comments

Please login or sign up to add a comment.

Share

Copyright Notice

The copyright for this content entitled "xssinterface and Google Gears" has been specified by the contributor as:

All Rights Reserved

This content may not be copied, distributed or adapted by anyone under any circumstances.

Login Here with
Any Email Address
Any Password
No account? Sign up.

Intel Contributor
This intel was contributed by frenstemichele

Qondio Archive
May, 2012
123456
78910111213
14151617181920
21222324252627
28293031


2008
January, February, March, April, May, June, July, August, September, October, November, December
2009
January, February, March, April, May, June, July, August, September, October, November, December
2010
January, February, March, April, May, June, July, August, September, October, November, December
2011
January, February, March, April, May, June, July, August, September, October, November, December
2012
January, February, March, April, May

Sign Up
Not a member yet? Qondio is a powerful network for making it online. If you have a website to promote, we can help. Sign up and get in on the action.

About Qondio
Welcome to Qondio! Discover the awesome power this network can deliver by going to our About page. Or you could skip straight to the Sign Up form.

ABOUT
SUCCESS GUIDE
FEATURES
FAQ
ADVERTISE
CONTACT
USAGE POLICY
PRIVACY POLICY


TWITTER
FACEBOOK