Bug 117707. Disabling most of the prefs in Edit>Prefs>Advanced>Scripts/Windows was causing real JS scripts to break because it used CAPS. Move the checks for these features into C++, with new prefs. Patch by doronr@naboonline.com (initial work) and caillon@returnzero.com. r=fabian sr=jst a=asa.
git-svn-id: svn://10.0.0.236/trunk@118839 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
90f86714b6
commit
d283e6e7a2
@ -58,6 +58,8 @@ public:
|
||||
nsIDocument *aNewDocument,
|
||||
nsIDocument *aOldDocument);
|
||||
|
||||
static PRBool IsCallerChrome();
|
||||
|
||||
// These are copied from nsJSUtils.h
|
||||
|
||||
static nsresult GetStaticScriptGlobal(JSContext* aContext,
|
||||
|
||||
@ -47,6 +47,11 @@
|
||||
#include "nsIDocument.h"
|
||||
#include "nsINodeInfo.h"
|
||||
|
||||
#include "nsIJSContextStack.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsIDocShellTreeItem.h"
|
||||
|
||||
static const char *sJSStackContractID = "@mozilla.org/js/xpc/ContextStack;1";
|
||||
|
||||
nsIDOMScriptObjectFactory *nsContentUtils::sDOMScriptObjectFactory = nsnull;
|
||||
nsIXPConnect *nsContentUtils::sXPConnect = nsnull;
|
||||
@ -516,3 +521,36 @@ nsContentUtils::ReparentContentWrapper(nsIContent *aContent,
|
||||
obj);
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsContentUtils::IsCallerChrome()
|
||||
{
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
nsCOMPtr<nsIThreadJSContextStack> stack(do_GetService(sJSStackContractID));
|
||||
|
||||
if (stack) {
|
||||
JSContext *cx = nsnull;
|
||||
stack->Peek(&cx);
|
||||
|
||||
if (cx) {
|
||||
nsCOMPtr<nsIScriptGlobalObject> sgo;
|
||||
nsContentUtils::GetDynamicScriptGlobal(cx, getter_AddRefs(sgo));
|
||||
|
||||
if (sgo) {
|
||||
sgo->GetDocShell(getter_AddRefs(docShell));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> item(do_QueryInterface(docShell));
|
||||
if (item) {
|
||||
PRInt32 callerType = nsIDocShellTreeItem::typeChrome;
|
||||
item->GetItemType(&callerType);
|
||||
|
||||
if (callerType != nsIDocShellTreeItem::typeChrome) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
|
||||
@ -68,6 +68,7 @@
|
||||
#include "nsGUIEvent.h"
|
||||
#include "nsContentPolicyUtils.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIPref.h"
|
||||
|
||||
#include "imgIContainer.h"
|
||||
#include "imgILoader.h"
|
||||
@ -80,6 +81,8 @@
|
||||
|
||||
#include "nsIJSContextStack.h"
|
||||
|
||||
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
|
||||
|
||||
// XXX nav attrs: suppress
|
||||
|
||||
class nsHTMLImageElement : public nsGenericHTMLLeafElement,
|
||||
@ -970,6 +973,21 @@ nsHTMLImageElement::SetSrcInner(nsIURI* aBaseURL,
|
||||
NS_IMETHODIMP
|
||||
nsHTMLImageElement::SetSrc(const nsAString& aSrc)
|
||||
{
|
||||
/*
|
||||
* If caller is not chrome and dom.disable_image_src_set is true,
|
||||
* prevent setting image.src by exiting early
|
||||
*/
|
||||
|
||||
nsCOMPtr<nsIPref> prefs(do_GetService(kPrefServiceCID));
|
||||
if (prefs) {
|
||||
PRBool disableImageSrcSet = PR_FALSE;
|
||||
prefs->GetBoolPref("dom.disable_image_src_set", &disableImageSrcSet);
|
||||
|
||||
if (disableImageSrcSet && !nsContentUtils::IsCallerChrome()) {
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIURI> baseURL;
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
|
||||
@ -158,6 +158,8 @@ static NS_DEFINE_CID(kCookieServiceCID, NS_COOKIESERVICE_CID);
|
||||
|
||||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
|
||||
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
|
||||
|
||||
static PRBool
|
||||
IsNamedItem(nsIContent* aContent, nsIAtom *aTag, nsAString& aName);
|
||||
|
||||
@ -2148,10 +2150,24 @@ nsHTMLDocument::GetAnchors(nsIDOMHTMLCollection** aAnchors)
|
||||
NS_IMETHODIMP
|
||||
nsHTMLDocument::GetCookie(nsAString& aCookie)
|
||||
{
|
||||
aCookie.Truncate(); // clear current cookie in case service fails;
|
||||
// no cookie isn't an error condition.
|
||||
|
||||
// If caller is not chrome and dom.disable_cookie_get is true,
|
||||
// prevent getting cookies by exiting early
|
||||
nsCOMPtr<nsIPref> prefs(do_GetService(kPrefServiceCID));
|
||||
if (prefs) {
|
||||
PRBool disableCookieGet = PR_FALSE;
|
||||
prefs->GetBoolPref("dom.disable_cookie_get", &disableCookieGet);
|
||||
|
||||
if (disableCookieGet && !nsContentUtils::IsCallerChrome()) {
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
nsresult result = NS_OK;
|
||||
nsAutoString str;
|
||||
|
||||
aCookie.Truncate(); // clear current cookie in case service fails; no cookie isn't an error condition.
|
||||
|
||||
nsCOMPtr<nsICookieService> service = do_GetService(kCookieServiceCID, &result);
|
||||
if (NS_SUCCEEDED(result) && service && mDocumentURL) {
|
||||
@ -2166,6 +2182,17 @@ nsHTMLDocument::GetCookie(nsAString& aCookie)
|
||||
NS_IMETHODIMP
|
||||
nsHTMLDocument::SetCookie(const nsAString& aCookie)
|
||||
{
|
||||
// If caller is not chrome and dom.disable_cookie_get is true,
|
||||
// prevent setting cookies by exiting early
|
||||
nsCOMPtr<nsIPref> prefs(do_GetService(kPrefServiceCID));
|
||||
if (prefs) {
|
||||
PRBool disableCookieSet = PR_FALSE;
|
||||
prefs->GetBoolPref("dom.disable_cookie_set", &disableCookieSet);
|
||||
if (disableCookieSet && !nsContentUtils::IsCallerChrome()) {
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
nsresult result = NS_OK;
|
||||
nsCOMPtr<nsICookieService> service = do_GetService(kCookieServiceCID, &result);
|
||||
if (NS_SUCCEEDED(result) && service && mDocumentURL) {
|
||||
|
||||
@ -170,6 +170,50 @@ static const char *kDOMBundleURL = "chrome://global/locale/commonDialogs.propert
|
||||
static const char * const kCryptoContractID = NS_CRYPTO_CONTRACTID;
|
||||
static const char * const kPkcs11ContractID = NS_PKCS11_CONTRACTID;
|
||||
|
||||
static PRBool IsCallerChrome()
|
||||
{
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
nsCOMPtr<nsIThreadJSContextStack> stack(do_GetService(sJSStackContractID));
|
||||
if (stack) {
|
||||
JSContext *cx = nsnull;
|
||||
stack->Peek(&cx);
|
||||
|
||||
if (cx) {
|
||||
nsCOMPtr<nsIScriptGlobalObject> sgo;
|
||||
nsJSUtils::GetDynamicScriptGlobal(cx, getter_AddRefs(sgo));
|
||||
if (sgo) {
|
||||
sgo->GetDocShell(getter_AddRefs(docShell));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> item(do_QueryInterface(docShell));
|
||||
if (item) {
|
||||
PRInt32 callerType = nsIDocShellTreeItem::typeChrome;
|
||||
item->GetItemType(&callerType);
|
||||
|
||||
if (callerType != nsIDocShellTreeItem::typeChrome) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
static PRBool CanSetProperty(const char * prefName)
|
||||
{
|
||||
nsCOMPtr<nsIPref> prefs(do_GetService(kPrefServiceCID));
|
||||
if (!prefs) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool prefValue = PR_TRUE;
|
||||
// if pref is set to true, we can't set the property
|
||||
prefs->GetBoolPref(prefName, &prefValue);
|
||||
|
||||
return !prefValue;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//*** GlobalWindowImpl: Object Management
|
||||
//*****************************************************************************
|
||||
@ -1261,6 +1305,15 @@ GlobalWindowImpl::GetStatus(nsAString& aStatus)
|
||||
NS_IMETHODIMP
|
||||
GlobalWindowImpl::SetStatus(const nsAString& aStatus)
|
||||
{
|
||||
/*
|
||||
* If caller is not chrome and dom.disable_window_status_change is true,
|
||||
* prevent setting window.status by exiting early
|
||||
*/
|
||||
|
||||
if (!CanSetProperty("dom.disable_window_status_change") && !IsCallerChrome()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
mStatus = aStatus;
|
||||
|
||||
nsCOMPtr<nsIWebBrowserChrome> browserChrome;
|
||||
@ -1283,13 +1336,23 @@ GlobalWindowImpl::GetDefaultStatus(nsAString& aDefaultStatus)
|
||||
NS_IMETHODIMP
|
||||
GlobalWindowImpl::SetDefaultStatus(const nsAString& aDefaultStatus)
|
||||
{
|
||||
/*
|
||||
* If caller is not chrome and dom.disable_window_status_change is true,
|
||||
* prevent setting window.defaultStatus by exiting early
|
||||
*/
|
||||
|
||||
if (!CanSetProperty("dom.disable_window_status_change") && !IsCallerChrome()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
mDefaultStatus = aDefaultStatus;
|
||||
|
||||
nsCOMPtr<nsIWebBrowserChrome> browserChrome;
|
||||
GetWebBrowserChrome(getter_AddRefs(browserChrome));
|
||||
if(browserChrome)
|
||||
browserChrome->SetStatus(nsIWebBrowserChrome::STATUS_SCRIPT_DEFAULT,
|
||||
PromiseFlatString(aDefaultStatus).get());
|
||||
nsCOMPtr<nsIWebBrowserChrome> browserChrome;
|
||||
GetWebBrowserChrome(getter_AddRefs(browserChrome));
|
||||
if (browserChrome) {
|
||||
browserChrome->SetStatus(nsIWebBrowserChrome::STATUS_SCRIPT_DEFAULT,
|
||||
PromiseFlatString(aDefaultStatus).get());
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@ -1332,6 +1395,15 @@ GlobalWindowImpl::GetInnerWidth(PRInt32* aInnerWidth)
|
||||
NS_IMETHODIMP
|
||||
GlobalWindowImpl::SetInnerWidth(PRInt32 aInnerWidth)
|
||||
{
|
||||
/*
|
||||
* If caller is not chrome and dom.disable_window_move_resize is true,
|
||||
* prevent setting window.innerWidth by exiting early
|
||||
*/
|
||||
|
||||
if (!CanSetProperty("dom.disable_window_move_resize") && !IsCallerChrome()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(mDocShell));
|
||||
NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE);
|
||||
|
||||
@ -1374,6 +1446,15 @@ GlobalWindowImpl::GetInnerHeight(PRInt32* aInnerHeight)
|
||||
NS_IMETHODIMP
|
||||
GlobalWindowImpl::SetInnerHeight(PRInt32 aInnerHeight)
|
||||
{
|
||||
/*
|
||||
* If caller is not chrome and dom.disable_window_move_resize is true,
|
||||
* prevent setting window.innerHeight by exiting early
|
||||
*/
|
||||
|
||||
if (!CanSetProperty("dom.disable_window_move_resize") && !IsCallerChrome()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(mDocShell));
|
||||
NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE);
|
||||
|
||||
@ -1419,6 +1500,15 @@ GlobalWindowImpl::GetOuterWidth(PRInt32* aOuterWidth)
|
||||
NS_IMETHODIMP
|
||||
GlobalWindowImpl::SetOuterWidth(PRInt32 aOuterWidth)
|
||||
{
|
||||
/*
|
||||
* If caller is not chrome and dom.disable_window_move_resize is true,
|
||||
* prevent setting window.outerWidth by exiting early
|
||||
*/
|
||||
|
||||
if (!CanSetProperty("dom.disable_window_move_resize") && !IsCallerChrome()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIBaseWindow> treeOwnerAsWin;
|
||||
GetTreeOwner(getter_AddRefs(treeOwnerAsWin));
|
||||
NS_ENSURE_TRUE(treeOwnerAsWin, NS_ERROR_FAILURE);
|
||||
@ -1453,6 +1543,15 @@ GlobalWindowImpl::GetOuterHeight(PRInt32* aOuterHeight)
|
||||
NS_IMETHODIMP
|
||||
GlobalWindowImpl::SetOuterHeight(PRInt32 aOuterHeight)
|
||||
{
|
||||
/*
|
||||
* If caller is not chrome and dom.disable_window_move_resize is true,
|
||||
* prevent setting window.outerHeight by exiting early
|
||||
*/
|
||||
|
||||
if (!CanSetProperty("dom.disable_window_move_resize") && !IsCallerChrome()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIBaseWindow> treeOwnerAsWin;
|
||||
GetTreeOwner(getter_AddRefs(treeOwnerAsWin));
|
||||
NS_ENSURE_TRUE(treeOwnerAsWin, NS_ERROR_FAILURE);
|
||||
@ -1487,6 +1586,15 @@ GlobalWindowImpl::GetScreenX(PRInt32* aScreenX)
|
||||
NS_IMETHODIMP
|
||||
GlobalWindowImpl::SetScreenX(PRInt32 aScreenX)
|
||||
{
|
||||
/*
|
||||
* If caller is not chrome and dom.disable_window_move_resize is true,
|
||||
* prevent setting window.screenX by exiting early
|
||||
*/
|
||||
|
||||
if (!CanSetProperty("dom.disable_window_move_resize") && !IsCallerChrome()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIBaseWindow> treeOwnerAsWin;
|
||||
GetTreeOwner(getter_AddRefs(treeOwnerAsWin));
|
||||
NS_ENSURE_TRUE(treeOwnerAsWin, NS_ERROR_FAILURE);
|
||||
@ -1522,6 +1630,15 @@ GlobalWindowImpl::GetScreenY(PRInt32* aScreenY)
|
||||
NS_IMETHODIMP
|
||||
GlobalWindowImpl::SetScreenY(PRInt32 aScreenY)
|
||||
{
|
||||
/*
|
||||
* If caller is not chrome and dom.disable_window_move_resize is true,
|
||||
* prevent setting window.screenY by exiting early
|
||||
*/
|
||||
|
||||
if (!CanSetProperty("dom.disable_window_move_resize") && !IsCallerChrome()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIBaseWindow> treeOwnerAsWin;
|
||||
GetTreeOwner(getter_AddRefs(treeOwnerAsWin));
|
||||
NS_ENSURE_TRUE(treeOwnerAsWin, NS_ERROR_FAILURE);
|
||||
@ -2166,6 +2283,15 @@ GlobalWindowImpl::Prompt(nsAString& aReturn)
|
||||
NS_IMETHODIMP
|
||||
GlobalWindowImpl::Focus()
|
||||
{
|
||||
/*
|
||||
* If caller is not chrome and dom.disable_window_flip is true,
|
||||
* prevent setting window.focus() by exiting early
|
||||
*/
|
||||
|
||||
if (!CanSetProperty("dom.disable_window_flip") && !IsCallerChrome()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIBaseWindow> treeOwnerAsWin;
|
||||
GetTreeOwner(getter_AddRefs(treeOwnerAsWin));
|
||||
if (treeOwnerAsWin) {
|
||||
@ -2300,6 +2426,15 @@ GlobalWindowImpl::Print()
|
||||
NS_IMETHODIMP
|
||||
GlobalWindowImpl::MoveTo(PRInt32 aXPos, PRInt32 aYPos)
|
||||
{
|
||||
/*
|
||||
* If caller is not chrome and dom.disable_window_move_resize is true,
|
||||
* prevent window.moveTo() by exiting early
|
||||
*/
|
||||
|
||||
if (!CanSetProperty("dom.disable_window_move_resize") && !IsCallerChrome()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIBaseWindow> treeOwnerAsWin;
|
||||
GetTreeOwner(getter_AddRefs(treeOwnerAsWin));
|
||||
NS_ENSURE_TRUE(treeOwnerAsWin, NS_ERROR_FAILURE);
|
||||
@ -2316,6 +2451,15 @@ GlobalWindowImpl::MoveTo(PRInt32 aXPos, PRInt32 aYPos)
|
||||
NS_IMETHODIMP
|
||||
GlobalWindowImpl::MoveBy(PRInt32 aXDif, PRInt32 aYDif)
|
||||
{
|
||||
/*
|
||||
* If caller is not chrome and dom.disable_window_move_resize is true,
|
||||
* prevent window.moveBy() by exiting early
|
||||
*/
|
||||
|
||||
if (!CanSetProperty("dom.disable_window_move_resize") && !IsCallerChrome()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIBaseWindow> treeOwnerAsWin;
|
||||
GetTreeOwner(getter_AddRefs(treeOwnerAsWin));
|
||||
NS_ENSURE_TRUE(treeOwnerAsWin, NS_ERROR_FAILURE);
|
||||
@ -2336,6 +2480,15 @@ GlobalWindowImpl::MoveBy(PRInt32 aXDif, PRInt32 aYDif)
|
||||
NS_IMETHODIMP
|
||||
GlobalWindowImpl::ResizeTo(PRInt32 aWidth, PRInt32 aHeight)
|
||||
{
|
||||
/*
|
||||
* If caller is not chrome and dom.disable_window_move_resize is true,
|
||||
* prevent window.resizeTo() by exiting early
|
||||
*/
|
||||
|
||||
if (!CanSetProperty("dom.disable_window_move_resize") && !IsCallerChrome()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIBaseWindow> treeOwnerAsWin;
|
||||
GetTreeOwner(getter_AddRefs(treeOwnerAsWin));
|
||||
NS_ENSURE_TRUE(treeOwnerAsWin, NS_ERROR_FAILURE);
|
||||
@ -2352,6 +2505,15 @@ GlobalWindowImpl::ResizeTo(PRInt32 aWidth, PRInt32 aHeight)
|
||||
NS_IMETHODIMP
|
||||
GlobalWindowImpl::ResizeBy(PRInt32 aWidthDif, PRInt32 aHeightDif)
|
||||
{
|
||||
/*
|
||||
* If caller is not chrome and dom.disable_window_move_resize is true,
|
||||
* prevent window.resizeBy() by exiting early
|
||||
*/
|
||||
|
||||
if (!CanSetProperty("dom.disable_window_move_resize") && !IsCallerChrome()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIBaseWindow> treeOwnerAsWin;
|
||||
GetTreeOwner(getter_AddRefs(treeOwnerAsWin));
|
||||
NS_ENSURE_TRUE(treeOwnerAsWin, NS_ERROR_FAILURE);
|
||||
@ -2373,6 +2535,15 @@ GlobalWindowImpl::ResizeBy(PRInt32 aWidthDif, PRInt32 aHeightDif)
|
||||
NS_IMETHODIMP
|
||||
GlobalWindowImpl::SizeToContent()
|
||||
{
|
||||
/*
|
||||
* If caller is not chrome and dom.disable_window_move_resize is true,
|
||||
* block window.SizeToContent() by exiting
|
||||
*/
|
||||
|
||||
if (!CanSetProperty("dom.disable_window_move_resize") && !IsCallerChrome()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(mDocShell));
|
||||
NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE);
|
||||
|
||||
|
||||
@ -349,7 +349,16 @@ pref("capability.policy.mailnews.Window.resizeTo", "noAccess");
|
||||
pref("capability.policy.mailnews.Window.screenX.set", "noAccess");
|
||||
pref("capability.policy.mailnews.Window.screenY.set", "noAccess");
|
||||
pref("capability.policy.mailnews.Window.sizeToContent", "noAccess");
|
||||
pref("dom.disable_open_during_load", false);
|
||||
|
||||
// Scripts & Windows prefs
|
||||
pref("browser.block.target_new_window", false);
|
||||
pref("dom.disable_cookie_get", false);
|
||||
pref("dom.disable_cookie_set", false);
|
||||
pref("dom.disable_image_src_set", false);
|
||||
pref("dom.disable_open_during_load", false);
|
||||
pref("dom.disable_window_flip", false);
|
||||
pref("dom.disable_window_move_resize", false);
|
||||
pref("dom.disable_window_status_change", false);
|
||||
|
||||
pref("javascript.enabled", true);
|
||||
pref("javascript.allow.mailnews", false);
|
||||
@ -358,7 +367,7 @@ pref("javascript.options.showInConsole", true);
|
||||
|
||||
// advanced prefs
|
||||
pref("advanced.always_load_images", true);
|
||||
pref("security.enable_java", true);
|
||||
pref("security.enable_java", true);
|
||||
pref("css.allow", true);
|
||||
pref("advanced.mailftp", false);
|
||||
pref("image.animation_mode", "normal");
|
||||
|
||||
@ -43,6 +43,7 @@ var data;
|
||||
function changeDisabledState(state){
|
||||
//Set the states of the groupbox children state based on the "javascript enabled" checkbox value
|
||||
document.getElementById("allowScripts").disabled = state;
|
||||
document.getElementById("allowTargetNew").disabled = state;
|
||||
document.getElementById("allowWindowMoveResize").disabled = state;
|
||||
document.getElementById("allowWindowOpen").disabled = state;
|
||||
document.getElementById("allowImageSrcChange").disabled = state;
|
||||
@ -67,19 +68,17 @@ function javascriptEnabledChange(){
|
||||
}
|
||||
|
||||
function getPrefValueForCheckbox(prefName){
|
||||
|
||||
var prefValue;
|
||||
var prefValue = false;
|
||||
|
||||
try {
|
||||
prefValue = pref.GetCharPref(prefName);
|
||||
|
||||
if(prefValue != "allAccess" && prefValue != "sameOrigin"){
|
||||
return false;
|
||||
}
|
||||
prefValue = pref.GetBoolPref(prefName);
|
||||
}
|
||||
catch(e) {}
|
||||
|
||||
return true;
|
||||
// the prefs are stored in terms of disabling,
|
||||
// but we want our value in terms of enabling.
|
||||
// so let's invert the prefValue.
|
||||
return !prefValue;
|
||||
}
|
||||
|
||||
function Startup(){
|
||||
@ -98,73 +97,30 @@ function Startup(){
|
||||
data.scriptData[ changedList[run] ].value = false;
|
||||
}
|
||||
|
||||
try{
|
||||
document.getElementById("allowWindowOpen").checked =
|
||||
!pref.GetBoolPref("dom.disable_open_during_load");
|
||||
} catch (e){
|
||||
//We will only get an error if the preference doesn't exist, when that happens we default to true
|
||||
document.getElementById("allowWindowOpen").checked = true;
|
||||
}
|
||||
|
||||
try{
|
||||
document.getElementById("allowTargetNew").checked =
|
||||
!pref.GetBoolPref("browser.block.target_new_window");
|
||||
} catch (e){
|
||||
//We will only get an error if the preference doesn't exist, when that happens we default to true
|
||||
document.getElementById("allowTargetNew").checked = true;
|
||||
}
|
||||
|
||||
//If one of the security capability prefs is set, then the checkbox becomes unchecked
|
||||
document.getElementById("allowWindowMoveResize").checked =
|
||||
getPrefValueForCheckbox("capability.policy.default.Window.resizeTo") &&
|
||||
getPrefValueForCheckbox("capability.policy.default.Window.innerWidth.set") &&
|
||||
getPrefValueForCheckbox("capability.policy.default.Window.innerHeight.set") &&
|
||||
getPrefValueForCheckbox("capability.policy.default.Window.outerWidth.set") &&
|
||||
getPrefValueForCheckbox("capability.policy.default.Window.outerHeight.set") &&
|
||||
getPrefValueForCheckbox("capability.policy.default.Window.sizeToContent") &&
|
||||
getPrefValueForCheckbox("capability.policy.default.Window.resizeBy") &&
|
||||
getPrefValueForCheckbox("capability.policy.default.Window.screenX.set") &&
|
||||
getPrefValueForCheckbox("capability.policy.default.Window.screenY.set") &&
|
||||
getPrefValueForCheckbox("capability.policy.default.Window.moveTo") &&
|
||||
getPrefValueForCheckbox("capability.policy.default.Window.moveBy");
|
||||
|
||||
document.getElementById("allowWindowFlip").checked =
|
||||
getPrefValueForCheckbox("capability.policy.default.Window.focus");
|
||||
|
||||
document.getElementById("allowWindowStatusChange").checked =
|
||||
getPrefValueForCheckbox("capability.policy.default.Window.status") &&
|
||||
getPrefValueForCheckbox("capability.policy.default.Window.defaultStatus");
|
||||
|
||||
document.getElementById("allowImageSrcChange").checked =
|
||||
getPrefValueForCheckbox("capability.policy.default.HTMLImageElement.src");
|
||||
|
||||
document.getElementById("allowDocumentCookieGet").checked =
|
||||
getPrefValueForCheckbox("capability.policy.default.HTMLDocument.cookie.get");
|
||||
|
||||
document.getElementById("allowDocumentCookieSet").checked =
|
||||
getPrefValueForCheckbox("capability.policy.default.HTMLDocument.cookie.set");
|
||||
document.getElementById("allowWindowOpen").checked = getPrefValueForCheckbox("dom.disable_open_during_load");
|
||||
document.getElementById("allowTargetNew").checked = getPrefValueForCheckbox("browser.block.target_new_window");
|
||||
document.getElementById("allowWindowMoveResize").checked = getPrefValueForCheckbox("dom.disable_window_move_resize");
|
||||
document.getElementById("allowWindowFlip").checked = getPrefValueForCheckbox("dom.disable_window_flip");
|
||||
document.getElementById("allowWindowStatusChange").checked = getPrefValueForCheckbox("dom.disable_window_status_change");
|
||||
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");
|
||||
|
||||
} 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("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"))
|
||||
if (document.getElementById("javascriptAllowMailnews")) {
|
||||
document.getElementById("javascriptAllowMailNews").checked = data["javascriptAllowMailNews"].checked;
|
||||
}
|
||||
}
|
||||
|
||||
javascriptEnabledChange();
|
||||
@ -189,74 +145,47 @@ function doOnOk(){
|
||||
|
||||
return data[name].checked;
|
||||
}
|
||||
|
||||
function setCapabilityPolicy(prefName, checkboxValue){
|
||||
|
||||
//If checked, we allow the script to do task, so we clear the pref.
|
||||
//since some options are made up of multiple capability policies and users can turn
|
||||
//individual ones on/off via prefs.js, it can happen that we clear a nonexistent pref
|
||||
if (checkboxValue){
|
||||
try {
|
||||
parent.hPrefWindow.pref.ClearUserPref(prefName);
|
||||
} catch (e) {}
|
||||
} else {
|
||||
parent.hPrefWindow.setPref("string", prefName, "noAccess");
|
||||
}
|
||||
}
|
||||
|
||||
var data = parent.hPrefWindow.wsm.dataManager.pageData["chrome://communicator/content/pref/pref-scripts.xul"];
|
||||
|
||||
if (data.scriptData["allowWindowOpenChanged"].value){
|
||||
parent.hPrefWindow.setPref("bool", "dom.disable_open_during_load",
|
||||
parent.hPrefWindow.setPref("bool", "dom.disable_open_during_load",
|
||||
!getCheckboxValue('allowWindowOpen'));
|
||||
}
|
||||
|
||||
if (data.scriptData["allowTargetNewChanged"].value){
|
||||
parent.hPrefWindow.setPref("bool", "browser.block.target_new_window",
|
||||
parent.hPrefWindow.setPref("bool", "browser.block.target_new_window",
|
||||
!getCheckboxValue('allowTargetNew'));
|
||||
}
|
||||
|
||||
if (data.scriptData["allowWindowMoveResizeChanged"].value){
|
||||
var allowWindowMoveResize = getCheckboxValue("allowWindowMoveResize");
|
||||
|
||||
setCapabilityPolicy("capability.policy.default.Window.resizeTo", allowWindowMoveResize);
|
||||
setCapabilityPolicy("capability.policy.default.Window.innerWidth.set", allowWindowMoveResize);
|
||||
setCapabilityPolicy("capability.policy.default.Window.innerHeight.set", allowWindowMoveResize);
|
||||
setCapabilityPolicy("capability.policy.default.Window.outerWidth.set", allowWindowMoveResize);
|
||||
setCapabilityPolicy("capability.policy.default.Window.outerHeight.set", allowWindowMoveResize);
|
||||
setCapabilityPolicy("capability.policy.default.Window.sizeToContent", allowWindowMoveResize);
|
||||
setCapabilityPolicy("capability.policy.default.Window.resizeBy", allowWindowMoveResize);
|
||||
setCapabilityPolicy("capability.policy.default.Window.screenX.set", allowWindowMoveResize);
|
||||
setCapabilityPolicy("capability.policy.default.Window.screenY.set", allowWindowMoveResize);
|
||||
setCapabilityPolicy("capability.policy.default.Window.moveTo", allowWindowMoveResize);
|
||||
setCapabilityPolicy("capability.policy.default.Window.moveBy", allowWindowMoveResize);
|
||||
parent.hPrefWindow.setPref("bool", "dom.disable_window_move_resize",
|
||||
!getCheckboxValue('allowWindowMoveResize'));
|
||||
}
|
||||
|
||||
if (data.scriptData["allowWindowStatusChangeChanged"].value){
|
||||
var allowWindowStatusChange = getCheckboxValue("allowWindowStatusChange");
|
||||
|
||||
setCapabilityPolicy("capability.policy.default.Window.status", allowWindowStatusChange);
|
||||
setCapabilityPolicy("capability.policy.default.Window.defaultStatus", allowWindowStatusChange);
|
||||
parent.hPrefWindow.setPref("bool", "dom.disable_window_status_change",
|
||||
!getCheckboxValue("allowWindowStatusChange"));
|
||||
}
|
||||
|
||||
if (data.scriptData["allowWindowFlipChanged"].value){
|
||||
setCapabilityPolicy("capability.policy.default.Window.focus",
|
||||
getCheckboxValue("allowWindowFlip"));
|
||||
parent.hPrefWindow.setPref("bool", "dom.disable_window_flip",
|
||||
!getCheckboxValue("allowWindowFlip"));
|
||||
}
|
||||
|
||||
if (data.scriptData["allowDocumentCookieSetChanged"].value){
|
||||
setCapabilityPolicy("capability.policy.default.HTMLDocument.cookie.set",
|
||||
getCheckboxValue("allowDocumentCookieSet"));
|
||||
parent.hPrefWindow.setPref("bool", "dom.disable_cookie_set",
|
||||
!getCheckboxValue("allowDocumentCookieSet"));
|
||||
}
|
||||
|
||||
if (data.scriptData["allowDocumentCookieGetChanged"].value){
|
||||
setCapabilityPolicy("capability.policy.default.HTMLDocument.cookie.get",
|
||||
getCheckboxValue("allowDocumentCookieGet"));
|
||||
parent.hPrefWindow.setPref("bool", "dom.disable_cookie_get",
|
||||
!getCheckboxValue("allowDocumentCookieGet"));
|
||||
}
|
||||
|
||||
if (data.scriptData["allowImageSrcChangeChanged"].value){
|
||||
setCapabilityPolicy("capability.policy.default.HTMLImageElement.src",
|
||||
getCheckboxValue("allowImageSrcChange"));
|
||||
parent.hPrefWindow.setPref("bool", "dom.disable_image_src_set",
|
||||
!getCheckboxValue("allowImageSrcChange"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -52,7 +52,7 @@
|
||||
<script type="application/x-javascript">
|
||||
<![CDATA[
|
||||
var panel = "chrome://communicator/content/pref/pref-scripts.xul";
|
||||
var _elementIDs = ["javascriptAllowNavigator", "allowWindowOpen", "allowTargetNew", "allowWindowMoveResize", "allowWindowFlip", "allowWindowStatusChange", "allowImageSrcChange", "allowDocumentCookieSet", "allowDocumentCookieGet"];
|
||||
var _elementIDs = ["javascriptAllowNavigator", "allowWindowOpen", "allowWindowMoveResize", "allowWindowFlip", "allowWindowStatusChange", "allowImageSrcChange", "allowDocumentCookieSet", "allowDocumentCookieGet","allowTargetNew"];
|
||||
]]>
|
||||
</script>
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user