Bug 759641 - small clean up of a11y logging, r=tbsaunde
authorAlexander Surkov <surkov.alexander@gmail.com>
Fri, 01 Jun 2012 13:26:28 +0900
changeset 97747 9a6e690f779f39078dbe4b779bbbc3b4f6e71292
parent 97726 07cec35eee231bbdbd4ce1ef0739cb71aec72af6
child 97748 f7bb3ca589692946e63a09eb1fbdfa18d42f7f91
push id1439
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 20:19:22 +0000
treeherdermozilla-aurora@ea74834dccd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstbsaunde
bugs759641
milestone15.0a1
Bug 759641 - small clean up of a11y logging, r=tbsaunde
accessible/src/base/Logging.cpp
accessible/src/base/Logging.h
accessible/src/generic/OuterDocAccessible.cpp
--- a/accessible/src/base/Logging.cpp
+++ b/accessible/src/base/Logging.cpp
@@ -2,19 +2,20 @@
 /* vim: set ts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "Logging.h"
 
 #include "AccEvent.h"
+#include "DocAccessible.h"
 #include "nsAccessibilityService.h"
 #include "nsCoreUtils.h"
-#include "DocAccessible.h"
+#include "OuterDocAccessible.h"
 
 #include "nsDocShellLoadTypes.h"
 #include "nsIChannel.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsTraceRefcntImpl.h"
 #include "nsIWebProgress.h"
 #include "prenv.h"
 
@@ -38,17 +39,18 @@ EnableLogging(const char* aModulesStr)
   if (!aModulesStr)
     return;
 
   static ModuleRep modules[] = {
     { "docload", logging::eDocLoad },
     { "doccreate", logging::eDocCreate },
     { "docdestroy", logging::eDocDestroy },
     { "doclifecycle", logging::eDocLifeCycle },
-    { "platforms", logging::ePlatforms }
+    { "platforms", logging::ePlatforms },
+    { "stack", logging::eStack }
   };
 
   const char* token = aModulesStr;
   while (*token != '\0') {
     size_t tokenLen = strcspn(token, ",");
     for (unsigned int idx = 0; idx < ArrayLength(modules); idx++) {
       if (strncmp(token, modules[idx].mStr, tokenLen) == 0) {
         sModules |= modules[idx].mModule;
@@ -177,18 +179,16 @@ LogDocParent(nsIDocument* aDocumentNode)
     LogDocURI(parentDoc);
     printf("\n");
   }
 }
 
 static void
 LogDocInfo(nsIDocument* aDocumentNode, DocAccessible* aDocument)
 {
-  printf("  {\n");
-
   printf("    DOM id: %p, acc id: %p\n    ",
          static_cast<void*>(aDocumentNode), static_cast<void*>(aDocument));
 
   // log document info
   if (aDocumentNode) {
     LogDocURI(aDocumentNode);
     printf("\n    ");
     LogDocShellState(aDocumentNode);
@@ -201,18 +201,16 @@ LogDocInfo(nsIDocument* aDocumentNode, D
     printf("\n    ");
     LogPresShell(aDocumentNode);
     printf("\n    ");
     LogDocLoadGroup(aDocumentNode);
     printf(", ");
     LogDocParent(aDocumentNode);
     printf("\n");
   }
-
-  printf("  }\n");
 }
 
 static void
 LogShellLoadType(nsIDocShell* aDocShell)
 {
   printf("load type: ");
 
   PRUint32 loadType = 0;
@@ -329,145 +327,182 @@ GetDocLoadEventType(AccEvent* aEvent, ns
         aEventType.AppendLiteral("false");
     }
   }
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // namespace logging:: document life cycle logging methods
 
+static const char* sDocLoadTitle = "DOCLOAD";
+static const char* sDocCreateTitle = "DOCCREATE";
+static const char* sDocDestroyTitle = "DOCDESTROY";
+static const char* sDocEventTitle = "DOCEVENT";
+
 void
 logging::DocLoad(const char* aMsg, nsIWebProgress* aWebProgress,
                  nsIRequest* aRequest, PRUint32 aStateFlags)
 {
-  printf("\nA11Y DOCLOAD: %s\n", aMsg);
+  MsgBegin(sDocLoadTitle, aMsg);
 
   nsCOMPtr<nsIDOMWindow> DOMWindow;
   aWebProgress->GetDOMWindow(getter_AddRefs(DOMWindow));
-  if (!DOMWindow)
+  if (!DOMWindow) {
+    MsgEnd();
     return;
+  }
 
   nsCOMPtr<nsIDOMDocument> DOMDocument;
   DOMWindow->GetDocument(getter_AddRefs(DOMDocument));
-  if (!DOMDocument)
+  if (!DOMDocument) {
+    MsgEnd();
     return;
+  }
 
   nsCOMPtr<nsIDocument> documentNode(do_QueryInterface(DOMDocument));
   DocAccessible* document =
     GetAccService()->GetDocAccessibleFromCache(documentNode);
 
   LogDocInfo(documentNode, document);
 
-  printf("  {\n");
   nsCOMPtr<nsIWebNavigation> webNav(do_GetInterface(DOMWindow));
   nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(webNav));
-  printf("    ");
+  printf("\n    ");
   LogShellLoadType(docShell);
   printf("\n");
   LogRequest(aRequest);
   printf("\n");
   printf("    state flags: %x", aStateFlags);
   bool isDocLoading;
   aWebProgress->GetIsLoadingDocument(&isDocLoading);
   printf(", document is %sloading\n", (isDocLoading ? "" : "not "));
-  printf("  }\n");
+
+  MsgEnd();
 }
 
 void
 logging::DocLoad(const char* aMsg, nsIDocument* aDocumentNode)
 {
-  printf("\nA11Y DOCLOAD: %s\n", aMsg);
+  MsgBegin(sDocLoadTitle, aMsg);
 
   DocAccessible* document =
     GetAccService()->GetDocAccessibleFromCache(aDocumentNode);
   LogDocInfo(aDocumentNode, document);
+
+  MsgEnd();
 }
 
 void
 logging::DocLoadEventFired(AccEvent* aEvent)
 {
   nsCAutoString strEventType;
   GetDocLoadEventType(aEvent, strEventType);
   if (!strEventType.IsEmpty())
     printf("  fire: %s\n", strEventType.get());
 }
 
 void
 logging::DocLoadEventHandled(AccEvent* aEvent)
 {
   nsCAutoString strEventType;
   GetDocLoadEventType(aEvent, strEventType);
-  if (!strEventType.IsEmpty()) {
-    printf("\nA11Y DOCEVENT: handled '%s' event ", strEventType.get());
+  if (strEventType.IsEmpty())
+    return;
+
+  MsgBegin(sDocEventTitle, "handled '%s' event", strEventType.get());
 
-    nsINode* node = aEvent->GetNode();
-    if (node->IsNodeOfType(nsINode::eDOCUMENT)) {
-      nsIDocument* documentNode = static_cast<nsIDocument*>(node);
-      DocAccessible* document = aEvent->GetDocAccessible();
-      LogDocInfo(documentNode, document);
-    }
+  nsINode* node = aEvent->GetNode();
+  if (node->IsNodeOfType(nsINode::eDOCUMENT)) {
+    nsIDocument* documentNode = static_cast<nsIDocument*>(node);
+    DocAccessible* document = aEvent->GetDocAccessible();
+    LogDocInfo(documentNode, document);
+  }
 
-    printf("\n");
-  }
+  MsgEnd();
 }
 
 void
 logging::DocCreate(const char* aMsg, nsIDocument* aDocumentNode,
                    DocAccessible* aDocument)
 {
   DocAccessible* document = aDocument ?
     aDocument : GetAccService()->GetDocAccessibleFromCache(aDocumentNode);
 
-  printf("\nA11Y DOCCREATE: %s\n", aMsg);
+  MsgBegin(sDocCreateTitle, aMsg);
   LogDocInfo(aDocumentNode, document);
+  MsgEnd();
 }
 
 void
 logging::DocDestroy(const char* aMsg, nsIDocument* aDocumentNode,
                     DocAccessible* aDocument)
 {
   DocAccessible* document = aDocument ?
     aDocument : GetAccService()->GetDocAccessibleFromCache(aDocumentNode);
 
-  printf("\nA11Y DOCDESTROY: %s\n", aMsg);
+  MsgBegin(sDocDestroyTitle, aMsg);
   LogDocInfo(aDocumentNode, document);
+  MsgEnd();
+}
+
+void
+logging::OuterDocDestroy(OuterDocAccessible* aOuterDoc)
+{
+  MsgBegin(sDocDestroyTitle, "outerdoc shutdown");
+  logging::Address("outerdoc", aOuterDoc);
+  MsgEnd();
 }
 
 void
 logging::Address(const char* aDescr, Accessible* aAcc)
 {
   nsINode* node = aAcc->GetNode();
   nsIDocument* docNode = aAcc->GetDocumentNode();
   DocAccessible* doc = GetAccService()->GetDocAccessibleFromCache(docNode);
-  printf("  %s accessible: %p, node: %p\n", aDescr,
+  printf("    %s accessible: %p, node: %p\n", aDescr,
          static_cast<void*>(aAcc), static_cast<void*>(node));
-  printf("  docacc for %s accessible: %p, node: %p\n", aDescr,
+  printf("    docacc for %s accessible: %p, node: %p\n", aDescr,
          static_cast<void*>(doc), static_cast<void*>(docNode));
-  printf("  ");
+  printf("    ");
   LogDocURI(docNode);
   printf("\n");
 }
 
 void
-logging::Msg(const char* aMsg)
+logging::MsgBegin(const char* aTitle, const char* aMsgText, ...)
 {
-  printf("\n%s\n", aMsg);
+  printf("\nA11Y %s: ", aTitle);
+
+  va_list argptr;
+  va_start(argptr, aMsgText);
+  vprintf(aMsgText, argptr);
+  va_end(argptr);
+
+  printf("\n  {\n");
+}
+
+void
+logging::MsgEnd()
+{
+  printf("  }\n");
 }
 
 void
 logging::Text(const char* aText)
 {
   printf("  %s\n", aText);
 }
 
 void
 logging::Stack()
 {
-  printf("  stack: \n");
-  nsTraceRefcntImpl::WalkTheStack(stdout);
+  if (IsEnabled(eStack)) {
+    printf("  stack: \n");
+    nsTraceRefcntImpl::WalkTheStack(stdout);
+  }
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // namespace logging:: initialization
 
 bool
 logging::IsEnabled(PRUint32 aModules)
 {
--- a/accessible/src/base/Logging.h
+++ b/accessible/src/base/Logging.h
@@ -14,24 +14,28 @@ class AccEvent;
 class Accessible;
 class DocAccessible;
 class nsIDocument;
 class nsIRequest;
 class nsIWebProgress;
 
 namespace mozilla {
 namespace a11y {
+
+class OuterDocAccessible;
+
 namespace logging {
 
 enum EModules {
   eDocLoad = 1 << 0,
   eDocCreate = 1 << 1,
   eDocDestroy = 1 << 2,
   eDocLifeCycle = eDocLoad | eDocCreate | eDocDestroy,
-  ePlatforms = 1 << 3
+  ePlatforms = 1 << 3,
+  eStack = 1 << 4
 };
 
 /**
  * Return true if the given module is logged.
  */
 bool IsEnabled(PRUint32 aModule);
 
 /**
@@ -59,27 +63,35 @@ void DocCreate(const char* aMsg, nsIDocu
 
 /**
  * Log the document was destroyed.
  */
 void DocDestroy(const char* aMsg, nsIDocument* aDocumentNode,
                 DocAccessible* aDocument = nsnull);
 
 /**
- * Log the message, a piece of text on own line, no offset.
+ * Log the outer document was destroyed.
  */
