Changing the named callback to avoid having the returned script call a function. This allows the protocol to be used with servers that sanitize callback identifiers for security. Great patch from vmische. r=me (closes 3417).

git-svn-id: http://svn.openlayers.org/trunk/openlayers@12250 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2011-08-15 18:27:55 +00:00
parent 0ebec29df1
commit 541b3dc7ae
2 changed files with 8 additions and 21 deletions

View File

@@ -207,7 +207,7 @@ OpenLayers.Protocol.Script = OpenLayers.Class(OpenLayers.Protocol, {
*/
createRequest: function(url, params, callback) {
var id = OpenLayers.Protocol.Script.register(callback);
var name = "OpenLayers.Protocol.Script.getCallback(" + id + ")";
var name = "OpenLayers.Protocol.Script.registry[" + id + "]";
params = OpenLayers.Util.extend({}, params);
params[this.callbackKey] = this.callbackPrefix + name;
url = OpenLayers.Util.urlAppend(
@@ -328,7 +328,7 @@ OpenLayers.Protocol.Script = OpenLayers.Class(OpenLayers.Protocol, {
(function() {
var o = OpenLayers.Protocol.Script;
var counter = 0;
var registry = {};
o.registry = [];
/**
* Function: OpenLayers.Protocol.Script.register
@@ -344,7 +344,10 @@ OpenLayers.Protocol.Script = OpenLayers.Class(OpenLayers.Protocol, {
*/
o.register = function(callback) {
var id = ++counter;
registry[id] = callback;
o.registry[id] = function() {
o.unregister(id);
callback.apply(this, arguments);
};
return id;
};
@@ -356,22 +359,6 @@ OpenLayers.Protocol.Script = OpenLayers.Class(OpenLayers.Protocol, {
* id: {Number} The identifer returned by the register function.
*/
o.unregister = function(id) {
delete registry[id];
};
/**
* Function: OpenLayers.Protocol.Script.getCallback
* Retreive and unregister a callback. A call to this function is the "P"
* in JSONP. For example, a script may be added with a src attribute
* http://example.com/features.json?callback=OpenLayers.Protocol.Script.getCallback(1)
*
* Parameters:
* id: {Number} The identifer returned by the register function.
*/
o.getCallback = function(id) {
var callback = registry[id];
o.unregister(id);
return callback;
delete o.registry[id];
};
})();