I am coding an external password manager-type utility that uses an XPCOM component to capture and submit passwords, as well as launch a new window with the stored URL that fills in the captured data and automatically logs in.

After the long and arduous process of learning how to work with XPCOM and searching for the basically non-existant documentation on how to do this, I've managed to get my component up and running pretty well. My Capture function works perfectly, however I am running into problems with the submit and navigate functions. Both seem to cause crashes that basically freeze firefox, and as far as I can tell, they should be working fine.

In the submit function, I get a crash on nsIDOMHTMLInputElement::Click(). I have no idea why this happens, as AFAIK there is no reason why it would crash (I have already confirmed that the element is an input element and that is is of type "submit" or "image"), so I am a bit baffled about this one. It is also functionally identical to the IE version of this function (just with XPCOM components instead of the IE-specific interfaces), which works perfectly, so I don't know why this is happening. I also tried to submit using nsIDOMHTMLFormElement::Submit() and I get the same crash.

I am also getting a crash of a similar nature in my Launch function when I call nsIWebNavigation::LoadURI(). My Launch function looks like this:

bool Launch(CWebPacket &pack)
{
   nsCOMPtr<nsIWindowWatcher> windowWatcher(do_GetService(NS_WINDOWWATCHER_CONTRACTID));
   nsCOMPtr<nsIDOMWindow> domWnd;

   // Gets topmost main firefox window
   windowWatcher->GetActiveWindow(getter_AddRefs(domWnd));

   if (domWnd)
   {
      // domWnd is the top-level browser's chrome window
      // so you need to iterate through its child windows (i.e. tabs)
      // to get the correct HTML document
      PRUint32 nWindowCount = 0;
      nsCOMPtr<nsIDOMWindowCollection> wndCol;

      domWnd->GetFrames(getter_AddRefs(wndCol));
      wndCol->GetLength(&nWindowCount);

      for (unsigned int i = 0; i < nWindowCount; i++)
      {
         nsCOMPtr<nsIDOMWindow> currWnd;

         wndCol->Item(i, getter_AddRefs(currWnd));

         nsCOMPtr<nsIDOMDocument> domDoc;
         currWnd->GetDocument(getter_AddRefs(domDoc));
         if (domDoc)
         {
            // try to get a HTML document from the DOM document
            nsCOMPtr<nsIDOMHTMLDocument> htmDoc(do_QueryInterface(domDoc));
            if (htmDoc)
            {
               // this is an HTML Document, now try and Navigate
               nsresult rv;
               nsCOMPtr<nsIWebNavigation> webNav;

               webNav = do_GetInterface(currWnd, &rv);

               if (rv == NS_OK && webNav != nsnull)
               {
                  rv = webNav->LoadURI(pack.m_sURL, nsIWebNavigation::LOAD_FLAGS_NONE, nsnull, nsnull, nsnull);
                  if (NS_FAILED(rv))
                     MessageBox(NULL, L"LoadURI Failed", NULL, 0);
                  else
                     MessageBox(NULL, L"Should be Navigating right now", NULL, 0);
                  //return SubmitData(pack);
                  return true;
               }
            }
         }
      }
   }

   return true;
}


pack.m_sURL is a wchar_t array, so it is correct to pass that to LoadURI right? Also, is it ok to pass NULL for the last three parameters (referrer, postdata, and headers)?

One more question, is this even the correct way to do WebNavigation from an XPCOM component? nsIWebNavigation.h wasn't even in the gecko-sdk, so perhaps there is a better/more correct way to do this?

I could also post my Submit() code, but the function is rather long, and like I said before, I don’t really see anything in it that could suggest a possible reason for a crash, esp. since 99.9% of the function works perfectly.


Hopefully there is someone out there who knows what I am doing wrong. Sorry for the long post, but I am really starting to run out of ideas for what to do. Thanks for your help!

Reply via email to