No. That's not quite what is happening. Your client (Firefox) requests a bunch of mails residing on Gmail's server somewhere. The server then scans the mails for keywords, finds the relevant ads in their database and then returns a html page with emails and ads combined.
When I open a mail (or write a mail) Indeed, gmail will display ads on the side bar and one small ad above the mail interface. But that is merely the page sending out a request to the google ad server thats tagged their ads with relevant keywords...