From 64ac997a95b7ea893661e50b24188e0d9ae496dd Mon Sep 17 00:00:00 2001 From: "jkeiser%netscape.com" Date: Thu, 26 Jun 2003 06:10:03 +0000 Subject: [PATCH] Make NOSCRIPT show up normally when script disabled (bug 77296), r=bzbarsky@mit.edu, sr=dbaron@dbaron.org git-svn-id: svn://10.0.0.236/trunk@144183 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/public/nsIDocument.h | 2 ++ mozilla/content/base/src/nsDocument.cpp | 27 +++++++++++++++++ mozilla/content/base/src/nsDocument.h | 1 + .../content/base/src/nsDocumentEncoder.cpp | 30 +------------------ mozilla/htmlparser/src/CNavDTD.cpp | 4 ++- mozilla/layout/base/nsPresShell.cpp | 25 +++++++++++++++- mozilla/layout/html/base/src/nsPresShell.cpp | 25 +++++++++++++++- mozilla/parser/htmlparser/src/CNavDTD.cpp | 4 ++- 8 files changed, 85 insertions(+), 33 deletions(-) diff --git a/mozilla/content/base/public/nsIDocument.h b/mozilla/content/base/public/nsIDocument.h index 195491dd9f7..5405ac94ca0 100644 --- a/mozilla/content/base/public/nsIDocument.h +++ b/mozilla/content/base/public/nsIDocument.h @@ -469,6 +469,8 @@ public: nsAString& Standalone) = 0; NS_IMETHOD_(PRBool) IsCaseSensitive() = 0; + + NS_IMETHOD_(PRBool) IsScriptEnabled() = 0; }; diff --git a/mozilla/content/base/src/nsDocument.cpp b/mozilla/content/base/src/nsDocument.cpp index 42a4c34ff76..349d90edb39 100644 --- a/mozilla/content/base/src/nsDocument.cpp +++ b/mozilla/content/base/src/nsDocument.cpp @@ -4060,6 +4060,33 @@ nsDocument::IsCaseSensitive() return PR_TRUE; } +NS_IMETHODIMP_(PRBool) +nsDocument::IsScriptEnabled() +{ + nsCOMPtr sm(do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID)); + NS_ENSURE_TRUE(sm, PR_TRUE); + + nsCOMPtr principal; + GetPrincipal(getter_AddRefs(principal)); + NS_ENSURE_TRUE(principal, PR_TRUE); + + nsCOMPtr globalObject; + GetScriptGlobalObject(getter_AddRefs(globalObject)); + NS_ENSURE_TRUE(globalObject, PR_TRUE); + + nsCOMPtr 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) diff --git a/mozilla/content/base/src/nsDocument.h b/mozilla/content/base/src/nsDocument.h index 1326f2fe74b..0ee991c0d77 100644 --- a/mozilla/content/base/src/nsDocument.h +++ b/mozilla/content/base/src/nsDocument.h @@ -501,6 +501,7 @@ public: nsAString& aEncoding, nsAString& Standalone); NS_IMETHOD_(PRBool) IsCaseSensitive(); + NS_IMETHOD_(PRBool) IsScriptEnabled(); // nsIRadioGroupContainer NS_IMETHOD WalkRadioGroup(const nsAString& aName, diff --git a/mozilla/content/base/src/nsDocumentEncoder.cpp b/mozilla/content/base/src/nsDocumentEncoder.cpp index ad8e4c8905b..9c40e5f46f5 100644 --- a/mozilla/content/base/src/nsDocumentEncoder.cpp +++ b/mozilla/content/base/src/nsDocumentEncoder.cpp @@ -198,34 +198,6 @@ nsDocumentEncoder::~nsDocumentEncoder() { } -static PRBool -IsScriptEnabled(nsIDocument *aDoc) -{ - NS_ENSURE_TRUE(aDoc, PR_TRUE); - - nsCOMPtr sm(do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID)); - NS_ENSURE_TRUE(sm, PR_TRUE); - - nsCOMPtr principal; - aDoc->GetPrincipal(getter_AddRefs(principal)); - NS_ENSURE_TRUE(principal, PR_TRUE); - - nsCOMPtr globalObject; - aDoc->GetScriptGlobalObject(getter_AddRefs(globalObject)); - NS_ENSURE_TRUE(globalObject, PR_TRUE); - - nsCOMPtr 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; diff --git a/mozilla/htmlparser/src/CNavDTD.cpp b/mozilla/htmlparser/src/CNavDTD.cpp index d2eb0999ce7..25ac56ca9a8 100644 --- a/mozilla/htmlparser/src/CNavDTD.cpp +++ b/mozilla/htmlparser/src/CNavDTD.cpp @@ -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; } diff --git a/mozilla/layout/base/nsPresShell.cpp b/mozilla/layout/base/nsPresShell.cpp index a8f3516e441..15c59bbccc3 100644 --- a/mozilla/layout/base/nsPresShell.cpp +++ b/mozilla/layout/base/nsPresShell.cpp @@ -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 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"); diff --git a/mozilla/layout/html/base/src/nsPresShell.cpp b/mozilla/layout/html/base/src/nsPresShell.cpp index a8f3516e441..15c59bbccc3 100644 --- a/mozilla/layout/html/base/src/nsPresShell.cpp +++ b/mozilla/layout/html/base/src/nsPresShell.cpp @@ -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 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"); diff --git a/mozilla/parser/htmlparser/src/CNavDTD.cpp b/mozilla/parser/htmlparser/src/CNavDTD.cpp index d2eb0999ce7..25ac56ca9a8 100644 --- a/mozilla/parser/htmlparser/src/CNavDTD.cpp +++ b/mozilla/parser/htmlparser/src/CNavDTD.cpp @@ -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; }