Till Vollmer Geschäftsführer MindMeister
Was ist Google Gears? Browser Plugin Lokale Datenbank Lokaler Store (urls) Tools Klassen JavaScript Library Aktuelle Version (1.6.08 : V 0.3.X)
Plugin für? Windows Windows XP/Vista Firefox 1.5+ and Internet Explorer 6.0+ Mac OS X Mac OS X 10.4+ Firefox 1.5+ Linux Linux Firefox 1.5+ 32-bit processor (64-bit not supported)
Klassenarchitektur JS Factory Daten Database URL Inhalte LocalServer Tools Timer ResultSet ManagedResourceStore WorkerPool ResourceStore Desktop FileSubmitter HTTPRequest
Initialisierung/Instanz <script src="gears_init.js"></script> <script> if (!window.google!google.gears) { location.href = "http://gears.google.com/? action=install&message=<your welcome message>" + "&return=<your website url>"; } </script>
gears_init.js (function() { if (window.google && google.gears) { return; } var factory = null; if (typeof GearsFactory!= 'undefined') { factory = new GearsFactory(); } else { try { factory = new ActiveXObject('Gears.Factory'); if (factory.getbuildinfo().indexof('ie_mobile')!= -1) { factory.privatesetglobalobject(this); } } catch (e) { if ((typeof navigator.mimetypes!= 'undefined') && navigator.mimetypes["application/x-googlegears"]) { factory = document.createelement("object"); factory.style.display = "none"; factory.width = 0; factory.height = 0; factory.type = "application/x-googlegears"; document.documentelement.appendchild(factory); } } } if (!factory) { return; } if (!window.google) { google = {}; } if (!google.gears) { google.gears = {factory: factory}; } })();
Factory Factory class Object create(classname, classversion) string getbuildinfo() readonly attribute string version Beispiel: var db = google.gears.factory.create('beta.database'); db.open('database-test'); classname beta.database beta.httprequest beta.localserver beta.timer beta.workerpool Google Gears class created Database HttpRequest LocalServer Timer WorkerPool
Database Database class void open([name]) ResultSet execute(sqlstatement, [argarray]) void close() readonly attribute int lastinsertrowid ResultSet class boolean isvalidrow() void next() void close() int fieldcount() string fieldname(int fieldindex) variant field(int fieldindex) variant fieldbyname(string fieldname)
Database Beispiel var db = google.gears.factory.create('beta.database'); db.open('database-test'); db.execute('create table if not exists Test' + ' (Phrase text, Timestamp int)'); db.execute('insert into Test values (?,?)', ['Monkey!', new Date().getTime()]); var rs = db.execute('select * from Test order by Timestamp desc'); while (rs.isvalidrow()) { alert(rs.field(0) + '@' + rs.field(1)); rs.next(); } rs.close();
Database Bemerkungen SQLite Volltext Suche Transaktionen (begin, commit) Execute can fail (retry?) db.execute('begin'); db.execute('insert INTO recipe_aux (dish, rating) VALUES (?,?)', ['soup', 3]); db.execute('insert INTO recipe (rowid, dish, ingredients) ' + 'VALUES (last_insert_rowid(),?,?)', ['soup', 'meat carrots celery noodles']); db.execute('commit');
Stores ManagedResourceStore URL zu einem Manifest Manifest sagt was geholt wird ResourceStore On the fly store Dynamische Sachen Achtung: ist ein Store "enabled" so liefert Gears auch bei aktivem Netzwerk alles aus dem Store
LocalServer LocalServer class boolean canservelocally(string url) ResourceStore createstore(string name,...) ResourceStore openstore(string name,...) void removestore(string name,...) ManagedResourceStore createmanagedstore(string name,...) ManagedResourceStore openmanagedstore(string name,...) void removemanagedstore(string name,...)
ManagedResourceStore ManagedResourceStore class readonly attribute string name readonly attribute string requiredcookie readwrite attribute boolean enabled readwrite attribute string manifesturl readonly attribute int lastupdatechecktime readonly attribute int updatestatus readonly attribute string lasterrormessage readonly attribute string currentversion event void oncomplete(object details) event void onerror(error error) event void onprogress(object details) void checkforupdate()
ResourceStore ResourceStore class readonly attribute string name readonly attribute string requiredcookie readwrite attribute boolean enabled int capture(string urlorurlarray,completioncallback) void abortcapture(int captureid) void remove(string url) void rename(string srcurl, string desturl) void copy(string srcurl, string desturl) boolean iscaptured(string url) void capturefile(fileinputelement, url) string getcapturedfilename(url) string getheader(string url, string name) string getallheaders(string url) FileSubmitter createfilesubmitter()
Manifest Beispiel { // version of the manifest file format "betamanifestversion": 1, // version of the set of resources described in this manifest file "version": "my_version_string", // optional // If the store specifies a requiredcookie, when a request would hit // an entry contained in the manifest except the requiredcookie is // not present, the local server responds with a redirect to this URL. "redirecturl": "login.html", } // URLs to be cached (URLs are given relative to the manifest URL) "entries": [ { "url": "main.html", "src": "main_offline.html" }, { "url": ".", "redirect": "main.html" }, { "url": "main.js" } { "url": "formhandler.html", "ignorequery": true }, ]
Beispiel Store var localserver=google.gears.factory.create('beta.localserver'); var store=localserver.createmanagedstore('test-store'); store.manifesturl='site-manifest.txt'; store.checkforupdate(); // site-manifest.txt { "betamanifestversion": 1, "version": "site_version_string", "entries": [ { "url": "site.html" }, { "url": "gears_init.js" } ] }
WorkerPool Eigener "Thread" UI Thread wird nicht gestört (längere Tasks) Kein DOM im Worker (window, document) Kein XMLHttpRequest, settimeout Extra Klassen Code isolation, aber Parent/Child Messaging Same origin policy (kann überschrieben werden)
Workerpool WorkerPool class callback onmessage(messagetext, senderid, [messageobject: {text,sender,origin}]) callback onerror(errorobject:{message}) int createworker(scripttext) int createworkerfromurl(scripturl) void sendmessage(messagetext, destworkerid) void allowcrossorigin()
WorkerPool Beispiel // main.js var workerpool = google.gears.factory.create('beta.workerpool'); workerpool.onmessage = function(a, b, message) { alert('received message from worker ' + message.sender + ': ' + message.text); }; var childworkerid = workerpool.createworkerfromurl('worker.js'); workerpool.sendmessage('hello, world!', childworkerid); // worker.js var wp = google.gears.workerpool; wp.onmessage = function(a, b, message) { wp.sendmessage('received: ' + message.text, message.sender); }
HTTPRequest HttpRequest class void open(method, url) void setrequestheader(name, value) void send([postdata]) void abort() string getresponseheader(name) string getallresponseheaders() callback onreadystatechange readonly attribute int readystate readonly attribute string responsetext readonly attribute int status readonly attribute string statustext var request = google.gears.factory.create('beta.httprequest'); request.open('get', '/index.html'); request.onreadystatechange = function() { if (request.readystate == 4) { console.write(request.responsetext); }}; request.send();
Timer Timer class int settimeout(fullscript, msecdelay) int settimeout(function, msecdelay) int setinterval(fullscript, msecdelay) int setinterval(function, msecdelay) void cleartimeout(timerid) void clearinterval(timerid) var timer = google.gears.factory.create('beta.timer'); timer.settimeout(function() { alert('hello, from the future!'); }, 1000);
Desktop Desktop class bool createshortcut(name, url, icons, [description]) var desktop = google.gears.factory.create('beta.desktop'); desktop.createshortcut("test Application", "http://example.com/index.html", {"128x128": "http://example.com/icon128x128.png", "48x48": "http://example.com/icon48x48.png", "32x32": "http://example.com/icon32x32.png", "16x16": "http://example.com/icon16x16.png"}, "An application at http://example.com/index.html");
Applikationsarchitektur Source: Google
Applikationsarchitektur Source: Google
Applikationsarchitektur Source: Google
Applikationsarchitektur Source: Google
Applikationsarchitektur Source: Google
Modal vs. modeless Modal Benutzer "switched" zwischen online/ offline Plötzlicher Ausfall des Netzes, geht nicht Modeless Komplexer zu implementieren Hintergrundsynchronisation CPU Zeit?
Gears on Rails Einfaches Plugin Transformation von controller actions -> JS JSON responses http://code.google.com/p/gearsonrails
Bemerkungen SQL Injection Stores (enabled?) https/http
Zukunft Firefox 3 Safari Internet Explorer? HTML 5 spec
Infos http://code.google.com/apis/gears http://code.google.com/p/gearsonrails BTW: We are hiring!!!! See http://www.mindmeister.com/home/jobs
Vielen Dank!