Bridging the GAP

so how does this really work?

iPhone bridge

gap://class.method/options

phonegap.js
    PhoneGap.exec("Location.start", args);
Location.h
- (void)start:(NSMutableArray*)arguments
     withDict:(NSMutableDictionary*)options;

iPhone bridge

and back…
Location.h
  NSString * jsCallBack =
   [NSString stringWithFormat:
   @"navigator.geolocation.setLocation({ timestamp: %d, %@ });", 
   epoch, 
   coords];
  [webView stringByEvaluatingJavaScriptFromString:jsCallBack];
phonegap.js
Geolocation.prototype.setLocation = function(position) {
    this.lastPosition = position;
    for (var i = 0; i < this.callbacks.onLocationChanged.length; i++) {
        var f = this.callbacks.onLocationChanged.shift();
        f(position);
    }
};

Android 101

No really, Line 101.
DroidGap.java
gap = new PhoneGap(this, appView);
geo = new GeoBroker(appView, this);
accel = new AccelListener(this, appView);

// This creates the new javascript interfaces for PhoneGap
appView.addJavascriptInterface(gap, "Device");
appView.addJavascriptInterface(geo, "Geo");
appView.addJavascriptInterface(accel, "Accel");

more Droid

GeoListener.java
  mAppView.loadUrl("
  javascript:Geolocation.gotCurrentPosition(" + loc.getLatitude() + ", " + loc.getLongitude() + ")
  ");
phonegap.js
Geolocation.gotCurrentPosition = function(lat, lng) {

  if (lat == "undefined" || lng == "undefined") {
    this.fail();
  } else {
    p = {};
    p.latitude = lat;
    p.longitude = lng;
    this.global_success(p);
  }
}

BlackBerry

BlackBerry

in device.js
exec: function(command, params, sync) {
    if (Device.available || command == "initialize") {
        try {
            var url = "gap://" + command;
            if (params) url += "/" + params.join("/");
            document.location = url;
        } catch(e) { ... }
    }
},
out device.js
poll: function(callback) {
	eval(document.cookie + (callback ? ";callback();" : ""));
},

BlackBerry

phonegap.java
public String getHTTPCookie(String url) {
	StringBuffer responseCode = new StringBuffer();
	synchronized (pendingResponses) {
		for (int index = 0; index < pendingResponses.size(); index++)
			responseCode.append(pendingResponses.elementAt(index));
		pendingResponses.removeAllElements();
	}
	return responseCode.toString();
}
Browser Field 2
CSS3 / DOM2

Everyhting else…

PalmPre / Nokia / WinMO








Coming soon…

Extend