From 8d173621f0ddc080dae3cb8440c7cb38cba1cbcf Mon Sep 17 00:00:00 2001 From: "akkana%netscape.com" Date: Sat, 27 Jan 2001 01:08:36 +0000 Subject: [PATCH] 56296: Disable popping up new window on target=, pref controlled. r=dveditz, sr=brendan git-svn-id: svn://10.0.0.236/trunk@85601 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/docshell/base/nsDocShell.cpp | 33 +++++++++++++++++++++++-- mozilla/docshell/base/nsDocShell.h | 3 +++ mozilla/modules/libpref/src/init/all.js | 2 ++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index 1d903da7a6c..b9e7c392dd7 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -126,13 +126,14 @@ nsDocShell::nsDocShell() : mViewMode(viewNormal), mLastViewMode(viewNormal), mRestoreViewMode(PR_FALSE), + mBusyFlags(BUSY_FLAGS_NONE), mEODForCurrentDocument (PR_FALSE), mURIResultedInDocument(PR_FALSE), mUseExternalProtocolHandler (PR_FALSE), + mDisallowPopupWindows(PR_FALSE), mParent(nsnull), mTreeOwner(nsnull), - mChromeEventHandler(nsnull), - mBusyFlags(BUSY_FLAGS_NONE) + mChromeEventHandler(nsnull) { NS_INIT_REFCNT(); } @@ -1665,6 +1666,7 @@ NS_IMETHODIMP nsDocShell::Create() // i don't want to read this pref in every time we load a url // so read it in once here and be done with it... mPrefs->GetBoolPref("network.protocols.useSystemDefaults", &mUseExternalProtocolHandler); + mPrefs->GetBoolPref("browser.target_new_blocked", &mDisallowPopupWindows); return NS_OK; } @@ -2148,6 +2150,7 @@ NS_IMETHODIMP nsDocShell::SetCurScrollPos(PRInt32 scrollOrientation, default: NS_ENSURE_TRUE(PR_FALSE, NS_ERROR_INVALID_ARG); + x=0; y=0; // fix compiler warning, not actually executed } NS_ENSURE_SUCCESS(scrollView->ScrollTo(x, y, NS_VMREFRESH_IMMEDIATE), @@ -3039,6 +3042,32 @@ NS_IMETHODIMP nsDocShell::InternalLoad(nsIURI* aURI, nsIURI* aReferrer, PRUint32 aLoadType) #endif { + if (mDisallowPopupWindows && aWindowTarget && aWindowTarget[0] != '\0') + { + nsXPIDLCString scheme; + nsresult rv = aURI->GetScheme(getter_Copies(scheme)); + if (NS_SUCCEEDED(rv) && + nsCRT::strcmp(scheme, "chrome") && + nsCRT::strcmp(scheme, "resource")) + { + static const char top[] = "_top"; + if (!nsCRT::strcmp(aWindowTarget, "_blank") || + !nsCRT::strcmp(aWindowTarget, "_new")) + { + aWindowTarget = top; + } + else + { + nsCOMPtr targetDocShell; + FindItemWithName(NS_ConvertASCIItoUCS2(aWindowTarget).GetUnicode(), + NS_STATIC_CAST(nsIInterfaceRequestor*, this), + getter_AddRefs(targetDocShell)); + if (!targetDocShell) + aWindowTarget = top; + } + } + } + mURIResultedInDocument = PR_FALSE; // reset the clock... // Check to see if the new URI is an anchor in the existing document. if ((aLoadType == LOAD_NORMAL || diff --git a/mozilla/docshell/base/nsDocShell.h b/mozilla/docshell/base/nsDocShell.h index d3ba4ff054d..1fcee615fda 100644 --- a/mozilla/docshell/base/nsDocShell.h +++ b/mozilla/docshell/base/nsDocShell.h @@ -322,6 +322,9 @@ protected: // figured out how to do that yet. PRBool mUseExternalProtocolHandler; + // Disallow popping up new windows with target= + PRBool mDisallowPopupWindows; + /* WEAK REFERENCES BELOW HERE. Note these are intentionally not addrefd. Doing so will create a cycle. For that reasons don't use nsCOMPtr.*/ diff --git a/mozilla/modules/libpref/src/init/all.js b/mozilla/modules/libpref/src/init/all.js index 033bb916e9a..f06d80cb8bf 100644 --- a/mozilla/modules/libpref/src/init/all.js +++ b/mozilla/modules/libpref/src/init/all.js @@ -97,6 +97,8 @@ pref("browser.PICS.reenable_for_this_session", false); pref("browser.PICS.service.http___home_netscape_com_default_rating.service_enabled", true); pref("browser.PICS.service.http___home_netscape_com_default_rating.s", 0); +pref("browser.target_new_blocked", false); + // gfx widgets pref("nglayout.widget.mode", 2); pref("nglayout.widget.gfxscrollbars", true);