-void Msg(const char* aMsg);
+void OuterDocDestroy(OuterDocAccessible* OuterDoc);
+
+/**
+ * Log the message ('title: text' format) on new line. Print the start and end
+ * boundaries of the message body designated by '{' and '}' (2 spaces indent for
+ * body).
+ */
+void MsgBegin(const char* aTitle, const char* aMsgText, ...);
+void MsgEnd();
 
 /**
  * Log the text, two spaces offset is used.
  */
 void Text(const char* aText);
 
 /**
- * Log the accesisble object address, two spaces offset is used.
+ * Log the accesisble object address (4 spaces indent).
  */
 void Address(const char* aDescr, Accessible* aAcc);
 
 /**
  * Log the call stack, two spaces offset is used.
  */
 void Stack();
 
--- a/accessible/src/generic/OuterDocAccessible.cpp
+++ b/accessible/src/generic/OuterDocAccessible.cpp
@@ -119,28 +119,26 @@ OuterDocAccessible::DoAction(PRUint8 aIn
 void
 OuterDocAccessible::Shutdown()
 {
   // XXX: sometimes outerdoc accessible is shutdown because of layout style
   // change however the presshell of underlying document isn't destroyed and
   // the document doesn't get pagehide events. Shutdown underlying document if
   // any to avoid hanging document accessible.
 #ifdef DEBUG
-  if (logging::IsEnabled(logging::eDocDestroy)) {
-    logging::Msg("A11y outerdoc shutdown");
-    logging::Address("outerdoc", this);
-  }
+  if (logging::IsEnabled(logging::eDocDestroy))
+    logging::OuterDocDestroy(this);
 #endif
 
   Accessible* childAcc = mChildren.SafeElementAt(0, nsnull);
   if (childAcc) {
 #ifdef DEBUG
     if (logging::IsEnabled(logging::eDocDestroy)) {
       logging::DocDestroy("outerdoc's child document shutdown",
-                      childAcc->GetDocumentNode());
+                          childAcc->GetDocumentNode());
     }
 #endif
     childAcc->Shutdown();
   }
 
   AccessibleWrap::Shutdown();
 }
 
@@ -174,17 +172,17 @@ OuterDocAccessible::AppendChild(Accessib
     mChildren[0]->Shutdown();
 
   if (!AccessibleWrap::AppendChild(aAccessible))
     return false;
 
 #ifdef DEBUG
   if (logging::IsEnabled(logging::eDocCreate)) {
     logging::DocCreate("append document to outerdoc",
-                   aAccessible->GetDocumentNode());
+                       aAccessible->GetDocumentNode());
     logging::Address("outerdoc", this);
   }
 #endif
 
   return true;
 }
 
 bool
@@ -194,17 +192,17 @@ OuterDocAccessible::RemoveChild(Accessib
   if (child != aAccessible) {
     NS_ERROR("Wrong child to remove!");
     return false;
   }
 
 #ifdef DEBUG
   if (logging::IsEnabled(logging::eDocDestroy)) {
     logging::DocDestroy("remove document from outerdoc", child->GetDocumentNode(),
-                    child->AsDoc());
+                        child->AsDoc());
     logging::Address("outerdoc", this);
   }
 #endif
 
   bool wasRemoved = AccessibleWrap::RemoveChild(child);
 
   NS_ASSERTION(!mChildren.Length(),
                "This child document of outerdoc accessible wasn't removed!");