24.07.2017 Views

Hacking Gmail

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

How <strong>Gmail</strong> Works<br />

chapter<br />

By now you’ve learned how to use <strong>Gmail</strong> with some flair, and<br />

you can change the way it looks to a certain extent. Now<br />

you have to look into exactly how it works. You already<br />

know that the majority of the <strong>Gmail</strong> functionality is enacted<br />

client-side — that is, on the browser, rather than at the server —<br />

and is done with JavaScript. This chapter describes exactly how<br />

this works and how you can exploit it.<br />

What the Devil Is Going On?<br />

Before revealing just what’s happening, let’s recap. In Chapter 4<br />

you used the DOM inspector inside Firefox to help you dissect<br />

the HTML, and this will help you again. So, as before, open up<br />

<strong>Gmail</strong> in Firefox, and open the DOM inspector.<br />

You already know that the main document is made of two frames,<br />

the first made of many subframes and the second one with nothing<br />

but a huge chunk of JavaScript. Figure 5-1 shows you that in<br />

the DOM inspector.<br />

Using the DOM inspector’s right-click menu Copy as XML<br />

function, you can grab the text of the script and copy it to a text<br />

editor. Ordinarily, I would include this code as a listing right<br />

here, but when I cut and pasted it into the manuscript of this<br />

book, it added another 120 pages in a single keystroke. This does<br />

not bode well, especially as Google has tried as hard as it can to<br />

format the JavaScript as tightly as possible. This saves bandwidth<br />

but doesn’t help anyone else read what Google is doing. We’ll<br />

reach that problem in a page or two.<br />

in this chapter<br />

˛ Getting at the code<br />

˛ The interface<br />

˛ XMLHttpRequest<br />

˛ Packet sniffing<br />

˛ Probing the<br />

interface<br />

˛ Decoding the data

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

Saved successfully!

Ooh no, something went wrong!