Skip to content

Commit

Permalink
Bug 540462 - Move GetDocument from nsIDocumentViewer to nsIContentVi…
Browse files Browse the repository at this point in the history
…ewer, r=bz
  • Loading branch information
Olli Pettay authored and Olli Pettay committed Jan 23, 2010
1 parent f580a5f commit 8f9e916
Show file tree
Hide file tree
Showing 14 changed files with 131 additions and 119 deletions.
10 changes: 2 additions & 8 deletions accessible/src/base/nsCoreUtils.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion content/base/src/nsDocument.cpp
Expand Up @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions content/html/document/src/nsHTMLDocument.cpp
Expand Up @@ -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();
}
}

Expand Down
66 changes: 24 additions & 42 deletions docshell/base/nsDocShell.cpp
Expand Up @@ -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;
}
Expand Down Expand Up @@ -2287,22 +2286,20 @@ 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;
NS_IF_ADDREF(*aResult = GetCurrentDocChannel());
return NS_OK;
}

nsCOMPtr<nsIDocument> doc(do_QueryInterface(domDoc));
if (doc) {
*aResult = doc->GetChannel();
NS_IF_ADDREF(*aResult);
nsIChannel*
nsDocShell::GetCurrentDocChannel()
{
if (mContentViewer) {
nsIDocument* doc = mContentViewer->GetDocument();
if (doc) {
return doc->GetChannel();
}
}

return NS_OK;
return nsnull;
}

//*****************************************************************************
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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)
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion docshell/base/nsDocShell.h
Expand Up @@ -614,7 +614,8 @@ class nsDocShell : public nsDocLoader,
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);
Expand Down
9 changes: 8 additions & 1 deletion docshell/base/nsIContentViewer.idl
Expand Up @@ -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
{

Expand Down Expand Up @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions docshell/test/Makefile.in
Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions docshell/test/file_bug540462.html
@@ -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>
45 changes: 45 additions & 0 deletions docshell/test/test_bug540462.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>
32 changes: 11 additions & 21 deletions layout/base/nsDocumentViewer.cpp
Expand Up @@ -322,7 +322,6 @@ class DocumentViewerImpl : public nsIDocumentViewer,
NS_DECL_NSICONTENTVIEWER

// nsIDocumentViewer interface...
NS_IMETHOD GetDocument(nsIDocument** aResult);
NS_IMETHOD GetPresShell(nsIPresShell** aResult);
NS_IMETHOD GetPresContext(nsPresContext** aResult);

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -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);


Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 2 additions & 4 deletions layout/base/nsIDocumentViewer.h
Expand Up @@ -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.
Expand All @@ -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;

Expand Down

0 comments on commit 8f9e916

Please sign in to comment.