Make NOSCRIPT show up normally when script disabled (bug 77296), r=bzbarsky@mit.edu, sr=dbaron@dbaron.org
This commit is contained in:
Родитель
a216d01ee9
Коммит
63f24a78b5
|
@ -469,6 +469,8 @@ public:
|
|||
nsAString& Standalone) = 0;
|
||||
|
||||
NS_IMETHOD_(PRBool) IsCaseSensitive() = 0;
|
||||
|
||||
NS_IMETHOD_(PRBool) IsScriptEnabled() = 0;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -4060,6 +4060,33 @@ nsDocument::IsCaseSensitive()
|
|||
return PR_TRUE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(PRBool)
|
||||
nsDocument::IsScriptEnabled()
|
||||
{
|
||||
nsCOMPtr<nsIScriptSecurityManager> sm(do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID));
|
||||
NS_ENSURE_TRUE(sm, PR_TRUE);
|
||||
|
||||
nsCOMPtr<nsIPrincipal> principal;
|
||||
GetPrincipal(getter_AddRefs(principal));
|
||||
NS_ENSURE_TRUE(principal, PR_TRUE);
|
||||
|
||||
nsCOMPtr<nsIScriptGlobalObject> globalObject;
|
||||
GetScriptGlobalObject(getter_AddRefs(globalObject));
|
||||
NS_ENSURE_TRUE(globalObject, PR_TRUE);
|
||||
|
||||
nsCOMPtr<nsIScriptContext> scriptContext;
|
||||
globalObject->GetContext(getter_AddRefs(scriptContext));
|
||||
NS_ENSURE_TRUE(scriptContext, PR_TRUE);
|
||||
|
||||
JSContext* cx = (JSContext *) scriptContext->GetNativeContext();
|
||||
NS_ENSURE_TRUE(cx, PR_TRUE);
|
||||
|
||||
PRBool enabled;
|
||||
nsresult rv = sm->CanExecuteScripts(cx, principal, &enabled);
|
||||
NS_ENSURE_SUCCESS(rv, PR_TRUE);
|
||||
return enabled;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDocument::GetRadioGroup(const nsAString& aName,
|
||||
nsRadioGroupStruct **aRadioGroup)
|
||||
|
|
|
@ -501,6 +501,7 @@ public:
|
|||
nsAString& aEncoding,
|
||||
nsAString& Standalone);
|
||||
NS_IMETHOD_(PRBool) IsCaseSensitive();
|
||||
NS_IMETHOD_(PRBool) IsScriptEnabled();
|
||||
|
||||
// nsIRadioGroupContainer
|
||||
NS_IMETHOD WalkRadioGroup(const nsAString& aName,
|
||||
|
|
|
@ -198,34 +198,6 @@ nsDocumentEncoder::~nsDocumentEncoder()
|
|||
{
|
||||
}
|
||||
|
||||
static PRBool
|
||||
IsScriptEnabled(nsIDocument *aDoc)
|
||||
{
|
||||
NS_ENSURE_TRUE(aDoc, PR_TRUE);
|
||||
|
||||
nsCOMPtr<nsIScriptSecurityManager> sm(do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID));
|
||||
NS_ENSURE_TRUE(sm, PR_TRUE);
|
||||
|
||||
nsCOMPtr<nsIPrincipal> principal;
|
||||
aDoc->GetPrincipal(getter_AddRefs(principal));
|
||||
NS_ENSURE_TRUE(principal, PR_TRUE);
|
||||
|
||||
nsCOMPtr<nsIScriptGlobalObject> globalObject;
|
||||
aDoc->GetScriptGlobalObject(getter_AddRefs(globalObject));
|
||||
NS_ENSURE_TRUE(globalObject, PR_TRUE);
|
||||
|
||||
nsCOMPtr<nsIScriptContext> scriptContext;
|
||||
globalObject->GetContext(getter_AddRefs(scriptContext));
|
||||
NS_ENSURE_TRUE(scriptContext, PR_TRUE);
|
||||
|
||||
JSContext* cx = (JSContext *) scriptContext->GetNativeContext();
|
||||
NS_ENSURE_TRUE(cx, PR_TRUE);
|
||||
|
||||
PRBool enabled = PR_TRUE;
|
||||
sm->CanExecuteScripts(cx, principal, &enabled);
|
||||
return enabled;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocumentEncoder::Init(nsIDocument* aDocument,
|
||||
const nsAString& aMimeType,
|
||||
|
@ -1112,7 +1084,7 @@ nsHTMLCopyEncoder::Init(nsIDocument* aDocument,
|
|||
// (see related bugs #57296, #41924, #58646, #32768)
|
||||
mFlags = aFlags | OutputAbsoluteLinks;
|
||||
|
||||
if (!IsScriptEnabled(mDocument))
|
||||
if (!mDocument->IsScriptEnabled())
|
||||
mFlags |= OutputNoScriptContent;
|
||||
|
||||
return NS_OK;
|
||||
|
|
|
@ -3429,11 +3429,13 @@ CNavDTD::OpenContainer(const nsCParserNode *aNode,
|
|||
break;
|
||||
|
||||
case eHTMLTag_noscript:
|
||||
// we want to make sure that OpenContainer gets called below since we're
|
||||
// not doing it here
|
||||
done=PR_FALSE;
|
||||
// If the script is disabled noscript should not be
|
||||
// in the content model until the layout can somehow
|
||||
// turn noscript's display property to block <-- bug 67899
|
||||
if(mFlags & NS_DTD_FLAG_SCRIPT_ENABLED) {
|
||||
done=PR_FALSE;
|
||||
mScratch.Truncate();
|
||||
mFlags |= NS_DTD_FLAG_ALTERNATE_CONTENT;
|
||||
}
|
||||
|
|
|
@ -1290,6 +1290,7 @@ protected:
|
|||
nsresult SetPrefColorRules(void);
|
||||
nsresult SetPrefLinkRules(void);
|
||||
nsresult SetPrefFocusRules(void);
|
||||
nsresult SetPrefNoScriptRule();
|
||||
|
||||
nsresult GetSelectionForCopy(nsISelection** outSelection);
|
||||
|
||||
|
@ -2172,7 +2173,9 @@ PresShell::SetPreferenceStyleRules(PRBool aForceReflow)
|
|||
if (NS_SUCCEEDED(result)) {
|
||||
result = SetPrefFocusRules();
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
result = SetPrefNoScriptRule();
|
||||
}
|
||||
|
||||
// update the styleset now that we are done inserting our rules
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
|
@ -2322,6 +2325,26 @@ nsresult PresShell::SetPrefColorRules(void)
|
|||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
PresShell::SetPrefNoScriptRule()
|
||||
{
|
||||
// If script is disabled, change noscript from display: none to display: block
|
||||
if (!mDocument->IsScriptEnabled()) {
|
||||
nsresult rv;
|
||||
if (!mPrefStyleSheet) {
|
||||
rv = CreatePreferenceStyleSheet();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
// get the DOM interface to the stylesheet
|
||||
nsCOMPtr<nsIDOMCSSStyleSheet> sheet(do_QueryInterface(mPrefStyleSheet,&rv));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
PRUint32 index = 0;
|
||||
rv = sheet->InsertRule(NS_LITERAL_STRING("noscript{display:block}"), 0, &index);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult PresShell::SetPrefLinkRules(void)
|
||||
{
|
||||
NS_ASSERTION(mPresContext,"null prescontext not allowed");
|
||||
|
|
|
@ -1290,6 +1290,7 @@ protected:
|
|||
nsresult SetPrefColorRules(void);
|
||||
nsresult SetPrefLinkRules(void);
|
||||
nsresult SetPrefFocusRules(void);
|
||||
nsresult SetPrefNoScriptRule();
|
||||
|
||||
nsresult GetSelectionForCopy(nsISelection** outSelection);
|
||||
|
||||
|
@ -2172,7 +2173,9 @@ PresShell::SetPreferenceStyleRules(PRBool aForceReflow)
|
|||
if (NS_SUCCEEDED(result)) {
|
||||
result = SetPrefFocusRules();
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
result = SetPrefNoScriptRule();
|
||||
}
|
||||
|
||||
// update the styleset now that we are done inserting our rules
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
|
@ -2322,6 +2325,26 @@ nsresult PresShell::SetPrefColorRules(void)
|
|||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
PresShell::SetPrefNoScriptRule()
|
||||
{
|
||||
// If script is disabled, change noscript from display: none to display: block
|
||||
if (!mDocument->IsScriptEnabled()) {
|
||||
nsresult rv;
|
||||
if (!mPrefStyleSheet) {
|
||||
rv = CreatePreferenceStyleSheet();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
// get the DOM interface to the stylesheet
|
||||
nsCOMPtr<nsIDOMCSSStyleSheet> sheet(do_QueryInterface(mPrefStyleSheet,&rv));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
PRUint32 index = 0;
|
||||
rv = sheet->InsertRule(NS_LITERAL_STRING("noscript{display:block}"), 0, &index);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult PresShell::SetPrefLinkRules(void)
|
||||
{
|
||||
NS_ASSERTION(mPresContext,"null prescontext not allowed");
|
||||
|
|
|
@ -3429,11 +3429,13 @@ CNavDTD::OpenContainer(const nsCParserNode *aNode,
|
|||
break;
|
||||
|
||||
case eHTMLTag_noscript:
|
||||
// we want to make sure that OpenContainer gets called below since we're
|
||||
// not doing it here
|
||||
done=PR_FALSE;
|
||||
// If the script is disabled noscript should not be
|
||||
// in the content model until the layout can somehow
|
||||
// turn noscript's display property to block <-- bug 67899
|
||||
if(mFlags & NS_DTD_FLAG_SCRIPT_ENABLED) {
|
||||
done=PR_FALSE;
|
||||
mScratch.Truncate();
|
||||
mFlags |= NS_DTD_FLAG_ALTERNATE_CONTENT;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче