b=408127 r=varga UI Elements/Events to be instrumented listen for Larry and bm star popups --pete
authorpete@mozdevgroup.com
Thu, 17 Jan 2008 08:13:25 -0800
changeset 10365 2a73a06b855626445147f12eb2b77df0b193c77c
parent 10364 acf90f4f0259433b2f018d53b055251ab1931cd3
child 10366 e5b2360c824fe7d64ca43a79e62971618962b00d
push idunknown
push userunknown
push dateunknown
reviewersvarga
bugs408127
milestone1.9b3pre
b=408127 r=varga UI Elements/Events to be instrumented listen for Larry and bm star popups --pete
extensions/metrics/src/nsUICommandCollector.cpp
extensions/metrics/src/nsUICommandCollector.h
--- a/extensions/metrics/src/nsUICommandCollector.cpp
+++ b/extensions/metrics/src/nsUICommandCollector.cpp
@@ -48,16 +48,17 @@
 #include "nsIDOMElement.h"
 #include "nsIDOMWindow.h"
 #include "nsDataHashtable.h"
 #include "nsMemory.h"
 
 const nsUICommandCollector::EventHandler nsUICommandCollector::kEvents[] = {
   { "command", &nsUICommandCollector::HandleCommandEvent },
   { "TabMove", &nsUICommandCollector::HandleTabMoveEvent },
+  { "popupshowing", &nsUICommandCollector::HandlePopupShowingEvent },
 };
 
 NS_IMPL_ISUPPORTS3(nsUICommandCollector, nsIObserver, nsIDOMEventListener,
                    nsIMetricsCollector)
 
 /* static */
 PLDHashOperator PR_CALLBACK nsUICommandCollector::AddCommandEventListener(
 const nsIDOMWindow* key, PRUint32 windowID, void* userArg)
@@ -286,16 +287,71 @@ nsUICommandCollector::HandleTabMoveEvent
   rv = ms->LogEvent(NS_LITERAL_STRING("uielement"), properties);
   NS_ENSURE_SUCCESS(rv, rv);
 
   MS_LOG(("Successfully logged UI Event"));
   return NS_OK;
 }
 
 nsresult
+nsUICommandCollector::HandlePopupShowingEvent(nsIDOMEvent* event)
+{
+  PRUint32 window;
+  if (NS_FAILED(GetEventWindow(event, &window))) 
+    return NS_OK;
+
+  nsString targetId, targetAnonId;
+  if (NS_FAILED(GetEventTargets(event, targetId, targetAnonId))) 
+    return NS_OK;
+
+  NS_ASSERTION(!targetId.IsEmpty(), "can't have an empty target id");
+
+  if (!targetId.Equals(NS_LITERAL_STRING("identity-popup")) && !targetId.Equals(NS_LITERAL_STRING("editBookmarkPanel"))) 
+    return NS_OK;
+
+  // Fill a property bag with what we want to log
+  nsCOMPtr<nsIWritablePropertyBag2> properties;
+  nsMetricsUtils::NewPropertyBag(getter_AddRefs(properties));
+  NS_ENSURE_STATE(properties);
+
+  nsresult rv;
+  rv = properties->SetPropertyAsUint32(NS_LITERAL_STRING("window"), window);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  rv = properties->SetPropertyAsAString(NS_LITERAL_STRING("action"),
+                                        NS_LITERAL_STRING("popupshowing"));
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  rv = SetHashedValue(properties, NS_LITERAL_STRING("targetidhash"), targetId);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  if (!targetAnonId.IsEmpty()) 
+  {
+    rv = SetHashedValue(properties, NS_LITERAL_STRING("targetanonidhash"),
+                        targetAnonId);
+    NS_ENSURE_SUCCESS(rv, rv);
+  }
+
+  nsMetricsService *ms = nsMetricsService::get();
+  NS_ENSURE_STATE(ms);
+
+  nsCOMPtr<nsIMetricsEventItem> item;
+  ms->CreateEventItem(NS_LITERAL_STRING("uielement"), getter_AddRefs(item));
+  NS_ENSURE_STATE(item);
+  item->SetProperties(properties);
+
+  // Actually log it
+  rv = ms->LogEvent(item);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  MS_LOG(("Successfully logged UI popupshowing Event"));
+  return NS_OK;
+}
+
+nsresult
 nsUICommandCollector::GetEventTargets(nsIDOMEvent *event,
                                       nsString &targetId,
                                       nsString &targetAnonId) const
 {
   // This code deals with both anonymous and explicit (non-anonymous) content.
   //
   // For explicit content, we just return the id of the event target in
   // targetId, and leave targetAnonId empty.  If there is no id, then
--- a/extensions/metrics/src/nsUICommandCollector.h
+++ b/extensions/metrics/src/nsUICommandCollector.h
@@ -100,16 +100,19 @@ class nsUICommandCollector : public nsIO
   void RemoveEventListeners(nsIDOMEventTarget* window);
 
   // Handles a XUL command event.
   nsresult HandleCommandEvent(nsIDOMEvent* event);
 
   // Handles a TabMove event from the tabbrowser widget.
   nsresult HandleTabMoveEvent(nsIDOMEvent* event);
 
+  // Handles a popupshowing event from the tabbrowser widget.
+  nsresult HandlePopupShowingEvent(nsIDOMEvent* event);
+
   // Checks whether the given target id corresponds to a bookmark resource,
   // and if so, adds additional data about the bookmark to parentItem.
   nsresult LogBookmarkInfo(const nsString& id,
                            nsIMetricsEventItem* parentItem);
 
   // Hashes the given property value and adds it to the property bag.
   nsresult SetHashedValue(nsIWritablePropertyBag2 *properties,
                           const nsString &propertyName,