Bug 871161 - Stop inheriting charset where other browsers do not inherit it. r=bzbarsky.

This commit is contained in:
Henri Sivonen 2013-10-16 04:46:10 +03:00
Родитель 844e130f1e
Коммит eb050aeb55
18 изменённых файлов: 140 добавлений и 460 удалений

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

@ -778,18 +778,6 @@ var gBrowserInit = {
window.QueryInterface(Ci.nsIDOMChromeWindow).browserDOMWindow = window.QueryInterface(Ci.nsIDOMChromeWindow).browserDOMWindow =
new nsBrowserAccess(); new nsBrowserAccess();
// set default character set if provided
// window.arguments[1]: character set (string)
if ("arguments" in window && window.arguments.length > 1 && window.arguments[1]) {
if (window.arguments[1].startsWith("charset=")) {
var arrayArgComponents = window.arguments[1].split("=");
if (arrayArgComponents) {
//we should "inherit" the charset menu setting in a new window
getMarkupDocumentViewer().defaultCharacterSet = arrayArgComponents[1];
}
}
}
// Manually hook up session and global history for the first browser // Manually hook up session and global history for the first browser
// so that we don't have to load global history before bringing up a // so that we don't have to load global history before bringing up a
// window. // window.

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

@ -21,6 +21,7 @@
#include "nsDocElementCreatedNotificationRunner.h" #include "nsDocElementCreatedNotificationRunner.h"
#include "mozilla/Services.h" #include "mozilla/Services.h"
#include "nsServiceManagerUtils.h" #include "nsServiceManagerUtils.h"
#include "nsIPrincipal.h"
namespace mozilla { namespace mozilla {
namespace dom { namespace dom {
@ -150,12 +151,7 @@ MediaDocument::StartDocumentLoad(const char* aCommand,
// |UpdateTitleAndCharset| and the worst thing possible is a mangled // |UpdateTitleAndCharset| and the worst thing possible is a mangled
// filename in the titlebar and the file picker. // filename in the titlebar and the file picker.
// When this document is opened in the window/tab of the referring // Note that we
// document (by a simple link-clicking), |prevDocCharacterSet| contains
// the charset of the referring document. On the other hand, if the
// document is opened in a new window, it is |defaultCharacterSet| of |muCV|
// where the charset of our interest is stored. In case of openining
// in a new tab, we get the charset from the docShell. Note that we
// exclude UTF-8 as 'invalid' because UTF-8 is likely to be the charset // exclude UTF-8 as 'invalid' because UTF-8 is likely to be the charset
// of a chrome document that has nothing to do with the actual content // of a chrome document that has nothing to do with the actual content
// whose charset we want to know. Even if "the actual content" is indeed // whose charset we want to know. Even if "the actual content" is indeed
@ -168,27 +164,16 @@ MediaDocument::StartDocumentLoad(const char* aCommand,
NS_ENSURE_TRUE(docShell, NS_OK); NS_ENSURE_TRUE(docShell, NS_OK);
nsAutoCString charset; nsAutoCString charset;
int32_t source;
nsCOMPtr<nsIPrincipal> principal;
// opening in a new tab // opening in a new tab
docShell->GetParentCharset(charset); docShell->GetParentCharset(charset, &source, getter_AddRefs(principal));
if (charset.IsEmpty() || charset.Equals("UTF-8")) { if (!charset.IsEmpty() &&
nsCOMPtr<nsIContentViewer> cv; !charset.Equals("UTF-8") &&
docShell->GetContentViewer(getter_AddRefs(cv)); NodePrincipal()->Equals(principal)) {
SetDocumentCharacterSetSource(source);
// not being able to set the charset is not critical.
NS_ENSURE_TRUE(cv, NS_OK);
nsCOMPtr<nsIMarkupDocumentViewer> muCV = do_QueryInterface(cv);
if (muCV) {
muCV->GetPrevDocCharacterSet(charset); // opening in the same window/tab
if (charset.Equals("UTF-8") || charset.IsEmpty()) {
muCV->GetDefaultCharacterSet(charset); // opening in a new window
}
}
}
if (!charset.IsEmpty() && !charset.Equals("UTF-8")) {
SetDocumentCharacterSet(charset); SetDocumentCharacterSet(charset);
mCharacterSetSource = kCharsetFromUserDefault;
} }
return NS_OK; return NS_OK;

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

@ -1134,47 +1134,8 @@ HTMLContentSink::FlushTags()
NS_IMETHODIMP NS_IMETHODIMP
HTMLContentSink::SetDocumentCharset(nsACString& aCharset) HTMLContentSink::SetDocumentCharset(nsACString& aCharset)
{ {
if (mDocShell) { MOZ_ASSUME_UNREACHABLE("<meta charset> case doesn't occur with about:blank");
// the following logic to get muCV is copied from return NS_ERROR_NOT_IMPLEMENTED;
// nsHTMLDocument::StartDocumentLoad
// We need to call muCV->SetPrevDocCharacterSet here in case
// the charset is detected by parser DetectMetaTag
nsCOMPtr<nsIMarkupDocumentViewer> muCV;
nsCOMPtr<nsIContentViewer> cv;
mDocShell->GetContentViewer(getter_AddRefs(cv));
if (cv) {
muCV = do_QueryInterface(cv);
} else {
// in this block of code, if we get an error result, we return
// it but if we get a null pointer, that's perfectly legal for
// parent and parentContentViewer
NS_ENSURE_TRUE(mDocShell, NS_ERROR_FAILURE);
nsCOMPtr<nsIDocShellTreeItem> parentAsItem;
mDocShell->GetSameTypeParent(getter_AddRefs(parentAsItem));
nsCOMPtr<nsIDocShell> parent(do_QueryInterface(parentAsItem));
if (parent) {
nsCOMPtr<nsIContentViewer> parentContentViewer;
nsresult rv =
parent->GetContentViewer(getter_AddRefs(parentContentViewer));
if (NS_SUCCEEDED(rv) && parentContentViewer) {
muCV = do_QueryInterface(parentContentViewer);
}
}
}
if (muCV) {
muCV->SetPrevDocCharacterSet(aCharset);
}
}
if (mDocument) {
mDocument->SetDocumentCharacterSet(aCharset);
}
return NS_OK;
} }
nsISupports * nsISupports *

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

@ -395,22 +395,8 @@ nsHTMLDocument::TryCacheCharset(nsICachingChannel* aCachingChannel,
} }
} }
static bool
CheckSameOrigin(nsINode* aNode1, nsINode* aNode2)
{
NS_PRECONDITION(aNode1, "Null node?");
NS_PRECONDITION(aNode2, "Null node?");
bool equal;
return
NS_SUCCEEDED(aNode1->NodePrincipal()->
Equals(aNode2->NodePrincipal(), &equal)) &&
equal;
}
void void
nsHTMLDocument::TryParentCharset(nsIDocShell* aDocShell, nsHTMLDocument::TryParentCharset(nsIDocShell* aDocShell,
nsIDocument* aParentDocument,
int32_t& aCharsetSource, int32_t& aCharsetSource,
nsACString& aCharset) nsACString& aCharset)
{ {
@ -423,11 +409,13 @@ nsHTMLDocument::TryParentCharset(nsIDocShell* aDocShell,
int32_t parentSource; int32_t parentSource;
nsAutoCString parentCharset; nsAutoCString parentCharset;
aDocShell->GetParentCharset(parentCharset); nsCOMPtr<nsIPrincipal> parentPrincipal;
aDocShell->GetParentCharset(parentCharset,
&parentSource,
getter_AddRefs(parentPrincipal));
if (parentCharset.IsEmpty()) { if (parentCharset.IsEmpty()) {
return; return;
} }
aDocShell->GetParentCharsetSource(&parentSource);
if (kCharsetFromParentForced == parentSource || if (kCharsetFromParentForced == parentSource ||
kCharsetFromUserForced == parentSource) { kCharsetFromUserForced == parentSource) {
if (WillIgnoreCharsetOverride() || if (WillIgnoreCharsetOverride() ||
@ -440,33 +428,13 @@ nsHTMLDocument::TryParentCharset(nsIDocShell* aDocShell,
return; return;
} }
if (aCharsetSource >= kCharsetFromHintPrevDoc) {
return;
}
if (kCharsetFromHintPrevDoc == parentSource) {
// Make sure that's OK
if (!aParentDocument ||
!CheckSameOrigin(this, aParentDocument) ||
!EncodingUtils::IsAsciiCompatible(parentCharset)) {
return;
}
// if parent is posted doc, set this prevent autodetections
// I'm not sure this makes much sense... but whatever.
aCharset.Assign(parentCharset);
aCharsetSource = kCharsetFromHintPrevDoc;
return;
}
if (aCharsetSource >= kCharsetFromParentFrame) { if (aCharsetSource >= kCharsetFromParentFrame) {
return; return;
} }
if (kCharsetFromCache <= parentSource) { if (kCharsetFromCache <= parentSource) {
// Make sure that's OK // Make sure that's OK
if (!aParentDocument || if (!NodePrincipal()->Equals(parentPrincipal) ||
!CheckSameOrigin(this, aParentDocument) ||
!EncodingUtils::IsAsciiCompatible(parentCharset)) { !EncodingUtils::IsAsciiCompatible(parentCharset)) {
return; return;
} }
@ -499,25 +467,6 @@ nsHTMLDocument::TryWeakDocTypeDefault(int32_t& aCharsetSource,
return; return;
} }
void
nsHTMLDocument::TryDefaultCharset( nsIMarkupDocumentViewer* aMarkupDV,
int32_t& aCharsetSource,
nsACString& aCharset)
{
if(kCharsetFromUserDefault <= aCharsetSource)
return;
nsAutoCString defaultCharsetFromDocShell;
if (aMarkupDV) {
nsresult rv =
aMarkupDV->GetDefaultCharacterSet(defaultCharsetFromDocShell);
if(NS_SUCCEEDED(rv) && EncodingUtils::IsAsciiCompatible(defaultCharsetFromDocShell)) {
aCharset = defaultCharsetFromDocShell;
aCharsetSource = kCharsetFromUserDefault;
}
}
}
void void
nsHTMLDocument::SetDocumentCharacterSet(const nsACString& aCharSetID) nsHTMLDocument::SetDocumentCharacterSet(const nsACString& aCharSetID)
{ {
@ -652,21 +601,13 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
} }
nsCOMPtr<nsIDocShell> parent(do_QueryInterface(parentAsItem)); nsCOMPtr<nsIDocShell> parent(do_QueryInterface(parentAsItem));
nsCOMPtr<nsIDocument> parentDocument;
nsCOMPtr<nsIContentViewer> parentContentViewer; nsCOMPtr<nsIContentViewer> parentContentViewer;
if (parent) { if (parent) {
rv = parent->GetContentViewer(getter_AddRefs(parentContentViewer)); rv = parent->GetContentViewer(getter_AddRefs(parentContentViewer));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
if (parentContentViewer) {
parentDocument = parentContentViewer->GetDocument();
}
} }
//
// The following logic is mirrored in nsWebShell::Embed!
//
nsCOMPtr<nsIMarkupDocumentViewer> muCV; nsCOMPtr<nsIMarkupDocumentViewer> muCV;
bool muCVIsParent = false;
nsCOMPtr<nsIContentViewer> cv; nsCOMPtr<nsIContentViewer> cv;
if (docShell) { if (docShell) {
docShell->GetContentViewer(getter_AddRefs(cv)); docShell->GetContentViewer(getter_AddRefs(cv));
@ -675,9 +616,6 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
muCV = do_QueryInterface(cv); muCV = do_QueryInterface(cv);
} else { } else {
muCV = do_QueryInterface(parentContentViewer); muCV = do_QueryInterface(parentContentViewer);
if (muCV) {
muCVIsParent = true;
}
} }
nsAutoCString urlSpec; nsAutoCString urlSpec;
@ -739,35 +677,14 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
TryUserForcedCharset(muCV, docShell, charsetSource, charset); TryUserForcedCharset(muCV, docShell, charsetSource, charset);
TryHintCharset(muCV, charsetSource, charset); // XXX mailnews-only TryHintCharset(muCV, charsetSource, charset); // XXX mailnews-only
TryParentCharset(docShell, parentDocument, charsetSource, charset); TryParentCharset(docShell, charsetSource, charset);
if (cachingChan && !urlSpec.IsEmpty()) { if (cachingChan && !urlSpec.IsEmpty()) {
TryCacheCharset(cachingChan, charsetSource, charset); TryCacheCharset(cachingChan, charsetSource, charset);
} }
TryDefaultCharset(muCV, charsetSource, charset);
TryWeakDocTypeDefault(charsetSource, charset); TryWeakDocTypeDefault(charsetSource, charset);
bool isPostPage = false;
// check if current doc is from POST command
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(aChannel));
if (httpChannel) {
nsAutoCString methodStr;
rv = httpChannel->GetRequestMethod(methodStr);
isPostPage = (NS_SUCCEEDED(rv) &&
methodStr.EqualsLiteral("POST"));
}
if (isPostPage && muCV && kCharsetFromHintPrevDoc > charsetSource) {
nsAutoCString requestCharset;
muCV->GetPrevDocCharacterSet(requestCharset);
if (!requestCharset.IsEmpty()) {
charsetSource = kCharsetFromHintPrevDoc;
charset = requestCharset;
}
}
if (wyciwygChannel) { if (wyciwygChannel) {
// We know for sure that the parser needs to be using UTF16. // We know for sure that the parser needs to be using UTF16.
parserCharset = "UTF-16"; parserCharset = "UTF-16";
@ -796,11 +713,6 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
SetDocumentCharacterSetSource(charsetSource); SetDocumentCharacterSetSource(charsetSource);
SetDocumentCharacterSet(charset); SetDocumentCharacterSet(charset);
// set doc charset to muCV for next document.
// Don't propagate this back up to the parent document if we have one.
if (muCV && !muCVIsParent)
muCV->SetPrevDocCharacterSet(charset);
if (cachingChan) { if (cachingChan) {
NS_ASSERTION(charset == parserCharset, NS_ASSERTION(charset == parserCharset,
"How did those end up different here? wyciwyg channels are " "How did those end up different here? wyciwyg channels are "

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

@ -311,15 +311,10 @@ protected:
static void TryCacheCharset(nsICachingChannel* aCachingChannel, static void TryCacheCharset(nsICachingChannel* aCachingChannel,
int32_t& aCharsetSource, int32_t& aCharsetSource,
nsACString& aCharset); nsACString& aCharset);
// aParentDocument could be null.
void TryParentCharset(nsIDocShell* aDocShell, void TryParentCharset(nsIDocShell* aDocShell,
nsIDocument* aParentDocument,
int32_t& charsetSource, nsACString& aCharset); int32_t& charsetSource, nsACString& aCharset);
static void TryWeakDocTypeDefault(int32_t& aCharsetSource, static void TryWeakDocTypeDefault(int32_t& aCharsetSource,
nsACString& aCharset); nsACString& aCharset);
static void TryDefaultCharset(nsIMarkupDocumentViewer* aMarkupDV,
int32_t& aCharsetSource,
nsACString& aCharset);
// Override so we can munge the charset on our wyciwyg channel as needed. // Override so we can munge the charset on our wyciwyg channel as needed.
virtual void SetDocumentCharacterSet(const nsACString& aCharSetID) MOZ_OVERRIDE; virtual void SetDocumentCharacterSet(const nsACString& aCharSetID) MOZ_OVERRIDE;

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

@ -66,5 +66,8 @@ MOCHITEST_FILES = test_bug1682.html \
test_non-ascii-cookie.html \ test_non-ascii-cookie.html \
test_non-ascii-cookie.html^headers^ \ test_non-ascii-cookie.html^headers^ \
test_bug765780.html \ test_bug765780.html \
test_bug871161.html \
file_bug871161-1.html \
file_bug871161-2.html \
$(NULL) $(NULL)

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

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<meta charset=windows-1251>
<title>Page with non-default charset</title>
<script>
function run() {
document.forms[0].submit();
}
</script>
</head>
<body onload="run();">
<form method=post action="http://example.org/tests/content/html/document/test/file_bug871161-2.html"></form>
</body>
</html>

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

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>Page without declared charset</title>
<script>
function done() {
window.opener.postMessage(document.characterSet, "*");
}
</script>
</head>
<body onload="done();">
</body>
</html>

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

@ -0,0 +1,37 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=871161
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 871161</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="application/javascript">
/** Test for Bug 871161 **/
SimpleTest.waitForExplicitFinish();
window.onmessage = function(e) {
is(e.data, "windows-1252", "Wrong charset");
e.source.close();
SimpleTest.finish();
}
function run() {
window.open("file_bug871161-1.html");
}
</script>
</head>
<body onload="run();">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=871161">Mozilla Bug 871161</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
</html>

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

@ -1859,20 +1859,15 @@ nsDocShell::SetCurrentURI(nsIURI *aURI, nsIRequest *aRequest,
} }
NS_IMETHODIMP NS_IMETHODIMP
nsDocShell::GetCharset(char** aCharset) nsDocShell::GetCharset(nsACString& aCharset)
{ {
NS_ENSURE_ARG_POINTER(aCharset); aCharset.Truncate();
*aCharset = nullptr;
nsIPresShell* presShell = GetPresShell(); nsIPresShell* presShell = GetPresShell();
NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE); NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
nsIDocument *doc = presShell->GetDocument(); nsIDocument *doc = presShell->GetDocument();
NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE); NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
*aCharset = ToNewCString(doc->GetDocumentCharacterSet()); aCharset = doc->GetDocumentCharacterSet();
if (!*aCharset) {
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK; return NS_OK;
} }
@ -1901,7 +1896,6 @@ nsDocShell::GatherCharsetMenuTelemetry()
int32_t charsetSource = doc->GetDocumentCharacterSetSource(); int32_t charsetSource = doc->GetDocumentCharacterSetSource();
switch (charsetSource) { switch (charsetSource) {
case kCharsetFromWeakDocTypeDefault: case kCharsetFromWeakDocTypeDefault:
case kCharsetFromUserDefault:
case kCharsetFromDocTypeDefault: case kCharsetFromDocTypeDefault:
case kCharsetFromCache: case kCharsetFromCache:
case kCharsetFromParentFrame: case kCharsetFromParentFrame:
@ -1945,23 +1939,10 @@ nsDocShell::GatherCharsetMenuTelemetry()
} }
NS_IMETHODIMP NS_IMETHODIMP
nsDocShell::SetCharset(const char* aCharset) nsDocShell::SetCharset(const nsACString& aCharset)
{ {
// set the default charset
nsCOMPtr<nsIContentViewer> viewer;
GetContentViewer(getter_AddRefs(viewer));
if (viewer) {
nsCOMPtr<nsIMarkupDocumentViewer> muDV(do_QueryInterface(viewer));
if (muDV) {
nsCString charset(aCharset);
NS_ENSURE_SUCCESS(muDV->SetDefaultCharacterSet(charset),
NS_ERROR_FAILURE);
}
}
// set the charset override // set the charset override
nsCString charset(aCharset); SetForcedCharset(aCharset);
SetForcedCharset(charset);
return NS_OK; return NS_OK;
} }
@ -1978,28 +1959,24 @@ NS_IMETHODIMP nsDocShell::GetForcedCharset(nsACString& aResult)
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP nsDocShell::SetParentCharset(const nsACString& aCharset) void
nsDocShell::SetParentCharset(const nsACString& aCharset,
int32_t aCharsetSource,
nsIPrincipal* aPrincipal)
{ {
mParentCharset = aCharset; mParentCharset = aCharset;
return NS_OK;
}
NS_IMETHODIMP nsDocShell::GetParentCharset(nsACString& aResult)
{
aResult = mParentCharset;
return NS_OK;
}
NS_IMETHODIMP nsDocShell::SetParentCharsetSource(int32_t aCharsetSource)
{
mParentCharsetSource = aCharsetSource; mParentCharsetSource = aCharsetSource;
return NS_OK; mParentCharsetPrincipal = aPrincipal;
} }
NS_IMETHODIMP nsDocShell::GetParentCharsetSource(int32_t * aParentCharsetSource) void
nsDocShell::GetParentCharset(nsACString& aCharset,
int32_t* aCharsetSource,
nsIPrincipal** aPrincipal)
{ {
*aParentCharsetSource = mParentCharsetSource; aCharset = mParentCharset;
return NS_OK; *aCharsetSource = mParentCharsetSource;
NS_IF_ADDREF(*aPrincipal = mParentCharsetPrincipal);
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -3572,7 +3549,6 @@ nsDocShell::AddChild(nsIDocShellTreeItem * aChild)
nsIDocument* doc = mContentViewer->GetDocument(); nsIDocument* doc = mContentViewer->GetDocument();
if (!doc) if (!doc)
return NS_OK; return NS_OK;
const nsACString &parentCS = doc->GetDocumentCharacterSet();
bool isWyciwyg = false; bool isWyciwyg = false;
@ -3587,17 +3563,12 @@ nsDocShell::AddChild(nsIDocShellTreeItem * aChild)
// the actual source charset, which is what we're trying to // the actual source charset, which is what we're trying to
// expose here. // expose here.
// set the child's parentCharset const nsACString &parentCS = doc->GetDocumentCharacterSet();
res = childAsDocShell->SetParentCharset(parentCS);
if (NS_FAILED(res))
return NS_OK;
int32_t charsetSource = doc->GetDocumentCharacterSetSource(); int32_t charsetSource = doc->GetDocumentCharacterSetSource();
// set the child's parentCharset // set the child's parentCharset
res = childAsDocShell->SetParentCharsetSource(charsetSource); childAsDocShell->SetParentCharset(parentCS,
if (NS_FAILED(res)) charsetSource,
return NS_OK; doc->NodePrincipal());
} }
// printf("### 1 >>> Adding child. Parent CS = %s. ItemType = %d.\n", NS_LossyConvertUTF16toASCII(parentCS).get(), mItemType); // printf("### 1 >>> Adding child. Parent CS = %s. ItemType = %d.\n", NS_LossyConvertUTF16toASCII(parentCS).get(), mItemType);
@ -8298,11 +8269,9 @@ nsDocShell::SetupNewViewer(nsIContentViewer * aNewViewer)
NS_ERROR_FAILURE); NS_ERROR_FAILURE);
nsCOMPtr<nsIDocShell> parent(do_QueryInterface(parentAsItem)); nsCOMPtr<nsIDocShell> parent(do_QueryInterface(parentAsItem));
nsAutoCString defaultCharset;
nsAutoCString forceCharset; nsAutoCString forceCharset;
nsAutoCString hintCharset; nsAutoCString hintCharset;
int32_t hintCharsetSource; int32_t hintCharsetSource;
nsAutoCString prevDocCharset;
int32_t minFontSize; int32_t minFontSize;
float textZoom; float textZoom;
float pageZoom; float pageZoom;
@ -8340,9 +8309,6 @@ nsDocShell::SetupNewViewer(nsIContentViewer * aNewViewer)
newMUDV = do_QueryInterface(aNewViewer,&rv); newMUDV = do_QueryInterface(aNewViewer,&rv);
if (newMUDV) { if (newMUDV) {
NS_ENSURE_SUCCESS(oldMUDV->
GetDefaultCharacterSet(defaultCharset),
NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(oldMUDV-> NS_ENSURE_SUCCESS(oldMUDV->
GetForceCharacterSet(forceCharset), GetForceCharacterSet(forceCharset),
NS_ERROR_FAILURE); NS_ERROR_FAILURE);
@ -8364,9 +8330,6 @@ nsDocShell::SetupNewViewer(nsIContentViewer * aNewViewer)
NS_ENSURE_SUCCESS(oldMUDV-> NS_ENSURE_SUCCESS(oldMUDV->
GetAuthorStyleDisabled(&styleDisabled), GetAuthorStyleDisabled(&styleDisabled),
NS_ERROR_FAILURE); NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(oldMUDV->
GetPrevDocCharacterSet(prevDocCharset),
NS_ERROR_FAILURE);
} }
} }
} }
@ -8421,8 +8384,6 @@ nsDocShell::SetupNewViewer(nsIContentViewer * aNewViewer)
// If we have old state to copy, set the old state onto the new content // If we have old state to copy, set the old state onto the new content
// viewer // viewer
if (newMUDV) { if (newMUDV) {
NS_ENSURE_SUCCESS(newMUDV->SetDefaultCharacterSet(defaultCharset),
NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(newMUDV->SetForceCharacterSet(forceCharset), NS_ENSURE_SUCCESS(newMUDV->SetForceCharacterSet(forceCharset),
NS_ERROR_FAILURE); NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(newMUDV->SetHintCharacterSet(hintCharset), NS_ENSURE_SUCCESS(newMUDV->SetHintCharacterSet(hintCharset),
@ -8430,8 +8391,6 @@ nsDocShell::SetupNewViewer(nsIContentViewer * aNewViewer)
NS_ENSURE_SUCCESS(newMUDV-> NS_ENSURE_SUCCESS(newMUDV->
SetHintCharacterSetSource(hintCharsetSource), SetHintCharacterSetSource(hintCharsetSource),
NS_ERROR_FAILURE); NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(newMUDV->SetPrevDocCharacterSet(prevDocCharset),
NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(newMUDV->SetMinFontSize(minFontSize), NS_ENSURE_SUCCESS(newMUDV->SetMinFontSize(minFontSize),
NS_ERROR_FAILURE); NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(newMUDV->SetTextZoom(textZoom), NS_ENSURE_SUCCESS(newMUDV->SetTextZoom(textZoom),

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

@ -870,9 +870,10 @@ protected:
private: private:
nsCString mForcedCharset; nsCString mForcedCharset;
nsCString mParentCharset; nsCString mParentCharset;
int32_t mParentCharsetSource;
nsCOMPtr<nsIPrincipal> mParentCharsetPrincipal;
nsTObserverArray<nsWeakPtr> mPrivacyObservers; nsTObserverArray<nsWeakPtr> mPrivacyObservers;
nsTObserverArray<nsWeakPtr> mReflowObservers; nsTObserverArray<nsWeakPtr> mReflowObservers;
int32_t mParentCharsetSource;
nsCString mOriginalUriString; nsCString mOriginalUriString;
// Separate function to do the actual name (i.e. not _top, _self etc.) // Separate function to do the actual name (i.e. not _top, _self etc.)

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

@ -43,7 +43,7 @@ interface nsIReflowObserver;
typedef unsigned long nsLoadFlags; typedef unsigned long nsLoadFlags;
[scriptable, builtinclass, uuid(c0bb3b19-5448-4f4d-9366-cbcd4d7cdb96)] [scriptable, builtinclass, uuid(4c8cd9da-4e93-42ed-9901-3781e90458d9)]
interface nsIDocShell : nsIDocShellTreeItem interface nsIDocShell : nsIDocShellTreeItem
{ {
/** /**
@ -597,40 +597,12 @@ interface nsIDocShell : nsIDocShellTreeItem
void createAboutBlankContentViewer(in nsIPrincipal aPrincipal); void createAboutBlankContentViewer(in nsIPrincipal aPrincipal);
/** /**
* The charset attribute allows the user to view, hint, and set which * Upon getting, returns the canonical encoding label of the document
* converter is used to read the document's data. * currently loaded into this docshell.
* *
* <P>Inside Mozilla all text is encoded as Unicode. By standardizing * Upon setting, sets forcedCharset for compatibility with legacy callers.
* on Unicode every piece of code that handles characters no longer
* needs to:
*
* Have access to a character encoding parameter.
* Ask is the data stateful?
* Ask is the data single byte?
* Ask is the data multi-byte?
* If multi-byte: have access to a routine that can
* determine how many bytes in the current character.
*
* When the document is read in a converter is used to convert
* the document's data to Unicode.
*
* The charset attribute provides the ability to:
*
* See what converter was used when inputting the documents
* data.
*
* Override the character set for documents where the specified
* fallback, or auto-detected character set is incorrect
*
* Get/sets the encoding (converter) used to read the
* document. Get returns the encoding used. Set forces
* (overrides) the encoding. After forcing the charset the
* embedding application will need to cause the data to be
* reparsed in order to update the DOM / display.
*
* A force also sets the fallback encoding for this frame.
*/ */
attribute string charset; attribute ACString charset;
/** /**
* Called when the user chose an encoding override from the character * Called when the user chose an encoding override from the character
@ -640,23 +612,21 @@ interface nsIDocShell : nsIDocShellTreeItem
void gatherCharsetMenuTelemetry(); void gatherCharsetMenuTelemetry();
/** /**
* The charset forced by the user. When the charset attribute is set this * The charset forced by the user.
* attribute is set to the same value.
*
* XXX Could this be replaced by a boolean?
*/ */
attribute ACString forcedCharset; attribute ACString forcedCharset;
/** /**
* In a child docshell, this is the charset of the parent docshell * In a child docshell, this is the charset of the parent docshell
*/ */
attribute ACString parentCharset; [noscript, notxpcom, nostdcall] void setParentCharset(
in ACString parentCharset,
/* in int32_t parentCharsetSource,
* In a child docshell, this is the source of parentCharset in nsIPrincipal parentCharsetPrincipal);
* @see nsCharsetSource.h [noscript, notxpcom, nostdcall] void getParentCharset(
*/ out ACString parentCharset,
attribute int32_t parentCharsetSource; out int32_t parentCharsetSource,
out nsIPrincipal parentCharsetPrincipal);
/** /**
* Add an observer to the list of parties to be notified when this docshell's * Add an observer to the list of parties to be notified when this docshell's

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

@ -23,7 +23,7 @@ interface nsIMarkupDocumentViewer;
[ref] native nsIMarkupDocumentViewerTArray(nsTArray<nsCOMPtr<nsIMarkupDocumentViewer> >); [ref] native nsIMarkupDocumentViewerTArray(nsTArray<nsCOMPtr<nsIMarkupDocumentViewer> >);
[scriptable, uuid(23326580-e6ce-4ee1-94b8-f1d9424a9977)] [scriptable, uuid(6acfadef-22ee-4924-be6c-776e8def6e1b)]
interface nsIMarkupDocumentViewer : nsISupports interface nsIMarkupDocumentViewer : nsISupports
{ {
@ -41,11 +41,6 @@ interface nsIMarkupDocumentViewer : nsISupports
/** Disable entire author style level (including HTML presentation hints) */ /** Disable entire author style level (including HTML presentation hints) */
attribute boolean authorStyleDisabled; attribute boolean authorStyleDisabled;
/*
XXX Comment here!
*/
attribute ACString defaultCharacterSet;
/** /**
* XXX comm-central only: bug 829543. Not the Character Encoding menu in * XXX comm-central only: bug 829543. Not the Character Encoding menu in
* browser! * browser!
@ -62,11 +57,6 @@ interface nsIMarkupDocumentViewer : nsISupports
*/ */
attribute int32_t hintCharacterSetSource; attribute int32_t hintCharacterSetSource;
/*
character set from prev document
*/
attribute ACString prevDocCharacterSet;
//void GetCharacterSetHint(in wstring hintCharset, in int32_t charsetSource); //void GetCharacterSetHint(in wstring hintCharset, in int32_t charsetSource);
/** /**

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

@ -771,52 +771,6 @@ nsWindowWatcher::OpenWindowInternal(nsIDOMWindow *aParent,
} }
} }
// Inherit the right character set into the new window to use as a fallback
// in the event the document being loaded does not specify a charset. When
// aCalledFromJS is true, we want to use the character set of the document in
// the caller; otherwise we want to use the character set of aParent's
// docshell. Failing to set this charset is not fatal, so we want to continue
// in the face of errors.
nsCOMPtr<nsIContentViewer> newCV;
newDocShell->GetContentViewer(getter_AddRefs(newCV));
nsCOMPtr<nsIMarkupDocumentViewer> newMuCV = do_QueryInterface(newCV);
if (newMuCV) {
nsCOMPtr<nsIDocShellTreeItem> parentItem;
GetWindowTreeItem(aParent, getter_AddRefs(parentItem));
if (aCalledFromJS) {
nsCOMPtr<nsIDocShellTreeItem> callerItem = GetCallerTreeItem(parentItem);
nsCOMPtr<nsPIDOMWindow> callerWin = do_GetInterface(callerItem);
if (callerWin) {
nsCOMPtr<nsIDocument> doc = callerWin->GetExtantDoc();
if (doc) {
newMuCV->SetDefaultCharacterSet(doc->GetDocumentCharacterSet());
}
}
}
else {
nsCOMPtr<nsIDocShell> parentDocshell = do_QueryInterface(parentItem);
// parentDocshell may be null if the parent got closed in the meantime
if (parentDocshell) {
nsCOMPtr<nsIContentViewer> parentCV;
parentDocshell->GetContentViewer(getter_AddRefs(parentCV));
nsCOMPtr<nsIMarkupDocumentViewer> parentMuCV =
do_QueryInterface(parentCV);
if (parentMuCV) {
nsAutoCString charset;
nsresult res = parentMuCV->GetDefaultCharacterSet(charset);
if (NS_SUCCEEDED(res)) {
newMuCV->SetDefaultCharacterSet(charset);
}
res = parentMuCV->GetPrevDocCharacterSet(charset);
if (NS_SUCCEEDED(res)) {
newMuCV->SetPrevDocCharacterSet(charset);
}
}
}
}
}
// Now we have to set the right opener principal on the new window. Note // Now we have to set the right opener principal on the new window. Note
// that we have to do this _before_ starting any URI loads, thanks to the // that we have to do this _before_ starting any URI loads, thanks to the
// sync nature of javascript: loads. Since this is the only place where we // sync nature of javascript: loads. Since this is the only place where we

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

@ -416,9 +416,7 @@ protected:
/* character set member data */ /* character set member data */
int32_t mHintCharsetSource; int32_t mHintCharsetSource;
nsCString mHintCharset; nsCString mHintCharset;
nsCString mDefaultCharacterSet;
nsCString mForceCharacterSet; nsCString mForceCharacterSet;
nsCString mPrevDocCharacterSet;
bool mIsPageMode; bool mIsPageMode;
bool mCallerIsClosingWindow; bool mCallerIsClosingWindow;
@ -3003,47 +3001,6 @@ nsDocumentViewer::StopEmulatingMedium()
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP
nsDocumentViewer::GetDefaultCharacterSet(nsACString& aDefaultCharacterSet)
{
if (mDefaultCharacterSet.IsEmpty())
{
const nsAdoptingCString& defCharset =
Preferences::GetLocalizedCString("intl.charset.default");
// Don't let the user break things by setting intl.charset.default to
// not a rough ASCII superset
nsAutoCString canonical;
if (EncodingUtils::FindEncodingForLabel(defCharset, canonical) &&
EncodingUtils::IsAsciiCompatible(canonical)) {
mDefaultCharacterSet = canonical;
} else {
mDefaultCharacterSet.AssignLiteral("windows-1252");
}
}
aDefaultCharacterSet = mDefaultCharacterSet;
return NS_OK;
}
static void
SetChildDefaultCharacterSet(nsIMarkupDocumentViewer* aChild, void* aClosure)
{
const nsACString* charset = static_cast<nsACString*>(aClosure);
aChild->SetDefaultCharacterSet(*charset);
}
NS_IMETHODIMP
nsDocumentViewer::SetDefaultCharacterSet(const nsACString& aDefaultCharacterSet)
{
mDefaultCharacterSet = aDefaultCharacterSet; // this does a copy of aDefaultCharacterSet
// now set the default char set on all children of mContainer
CallChildren(SetChildDefaultCharacterSet, (void*) &aDefaultCharacterSet);
return NS_OK;
}
// XXX: SEMANTIC CHANGE!
// returns a copy of the string. Caller is responsible for freeing result
// using Recycle(aForceCharacterSet)
NS_IMETHODIMP nsDocumentViewer::GetForceCharacterSet(nsACString& aForceCharacterSet) NS_IMETHODIMP nsDocumentViewer::GetForceCharacterSet(nsACString& aForceCharacterSet)
{ {
aForceCharacterSet = mForceCharacterSet; aForceCharacterSet = mForceCharacterSet;
@ -3066,9 +3023,6 @@ nsDocumentViewer::SetForceCharacterSet(const nsACString& aForceCharacterSet)
return NS_OK; return NS_OK;
} }
// XXX: SEMANTIC CHANGE!
// returns a copy of the string. Caller is responsible for freeing result
// using Recycle(aHintCharacterSet)
NS_IMETHODIMP nsDocumentViewer::GetHintCharacterSet(nsACString& aHintCharacterSet) NS_IMETHODIMP nsDocumentViewer::GetHintCharacterSet(nsACString& aHintCharacterSet)
{ {
@ -3090,31 +3044,6 @@ NS_IMETHODIMP nsDocumentViewer::GetHintCharacterSetSource(int32_t *aHintCharacte
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP nsDocumentViewer::GetPrevDocCharacterSet(nsACString& aPrevDocCharacterSet)
{
aPrevDocCharacterSet = mPrevDocCharacterSet;
return NS_OK;
}
static void
SetChildPrevDocCharacterSet(nsIMarkupDocumentViewer* aChild, void* aClosure)
{
const nsACString* charset = static_cast<nsACString*>(aClosure);
aChild->SetPrevDocCharacterSet(*charset);
}
NS_IMETHODIMP
nsDocumentViewer::SetPrevDocCharacterSet(const nsACString& aPrevDocCharacterSet)
{
mPrevDocCharacterSet = aPrevDocCharacterSet;
CallChildren(SetChildPrevDocCharacterSet, (void*) &aPrevDocCharacterSet);
return NS_OK;
}
static void static void
SetChildHintCharacterSetSource(nsIMarkupDocumentViewer* aChild, void* aClosure) SetChildHintCharacterSetSource(nsIMarkupDocumentViewer* aChild, void* aClosure)
{ {

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

@ -221,39 +221,6 @@ nsHtml5TreeOpExecutor::SetDocumentCharsetAndSource(nsACString& aCharset, int32_t
mDocument->SetDocumentCharacterSetSource(aCharsetSource); mDocument->SetDocumentCharacterSetSource(aCharsetSource);
mDocument->SetDocumentCharacterSet(aCharset); mDocument->SetDocumentCharacterSet(aCharset);
} }
if (mDocShell) {
// the following logic to get muCV is copied from
// nsHTMLDocument::StartDocumentLoad
// We need to call muCV->SetPrevDocCharacterSet here in case
// the charset is detected by parser DetectMetaTag
nsCOMPtr<nsIMarkupDocumentViewer> mucv;
nsCOMPtr<nsIContentViewer> cv;
mDocShell->GetContentViewer(getter_AddRefs(cv));
if (cv) {
mucv = do_QueryInterface(cv);
} else {
// in this block of code, if we get an error result, we return
// it but if we get a null pointer, that's perfectly legal for
// parent and parentContentViewer
if (!mDocShell) {
return;
}
nsCOMPtr<nsIDocShellTreeItem> parentAsItem;
mDocShell->GetSameTypeParent(getter_AddRefs(parentAsItem));
nsCOMPtr<nsIDocShell> parent(do_QueryInterface(parentAsItem));
if (parent) {
nsCOMPtr<nsIContentViewer> parentContentViewer;
nsresult rv =
parent->GetContentViewer(getter_AddRefs(parentContentViewer));
if (NS_SUCCEEDED(rv) && parentContentViewer) {
mucv = do_QueryInterface(parentContentViewer);
}
}
}
if (mucv) {
mucv->SetPrevDocCharacterSet(aCharset);
}
}
} }
nsISupports* nsISupports*

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

@ -8,19 +8,18 @@
// note: the value order defines the priority; higher numbers take priority // note: the value order defines the priority; higher numbers take priority
#define kCharsetUninitialized 0 #define kCharsetUninitialized 0
#define kCharsetFromWeakDocTypeDefault 1 #define kCharsetFromWeakDocTypeDefault 1
#define kCharsetFromUserDefault 2 #define kCharsetFromDocTypeDefault 2 // This and up confident for XHR
#define kCharsetFromDocTypeDefault 3 // This and up confident for XHR #define kCharsetFromCache 3
#define kCharsetFromCache 4 #define kCharsetFromParentFrame 4
#define kCharsetFromParentFrame 5 #define kCharsetFromAutoDetection 5
#define kCharsetFromAutoDetection 6 #define kCharsetFromHintPrevDoc 6
#define kCharsetFromHintPrevDoc 7 #define kCharsetFromMetaPrescan 7 // this one and smaller: HTML5 Tentative
#define kCharsetFromMetaPrescan 8 // this one and smaller: HTML5 Tentative #define kCharsetFromMetaTag 8 // this one and greater: HTML5 Confident
#define kCharsetFromMetaTag 9 // this one and greater: HTML5 Confident #define kCharsetFromIrreversibleAutoDetection 9
#define kCharsetFromIrreversibleAutoDetection 10 #define kCharsetFromChannel 10
#define kCharsetFromChannel 11 #define kCharsetFromOtherComponent 11
#define kCharsetFromOtherComponent 12 #define kCharsetFromParentForced 12 // propagates to child frames
#define kCharsetFromParentForced 13 // propagates to child frames #define kCharsetFromUserForced 13 // propagates to child frames
#define kCharsetFromUserForced 14 // propagates to child frames #define kCharsetFromByteOrderMark 14
#define kCharsetFromByteOrderMark 15
#endif /* nsCharsetSource_h_ */ #endif /* nsCharsetSource_h_ */

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

@ -110,9 +110,9 @@ function viewSource(url)
if (typeof(arg) == "string" && arg.indexOf('charset=') != -1) { if (typeof(arg) == "string" && arg.indexOf('charset=') != -1) {
var arrayArgComponents = arg.split('='); var arrayArgComponents = arg.split('=');
if (arrayArgComponents) { if (arrayArgComponents) {
//we should "inherit" the charset menu setting in a new window // Remember the charset here so that it can be used below in case
// the document had a forced charset.
charset = arrayArgComponents[1]; charset = arrayArgComponents[1];
gBrowser.markupDocumentViewer.defaultCharacterSet = charset;
} }
} }
} catch (ex) { } catch (ex) {