Skip to content

Commit

Permalink
Extracted XMLHttpRequest object instantiation into a separate method.
Browse files Browse the repository at this point in the history
Added a test and workaround for Visualforce's Sarissa library XMLHttpRequest constructor masking.
  • Loading branch information
jperezq committed Feb 3, 2017
1 parent 0c73636 commit d2ed82f
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions forcetk.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ if (forcetk.Client === undefined) {
this.asyncAjax = true;
};

/**
* Creates an AJAX request object. Can be overridden for particular implementations.
*/
forcetk.Client.prototype.getXHR = function () {
if (window && window.Sarissa && window.Sarissa.originalXMLHttpRequest) {
return new window.Sarissa.originalXMLHttpRequest();
} else {
return new XMLHttpRequest();
}
};

/**
* Set a refresh token in the client.
* @param refreshToken an OAuth refresh token
Expand Down Expand Up @@ -211,7 +222,7 @@ if (forcetk.Client === undefined) {
'use strict';
var that = this,
url = (this.visualforce ? '' : this.instanceUrl) + path,
request = new XMLHttpRequest();
request = this.getXHR();

request.open("GET", (this.proxyUrl !== null && !this.visualforce) ? this.proxyUrl : url, true);
request.responseType = "arraybuffer";
Expand Down Expand Up @@ -293,7 +304,7 @@ if (forcetk.Client === undefined) {
"\n\n"
+ "--boundary_" + boundary + "--"
], {type : 'multipart/form-data; boundary=\"boundary_' + boundary + '\"'}),
request = new XMLHttpRequest();
request = this.getXHR();

request.open("POST", (this.proxyUrl !== null && !this.visualforce) ? this.proxyUrl : url, this.asyncAjax);

Expand Down

0 comments on commit d2ed82f

Please sign in to comment.