24.07.2017 Views

Hacking Gmail

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 5 — How <strong>Gmail</strong> Works<br />

61<br />

Finding XMLHttpRequest within the <strong>Gmail</strong> code<br />

Don’t take the presence of XMLHttpRequest within <strong>Gmail</strong> on trust. You can see<br />

this in action in <strong>Gmail</strong>’s own code. Go back to the DOM inspector and open the<br />

second frameset — the one with all of the JavaScript in it. Copy the entire script<br />

into a text editor and save it, as you’re going to refer to it a lot in this section.<br />

Once you’ve done that, search for the string xmlhttp. You’ll find the function in<br />

Listing 5-2.<br />

Listing 5-2: <strong>Gmail</strong>’s XMLHttpRequest Function<br />

function zd(){var R=null;if(da){var<br />

vN=lJ?”Microsoft.XMLHTTP”:”Msxml2.XMLHTTP”;try{R=new<br />

ActiveXObject(vN)}catch(f){C(f);alert(“You need to enable active<br />

scripting and activeX controls.”)}}else{R=new<br />

XMLHttpRequest();if(!R){;alert(“XMLHttpRequest is not supported on<br />

this browser.”)}}return R}<br />

As with all of the <strong>Gmail</strong> JavaScript, this is compressed and slightly confusing.<br />

Reformatted, it looks like Listing 5-3.<br />

Listing 5-3: <strong>Gmail</strong>’s XMLHttpRequest Function, Tidied<br />

function zd(){<br />

var R=null;<br />

if(da){<br />

var vN=lJ?”Microsoft.XMLHTTP”:”Msxml2.XMLHTTP”;<br />

try{R=new ActiveXObject(vN)}<br />

catch(f){<br />

C(f);alert(“You need to enable active scripting and<br />

activeX controls.”)}<br />

}else{<br />

R=new XMLHttpRequest();<br />

if(!R){<br />

;alert(“XMLHttpRequest is not supported on this<br />

browser.”)}<br />

}<br />

return R}<br />

This listing does exactly the same thing you did earlier: tries out the Microsoft<br />

Active X controls, then tries the more standard XMLHttpRequest and then, if all<br />

fails, bails with an error message. For future reference, and remember this because<br />

you’ll need it later, the XMLHttpRequest object in the <strong>Gmail</strong> code is called R.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!