Well, it turns out it's not so simple, and I still need help.  Here's
what I have now:

I get the nsIWebPageDescriptor (pageCookie) from the docShell for the
page for which I want to get the source bytes.

I create a new nsIWebBrowser, and initialize it:

    mWebBrowser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID);

    mWebBrowser->SetContainerWindow(nsnull);

    nsCOMPtr<nsIDocShellTreeItem> item =
do_QueryInterface(mWebBrowser);
    item->SetItemType(nsIDocShellTreeItem::typeContentWrapper);

I get the nsIBaseWindow and init it:

    mBaseWindow = do_QueryInterface(mWebBrowser);
    rv = mBaseWindow->InitWindow(ownerAsWidget,
                                 nsnull,
                                 0, 0,
                                 width, height);

I create the baseWindow:

    rv = mBaseWindow->Create();

I get the docShell from the webBrowser:

    nsCOMPtr<nsIDocShell> newDocShell = do_GetInterface(mWebBrowser);

I get the pageDescriptor from the new docShell:

    nsCOMPtr<nsIWebPageDescriptor> newPageDesc =
do_GetInterface(newDocShell);

I load the view source page, using the cookie:

    rv = newPageDesc->LoadPage(pageCookie,

nsIWebPageDescriptor::DISPLAY_AS_SOURCE);

I run my event loop to allow the page load to complete:

    // allow the page load to complete
    nativeBrowserControl->GetWrapperFactory()->ProcessEventLoop();

I get the contentViewer and contentViewerEdit from the docShell:

    nsCOMPtr<nsIDocShell> docShell = do_GetInterface(mWebBrowser);
    if (!docShell) {
        return NS_ERROR_FAILURE;
    }
    nsCOMPtr<nsIContentViewer> contentViewer;
    nsresult rv =
docShell->GetContentViewer(getter_AddRefs(contentViewer));
    if (!contentViewer) {
        return NS_ERROR_FAILURE;
    }
    nsCOMPtr<nsIContentViewerEdit>
contentViewerEdit(do_QueryInterface(contentViewer));

I tell it to selectAll();

    rv = contentViewerEdit->SelectAll();

NOW here's where I get into trouble.  This eventually boils down to
nsHTMLDocument::GetBodyContent().  The problem is that the mBodyContent
ivar never gets set, and I don't know why:

PRBool
nsHTMLDocument::GetBodyContent()
{
  if (!mRootContent) {
    return PR_FALSE;
  }

  PRUint32 i, child_count = mRootContent->GetChildCount();

  for (i = 0; i < child_count; ++i) {
    nsIContent *child = mRootContent->GetChildAt(i);
    NS_ENSURE_TRUE(child, NS_ERROR_UNEXPECTED);

    if (child->IsContentOfType(nsIContent::eHTML) &&
        child->GetNodeInfo()->Equals(nsHTMLAtoms::body,
                                     mDefaultNamespaceID)) {
      mBodyContent = do_QueryInterface(child);

      return PR_TRUE;
    }
  }

  return PR_FALSE;

I note that a regular render of the page does cause mBodyContent to be
set, but a view Source one does not.

Any ideas?

Ed

_______________________________________________
mozilla-embedding mailing list
[email protected]
http://mail.mozilla.org/listinfo/mozilla-embedding

Reply via email to