Move nsIDocumentCharsetInfo out of intl/chardet into nsIDocShell, Bug 713825, r=bz, mbrubeck

This commit is contained in:
Simon Montagu
2012-01-24 11:52:05 +02:00
parent 22832cf881
commit 5c995efcb2
20 changed files with 114 additions and 312 deletions

View File

@@ -49,7 +49,6 @@
#include "nsIMarkupDocumentViewer.h"
#include "nsIDocShell.h"
#include "nsIParser.h" // kCharsetFrom* macro definition
#include "nsIDocumentCharsetInfo.h"
#include "nsNodeInfoManager.h"
#include "nsContentUtils.h"
@@ -185,7 +184,7 @@ MediaDocument::StartDocumentLoad(const char* aCommand,
// 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 |documentCharsetInfo|. Note that we
// 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
// 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
@@ -197,16 +196,12 @@ MediaDocument::StartDocumentLoad(const char* aCommand,
// not being able to set the charset is not critical.
NS_ENSURE_TRUE(docShell, NS_OK);
nsCOMPtr<nsIDocumentCharsetInfo> dcInfo;
nsCAutoString charset;
docShell->GetDocumentCharsetInfo(getter_AddRefs(dcInfo));
if (dcInfo) {
nsCOMPtr<nsIAtom> csAtom;
dcInfo->GetParentCharset(getter_AddRefs(csAtom));
if (csAtom) { // opening in a new tab
csAtom->ToUTF8String(charset);
}
nsCOMPtr<nsIAtom> csAtom;
docShell->GetParentCharset(getter_AddRefs(csAtom));
if (csAtom) { // opening in a new tab
csAtom->ToUTF8String(charset);
}
if (charset.IsEmpty() || charset.Equals("UTF-8")) {

View File

@@ -105,7 +105,6 @@
#include "nsICharsetAlias.h"
#include "nsContentUtils.h"
#include "nsJSUtils.h"
#include "nsIDocumentCharsetInfo.h"
#include "nsIDocumentEncoder.h" //for outputting selection
#include "nsICachingChannel.h"
#include "nsIJSContextStack.h"
@@ -383,7 +382,7 @@ nsHTMLDocument::TryHintCharset(nsIMarkupDocumentViewer* aMarkupDV,
bool
nsHTMLDocument::TryUserForcedCharset(nsIMarkupDocumentViewer* aMarkupDV,
nsIDocumentCharsetInfo* aDocInfo,
nsIDocShell* aDocShell,
PRInt32& aCharsetSource,
nsACString& aCharset)
{
@@ -401,13 +400,13 @@ nsHTMLDocument::TryUserForcedCharset(nsIMarkupDocumentViewer* aMarkupDV,
aCharset = forceCharsetFromDocShell;
//TODO: we should define appropriate constant for force charset
aCharsetSource = kCharsetFromUserForced;
} else if (aDocInfo) {
} else if (aDocShell) {
nsCOMPtr<nsIAtom> csAtom;
aDocInfo->GetForcedCharset(getter_AddRefs(csAtom));
aDocShell->GetForcedCharset(getter_AddRefs(csAtom));
if (csAtom) {
csAtom->ToUTF8String(aCharset);
aCharsetSource = kCharsetFromUserForced;
aDocInfo->SetForcedCharset(nsnull);
aDocShell->SetForcedCharset(nsnull);
return true;
}
}
@@ -453,16 +452,16 @@ CheckSameOrigin(nsINode* aNode1, nsINode* aNode2)
}
bool
nsHTMLDocument::TryParentCharset(nsIDocumentCharsetInfo* aDocInfo,
nsHTMLDocument::TryParentCharset(nsIDocShell* aDocShell,
nsIDocument* aParentDocument,
PRInt32& aCharsetSource,
nsACString& aCharset)
{
if (aDocInfo) {
if (aDocShell) {
PRInt32 source;
nsCOMPtr<nsIAtom> csAtom;
PRInt32 parentSource;
aDocInfo->GetParentCharsetSource(&parentSource);
aDocShell->GetParentCharsetSource(&parentSource);
if (kCharsetFromParentForced <= parentSource)
source = kCharsetFromParentForced;
else if (kCharsetFromHintPrevDoc == parentSource) {
@@ -489,7 +488,7 @@ nsHTMLDocument::TryParentCharset(nsIDocumentCharsetInfo* aDocInfo,
if (source < aCharsetSource)
return true;
aDocInfo->GetParentCharset(getter_AddRefs(csAtom));
aDocShell->GetParentCharset(getter_AddRefs(csAtom));
if (csAtom) {
csAtom->ToUTF8String(aCharset);
aCharsetSource = source;
@@ -744,9 +743,6 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
parserCharset = charset;
} else {
NS_ASSERTION(docShell && docShellAsItem, "Unexpected null value");
nsCOMPtr<nsIDocumentCharsetInfo> dcInfo;
docShell->GetDocumentCharsetInfo(getter_AddRefs(dcInfo));
charsetSource = kCharsetUninitialized;
wyciwygChannel = do_QueryInterface(aChannel);
@@ -757,9 +753,9 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
// describes. Some try call might change charset source to
// multiple values, like TryHintCharset and TryParentCharset. It
// should be always safe to try more sources.
if (!TryUserForcedCharset(muCV, dcInfo, charsetSource, charset)) {
if (!TryUserForcedCharset(muCV, docShell, charsetSource, charset)) {
TryHintCharset(muCV, charsetSource, charset);
TryParentCharset(dcInfo, parentDocument, charsetSource, charset);
TryParentCharset(docShell, parentDocument, charsetSource, charset);
// Don't actually get the charset from the channel if this is a
// wyciwyg channel; it'll always be UTF-16

View File

@@ -63,7 +63,7 @@ class nsIEditorDocShell;
class nsIParser;
class nsIURI;
class nsIMarkupDocumentViewer;
class nsIDocumentCharsetInfo;
class nsIDocShell;
class nsICachingChannel;
class nsHTMLDocument : public nsDocument,
@@ -253,14 +253,14 @@ protected:
PRInt32& aCharsetSource,
nsACString& aCharset);
static bool TryUserForcedCharset(nsIMarkupDocumentViewer* aMarkupDV,
nsIDocumentCharsetInfo* aDocInfo,
nsIDocShell* aDocShell,
PRInt32& aCharsetSource,
nsACString& aCharset);
static bool TryCacheCharset(nsICachingChannel* aCachingChannel,
PRInt32& aCharsetSource,
nsACString& aCharset);
// aParentDocument could be null.
bool TryParentCharset(nsIDocumentCharsetInfo* aDocInfo,
bool TryParentCharset(nsIDocShell* aDocShell,
nsIDocument* aParentDocument,
PRInt32& charsetSource, nsACString& aCharset);
static bool UseWeakDocTypeDefault(PRInt32& aCharsetSource,