executingKeyBind = PR_TRUE;  if (!aKeyEvent) { executingKeyBind = PR_FALSE;
if (!mDOMDocument)
nsresult nsXULKeyListenerImpl::DoKey(nsIDOMEvent* aKeyEvent, eEventType aEventType){  // Check the preventDefault flag.  We don't ever execute a XUL key binding  // if this flag is set.  nsCOMPtr<nsIDOMNSUIEvent> evt = do_QueryInterface(aKeyEvent);  PRBool prevent;  evt->GetPreventDefault(&prevent);  if (prevent)    return NS_OK;  static PRBool executingKeyBind = PR_FALSE;  nsresult ret = NS_OK;  if (executingKeyBind)    return NS_OK;  executingKeyBind = PR_TRUE;  if (!aKeyEvent) {    executingKeyBind = PR_FALSE;    return ret;  }  if (!mDOMDocument) {    executingKeyBind = PR_FALSE;    return ret;  }  // Get DOMEvent target  nsCOMPtr<nsIDOMNode> target = nsnull;  aKeyEvent->GetTarget(getter_AddRefs(target));  nsCOMPtr<nsPIDOMWindow> piWindow;  nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aKeyEvent);  // Find a keyset node  // Get the current focused object from the command dispatcher  nsCOMPtr<nsIDOMXULCommandDispatcher> commandDispatcher;  mDOMDocument->GetCommandDispatcher(getter_AddRefs(commandDispatcher));   nsCOMPtr<nsIDOMWindow> domWindow;  commandDispatcher->GetFocusedWindow(getter_AddRefs(domWindow));  piWindow = do_QueryInterface(domWindow);  // Locate the key node and execute the JS on a match.  PRBool handled = PR_FALSE;    nsCAutoString browserFile = "chrome://global/content/browserBindings.xul";  nsCAutoString editorFile = "chrome://global/content/editorBindings.xul";  nsCAutoString browserPlatformFile = "chrome://global/content/platformBrowserBindings.xul";  nsCAutoString editorPlatformFile = "chrome://global/content/platformEditorBindings.xul";  nsresult result;  nsCOMPtr<nsIDOMXULDocument> document;  if (!handled) {    while (piWindow && !handled) {      // See if we have a XUL document. Give it a crack.      nsCOMPtr<nsIDOMWindow> domWindow = do_QueryInterface(piWindow);      nsCOMPtr<nsIDOMDocument> windowDoc;      domWindow->GetDocument(getter_AddRefs(windowDoc));      nsCOMPtr<nsIDOMXULDocument> xulWindowDoc = do_QueryInterface(windowDoc);      if (xulWindowDoc) {        // Give the local key bindings in this XUL file a shot.        LocateAndExecuteKeyBinding(keyEvent, aEventType, xulWindowDoc, handled);      }      if (!handled) {        // Give the DOM window's associated key binding doc a shot.        // XXX Check to see if we're in edit mode (how??!)        nsCOMPtr<nsIDocShell> docShell;        result = piWindow->GetDocShell(getter_AddRefs(docShell));        nsCOMPtr<nsIPresShell> presShell;        if(docShell)         docShell->GetPresShell(getter_AddRefs(presShell));        PRBool editorHasBindings = PR_FALSE;        nsCOMPtr<nsIDOMXULDocument> platformDoc;        if (presShell) {          PRBool isEditor;          if (NS_SUCCEEDED(presShell->GetDisplayNonTextSelection(&isEditor)) && isEditor) {            editorHasBindings = PR_TRUE;            GetKeyBindingDocument(editorPlatformFile, getter_AddRefs(platformDoc));            GetKeyBindingDocument(editorFile, getter_AddRefs(document));          }        }        if (!editorHasBindings) {          GetKeyBindingDocument(browserPlatformFile, getter_AddRefs(platformDoc));          GetKeyBindingDocument(browserFile, getter_AddRefs(document));        }        if (platformDoc)          LocateAndExecuteKeyBinding(keyEvent, aEventType, platformDoc, handled);        if (!handled && document)          LocateAndExecuteKeyBinding(keyEvent, aEventType, document, handled);      }      // Move up to the parent DOM window. Need to use the private API      // to cross sandboxes      nsCOMPtr<nsPIDOMWindow> piParent;      piWindow->GetPrivateParent(getter_AddRefs(piParent));      piWindow = piParent;    }  }  executingKeyBind = PR_FALSE;  return ret;}