NS_IMETHODIMP nsURLFetcher::SetLoadCookie(nsISupports * aLoadCookie) { // Remove the DocShell as a listener of the old WebProgress... if (mLoadCookie) { nsCOMPtr<nsIWebProgress> webProgress(do_QueryInterface(mLoadCookie)); if (webProgress) webProgress->RemoveProgressListener(this); } mLoadCookie = aLoadCookie; // 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_ALL); } return NS_OK; }
nsURLFetcher::~nsURLFetcher() { mStillRunning = false; PR_FREEIF(mBuffer); // Remove the DocShell as a listener of the old WebProgress... if (mLoadCookie) { nsCOMPtr<nsIWebProgress> webProgress(do_QueryInterface(mLoadCookie)); if (webProgress) webProgress->RemoveProgressListener(this); } }
NS_IMETHODIMP nsMsgWindow::SetStatusFeedback(nsIMsgStatusFeedback * aStatusFeedback) { mStatusFeedback = aStatusFeedback; nsCOMPtr<nsIDocShell> messageWindowDocShell; GetMessageWindowDocShell(getter_AddRefs(messageWindowDocShell)); // register our status feedback object as a web progress listener nsCOMPtr<nsIWebProgress> webProgress(do_GetInterface(messageWindowDocShell)); if (webProgress && mStatusFeedback && messageWindowDocShell) { nsCOMPtr<nsIWebProgressListener> webProgressListener = do_QueryInterface(mStatusFeedback); webProgress->AddProgressListener(webProgressListener, nsIWebProgress::NOTIFY_ALL); } return NS_OK; }
// nsIBaseWindow NS_IMETHODIMP nsWebShellWindow::Destroy() { nsresult rv; nsCOMPtr<nsIWebProgress> webProgress(do_GetInterface(mDocShell, &rv)); if (webProgress) { webProgress->RemoveProgressListener(this); } nsCOMPtr<nsIXULWindow> kungFuDeathGrip(this); if (mSPTimerLock) { PR_Lock(mSPTimerLock); if (mSPTimer) { mSPTimer->Cancel(); SavePersistentAttributes(); mSPTimer = nsnull; NS_RELEASE_THIS(); // the timer held a reference to us } PR_Unlock(mSPTimerLock); PR_DestroyLock(mSPTimerLock); mSPTimerLock = nsnull; } return nsXULWindow::Destroy(); }
nsresult nsWebShellWindow::Initialize(nsIXULWindow* aParent, nsIAppShell* aShell, nsIURI* aUrl, PRInt32 aInitialWidth, PRInt32 aInitialHeight, PRBool aIsHiddenWindow, nsWidgetInitData& widgetInitData) { nsresult rv; nsCOMPtr<nsIWidget> parentWidget; mIsHiddenWindow = aIsHiddenWindow; // XXX: need to get the default window size from prefs... // Doesn't come from prefs... will come from CSS/XUL/RDF nsRect r(0, 0, aInitialWidth, aInitialHeight); // Create top level window mWindow = do_CreateInstance(kWindowCID, &rv); if (NS_OK != rv) { return rv; } /* This next bit is troublesome. We carry two different versions of a pointer to our parent window. One is the parent window's widget, which is passed to our own widget. The other is a weak reference we keep here to our parent WebShellWindow. The former is useful to the widget, and we can't trust its treatment of the parent reference because they're platform- specific. The latter is useful to this class. A better implementation would be one in which the parent keeps strong references to its children and closes them before it allows itself to be closed. This would mimic the behaviour of OSes that support top-level child windows in OSes that do not. Later. */ nsCOMPtr<nsIBaseWindow> parentAsWin(do_QueryInterface(aParent)); if (parentAsWin) { parentAsWin->GetMainWidget(getter_AddRefs(parentWidget)); mParentWindow = do_GetWeakReference(aParent); } mWindow->SetClientData(this); mWindow->Create((nsIWidget *)parentWidget, // Parent nsIWidget r, // Widget dimensions nsWebShellWindow::HandleEvent, // Event handler function nsnull, // Device context aShell, // Application shell nsnull, // nsIToolkit &widgetInitData); // Widget initialization data mWindow->GetClientBounds(r); mWindow->SetBackgroundColor(NS_RGB(192,192,192)); // Create web shell mDocShell = do_CreateInstance("@mozilla.org/webshell;1"); NS_ENSURE_TRUE(mDocShell, NS_ERROR_FAILURE); // Make sure to set the item type on the docshell _before_ calling // Create() so it knows what type it is. nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(mDocShell)); NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE); NS_ENSURE_SUCCESS(EnsureChromeTreeOwner(), NS_ERROR_FAILURE); docShellAsItem->SetTreeOwner(mChromeTreeOwner); docShellAsItem->SetItemType(nsIDocShellTreeItem::typeChrome); r.x = r.y = 0; nsCOMPtr<nsIBaseWindow> docShellAsWin(do_QueryInterface(mDocShell)); NS_ENSURE_SUCCESS(docShellAsWin->InitWindow(nsnull, mWindow, r.x, r.y, r.width, r.height), NS_ERROR_FAILURE); NS_ENSURE_SUCCESS(docShellAsWin->Create(), NS_ERROR_FAILURE); // Attach a WebProgress listener.during initialization... nsCOMPtr<nsIWebProgress> webProgress(do_GetInterface(mDocShell, &rv)); if (webProgress) { webProgress->AddProgressListener(this, nsIWebProgress::NOTIFY_STATE_NETWORK); } if (nsnull != aUrl) { nsCAutoString tmpStr; rv = aUrl->GetSpec(tmpStr); if (NS_FAILED(rv)) return rv; NS_ConvertUTF8toUCS2 urlString(tmpStr); nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mDocShell)); NS_ENSURE_TRUE(webNav, NS_ERROR_FAILURE); rv = webNav->LoadURI(urlString.get(), nsIWebNavigation::LOAD_FLAGS_NONE, nsnull, nsnull, nsnull); NS_ENSURE_SUCCESS(rv, rv); } return rv; }