9266: Disable JS in the editor (and allow for disabling it anywhere). r=brendan,jband,norris,sfraser

This commit is contained in:
akkana%netscape.com 2000-03-28 00:15:56 +00:00
Родитель 7a61aa1ec0
Коммит 1b96eaa6ca
5 изменённых файлов: 76 добавлений и 6 удалений

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

@ -309,6 +309,12 @@ public:
*/
NS_IMETHOD SetTerminationFunction(nsScriptTerminationFunc aFunc,
nsISupports* aRef) = 0;
/**
* Called to disable/enable script execution in this context.
*/
NS_IMETHOD GetScriptsEnabled(PRBool *aEnabled) = 0;
NS_IMETHOD SetScriptsEnabled(PRBool aEnabled) = 0;
};
/**

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

@ -164,6 +164,7 @@ nsJSContext::nsJSContext(JSRuntime *aRuntime)
mSecurityManager = nsnull;
mOwner = nsnull;
mTerminationFunc = nsnull;
mScriptsEnabled = PR_TRUE;
}
const char kScriptSecurityManagerProgID[] = NS_SCRIPTSECURITYMANAGER_PROGID;
@ -203,6 +204,12 @@ nsJSContext::EvaluateString(const nsString& aScript,
nsString& aRetValue,
PRBool* aIsUndefined)
{
if (!mScriptsEnabled) {
*aIsUndefined = PR_TRUE;
aRetValue.Truncate();
return NS_OK;
}
nsresult rv;
if (!aScopeObject)
aScopeObject = ::JS_GetGlobalObject(mContext);
@ -288,7 +295,7 @@ nsJSContext::EvaluateString(const nsString& aScript,
// If all went well, convert val to a string (XXXbe unless undefined?).
if (ok) {
*aIsUndefined = JSVAL_IS_VOID(val);
if (aIsUndefined) *aIsUndefined = JSVAL_IS_VOID(val);
JSString* jsstring = ::JS_ValueToString(mContext, val);
if (jsstring)
aRetValue.Assign(::JS_GetStringChars(jsstring));
@ -296,7 +303,7 @@ nsJSContext::EvaluateString(const nsString& aScript,
rv = NS_ERROR_OUT_OF_MEMORY;
}
else {
*aIsUndefined = PR_TRUE;
if (aIsUndefined) *aIsUndefined = PR_TRUE;
aRetValue.Truncate();
}
@ -386,6 +393,12 @@ nsJSContext::ExecuteScript(void* aScriptObject,
nsString* aRetValue,
PRBool* aIsUndefined)
{
if (!mScriptsEnabled) {
*aIsUndefined = PR_TRUE;
aRetValue->Truncate();
return NS_OK;
}
nsresult rv;
if (!aScopeObject)
@ -818,6 +831,20 @@ nsJSContext::SetTerminationFunction(nsScriptTerminationFunc aFunc,
return NS_OK;
}
NS_IMETHODIMP
nsJSContext::GetScriptsEnabled(PRBool *aEnabled)
{
*aEnabled = mScriptsEnabled;
return NS_OK;
}
NS_IMETHODIMP
nsJSContext::SetScriptsEnabled(PRBool aEnabled)
{
mScriptsEnabled = aEnabled;
return NS_OK;
}
nsJSEnvironment *nsJSEnvironment::sTheEnvironment = nsnull;
// Class to manage destruction of the singleton

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

@ -46,6 +46,7 @@ private:
nsIScriptContextOwner* mOwner; /* NB: weak reference, not ADDREF'd */
nsScriptTerminationFunc mTerminationFunc;
nsCOMPtr<nsISupports> mRef;
PRBool mScriptsEnabled;
public:
nsJSContext(JSRuntime *aRuntime);
@ -103,6 +104,8 @@ public:
NS_IMETHOD GetOwner(nsIScriptContextOwner** owner);
NS_IMETHOD SetTerminationFunction(nsScriptTerminationFunc aFunc,
nsISupports* aRef);
NS_IMETHOD GetScriptsEnabled(PRBool *aEnabled);
NS_IMETHOD SetScriptsEnabled(PRBool aEnabled);
nsresult InitializeExternalClasses();
nsresult InitializeLiveConnectClasses();

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

@ -32,8 +32,8 @@
#include "nsIComponentManager.h"
#include "nsIScriptContext.h"
#include "nsIScriptContextOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptGlobalObjectOwner.h"
#include "nsIDOMDocument.h"
#include "nsIDOMXULDocument.h"
#include "nsIDOMHTMLDocument.h"
@ -4041,6 +4041,24 @@ nsEditorShell::OnStartDocumentLoad(nsIDocumentLoader* loader, nsIURI* aURL, cons
// Start the throbber
// TODO: We should also start/stop it for saving and publishing?
SetChromeAttribute( mWebShell, "Editor:Throbber", "busy", "true" );
// Disable JavaScript in this document:
nsCOMPtr<nsIScriptGlobalObjectOwner> sgoo (do_QueryInterface(mContentAreaWebShell));
if (sgoo)
{
nsCOMPtr<nsIScriptGlobalObject> sgo;
sgoo->GetScriptGlobalObject(getter_AddRefs(sgo));
if (sgo)
{
nsCOMPtr<nsIScriptContext> scriptContext;
sgo->GetContext(getter_AddRefs(scriptContext));
if (scriptContext)
{
scriptContext->SetScriptsEnabled(PR_FALSE);
}
}
}
return NS_OK;
}
@ -4065,7 +4083,6 @@ NS_IMETHODIMP
nsEditorShell::OnStartURLLoad(nsIDocumentLoader* loader,
nsIChannel* channel)
{
return NS_OK;
}

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

@ -32,8 +32,8 @@
#include "nsIComponentManager.h"
#include "nsIScriptContext.h"
#include "nsIScriptContextOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptGlobalObjectOwner.h"
#include "nsIDOMDocument.h"
#include "nsIDOMXULDocument.h"
#include "nsIDOMHTMLDocument.h"
@ -4041,6 +4041,24 @@ nsEditorShell::OnStartDocumentLoad(nsIDocumentLoader* loader, nsIURI* aURL, cons
// Start the throbber
// TODO: We should also start/stop it for saving and publishing?
SetChromeAttribute( mWebShell, "Editor:Throbber", "busy", "true" );
// Disable JavaScript in this document:
nsCOMPtr<nsIScriptGlobalObjectOwner> sgoo (do_QueryInterface(mContentAreaWebShell));
if (sgoo)
{
nsCOMPtr<nsIScriptGlobalObject> sgo;
sgoo->GetScriptGlobalObject(getter_AddRefs(sgo));
if (sgo)
{
nsCOMPtr<nsIScriptContext> scriptContext;
sgo->GetContext(getter_AddRefs(scriptContext));
if (scriptContext)
{
scriptContext->SetScriptsEnabled(PR_FALSE);
}
}
}
return NS_OK;
}
@ -4065,7 +4083,6 @@ NS_IMETHODIMP
nsEditorShell::OnStartURLLoad(nsIDocumentLoader* loader,
nsIChannel* channel)
{
return NS_OK;
}