Make docshell inherit from docloader; clean up related code, move toward

eliminating the nsIWebShell, nsIWebShellContainer, nsIDocumentLoader
interfaces and clarifying the other docshell-related interfaces.
r=darin, biesi, sr=jst
This commit is contained in:
bzbarsky%mit.edu 2004-12-08 17:32:06 +00:00
Родитель 49695f5b48
Коммит 194e16cd98
21 изменённых файлов: 476 добавлений и 809 удалений

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

@ -43,6 +43,7 @@
#include "nsXPIDLString.h"
#include "nsIServiceManager.h"
#include "nsIDOMWindowInternal.h"
#include "nsAutoPtr.h"
//*****************************************************************************
//*** nsDSURIContentListener: Object Management
@ -209,13 +210,20 @@ nsDSURIContentListener::CanHandleContent(const char* aContentType,
NS_IMETHODIMP
nsDSURIContentListener::GetLoadCookie(nsISupports ** aLoadCookie)
{
return mDocShell->GetLoadCookie(aLoadCookie);
NS_ADDREF(*aLoadCookie = NS_STATIC_CAST(nsIDocumentLoader*, mDocShell));
return NS_OK;
}
NS_IMETHODIMP
nsDSURIContentListener::SetLoadCookie(nsISupports * aLoadCookie)
{
return mDocShell->SetLoadCookie(aLoadCookie);
#ifdef DEBUG
nsRefPtr<nsDocLoader> cookieAsDocLoader =
nsDocLoader::GetAsDocLoader(aLoadCookie);
NS_ASSERTION(cookieAsDocLoader && cookieAsDocLoader == mDocShell,
"Invalid load cookie being set!");
#endif
return NS_OK;
}
NS_IMETHODIMP

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

@ -230,6 +230,7 @@ nsDocShellFocusController nsDocShellFocusController::mDocShellFocusControllerSin
//*****************************************************************************
nsDocShell::nsDocShell():
nsDocLoader(),
mAllowSubframes(PR_TRUE),
mAllowPlugins(PR_TRUE),
mAllowJavascript(PR_TRUE),
@ -256,7 +257,6 @@ nsDocShell::nsDocShell():
mContentListener(nsnull),
mDefaultScrollbarPref(Scrollbar_Auto, Scrollbar_Auto),
mEditorData(nsnull),
mParent(nsnull),
mTreeOwner(nsnull),
mChromeEventHandler(nsnull)
{
@ -286,37 +286,59 @@ nsDocShell::~nsDocShell()
}
}
NS_IMETHODIMP
nsresult
nsDocShell::Init()
{
nsresult rv = nsDocLoader::Init();
NS_ENSURE_SUCCESS(rv, rv);
NS_ASSERTION(mLoadGroup, "Something went wrong!");
// We want to hold a strong ref to the loadgroup, so it better hold a weak
// ref to us... use an InterfaceRequestorProxy to do this.
nsCOMPtr<InterfaceRequestorProxy> proxy =
new InterfaceRequestorProxy(NS_STATIC_CAST(nsIInterfaceRequestor*,
this));
NS_ENSURE_TRUE(proxy, NS_ERROR_OUT_OF_MEMORY);
mLoadGroup->SetNotificationCallbacks(proxy);
rv = nsDocLoader::AddDocLoaderAsChildOfRoot(this);
NS_ENSURE_SUCCESS(rv, rv);
// Add as |this| a progress listener to itself. A little weird, but
// simpler than reproducing all the listener-notification logic in
// overrides of the various methods via which nsDocLoader can be
// notified. Note that this holds an nsWeakPtr to ourselves, so it's ok.
return AddProgressListener(this, nsIWebProgress::NOTIFY_STATE_DOCUMENT |
nsIWebProgress::NOTIFY_STATE_NETWORK);
}
void
nsDocShell::DestroyChildren()
{
PRInt32 i, n = mChildren.Count();
nsCOMPtr<nsIDocShellTreeItem> shell;
for (i = 0; i < n; i++) {
shell = dont_AddRef((nsIDocShellTreeItem *) mChildren.ElementAt(i));
PRInt32 n = mChildList.Count();
for (PRInt32 i = 0; i < n; i++) {
shell = do_QueryInterface(ChildAt(i));
NS_WARN_IF_FALSE(shell, "docshell has null child");
if (shell) {
shell->SetParent(nsnull);
shell->SetTreeOwner(nsnull);
// just clear out the array. When the nsFrameFrame that holds
// the subshell is destroyed, then the Destroy() method of
// that subshell will actually get called.
}
}
mChildren.Clear();
return NS_OK;
nsDocLoader::DestroyChildren();
}
//*****************************************************************************
// nsDocShell::nsISupports
//*****************************************************************************
NS_IMPL_THREADSAFE_ADDREF(nsDocShell)
NS_IMPL_THREADSAFE_RELEASE(nsDocShell)
NS_IMPL_ADDREF_INHERITED(nsDocShell, nsDocLoader)
NS_IMPL_RELEASE_INHERITED(nsDocShell, nsDocLoader)
NS_INTERFACE_MAP_BEGIN(nsDocShell)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDocShell)
NS_INTERFACE_MAP_ENTRY(nsIDocShell)
NS_INTERFACE_MAP_ENTRY(nsIDocShellTreeItem)
NS_INTERFACE_MAP_ENTRY(nsIDocShellTreeNode)
@ -326,7 +348,6 @@ NS_INTERFACE_MAP_BEGIN(nsDocShell)
NS_INTERFACE_MAP_ENTRY(nsIScrollable)
NS_INTERFACE_MAP_ENTRY(nsITextScroll)
NS_INTERFACE_MAP_ENTRY(nsIDocCharset)
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
NS_INTERFACE_MAP_ENTRY(nsIScriptGlobalObjectOwner)
NS_INTERFACE_MAP_ENTRY(nsIRefreshURI)
NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener)
@ -335,7 +356,7 @@ NS_INTERFACE_MAP_BEGIN(nsDocShell)
NS_INTERFACE_MAP_ENTRY(nsIEditorDocShell)
NS_INTERFACE_MAP_ENTRY(nsIWebPageDescriptor)
NS_INTERFACE_MAP_ENTRY(nsIAuthPromptProvider)
NS_INTERFACE_MAP_END_THREADSAFE
NS_INTERFACE_MAP_END_INHERITING(nsDocLoader)
///*****************************************************************************
// nsDocShell::nsIInterfaceRequestor
@ -344,6 +365,8 @@ NS_IMETHODIMP nsDocShell::GetInterface(const nsIID & aIID, void **aSink)
{
NS_PRECONDITION(aSink, "null out param");
*aSink = nsnull;
if (aIID.Equals(NS_GET_IID(nsIURIContentListener)) &&
NS_SUCCEEDED(EnsureContentListener())) {
*aSink = mContentListener;
@ -354,35 +377,25 @@ NS_IMETHODIMP nsDocShell::GetInterface(const nsIID & aIID, void **aSink)
}
else if (aIID.Equals(NS_GET_IID(nsIDOMWindowInternal)) &&
NS_SUCCEEDED(EnsureScriptEnvironment())) {
NS_ENSURE_SUCCESS(mScriptGlobal->
QueryInterface(NS_GET_IID(nsIDOMWindowInternal),
aSink), NS_ERROR_FAILURE);
return NS_OK;
return mScriptGlobal->QueryInterface(aIID, aSink);
}
else if (aIID.Equals(NS_GET_IID(nsPIDOMWindow)) &&
NS_SUCCEEDED(EnsureScriptEnvironment())) {
NS_ENSURE_SUCCESS(mScriptGlobal->
QueryInterface(NS_GET_IID(nsPIDOMWindow), aSink),
NS_ERROR_FAILURE);
return NS_OK;
return mScriptGlobal->QueryInterface(aIID, aSink);
}
else if (aIID.Equals(NS_GET_IID(nsIDOMWindow)) &&
NS_SUCCEEDED(EnsureScriptEnvironment())) {
NS_ENSURE_SUCCESS(mScriptGlobal->
QueryInterface(NS_GET_IID(nsIDOMWindow), aSink),
NS_ERROR_FAILURE);
return NS_OK;
return mScriptGlobal->QueryInterface(aIID, aSink);
}
else if (aIID.Equals(NS_GET_IID(nsIDOMDocument)) &&
NS_SUCCEEDED(EnsureContentViewer())) {
mContentViewer->GetDOMDocument((nsIDOMDocument **) aSink);
return NS_OK;
return *aSink ? NS_OK : NS_NOINTERFACE;
}
else if (aIID.Equals(NS_GET_IID(nsIPrompt))) {
nsCOMPtr<nsIPrompt> prompter(do_GetInterface(mTreeOwner));
if (prompter) {
*aSink = prompter;
NS_ADDREF((nsISupports *) * aSink);
prompter.swap((nsIPrompt*) *aSink);
return NS_OK;
}
else
@ -394,27 +407,6 @@ NS_IMETHODIMP nsDocShell::GetInterface(const nsIID & aIID, void **aSink)
NS_OK : NS_NOINTERFACE;
}
else if (aIID.Equals(NS_GET_IID(nsIProgressEventSink))
|| aIID.Equals(NS_GET_IID(nsIHttpEventSink))
|| aIID.Equals(NS_GET_IID(nsIWebProgress))
|| aIID.Equals(NS_GET_IID(nsISecurityEventSink))) {
nsCOMPtr<nsIURILoader>
uriLoader(do_GetService(NS_URI_LOADER_CONTRACTID));
NS_ENSURE_TRUE(uriLoader, NS_ERROR_FAILURE);
nsCOMPtr<nsIDocumentLoader> docLoader;
NS_ENSURE_SUCCESS(uriLoader->
GetDocumentLoaderForContext(this,
getter_AddRefs
(docLoader)),
NS_ERROR_FAILURE);
if (docLoader) {
nsCOMPtr<nsIInterfaceRequestor>
requestor(do_QueryInterface(docLoader));
return requestor->GetInterface(aIID, aSink);
}
else
return NS_ERROR_FAILURE;
}
else if (aIID.Equals(NS_GET_IID(nsISHistory))) {
nsCOMPtr<nsISHistory> shistory;
nsresult
@ -466,11 +458,11 @@ NS_IMETHODIMP nsDocShell::GetInterface(const nsIID & aIID, void **aSink)
return treeOwner->QueryInterface(aIID, aSink);
}
else {
return QueryInterface(aIID, aSink);
return nsDocLoader::GetInterface(aIID, aSink);
}
NS_IF_ADDREF(((nsISupports *) * aSink));
return NS_OK;
return *aSink ? NS_OK : NS_NOINTERFACE;
}
PRUint32
@ -838,11 +830,9 @@ nsDocShell::FireUnloadNotification()
mContentViewer->Unload();
PRInt32 i, n = mChildren.Count();
PRInt32 i, n = mChildList.Count();
for (i = 0; i < n; i++) {
nsIDocShellTreeItem* item = (nsIDocShellTreeItem*) mChildren.ElementAt(i);
nsCOMPtr<nsIDocShell> shell(do_QueryInterface(item));
nsCOMPtr<nsIDocShell> shell(do_QueryInterface(ChildAt(i)));
if (shell) {
shell->FireUnloadNotification();
}
@ -1373,11 +1363,6 @@ nsDocShell::SetCurrentURI(nsIURI *aURI)
PRBool isRoot = PR_FALSE; // Is this the root docshell
PRBool isSubFrame = PR_FALSE; // Is this a subframe navigation?
if (!mLoadCookie)
return NS_OK;
nsCOMPtr<nsIDocumentLoader> loader(do_GetInterface(mLoadCookie));
nsCOMPtr<nsIWebProgress> webProgress(do_QueryInterface(mLoadCookie));
nsCOMPtr<nsIDocShellTreeItem> root;
GetSameTypeRootTreeItem(getter_AddRefs(root));
@ -1404,10 +1389,7 @@ nsDocShell::SetCurrentURI(nsIURI *aURI)
return NS_OK;
}
NS_ASSERTION(loader, "No document loader");
if (loader) {
loader->FireOnLocationChange(webProgress, nsnull, aURI);
}
FireOnLocationChange(this, nsnull, aURI);
return NS_OK;
}
@ -1756,7 +1738,14 @@ NS_IMETHODIMP
nsDocShell::SetItemType(PRInt32 aItemType)
{
NS_ENSURE_ARG((aItemType == typeChrome) || (typeContent == aItemType));
NS_ENSURE_STATE(!mParent);
// Only allow setting the type on root docshells. Those would be the ones
// that have the docloader service as mParent or have no mParent at all.
nsCOMPtr<nsIDocumentLoader> docLoaderService =
do_GetService(NS_DOCUMENTLOADER_SERVICE_CONTRACTID);
NS_ENSURE_TRUE(docLoaderService, NS_ERROR_UNEXPECTED);
NS_ENSURE_STATE(!mParent || mParent == docLoaderService);
mItemType = aItemType;
@ -1769,28 +1758,27 @@ nsDocShell::SetItemType(PRInt32 aItemType)
NS_IMETHODIMP
nsDocShell::GetParent(nsIDocShellTreeItem ** aParent)
{
NS_ENSURE_ARG_POINTER(aParent);
*aParent = mParent;
NS_IF_ADDREF(*aParent);
if (!mParent) {
*aParent = nsnull;
} else {
CallQueryInterface(mParent, aParent);
}
// Note that in the case when the parent is not an nsIDocShellTreeItem we
// don't want to throw; we just want to return null.
return NS_OK;
}
NS_IMETHODIMP
nsDocShell::SetParent(nsIDocShellTreeItem * aParent)
nsresult
nsDocShell::SetDocLoaderParent(nsDocLoader * aParent)
{
// null aParent is ok
/*
Note this doesn't do an addref on purpose. This is because the parent
is an implied lifetime. We don't want to create a cycle by refcounting
the parent.
*/
mParent = aParent;
nsDocLoader::SetDocLoaderParent(aParent);
// Curse ambiguous nsISupports inheritance!
nsISupports* parent = GetAsSupports(aParent);
// If parent is another docshell, we inherit all their flags for
// allowing plugins, scripting etc.
nsCOMPtr<nsIDocShell> parentAsDocShell = do_QueryInterface(mParent);
nsCOMPtr<nsIDocShell> parentAsDocShell(do_QueryInterface(parent));
if (parentAsDocShell)
{
PRBool value;
@ -1816,8 +1804,7 @@ nsDocShell::SetParent(nsIDocShellTreeItem * aParent)
}
}
nsCOMPtr<nsIURIContentListener>
parentURIListener(do_GetInterface(aParent));
nsCOMPtr<nsIURIContentListener> parentURIListener(do_GetInterface(parent));
if (parentURIListener)
SetParentURIContentListener(parentURIListener);
return NS_OK;
@ -1829,15 +1816,16 @@ nsDocShell::GetSameTypeParent(nsIDocShellTreeItem ** aParent)
NS_ENSURE_ARG_POINTER(aParent);
*aParent = nsnull;
if (!mParent)
nsCOMPtr<nsIDocShellTreeItem> parent =
do_QueryInterface(GetAsSupports(mParent));
if (!parent)
return NS_OK;
PRInt32 parentType;
NS_ENSURE_SUCCESS(mParent->GetItemType(&parentType), NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(parent->GetItemType(&parentType), NS_ERROR_FAILURE);
if (parentType == mItemType) {
*aParent = mParent;
NS_ADDREF(*aParent);
parent.swap(*aParent);
}
return NS_OK;
}
@ -1929,22 +1917,24 @@ nsDocShell::FindItemWithName(const PRUnichar * aName,
// and let the parent do the rest.
// If we don't have a parent, then we should ask the docShellTreeOwner to do
// the search.
if (mParent) {
if (mParent == reqAsTreeItem.get())
nsCOMPtr<nsIDocShellTreeItem> parentAsTreeItem =
do_QueryInterface(GetAsSupports(mParent));
if (parentAsTreeItem) {
if (parentAsTreeItem == reqAsTreeItem)
return NS_OK;
PRInt32 parentType;
mParent->GetItemType(&parentType);
parentAsTreeItem->GetItemType(&parentType);
if (parentType == mItemType) {
NS_ENSURE_SUCCESS(mParent->FindItemWithName(aName,
NS_STATIC_CAST
(nsIDocShellTreeItem *,
this), _retval),
NS_ERROR_FAILURE);
return NS_OK;
return parentAsTreeItem->FindItemWithName(aName,
NS_STATIC_CAST
(nsIDocShellTreeItem *,
this), _retval);
}
// If the parent isn't of the same type fall through and ask tree owner.
}
// If the parent is null or not of the same type fall through and ask tree
// owner.
// This may fail, but comparing against null serves the same purpose
nsCOMPtr<nsIDocShellTreeOwner>
@ -2057,7 +2047,8 @@ nsDocShell::SetTreeOwner(nsIDocShellTreeOwner * aTreeOwner)
// Don't automatically set the progress based on the tree owner for frames
if (!IsFrame()) {
nsCOMPtr<nsIWebProgress> webProgress(do_QueryInterface(mLoadCookie));
nsCOMPtr<nsIWebProgress> webProgress =
do_QueryInterface(GetAsSupports(this));
if (webProgress) {
nsCOMPtr<nsIWebProgressListener>
@ -2078,9 +2069,9 @@ nsDocShell::SetTreeOwner(nsIDocShellTreeOwner * aTreeOwner)
mTreeOwner = aTreeOwner; // Weak reference per API
PRInt32 i, n = mChildren.Count();
PRInt32 i, n = mChildList.Count();
for (i = 0; i < n; i++) {
nsIDocShellTreeItem *child = (nsIDocShellTreeItem *) mChildren.ElementAt(i); // doesn't addref the result
nsCOMPtr<nsIDocShellTreeItem> child = do_QueryInterface(ChildAt(i));
NS_ENSURE_TRUE(child, NS_ERROR_FAILURE);
PRInt32 childType = ~mItemType; // Set it to not us in case the get fails
child->GetItemType(&childType); // We don't care if this fails, if it does we won't set the owner
@ -2114,7 +2105,7 @@ NS_IMETHODIMP
nsDocShell::GetChildCount(PRInt32 * aChildCount)
{
NS_ENSURE_ARG_POINTER(aChildCount);
*aChildCount = mChildren.Count();
*aChildCount = mChildList.Count();
return NS_OK;
}
@ -2125,15 +2116,35 @@ nsDocShell::AddChild(nsIDocShellTreeItem * aChild)
{
NS_ENSURE_ARG_POINTER(aChild);
NS_ENSURE_SUCCESS(aChild->SetParent(this), NS_ERROR_FAILURE);
mChildren.AppendElement(aChild);
NS_ADDREF(aChild);
nsRefPtr<nsDocLoader> childAsDocLoader = GetAsDocLoader(aChild);
NS_ENSURE_TRUE(childAsDocLoader, NS_ERROR_UNEXPECTED);
// Make sure we're not creating a loop in the docshell tree
nsDocLoader* ancestor = this;
do {
if (childAsDocLoader == ancestor) {
return NS_ERROR_ILLEGAL_VALUE;
}
ancestor = ancestor->GetParent();
} while (ancestor);
// Make sure to remove the child from its current parent.
nsDocLoader* childsParent = childAsDocLoader->GetParent();
if (childsParent) {
childsParent->RemoveChildLoader(childAsDocLoader);
}
// Make sure to clear the treeowner in case this child is a different type
// from us.
aChild->SetTreeOwner(nsnull);
nsresult res = AddChildLoader(childAsDocLoader);
NS_ENSURE_SUCCESS(res, res);
// Set the child's index in the parent's children list
// XXX What if the parent had different types of children?
// XXX in that case docshell hierarchyand SH hierarchy won't match.
PRInt32 childCount = mChildren.Count();
aChild->SetChildOffset(childCount - 1);
// XXX in that case docshell hierarchy and SH hierarchy won't match.
aChild->SetChildOffset(mChildList.Count() - 1);
/* Set the child's global history if the parent has one */
if (mGlobalHistory) {
@ -2171,8 +2182,6 @@ nsDocShell::AddChild(nsIDocShellTreeItem * aChild)
if (mItemType == nsIDocShellTreeItem::typeChrome)
return NS_OK;
nsresult res = NS_OK;
// get the child's docCSInfo object
nsCOMPtr<nsIDocumentCharsetInfo> dcInfo = NULL;
res = childAsDocShell->GetDocumentCharsetInfo(getter_AddRefs(dcInfo));
@ -2226,15 +2235,15 @@ nsDocShell::RemoveChild(nsIDocShellTreeItem * aChild)
{
NS_ENSURE_ARG_POINTER(aChild);
if (mChildren.RemoveElement(aChild)) {
aChild->SetParent(nsnull);
aChild->SetTreeOwner(nsnull);
NS_RELEASE(aChild);
}
else
NS_ENSURE_TRUE(PR_FALSE, NS_ERROR_INVALID_ARG);
nsRefPtr<nsDocLoader> childAsDocLoader = GetAsDocLoader(aChild);
NS_ENSURE_TRUE(childAsDocLoader, NS_ERROR_UNEXPECTED);
nsresult rv = RemoveChildLoader(childAsDocLoader);
NS_ENSURE_SUCCESS(rv, rv);
aChild->SetTreeOwner(nsnull);
return NS_OK;
return nsDocLoader::AddDocLoaderAsChildOfRoot(childAsDocLoader);
}
NS_IMETHODIMP
@ -2242,11 +2251,13 @@ nsDocShell::GetChildAt(PRInt32 aIndex, nsIDocShellTreeItem ** aChild)
{
NS_ENSURE_ARG_POINTER(aChild);
NS_WARN_IF_FALSE(aIndex >=0 && aIndex < mChildren.Count(), "index of child element is out of range!");
*aChild = (nsIDocShellTreeItem *) mChildren.SafeElementAt(aIndex);
NS_IF_ADDREF(*aChild);
NS_WARN_IF_FALSE(aIndex >=0 && aIndex < mChildList.Count(),
"index of child element is out of range!");
return NS_OK;
nsIDocumentLoader* child = SafeChildAt(aIndex);
NS_ENSURE_TRUE(child, NS_ERROR_UNEXPECTED);
return CallQueryInterface(child, aChild);
}
NS_IMETHODIMP
@ -2261,9 +2272,9 @@ nsDocShell::FindChildWithName(const PRUnichar * aName,
*_retval = nsnull; // if we don't find one, we return NS_OK and a null result
nsXPIDLString childName;
PRInt32 i, n = mChildren.Count();
PRInt32 i, n = mChildList.Count();
for (i = 0; i < n; i++) {
nsIDocShellTreeItem *child = (nsIDocShellTreeItem *) mChildren.ElementAt(i); // doesn't addref the result
nsCOMPtr<nsIDocShellTreeItem> child = do_QueryInterface(ChildAt(i));
NS_ENSURE_TRUE(child, NS_ERROR_FAILURE);
PRInt32 childType;
child->GetItemType(&childType);
@ -2418,7 +2429,8 @@ nsDocShell::AddChildSHEntry(nsISHEntry * aCloneRef, nsISHEntry * aNewEntry,
}
else {
/* Just pass this along */
nsCOMPtr<nsIDocShellHistory> parent(do_QueryInterface(mParent, &rv));
nsCOMPtr<nsIDocShellHistory> parent =
do_QueryInterface(GetAsSupports(mParent), &rv);
if (parent) {
rv = parent->AddChildSHEntry(aCloneRef, aNewEntry, aChildOffset);
}
@ -2437,7 +2449,8 @@ nsDocShell::DoAddChildSHEntry(nsISHEntry* aNewEntry, PRInt32 aChildOffset)
*/
nsresult rv;
nsCOMPtr<nsIDocShellHistory> parent(do_QueryInterface(mParent, &rv));
nsCOMPtr<nsIDocShellHistory> parent =
do_QueryInterface(GetAsSupports(mParent), &rv);
if (parent) {
rv = parent->AddChildSHEntry(mOSHE, aNewEntry, aChildOffset);
}
@ -2921,21 +2934,16 @@ nsDocShell::Stop(PRUint32 aStopFlags)
// Cancel any timers that were set for this loader.
CancelRefreshURITimers();
if (mLoadCookie) {
nsCOMPtr<nsIURILoader> uriLoader;
uriLoader = do_GetService(NS_URI_LOADER_CONTRACTID);
if (uriLoader)
uriLoader->Stop(mLoadCookie);
}
// XXXbz We could also pass |this| to nsIURILoader::Stop. That will
// just call Stop() on us as an nsIDocumentLoader... We need fewer
// redundant apis!
Stop();
}
PRInt32 n;
PRInt32 count = mChildren.Count();
PRInt32 count = mChildList.Count();
for (n = 0; n < count; n++) {
nsIDocShellTreeItem *shell =
(nsIDocShellTreeItem *) mChildren.ElementAt(n);
nsCOMPtr<nsIWebNavigation> shellAsNav(do_QueryInterface(shell));
nsCOMPtr<nsIWebNavigation> shellAsNav(do_QueryInterface(ChildAt(n)));
if (shellAsNav)
shellAsNav->Stop(aStopFlags);
}
@ -3163,8 +3171,8 @@ nsDocShell::Destroy()
PersistLayoutHistoryState();
// Remove this docshell from its parent's child list
nsCOMPtr<nsIDocShellTreeNode>
docShellParentAsNode(do_QueryInterface(mParent));
nsCOMPtr<nsIDocShellTreeNode> docShellParentAsNode =
do_QueryInterface(GetAsSupports(mParent));
if (docShellParentAsNode)
docShellParentAsNode->RemoveChild(this);
@ -3174,8 +3182,8 @@ nsDocShell::Destroy()
mContentViewer = nsnull;
}
DestroyChildren();
nsDocLoader::Destroy();
mParentWidget = nsnull;
mCurrentURI = nsnull;
@ -3192,8 +3200,6 @@ nsDocShell::Destroy()
mSessionHistory = nsnull;
SetTreeOwner(nsnull);
SetLoadCookie(nsnull);
if (mContentListener) {
mContentListener->DocShell(nsnull);
mContentListener->SetParentContentListener(nsnull);
@ -4224,7 +4230,8 @@ nsDocShell::OnStateChange(nsIWebProgress * aProgress, nsIRequest * aRequest,
// Update the busy cursor
if ((~aStateFlags & (STATE_START | STATE_IS_NETWORK)) == 0) {
nsCOMPtr<nsIWyciwygChannel> wcwgChannel(do_QueryInterface(aRequest));
nsCOMPtr<nsIWebProgress> webProgress(do_QueryInterface(mLoadCookie));
nsCOMPtr<nsIWebProgress> webProgress =
do_QueryInterface(GetAsSupports(this));
// Was the wyciwyg document loaded on this docshell?
if (wcwgChannel && !mLSHE && (mItemType == typeContent) && aProgress == webProgress.get()) {
@ -4271,7 +4278,8 @@ nsDocShell::OnStateChange(nsIWebProgress * aProgress, nsIRequest * aRequest,
}
}
if ((~aStateFlags & (STATE_IS_DOCUMENT | STATE_STOP)) == 0) {
nsCOMPtr<nsIWebProgress> webProgress(do_QueryInterface(mLoadCookie));
nsCOMPtr<nsIWebProgress> webProgress =
do_QueryInterface(GetAsSupports(this));
// Is the document stop notification for this document?
if (aProgress == webProgress.get()) {
nsCOMPtr<nsIChannel> channel(do_QueryInterface(aRequest));
@ -4280,7 +4288,8 @@ nsDocShell::OnStateChange(nsIWebProgress * aProgress, nsIRequest * aRequest,
}
else if ((~aStateFlags & (STATE_IS_DOCUMENT | STATE_REDIRECTING)) == 0) {
// XXX Is it enough if I check just for the above 2 flags for redirection
nsCOMPtr<nsIWebProgress> webProgress(do_QueryInterface(mLoadCookie));
nsCOMPtr<nsIWebProgress> webProgress =
do_QueryInterface(GetAsSupports(this));
// Is the document stop notification for this document?
if (aProgress == webProgress.get()) {
@ -4462,11 +4471,8 @@ nsDocShell::CreateAboutBlankContentViewer()
nsCOMPtr<nsIDocumentLoaderFactory> docFactory(do_GetService(contractId));
if (docFactory) {
nsCOMPtr<nsILoadGroup> loadGroup(do_GetInterface(mLoadCookie));
// generate (about:blank) document to load
docFactory->CreateBlankDocument(loadGroup, getter_AddRefs(blankDoc));
docFactory->CreateBlankDocument(mLoadGroup, getter_AddRefs(blankDoc));
if (blankDoc) {
blankDoc->SetContainer(NS_STATIC_CAST(nsIDocShell *, this));
@ -4500,12 +4506,11 @@ nsDocShell::CreateContentViewer(const char *aContentType,
// Can we check the content type of the current content viewer
// and reuse it without destroying it and re-creating it?
nsCOMPtr<nsILoadGroup> loadGroup(do_GetInterface(mLoadCookie));
NS_ENSURE_TRUE(loadGroup, NS_ERROR_FAILURE);
NS_ASSERTION(mLoadGroup, "Someone ignored return from Init()?");
// Instantiate the content viewer object
nsCOMPtr<nsIContentViewer> viewer;
nsresult rv = NewContentViewerObj(aContentType, request, loadGroup,
nsresult rv = NewContentViewerObj(aContentType, request, mLoadGroup,
aContentHandler, getter_AddRefs(viewer));
if (NS_FAILED(rv))
@ -4536,7 +4541,7 @@ nsDocShell::CreateContentViewer(const char *aContentType,
GetLoadGroup(getter_AddRefs(currentLoadGroup)),
NS_ERROR_FAILURE);
if (currentLoadGroup.get() != loadGroup.get()) {
if (currentLoadGroup != mLoadGroup) {
nsLoadFlags loadFlags = 0;
//Cancel any URIs that are currently loading...
@ -4550,7 +4555,7 @@ nsDocShell::CreateContentViewer(const char *aContentType,
* we don't null-out mLSHE in OnStateChange() for
* all redirected urls
*/
aOpenedChannel->SetLoadGroup(loadGroup);
aOpenedChannel->SetLoadGroup(mLoadGroup);
// Mark the channel as being a document URI...
aOpenedChannel->GetLoadFlags(&loadFlags);
@ -4558,7 +4563,7 @@ nsDocShell::CreateContentViewer(const char *aContentType,
aOpenedChannel->SetLoadFlags(loadFlags);
loadGroup->AddRequest(request, nsnull);
mLoadGroup->AddRequest(request, nsnull);
if (currentLoadGroup)
currentLoadGroup->RemoveRequest(request, nsnull,
NS_BINDING_RETARGETED);
@ -6581,53 +6586,6 @@ nsDocShell::AddToGlobalHistory(nsIURI * aURI, PRBool aRedirect, nsIURI * aReferr
// nsDocShell: Helper Routines
//*****************************************************************************
nsresult
nsDocShell::SetLoadCookie(nsISupports * aCookie)
{
// Remove the DocShell as a listener of the old WebProgress...
if (mLoadCookie) {
nsCOMPtr<nsIWebProgress> webProgress(do_QueryInterface(mLoadCookie));
if (webProgress) {
webProgress->RemoveProgressListener(this);
}
}
mLoadCookie = aCookie;
// Add the DocShell as a listener to the new WebProgress...
if (mLoadCookie) {
nsCOMPtr<nsIWebProgress> webProgress(do_QueryInterface(mLoadCookie));
if (webProgress) {
webProgress->AddProgressListener(this,
nsIWebProgress::NOTIFY_STATE_DOCUMENT |
nsIWebProgress::NOTIFY_STATE_NETWORK);
}
nsCOMPtr<nsILoadGroup> loadGroup(do_GetInterface(mLoadCookie));
NS_ENSURE_TRUE(loadGroup, NS_ERROR_FAILURE);
if (loadGroup) {
nsIInterfaceRequestor *ifPtr = NS_STATIC_CAST(nsIInterfaceRequestor *, this);
nsCOMPtr<InterfaceRequestorProxy> ptr(new InterfaceRequestorProxy(ifPtr));
if (ptr) {
loadGroup->SetNotificationCallbacks(ptr);
}
}
}
return NS_OK;
}
nsresult
nsDocShell::GetLoadCookie(nsISupports ** aResult)
{
*aResult = mLoadCookie;
NS_IF_ADDREF(*aResult);
return NS_OK;
}
NS_IMETHODIMP
nsDocShell::SetLoadType(PRUint32 aLoadType)
{
@ -6831,9 +6789,11 @@ NS_IMETHODIMP nsDocShell::EnsureFind()
PRBool
nsDocShell::IsFrame()
{
if (mParent) {
nsCOMPtr<nsIDocShellTreeItem> parent =
do_QueryInterface(GetAsSupports(mParent));
if (parent) {
PRInt32 parentType = ~mItemType; // Not us
mParent->GetItemType(&parentType);
parent->GetItemType(&parentType);
if (parentType == mItemType) // This is a frame
return PR_TRUE;
}

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

@ -56,7 +56,7 @@
#include "nsIContentViewerContainer.h"
#include "nsIDeviceContext.h"
#include "nsIDocumentLoader.h"
#include "nsDocLoader.h"
#include "nsIURILoader.h"
#include "nsIEditorDocShell.h"
@ -179,7 +179,8 @@ protected:
//*** nsDocShell
//*****************************************************************************
class nsDocShell : public nsIDocShell,
class nsDocShell : public nsDocLoader,
public nsIDocShell,
public nsIDocShellTreeItem,
public nsIDocShellTreeNode,
public nsIDocShellHistory,
@ -189,14 +190,12 @@ class nsDocShell : public nsIDocShell,
public nsITextScroll,
public nsIDocCharset,
public nsIContentViewerContainer,
public nsIInterfaceRequestor,
public nsIScriptGlobalObjectOwner,
public nsIRefreshURI,
public nsIWebProgressListener,
public nsIEditorDocShell,
public nsIWebPageDescriptor,
public nsIAuthPromptProvider,
public nsSupportsWeakReference
public nsIAuthPromptProvider
{
friend class nsDSURIContentListener;
@ -204,7 +203,9 @@ public:
// Object Management
nsDocShell();
NS_DECL_ISUPPORTS
virtual nsresult Init();
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIDOCSHELL
NS_DECL_NSIDOCSHELLTREEITEM
@ -223,8 +224,16 @@ public:
NS_DECL_NSIWEBPAGEDESCRIPTOR
NS_DECL_NSIAUTHPROMPTPROVIDER
nsresult SetLoadCookie(nsISupports * aCookie);
nsresult GetLoadCookie(nsISupports ** aResult);
NS_IMETHOD Stop() {
// Need this here because otherwise nsIWebNavigation::Stop
// overrides the docloader's Stop()
return nsDocLoader::Stop();
}
// Need to implement (and forward) nsISecurityEventSink, because
// nsIWebProgressListener has methods with identical names...
NS_FORWARD_NSISECURITYEVENTSINK(nsDocLoader::)
nsDocShellInfoLoadType ConvertLoadTypeToDocShellLoadInfo(PRUint32 aLoadType);
PRUint32 ConvertDocShellLoadInfoToLoadType(nsDocShellInfoLoadType aDocShellLoadType);
@ -233,7 +242,7 @@ public:
protected:
// Object Management
virtual ~nsDocShell();
NS_IMETHOD DestroyChildren();
virtual void DestroyChildren();
// Content Viewer Management
NS_IMETHOD EnsureContentViewer();
@ -333,6 +342,9 @@ protected:
nsresult CheckLoadingPermissions();
protected:
// Override the parent setter from nsDocLoader
virtual nsresult SetDocLoaderParent(nsDocLoader * aLoader);
PRPackedBool mAllowSubframes;
PRPackedBool mAllowPlugins;
PRPackedBool mAllowJavascript;
@ -383,7 +395,6 @@ protected:
* session history entries.
*/
nsCString mContentTypeHint;
nsVoidArray mChildren;
nsCOMPtr<nsISupportsArray> mRefreshURIList;
nsDSURIContentListener * mContentListener;
nsRect mBounds; // Dimensions of the docshell
@ -398,7 +409,6 @@ protected:
nsCOMPtr<nsIScriptContext> mScriptContext;
nsCOMPtr<nsISHistory> mSessionHistory;
nsCOMPtr<nsIGlobalHistory2> mGlobalHistory;
nsCOMPtr<nsISupports> mLoadCookie; // the load cookie associated with the window context.
nsCOMPtr<nsIWebBrowserFind> mFind;
nsPoint mDefaultScrollbarPref; // persistent across doc loads
// Reference to the SHEntry for this docshell until the page is destroyed.
@ -418,7 +428,6 @@ protected:
// Note these are intentionally not addrefd. Doing so will create a cycle.
// For that reasons don't use nsCOMPtr.
nsIDocShellTreeItem * mParent; // Weak Reference
nsIDocShellTreeOwner * mTreeOwner; // Weak Reference
nsIChromeEventHandler * mChromeEventHandler; //Weak Reference

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

@ -48,7 +48,7 @@ interface nsIDocShellTreeOwner;
* node or a leaf.
*/
[scriptable, uuid(B52AE780-A966-11d3-AFC7-00A024FFC08C)]
[scriptable, uuid(1b3416f3-0ec6-49e6-8bdf-77bfdbc4a102)]
interface nsIDocShellTreeItem : nsISupports
{
/*
@ -81,17 +81,9 @@ interface nsIDocShellTreeItem : nsISupports
attribute long itemType;
/*
Parent DocShell.. Note Implementers of this interface should NOT effect
the lifetime of the parent DocShellTreeItem by holding this reference as it
creates a cycle. Parents when releasing this interface should set the
parent to nsnull. Implementers of this interface are guaranteed that when
parent is set that the pointer is valid without having to addref.
Further note however when others try to Get the interface you should add
ref it before handing it to them.
Parent DocShell.
*/
readonly attribute nsIDocShellTreeItem parent;
[noscript] void setParent(in nsIDocShellTreeItem parent);
/*
This is call returns the same thing parent does however if the parent is

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

@ -47,6 +47,9 @@
* into a docshell tree.
*/
// XXXbz this interface should probably inherit from nsIDocShellTreeItem, and
// some methods should move from there to here...
[scriptable, uuid(C094F810-A8AB-11d3-AFC6-00A024FFC08C)]
interface nsIDocShellTreeNode : nsISupports
{
@ -58,11 +61,17 @@ interface nsIDocShellTreeNode : nsISupports
/*
Add a new child DocShellTreeItem. Adds to the end of the list.
Note that this does NOT take a reference to the child. The child stays
alive only as long as it's referenced from outside the docshell tree.
@throws NS_ERROR_ILLEGAL_VALUE if child corresponds to the same
object as this treenode or an ancestor of this treenode.
// XXXbz this should take an nsIDocShellTreeNode, I think.
*/
void addChild(in nsIDocShellTreeItem child);
/*
Removes a child DocShellTreeItem.
// XXXbz this should take an nsIDocShellTreeNode, I think.
*/
void removeChild(in nsIDocShellTreeItem child);
@ -80,6 +89,7 @@ interface nsIDocShellTreeNode : nsISupports
tree again when a child has asked a parent to search for children.
Note the search is depth first when recursing.
// XXXbz this should return an nsIDocShellTreeNode, I think.
*/
nsIDocShellTreeItem findChildWithName(in wstring aName, in boolean aRecurse,
in boolean aSameType, in nsIDocShellTreeItem aRequestor);

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

@ -183,13 +183,6 @@ nsWebShell::~nsWebShell()
{
Destroy();
// Stop any pending document loads and destroy the loader...
if (mDocLoader) {
mDocLoader->Stop();
mDocLoader->SetContainer(nsnull);
mDocLoader->Destroy();
mDocLoader = nsnull;
}
// Cancel any timers that were set for this loader.
CancelRefreshURITimers();
@ -264,55 +257,19 @@ NS_INTERFACE_MAP_END_INHERITING(nsDocShell)
NS_IMETHODIMP
nsWebShell::GetInterface(const nsIID &aIID, void** aInstancePtr)
{
NS_ENSURE_ARG_POINTER(aInstancePtr);
nsresult rv = NS_OK;
NS_PRECONDITION(aInstancePtr, "null out param");
*aInstancePtr = nsnull;
if(aIID.Equals(NS_GET_IID(nsILinkHandler)))
{
// Note: If we ever allow for registering other link handlers,
// we need to make sure that link handler implementations take
// the necessary precautions to prevent the security compromise
// that is blocked by nsWebSell::OnLinkClickSync().
*aInstancePtr = NS_STATIC_CAST(nsILinkHandler*, this);
NS_ADDREF((nsISupports*)*aInstancePtr);
return NS_OK;
}
else if(aIID.Equals(NS_GET_IID(nsIScriptGlobalObjectOwner)))
{
*aInstancePtr = NS_STATIC_CAST(nsIScriptGlobalObjectOwner*, this);
NS_ADDREF((nsISupports*)*aInstancePtr);
return NS_OK;
}
else if(aIID.Equals(NS_GET_IID(nsIScriptGlobalObject)))
{
NS_ENSURE_SUCCESS(EnsureScriptEnvironment(), NS_ERROR_FAILURE);
*aInstancePtr = mScriptGlobal;
NS_ADDREF((nsISupports*)*aInstancePtr);
return NS_OK;
}
else if(aIID.Equals(NS_GET_IID(nsIDOMWindowInternal)) ||
aIID.Equals(NS_GET_IID(nsIDOMWindow)))
{
NS_ENSURE_SUCCESS(EnsureScriptEnvironment(), NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(mScriptGlobal->QueryInterface(aIID, aInstancePtr),
NS_ERROR_FAILURE);
return NS_OK;
}
else if(aIID.Equals(NS_GET_IID(nsICommandManager)))
if(aIID.Equals(NS_GET_IID(nsICommandManager)))
{
NS_ENSURE_SUCCESS(EnsureCommandHandler(), NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(mCommandManager->QueryInterface(NS_GET_IID(nsICommandManager),
aInstancePtr), NS_ERROR_FAILURE);
*aInstancePtr = mCommandManager;
NS_ADDREF((nsISupports*) *aInstancePtr);
return NS_OK;
}
if (!*aInstancePtr || NS_FAILED(rv))
return nsDocShell::GetInterface(aIID,aInstancePtr);
else
return rv;
return nsDocShell::GetInterface(aIID, aInstancePtr);
}
NS_IMETHODIMP
@ -340,19 +297,6 @@ nsWebShell::HandleEvent(nsGUIEvent *aEvent)
}
/**
* Document Load methods
*/
NS_IMETHODIMP
nsWebShell::GetDocumentLoader(nsIDocumentLoader*& aResult)
{
aResult = mDocLoader;
if (!mDocLoader)
return NS_ERROR_FAILURE;
NS_ADDREF(aResult);
return NS_OK;
}
//----------------------------------------------------------------------
// Web Shell Services API
@ -1194,22 +1138,6 @@ NS_IMETHODIMP nsWebShell::Create()
WEB_TRACE(WEB_TRACE_CALLS,
("nsWebShell::Init: this=%p", this));
// HACK....force the uri loader to give us a load cookie for this webshell...then get its
// doc loader and store it...as more of the docshell lands, we'll be able to get rid
// of this hack...
nsresult rv;
nsCOMPtr<nsIURILoader> uriLoader = do_GetService(NS_URI_LOADER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = uriLoader->GetDocumentLoaderForContext(this,
getter_AddRefs(mDocLoader));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIContentViewerContainer> shellAsContainer;
CallQueryInterface(this, NS_STATIC_CAST(nsIContentViewerContainer**, getter_AddRefs(shellAsContainer)));
// Set the webshell as the default IContentViewerContainer for the loader...
mDocLoader->SetContainer(shellAsContainer);
return nsDocShell::Create();
}
@ -1217,7 +1145,7 @@ NS_IMETHODIMP nsWebShell::Destroy()
{
nsDocShell::Destroy();
SetContainer(nsnull);
NS_IF_RELEASE(mContainer);
return NS_OK;
}

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

@ -83,8 +83,13 @@ public:
// nsIWebShell
NS_IMETHOD SetContainer(nsIWebShellContainer* aContainer);
NS_IMETHOD GetContainer(nsIWebShellContainer*& aResult);
NS_IMETHOD GetDocumentLoader(nsIDocumentLoader*& aResult);
// nsIWebShellContainer::GetContainer overrides an
// nsIDocumentLoader method, so redeclare and forward
NS_IMETHOD GetContainer(nsISupports** aContainer) {
return nsDocLoader::GetContainer(aContainer);
}
// nsILinkHandler
NS_IMETHOD OnLinkClick(nsIContent* aContent,
nsLinkVerb aVerb,
@ -139,7 +144,6 @@ protected:
PRThread *mThread;
nsIWebShellContainer* mContainer;
nsCOMPtr<nsIDocumentLoader> mDocLoader;
eCharsetReloadState mCharsetReloadState;

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

@ -59,12 +59,12 @@
#include "nsGlobalHistory2Adapter.h"
// docshell
NS_GENERIC_FACTORY_CONSTRUCTOR(nsWebShell)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsWebShell, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDefaultURIFixup)
// uriloader
NS_GENERIC_FACTORY_CONSTRUCTOR(nsURILoader)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsDocLoaderImpl, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsDocLoader, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsOSHelperAppService, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsExternalProtocolHandler)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsBlockedExternalProtocolHandler)
@ -102,9 +102,8 @@ static const nsModuleComponentInfo gDocShellModuleInfo[] = {
// uriloader
{ "Netscape URI Loader Service", NS_URI_LOADER_CID, NS_URI_LOADER_CONTRACTID, nsURILoaderConstructor, },
{ "Netscape Doc Loader", NS_DOCUMENTLOADER_CID, NS_DOCUMENTLOADER_CONTRACTID, nsDocLoaderImplConstructor, },
{ "Netscape Doc Loader Service", NS_DOCUMENTLOADER_SERVICE_CID, NS_DOCUMENTLOADER_SERVICE_CONTRACTID,
nsDocLoaderImplConstructor, },
nsDocLoaderConstructor, },
{ "Netscape External Helper App Service", NS_EXTERNALHELPERAPPSERVICE_CID, NS_EXTERNALHELPERAPPSERVICE_CONTRACTID,
nsOSHelperAppServiceConstructor, },
{ "Netscape External Helper App Service", NS_EXTERNALHELPERAPPSERVICE_CID, NS_EXTERNALPROTOCOLSERVICE_CONTRACTID,

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

@ -114,7 +114,6 @@ nsWebBrowser::nsWebBrowser() : mDocShellTreeOwner(nsnull),
mPersistFlags(nsIWebBrowserPersist::PERSIST_FLAGS_NONE),
mStream(nsnull),
mParentWidget(nsnull),
mParent(nsnull),
mListenerArray(nsnull)
#if (defined(XP_MAC) || defined(XP_MACOSX)) && !defined(MOZ_WIDGET_COCOA)
, mTopLevelWidget(nsnull)
@ -521,41 +520,14 @@ NS_IMETHODIMP nsWebBrowser::SetItemType(PRInt32 aItemType)
NS_IMETHODIMP nsWebBrowser::GetParent(nsIDocShellTreeItem** aParent)
{
NS_ENSURE_ARG_POINTER(aParent);
*aParent = mParent;
NS_IF_ADDREF(*aParent);
*aParent = nsnull;
return NS_OK;
}
NS_IMETHODIMP nsWebBrowser::SetParent(nsIDocShellTreeItem* aParent)
{
// null aParent is ok
/* Note this doesn't do an addref on purpose. This is because the parent
is an implied lifetime. We don't want to create a cycle by refcounting
the parent.*/
mParent = aParent;
return NS_OK;
}
NS_IMETHODIMP nsWebBrowser::GetSameTypeParent(nsIDocShellTreeItem** aParent)
{
NS_ENSURE_ARG_POINTER(aParent);
*aParent = nsnull;
if(!mParent)
return NS_OK;
PRInt32 parentType;
NS_ENSURE_SUCCESS(mParent->GetItemType(&parentType), NS_ERROR_FAILURE);
if(typeContentWrapper == parentType)
{
*aParent = mParent;
NS_ADDREF(*aParent);
}
return NS_OK;
}

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

@ -181,7 +181,6 @@ protected:
//Weak Reference interfaces...
nsIWidget* mParentWidget;
nsIDocShellTreeItem* mParent;
nsVoidArray * mListenerArray;
#if (defined(XP_MAC) || defined(XP_MACOSX)) && !defined(MOZ_WIDGET_COCOA)

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

@ -269,16 +269,12 @@ NS_IMETHODIMP nsMsgWindow::SetOpenFolder(nsIMsgFolder * aOpenFolder)
NS_IMETHODIMP nsMsgWindow::GetRootDocShell(nsIDocShell * *aDocShell)
{
if(!aDocShell)
return NS_ERROR_NULL_POINTER;
nsCOMPtr<nsIDocShell> rootShell(do_QueryReferent(mRootDocShellWeak));
if (rootShell == nsnull)
if (mRootDocShellWeak) {
CallQueryReferent(mRootDocShellWeak.get(), aDocShell);
} else {
*aDocShell = nsnull;
else
rootShell->QueryInterface(nsIDocShell::GetIID(), (void **) aDocShell);
}
return NS_OK;
}
@ -382,30 +378,12 @@ NS_IMETHODIMP nsMsgWindow::SetDOMWindow(nsIDOMWindowInternal *aWindow)
NS_IMETHODIMP nsMsgWindow::StopUrls()
{
m_stopped = PR_TRUE;
nsCOMPtr<nsIDocShell> docShell;
GetRootDocShell(getter_AddRefs(docShell));
if (docShell)
nsCOMPtr<nsIWebNavigation> webnav(do_QueryReferent(mRootDocShellWeak));
if (webnav)
{
nsCOMPtr<nsIWebNavigation> webnav(do_QueryInterface(docShell));
return webnav->Stop(nsIWebNavigation::STOP_NETWORK);
}
nsCOMPtr<nsIDocShell> rootShell(do_QueryReferent(mRootDocShellWeak));
nsCOMPtr <nsIWebShell> rootWebShell(do_QueryInterface(rootShell));
if (rootWebShell)
{
nsCOMPtr <nsIDocumentLoader> docLoader;
nsCOMPtr <nsILoadGroup> loadGroup;
rootWebShell->GetDocumentLoader(*getter_AddRefs(docLoader));
if (docLoader)
{
docLoader->GetLoadGroup(getter_AddRefs(loadGroup));
if (loadGroup)
loadGroup->Cancel(NS_BINDING_ABORTED);
}
return NS_OK;
}
return NS_ERROR_NULL_POINTER;
}

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

@ -272,9 +272,10 @@ NS_IMETHODIMP nsMsgMailNewsUrl::GetLoadGroup(nsILoadGroup **aLoadGroup)
{
if (m_msgWindow)
{
// XXXbz This is really weird... why are we getting some
// random loadgroup we're not really a part of?
nsCOMPtr<nsIDocShell> docShell;
m_msgWindow->GetRootDocShell(getter_AddRefs(docShell));
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(docShell));
#if 0 // since we're not going through the doc loader for most mail/news urls,
//, this code isn't useful
@ -299,13 +300,7 @@ NS_IMETHODIMP nsMsgMailNewsUrl::GetLoadGroup(nsILoadGroup **aLoadGroup)
}
}
#endif
if (webShell)
{
nsCOMPtr <nsIDocumentLoader> docLoader;
webShell->GetDocumentLoader(*getter_AddRefs(docLoader));
if (docLoader)
docLoader->GetLoadGroup(getter_AddRefs(m_loadGroup));
}
m_loadGroup = do_GetInterface(docShell);
}
}

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

@ -52,15 +52,6 @@ nsIURILoader
#define NS_URI_LOADER_CONTRACTID \
"@mozilla.org/uriloader;1"
/* 057b04d0-0ccf-11d2-beba-00805f8a66dc */
#define NS_DOCUMENTLOADER_SERVICE_CID \
{ 0x057b04d0, 0x0ccf, 0x11d2,{0xbe, 0xba, 0x00, 0x80, 0x5f, 0x8a, 0x66, 0xdc}}
#define NS_DOCUMENTLOADER_CID \
{ 0xdbe63944, 0xd434, 0x11d3, { 0x98, 0xb1, 0x0, 0x10, 0x83, 0x1, 0xe, 0x9b}}
#define NS_DOCUMENTLOADER_CONTRACTID \
"@mozilla.org/docloader;1"
/* 057b04d0-0ccf-11d2-beba-00805f8a66dc */
#define NS_DOCUMENTLOADER_SERVICE_CID \
{ 0x057b04d0, 0x0ccf, 0x11d2,{0xbe, 0xba, 0x00, 0x80, 0x5f, 0x8a, 0x66, 0xdc}}

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

@ -50,6 +50,7 @@
#include "nsCOMPtr.h"
#include "nscore.h"
#include "nsWeakPtr.h"
#include "nsAutoPtr.h"
#include "nsIDOMWindow.h"
@ -62,6 +63,7 @@
#include "nsISocketTransport.h"
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
static NS_DEFINE_CID(kThisImplCID, NS_THIS_DOCLOADER_IMPL_CID);
#if defined(PR_LOGGING)
//
@ -128,7 +130,7 @@ struct nsListenerInfo {
};
nsDocLoaderImpl::nsDocLoaderImpl()
nsDocLoader::nsDocLoader()
: mListenerInfoList(8)
{
#if defined(PR_LOGGING)
@ -137,7 +139,6 @@ nsDocLoaderImpl::nsDocLoaderImpl()
}
#endif /* PR_LOGGING */
mContainer = nsnull;
mParent = nsnull;
mIsLoadingDocument = PR_FALSE;
@ -167,14 +168,14 @@ nsDocLoaderImpl::nsDocLoaderImpl()
}
nsresult
nsDocLoaderImpl::SetDocLoaderParent(nsDocLoaderImpl *aParent)
nsDocLoader::SetDocLoaderParent(nsDocLoader *aParent)
{
mParent = aParent;
return NS_OK;
}
nsresult
nsDocLoaderImpl::Init()
nsDocLoader::Init()
{
if (!mRequestInfoHash.ops) {
return NS_ERROR_OUT_OF_MEMORY;
@ -189,7 +190,7 @@ nsDocLoaderImpl::Init()
return NS_OK;
}
nsDocLoaderImpl::~nsDocLoaderImpl()
nsDocLoader::~nsDocLoader()
{
/*
|ClearWeakReferences()| here is intended to prevent people holding weak references
@ -200,6 +201,8 @@ nsDocLoaderImpl::~nsDocLoaderImpl()
An alternative would be incrementing our refcount (consider it a compressed flag
saying "Don't re-destroy."). I haven't yet decided which is better. [scc]
*/
// XXXbz now that NS_IMPL_RELEASE stabilizes by setting refcount to 1, is
// this needed?
ClearWeakReferences();
Destroy();
@ -207,25 +210,6 @@ nsDocLoaderImpl::~nsDocLoaderImpl()
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
("DocLoader:%p: deleted.\n", this));
PRInt32 count = mChildList.Count();
// if the doc loader still has children...we need to enumerate the
// children and make them null out their back ptr to the parent doc
// loader
if (count > 0)
{
for (PRInt32 i=0; i < count; i++)
{
nsIDocumentLoader* loader = mChildList.ObjectAt(i);
if (loader) {
// This is a safe cast, as we only put nsDocLoaderImpl objects into the
// array
NS_STATIC_CAST(nsDocLoaderImpl*, loader)->SetDocLoaderParent(nsnull);
}
}
mChildList.Clear();
}
if (mRequestInfoHash.ops) {
PL_DHashTableFinish(&mRequestInfoHash);
}
@ -235,10 +219,10 @@ nsDocLoaderImpl::~nsDocLoaderImpl()
/*
* Implementation of ISupports methods...
*/
NS_IMPL_THREADSAFE_ADDREF(nsDocLoaderImpl)
NS_IMPL_THREADSAFE_RELEASE(nsDocLoaderImpl)
NS_IMPL_THREADSAFE_ADDREF(nsDocLoader)
NS_IMPL_THREADSAFE_RELEASE(nsDocLoader)
NS_INTERFACE_MAP_BEGIN(nsDocLoaderImpl)
NS_INTERFACE_MAP_BEGIN(nsDocLoader)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIRequestObserver)
NS_INTERFACE_MAP_ENTRY(nsIRequestObserver)
NS_INTERFACE_MAP_ENTRY(nsIDocumentLoader)
@ -248,13 +232,16 @@ NS_INTERFACE_MAP_BEGIN(nsDocLoaderImpl)
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
NS_INTERFACE_MAP_ENTRY(nsIHttpEventSink)
NS_INTERFACE_MAP_ENTRY(nsISecurityEventSink)
if (aIID.Equals(kThisImplCID))
foundInterface = NS_STATIC_CAST(nsIDocumentLoader *, this);
else
NS_INTERFACE_MAP_END
/*
* Implementation of nsIInterfaceRequestor methods...
*/
NS_IMETHODIMP nsDocLoaderImpl::GetInterface(const nsIID& aIID, void** aSink)
NS_IMETHODIMP nsDocLoader::GetInterface(const nsIID& aIID, void** aSink)
{
nsresult rv = NS_ERROR_NO_INTERFACE;
@ -271,43 +258,36 @@ NS_IMETHODIMP nsDocLoaderImpl::GetInterface(const nsIID& aIID, void** aSink)
return rv;
}
NS_IMETHODIMP
nsDocLoaderImpl::CreateDocumentLoader(nsIDocumentLoader** anInstance)
/* static */
already_AddRefed<nsDocLoader>
nsDocLoader::GetAsDocLoader(nsISupports* aSupports)
{
nsresult rv = NS_OK;
*anInstance = nsnull;
nsDocLoaderImpl * newLoader = new nsDocLoaderImpl();
NS_ENSURE_TRUE(newLoader, NS_ERROR_OUT_OF_MEMORY);
NS_ADDREF(newLoader);
// Initialize now that we have a reference
rv = newLoader->Init();
if (NS_SUCCEEDED(rv)) {
rv = newLoader->SetDocLoaderParent(this);
if (!aSupports) {
return nsnull;
}
if (NS_SUCCEEDED(rv)) {
rv = mChildList.AppendObject(newLoader)
? NS_OK : NS_ERROR_FAILURE;
}
if (NS_SUCCEEDED(rv)) {
rv = CallQueryInterface(newLoader, anInstance);
}
NS_RELEASE(newLoader);
return rv;
nsDocLoader* ptr;
CallQueryInterface(aSupports, &ptr);
return ptr;
}
/* static */
nsresult
nsDocLoader::AddDocLoaderAsChildOfRoot(nsDocLoader* aDocLoader)
{
nsresult rv;
nsCOMPtr<nsIDocumentLoader> docLoaderService =
do_GetService(NS_DOCUMENTLOADER_SERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsRefPtr<nsDocLoader> rootDocLoader = GetAsDocLoader(docLoaderService);
NS_ENSURE_TRUE(rootDocLoader, NS_ERROR_UNEXPECTED);
return rootDocLoader->AddChildLoader(aDocLoader);
}
NS_IMETHODIMP
nsDocLoaderImpl::Stop(void)
nsDocLoader::Stop(void)
{
nsresult rv = NS_OK;
PRInt32 count, i;
@ -319,7 +299,7 @@ nsDocLoaderImpl::Stop(void)
nsCOMPtr<nsIDocumentLoader> loader;
for (i=0; i < count; i++) {
loader = mChildList.ObjectAt(i);
loader = ChildAt(i);
if (loader) {
(void) loader->Stop();
@ -334,7 +314,7 @@ nsDocLoaderImpl::Stop(void)
PRBool
nsDocLoaderImpl::IsBusy()
nsDocLoader::IsBusy()
{
nsresult rv;
@ -361,11 +341,11 @@ nsDocLoaderImpl::IsBusy()
count = mChildList.Count();
for (i=0; i < count; i++) {
nsIDocumentLoader* loader = mChildList.ObjectAt(i);
nsIDocumentLoader* loader = ChildAt(i);
// This is a safe cast, because we only put nsDocLoaderImpl objects into the
// This is a safe cast, because we only put nsDocLoader objects into the
// array
if (loader && NS_STATIC_CAST(nsDocLoaderImpl*, loader)->IsBusy())
if (loader && NS_STATIC_CAST(nsDocLoader*, loader)->IsBusy())
return PR_TRUE;
}
@ -373,27 +353,15 @@ nsDocLoaderImpl::IsBusy()
}
NS_IMETHODIMP
nsDocLoaderImpl::SetContainer(nsISupports* aContainer)
nsDocLoader::GetContainer(nsISupports** aResult)
{
// This is a weak reference...
mContainer = aContainer;
return NS_OK;
}
NS_IMETHODIMP
nsDocLoaderImpl::GetContainer(nsISupports** aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
*aResult = mContainer;
NS_IF_ADDREF(*aResult);
NS_ADDREF(*aResult = NS_STATIC_CAST(nsIDocumentLoader*, this));
return NS_OK;
}
NS_IMETHODIMP
nsDocLoaderImpl::GetLoadGroup(nsILoadGroup** aResult)
nsDocLoader::GetLoadGroup(nsILoadGroup** aResult)
{
nsresult rv = NS_OK;
@ -406,26 +374,23 @@ nsDocLoaderImpl::GetLoadGroup(nsILoadGroup** aResult)
return rv;
}
NS_IMETHODIMP
nsDocLoaderImpl::Destroy()
void
nsDocLoader::Destroy()
{
Stop();
// Remove the document loader from the parent list of loaders...
// Remove the document loader from the parent list of loaders...
if (mParent)
{
mParent->RemoveChildGroup(this);
mParent = nsnull;
mParent->RemoveChildLoader(this);
}
// Release all the information about network requests...
ClearRequestInfoHash();
// Release all the information about registered listeners...
PRInt32 i, count;
count = mListenerInfoList.Count();
for(i=0; i<count; i++) {
PRInt32 count = mListenerInfoList.Count();
for(PRInt32 i = 0; i < count; i++) {
nsListenerInfo *info =
NS_STATIC_CAST(nsListenerInfo*, mListenerInfoList.ElementAt(i));
@ -440,11 +405,33 @@ nsDocLoaderImpl::Destroy()
if (mLoadGroup)
mLoadGroup->SetGroupObserver(nsnull);
return NS_OK;
DestroyChildren();
}
void
nsDocLoader::DestroyChildren()
{
PRInt32 i, count;
count = mChildList.Count();
// if the doc loader still has children...we need to enumerate the
// children and make them null out their back ptr to the parent doc
// loader
for (i=0; i < count; i++)
{
nsIDocumentLoader* loader = ChildAt(i);
if (loader) {
// This is a safe cast, as we only put nsDocLoader objects into the
// array
NS_STATIC_CAST(nsDocLoader*, loader)->SetDocLoaderParent(nsnull);
}
}
mChildList.Clear();
}
NS_IMETHODIMP
nsDocLoaderImpl::OnStartRequest(nsIRequest *request, nsISupports *aCtxt)
nsDocLoader::OnStartRequest(nsIRequest *request, nsISupports *aCtxt)
{
// called each time a request is added to the group.
@ -527,7 +514,7 @@ nsDocLoaderImpl::OnStartRequest(nsIRequest *request, nsISupports *aCtxt)
}
NS_IMETHODIMP
nsDocLoaderImpl::OnStopRequest(nsIRequest *aRequest,
nsDocLoader::OnStopRequest(nsIRequest *aRequest,
nsISupports *aCtxt,
nsresult aStatus)
{
@ -666,17 +653,25 @@ nsDocLoaderImpl::OnStopRequest(nsIRequest *aRequest,
}
nsresult nsDocLoaderImpl::RemoveChildGroup(nsDocLoaderImpl* aLoader)
nsresult nsDocLoader::RemoveChildLoader(nsDocLoader* aChild)
{
nsresult rv = NS_OK;
nsresult rv = mChildList.RemoveElement(aChild) ? NS_OK : NS_ERROR_FAILURE;
if (NS_SUCCEEDED(rv)) {
mChildList.RemoveObject((nsIDocumentLoader*)aLoader);
aChild->SetDocLoaderParent(nsnull);
}
return rv;
}
NS_IMETHODIMP nsDocLoaderImpl::GetDocumentChannel(nsIChannel ** aChannel)
nsresult nsDocLoader::AddChildLoader(nsDocLoader* aChild)
{
nsresult rv = mChildList.AppendElement(aChild) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
if (NS_SUCCEEDED(rv)) {
aChild->SetDocLoaderParent(this);
}
return rv;
}
NS_IMETHODIMP nsDocLoader::GetDocumentChannel(nsIChannel ** aChannel)
{
if (!mDocumentRequest) {
*aChannel = nsnull;
@ -687,7 +682,7 @@ NS_IMETHODIMP nsDocLoaderImpl::GetDocumentChannel(nsIChannel ** aChannel)
}
void nsDocLoaderImpl::DocLoaderIsEmpty()
void nsDocLoader::DocLoaderIsEmpty()
{
if (mIsLoadingDocument) {
/* In the unimagineably rude circumstance that onload event handlers
@ -733,7 +728,7 @@ void nsDocLoaderImpl::DocLoaderIsEmpty()
}
}
void nsDocLoaderImpl::doStartDocumentLoad(void)
void nsDocLoader::doStartDocumentLoad(void)
{
#if defined(DEBUG)
@ -759,7 +754,7 @@ void nsDocLoaderImpl::doStartDocumentLoad(void)
NS_OK);
}
void nsDocLoaderImpl::doStartURLLoad(nsIRequest *request)
void nsDocLoader::doStartURLLoad(nsIRequest *request)
{
#if defined(DEBUG)
nsCAutoString buffer;
@ -778,7 +773,7 @@ void nsDocLoaderImpl::doStartURLLoad(nsIRequest *request)
NS_OK);
}
void nsDocLoaderImpl::doStopURLLoad(nsIRequest *request, nsresult aStatus)
void nsDocLoader::doStopURLLoad(nsIRequest *request, nsresult aStatus)
{
#if defined(DEBUG)
nsCAutoString buffer;
@ -797,7 +792,7 @@ void nsDocLoaderImpl::doStopURLLoad(nsIRequest *request, nsresult aStatus)
aStatus);
}
void nsDocLoaderImpl::doStopDocumentLoad(nsIRequest *request,
void nsDocLoader::doStopDocumentLoad(nsIRequest *request,
nsresult aStatus)
{
#if defined(DEBUG)
@ -839,7 +834,7 @@ void nsDocLoaderImpl::doStopDocumentLoad(nsIRequest *request,
// get web progress returns our web progress listener or if
// we don't have one, it will look up the doc loader hierarchy
// to see if one of our parent doc loaders has one.
nsresult nsDocLoaderImpl::GetParentWebProgressListener(nsDocLoaderImpl * aDocLoader, nsIWebProgressListener ** aWebProgress)
nsresult nsDocLoader::GetParentWebProgressListener(nsDocLoader * aDocLoader, nsIWebProgressListener ** aWebProgress)
{
// if we got here, there is no web progress to return
*aWebProgress = nsnull;
@ -848,7 +843,7 @@ nsresult nsDocLoaderImpl::GetParentWebProgressListener(nsDocLoaderImpl * aDocLoa
}
NS_IMETHODIMP
nsDocLoaderImpl::AddProgressListener(nsIWebProgressListener *aListener,
nsDocLoader::AddProgressListener(nsIWebProgressListener *aListener,
PRUint32 aNotifyMask)
{
nsresult rv;
@ -874,7 +869,7 @@ nsDocLoaderImpl::AddProgressListener(nsIWebProgressListener *aListener,
}
NS_IMETHODIMP
nsDocLoaderImpl::RemoveProgressListener(nsIWebProgressListener *aListener)
nsDocLoader::RemoveProgressListener(nsIWebProgressListener *aListener)
{
nsresult rv;
@ -890,36 +885,20 @@ nsDocLoaderImpl::RemoveProgressListener(nsIWebProgressListener *aListener)
}
NS_IMETHODIMP
nsDocLoaderImpl::GetDOMWindow(nsIDOMWindow **aResult)
nsDocLoader::GetDOMWindow(nsIDOMWindow **aResult)
{
nsresult rv = NS_OK;
*aResult = nsnull;
//
// The DOM Window is available from the associated container (ie DocShell)
// if one is available...
//
if (mContainer) {
nsCOMPtr<nsIDOMWindow> window(do_GetInterface(mContainer, &rv));
*aResult = window;
NS_IF_ADDREF(*aResult);
} else {
rv = NS_ERROR_FAILURE;
}
return rv;
return CallGetInterface(this, aResult);
}
NS_IMETHODIMP
nsDocLoaderImpl::GetIsLoadingDocument(PRBool *aIsLoadingDocument)
nsDocLoader::GetIsLoadingDocument(PRBool *aIsLoadingDocument)
{
*aIsLoadingDocument = mIsLoadingDocument;
return NS_OK;
}
PRInt32 nsDocLoaderImpl::GetMaxTotalProgress()
PRInt32 nsDocLoader::GetMaxTotalProgress()
{
PRInt32 count = 0;
PRInt32 individualProgress, newMaxTotal;
@ -932,11 +911,11 @@ PRInt32 nsDocLoaderImpl::GetMaxTotalProgress()
for (PRInt32 i=0; i < count; i++)
{
individualProgress = 0;
docloader = mChildList.ObjectAt(i);
docloader = ChildAt(i);
if (docloader)
{
// Cast is safe since all children are nsDocLoaderImpl too
individualProgress = ((nsDocLoaderImpl *) docloader.get())->GetMaxTotalProgress();
// Cast is safe since all children are nsDocLoader too
individualProgress = ((nsDocLoader *) docloader.get())->GetMaxTotalProgress();
}
if (individualProgress < 0) // if one of the elements doesn't know it's size
// then none of them do
@ -961,7 +940,7 @@ PRInt32 nsDocLoaderImpl::GetMaxTotalProgress()
// then turns around and makes the right web progress calls based on this information.
////////////////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP nsDocLoaderImpl::OnProgress(nsIRequest *aRequest, nsISupports* ctxt,
NS_IMETHODIMP nsDocLoader::OnProgress(nsIRequest *aRequest, nsISupports* ctxt,
PRUint32 aProgress, PRUint32 aProgressMax)
{
nsRequestInfo *info;
@ -1052,7 +1031,7 @@ NS_IMETHODIMP nsDocLoaderImpl::OnProgress(nsIRequest *aRequest, nsISupports* ctx
return NS_OK;
}
NS_IMETHODIMP nsDocLoaderImpl::OnStatus(nsIRequest* aRequest, nsISupports* ctxt,
NS_IMETHODIMP nsDocLoader::OnStatus(nsIRequest* aRequest, nsISupports* ctxt,
nsresult aStatus, const PRUnichar* aStatusArg)
{
//
@ -1089,7 +1068,7 @@ NS_IMETHODIMP nsDocLoaderImpl::OnStatus(nsIRequest* aRequest, nsISupports* ctxt,
return NS_OK;
}
void nsDocLoaderImpl::ClearInternalProgress()
void nsDocLoader::ClearInternalProgress()
{
ClearRequestInfoHash();
@ -1100,13 +1079,13 @@ void nsDocLoaderImpl::ClearInternalProgress()
}
void nsDocLoaderImpl::FireOnProgressChange(nsDocLoaderImpl *aLoadInitiator,
nsIRequest *request,
PRInt32 aProgress,
PRInt32 aProgressMax,
PRInt32 aProgressDelta,
PRInt32 aTotalProgress,
PRInt32 aMaxTotalProgress)
void nsDocLoader::FireOnProgressChange(nsDocLoader *aLoadInitiator,
nsIRequest *request,
PRInt32 aProgress,
PRInt32 aProgressMax,
PRInt32 aProgressDelta,
PRInt32 aTotalProgress,
PRInt32 aMaxTotalProgress)
{
if (mIsLoadingDocument) {
mCurrentTotalProgress += aProgressDelta;
@ -1167,10 +1146,10 @@ void nsDocLoaderImpl::FireOnProgressChange(nsDocLoaderImpl *aLoadInitiator,
}
void nsDocLoaderImpl::FireOnStateChange(nsIWebProgress *aProgress,
nsIRequest *aRequest,
PRInt32 aStateFlags,
nsresult aStatus)
void nsDocLoader::FireOnStateChange(nsIWebProgress *aProgress,
nsIRequest *aRequest,
PRInt32 aStateFlags,
nsresult aStatus)
{
//
// Remove the STATE_IS_NETWORK bit if necessary.
@ -1234,10 +1213,10 @@ void nsDocLoaderImpl::FireOnStateChange(nsIWebProgress *aProgress,
NS_IMETHODIMP
nsDocLoaderImpl::FireOnLocationChange(nsIWebProgress* aWebProgress,
nsIRequest* aRequest,
nsIURI *aUri)
void
nsDocLoader::FireOnLocationChange(nsIWebProgress* aWebProgress,
nsIRequest* aRequest,
nsIURI *aUri)
{
/*
* First notify any listeners of the new state info...
@ -1273,15 +1252,13 @@ nsDocLoaderImpl::FireOnLocationChange(nsIWebProgress* aWebProgress,
if (mParent) {
mParent->FireOnLocationChange(aWebProgress, aRequest, aUri);
}
return NS_OK;
}
void
nsDocLoaderImpl::FireOnStatusChange(nsIWebProgress* aWebProgress,
nsIRequest* aRequest,
nsresult aStatus,
const PRUnichar* aMessage)
nsDocLoader::FireOnStatusChange(nsIWebProgress* aWebProgress,
nsIRequest* aRequest,
nsresult aStatus,
const PRUnichar* aMessage)
{
/*
* First notify any listeners of the new state info...
@ -1319,7 +1296,7 @@ nsDocLoaderImpl::FireOnStatusChange(nsIWebProgress* aWebProgress,
}
nsListenerInfo *
nsDocLoaderImpl::GetListenerInfo(nsIWebProgressListener *aListener)
nsDocLoader::GetListenerInfo(nsIWebProgressListener *aListener)
{
PRInt32 i, count;
nsListenerInfo *info;
@ -1339,7 +1316,7 @@ nsDocLoaderImpl::GetListenerInfo(nsIWebProgressListener *aListener)
return nsnull;
}
nsresult nsDocLoaderImpl::AddRequestInfo(nsIRequest *aRequest)
nsresult nsDocLoader::AddRequestInfo(nsIRequest *aRequest)
{
if (!PL_DHashTableOperate(&mRequestInfoHash, aRequest, PL_DHASH_ADD)) {
return NS_ERROR_OUT_OF_MEMORY;
@ -1348,7 +1325,7 @@ nsresult nsDocLoaderImpl::AddRequestInfo(nsIRequest *aRequest)
return NS_OK;
}
nsRequestInfo * nsDocLoaderImpl::GetRequestInfo(nsIRequest *aRequest)
nsRequestInfo * nsDocLoader::GetRequestInfo(nsIRequest *aRequest)
{
nsRequestInfo *info =
NS_STATIC_CAST(nsRequestInfo *,
@ -1375,7 +1352,7 @@ RemoveInfoCallback(PLDHashTable *table, PLDHashEntryHdr *hdr, PRUint32 number,
return PL_DHASH_REMOVE;
}
void nsDocLoaderImpl::ClearRequestInfoHash(void)
void nsDocLoader::ClearRequestInfoHash(void)
{
if (!mRequestInfoHash.ops || !mRequestInfoHash.entryCount) {
// No hash, or the hash is empty, nothing to do here then...
@ -1405,14 +1382,15 @@ CalcMaxProgressCallback(PLDHashTable *table, PLDHashEntryHdr *hdr,
return PL_DHASH_NEXT;
}
PRInt32 nsDocLoaderImpl::CalculateMaxProgress()
PRInt32 nsDocLoader::CalculateMaxProgress()
{
PRInt32 max = 0;
PL_DHashTableEnumerate(&mRequestInfoHash, CalcMaxProgressCallback, &max);
return max;
}
NS_IMETHODIMP nsDocLoaderImpl::OnRedirect(nsIHttpChannel *aOldChannel, nsIChannel *aNewChannel)
NS_IMETHODIMP nsDocLoader::OnRedirect(nsIHttpChannel *aOldChannel,
nsIChannel *aNewChannel)
{
if (aOldChannel)
{
@ -1452,8 +1430,8 @@ NS_IMETHODIMP nsDocLoaderImpl::OnRedirect(nsIHttpChannel *aOldChannel, nsIChanne
* Implementation of nsISecurityEventSink method...
*/
NS_IMETHODIMP nsDocLoaderImpl::OnSecurityChange(nsISupports * aContext,
PRUint32 aState)
NS_IMETHODIMP nsDocLoader::OnSecurityChange(nsISupports * aContext,
PRUint32 aState)
{
//
// Fire progress notifications out to any registered nsIWebProgressListeners.
@ -1503,7 +1481,7 @@ NS_IMETHODIMP nsDocLoaderImpl::OnSecurityChange(nsISupports * aContext,
#if 0
void nsDocLoaderImpl::DumpChannelInfo()
void nsDocLoader::DumpChannelInfo()
{
nsChannelInfo *info;
PRInt32 i, count;

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

@ -63,26 +63,41 @@ struct nsRequestInfo;
struct nsListenerInfo;
/****************************************************************************
* nsDocLoaderImpl implementation...
* nsDocLoader implementation...
****************************************************************************/
class nsDocLoaderImpl : public nsIDocumentLoader,
public nsIRequestObserver,
public nsSupportsWeakReference,
public nsIProgressEventSink,
public nsIWebProgress,
public nsIInterfaceRequestor,
public nsIHttpEventSink,
public nsISecurityEventSink
#define NS_THIS_DOCLOADER_IMPL_CID \
{ /* 2f7f940d-d67e-40bc-b1ba-8c46de2b4cec */ \
0x2f7f940d, \
0xd67e, \
0x40bc, \
{0xb1, 0xba, 0x8c, 0x46, 0xde, 0x2b, 0x4c, 0xec} \
}
class nsDocLoader : public nsIDocumentLoader,
public nsIRequestObserver,
public nsSupportsWeakReference,
public nsIProgressEventSink,
public nsIWebProgress,
public nsIInterfaceRequestor,
public nsIHttpEventSink,
public nsISecurityEventSink
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_THIS_DOCLOADER_IMPL_CID);
nsDocLoaderImpl();
nsDocLoader();
nsresult Init();
virtual nsresult Init();
// for nsIGenericFactory:
static NS_IMETHODIMP Create(nsISupports *aOuter, const nsIID &aIID, void **aResult);
static already_AddRefed<nsDocLoader> GetAsDocLoader(nsISupports* aSupports);
// Needed to deal with ambiguous inheritance from nsISupports...
static nsISupports* GetAsSupports(nsDocLoader* aDocLoader) {
return NS_STATIC_CAST(nsIDocumentLoader*, aDocLoader);
}
// Add aDocLoader as a child to the docloader service.
static nsresult AddDocLoaderAsChildOfRoot(nsDocLoader* aDocLoader);
NS_DECL_ISUPPORTS
NS_DECL_NSIDOCUMENTLOADER
@ -100,16 +115,36 @@ public:
NS_DECL_NSIHTTPEVENTSINK
// Implementation specific methods...
protected:
virtual ~nsDocLoaderImpl();
nsresult SetDocLoaderParent(nsDocLoaderImpl * aLoader);
nsresult RemoveChildGroup(nsDocLoaderImpl *aLoader);
// Remove aChild from our childlist. This nulls out the child's mParent
// pointer.
nsresult RemoveChildLoader(nsDocLoader *aChild);
// Add aChild to our child list. This will set aChild's mParent pointer to
// |this|.
nsresult AddChildLoader(nsDocLoader* aChild);
nsDocLoader* GetParent() const { return mParent; }
protected:
virtual ~nsDocLoader();
virtual nsresult SetDocLoaderParent(nsDocLoader * aLoader);
void DocLoaderIsEmpty();
PRBool IsBusy();
void FireOnProgressChange(nsDocLoaderImpl* aLoadInitiator,
void Destroy();
virtual void DestroyChildren();
nsIDocumentLoader* ChildAt(PRInt32 i) {
return NS_STATIC_CAST(nsDocLoader*, mChildList[i]);
}
nsIDocumentLoader* SafeChildAt(PRInt32 i) {
return NS_STATIC_CAST(nsDocLoader*, mChildList.SafeElementAt(i));
}
void FireOnProgressChange(nsDocLoader* aLoadInitiator,
nsIRequest *request,
PRInt32 aProgress,
PRInt32 aProgressMax,
@ -127,6 +162,10 @@ protected:
nsresult aStatus,
const PRUnichar* aMessage);
void FireOnLocationChange(nsIWebProgress* aWebProgress,
nsIRequest* aRequest,
nsIURI *aUri);
void doStartDocumentLoad();
void doStartURLLoad(nsIRequest *request);
void doStopURLLoad(nsIRequest *request, nsresult aStatus);
@ -135,10 +174,9 @@ protected:
// get web progress returns our web progress listener or if
// we don't have one, it will look up the doc loader hierarchy
// to see if one of our parent doc loaders has one.
nsresult GetParentWebProgressListener(nsDocLoaderImpl * aDocLoader, nsIWebProgressListener ** aWebProgres);
nsresult GetParentWebProgressListener(nsDocLoader * aDocLoader, nsIWebProgressListener ** aWebProgres);
protected:
// IMPORTANT: The ownership implicit in the following member
// variables has been explicitly checked and set using nsCOMPtr
// for owning pointers and raw COM interface pointers for weak
@ -146,9 +184,8 @@ protected:
// class, please make the ownership explicit (pinkerton, scc).
nsCOMPtr<nsIRequest> mDocumentRequest; // [OWNER] ???compare with document
nsISupports* mContainer; // [WEAK] it owns me!
nsDocLoaderImpl* mParent; // [WEAK]
nsDocLoader* mParent; // [WEAK]
nsVoidArray mListenerInfoList;
/*
@ -159,11 +196,11 @@ protected:
PRBool mIsLoadingDocument;
nsCOMPtr<nsILoadGroup> mLoadGroup;
nsCOMArray<nsIDocumentLoader> mChildList;
// We hold weak refs to all our kids
nsVoidArray mChildList;
// The following member variables are related to the new nsIWebProgress
// feedback interfaces that travis cooked up.
nsCOMPtr<nsIWebProgressListener> mProgressListener;
PRInt32 mProgressStateFlags;
PRInt32 mCurrentSelfProgress;

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

@ -43,28 +43,26 @@ interface nsIWebProgress;
interface nsIRequest;
/**
* An nsIDocumentLoader is a component responsible for tracking groups of loads
* that belong together (images, external scripts, etc) and subdocuments
* An nsIDocumentLoader is an interface responsible for tracking groups of
* loads that belong together (images, external scripts, etc) and subdocuments
* (<iframe>, <frame>, etc). It is also responsible for sending
* nsIWebProgressListener notifications.
* XXXbz this interface should go away, we think...
*/
[scriptable, uuid(8cb3d66d-a39c-46d4-9786-373b6b052e6d)]
[scriptable, uuid(bbe961ee-59e9-42bb-be50-0331979bb79f)]
interface nsIDocumentLoader : nsISupports
{
// Stop all loads in the loadgroup of this docloader
void stop();
// XXXbiesi this seems like not such a good method here
void createDocumentLoader(out nsIDocumentLoader anInstance);
attribute nsISupports container;
nsILoadGroup getLoadGroup();
// XXXbz is this needed? For embedding? What this does is does is not
// defined by this interface!
readonly attribute nsISupports container;
void destroy();
// The loadgroup associated with this docloader
readonly attribute nsILoadGroup loadGroup;
// The defaultLoadRequest of the loadgroup associated with this docloader
readonly attribute nsIChannel documentChannel;
void fireOnLocationChange(in nsIWebProgress aWebProgress,
in nsIRequest aRequest,
in nsIURI aUri);
};

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

@ -40,7 +40,6 @@
interface nsIURIContentListener;
interface nsIURI;
interface nsILoadGroup;
interface nsIDocumentLoader;
interface nsIProgressEventSink;
interface nsIChannel;
interface nsIRequest;
@ -68,7 +67,7 @@ interface nsIInterfaceRequestor;
* or helper app. Or it may hand the url off to an OS registered
* application.
*/
[scriptable, uuid(b90c6e12-48a0-4954-8eb3-b6e0075d4e4f)]
[scriptable, uuid(5cf6420c-74f3-4a7c-bc1d-f5756d79ea07)]
interface nsIURILoader : nsISupports
{
/**
@ -112,10 +111,5 @@ interface nsIURILoader : nsISupports
* Stops an in progress load
*/
void stop(in nsISupports aLoadCookie);
/**
* XXXbiesi is this really needed?
*/
nsIDocumentLoader getDocumentLoaderForContext (in nsIInterfaceRequestor aWindowContext);
};

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

@ -77,6 +77,8 @@
#include "nsMimeTypes.h"
#include "nsDocLoader.h"
static NS_DEFINE_CID(kStreamConverterServiceCID, NS_STREAMCONVERTERSERVICE_CID);
#ifdef PR_LOGGING
PRLogModuleInfo* nsURILoader::mLog = nsnull;
@ -845,13 +847,32 @@ NS_IMETHODIMP nsURILoader::OpenURI(nsIChannel *channel,
if (!loader) return NS_ERROR_OUT_OF_MEMORY;
nsCOMPtr<nsIInterfaceRequestor> loadCookie;
SetupLoadCookie(aWindowContext, getter_AddRefs(loadCookie));
// Set the correct loadgroup on the channel
nsCOMPtr<nsILoadGroup> loadGroup(do_GetInterface(loadCookie));
channel->SetLoadGroup(loadGroup);
nsCOMPtr<nsILoadGroup> loadGroup(do_GetInterface(aWindowContext));
if (!loadGroup) {
// XXXbz This context is violating what we'd like to be the new uriloader
// api.... Set up a nsDocLoader to handle the loadgroup for this context.
// This really needs to go away!
nsCOMPtr<nsIURIContentListener> listener(do_GetInterface(aWindowContext));
if (listener) {
nsCOMPtr<nsISupports> cookie;
listener->GetLoadCookie(getter_AddRefs(cookie));
if (!cookie) {
nsRefPtr<nsDocLoader> newDocLoader = new nsDocLoader();
nsresult rv = newDocLoader->Init();
if (NS_FAILED(rv))
return rv;
rv = nsDocLoader::AddDocLoaderAsChildOfRoot(newDocLoader);
if (NS_FAILED(rv))
return rv;
listener->SetLoadCookie(nsDocLoader::GetAsSupports(newDocLoader));
}
}
}
channel->SetLoadGroup(loadGroup);
// now instruct the loader to go ahead and open the url
return loader->Open(channel);
}
@ -870,90 +891,3 @@ NS_IMETHODIMP nsURILoader::Stop(nsISupports* aLoadCookie)
return rv;
}
NS_IMETHODIMP
nsURILoader::GetDocumentLoaderForContext(nsIInterfaceRequestor * aWindowContext,
nsIDocumentLoader ** aDocLoader)
{
nsresult rv;
nsCOMPtr<nsIInterfaceRequestor> loadCookieForWindow;
// Initialize the [out] parameter...
*aDocLoader = nsnull;
NS_ENSURE_ARG(aWindowContext);
rv = SetupLoadCookie(aWindowContext, getter_AddRefs(loadCookieForWindow));
if (NS_FAILED(rv)) return rv;
rv = CallGetInterface(loadCookieForWindow.get(), aDocLoader);
return rv;
}
nsresult nsURILoader::SetupLoadCookie(nsIInterfaceRequestor * aWindowContext,
nsIInterfaceRequestor ** aLoadCookie)
{
// first, see if we have already set a load cookie on the cnt listener..
// i.e. if this isn't the first time we've tried to run a url through this window
// context then we don't need to create another load cookie, we can reuse the first one.
nsresult rv = NS_OK;
nsCOMPtr<nsISupports> loadCookie;
// Initialize the [out] parameter...
*aLoadCookie = nsnull;
nsCOMPtr<nsIURIContentListener> cntListener (do_GetInterface(aWindowContext));
if (cntListener) {
// Get the load cookie for the requested window context...
rv = cntListener->GetLoadCookie(getter_AddRefs(loadCookie));
//
// If we don't have a load cookie for this window context yet, then
// go create one! In order to create a load cookie, we need to get
// the parent's load cookie if there is one...
//
if (!loadCookie) {
nsCOMPtr<nsIURIContentListener> parentListener;
nsCOMPtr<nsIDocumentLoader> parentDocLoader;
nsCOMPtr<nsIDocumentLoader> newDocLoader;
// Try to get the parent's load cookie...
cntListener->GetParentContentListener(getter_AddRefs(parentListener));
if (parentListener) {
rv = parentListener->GetLoadCookie(getter_AddRefs(loadCookie));
// if we had a parent cookie use it to help with the creation process
if (loadCookie) {
parentDocLoader = do_GetInterface(loadCookie);
}
}
// If there is no parent DocLoader, then use the global DocLoader
// service as the parent...
if (!parentDocLoader) {
parentDocLoader = do_GetService(NS_DOCUMENTLOADER_SERVICE_CONTRACTID, &rv);
}
if (NS_FAILED(rv)) return rv;
//
// Create a new document loader. The document loader represents
// the load cookie which the uriloader hands out...
//
rv = parentDocLoader->CreateDocumentLoader(getter_AddRefs(newDocLoader));
if (NS_FAILED(rv)) return rv;
newDocLoader->QueryInterface(NS_GET_IID(nsIInterfaceRequestor),
getter_AddRefs(loadCookie));
rv = cntListener->SetLoadCookie(loadCookie);
} // if we don't have a load cookie already
} // if we have a cntListener
// loadCookie may be null - for example, <a target="popupWin"> if popupWin is
// not a defined window. The following prevents a crash (Bug 32898)
if (loadCookie) {
rv = CallQueryInterface(loadCookie, aLoadCookie);
} else {
rv = NS_ERROR_UNEXPECTED;
}
return rv;
}

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

@ -72,9 +72,6 @@ protected:
*/
nsCOMArray<nsIWeakReference> m_listeners;
/** prepare the load cookie for the window context */
nsresult SetupLoadCookie(nsIInterfaceRequestor * aWindowContext, nsIInterfaceRequestor ** aLoadCookie);
#ifdef PR_LOGGING
/**
* NSPR logging. The module is called "URILoader"

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

@ -55,7 +55,6 @@
#include "nsIStreamListener.h"
#include "nsIMIMEService.h"
#include "nsILoadGroup.h"
#include "nsCURILoader.h"
#include "nsIWebProgressListener.h"
#include "nsIDownload.h"
#include "nsReadableUtils.h"
@ -1453,10 +1452,6 @@ void nsExternalAppHandler::RetargetLoadNotifications(nsIRequest *request)
aChannel->SetLoadGroup(nsnull);
aChannel->SetNotificationCallbacks(nsnull);
nsCOMPtr<nsIURILoader> uriLoader(do_GetService(NS_URI_LOADER_CONTRACTID));
if (!uriLoader)
return;
// we need to store off the original (pre redirect!) channel that initiated the load. We do
// this so later on, we can pass any refresh urls associated with the original channel back to the
// window context which started the whole process. More comments about that are listed below....
@ -1465,8 +1460,8 @@ void nsExternalAppHandler::RetargetLoadNotifications(nsIRequest *request)
// the default load channel associated with the original load group. Unfortunately because
// a redirect may have occurred, the doc loader is the only one with a ptr to the original channel
// which is what we really want....
nsCOMPtr<nsIDocumentLoader> origContextLoader;
uriLoader->GetDocumentLoaderForContext(mWindowContext, getter_AddRefs(origContextLoader));
nsCOMPtr<nsIDocumentLoader> origContextLoader =
do_GetInterface(mWindowContext);
if (origContextLoader)
origContextLoader->GetDocumentChannel(getter_AddRefs(mOriginalChannel));
}

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

@ -1,111 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsIWebShell_h___
#define nsIWebShell_h___
#include "nsIContentViewerContainer.h"
class nsIDocumentLoader;
class nsIURI;
// Interface ID for nsIWebShell
#define NS_IWEB_SHELL_IID \
{ 0xa6cf9058, 0x15b3, 0x11d2,{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
// Interface ID for nsIWebShellContainer
#define NS_IWEB_SHELL_CONTAINER_IID \
{ 0xa6cf905a, 0x15b3, 0x11d2,{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
// Class ID for an implementation of nsIWebShell
#define NS_WEB_SHELL_CID \
{ 0xa6cf9059, 0x15b3, 0x11d2,{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
//----------------------------------------------------------------------
typedef enum {
nsLoadURL,
nsLoadHistory,
nsLoadLink,
nsLoadRefresh
} nsLoadType;
// Container for web shell's
class nsIWebShellContainer : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IWEB_SHELL_CONTAINER_IID)
};
//----------------------------------------------------------------------
/**
* The web shell is a container for implementations of nsIContentViewer.
* It is a content-viewer-container and also knows how to delegate certain
* behavior to an nsIWebShellContainer.
*
* Web shells can be arranged in a tree.
*
* Web shells are also nsIWebShellContainer's because they can contain
* other web shells.
*/
class nsIWebShell : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IWEB_SHELL_IID)
/**
* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING !!!!
*
* THIS INTERFACE IS DEPRECATED. DO NOT ADD STUFF OR CODE TO IT!!!!
*/
/**
* Set the nsIWebShellContainer for the WebShell.
*/
NS_IMETHOD SetContainer(nsIWebShellContainer* aContainer) = 0;
/**
* Return the current nsIWebShellContainer.
*/
NS_IMETHOD GetContainer(nsIWebShellContainer*& aResult) = 0;
/**
* Return the nsIDocumentLoader associated with the WebShell.
*/
NS_IMETHOD GetDocumentLoader(nsIDocumentLoader*& aResult) = 0;
};
#endif /* nsIWebShell_h___ */