Bug 540462 - Move GetDocument from nsIDocumentViewer to nsIContentViewer, r=bz

This commit is contained in:
Olli Pettay 2010-01-23 13:41:41 +02:00
Родитель f48cfb61db
Коммит d1f21ee014
14 изменённых файлов: 132 добавлений и 120 удалений

Просмотреть файл

@ -56,7 +56,6 @@
#include "nsIDOMWindowInternal.h"
#include "nsIDOMXULElement.h"
#include "nsIDocShell.h"
#include "nsIDocumentViewer.h"
#include "nsIContentViewer.h"
#include "nsIEventListenerManager.h"
#include "nsIPresShell.h"
@ -560,17 +559,12 @@ nsCoreUtils::GetDOMNodeForContainer(nsIDocShellTreeItem *aContainer)
if (!cv)
return nsnull;
nsCOMPtr<nsIDocumentViewer> docv(do_QueryInterface(cv));
if (!docv)
return nsnull;
nsCOMPtr<nsIDocument> doc;
docv->GetDocument(getter_AddRefs(doc));
nsIDocument* doc = cv->GetDocument();
if (!doc)
return nsnull;
nsIDOMNode* node = nsnull;
CallQueryInterface(doc.get(), &node);
CallQueryInterface(doc, &node);
return node;
}

Просмотреть файл

