Include a hash of the document URL for chrome:// loads, to distinguish between known XUL documents (bug 335841) r=marria

This commit is contained in:
bryner%brianryner.com 2006-05-20 22:49:42 +00:00
parent 0cb1a2fd02
commit ae5b528aac
5 changed files with 41 additions and 10 deletions

View File

@ -53,6 +53,7 @@
#include "nsIDOMWindow.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsServiceManagerUtils.h"
#include "nsIURI.h"
// This is needed to gain access to the LOAD_ defines in this file.
#define MOZILLA_INTERNAL_API
@ -312,7 +313,32 @@ nsLoadCollector::OnStateChange(nsIWebProgress *webProgress,
NS_ENSURE_SUCCESS(rv, rv);
}
// If this was a load of a chrome document, hash the URL of the document
// so it can be identified.
nsMetricsService *ms = nsMetricsService::get();
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
if (channel) {
nsCOMPtr<nsIURI> uri;
channel->GetURI(getter_AddRefs(uri));
if (uri) {
PRBool isChrome = PR_FALSE;
uri->SchemeIs("chrome", &isChrome);
if (isChrome) {
nsCAutoString spec;
uri->GetSpec(spec);
nsCAutoString hashedSpec;
rv = ms->HashUTF8(spec, hashedSpec);
NS_ENSURE_SUCCESS(rv, rv);
rv = props->SetPropertyAsACString(NS_LITERAL_STRING("urlhash"),
hashedSpec);
NS_ENSURE_SUCCESS(rv, rv);
}
}
}
rv = ms->LogEvent(NS_LITERAL_STRING("document"), props);
mRequestMap.Remove(request);

View File

@ -1427,15 +1427,14 @@ nsMetricsService::GetWindowIDInternal(nsIDOMWindow *window)
}
nsresult
nsMetricsService::Hash(const nsAString &str, nsCString &hashed)
nsMetricsService::HashUTF8(const nsCString &str, nsCString &hashed)
{
if (str.IsEmpty()) {
return NS_ERROR_INVALID_ARG;
}
NS_ConvertUTF16toUTF8 utf8(str);
return HashBytes(
NS_REINTERPRET_CAST(const PRUint8 *, utf8.get()), utf8.Length(), hashed);
NS_REINTERPRET_CAST(const PRUint8 *, str.get()), str.Length(), hashed);
}
/* static */ nsresult

View File

@ -136,8 +136,14 @@ public:
return mWindowMap;
}
// Creates a one-way hash of the given string
nsresult Hash(const nsAString &str, nsCString &hashed);
// Creates a one-way hash of the given string.
nsresult HashUTF8(const nsCString &str, nsCString &hashed);
// Convenience method for hashing UTF-16 strings.
// The string is converted to UTF-8, then HashUTF8() is called.
nsresult HashUTF16(const nsString &str, nsCString &hashed) {
return HashUTF8(NS_ConvertUTF16toUTF8(str), hashed);
}
private:
nsMetricsService();

View File

@ -438,9 +438,9 @@ nsProfileCollector::PluginEnumerator::CreatePluginItem(nsIDOMPlugin *plugin)
plugin->GetFilename(filename);
nsCString hashedName, hashedFilename;
nsresult rv = mMetricsService->Hash(name, hashedName);
nsresult rv = mMetricsService->HashUTF16(name, hashedName);
NS_ENSURE_SUCCESS(rv, nsnull);
rv = mMetricsService->Hash(filename, hashedFilename);
rv = mMetricsService->HashUTF16(filename, hashedFilename);
NS_ENSURE_SUCCESS(rv, nsnull);
properties->SetPropertyAsACString(NS_LITERAL_STRING("name"), hashedName);
@ -535,7 +535,7 @@ nsProfileCollector::ExtensionEnumerator::CreateExtensionItem(
NS_ENSURE_TRUE(!id.IsEmpty(), nsnull);
nsCString hashedID;
nsresult rv = mMetricsService->Hash(id, hashedID);
nsresult rv = mMetricsService->HashUTF16(id, hashedID);
NS_ENSURE_SUCCESS(rv, nsnull);
properties->SetPropertyAsACString(

View File

@ -310,7 +310,7 @@ nsUICommandCollector::HandleEvent(nsIDOMEvent* event)
// Log the Target Id which will be the same as the Original Target Id
// unless the target is anonymous content
nsCString hashedTarId;
rv = ms->Hash(tar_id, hashedTarId);
rv = ms->HashUTF16(tar_id, hashedTarId);
NS_ENSURE_SUCCESS(rv, rv);
rv = properties->SetPropertyAsACString(NS_LITERAL_STRING("targetidhash"),
@ -319,7 +319,7 @@ nsUICommandCollector::HandleEvent(nsIDOMEvent* event)
if (logAnonId) {
nsCString hashedAnonId;
rv = ms->Hash(orig_anon, hashedAnonId);
rv = ms->HashUTF16(orig_anon, hashedAnonId);
NS_ENSURE_SUCCESS(rv, rv);
rv = properties->SetPropertyAsACString(