Clear Private Data

From CDOT Wiki
Jump to: navigation, search

LXR Exercise

Documenting the search of the "Clear Private Data" feature by Mohamed, Man, and Mark. Using Mozilla 1.8.0 branch.

Documentation

Searched (via Text Search) "Clear Private Data" in LXR.

Found "/browser/locales/en-US/chrome/browser/browser.dtd, line 169 -- <!ENTITY clearPrivateDataCmd.label "Clear Private Data">", line 169 which did not help us. This file seems to describe the browser labels and buttons, but it does not link to code.

Found "/browser/locales/en-US/chrome/help/menu_reference.xhtml, line 351 -- <h 3 id="clear_private_data">Clear Private Data...</h 3>" which gives us some xml tag id which may help. Going to search that tag.

The previous paths didn't lead us to anything significant. We found another route that lead to our success. =)

Found "/browser/locales/en-US/chrome/browser/browser.properties, line 106 -- sanitizeButton=Clear Private Data Now". The sanitize button seemed interesting, so we searched that and got:

104 # Sanitize
105 sanitizeWithPromptLabel=Clear Private Data...
106 sanitizeButton=Clear Private Data Now

Found "/browser/base/content/sanitize.xul, line 75 -- document.documentElement.getButton("accept").label = bundleBrowser.getString("sanitizeButton");". sanitize.xul seems to link the button to some javascript source. We will search sanitize.js and see if that brings up anything interesting.

In sanitize.js we found some javascript code that seems to link to c++ code.

151     cookies: {
152       clear: function ()
153       {
154         var cookieMgr = Components.classes["@mozilla.org/cookiemanager;1"]
155                                   .getService(Components.interfaces.nsICookieManager);
156         cookieMgr.removeAll();
157       },
158       
159       get canClear()
160       {
161         var cookieMgr = Components.classes["@mozilla.org/cookiemanager;1"]
162                                   .getService(Components.interfaces.nsICookieManager);
163         return cookieMgr.enumerator.hasMoreElements();
164       }
165     },

We'll search "nsICookieManager" and found a "/netwerk/cookie/public/nsICookieManager.idl".

In "nsICookieManager.idl" we found a link nsICookieManager which links nsCookieServer.cpp.

449     if (!nsCRT::strcmp(aData, NS_LITERAL_STRING("shutdown-cleanse").get())) {
450       RemoveAllFromMemory();
451       // delete the cookie file
452       if (mCookieFile) {
453         mCookieFile->Remove(PR_FALSE);
454       }
455     } else {
456       Write();
457       RemoveAllFromMemory();
458     }

This file is the cpp cookie implementation and it seems the code above removes the cookie. Good learning experience I think we'd all say!

Some advice:

1. Search using "Text Search" the keyword you have. In our case "Clear Private Data" we found a lot of results most which did not help.

2. Once you found some code that calls what you want try using "File Name Search". We tried "sanitize.js" and just went fishing.

3. We tried looking for some interfaces which linked to an idl file which linked to the cpp code.