166
edits
Line 220: | Line 220: | ||
Das mag sowohl für die Anwender, als auch für die Entwickler recht bequem sein, jedoch eröffnet sich hier auch ein weiteres Sicherheitsrisiko. Nur weil zu einem bestimmten Zeitpunkt ein Kommando als sicher eingestuft worden ist, heisst das nicht, dass es in Zukunft auch sicher bleibt. Aus diesem Grund müssen wir dafür sorgen, dass das Sicherheits-Netzwerk solche Änderungen in einer Änderungshistorie protokolliert und die Anwender benachrichtigt, sobald ein Kommando unsicher geworden ist. | Das mag sowohl für die Anwender, als auch für die Entwickler recht bequem sein, jedoch eröffnet sich hier auch ein weiteres Sicherheitsrisiko. Nur weil zu einem bestimmten Zeitpunkt ein Kommando als sicher eingestuft worden ist, heisst das nicht, dass es in Zukunft auch sicher bleibt. Aus diesem Grund müssen wir dafür sorgen, dass das Sicherheits-Netzwerk solche Änderungen in einer Änderungshistorie protokolliert und die Anwender benachrichtigt, sobald ein Kommando unsicher geworden ist. | ||
== Map Me! Location, Snapshots, and Inserting HTML == | |||
The "map" command that comes with Ubiquity is fairly powerful. It's also fairly complicated—well, comparatively. It's still only a couple hundred lines of code. The command, though, can get even more useful. Imagine being able to select some houses on Craigslist, or a list of restaurant names, and Ubiq "map these" to get just the map you want. The concept of "these" puts the power of mashups into the users hands. But I digress. Let's make a simple command that inserts a map of your current location. | |||
In this command, we use the Google [http://code.google.com/apis/maps/documentation/staticmaps/ static map API] and the Ubiquity function <code>CmdUtils.getGeoLocation()</code> to insert a map of your current location. Ubiquity currently uses the [http://www.maxmind.com/app/api MaxMind] API for trying to guess your location from your IP. That will probably change in the future. | |||
<pre> | |||
CmdUtils.CreateCommand({ | |||
name: "map-me", | |||
_getMapUrl: function() { | |||
var loc = CmdUtils.getGeoLocation(); | |||
var mapUrl = "http://maps.google.com/staticmap?"; | |||
var params = { | |||
center: loc.lat + "," + loc.long, | |||
size: "500x400", | |||
zoom: 14, | |||
key: "ABQIAAAAGZ11mh1LzgQ8-8LRW3wEShQeSuJunOpTb3RsLsk00-MAdzxmXhQoiCd940lo0KlfQM5PeNYEPLW-3w" | |||
}; | |||
return mapUrl + jQuery.param( params ); | |||
}, | |||
preview: function( pblock ) { | |||
var msg = "Inserts a map of your current location: <br/>"; | |||
msg += "<img src='%s'/>".replace( /%s/, this._getMapUrl() ); | |||
pblock.innerHTML = msg; | |||
}, | |||
execute: function( ) { | |||
CmdUtils.getImageSnapshot( this._getMapUrl(), function(imgData) { | |||
CmdUtils.setSelection( "<img src='" + imgData +"'/>"); | |||
}) | |||
} | |||
}) | |||
</pre> | |||
There are three new things here: <code>CmdUtils.setSelection</code> to set HTML (yep, it can do that); the use of <code>CmdUtils.getGeoLocation()</code>; and using <code>CmdUtils.getImageSnapshot()</code> to capture the bits for the image. | |||
I find getting the location—as imprecise as IP-based location can be—useful for doing sensible defaults for location-based commands, like Yelp. <code>CmdUtils.getGeoLocation()</code> returns an object which has the following properties: city, state, country, lat, and long. | |||
Why do we need to use <code>CmdUtils.getImageSnapshot()</code>? Because the Google Maps API requires a key that is tied to a particular URL. If we naively inject the image tag into a random web page, the image won't load because the key doesn't match that random web page's URL. Thus, we use the <code>snapshotImage()</code> function to convert the image into a [http://en.wikipedia.org/wiki/Data:_URI_scheme data url]. | |||
There's also a <code>CmdUtils.getWindowSnapshot()</code> function, which allows you to get the image data for any tab/window. The function takes a window as the first paramater, and a callback for the second. |
edits