Bug 107949, Allow the user to prevent sites from disabling window features via window.open(). r=danm, sr=jag

This commit is contained in:
caillon%returnzero.com 2002-06-04 22:24:00 +00:00
parent 8f814b2b04
commit e619a700c4
7 changed files with 97 additions and 50 deletions

View File

@ -36,6 +36,7 @@ REQUIRES = xpcom \
xpconnect \
caps \
content \
pref \
necko \
uriloader \
docshell \

View File

@ -30,6 +30,7 @@ REQUIRES = xpcom \
xpconnect \
caps \
content \
pref \
necko \
uriloader \
docshell \

View File

@ -76,6 +76,9 @@
#include "nsIXPConnect.h"
#include "nsPIDOMWindow.h"
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
#ifdef XP_UNIX
// please see bug 78421 for the eventual "right" fix for this
#define HAVE_LAME_APPSHELL
@ -1082,6 +1085,16 @@ void nsWindowWatcher::CheckWindowName(nsString& aName)
}
}
#define NS_CALCULATE_CHROME_FLAG_FOR(feature, flag) \
prefBranch->GetBoolPref(feature, &forceEnable); \
if (forceEnable && !isChrome) { \
chromeFlags |= flag; \
} else { \
chromeFlags |= WinHasOption(aFeatures, feature, \
0, &presenceFlag) \
? flag : 0; \
}
/**
* Calculate the chrome bitmask from a string list of features.
* @param aFeatures a string containing a list of named chrome features
@ -1120,27 +1133,45 @@ PRUint32 nsWindowWatcher::CalculateChromeFlags(const char *aFeatures,
/* Next, allow explicitly named options to override the initial settings */
chromeFlags |= WinHasOption(aFeatures, "titlebar", 0, &presenceFlag)
? nsIWebBrowserChrome::CHROME_TITLEBAR : 0;
chromeFlags |= WinHasOption(aFeatures, "close", 0, &presenceFlag)
? nsIWebBrowserChrome::CHROME_WINDOW_CLOSE : 0;
chromeFlags |= WinHasOption(aFeatures, "toolbar", 0, &presenceFlag)
? nsIWebBrowserChrome::CHROME_TOOLBAR : 0;
chromeFlags |= WinHasOption(aFeatures, "location", 0, &presenceFlag)
? nsIWebBrowserChrome::CHROME_LOCATIONBAR : 0;
chromeFlags |= (WinHasOption(aFeatures, "directories", 0, &presenceFlag) ||
WinHasOption(aFeatures, "personalbar", 0, &presenceFlag))
? nsIWebBrowserChrome::CHROME_PERSONAL_TOOLBAR : 0;
chromeFlags |= WinHasOption(aFeatures, "status", 0, &presenceFlag)
? nsIWebBrowserChrome::CHROME_STATUSBAR : 0;
chromeFlags |= WinHasOption(aFeatures, "menubar", 0, &presenceFlag)
? nsIWebBrowserChrome::CHROME_MENUBAR : 0;
chromeFlags |= WinHasOption(aFeatures, "scrollbars", 0, &presenceFlag)
? nsIWebBrowserChrome::CHROME_SCROLLBARS : 0;
chromeFlags |= WinHasOption(aFeatures, "resizable", 0, &presenceFlag)
? nsIWebBrowserChrome::CHROME_WINDOW_RESIZE : 0;
chromeFlags |= WinHasOption(aFeatures, "minimizable", 0, &presenceFlag)
? nsIWebBrowserChrome::CHROME_WINDOW_MIN : 0;
nsCOMPtr<nsIScriptSecurityManager>
securityManager(do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID));
NS_ENSURE_TRUE(securityManager, NS_ERROR_FAILURE);
PRBool isChrome = PR_FALSE;
securityManager->SubjectPrincipalIsSystem(&isChrome);
nsCOMPtr<nsIPrefBranch> prefBranch;
nsresult rv;
nsCOMPtr<nsIPrefService> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, PR_TRUE);
rv = prefs->GetBranch("dom.disable_window_open_feature.", getter_AddRefs(prefBranch));
NS_ENSURE_SUCCESS(rv, PR_TRUE);
PRBool forceEnable = PR_FALSE;
NS_CALCULATE_CHROME_FLAG_FOR("titlebar",
nsIWebBrowserChrome::CHROME_TITLEBAR);
NS_CALCULATE_CHROME_FLAG_FOR("close",
nsIWebBrowserChrome::CHROME_WINDOW_CLOSE);
NS_CALCULATE_CHROME_FLAG_FOR("toolbar",
nsIWebBrowserChrome::CHROME_TOOLBAR);
NS_CALCULATE_CHROME_FLAG_FOR("location",
nsIWebBrowserChrome::CHROME_LOCATIONBAR);
NS_CALCULATE_CHROME_FLAG_FOR("directories",
nsIWebBrowserChrome::CHROME_PERSONAL_TOOLBAR);
NS_CALCULATE_CHROME_FLAG_FOR("personalbar",
nsIWebBrowserChrome::CHROME_PERSONAL_TOOLBAR);
NS_CALCULATE_CHROME_FLAG_FOR("status",
nsIWebBrowserChrome::CHROME_STATUSBAR);
NS_CALCULATE_CHROME_FLAG_FOR("menubar",
nsIWebBrowserChrome::CHROME_MENUBAR);
NS_CALCULATE_CHROME_FLAG_FOR("scrollbars",
nsIWebBrowserChrome::CHROME_SCROLLBARS);
NS_CALCULATE_CHROME_FLAG_FOR("resizable",
nsIWebBrowserChrome::CHROME_WINDOW_RESIZE);
NS_CALCULATE_CHROME_FLAG_FOR("minimizable",
nsIWebBrowserChrome::CHROME_WINDOW_MIN);
chromeFlags |= WinHasOption(aFeatures, "popup", 0, &presenceFlag)
? nsIWebBrowserChrome::CHROME_WINDOW_POPUP : 0;
@ -1197,16 +1228,10 @@ PRUint32 nsWindowWatcher::CalculateChromeFlags(const char *aFeatures,
chromeFlags->copy_history
*/
//Check security state for use in determing window dimensions
nsCOMPtr<nsIScriptSecurityManager>
securityManager(do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID));
NS_ENSURE_TRUE(securityManager, NS_ERROR_FAILURE);
// Check security state for use in determing window dimensions
PRBool enabled;
nsresult res =
securityManager->IsCapabilityEnabled("UniversalBrowserWrite", &enabled);
res = securityManager->IsCapabilityEnabled("UniversalBrowserWrite", &enabled);
if (NS_FAILED(res) || !enabled) {
//If priv check fails, set all elements to minimum reqs., else leave them alone.
@ -1235,7 +1260,7 @@ nsWindowWatcher::WinHasOption(const char *aOptions, const char *aName,
while (PR_TRUE) {
while (nsCRT::IsAsciiSpace(*aOptions))
aOptions++;
++aOptions;
comma = PL_strchr(aOptions, ',');
if (comma)

View File

@ -362,6 +362,18 @@ pref("dom.disable_window_flip", false);
pref("dom.disable_window_move_resize", false);
pref("dom.disable_window_status_change", false);
pref("dom.disable_window_open_feature.titlebar", false);
pref("dom.disable_window_open_feature.close", false);
pref("dom.disable_window_open_feature.toolbar", false);
pref("dom.disable_window_open_feature.location", false);
pref("dom.disable_window_open_feature.directories", false);
pref("dom.disable_window_open_feature.personalbar", false);
pref("dom.disable_window_open_feature.menubar", false);
pref("dom.disable_window_open_feature.scrollbars", false);
pref("dom.disable_window_open_feature.resizable", false);
pref("dom.disable_window_open_feature.minimizable", false);
pref("dom.disable_window_open_feature.status", false);
pref("javascript.enabled", true);
pref("javascript.allow.mailnews", false);
pref("javascript.options.strict", false);

View File

@ -51,6 +51,7 @@ function changeDisabledState(state){
document.getElementById("allowDocumentCookieGet").disabled = state;
document.getElementById("allowWindowStatusChange").disabled = state;
document.getElementById("allowWindowFlip").disabled = state;
document.getElementById("allowHideStatusBar").disabled = state;
}
function javascriptEnabledChange(){
@ -87,10 +88,16 @@ function Startup(){
//If scriptData does not exist, then it is the first time the panel was shown and we default to false
if (!("scriptData" in data)){
var changedList = ["allowWindowOpenChanged", "allowTargetNewChanged",
"allowWindowMoveResizeChanged", "allowWindowStatusChangeChanged",
"allowWindowFlipChanged", "allowDocumentCookieSetChanged",
"allowDocumentCookieGetChanged", "allowImageSrcChangeChanged"];
var changedList = ["allowWindowOpenChanged",
"allowTargetNewChanged",
"allowWindowMoveResizeChanged",
"allowWindowStatusChangeChanged",
"allowWindowFlipChanged",
"allowDocumentCookieSetChanged",
"allowDocumentCookieGetChanged",
"allowImageSrcChangeChanged",
"allowHideStatusBarChanged"];
data.scriptData = [];
for(var run = 0; run < changedList.length; run++ ){
data.scriptData[ changedList[run] ] = [];
@ -105,28 +112,13 @@ function Startup(){
document.getElementById("allowImageSrcChange").checked = getPrefValueForCheckbox("dom.disable_image_src_set");
document.getElementById("allowDocumentCookieGet").checked = getPrefValueForCheckbox("dom.disable_cookie_get");
document.getElementById("allowDocumentCookieSet").checked = getPrefValueForCheckbox("dom.disable_cookie_set");
document.getElementById("allowHideStatusBar").checked = getPrefValueForCheckbox("dom.disable_window_open_feature.status");
//If we don't have a checkbox under groupbox pluginPreferences, we should hide it
var pluginGroup = document.getElementById("pluginPreferences")
var children = pluginGroup.childNodes;
if (!children || children.length <= 1) // 1 for the caption
pluginGroup.setAttribute("hidden", "true");
} else { //not first time it was loaded, get default values from data
document.getElementById("allowWindowOpen").checked = data["allowWindowOpen"].checked;
document.getElementById("allowTargetNew").checked = data["allowTargetNew"].checked;
document.getElementById("allowWindowMoveResize").checked = data["allowWindowMoveResize"].checked;
document.getElementById("allowWindowFlip").checked = data["allowWindowFlip"].checked;
document.getElementById("allowWindowStatusChange").checked = data["allowWindowStatusChange"].checked;
document.getElementById("allowImageSrcChange").checked = data["allowImageSrcChange"].checked;
document.getElementById("allowDocumentCookieSet").checked = data["allowDocumentCookieSet"].checked;
document.getElementById("allowDocumentCookieGet").checked = data["allowDocumentCookieGet"].checked;
document.getElementById("javascriptAllowNavigator").checked = data["javascriptAllowNavigator"].checked;
if (document.getElementById("javascriptAllowMailnews")) {
document.getElementById("javascriptAllowMailNews").checked = data["javascriptAllowMailNews"].checked;
}
}
javascriptEnabledChange();
@ -193,6 +185,11 @@ function doOnOk(){
parent.hPrefWindow.setPref("bool", "dom.disable_image_src_set",
!getCheckboxValue("allowImageSrcChange"));
}
if (data.scriptData["allowHideStatusBarChanged"].value) {
parent.hPrefWindow.setPref("bool", "dom.disable_window_open_feature.status",
!getCheckboxValue("allowHideStatusBar"));
}
}
function onCheckboxCheck(event)

View File

@ -52,7 +52,16 @@
<script type="application/x-javascript">
<![CDATA[
var panel = "chrome://communicator/content/pref/pref-scripts.xul";
var _elementIDs = ["javascriptAllowNavigator", "allowWindowOpen", "allowWindowMoveResize", "allowWindowFlip", "allowWindowStatusChange", "allowImageSrcChange", "allowDocumentCookieSet", "allowDocumentCookieGet","allowTargetNew"];
var _elementIDs = ["javascriptAllowNavigator",
"allowWindowOpen",
"allowWindowMoveResize",
"allowWindowFlip",
"allowWindowStatusChange",
"allowImageSrcChange",
"allowDocumentCookieSet",
"allowDocumentCookieGet",
"allowTargetNew",
"allowHideStatusBar"];
]]>
</script>
@ -72,6 +81,7 @@
<listitem type="checkbox" id="allowTargetNew" label="&allowTargetNew.label;"/>
<listitem type="checkbox" id="allowWindowMoveResize" label="&allowWindowMoveResize.label;"/>
<listitem type="checkbox" id="allowWindowFlip" label="&allowWindowFlip.label;"/>
<listitem type="checkbox" id="allowHideStatusBar" label="&allowHideStatusBar.label;"/>
<listitem type="checkbox" id="allowWindowStatusChange" label="&allowWindowStatusChange.label;"/>
<listitem type="checkbox" id="allowImageSrcChange" label="&allowWindowImageSrcChange.label;"/>
<listitem type="checkbox" id="allowDocumentCookieSet" label="&allowDocumentCookieSet.label;"/>

View File

@ -17,5 +17,6 @@
<!ENTITY allowWindowImageSrcChange.label "Change images">
<!ENTITY allowDocumentCookieSet.label "Create or change cookies">
<!ENTITY allowDocumentCookieGet.label "Read cookies">
<!ENTITY allowHideStatusBar.label "Hide the status bar">
<!ENTITY enablePlugin.label "Enable Plugins for">