@ -905,7 +905,7 @@ nsExternalResourceMap::AddExternalResource(nsIURI* aURI,
nsCOMPtr<nsIDocument> doc;
if (aViewer) {
aViewer->GetDocument(getter_AddRefs(doc));
doc = aViewer->GetDocument();
NS_ASSERTION(doc, "Must have a document");
nsCOMPtr<nsIXULDocument> xulDoc = do_QueryInterface(doc);

Просмотреть файл

@ -775,10 +775,8 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
if (parent) {
rv = parent->GetContentViewer(getter_AddRefs(parentContentViewer));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDocumentViewer> docViewer =
do_QueryInterface(parentContentViewer);
if (docViewer) {
docViewer->GetDocument(getter_AddRefs(parentDocument));
if (parentContentViewer) {
parentDocument = parentContentViewer->GetDocument();
}
}

Просмотреть файл

@ -1792,8 +1792,7 @@ nsDocShell::GetChannelIsUnsafe(PRBool *aUnsafe)
{
*aUnsafe = PR_FALSE;
nsCOMPtr<nsIChannel> channel;
GetCurrentDocumentChannel(getter_AddRefs(channel));
nsIChannel* channel = GetCurrentDocChannel();
if (!channel) {
return NS_OK;
}
@ -2287,24 +2286,22 @@ nsDocShell::AddSessionStorage(nsIPrincipal* aPrincipal,
NS_IMETHODIMP
nsDocShell::GetCurrentDocumentChannel(nsIChannel** aResult)
{
*aResult = nsnull;
if (!mContentViewer)
return NS_OK;
nsCOMPtr<nsIDOMDocument> domDoc;
nsresult rv = mContentViewer->GetDOMDocument(getter_AddRefs(domDoc));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIDocument> doc(do_QueryInterface(domDoc));
if (doc) {
*aResult = doc->GetChannel();
NS_IF_ADDREF(*aResult);
}
NS_IF_ADDREF(*aResult = GetCurrentDocChannel());
return NS_OK;
}
nsIChannel*
nsDocShell::GetCurrentDocChannel()
{
if (mContentViewer) {
nsIDocument* doc = mContentViewer->GetDocument();
if (doc) {
return doc->GetChannel();
}
}
return nsnull;
}
//*****************************************************************************
// nsDocShell::nsIDocShellTreeItem
//*****************************************************************************
@ -2988,12 +2985,10 @@ nsDocShell::AddChild(nsIDocShellTreeItem * aChild)
return NS_OK;
// get the parent's current charset
nsCOMPtr<nsIDocumentViewer> docv(do_QueryInterface(mContentViewer));
if (!docv)
if (!mContentViewer)
return NS_OK;
nsCOMPtr<nsIDocument> doc;
res = docv->GetDocument(getter_AddRefs(doc));
if (NS_FAILED(res) || (!doc))
nsIDocument* doc = mContentViewer->GetDocument();
if (!doc)
return NS_OK;
const nsACString &parentCS = doc->GetDocumentCharacterSet();
@ -8050,11 +8045,7 @@ nsDocShell::GetInheritedPrincipal(PRBool aConsiderCurrentDocument)
nsCOMPtr<nsIDocument> document;
if (aConsiderCurrentDocument && mContentViewer) {
nsCOMPtr<nsIDocumentViewer>
docViewer(do_QueryInterface(mContentViewer));
if (!docViewer)
return nsnull;
docViewer->GetDocument(getter_AddRefs(document));
document = mContentViewer->GetDocument();
}
if (!document) {
@ -8076,11 +8067,9 @@ nsDocShell::GetInheritedPrincipal(PRBool aConsiderCurrentDocument)
EnsureContentViewer(); // If this fails, we'll just get a null
// docViewer and bail.
nsCOMPtr<nsIDocumentViewer>
docViewer(do_QueryInterface(mContentViewer));
if (!docViewer)
if (!mContentViewer)
return nsnull;
docViewer->GetDocument(getter_AddRefs(document));
document = mContentViewer->GetDocument();
}
//-- Get the document's principal
@ -8700,12 +8689,8 @@ nsDocShell::ScrollIfAnchor(nsIURI * aURI, PRBool * aWasAnchor,
// Get a document charset
NS_ENSURE_TRUE(mContentViewer, NS_ERROR_FAILURE);
nsCOMPtr<nsIDocumentViewer>
docv(do_QueryInterface(mContentViewer));
NS_ENSURE_TRUE(docv, NS_ERROR_FAILURE);
nsCOMPtr<nsIDocument> doc;
rv = docv->GetDocument(getter_AddRefs(doc));
NS_ENSURE_SUCCESS(rv, rv);
nsIDocument* doc = mContentViewer->GetDocument();
NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
const nsACString &aCharset = doc->GetDocumentCharacterSet();
nsCOMPtr<nsITextToSubURI> textToSubURI =
@ -10088,7 +10073,6 @@ nsDocShell::SetBaseUrlForWyciwyg(nsIContentViewer * aContentViewer)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIURI> baseURI;
nsCOMPtr<nsIDocument> document;
nsresult rv = NS_ERROR_NOT_AVAILABLE;
if (sURIFixup)
@ -10097,11 +10081,9 @@ nsDocShell::SetBaseUrlForWyciwyg(nsIContentViewer * aContentViewer)
// Get the current document and set the base uri
if (baseURI) {
nsCOMPtr<nsIDocumentViewer> docViewer(do_QueryInterface(aContentViewer));
if (docViewer) {
rv = docViewer->GetDocument(getter_AddRefs(document));
if (document)
rv = document->SetBaseURI(baseURI);
nsIDocument* document = aContentViewer->GetDocument();
if (document) {
rv = document->SetBaseURI(baseURI);
}
}
return rv;

Просмотреть файл

@ -614,7 +614,8 @@ protected:
nsresult IsCommandEnabled(const char * inCommand, PRBool* outEnabled);
nsresult DoCommand(const char * inCommand);
nsresult EnsureCommandHandler();
nsIChannel* GetCurrentDocChannel();
protected:
// Override the parent setter from nsDocLoader
virtual nsresult SetDocLoaderParent(nsDocLoader * aLoader);

Просмотреть файл

@ -7,13 +7,15 @@ interface nsIPrintSettings;
%{ C++
class nsIWidget;
class nsIDocument;
struct nsIntRect;
%}
[ptr] native nsIWidgetPtr(nsIWidget);
[ptr] native nsIDocumentPtr(nsIDocument);
[ref] native nsIntRectRef(nsIntRect);
[scriptable, uuid(08665a60-b398-11de-8a39-0800200c9a66)]
[scriptable, uuid(c824ac5e-3d86-4ae5-9ccc-9433bdc43004)]
interface nsIContentViewer : nsISupports
{
@ -75,6 +77,11 @@ interface nsIContentViewer : nsISupports
attribute nsIDOMDocument DOMDocument;
/**
* Returns DOMDocument as nsIDocument and without addrefing.
*/
[noscript,notxpcom] nsIDocumentPtr getDocument();
[noscript] void getBounds(in nsIntRectRef aBounds);
[noscript] void setBounds([const] in nsIntRectRef aBounds);

Просмотреть файл

@ -81,6 +81,8 @@ _TEST_FILES = \
test_bug529119-1.html \
test_bug529119-2.html \
bug529119-window.html \
test_bug540462.html \
file_bug540462.html \
$(NULL)
ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)

Просмотреть файл

@ -0,0 +1,16 @@
<html>
<head>
<script>
//<!--
function test() {
document.open();
document.write("<html><body onload='opener.documentWriteLoad(); rel();'><a href='foo.html'>foo</a><script>function rel() { setTimeout('location.reload()', 0); }</script></body></html>");
document.close();
}
//-->
</script>
</head>
<body onload="setTimeout('test()', 0)">
Test for bug 540462
</body>
</html>

Просмотреть файл

@ -0,0 +1,45 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=540462
-->
<head>
<title>Test for Bug 540462</title>
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body onload="runTest()">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=540462">Mozilla Bug 540462</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 540462 **/
var win;
function runTest() {
win = window.open("file_bug540462.html", "", "width=100,height=100");
}
var dwlCount = 0;
var originalURL;
function documentWriteLoad() {
if (++dwlCount == 1) {
originalURL = win.document.body.firstChild.href;
} else if (dwlCount == 2) {
is(win.document.body.firstChild.href, originalURL, "Wrong href!");
win.close();
SimpleTest.finish();
}
}
SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>

Просмотреть файл

@ -322,7 +322,6 @@ public:
NS_DECL_NSICONTENTVIEWER
// nsIDocumentViewer interface...
NS_IMETHOD GetDocument(nsIDocument** aResult);
NS_IMETHOD GetPresShell(nsIPresShell** aResult);
NS_IMETHOD GetPresContext(nsPresContext** aResult);
@ -1316,8 +1315,7 @@ AttachContainerRecurse(nsIDocShell* aShell)
aShell->GetContentViewer(getter_AddRefs(viewer));
nsCOMPtr<nsIDocumentViewer> docViewer = do_QueryInterface(viewer);
if (docViewer) {
nsCOMPtr<nsIDocument> doc;
docViewer->GetDocument(getter_AddRefs(doc));
nsIDocument* doc = docViewer->GetDocument();
if (doc) {
doc->SetContainer(aShell);
}
@ -1445,8 +1443,7 @@ DetachContainerRecurse(nsIDocShell *aShell)
aShell->GetContentViewer(getter_AddRefs(viewer));
nsCOMPtr<nsIDocumentViewer> docViewer = do_QueryInterface(viewer);
if (docViewer) {
nsCOMPtr<nsIDocument> doc;
docViewer->GetDocument(getter_AddRefs(doc));
nsIDocument* doc = docViewer->GetDocument();
if (doc) {
doc->SetContainer(nsnull);
}
@ -1662,6 +1659,12 @@ DocumentViewerImpl::GetDOMDocument(nsIDOMDocument **aResult)
return CallQueryInterface(mDocument, aResult);
}
NS_IMETHODIMP_(nsIDocument *)
DocumentViewerImpl::GetDocument()
{
return mDocument;
}
NS_IMETHODIMP
DocumentViewerImpl::SetDOMDocument(nsIDOMDocument *aDocument)
{
@ -1759,14 +1762,6 @@ DocumentViewerImpl::SetDOMDocument(nsIDOMDocument *aDocument)
return rv;
}
NS_IMETHODIMP
DocumentViewerImpl::GetDocument(nsIDocument** aResult)
{
NS_IF_ADDREF(*aResult = mDocument);
return NS_OK;
}
nsIPresShell*
DocumentViewerImpl::GetPresShell()
{
@ -3399,12 +3394,8 @@ DocumentViewerImpl::GetPopupNode(nsIDOMNode** aNode)
{
NS_ENSURE_ARG_POINTER(aNode);
nsresult rv;
// get the document
nsCOMPtr<nsIDocument> document;
rv = GetDocument(getter_AddRefs(document));
NS_ENSURE_SUCCESS(rv, rv);
nsIDocument* document = GetDocument();
NS_ENSURE_TRUE(document, NS_ERROR_FAILURE);
@ -3419,7 +3410,7 @@ DocumentViewerImpl::GetPopupNode(nsIDOMNode** aNode)
// get the popup node
focusController->GetPopupNode(aNode); // addref happens here
return rv;
return NS_OK;
}
// GetPopupLinkNode: return popup link node or fail
@ -3567,8 +3558,7 @@ NS_IMETHODIMP nsDocViewerSelectionListener::NotifySelectionChanged(nsIDOMDocumen
// for simple selection changes, but that would be expenseive.
if (!mGotSelectionState || mSelectionWasCollapsed != selectionCollapsed)
{
nsCOMPtr<nsIDocument> theDoc;
mDocViewer->GetDocument(getter_AddRefs(theDoc));
nsIDocument* theDoc = mDocViewer->GetDocument();
if (!theDoc) return NS_ERROR_FAILURE;
nsPIDOMWindow *domWindow = theDoc->GetWindow();

Просмотреть файл

@ -48,8 +48,8 @@ class nsIPresShell;
class nsIStyleSheet;
#define NS_IDOCUMENT_VIEWER_IID \
{ 0xf81fc126, 0x6693, 0x4bc5,{0xa7, 0xe9, 0xfc, 0xb0, 0x76, 0xd9, 0x06, 0x6d} }
{ 0xf29e5537, 0x0763, 0x4977, \
{ 0x83, 0xc2, 0x3c, 0x93, 0x6c, 0x66, 0xa9, 0xfc } }
/**
* A document viewer is a kind of content viewer that uses NGLayout
* to manage the presentation of the content.
@ -58,8 +58,6 @@ class nsIDocumentViewer : public nsIContentViewer
{
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDOCUMENT_VIEWER_IID)
NS_IMETHOD GetDocument(nsIDocument** aResult) = 0;
NS_IMETHOD GetPresShell(nsIPresShell** aResult) = 0;

Просмотреть файл

@ -79,19 +79,12 @@ nsCOMPtr<nsIDOMNode> GetDOMNodeFromDocShell(nsIDocShell *aShell)
nsCOMPtr<nsIContentViewer> cv;
aShell->GetContentViewer(getter_AddRefs(cv));
if (cv) {
nsCOMPtr<nsIDocumentViewer> docv(do_QueryInterface(cv));
if (docv) {
nsCOMPtr<nsIDocument> doc;
docv->GetDocument(getter_AddRefs(doc));
if (doc) {
nsCOMPtr<nsIDOMDocument> domdoc(do_QueryInterface(doc));
if (domdoc) {
nsCOMPtr<nsIDOMElement> element;
domdoc->GetDocumentElement(getter_AddRefs(element));
if (element)
node = do_QueryInterface(element);
}
}
nsCOMPtr<nsIDOMDocument> domdoc(do_QueryInterface(cv->GetDocument()));
if (domdoc) {
nsCOMPtr<nsIDOMElement> element;
domdoc->GetDocumentElement(getter_AddRefs(element));
if (element)
node = do_QueryInterface(element);
}
}

Просмотреть файл

@ -631,13 +631,8 @@ nsCOMPtr<nsIDOMDocument> nsWebShellWindow::GetNamedDOMDoc(const nsAString & aDoc
childDocShell->GetContentViewer(getter_AddRefs(cv));
if (!cv)
return domDoc;
nsCOMPtr<nsIDocumentViewer> docv(do_QueryInterface(cv));
if (!docv)
return domDoc;
nsCOMPtr<nsIDocument> doc;
docv->GetDocument(getter_AddRefs(doc));
nsIDocument* doc = cv->GetDocument();
if (doc)
return nsCOMPtr<nsIDOMDocument>(do_QueryInterface(doc));
@ -658,11 +653,9 @@ void nsWebShellWindow::LoadContentAreas() {
if (mDocShell)
mDocShell->GetContentViewer(getter_AddRefs(contentViewer));
if (contentViewer) {
nsCOMPtr<nsIDocumentViewer> docViewer = do_QueryInterface(contentViewer);
if (docViewer) {
nsCOMPtr<nsIDocument> doc;
docViewer->GetDocument(getter_AddRefs(doc));
nsIURI *mainURL = doc->GetDocumentURI();
nsIDocument* doc = contentViewer->GetDocument();
if (doc) {
nsIURI* mainURL = doc->GetDocumentURI();
nsCOMPtr<nsIURL> url = do_QueryInterface(mainURL);
if (url) {

Просмотреть файл

@ -270,11 +270,9 @@ NS_IMETHODIMP nsXULWindow::SetZLevel(PRUint32 aLevel)
nsCOMPtr<nsIContentViewer> cv;
mDocShell->GetContentViewer(getter_AddRefs(cv));
nsCOMPtr<nsIDocumentViewer> dv(do_QueryInterface(cv));
if (dv) {
nsCOMPtr<nsIDocument> doc;
dv->GetDocument(getter_AddRefs(doc));
nsCOMPtr<nsIDOMDocumentEvent> docEvent(do_QueryInterface(doc));
if (cv) {
nsCOMPtr<nsIDOMDocumentEvent> docEvent(
do_QueryInterface(cv->GetDocument()));
if (docEvent) {
nsCOMPtr<nsIDOMEvent> event;
docEvent->CreateEvent(NS_LITERAL_STRING("Events"), getter_AddRefs(event));
@ -284,7 +282,7 @@ NS_IMETHODIMP nsXULWindow::SetZLevel(PRUint32 aLevel)
nsCOMPtr<nsIPrivateDOMEvent> privateEvent(do_QueryInterface(event));
privateEvent->SetTrusted(PR_TRUE);
nsCOMPtr<nsIDOMEventTarget> targ(do_QueryInterface(doc));
nsCOMPtr<nsIDOMEventTarget> targ(do_QueryInterface(docEvent));
if (targ) {
PRBool defaultActionEnabled;
targ->DispatchEvent(event, &defaultActionEnabled);
@ -1543,12 +1541,7 @@ NS_IMETHODIMP nsXULWindow::GetWindowDOMElement(nsIDOMElement** aDOMElement)
mDocShell->GetContentViewer(getter_AddRefs(cv));
NS_ENSURE_TRUE(cv, NS_ERROR_FAILURE);
nsCOMPtr<nsIDocumentViewer> docv(do_QueryInterface(cv));
NS_ENSURE_TRUE(docv, NS_ERROR_FAILURE);
nsCOMPtr<nsIDocument> doc;
docv->GetDocument(getter_AddRefs(doc));
nsCOMPtr<nsIDOMDocument> domdoc(do_QueryInterface(doc));
nsCOMPtr<nsIDOMDocument> domdoc(do_QueryInterface(cv->GetDocument()));
NS_ENSURE_TRUE(domdoc, NS_ERROR_FAILURE);
domdoc->GetDocumentElement(aDOMElement);