BZ> Note that if you do what the view-source window does in Mozilla to
load
BZ> Mozilla's built-in view-source into a display:none docshell or
something
BZ> and then grab the text out of that, it'll be about what you want
(though
BZ> characters, not bytes, and not as fast as just getting the bytes).
This
BZ> preserves whitespace, all sorts of malformed stuff, etc.

EB> Thanks, I'll try that approach, but I need more specifics on "grab
EB> the text out of that".  I have an nsIDocShell that has been loaded
EB> in the same manner as the view-source window.  Now, how do I get
the
EB> text out of it?

I've done a bit of research.

The trail starts at
<http://lxr.mozilla.org/mozilla/source/browser/base/content/browser.js#1820>.

BrowserViewSourceOfDocument() QIs nsIWebNavigation to an
nsIWebPageDescriptor.  The "currentDescriptor" property is extracted
and
passed as the "pageCookie" to BrowserViewSourceofURL() along with the
current uri for the nsIWebNavigation and the charset.

BrowserViewSourceofURL() calls through to:

openDialog("chrome://global/content/viewSource.xul",
              "_blank",
              "scrollbars,resizable,chrome,dialog=no",
              url, charset, pageCookie);

This eventually calls
<http://lxr.mozilla.org/mozilla/source/xpfe/browser/resources/content/viewsource.js#96>,
which uses the pageCookie (here called "arg"):

PageLoader.loadPage(arg, pageLoaderIface.DISPLAY_AS_SOURCE);

It turns out this is actually implemented by nsDocShell.cpp, (whew!
finally we're back in C++ land).

nsDocShell::LoadPage(nsISupports *aPageDescriptor, PRUint32
aDisplayType)

This QIs aPageDescriptor to an nsISHEntry (session history entry), QIs
that to an nsIHistoryEntry, gets the URI from the nsIHistoryEntry,
prepends "view-source:" to the URI, clones the URI, sets it as the
current URI for the nsISHEntry, and sets the parent property of the
nsISHEntry to nsnull ad the isSubFrame property to PR_FALSE.  Then it
calls through to ::LoadHistoryEntry, passing the nsISHEntry.

I think this adequately describes how ViewSource differs from a regular
page load, but I still don't see how to get the text.  Boris?  Help?

Thanks,

Ed

_______________________________________________
mozilla-embedding mailing list
mozilla-embedding@mozilla.org
http://mail.mozilla.org/listinfo/mozilla-embedding

Reply via email to