1 | define([ |
---|
2 | "dojo/_base/kernel", |
---|
3 | "dojo/_base/json", |
---|
4 | "dojo/_base/xhr", |
---|
5 | "dojox/io/xhrPlugins", |
---|
6 | "dojox/io/windowName", |
---|
7 | "dojox/io/httpParse", |
---|
8 | "dojox/secure/capability" |
---|
9 | ], function(dojo, json, xhr, xhrPlugins, windowName, httpParse, capability){ |
---|
10 | dojo.getObject("io.xhrWindowNamePlugin", true, dojox); |
---|
11 | |
---|
12 | dojox.io.xhrWindowNamePlugin = function(/*String*/url, /*Function?*/httpAdapter, /*Boolean?*/trusted){ |
---|
13 | // summary: |
---|
14 | // Adds the windowName transport as an XHR plugin for the given site. See |
---|
15 | // dojox.io.windowName for more information on the transport. |
---|
16 | // url: |
---|
17 | // Url prefix of the site which can handle windowName requests. |
---|
18 | // httpAdapter: This allows for adapting HTTP requests that could not otherwise be |
---|
19 | // sent with window.name, so you can use a convention for headers and PUT/DELETE methods. |
---|
20 | xhrPlugins.register( |
---|
21 | "windowName", |
---|
22 | function(method,args){ |
---|
23 | return args.sync !== true && |
---|
24 | (method == "GET" || method == "POST" || httpAdapter) && |
---|
25 | (args.url.substring(0,url.length) == url); |
---|
26 | }, |
---|
27 | function(method,args,hasBody){ |
---|
28 | var send = windowName.send; |
---|
29 | var load = args.load; |
---|
30 | args.load = undefined; //we don't want send to set this callback |
---|
31 | var dfd = (httpAdapter ? httpAdapter(send, true) : send)(method, args, hasBody); // use the windowName transport |
---|
32 | dfd.addCallback(function(result){ |
---|
33 | var ioArgs = dfd.ioArgs; |
---|
34 | ioArgs.xhr = { |
---|
35 | getResponseHeader: function(name){ |
---|
36 | // convert the hash to an object to act like response headers |
---|
37 | return dojo.queryToObject(ioArgs.hash.match(/[^#]*$/)[0])[name]; |
---|
38 | } |
---|
39 | } |
---|
40 | // use the XHR content handlers for handling |
---|
41 | if(ioArgs.handleAs == 'json'){ |
---|
42 | // use a secure json verifier, using object capability validator for now |
---|
43 | if(!trusted){ |
---|
44 | capability.validate(result,["Date"],{}); |
---|
45 | } |
---|
46 | return dojo.fromJson(result); |
---|
47 | } |
---|
48 | return dojo._contentHandlers[ioArgs.handleAs || "text"]({responseText:result}); |
---|
49 | }); |
---|
50 | args.load = load; |
---|
51 | if(load){ |
---|
52 | dfd.addCallback(load); |
---|
53 | } |
---|
54 | return dfd; |
---|
55 | } |
---|
56 | ); |
---|
57 | }; |
---|
58 | |
---|
59 | return dojox.io.xhrWindowNamePlugin; |
---|
60 | }); |
---|