зеркало из https://github.com/mozilla/pjs.git
Fix for bug 97687 ([serializer]cs/gecko: copying using keyboard shortcuts>paste>source pasted {Country=US}) r=heikki, sr=jst.
This commit is contained in:
Родитель
747cfc77bf
Коммит
65ca41c6c4
|
@ -148,7 +148,11 @@ public:
|
|||
// CR, LF, or CRLF. If neither of these flags is set, then we
|
||||
// will use platform line breaks.
|
||||
OutputCRLineBreak = 512,
|
||||
OutputLFLineBreak = 1024
|
||||
OutputLFLineBreak = 1024,
|
||||
|
||||
// Output the content of noscript elements (only for serializing
|
||||
// to plaintext).
|
||||
OutputNoScriptContent = 2048
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -71,6 +71,9 @@
|
|||
#include "nsISupportsArray.h"
|
||||
#include "nsIParserService.h"
|
||||
#include "nsParserCIID.h"
|
||||
#include "nsIScriptContext.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
|
||||
static NS_DEFINE_CID(kCharsetConverterManagerCID,
|
||||
NS_ICHARSETCONVERTERMANAGER_CID);
|
||||
|
@ -195,6 +198,33 @@ 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));
|
||||
|
||||
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 nsAReadableString& aMimeType,
|
||||
|
@ -1049,6 +1079,9 @@ nsHTMLCopyEncoder::Init(nsIDocument* aDocument,
|
|||
// (see related bugs #57296, #41924, #58646, #32768)
|
||||
mFlags = aFlags | OutputAbsoluteLinks;
|
||||
|
||||
if (!IsScriptEnabled(mDocument))
|
||||
mFlags |= OutputNoScriptContent;
|
||||
|
||||
nsresult rv;
|
||||
mParserService = do_GetService(kParserServiceCID, &rv);
|
||||
return rv;
|
||||
|
|
|
@ -226,6 +226,11 @@ nsPlainTextSerializer::AppendText(nsIDOMText* aText,
|
|||
PRInt32 aEndOffset,
|
||||
nsAWritableString& aStr)
|
||||
{
|
||||
if ((mTagStack[mTagStackIndex-1] == eHTMLTag_noscript) &&
|
||||
!(mFlags & nsIDocumentEncoder::OutputNoScriptContent)) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_ENSURE_ARG(aText);
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
|
@ -388,6 +393,11 @@ nsPlainTextSerializer::CloseContainer(const nsIParserNode& aNode)
|
|||
NS_IMETHODIMP
|
||||
nsPlainTextSerializer::AddLeaf(const nsIParserNode& aNode)
|
||||
{
|
||||
if ((mTagStack[mTagStackIndex-1] == eHTMLTag_noscript) &&
|
||||
!(mFlags & nsIDocumentEncoder::OutputNoScriptContent)) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
eHTMLTags type = (eHTMLTags)aNode.GetNodeType();
|
||||
const nsAReadableString& text = aNode.GetText();
|
||||
|
||||
|
@ -494,6 +504,11 @@ nsPlainTextSerializer::DoOpenContainer(PRInt32 aTag)
|
|||
{
|
||||
eHTMLTags type = (eHTMLTags)aTag;
|
||||
|
||||
if ((mTagStack[mTagStackIndex-1] == eHTMLTag_noscript) &&
|
||||
!(mFlags & nsIDocumentEncoder::OutputNoScriptContent)) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (mTagStackIndex < TagStackSize) {
|
||||
mTagStack[mTagStackIndex++] = type;
|
||||
}
|
||||
|
@ -722,6 +737,12 @@ nsPlainTextSerializer::DoCloseContainer(PRInt32 aTag)
|
|||
{
|
||||
eHTMLTags type = (eHTMLTags)aTag;
|
||||
|
||||
if ((mTagStack[mTagStackIndex-1] == eHTMLTag_noscript) &&
|
||||
!(mFlags & nsIDocumentEncoder::OutputNoScriptContent) &&
|
||||
(type != eHTMLTag_noscript)) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (mTagStackIndex > 0) {
|
||||
--mTagStackIndex;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче