Bug 851230 - Framed plain text documents should not have word wrap applied. r=bz
This commit is contained in:
@@ -848,6 +848,11 @@ public:
|
||||
*/
|
||||
static bool IsChildOfSameType(nsIDocument* aDoc);
|
||||
|
||||
/**
|
||||
'* Returns true if the content-type will be rendered as plain-text.
|
||||
*/
|
||||
static bool IsPlainTextType(const nsACString& aContentType);
|
||||
|
||||
/**
|
||||
* Get the script file name to use when compiling the script
|
||||
* referenced by aURI. In cases where there's no need for any extra
|
||||
|
||||
@@ -3364,6 +3364,20 @@ nsContentUtils::IsChildOfSameType(nsIDocument* aDoc)
|
||||
return sameTypeParent != nullptr;
|
||||
}
|
||||
|
||||
bool
|
||||
nsContentUtils::IsPlainTextType(const nsACString& aContentType)
|
||||
{
|
||||
return aContentType.EqualsLiteral(TEXT_PLAIN) ||
|
||||
aContentType.EqualsLiteral(TEXT_CSS) ||
|
||||
aContentType.EqualsLiteral(TEXT_CACHE_MANIFEST) ||
|
||||
aContentType.EqualsLiteral(APPLICATION_JAVASCRIPT) ||
|
||||
aContentType.EqualsLiteral(APPLICATION_XJAVASCRIPT) ||
|
||||
aContentType.EqualsLiteral(TEXT_ECMASCRIPT) ||
|
||||
aContentType.EqualsLiteral(APPLICATION_ECMASCRIPT) ||
|
||||
aContentType.EqualsLiteral(TEXT_JAVASCRIPT) ||
|
||||
aContentType.EqualsLiteral(APPLICATION_JSON);
|
||||
}
|
||||
|
||||
bool
|
||||
nsContentUtils::GetWrapperSafeScriptFilename(nsIDocument *aDocument,
|
||||
nsIURI *aURI,
|
||||
|
||||
@@ -105,6 +105,7 @@
|
||||
#include "nsSandboxFlags.h"
|
||||
#include "mozilla/dom/HTMLBodyElement.h"
|
||||
#include "nsCharsetSource.h"
|
||||
#include "nsIStringBundle.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
@@ -587,15 +588,7 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
|
||||
|
||||
bool html = contentType.EqualsLiteral(TEXT_HTML);
|
||||
bool xhtml = !html && contentType.EqualsLiteral(APPLICATION_XHTML_XML);
|
||||
bool plainText = !html && !xhtml && (contentType.EqualsLiteral(TEXT_PLAIN) ||
|
||||
contentType.EqualsLiteral(TEXT_CSS) ||
|
||||
contentType.EqualsLiteral(TEXT_CACHE_MANIFEST) ||
|
||||
contentType.EqualsLiteral(APPLICATION_JAVASCRIPT) ||
|
||||
contentType.EqualsLiteral(APPLICATION_XJAVASCRIPT) ||
|
||||
contentType.EqualsLiteral(TEXT_ECMASCRIPT) ||
|
||||
contentType.EqualsLiteral(APPLICATION_ECMASCRIPT) ||
|
||||
contentType.EqualsLiteral(TEXT_JAVASCRIPT) ||
|
||||
contentType.EqualsLiteral(APPLICATION_JSON));
|
||||
bool plainText = !html && !xhtml && nsContentUtils::IsPlainTextType(contentType);
|
||||
if (!(html || xhtml || plainText || viewSource)) {
|
||||
MOZ_ASSERT(false, "Channel with bad content type.");
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
@@ -868,6 +861,21 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
|
||||
}
|
||||
}
|
||||
|
||||
if (plainText && !nsContentUtils::IsChildOfSameType(this) &&
|
||||
Preferences::GetBool("plain_text.wrap_long_lines")) {
|
||||
nsCOMPtr<nsIStringBundleService> bundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv) && bundleService, "The bundle service could not be loaded");
|
||||
nsCOMPtr<nsIStringBundle> bundle;
|
||||
rv = bundleService->CreateBundle("chrome://global/locale/browser.properties",
|
||||
getter_AddRefs(bundle));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv) && bundle, "chrome://global/locale/browser.properties could not be loaded");
|
||||
nsXPIDLString title;
|
||||
if (bundle) {
|
||||
bundle->GetStringFromName(NS_LITERAL_STRING("plainText.wordWrap").get(), getter_Copies(title));
|
||||
}
|
||||
SetSelectedStyleSheetSet(title);
|
||||
}
|
||||
|
||||
// parser the content of the URI
|
||||
mParser->Parse(uri, nullptr, (void *)this);
|
||||
|
||||
|
||||
@@ -14,9 +14,7 @@ nsHtml5HtmlAttributes*
|
||||
nsHtml5PlainTextUtils::NewLinkAttributes()
|
||||
{
|
||||
nsHtml5HtmlAttributes* linkAttrs = new nsHtml5HtmlAttributes(0);
|
||||
nsString* rel = mozilla::Preferences::GetBool("plain_text.wrap_long_lines") ?
|
||||
new nsString(NS_LITERAL_STRING("stylesheet")) :
|
||||
new nsString(NS_LITERAL_STRING("alternate stylesheet"));
|
||||
nsString* rel = new nsString(NS_LITERAL_STRING("alternate stylesheet"));
|
||||
linkAttrs->addAttribute(nsHtml5AttributeName::ATTR_REL, rel);
|
||||
nsString* type = new nsString(NS_LITERAL_STRING("text/css"));
|
||||
linkAttrs->addAttribute(nsHtml5AttributeName::ATTR_TYPE, type);
|
||||
|
||||
@@ -791,15 +791,7 @@ DetermineParseMode(const nsString& aBuffer, nsDTDMode& aParseMode,
|
||||
{
|
||||
if (aMimeType.EqualsLiteral(TEXT_HTML)) {
|
||||
DetermineHTMLParseMode(aBuffer, aParseMode, aDocType);
|
||||
} else if (aMimeType.EqualsLiteral(TEXT_PLAIN) ||
|
||||
aMimeType.EqualsLiteral(TEXT_CACHE_MANIFEST) ||
|
||||
aMimeType.EqualsLiteral(TEXT_CSS) ||
|
||||
aMimeType.EqualsLiteral(APPLICATION_JAVASCRIPT) ||
|
||||
aMimeType.EqualsLiteral(APPLICATION_XJAVASCRIPT) ||
|
||||
aMimeType.EqualsLiteral(APPLICATION_JSON) ||
|
||||
aMimeType.EqualsLiteral(TEXT_ECMASCRIPT) ||
|
||||
aMimeType.EqualsLiteral(APPLICATION_ECMASCRIPT) ||
|
||||
aMimeType.EqualsLiteral(TEXT_JAVASCRIPT)) {
|
||||
} else if (nsContentUtils::IsPlainTextType(aMimeType)) {
|
||||
aDocType = ePlainText;
|
||||
aParseMode = eDTDMode_quirks;
|
||||
} else { // Some form of XML
|
||||
|
||||
Reference in New Issue
Block a user