зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset 77af189b5c49 (bug 1373984) for build bustage in nsHtml5Parser.cpp a=backout CLOSED TREE
MozReview-Commit-ID: 6kBmU71j2To
This commit is contained in:
Родитель
55564f75eb
Коммит
e02435a31e
|
@ -281,7 +281,7 @@ XULLinkAccessible::AnchorURIAt(uint32_t aAnchorIndex)
|
|||
|
||||
nsCOMPtr<nsIURI> anchorURI;
|
||||
NS_NewURI(getter_AddRefs(anchorURI), href,
|
||||
document->GetDocumentCharacterSet(),
|
||||
document->GetDocumentCharacterSet().get(),
|
||||
baseURI);
|
||||
|
||||
return anchorURI.forget();
|
||||
|
|
|
@ -374,15 +374,14 @@ ForEachPing(nsIContent* aContent, ForEachPingCallback aCallback, void* aClosure)
|
|||
}
|
||||
|
||||
nsIDocument* doc = aContent->OwnerDoc();
|
||||
nsAutoCString charset;
|
||||
doc->GetDocumentCharacterSet()->Name(charset);
|
||||
|
||||
nsWhitespaceTokenizer tokenizer(value);
|
||||
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
nsCOMPtr<nsIURI> uri, baseURI = aContent->GetBaseURI();
|
||||
ios->NewURI(NS_ConvertUTF16toUTF8(tokenizer.nextToken()),
|
||||
charset.get(), baseURI, getter_AddRefs(uri));
|
||||
doc->GetDocumentCharacterSet().get(),
|
||||
baseURI, getter_AddRefs(uri));
|
||||
// if we can't generate a valid URI, then there is nothing to do
|
||||
if (!uri) {
|
||||
continue;
|
||||
|
@ -833,8 +832,6 @@ nsDocShell::nsDocShell()
|
|||
, mDefaultLoadFlags(nsIRequest::LOAD_NORMAL)
|
||||
, mFrameType(FRAME_TYPE_REGULAR)
|
||||
, mPrivateBrowsingId(0)
|
||||
, mForcedCharset(nullptr)
|
||||
, mParentCharset(nullptr)
|
||||
, mParentCharsetSource(0)
|
||||
, mJSRunToCompletionDepth(0)
|
||||
, mTouchEventsOverride(nsIDocShell::TOUCHEVENTS_OVERRIDE_NONE)
|
||||
|
@ -2033,7 +2030,7 @@ nsDocShell::GetCharset(nsACString& aCharset)
|
|||
NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
|
||||
nsIDocument* doc = presShell->GetDocument();
|
||||
NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
|
||||
doc->GetDocumentCharacterSet()->Name(aCharset);
|
||||
aCharset = doc->GetDocumentCharacterSet();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -2119,7 +2116,7 @@ NS_IMETHODIMP
|
|||
nsDocShell::SetForcedCharset(const nsACString& aCharset)
|
||||
{
|
||||
if (aCharset.IsEmpty()) {
|
||||
mForcedCharset = nullptr;
|
||||
mForcedCharset.Truncate();
|
||||
return NS_OK;
|
||||
}
|
||||
const Encoding* encoding = Encoding::ForLabel(aCharset);
|
||||
|
@ -2131,19 +2128,19 @@ nsDocShell::SetForcedCharset(const nsACString& aCharset)
|
|||
// Reject XSS hazards
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
mForcedCharset = encoding;
|
||||
encoding->Name(mForcedCharset);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocShell::GetForcedCharset(nsACString& aResult)
|
||||
{
|
||||
mForcedCharset->Name(aResult);
|
||||
aResult = mForcedCharset;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsDocShell::SetParentCharset(const Encoding*& aCharset,
|
||||
nsDocShell::SetParentCharset(const nsACString& aCharset,
|
||||
int32_t aCharsetSource,
|
||||
nsIPrincipal* aPrincipal)
|
||||
{
|
||||
|
@ -2153,7 +2150,7 @@ nsDocShell::SetParentCharset(const Encoding*& aCharset,
|
|||
}
|
||||
|
||||
void
|
||||
nsDocShell::GetParentCharset(const Encoding*& aCharset,
|
||||
nsDocShell::GetParentCharset(nsACString& aCharset,
|
||||
int32_t* aCharsetSource,
|
||||
nsIPrincipal** aPrincipal)
|
||||
{
|
||||
|
@ -4195,7 +4192,7 @@ nsDocShell::AddChild(nsIDocShellTreeItem* aChild)
|
|||
// the actual source charset, which is what we're trying to
|
||||
// expose here.
|
||||
|
||||
const Encoding* parentCS = doc->GetDocumentCharacterSet();
|
||||
const nsACString& parentCS = doc->GetDocumentCharacterSet();
|
||||
int32_t charsetSource = doc->GetDocumentCharacterSetSource();
|
||||
// set the child's parentCharset
|
||||
childAsDocShell->SetParentCharset(parentCS,
|
||||
|
@ -11624,8 +11621,7 @@ nsDocShell::ScrollToAnchor(bool aCurHasRef, bool aNewHasRef,
|
|||
NS_ENSURE_TRUE(mContentViewer, NS_ERROR_FAILURE);
|
||||
nsIDocument* doc = mContentViewer->GetDocument();
|
||||
NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
|
||||
nsAutoCString charset;
|
||||
doc->GetDocumentCharacterSet()->Name(charset);
|
||||
const nsACString& charset = doc->GetDocumentCharacterSet();
|
||||
|
||||
nsCOMPtr<nsITextToSubURI> textToSubURI =
|
||||
do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv);
|
||||
|
|
|
@ -62,7 +62,6 @@
|
|||
#include "nsIDeprecationWarner.h"
|
||||
|
||||
namespace mozilla {
|
||||
class Encoding;
|
||||
enum class TaskCategory;
|
||||
namespace dom {
|
||||
class EventTarget;
|
||||
|
@ -156,7 +155,6 @@ class nsDocShell final
|
|||
{
|
||||
friend class nsDSURIContentListener;
|
||||
friend class FramingChecker;
|
||||
using Encoding = mozilla::Encoding;
|
||||
|
||||
public:
|
||||
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(nsDocShell)
|
||||
|
@ -276,8 +274,6 @@ public:
|
|||
}
|
||||
bool InFrameSwap();
|
||||
|
||||
const Encoding* GetForcedCharset() { return mForcedCharset; }
|
||||
|
||||
private:
|
||||
bool CanSetOriginAttributes();
|
||||
|
||||
|
@ -1040,8 +1036,8 @@ protected:
|
|||
nsString mInterceptedDocumentId;
|
||||
|
||||
private:
|
||||
const Encoding* mForcedCharset;
|
||||
const Encoding* mParentCharset;
|
||||
nsCString mForcedCharset;
|
||||
nsCString mParentCharset;
|
||||
int32_t mParentCharsetSource;
|
||||
nsCOMPtr<nsIPrincipal> mParentCharsetPrincipal;
|
||||
nsTObserverArray<nsWeakPtr> mPrivacyObservers;
|
||||
|
|
|
@ -11,12 +11,8 @@
|
|||
%{ C++
|
||||
#include "js/TypeDecls.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/NotNull.h"
|
||||
class nsPresContext;
|
||||
class nsIPresShell;
|
||||
namespace mozilla {
|
||||
class Encoding;
|
||||
}
|
||||
%}
|
||||
|
||||
/**
|
||||
|
@ -26,7 +22,6 @@ class Encoding;
|
|||
[ptr] native nsPresContext(nsPresContext);
|
||||
[ptr] native nsIPresShell(nsIPresShell);
|
||||
[ref] native MaybeURI(mozilla::Maybe<nsCOMPtr<nsIURI>>);
|
||||
[ref] native Encoding(const mozilla::Encoding*);
|
||||
|
||||
interface nsIURI;
|
||||
interface nsIChannel;
|
||||
|
@ -718,11 +713,11 @@ interface nsIDocShell : nsIDocShellTreeItem
|
|||
* In a child docshell, this is the charset of the parent docshell
|
||||
*/
|
||||
[noscript, notxpcom, nostdcall] void setParentCharset(
|
||||
in Encoding parentCharset,
|
||||
in ACString parentCharset,
|
||||
in int32_t parentCharsetSource,
|
||||
in nsIPrincipal parentCharsetPrincipal);
|
||||
[noscript, notxpcom, nostdcall] void getParentCharset(
|
||||
out Encoding parentCharset,
|
||||
out ACString parentCharset,
|
||||
out int32_t parentCharsetSource,
|
||||
out nsIPrincipal parentCharsetPrincipal);
|
||||
|
||||
|
|
|
@ -429,7 +429,7 @@ nsIContent::GetBaseURI(bool aTryUseXHRDocBaseURI) const
|
|||
for (uint32_t i = baseAttrs.Length() - 1; i != uint32_t(-1); --i) {
|
||||
nsCOMPtr<nsIURI> newBase;
|
||||
nsresult rv = NS_NewURI(getter_AddRefs(newBase), baseAttrs[i],
|
||||
doc->GetDocumentCharacterSet(), base);
|
||||
doc->GetDocumentCharacterSet().get(), base);
|
||||
// Do a security check, almost the same as nsDocument::SetBaseURL()
|
||||
// Only need to do this on the final uri
|
||||
if (NS_SUCCEEDED(rv) && i == 0) {
|
||||
|
|
|
@ -39,6 +39,18 @@
|
|||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
static nsresult
|
||||
GetDocumentCharacterSetForURI(const nsAString& aHref, nsACString& aCharset)
|
||||
{
|
||||
aCharset.Truncate();
|
||||
|
||||
if (nsIDocument* doc = GetEntryDocument()) {
|
||||
aCharset = doc->GetDocumentCharacterSet();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
Location::Location(nsPIDOMWindowInner* aWindow, nsIDocShell *aDocShell)
|
||||
: mInnerWindow(aWindow)
|
||||
{
|
||||
|
@ -494,12 +506,11 @@ Location::SetHrefWithBase(const nsAString& aHref, nsIURI* aBase,
|
|||
|
||||
nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mDocShell));
|
||||
|
||||
if (nsIDocument* doc = GetEntryDocument()) {
|
||||
result = NS_NewURI(getter_AddRefs(newUri), aHref,
|
||||
doc->GetDocumentCharacterSet(), aBase);
|
||||
} else {
|
||||
nsAutoCString docCharset;
|
||||
if (NS_SUCCEEDED(GetDocumentCharacterSetForURI(aHref, docCharset)))
|
||||
result = NS_NewURI(getter_AddRefs(newUri), aHref, docCharset.get(), aBase);
|
||||
else
|
||||
result = NS_NewURI(getter_AddRefs(newUri), aHref, nullptr, aBase);
|
||||
}
|
||||
|
||||
if (newUri) {
|
||||
/* Check with the scriptContext if it is currently processing a script tag.
|
||||
|
|
|
@ -845,9 +845,10 @@ nsContentSink::PrefetchHref(const nsAString &aHref,
|
|||
nsCOMPtr<nsIPrefetchService> prefetchService(do_GetService(NS_PREFETCHSERVICE_CONTRACTID));
|
||||
if (prefetchService) {
|
||||
// construct URI using document charset
|
||||
auto encoding = mDocument->GetDocumentCharacterSet();
|
||||
const nsACString &charset = mDocument->GetDocumentCharacterSet();
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
NS_NewURI(getter_AddRefs(uri), aHref, encoding,
|
||||
NS_NewURI(getter_AddRefs(uri), aHref,
|
||||
charset.IsEmpty() ? nullptr : PromiseFlatCString(charset).get(),
|
||||
mDocument->GetDocBaseURI());
|
||||
if (uri) {
|
||||
nsCOMPtr<nsIDOMNode> domNode = do_QueryInterface(aSource);
|
||||
|
@ -891,9 +892,10 @@ void
|
|||
nsContentSink::Preconnect(const nsAString& aHref, const nsAString& aCrossOrigin)
|
||||
{
|
||||
// construct URI using document charset
|
||||
auto encoding = mDocument->GetDocumentCharacterSet();
|
||||
const nsACString& charset = mDocument->GetDocumentCharacterSet();
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
NS_NewURI(getter_AddRefs(uri), aHref, encoding,
|
||||
NS_NewURI(getter_AddRefs(uri), aHref,
|
||||
charset.IsEmpty() ? nullptr : PromiseFlatCString(charset).get(),
|
||||
mDocument->GetDocBaseURI());
|
||||
|
||||
if (uri && mDocument) {
|
||||
|
|
|
@ -3158,12 +3158,9 @@ nsContentUtils::NewURIWithDocumentCharset(nsIURI** aResult,
|
|||
nsIDocument* aDocument,
|
||||
nsIURI* aBaseURI)
|
||||
{
|
||||
if (aDocument) {
|
||||
return NS_NewURI(aResult, aSpec,
|
||||
aDocument->GetDocumentCharacterSet(),
|
||||
aBaseURI, sIOService);
|
||||
}
|
||||
return NS_NewURI(aResult, aSpec, nullptr, aBaseURI, sIOService);
|
||||
return NS_NewURI(aResult, aSpec,
|
||||
aDocument ? aDocument->GetDocumentCharacterSet().get() : nullptr,
|
||||
aBaseURI, sIOService);
|
||||
}
|
||||
|
||||
// static
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
#include "nsDOMSerializer.h"
|
||||
|
||||
#include "mozilla/Encoding.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIDocumentEncoder.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
|
@ -72,7 +71,7 @@ SetUpEncoder(nsIDOMNode *aRoot, const nsACString& aCharset,
|
|||
if (charset.IsEmpty()) {
|
||||
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
|
||||
NS_ASSERTION(doc, "Need a document");
|
||||
doc->GetDocumentCharacterSet()->Name(charset);
|
||||
charset = doc->GetDocumentCharacterSet();
|
||||
}
|
||||
rv = encoder->SetCharset(charset);
|
||||
if (NS_FAILED(rv))
|
||||
|
|
|
@ -1287,7 +1287,7 @@ nsIDocument::nsIDocument()
|
|||
mBlockAllMixedContentPreloads(false),
|
||||
mUpgradeInsecureRequests(false),
|
||||
mUpgradeInsecurePreloads(false),
|
||||
mCharacterSet(WINDOWS_1252_ENCODING),
|
||||
mCharacterSet(NS_LITERAL_CSTRING("windows-1252")),
|
||||
mCharacterSetSource(0),
|
||||
mParentDocument(nullptr),
|
||||
mCachedRootElement(nullptr),
|
||||
|
@ -3670,14 +3670,13 @@ nsDocument::GetBaseTarget(nsAString &aBaseTarget)
|
|||
}
|
||||
|
||||
void
|
||||
nsDocument::SetDocumentCharacterSet(NotNull<const Encoding*> aEncoding)
|
||||
nsDocument::SetDocumentCharacterSet(const nsACString& aCharSetID)
|
||||
{
|
||||
if (mCharacterSet != aEncoding) {
|
||||
mCharacterSet = aEncoding;
|
||||
|
||||
nsAutoCString charsetID;
|
||||
aEncoding->Name(charsetID);
|
||||
NS_ConvertASCIItoUTF16 charset16(charsetID);
|
||||
// XXX it would be a good idea to assert the sanity of the argument,
|
||||
// but before we figure out what to do about non-Encoding Standard
|
||||
// encodings in the charset menu and in mailnews, assertions are futile.
|
||||
if (!mCharacterSet.Equals(aCharSetID)) {
|
||||
mCharacterSet = aCharSetID;
|
||||
|
||||
int32_t n = mCharSetObservers.Length();
|
||||
|
||||
|
@ -3685,7 +3684,7 @@ nsDocument::SetDocumentCharacterSet(NotNull<const Encoding*> aEncoding)
|
|||
nsIObserver* observer = mCharSetObservers.ElementAt(i);
|
||||
|
||||
observer->Observe(static_cast<nsIDocument *>(this), "charset",
|
||||
charset16.get());
|
||||
NS_ConvertASCIItoUTF16(aCharSetID).get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3842,7 +3841,7 @@ nsDocument::SetHeaderData(nsIAtom* aHeaderField, const nsAString& aData)
|
|||
void
|
||||
nsDocument::TryChannelCharset(nsIChannel *aChannel,
|
||||
int32_t& aCharsetSource,
|
||||
NotNull<const Encoding*>& aEncoding,
|
||||
nsACString& aCharset,
|
||||
nsHtml5TreeOpExecutor* aExecutor)
|
||||
{
|
||||
if (aChannel) {
|
||||
|
@ -3851,7 +3850,7 @@ nsDocument::TryChannelCharset(nsIChannel *aChannel,
|
|||
if (NS_SUCCEEDED(rv)) {
|
||||
const Encoding* preferred = Encoding::ForLabel(charsetVal);
|
||||
if (preferred) {
|
||||
aEncoding = WrapNotNull(preferred);
|
||||
preferred->Name(aCharset);
|
||||
aCharsetSource = kCharsetFromChannel;
|
||||
return;
|
||||
} else if (aExecutor && !charsetVal.IsEmpty()) {
|
||||
|
@ -6482,9 +6481,7 @@ nsDocument::GetCharacterSet(nsAString& aCharacterSet)
|
|||
void
|
||||
nsIDocument::GetCharacterSet(nsAString& aCharacterSet) const
|
||||
{
|
||||
nsAutoCString charset;
|
||||
GetDocumentCharacterSet()->Name(charset);
|
||||
CopyASCIItoUTF16(charset, aCharacterSet);
|
||||
CopyASCIItoUTF16(GetDocumentCharacterSet(), aCharacterSet);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -6581,7 +6578,9 @@ nsIDocument::LoadBindingDocument(const nsAString& aURI,
|
|||
ErrorResult& rv)
|
||||
{
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
rv = NS_NewURI(getter_AddRefs(uri), aURI, mCharacterSet, GetDocBaseURI());
|
||||
rv = NS_NewURI(getter_AddRefs(uri), aURI,
|
||||
mCharacterSet.get(),
|
||||
GetDocBaseURI());
|
||||
if (rv.Failed()) {
|
||||
return;
|
||||
}
|
||||
|
@ -9898,7 +9897,8 @@ nsDocument::ScrollToRef()
|
|||
// document's charset.
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
auto encoding = GetDocumentCharacterSet();
|
||||
const nsACString &docCharset = GetDocumentCharacterSet();
|
||||
const Encoding* encoding = Encoding::ForName(docCharset);
|
||||
|
||||
rv = encoding->DecodeWithoutBOMHandling(unescapedRef, ref);
|
||||
|
||||
|
|
|
@ -425,11 +425,10 @@ public:
|
|||
virtual void GetBaseTarget(nsAString &aBaseTarget) override;
|
||||
|
||||
/**
|
||||
* Set the document's character encoding. This will
|
||||
* Return a standard name for the document's character set. This will
|
||||
* trigger a startDocumentLoad if necessary to answer the question.
|
||||
*/
|
||||
virtual void
|
||||
SetDocumentCharacterSet(NotNull<const Encoding*> aEncoding) override;
|
||||
virtual void SetDocumentCharacterSet(const nsACString& aCharSetID) override;
|
||||
|
||||
/**
|
||||
* Add an observer that gets notified whenever the charset changes.
|
||||
|
@ -1050,7 +1049,7 @@ protected:
|
|||
|
||||
void TryChannelCharset(nsIChannel *aChannel,
|
||||
int32_t& aCharsetSource,
|
||||
NotNull<const Encoding*>& aEncoding,
|
||||
nsACString& aCharset,
|
||||
nsHtml5TreeOpExecutor* aExecutor);
|
||||
|
||||
// Call this before the document does something that will unbind all content.
|
||||
|
|
|
@ -272,15 +272,16 @@ nsFrameLoader::LoadFrame()
|
|||
}
|
||||
|
||||
nsCOMPtr<nsIURI> base_uri = mOwnerContent->GetBaseURI();
|
||||
auto encoding = doc->GetDocumentCharacterSet();
|
||||
const nsCString& doc_charset = doc->GetDocumentCharacterSet();
|
||||
const char *charset = doc_charset.IsEmpty() ? nullptr : doc_charset.get();
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
nsresult rv = NS_NewURI(getter_AddRefs(uri), src, encoding, base_uri);
|
||||
nsresult rv = NS_NewURI(getter_AddRefs(uri), src, charset, base_uri);
|
||||
|
||||
// If the URI was malformed, try to recover by loading about:blank.
|
||||
if (rv == NS_ERROR_MALFORMED_URI) {
|
||||
rv = NS_NewURI(getter_AddRefs(uri), NS_LITERAL_STRING("about:blank"),
|
||||
encoding, base_uri);
|
||||
charset, base_uri);
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
|
|
|
@ -13398,14 +13398,14 @@ nsGlobalWindow::SecurityCheckURL(const char *aURL)
|
|||
// used to actually kick off the load in nsWindowWatcher.cpp.
|
||||
nsCOMPtr<nsIDocument> doc = sourceWindow->GetDoc();
|
||||
nsIURI* baseURI = nullptr;
|
||||
auto encoding = UTF_8_ENCODING; // default to utf-8
|
||||
nsAutoCString charset(NS_LITERAL_CSTRING("UTF-8")); // default to utf-8
|
||||
if (doc) {
|
||||
baseURI = doc->GetDocBaseURI();
|
||||
encoding = doc->GetDocumentCharacterSet();
|
||||
charset = doc->GetDocumentCharacterSet();
|
||||
}
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
nsresult rv = NS_NewURI(getter_AddRefs(uri), nsDependentCString(aURL),
|
||||
encoding, baseURI);
|
||||
charset.get(), baseURI);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,6 @@
|
|||
#include "mozilla/CORSMode.h"
|
||||
#include "mozilla/dom/DispatcherTrait.h"
|
||||
#include "mozilla/LinkedList.h"
|
||||
#include "mozilla/NotNull.h"
|
||||
#include "mozilla/SegmentedVector.h"
|
||||
#include "mozilla/StyleBackendType.h"
|
||||
#include "mozilla/StyleSheet.h"
|
||||
|
@ -105,7 +104,6 @@ struct nsCSSSelectorList;
|
|||
namespace mozilla {
|
||||
class AbstractThread;
|
||||
class CSSStyleSheet;
|
||||
class Encoding;
|
||||
class ErrorResult;
|
||||
class EventStates;
|
||||
class PendingAnimationTracker;
|
||||
|
@ -213,10 +211,6 @@ class nsIDocument : public nsINode,
|
|||
{
|
||||
typedef mozilla::dom::GlobalObject GlobalObject;
|
||||
|
||||
protected:
|
||||
using Encoding = mozilla::Encoding;
|
||||
template <typename T> using NotNull = mozilla::NotNull<T>;
|
||||
|
||||
public:
|
||||
typedef mozilla::net::ReferrerPolicy ReferrerPolicyEnum;
|
||||
typedef mozilla::dom::Element Element;
|
||||
|
@ -510,15 +504,16 @@ public:
|
|||
/**
|
||||
* Return a standard name for the document's character set.
|
||||
*/
|
||||
NotNull<const Encoding*> GetDocumentCharacterSet() const
|
||||
const nsCString& GetDocumentCharacterSet() const
|
||||
{
|
||||
return mCharacterSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the document's character encoding.
|
||||
* Set the document's character encoding. |aCharSetID| should be canonical.
|
||||
* That is, callers are responsible for the charset alias resolution.
|
||||
*/
|
||||
virtual void SetDocumentCharacterSet(NotNull<const Encoding*> aEncoding) = 0;
|
||||
virtual void SetDocumentCharacterSet(const nsACString& aCharSetID) = 0;
|
||||
|
||||
int32_t GetDocumentCharacterSetSource() const
|
||||
{
|
||||
|
@ -3064,7 +3059,7 @@ protected:
|
|||
|
||||
mozilla::WeakPtr<nsDocShell> mDocumentContainer;
|
||||
|
||||
NotNull<const Encoding*> mCharacterSet;
|
||||
nsCString mCharacterSet;
|
||||
int32_t mCharacterSetSource;
|
||||
|
||||
// This is just a weak pointer; the parent document owns its children.
|
||||
|
|
|
@ -1128,12 +1128,12 @@ nsImageLoadingContent::StringToURI(const nsAString& aSpec,
|
|||
nsCOMPtr<nsIURI> baseURL = thisContent->GetBaseURI();
|
||||
|
||||
// (2) Get the charset
|
||||
auto encoding = aDocument->GetDocumentCharacterSet();
|
||||
const nsCString& charset = aDocument->GetDocumentCharacterSet();
|
||||
|
||||
// (3) Construct the silly thing
|
||||
return NS_NewURI(aURI,
|
||||
aSpec,
|
||||
encoding,
|
||||
charset.IsEmpty() ? nullptr : charset.get(),
|
||||
baseURL,
|
||||
nsContentUtils::GetIOService());
|
||||
}
|
||||
|
|
|
@ -33,10 +33,8 @@ nsReferencedElement::Reset(nsIContent* aFromContent, nsIURI* aURI,
|
|||
|
||||
nsAutoCString charset;
|
||||
aURI->GetOriginCharset(charset);
|
||||
auto encoding = Encoding::ForLabelNoReplacement(charset);
|
||||
if (!encoding) {
|
||||
encoding = UTF_8_ENCODING;
|
||||
}
|
||||
const Encoding* encoding = charset.IsEmpty() ?
|
||||
UTF_8_ENCODING : Encoding::ForName(charset);
|
||||
nsAutoString ref;
|
||||
nsresult rv = encoding->DecodeWithoutBOMHandling(refPart, ref);
|
||||
if (NS_FAILED(rv) || ref.IsEmpty()) {
|
||||
|
|
|
@ -36,33 +36,34 @@ FallbackEncoding* FallbackEncoding::sInstance = nullptr;
|
|||
bool FallbackEncoding::sGuessFallbackFromTopLevelDomain = true;
|
||||
|
||||
FallbackEncoding::FallbackEncoding()
|
||||
: mFallback(nullptr)
|
||||
{
|
||||
MOZ_ASSERT(!FallbackEncoding::sInstance,
|
||||
"Singleton already exists.");
|
||||
}
|
||||
|
||||
NotNull<const Encoding*>
|
||||
FallbackEncoding::Get()
|
||||
void
|
||||
FallbackEncoding::Get(nsACString& aFallback)
|
||||
{
|
||||
if (mFallback) {
|
||||
return WrapNotNull(mFallback);
|
||||
if (!mFallback.IsEmpty()) {
|
||||
aFallback = mFallback;
|
||||
return;
|
||||
}
|
||||
|
||||
const nsAdoptingCString& override =
|
||||
Preferences::GetCString("intl.charset.fallback.override");
|
||||
// Don't let the user break things by setting the override to unreasonable
|
||||
// values via about:config
|
||||
auto encoding = Encoding::ForLabel(override);
|
||||
const Encoding* encoding = Encoding::ForLabel(override);
|
||||
if (!encoding || !encoding->IsAsciiCompatible() ||
|
||||
encoding == UTF_8_ENCODING) {
|
||||
mFallback = nullptr;
|
||||
mFallback.Truncate();
|
||||
} else {
|
||||
mFallback = encoding;
|
||||
encoding->Name(mFallback);
|
||||
}
|
||||
|
||||
if (mFallback) {
|
||||
return WrapNotNull(mFallback);
|
||||
if (!mFallback.IsEmpty()) {
|
||||
aFallback = mFallback;
|
||||
return;
|
||||
}
|
||||
|
||||
nsAutoCString locale;
|
||||
|
@ -79,8 +80,9 @@ FallbackEncoding::Get()
|
|||
locale.EqualsLiteral("zh-hk") ||
|
||||
locale.EqualsLiteral("zh-mo") ||
|
||||
locale.EqualsLiteral("zh-hant")) {
|
||||
mFallback = BIG5_ENCODING;
|
||||
return WrapNotNull(mFallback);
|
||||
mFallback.AssignLiteral("Big5");
|
||||
aFallback = mFallback;
|
||||
return;
|
||||
}
|
||||
|
||||
// Throw away regions and other variants to accommodate weird stuff seen
|
||||
|
@ -90,23 +92,20 @@ FallbackEncoding::Get()
|
|||
locale.Truncate(index);
|
||||
}
|
||||
|
||||
nsAutoCString fallback;
|
||||
if (NS_FAILED(nsUConvPropertySearch::SearchPropertyValue(
|
||||
localesFallbacks, ArrayLength(localesFallbacks), locale, fallback))) {
|
||||
mFallback = WINDOWS_1252_ENCODING;
|
||||
} else {
|
||||
mFallback = Encoding::ForName(fallback);
|
||||
localesFallbacks, ArrayLength(localesFallbacks), locale, mFallback))) {
|
||||
mFallback.AssignLiteral("windows-1252");
|
||||
}
|
||||
|
||||
return WrapNotNull(mFallback);
|
||||
aFallback = mFallback;
|
||||
}
|
||||
|
||||
NotNull<const Encoding*>
|
||||
FallbackEncoding::FromLocale()
|
||||
void
|
||||
FallbackEncoding::FromLocale(nsACString& aFallback)
|
||||
{
|
||||
MOZ_ASSERT(FallbackEncoding::sInstance,
|
||||
"Using uninitialized fallback cache.");
|
||||
return FallbackEncoding::sInstance->Get();
|
||||
FallbackEncoding::sInstance->Get(aFallback);
|
||||
}
|
||||
|
||||
// PrefChangedFunc
|
||||
|
@ -170,15 +169,14 @@ FallbackEncoding::IsParticipatingTopLevelDomain(const nsACString& aTLD)
|
|||
dummy));
|
||||
}
|
||||
|
||||
NotNull<const Encoding*>
|
||||
FallbackEncoding::FromTopLevelDomain(const nsACString& aTLD)
|
||||
void
|
||||
FallbackEncoding::FromTopLevelDomain(const nsACString& aTLD,
|
||||
nsACString& aFallback)
|
||||
{
|
||||
nsAutoCString fallback;
|
||||
if (NS_FAILED(nsUConvPropertySearch::SearchPropertyValue(
|
||||
domainsFallbacks, ArrayLength(domainsFallbacks), aTLD, fallback))) {
|
||||
return WINDOWS_1252_ENCODING;
|
||||
domainsFallbacks, ArrayLength(domainsFallbacks), aTLD, aFallback))) {
|
||||
aFallback.AssignLiteral("windows-1252");
|
||||
}
|
||||
return Encoding::ForName(fallback);
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
|
|
|
@ -7,12 +7,10 @@
|
|||
#ifndef mozilla_dom_FallbackEncoding_h_
|
||||
#define mozilla_dom_FallbackEncoding_h_
|
||||
|
||||
#include "mozilla/NotNull.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsString.h"
|
||||
|
||||
namespace mozilla {
|
||||
class Encoding;
|
||||
namespace dom {
|
||||
|
||||
class FallbackEncoding : public nsIObserver
|
||||
|
@ -32,7 +30,7 @@ public:
|
|||
*
|
||||
* @param aFallback the outparam for the fallback encoding
|
||||
*/
|
||||
static NotNull<const Encoding*> FromLocale();
|
||||
static void FromLocale(nsACString& aFallback);
|
||||
|
||||
/**
|
||||
* Checks if it is appropriate to call FromTopLevelDomain() for a given TLD.
|
||||
|
@ -49,7 +47,7 @@ public:
|
|||
* @param aTLD the top-level domain (in Punycode)
|
||||
* @param aFallback the outparam for the fallback encoding
|
||||
*/
|
||||
static NotNull<const Encoding*> FromTopLevelDomain(const nsACString& aTLD);
|
||||
static void FromTopLevelDomain(const nsACString& aTLD, nsACString& aFallback);
|
||||
|
||||
// public API ends here!
|
||||
|
||||
|
@ -80,7 +78,7 @@ private:
|
|||
*/
|
||||
void Invalidate()
|
||||
{
|
||||
mFallback = nullptr;
|
||||
mFallback.Truncate();
|
||||
}
|
||||
|
||||
static void PrefChanged(const char*, void*);
|
||||
|
@ -89,9 +87,9 @@ private:
|
|||
* Gets the fallback encoding label.
|
||||
* @param aFallback the fallback encoding
|
||||
*/
|
||||
NotNull<const Encoding*> Get();
|
||||
void Get(nsACString& aFallback);
|
||||
|
||||
const Encoding* mFallback;
|
||||
nsCString mFallback;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
|
|
@ -887,7 +887,7 @@ GetSubmitEncoding(nsGenericHTMLElement* aForm)
|
|||
// Get the charset from document
|
||||
nsIDocument* doc = aForm->GetComposedDoc();
|
||||
if (doc) {
|
||||
return doc->GetDocumentCharacterSet();
|
||||
return Encoding::ForName(doc->GetDocumentCharacterSet());
|
||||
}
|
||||
return UTF_8_ENCODING;
|
||||
}
|
||||
|
|
|
@ -171,16 +171,17 @@ MediaDocument::StartDocumentLoad(const char* aCommand,
|
|||
// not being able to set the charset is not critical.
|
||||
NS_ENSURE_TRUE(docShell, NS_OK);
|
||||
|
||||
const Encoding* encoding;
|
||||
nsAutoCString charset;
|
||||
int32_t source;
|
||||
nsCOMPtr<nsIPrincipal> principal;
|
||||
// opening in a new tab
|
||||
docShell->GetParentCharset(encoding, &source, getter_AddRefs(principal));
|
||||
docShell->GetParentCharset(charset, &source, getter_AddRefs(principal));
|
||||
|
||||
if (encoding && encoding != UTF_8_ENCODING &&
|
||||
if (!charset.IsEmpty() &&
|
||||
!charset.EqualsLiteral("UTF-8") &&
|
||||
NodePrincipal()->Equals(principal)) {
|
||||
SetDocumentCharacterSetSource(source);
|
||||
SetDocumentCharacterSet(WrapNotNull(encoding));
|
||||
SetDocumentCharacterSet(charset);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
@ -298,14 +299,11 @@ MediaDocument::GetFileName(nsAString& aResult, nsIChannel* aChannel)
|
|||
// window or a new tab, in which case |originCharset| of |nsIURI| is not
|
||||
// reliable.
|
||||
if (mCharacterSetSource != kCharsetUninitialized) {
|
||||
mCharacterSet->Name(docCharset);
|
||||
docCharset = mCharacterSet;
|
||||
} else {
|
||||
// resort to |originCharset|
|
||||
url->GetOriginCharset(docCharset);
|
||||
auto encoding = Encoding::ForLabelNoReplacement(docCharset);
|
||||
if (encoding) {
|
||||
SetDocumentCharacterSet(WrapNotNull(encoding));
|
||||
}
|
||||
SetDocumentCharacterSet(docCharset);
|
||||
}
|
||||
|
||||
nsresult rv;
|
||||
|
|
|
@ -136,7 +136,7 @@ public:
|
|||
NS_IMETHOD WillResume(void) override;
|
||||
NS_IMETHOD SetParser(nsParserBase* aParser) override;
|
||||
virtual void FlushPendingNotifications(FlushType aType) override;
|
||||
virtual void SetDocumentCharset(NotNull<const Encoding*> aEncoding) override;
|
||||
NS_IMETHOD SetDocumentCharset(nsACString& aCharset) override;
|
||||
virtual nsISupports *GetTarget() override;
|
||||
virtual bool IsScriptExecuting() override;
|
||||
|
||||
|
@ -1087,10 +1087,11 @@ HTMLContentSink::FlushTags()
|
|||
return mCurrentContext ? mCurrentContext->FlushTags() : NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
HTMLContentSink::SetDocumentCharset(NotNull<const Encoding*> aEncoding)
|
||||
NS_IMETHODIMP
|
||||
HTMLContentSink::SetDocumentCharset(nsACString& aCharset)
|
||||
{
|
||||
MOZ_ASSERT_UNREACHABLE("<meta charset> case doesn't occur with about:blank");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsISupports *
|
||||
|
|
|
@ -164,12 +164,6 @@ IsAsciiCompatible(const nsACString& aPreferredName)
|
|||
aPreferredName.LowerCaseEqualsLiteral("x-imap4-modified-utf7"));
|
||||
}
|
||||
|
||||
static bool
|
||||
IsAsciiCompatible(const Encoding* aEncoding)
|
||||
{
|
||||
return aEncoding->IsAsciiCompatible() || aEncoding == ISO_2022_JP_ENCODING;
|
||||
}
|
||||
|
||||
nsresult
|
||||
NS_NewHTMLDocument(nsIDocument** aInstancePtrResult, bool aLoadedAsData)
|
||||
{
|
||||
|
@ -292,8 +286,7 @@ nsHTMLDocument::ResetToURI(nsIURI *aURI, nsILoadGroup *aLoadGroup,
|
|||
|
||||
void
|
||||
nsHTMLDocument::TryHintCharset(nsIContentViewer* aCv,
|
||||
int32_t& aCharsetSource,
|
||||
NotNull<const Encoding*>& aEncoding)
|
||||
int32_t& aCharsetSource, nsACString& aCharset)
|
||||
{
|
||||
if (aCv) {
|
||||
int32_t requestCharsetSource;
|
||||
|
@ -304,15 +297,13 @@ nsHTMLDocument::TryHintCharset(nsIContentViewer* aCv,
|
|||
rv = aCv->GetHintCharacterSet(requestCharset);
|
||||
aCv->SetHintCharacterSetSource((int32_t)(kCharsetUninitialized));
|
||||
|
||||
if (requestCharsetSource <= aCharsetSource)
|
||||
if(requestCharsetSource <= aCharsetSource)
|
||||
return;
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
auto encoding = Encoding::ForName(requestCharset);
|
||||
if (IsAsciiCompatible(encoding)) {
|
||||
aCharsetSource = requestCharsetSource;
|
||||
aEncoding = encoding;
|
||||
}
|
||||
if(NS_SUCCEEDED(rv) && IsAsciiCompatible(requestCharset)) {
|
||||
aCharsetSource = requestCharsetSource;
|
||||
aCharset = requestCharset;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -325,15 +316,15 @@ void
|
|||
nsHTMLDocument::TryUserForcedCharset(nsIContentViewer* aCv,
|
||||
nsIDocShell* aDocShell,
|
||||
int32_t& aCharsetSource,
|
||||
NotNull<const Encoding*>& aEncoding)
|
||||
nsACString& aCharset)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if(kCharsetFromUserForced <= aCharsetSource)
|
||||
return;
|
||||
|
||||
// mCharacterSet not updated yet for channel, so check aEncoding, too.
|
||||
if (WillIgnoreCharsetOverride() || !IsAsciiCompatible(aEncoding)) {
|
||||
// mCharacterSet not updated yet for channel, so check aCharset, too.
|
||||
if (WillIgnoreCharsetOverride() || !IsAsciiCompatible(aCharset)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -346,20 +337,21 @@ nsHTMLDocument::TryUserForcedCharset(nsIContentViewer* aCv,
|
|||
if(NS_SUCCEEDED(rv) &&
|
||||
!forceCharsetFromDocShell.IsEmpty() &&
|
||||
IsAsciiCompatible(forceCharsetFromDocShell)) {
|
||||
aEncoding = Encoding::ForName(forceCharsetFromDocShell);
|
||||
aCharset = forceCharsetFromDocShell;
|
||||
aCharsetSource = kCharsetFromUserForced;
|
||||
return;
|
||||
}
|
||||
|
||||
if (aDocShell) {
|
||||
// This is the Character Encoding menu code path in Firefox
|
||||
auto encoding = nsDocShell::Cast(aDocShell)->GetForcedCharset();
|
||||
nsAutoCString charset;
|
||||
rv = aDocShell->GetForcedCharset(charset);
|
||||
|
||||
if (encoding) {
|
||||
if (!IsAsciiCompatible(encoding)) {
|
||||
if (NS_SUCCEEDED(rv) && !charset.IsEmpty()) {
|
||||
if (!IsAsciiCompatible(charset)) {
|
||||
return;
|
||||
}
|
||||
aEncoding = WrapNotNull(encoding);
|
||||
aCharset = charset;
|
||||
aCharsetSource = kCharsetFromUserForced;
|
||||
aDocShell->SetForcedCharset(NS_LITERAL_CSTRING(""));
|
||||
}
|
||||
|
@ -369,7 +361,7 @@ nsHTMLDocument::TryUserForcedCharset(nsIContentViewer* aCv,
|
|||
void
|
||||
nsHTMLDocument::TryCacheCharset(nsICachingChannel* aCachingChannel,
|
||||
int32_t& aCharsetSource,
|
||||
NotNull<const Encoding*>& aEncoding)
|
||||
nsACString& aCharset)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
|
@ -397,14 +389,15 @@ nsHTMLDocument::TryCacheCharset(nsICachingChannel* aCachingChannel,
|
|||
if (!encoding->IsAsciiCompatible() && encoding != ISO_2022_JP_ENCODING) {
|
||||
return;
|
||||
}
|
||||
aEncoding = WrapNotNull(encoding);
|
||||
encoding->Name(cachedCharset);
|
||||
aCharset = cachedCharset;
|
||||
aCharsetSource = kCharsetFromCache;
|
||||
}
|
||||
|
||||
void
|
||||
nsHTMLDocument::TryParentCharset(nsIDocShell* aDocShell,
|
||||
int32_t& aCharsetSource,
|
||||
NotNull<const Encoding*>& aEncoding)
|
||||
nsACString& aCharset)
|
||||
{
|
||||
if (!aDocShell) {
|
||||
return;
|
||||
|
@ -414,22 +407,22 @@ nsHTMLDocument::TryParentCharset(nsIDocShell* aDocShell,
|
|||
}
|
||||
|
||||
int32_t parentSource;
|
||||
const Encoding* parentCharset;
|
||||
nsAutoCString parentCharset;
|
||||
nsCOMPtr<nsIPrincipal> parentPrincipal;
|
||||
aDocShell->GetParentCharset(parentCharset,
|
||||
&parentSource,
|
||||
getter_AddRefs(parentPrincipal));
|
||||
if (!parentCharset) {
|
||||
if (parentCharset.IsEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (kCharsetFromParentForced == parentSource ||
|
||||
kCharsetFromUserForced == parentSource) {
|
||||
if (WillIgnoreCharsetOverride() ||
|
||||
!IsAsciiCompatible(aEncoding) || // if channel said UTF-16
|
||||
!IsAsciiCompatible(aCharset) || // if channel said UTF-16
|
||||
!IsAsciiCompatible(parentCharset)) {
|
||||
return;
|
||||
}
|
||||
aEncoding = WrapNotNull(parentCharset);
|
||||
aCharset.Assign(parentCharset);
|
||||
aCharsetSource = kCharsetFromParentForced;
|
||||
return;
|
||||
}
|
||||
|
@ -445,14 +438,13 @@ nsHTMLDocument::TryParentCharset(nsIDocShell* aDocShell,
|
|||
return;
|
||||
}
|
||||
|
||||
aEncoding = WrapNotNull(parentCharset);
|
||||
aCharset.Assign(parentCharset);
|
||||
aCharsetSource = kCharsetFromParentFrame;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsHTMLDocument::TryTLD(int32_t& aCharsetSource,
|
||||
NotNull<const Encoding*>& aEncoding)
|
||||
nsHTMLDocument::TryTLD(int32_t& aCharsetSource, nsACString& aCharset)
|
||||
{
|
||||
if (aCharsetSource >= kCharsetFromTopLevelDomain) {
|
||||
return;
|
||||
|
@ -508,32 +500,29 @@ nsHTMLDocument::TryTLD(int32_t& aCharsetSource,
|
|||
return;
|
||||
}
|
||||
aCharsetSource = kCharsetFromTopLevelDomain;
|
||||
aEncoding = FallbackEncoding::FromTopLevelDomain(tld);
|
||||
FallbackEncoding::FromTopLevelDomain(tld, aCharset);
|
||||
}
|
||||
|
||||
void
|
||||
nsHTMLDocument::TryFallback(int32_t& aCharsetSource,
|
||||
NotNull<const Encoding*>& aEncoding)
|
||||
nsHTMLDocument::TryFallback(int32_t& aCharsetSource, nsACString& aCharset)
|
||||
{
|
||||
if (kCharsetFromFallback <= aCharsetSource)
|
||||
return;
|
||||
|
||||
aCharsetSource = kCharsetFromFallback;
|
||||
aEncoding = FallbackEncoding::FromLocale();
|
||||
FallbackEncoding::FromLocale(aCharset);
|
||||
}
|
||||
|
||||
void
|
||||
nsHTMLDocument::SetDocumentCharacterSet(NotNull<const Encoding*> aEncoding)
|
||||
nsHTMLDocument::SetDocumentCharacterSet(const nsACString& aCharSetID)
|
||||
{
|
||||
nsDocument::SetDocumentCharacterSet(aEncoding);
|
||||
nsDocument::SetDocumentCharacterSet(aCharSetID);
|
||||
// Make sure to stash this charset on our channel as needed if it's a wyciwyg
|
||||
// channel.
|
||||
nsCOMPtr<nsIWyciwygChannel> wyciwygChannel = do_QueryInterface(mChannel);
|
||||
if (wyciwygChannel) {
|
||||
nsAutoCString charset;
|
||||
aEncoding->Name(charset);
|
||||
wyciwygChannel->SetCharsetAndSource(GetDocumentCharacterSetSource(),
|
||||
charset);
|
||||
aCharSetID);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -682,12 +671,12 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
|
|||
|
||||
// These are the charset source and charset for our document
|
||||
int32_t charsetSource;
|
||||
auto encoding = UTF_8_ENCODING;
|
||||
nsAutoCString charset;
|
||||
|
||||
// These are the charset source and charset for the parser. This can differ
|
||||
// from that for the document if the channel is a wyciwyg channel.
|
||||
int32_t parserCharsetSource;
|
||||
auto parserCharset = UTF_8_ENCODING;
|
||||
nsAutoCString parserCharset;
|
||||
|
||||
nsCOMPtr<nsIWyciwygChannel> wyciwygChannel;
|
||||
|
||||
|
@ -704,13 +693,16 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
|
|||
|
||||
if (forceUtf8) {
|
||||
charsetSource = kCharsetFromUtf8OnlyMime;
|
||||
charset.AssignLiteral("UTF-8");
|
||||
parserCharsetSource = charsetSource;
|
||||
parserCharset = charset;
|
||||
} else if (!IsHTMLDocument() || !docShell) { // no docshell for text/html XHR
|
||||
charsetSource = IsHTMLDocument() ? kCharsetFromFallback
|
||||
: kCharsetFromDocTypeDefault;
|
||||
TryChannelCharset(aChannel, charsetSource, encoding, executor);
|
||||
parserCharset = encoding;
|
||||
charset.AssignLiteral("UTF-8");
|
||||
TryChannelCharset(aChannel, charsetSource, charset, executor);
|
||||
parserCharsetSource = charsetSource;
|
||||
parserCharset = charset;
|
||||
} else {
|
||||
NS_ASSERTION(docShell, "Unexpected null value");
|
||||
|
||||
|
@ -734,24 +726,24 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
|
|||
// content to a UTF-16 site such that the byte have a dangerous
|
||||
// interpretation as ASCII and the user can be lured to using the
|
||||
// charset menu.
|
||||
TryChannelCharset(aChannel, charsetSource, encoding, executor);
|
||||
TryChannelCharset(aChannel, charsetSource, charset, executor);
|
||||
}
|
||||
|
||||
TryUserForcedCharset(cv, docShell, charsetSource, encoding);
|
||||
TryUserForcedCharset(cv, docShell, charsetSource, charset);
|
||||
|
||||
TryHintCharset(cv, charsetSource, encoding); // XXX mailnews-only
|
||||
TryParentCharset(docShell, charsetSource, encoding);
|
||||
TryHintCharset(cv, charsetSource, charset); // XXX mailnews-only
|
||||
TryParentCharset(docShell, charsetSource, charset);
|
||||
|
||||
if (cachingChan && !urlSpec.IsEmpty()) {
|
||||
TryCacheCharset(cachingChan, charsetSource, encoding);
|
||||
TryCacheCharset(cachingChan, charsetSource, charset);
|
||||
}
|
||||
|
||||
TryTLD(charsetSource, encoding);
|
||||
TryFallback(charsetSource, encoding);
|
||||
TryTLD(charsetSource, charset);
|
||||
TryFallback(charsetSource, charset);
|
||||
|
||||
if (wyciwygChannel) {
|
||||
// We know for sure that the parser needs to be using UTF16.
|
||||
parserCharset = UTF_16LE_ENCODING;
|
||||
parserCharset = "UTF-16LE";
|
||||
parserCharsetSource = charsetSource < kCharsetFromChannel ?
|
||||
kCharsetFromChannel : charsetSource;
|
||||
|
||||
|
@ -760,34 +752,27 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
|
|||
rv = wyciwygChannel->GetCharsetAndSource(&cachedSource, cachedCharset);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
if (cachedSource > charsetSource) {
|
||||
auto cachedEncoding = Encoding::ForLabel(cachedCharset);
|
||||
if (!cachedEncoding && cachedCharset.EqualsLiteral("replacement")) {
|
||||
cachedEncoding = REPLACEMENT_ENCODING;
|
||||
}
|
||||
if (cachedEncoding) {
|
||||
charsetSource = cachedSource;
|
||||
encoding = WrapNotNull(cachedEncoding);
|
||||
}
|
||||
charsetSource = cachedSource;
|
||||
charset = cachedCharset;
|
||||
}
|
||||
} else {
|
||||
// Don't propagate this error.
|
||||
rv = NS_OK;
|
||||
}
|
||||
|
||||
} else {
|
||||
parserCharset = encoding;
|
||||
parserCharset = charset;
|
||||
parserCharsetSource = charsetSource;
|
||||
}
|
||||
}
|
||||
|
||||
SetDocumentCharacterSetSource(charsetSource);
|
||||
SetDocumentCharacterSet(encoding);
|
||||
SetDocumentCharacterSet(charset);
|
||||
|
||||
if (cachingChan) {
|
||||
NS_ASSERTION(encoding == parserCharset,
|
||||
NS_ASSERTION(charset == parserCharset,
|
||||
"How did those end up different here? wyciwyg channels are "
|
||||
"not nsICachingChannel");
|
||||
nsAutoCString charset;
|
||||
encoding->Name(charset);
|
||||
rv = cachingChan->SetCacheTokenCachedCharset(charset);
|
||||
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "cannot SetMetaDataElement");
|
||||
rv = NS_OK; // don't propagate error
|
||||
|
@ -800,7 +785,7 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
|
|||
|
||||
#ifdef DEBUG_charset
|
||||
printf(" charset = %s source %d\n",
|
||||
charset.get(), charsetSource);
|
||||
charset.get(), charsetSource);
|
||||
#endif
|
||||
mParser->SetDocumentCharset(parserCharset, parserCharsetSource);
|
||||
mParser->SetCommand(aCommand);
|
||||
|
@ -2431,9 +2416,8 @@ nsHTMLDocument::CreateAndAddWyciwygChannel(void)
|
|||
// Note: we want to treat this like a "previous document" hint so that,
|
||||
// e.g. a <meta> tag in the document.write content can override it.
|
||||
SetDocumentCharacterSetSource(kCharsetFromHintPrevDoc);
|
||||
nsAutoCString charset;
|
||||
GetDocumentCharacterSet()->Name(charset);
|
||||
mWyciwygChannel->SetCharsetAndSource(kCharsetFromHintPrevDoc, charset);
|
||||
mWyciwygChannel->SetCharsetAndSource(kCharsetFromHintPrevDoc,
|
||||
GetDocumentCharacterSet());
|
||||
|
||||
// Inherit load flags from the original document's channel
|
||||
channel->SetLoadFlags(mLoadFlags);
|
||||
|
@ -3758,8 +3742,7 @@ nsHTMLDocument::WillIgnoreCharsetOverride()
|
|||
if (mCharacterSetSource >= kCharsetFromByteOrderMark) {
|
||||
return true;
|
||||
}
|
||||
if (!mCharacterSet->IsAsciiCompatible() &&
|
||||
mCharacterSet != ISO_2022_JP_ENCODING) {
|
||||
if (!IsAsciiCompatible(mCharacterSet)) {
|
||||
return true;
|
||||
}
|
||||
nsCOMPtr<nsIWyciwygChannel> wyciwyg = do_QueryInterface(mChannel);
|
||||
|
|
|
@ -321,24 +321,21 @@ protected:
|
|||
|
||||
static void TryHintCharset(nsIContentViewer* aContentViewer,
|
||||
int32_t& aCharsetSource,
|
||||
NotNull<const Encoding*>& aEncoding);
|
||||
nsACString& aCharset);
|
||||
void TryUserForcedCharset(nsIContentViewer* aCv,
|
||||
nsIDocShell* aDocShell,
|
||||
int32_t& aCharsetSource,
|
||||
NotNull<const Encoding*>& aEncoding);
|
||||
nsACString& aCharset);
|
||||
static void TryCacheCharset(nsICachingChannel* aCachingChannel,
|
||||
int32_t& aCharsetSource,
|
||||
NotNull<const Encoding*>& aEncoding);
|
||||
int32_t& aCharsetSource,
|
||||
nsACString& aCharset);
|
||||
void TryParentCharset(nsIDocShell* aDocShell,
|
||||
int32_t& charsetSource,
|
||||
NotNull<const Encoding*>& aEncoding);
|
||||
void TryTLD(int32_t& aCharsetSource, NotNull<const Encoding*>& aCharset);
|
||||
static void TryFallback(int32_t& aCharsetSource,
|
||||
NotNull<const Encoding*>& aEncoding);
|
||||
int32_t& charsetSource, nsACString& aCharset);
|
||||
void TryTLD(int32_t& aCharsetSource, nsACString& aCharset);
|
||||
static void TryFallback(int32_t& aCharsetSource, nsACString& aCharset);
|
||||
|
||||
// Override so we can munge the charset on our wyciwyg channel as needed.
|
||||
virtual void
|
||||
SetDocumentCharacterSet(NotNull<const Encoding*> aEncoding) override;
|
||||
virtual void SetDocumentCharacterSet(const nsACString& aCharSetID) override;
|
||||
|
||||
// Tracks if we are currently processing any document.write calls (either
|
||||
// implicit or explicit). Note that if a write call writes out something which
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
#include "mozilla/dom/Notification.h"
|
||||
|
||||
#include "mozilla/Encoding.h"
|
||||
#include "mozilla/JSONWriter.h"
|
||||
#include "mozilla/Move.h"
|
||||
#include "mozilla/OwningNonNull.h"
|
||||
|
@ -1923,7 +1922,7 @@ Notification::ResolveIconAndSoundURL(nsString& iconUrl, nsString& soundUrl)
|
|||
// the API base URL and no override encoding. So we've to use UTF-8 on
|
||||
// workers, but for backwards compat keeping it document charset on main
|
||||
// thread.
|
||||
auto encoding = UTF_8_ENCODING;
|
||||
const char* charset = "UTF-8";
|
||||
|
||||
if (mWorkerPrivate) {
|
||||
baseUri = mWorkerPrivate->GetBaseURI();
|
||||
|
@ -1931,7 +1930,7 @@ Notification::ResolveIconAndSoundURL(nsString& iconUrl, nsString& soundUrl)
|
|||
nsIDocument* doc = GetOwner() ? GetOwner()->GetExtantDoc() : nullptr;
|
||||
if (doc) {
|
||||
baseUri = doc->GetBaseURI();
|
||||
encoding = doc->GetDocumentCharacterSet();
|
||||
charset = doc->GetDocumentCharacterSet().get();
|
||||
} else {
|
||||
NS_WARNING("No document found for main thread notification!");
|
||||
return NS_ERROR_FAILURE;
|
||||
|
@ -1941,7 +1940,7 @@ Notification::ResolveIconAndSoundURL(nsString& iconUrl, nsString& soundUrl)
|
|||
if (baseUri) {
|
||||
if (mIconUrl.Length() > 0) {
|
||||
nsCOMPtr<nsIURI> srcUri;
|
||||
rv = NS_NewURI(getter_AddRefs(srcUri), mIconUrl, encoding, baseUri);
|
||||
rv = NS_NewURI(getter_AddRefs(srcUri), mIconUrl, charset, baseUri);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsAutoCString src;
|
||||
srcUri->GetSpec(src);
|
||||
|
@ -1950,7 +1949,7 @@ Notification::ResolveIconAndSoundURL(nsString& iconUrl, nsString& soundUrl)
|
|||
}
|
||||
if (mBehavior.mSoundFile.Length() > 0) {
|
||||
nsCOMPtr<nsIURI> srcUri;
|
||||
rv = NS_NewURI(getter_AddRefs(srcUri), mBehavior.mSoundFile, encoding, baseUri);
|
||||
rv = NS_NewURI(getter_AddRefs(srcUri), mBehavior.mSoundFile, charset, baseUri);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsAutoCString src;
|
||||
srcUri->GetSpec(src);
|
||||
|
|
|
@ -47,13 +47,11 @@ GetAbsoluteURL(const nsAString& aUrl,
|
|||
nsAString& aAbsoluteUrl)
|
||||
{
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
nsresult rv;
|
||||
if (aDocument) {
|
||||
rv = NS_NewURI(getter_AddRefs(uri), aUrl,
|
||||
aDocument->GetDocumentCharacterSet(), aBaseUri);
|
||||
} else {
|
||||
rv = NS_NewURI(getter_AddRefs(uri), aUrl, nullptr, aBaseUri);
|
||||
}
|
||||
nsresult rv = NS_NewURI(getter_AddRefs(uri),
|
||||
aUrl,
|
||||
aDocument ? aDocument->GetDocumentCharacterSet().get()
|
||||
: nullptr,
|
||||
aBaseUri);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
|
|
|
@ -228,7 +228,8 @@ ScriptLoadHandler::EnsureDecoder(nsIIncrementalStreamLoader* aLoader,
|
|||
|
||||
// Get the charset from the charset of the document.
|
||||
if (mScriptLoader->mDocument) {
|
||||
encoding = mScriptLoader->mDocument->GetDocumentCharacterSet();
|
||||
encoding =
|
||||
Encoding::ForName(mScriptLoader->mDocument->GetDocumentCharacterSet());
|
||||
mDecoder = encoding->NewDecoderWithoutBOMHandling();
|
||||
encoding->Name(oCharset);
|
||||
return true;
|
||||
|
|
|
@ -2564,7 +2564,7 @@ ScriptLoader::ConvertToUTF16(nsIChannel* aChannel, const uint8_t* aData,
|
|||
}
|
||||
|
||||
if (!unicodeDecoder && aDocument) {
|
||||
unicodeDecoder = aDocument->GetDocumentCharacterSet()
|
||||
unicodeDecoder = Encoding::ForName(aDocument->GetDocumentCharacterSet())
|
||||
->NewDecoderWithoutBOMHandling();
|
||||
}
|
||||
|
||||
|
|
|
@ -137,7 +137,7 @@ WebBrowserPersistLocalDocument::GetContentType(nsACString& aContentType)
|
|||
NS_IMETHODIMP
|
||||
WebBrowserPersistLocalDocument::GetCharacterSet(nsACString& aCharSet)
|
||||
{
|
||||
GetCharacterSet()->Name(aCharSet);
|
||||
aCharSet = GetCharacterSet();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -236,7 +236,7 @@ WebBrowserPersistLocalDocument::GetHistory()
|
|||
return history.forget();
|
||||
}
|
||||
|
||||
NotNull<const Encoding*>
|
||||
const nsCString&
|
||||
WebBrowserPersistLocalDocument::GetCharacterSet() const
|
||||
{
|
||||
return mDocument->GetDocumentCharacterSet();
|
||||
|
@ -397,7 +397,7 @@ ResourceReader::OnWalkURI(const nsACString& aURISpec)
|
|||
|
||||
rv = NS_NewURI(getter_AddRefs(uri),
|
||||
aURISpec,
|
||||
mParent->GetCharacterSet(),
|
||||
mParent->GetCharacterSet().get(),
|
||||
mCurrentBaseURI);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return OnWalkURI(uri);
|
||||
|
@ -552,7 +552,7 @@ ResourceReader::OnWalkDOMNode(nsIDOMNode* aNode)
|
|||
if (!codebase.IsEmpty()) {
|
||||
nsCOMPtr<nsIURI> baseURI;
|
||||
rv = NS_NewURI(getter_AddRefs(baseURI), codebase,
|
||||
mParent->GetCharacterSet(), mCurrentBaseURI);
|
||||
mParent->GetCharacterSet().get(), mCurrentBaseURI);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (baseURI) {
|
||||
mCurrentBaseURI = baseURI;
|
||||
|
@ -717,7 +717,7 @@ PersistNodeFixup::FixupURI(nsAString &aURI)
|
|||
// get the current location of the file (absolutized)
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
nsresult rv = NS_NewURI(getter_AddRefs(uri), aURI,
|
||||
mParent->GetCharacterSet(), mCurrentBaseURI);
|
||||
mParent->GetCharacterSet().get(), mCurrentBaseURI);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsAutoCString spec;
|
||||
rv = uri->GetSpec(spec);
|
||||
|
@ -804,7 +804,7 @@ PersistNodeFixup::FixupAnchor(nsIDOMNode *aNode)
|
|||
// Make a new URI to replace the current one
|
||||
nsCOMPtr<nsIURI> newURI;
|
||||
rv = NS_NewURI(getter_AddRefs(newURI), oldCValue,
|
||||
mParent->GetCharacterSet(), relativeURI);
|
||||
mParent->GetCharacterSet().get(), relativeURI);
|
||||
if (NS_SUCCEEDED(rv) && newURI) {
|
||||
newURI->SetUserPass(EmptyCString());
|
||||
nsAutoCString uriSpec;
|
||||
|
@ -1130,7 +1130,7 @@ PersistNodeFixup::FixupNode(nsIDOMNode *aNodeIn,
|
|||
if (!codebase.IsEmpty()) {
|
||||
nsCOMPtr<nsIURI> baseURI;
|
||||
NS_NewURI(getter_AddRefs(baseURI), codebase,
|
||||
mParent->GetCharacterSet(), mCurrentBaseURI);
|
||||
mParent->GetCharacterSet().get(), mCurrentBaseURI);
|
||||
if (baseURI) {
|
||||
mCurrentBaseURI = baseURI;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ class WebBrowserPersistLocalDocument final
|
|||
public:
|
||||
explicit WebBrowserPersistLocalDocument(nsIDocument* aDocument);
|
||||
|
||||
NotNull<const Encoding*> GetCharacterSet() const;
|
||||
const nsCString& GetCharacterSet() const;
|
||||
uint32_t GetPersistFlags() const;
|
||||
already_AddRefed<nsIURI> GetBaseURI() const;
|
||||
|
||||
|
|
|
@ -1632,7 +1632,7 @@ nsXBLPrototypeBinding::ResolveBaseBinding()
|
|||
mBinding->UnsetAttr(kNameSpaceID_None, nsGkAtoms::display, false);
|
||||
|
||||
return NS_NewURI(getter_AddRefs(mBaseBindingURI), value,
|
||||
doc->GetDocumentCharacterSet(),
|
||||
doc->GetDocumentCharacterSet().get(),
|
||||
doc->GetDocBaseURI());
|
||||
}
|
||||
|
||||
|
|
|
@ -113,7 +113,7 @@ nsXBLResourceLoader::LoadResources(nsIContent* aBoundElement)
|
|||
continue;
|
||||
|
||||
if (NS_FAILED(NS_NewURI(getter_AddRefs(url), curr->mSrc,
|
||||
doc->GetDocumentCharacterSet(), docURL)))
|
||||
doc->GetDocumentCharacterSet().get(), docURL)))
|
||||
continue;
|
||||
|
||||
if (curr->mType == nsGkAtoms::image) {
|
||||
|
|
|
@ -492,7 +492,7 @@ XMLHttpRequestMainThread::GetResponseXML(ErrorResult& aRv)
|
|||
nsresult
|
||||
XMLHttpRequestMainThread::DetectCharset()
|
||||
{
|
||||
mResponseCharset = nullptr;
|
||||
mResponseCharset.Truncate();
|
||||
mDecoder = nullptr;
|
||||
|
||||
if (mResponseType != XMLHttpRequestResponseType::_empty &&
|
||||
|
@ -519,7 +519,7 @@ XMLHttpRequestMainThread::DetectCharset()
|
|||
encoding = UTF_8_ENCODING;
|
||||
}
|
||||
|
||||
mResponseCharset = encoding;
|
||||
encoding->Name(mResponseCharset);
|
||||
mDecoder = encoding->NewDecoderWithBOMRemoval();
|
||||
|
||||
return NS_OK;
|
||||
|
@ -2433,7 +2433,7 @@ XMLHttpRequestMainThread::MatchCharsetAndDecoderToResponseDocument()
|
|||
mResponseCharset = mResponseXML->GetDocumentCharacterSet();
|
||||
TruncateResponseText();
|
||||
mResponseBodyDecodedPos = 0;
|
||||
mDecoder = mResponseCharset->NewDecoderWithBOMRemoval();
|
||||
mDecoder = Encoding::ForName(mResponseCharset)->NewDecoderWithBOMRemoval();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -708,7 +708,7 @@ protected:
|
|||
// part of the surrogate.
|
||||
mozilla::UniquePtr<mozilla::Decoder> mDecoder;
|
||||
|
||||
const Encoding* mResponseCharset;
|
||||
nsCString mResponseCharset;
|
||||
|
||||
void MatchCharsetAndDecoderToResponseDocument();
|
||||
|
||||
|
|
|
@ -151,7 +151,7 @@ NS_NewDOMDocument(nsIDOMDocument** aInstancePtrResult,
|
|||
|
||||
// XMLDocuments and documents "created in memory" get to be UTF-8 by default,
|
||||
// unlike the legacy HTML mess
|
||||
doc->SetDocumentCharacterSet(UTF_8_ENCODING);
|
||||
doc->SetDocumentCharacterSet(NS_LITERAL_CSTRING("UTF-8"));
|
||||
|
||||
if (aDoctype) {
|
||||
nsCOMPtr<nsINode> doctypeAsNode = do_QueryInterface(aDoctype);
|
||||
|
@ -322,7 +322,7 @@ XMLDocument::Load(const nsAString& aUrl, CallerType aCallerType,
|
|||
|
||||
if (callingDoc) {
|
||||
baseURI = callingDoc->GetDocBaseURI();
|
||||
callingDoc->GetDocumentCharacterSet()->Name(charset);
|
||||
charset = callingDoc->GetDocumentCharacterSet();
|
||||
}
|
||||
|
||||
// Create a new URI
|
||||
|
@ -530,8 +530,8 @@ XMLDocument::StartDocumentLoad(const char* aCommand,
|
|||
|
||||
|
||||
int32_t charsetSource = kCharsetFromDocTypeDefault;
|
||||
NotNull<const Encoding*> encoding = UTF_8_ENCODING;
|
||||
TryChannelCharset(aChannel, charsetSource, encoding, nullptr);
|
||||
nsAutoCString charset(NS_LITERAL_CSTRING("UTF-8"));
|
||||
TryChannelCharset(aChannel, charsetSource, charset, nullptr);
|
||||
|
||||
nsCOMPtr<nsIURI> aUrl;
|
||||
rv = aChannel->GetURI(getter_AddRefs(aUrl));
|
||||
|
@ -565,8 +565,8 @@ XMLDocument::StartDocumentLoad(const char* aCommand,
|
|||
NS_ASSERTION(mChannel, "How can we not have a channel here?");
|
||||
mChannelIsPending = true;
|
||||
|
||||
SetDocumentCharacterSet(encoding);
|
||||
mParser->SetDocumentCharset(encoding, charsetSource);
|
||||
SetDocumentCharacterSet(charset);
|
||||
mParser->SetDocumentCharset(charset, charsetSource);
|
||||
mParser->SetCommand(aCommand);
|
||||
mParser->SetContentSink(sink);
|
||||
mParser->Parse(aUrl, nullptr, (void *)this);
|
||||
|
|
|
@ -114,14 +114,15 @@ XMLStylesheetProcessingInstruction::GetStyleSheetURL(bool* aIsInline)
|
|||
}
|
||||
|
||||
nsIURI *baseURL;
|
||||
nsAutoCString charset;
|
||||
nsIDocument *document = OwnerDoc();
|
||||
baseURL = mOverriddenBaseURI ?
|
||||
mOverriddenBaseURI.get() :
|
||||
document->GetDocBaseURI();
|
||||
auto encoding = document->GetDocumentCharacterSet();
|
||||
charset = document->GetDocumentCharacterSet();
|
||||
|
||||
nsCOMPtr<nsIURI> aURI;
|
||||
NS_NewURI(getter_AddRefs(aURI), href, encoding, baseURL);
|
||||
NS_NewURI(getter_AddRefs(aURI), href, charset.get(), baseURL);
|
||||
return aURI.forget();
|
||||
}
|
||||
|
||||
|
|
|
@ -731,12 +731,14 @@ nsXMLContentSink::ProcessStyleLink(nsIContent* aElement,
|
|||
return rv;
|
||||
}
|
||||
|
||||
void
|
||||
nsXMLContentSink::SetDocumentCharset(NotNull<const Encoding*> aEncoding)
|
||||
NS_IMETHODIMP
|
||||
nsXMLContentSink::SetDocumentCharset(nsACString& aCharset)
|
||||
{
|
||||
if (mDocument) {
|
||||
mDocument->SetDocumentCharacterSet(aEncoding);
|
||||
mDocument->SetDocumentCharacterSet(aCharset);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsISupports *
|
||||
|
|
|
@ -70,7 +70,7 @@ public:
|
|||
NS_IMETHOD WillResume(void) override;
|
||||
NS_IMETHOD SetParser(nsParserBase* aParser) override;
|
||||
virtual void FlushPendingNotifications(mozilla::FlushType aType) override;
|
||||
virtual void SetDocumentCharset(NotNull<const Encoding*> aEncoding) override;
|
||||
NS_IMETHOD SetDocumentCharset(nsACString& aCharset) override;
|
||||
virtual nsISupports *GetTarget() override;
|
||||
virtual bool IsScriptExecuting() override;
|
||||
virtual void ContinueInterruptedParsingAsync() override;
|
||||
|
|
|
@ -62,7 +62,7 @@ public:
|
|||
// nsIContentSink
|
||||
NS_IMETHOD WillBuildModel(nsDTDMode aDTDMode) override;
|
||||
NS_IMETHOD DidBuildModel(bool aTerminated) override;
|
||||
virtual void SetDocumentCharset(NotNull<const Encoding*> aEncoding) override;
|
||||
NS_IMETHOD SetDocumentCharset(nsACString& aCharset) override;
|
||||
virtual nsISupports* GetTarget() override;
|
||||
NS_IMETHOD DidProcessATokenImpl();
|
||||
|
||||
|
@ -173,11 +173,11 @@ nsXMLFragmentContentSink::DidBuildModel(bool aTerminated)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsXMLFragmentContentSink::SetDocumentCharset(
|
||||
NotNull<const Encoding*> aEncoding)
|
||||
NS_IMETHODIMP
|
||||
nsXMLFragmentContentSink::SetDocumentCharset(nsACString& aCharset)
|
||||
{
|
||||
NS_NOTREACHED("fragments shouldn't set charset");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsISupports *
|
||||
|
|
|
@ -84,8 +84,7 @@ public:
|
|||
NS_IMETHOD WillResume(void) override { return NS_OK; }
|
||||
NS_IMETHOD SetParser(nsParserBase* aParser) override { return NS_OK; }
|
||||
virtual void FlushPendingNotifications(mozilla::FlushType aType) override { }
|
||||
virtual void SetDocumentCharset(NotNull<const Encoding*> aEncoding)
|
||||
override { }
|
||||
NS_IMETHOD SetDocumentCharset(nsACString& aCharset) override { return NS_OK; }
|
||||
virtual nsISupports *GetTarget() override { return nullptr; }
|
||||
|
||||
private:
|
||||
|
@ -270,7 +269,9 @@ txStylesheetSink::OnStartRequest(nsIRequest *aRequest, nsISupports *aContext)
|
|||
encoding = UTF_8_ENCODING;
|
||||
}
|
||||
|
||||
mParser->SetDocumentCharset(WrapNotNull(encoding), charsetSource);
|
||||
nsAutoCString charset;
|
||||
encoding->Name(charset);
|
||||
mParser->SetDocumentCharset(charset, charsetSource);
|
||||
|
||||
nsAutoCString contentType;
|
||||
channel->GetContentType(contentType);
|
||||
|
|
|
@ -163,7 +163,9 @@ txMozillaTextOutput::createResultDocument(nsIDOMDocument* aSourceDocument,
|
|||
const Encoding* encoding = Encoding::ForLabel(mOutputFormat.mEncoding);
|
||||
if (encoding) {
|
||||
mDocument->SetDocumentCharacterSetSource(kCharsetFromOtherComponent);
|
||||
mDocument->SetDocumentCharacterSet(WrapNotNull(encoding));
|
||||
nsAutoCString canonicalCharset;
|
||||
encoding->Name(canonicalCharset);
|
||||
mDocument->SetDocumentCharacterSet(canonicalCharset);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -823,7 +823,9 @@ txMozillaXMLOutput::createResultDocument(const nsAString& aName, int32_t aNsID,
|
|||
const Encoding* encoding = Encoding::ForLabel(mOutputFormat.mEncoding);
|
||||
if (encoding) {
|
||||
mDocument->SetDocumentCharacterSetSource(kCharsetFromOtherComponent);
|
||||
mDocument->SetDocumentCharacterSet(WrapNotNull(encoding));
|
||||
nsAutoCString canonicalCharset;
|
||||
encoding->Name(canonicalCharset);
|
||||
mDocument->SetDocumentCharacterSet(canonicalCharset);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -213,7 +213,7 @@ XULDocument::XULDocument(void)
|
|||
mHandlingDelayedBroadcasters(false)
|
||||
{
|
||||
// Override the default in nsDocument
|
||||
mCharacterSet = UTF_8_ENCODING;
|
||||
mCharacterSet.AssignLiteral("UTF-8");
|
||||
|
||||
mDefaultElementType = kNameSpaceID_XUL;
|
||||
mType = eXUL;
|
||||
|
@ -2021,7 +2021,7 @@ XULDocument::PrepareToLoadPrototype(nsIURI* aURI, const char* aCommand,
|
|||
parser->SetCommand(nsCRT::strcmp(aCommand, "view-source") ? eViewNormal :
|
||||
eViewSource);
|
||||
|
||||
parser->SetDocumentCharset(UTF_8_ENCODING,
|
||||
parser->SetDocumentCharset(NS_LITERAL_CSTRING("UTF-8"),
|
||||
kCharsetFromDocTypeDefault);
|
||||
parser->SetContentSink(sink); // grabs a reference to the parser
|
||||
|
||||
|
|
|
@ -256,13 +256,15 @@ XULContentSinkImpl::SetParser(nsParserBase* aParser)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
XULContentSinkImpl::SetDocumentCharset(NotNull<const Encoding*> aEncoding)
|
||||
NS_IMETHODIMP
|
||||
XULContentSinkImpl::SetDocumentCharset(nsACString& aCharset)
|
||||
{
|
||||
nsCOMPtr<nsIDocument> doc = do_QueryReferent(mDocument);
|
||||
if (doc) {
|
||||
doc->SetDocumentCharacterSet(aEncoding);
|
||||
doc->SetDocumentCharacterSet(aCharset);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsISupports *
|
||||
|
|
|
@ -41,7 +41,7 @@ public:
|
|||
NS_IMETHOD WillResume(void) override;
|
||||
NS_IMETHOD SetParser(nsParserBase* aParser) override;
|
||||
virtual void FlushPendingNotifications(mozilla::FlushType aType) override { }
|
||||
virtual void SetDocumentCharset(NotNull<const Encoding*> aEncoding) override;
|
||||
NS_IMETHOD SetDocumentCharset(nsACString& aCharset) override;
|
||||
virtual nsISupports *GetTarget() override;
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
#include "mozilla/EditorBase.h"
|
||||
|
||||
#include "mozilla/DebugOnly.h" // for DebugOnly
|
||||
#include "mozilla/Encoding.h" // for Encoding
|
||||
|
||||
#include <stdio.h> // for nullptr, stdout
|
||||
#include <string.h> // for strcmp
|
||||
|
@ -1181,7 +1180,7 @@ EditorBase::GetDocumentCharacterSet(nsACString& characterSet)
|
|||
if (NS_WARN_IF(!document)) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
document->GetDocumentCharacterSet()->Name(characterSet);
|
||||
characterSet = document->GetDocumentCharacterSet();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -1192,13 +1191,7 @@ EditorBase::SetDocumentCharacterSet(const nsACString& characterSet)
|
|||
if (NS_WARN_IF(!document)) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
// This method is scriptable, so add-ons could pass in something other
|
||||
// than a canonical name.
|
||||
auto encoding = Encoding::ForLabelNoReplacement(characterSet);
|
||||
if (!encoding) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
document->SetDocumentCharacterSet(WrapNotNull(encoding));
|
||||
document->SetDocumentCharacterSet(characterSet);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
#include "nsIAtom.h"
|
||||
#include "mozilla/ArrayUtils.h"
|
||||
#include "mozilla/ClearOnShutdown.h"
|
||||
#include "mozilla/Encoding.h"
|
||||
#include "mozilla/intl/OSPreferences.h"
|
||||
#include "mozilla/ServoBindings.h"
|
||||
|
||||
|
@ -47,13 +46,11 @@ nsLanguageAtomService::LookupLanguage(const nsACString &aLanguage)
|
|||
}
|
||||
|
||||
already_AddRefed<nsIAtom>
|
||||
nsLanguageAtomService::LookupCharSet(NotNull<const Encoding*> aEncoding)
|
||||
nsLanguageAtomService::LookupCharSet(const nsACString& aCharSet)
|
||||
{
|
||||
nsAutoCString charset;
|
||||
aEncoding->Name(charset);
|
||||
nsAutoCString group;
|
||||
if (NS_FAILED(nsUConvPropertySearch::SearchPropertyValue(
|
||||
encodingsGroups, ArrayLength(encodingsGroups), charset, group))) {
|
||||
encodingsGroups, ArrayLength(encodingsGroups), aCharSet, group))) {
|
||||
return RefPtr<nsIAtom>(nsGkAtoms::Unicode).forget();
|
||||
}
|
||||
return NS_Atomize(group);
|
||||
|
|
|
@ -11,24 +11,17 @@
|
|||
#ifndef nsLanguageAtomService_h_
|
||||
#define nsLanguageAtomService_h_
|
||||
|
||||
#include "mozilla/NotNull.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIAtom.h"
|
||||
#include "nsInterfaceHashtable.h"
|
||||
|
||||
namespace mozilla {
|
||||
class Encoding;
|
||||
}
|
||||
|
||||
class nsLanguageAtomService final
|
||||
class nsLanguageAtomService
|
||||
{
|
||||
using Encoding = mozilla::Encoding;
|
||||
template <typename T> using NotNull = mozilla::NotNull<T>;
|
||||
public:
|
||||
static nsLanguageAtomService* GetService();
|
||||
|
||||
nsIAtom* LookupLanguage(const nsACString &aLanguage);
|
||||
already_AddRefed<nsIAtom> LookupCharSet(NotNull<const Encoding*> aCharSet);
|
||||
already_AddRefed<nsIAtom> LookupCharSet(const nsACString& aCharSet);
|
||||
nsIAtom* GetLocaleLanguage();
|
||||
|
||||
// Returns the language group that the specified language is a part of.
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
#include "mozilla/ArrayUtils.h"
|
||||
#include "mozilla/DebugOnly.h"
|
||||
#include "mozilla/Encoding.h"
|
||||
#include "mozilla/EventDispatcher.h"
|
||||
#include "mozilla/EventStateManager.h"
|
||||
|
||||
|
@ -121,7 +120,7 @@ class CharSetChangingRunnable : public Runnable
|
|||
{
|
||||
public:
|
||||
CharSetChangingRunnable(nsPresContext* aPresContext,
|
||||
NotNull<const Encoding*> aCharSet)
|
||||
const nsCString& aCharSet)
|
||||
: Runnable("CharSetChangingRunnable"),
|
||||
mPresContext(aPresContext),
|
||||
mCharSet(aCharSet)
|
||||
|
@ -136,7 +135,7 @@ public:
|
|||
|
||||
private:
|
||||
RefPtr<nsPresContext> mPresContext;
|
||||
NotNull<const Encoding*> mCharSet;
|
||||
nsCString mCharSet;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
@ -197,9 +196,15 @@ nsPresContext::PrefChangedUpdateTimerCallback(nsITimer *aTimer, void *aClosure)
|
|||
}
|
||||
|
||||
static bool
|
||||
IsVisualCharset(NotNull<const Encoding*> aCharset)
|
||||
IsVisualCharset(const nsCString& aCharset)
|
||||
{
|
||||
return aCharset == ISO_8859_8_ENCODING;
|
||||
if (aCharset.LowerCaseEqualsLiteral("ibm862") // Hebrew
|
||||
|| aCharset.LowerCaseEqualsLiteral("iso-8859-8") ) { // Hebrew
|
||||
return true; // visual text type
|
||||
}
|
||||
else {
|
||||
return false; // logical text type
|
||||
}
|
||||
}
|
||||
|
||||
nsPresContext::nsPresContext(nsIDocument* aDocument, nsPresContextType aType)
|
||||
|
@ -1065,7 +1070,7 @@ nsPresContext::DetachShell()
|
|||
}
|
||||
|
||||
void
|
||||
nsPresContext::DoChangeCharSet(NotNull<const Encoding*> aCharSet)
|
||||
nsPresContext::DoChangeCharSet(const nsCString& aCharSet)
|
||||
{
|
||||
UpdateCharSet(aCharSet);
|
||||
mDeviceContext->FlushFontCache();
|
||||
|
@ -1073,7 +1078,7 @@ nsPresContext::DoChangeCharSet(NotNull<const Encoding*> aCharSet)
|
|||
}
|
||||
|
||||
void
|
||||
nsPresContext::UpdateCharSet(NotNull<const Encoding*> aCharSet)
|
||||
nsPresContext::UpdateCharSet(const nsCString& aCharSet)
|
||||
{
|
||||
mLanguage = mLangService->LookupCharSet(aCharSet);
|
||||
// this will be a language group (or script) code rather than a true language code
|
||||
|
@ -1107,9 +1112,8 @@ nsPresContext::Observe(nsISupports* aSubject,
|
|||
const char16_t* aData)
|
||||
{
|
||||
if (!nsCRT::strcmp(aTopic, "charset")) {
|
||||
auto encoding = Encoding::ForName(NS_LossyConvertUTF16toASCII(aData));
|
||||
RefPtr<CharSetChangingRunnable> runnable =
|
||||
new CharSetChangingRunnable(this, encoding);
|
||||
new CharSetChangingRunnable(this, NS_LossyConvertUTF16toASCII(aData));
|
||||
return Document()->Dispatch("CharSetChangingRunnable",
|
||||
TaskCategory::Other,
|
||||
runnable.forget());
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
#define nsPresContext_h___
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/NotNull.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
#include "mozilla/WeakPtr.h"
|
||||
#include "nsColor.h"
|
||||
|
@ -72,7 +71,6 @@ class gfxMissingFontRecorder;
|
|||
|
||||
namespace mozilla {
|
||||
class EffectCompositor;
|
||||
class Encoding;
|
||||
class EventStateManager;
|
||||
class CounterStyleManager;
|
||||
class RestyleManager;
|
||||
|
@ -127,8 +125,6 @@ class nsRootPresContext;
|
|||
class nsPresContext : public nsIObserver,
|
||||
public mozilla::SupportsWeakPtr<nsPresContext> {
|
||||
public:
|
||||
using Encoding = mozilla::Encoding;
|
||||
template <typename T> using NotNull = mozilla::NotNull<T>;
|
||||
typedef mozilla::LangGroupFontPrefs LangGroupFontPrefs;
|
||||
typedef mozilla::ScrollbarStyles ScrollbarStyles;
|
||||
typedef mozilla::StaticPresData StaticPresData;
|
||||
|
@ -1232,12 +1228,12 @@ protected:
|
|||
return StaticPresData::Get()->GetFontPrefsForLangHelper(lang, &mLangGroupFontPrefs, aNeedsToCache);
|
||||
}
|
||||
|
||||
void UpdateCharSet(NotNull<const Encoding*> aCharSet);
|
||||
void UpdateCharSet(const nsCString& aCharSet);
|
||||
|
||||
static bool NotifyDidPaintSubdocumentCallback(nsIDocument* aDocument, void* aData);
|
||||
|
||||
public:
|
||||
void DoChangeCharSet(NotNull<const Encoding*> aCharSet);
|
||||
void DoChangeCharSet(const nsCString& aCharSet);
|
||||
|
||||
/**
|
||||
* Checks for MozAfterPaint listeners on the document
|
||||
|
|
|
@ -3,11 +3,8 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
#include "nsContentDLF.h"
|
||||
|
||||
#include "mozilla/Encoding.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsContentDLF.h"
|
||||
#include "nsDocShell.h"
|
||||
#include "nsGenericHTMLElement.h"
|
||||
#include "nsGkAtoms.h"
|
||||
|
@ -330,7 +327,7 @@ nsContentDLF::CreateBlankDocument(nsILoadGroup *aLoadGroup,
|
|||
// add a nice bow
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
blankDoc->SetDocumentCharacterSetSource(kCharsetFromDocTypeDefault);
|
||||
blankDoc->SetDocumentCharacterSet(UTF_8_ENCODING);
|
||||
blankDoc->SetDocumentCharacterSet(NS_LITERAL_CSTRING("UTF-8"));
|
||||
|
||||
blankDoc.forget(aDocument);
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#include "gfxContext.h"
|
||||
#include "gfxUtils.h"
|
||||
#include "mozilla/DebugOnly.h"
|
||||
#include "mozilla/Encoding.h"
|
||||
#include "mozilla/EventStates.h"
|
||||
#include "mozilla/gfx/2D.h"
|
||||
#include "mozilla/gfx/Helpers.h"
|
||||
|
@ -2252,7 +2251,7 @@ nsImageFrame::GetDocumentCharacterSet(nsACString& aCharset) const
|
|||
if (mContent) {
|
||||
NS_ASSERTION(mContent->GetComposedDoc(),
|
||||
"Frame still alive after content removed from document!");
|
||||
mContent->GetComposedDoc()->GetDocumentCharacterSet()->Name(aCharset);
|
||||
aCharset = mContent->GetComposedDoc()->GetDocumentCharacterSet();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -761,8 +761,8 @@ SheetLoadData::OnDetermineCharset(nsIUnicharStreamLoader* aLoader,
|
|||
|
||||
if (mLoader->mDocument) {
|
||||
// no useful data on charset. Try the document charset.
|
||||
auto encoding = mLoader->mDocument->GetDocumentCharacterSet();
|
||||
encoding->Name(aCharset);
|
||||
aCharset = mLoader->mDocument->GetDocumentCharacterSet();
|
||||
MOZ_ASSERT(!aCharset.IsEmpty());
|
||||
mCharset.Assign(aCharset);
|
||||
LOG((" Setting from document to: %s", PromiseFlatCString(aCharset).get()));
|
||||
return NS_OK;
|
||||
|
|
|
@ -7,13 +7,11 @@
|
|||
// HttpLog.h should generally be included first
|
||||
#include "HttpLog.h"
|
||||
|
||||
#include "nsNetUtil.h"
|
||||
|
||||
#include "mozilla/Encoding.h"
|
||||
#include "mozilla/LoadContext.h"
|
||||
#include "mozilla/LoadInfo.h"
|
||||
#include "mozilla/BasePrincipal.h"
|
||||
#include "mozilla/Telemetry.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsCategoryCache.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsHashKeys.h"
|
||||
|
@ -1537,18 +1535,6 @@ NS_NewURI(nsIURI **result,
|
|||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
NS_NewURI(nsIURI **result,
|
||||
const nsACString &spec,
|
||||
NotNull<const Encoding*> encoding,
|
||||
nsIURI *baseURI /* = nullptr */,
|
||||
nsIIOService *ioService /* = nullptr */) // pass in nsIIOService to optimize callers
|
||||
{
|
||||
nsAutoCString charset;
|
||||
encoding->Name(charset);
|
||||
return NS_NewURI(result, spec, charset.get(), baseURI, ioService);
|
||||
}
|
||||
|
||||
nsresult
|
||||
NS_NewURI(nsIURI **result,
|
||||
const nsAString &spec,
|
||||
|
@ -1559,16 +1545,6 @@ NS_NewURI(nsIURI **result,
|
|||
return NS_NewURI(result, NS_ConvertUTF16toUTF8(spec), charset, baseURI, ioService);
|
||||
}
|
||||
|
||||
nsresult
|
||||
NS_NewURI(nsIURI **result,
|
||||
const nsAString &spec,
|
||||
NotNull<const Encoding*> encoding,
|
||||
nsIURI *baseURI /* = nullptr */,
|
||||
nsIIOService *ioService /* = nullptr */) // pass in nsIIOService to optimize callers
|
||||
{
|
||||
return NS_NewURI(result, NS_ConvertUTF16toUTF8(spec), encoding, baseURI, ioService);
|
||||
}
|
||||
|
||||
nsresult
|
||||
NS_NewURI(nsIURI **result,
|
||||
const char *spec,
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
#include "nsIRequest.h"
|
||||
#include "nsILoadInfo.h"
|
||||
#include "nsIIOService.h"
|
||||
#include "mozilla/NotNull.h"
|
||||
#include "mozilla/Services.h"
|
||||
#include "mozilla/Unused.h"
|
||||
#include "nsNetCID.h"
|
||||
|
@ -52,10 +51,7 @@ class nsIIncrementalStreamLoaderObserver;
|
|||
class nsIUnicharStreamLoader;
|
||||
class nsIUnicharStreamLoaderObserver;
|
||||
|
||||
namespace mozilla {
|
||||
class Encoding;
|
||||
class OriginAttributes;
|
||||
}
|
||||
namespace mozilla { class OriginAttributes; }
|
||||
|
||||
template <class> class nsCOMPtr;
|
||||
template <typename> struct already_AddRefed;
|
||||
|
@ -73,24 +69,12 @@ nsresult NS_NewURI(nsIURI **result,
|
|||
nsIURI *baseURI = nullptr,
|
||||
nsIIOService *ioService = nullptr); // pass in nsIIOService to optimize callers
|
||||
|
||||
nsresult NS_NewURI(nsIURI **result,
|
||||
const nsACString &spec,
|
||||
mozilla::NotNull<const mozilla::Encoding*> encoding,
|
||||
nsIURI *baseURI = nullptr,
|
||||
nsIIOService *ioService = nullptr); // pass in nsIIOService to optimize callers
|
||||
|
||||
nsresult NS_NewURI(nsIURI **result,
|
||||
const nsAString &spec,
|
||||
const char *charset = nullptr,
|
||||
nsIURI *baseURI = nullptr,
|
||||
nsIIOService *ioService = nullptr); // pass in nsIIOService to optimize callers
|
||||
|
||||
nsresult NS_NewURI(nsIURI **result,
|
||||
const nsAString &spec,
|
||||
mozilla::NotNull<const mozilla::Encoding*> encoding,
|
||||
nsIURI *baseURI = nullptr,
|
||||
nsIIOService *ioService = nullptr); // pass in nsIIOService to optimize callers
|
||||
|
||||
nsresult NS_NewURI(nsIURI **result,
|
||||
const char *spec,
|
||||
nsIURI *baseURI = nullptr,
|
||||
|
|
|
@ -5,17 +5,17 @@
|
|||
|
||||
/* This parsing code originally lived in xpfe/components/directory/ - bbaetz */
|
||||
|
||||
#include "nsDirIndexParser.h"
|
||||
|
||||
#include "mozilla/ArrayUtils.h"
|
||||
#include "mozilla/dom/FallbackEncoding.h"
|
||||
#include "mozilla/Encoding.h"
|
||||
|
||||
#include "prprf.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
#include "nsDirIndexParser.h"
|
||||
#include "nsEscape.h"
|
||||
#include "nsIDirIndex.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsCRT.h"
|
||||
#include "mozilla/dom/FallbackEncoding.h"
|
||||
#include "nsITextToSubURI.h"
|
||||
#include "nsIDirIndex.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
@ -33,8 +33,7 @@ nsDirIndexParser::Init() {
|
|||
mLineStart = 0;
|
||||
mHasDescription = false;
|
||||
mFormat[0] = -1;
|
||||
auto encoding = mozilla::dom::FallbackEncoding::FromLocale();
|
||||
encoding->Name(mEncoding);
|
||||
mozilla::dom::FallbackEncoding::FromLocale(mEncoding);
|
||||
|
||||
nsresult rv;
|
||||
// XXX not threadsafe
|
||||
|
|
|
@ -49,12 +49,11 @@ nsHtml5DocumentBuilder::MarkAsBroken(nsresult aReason)
|
|||
}
|
||||
|
||||
void
|
||||
nsHtml5DocumentBuilder::SetDocumentCharsetAndSource(NotNull<const Encoding*> aEncoding,
|
||||
int32_t aCharsetSource)
|
||||
nsHtml5DocumentBuilder::SetDocumentCharsetAndSource(nsACString& aCharset, int32_t aCharsetSource)
|
||||
{
|
||||
if (mDocument) {
|
||||
mDocument->SetDocumentCharacterSetSource(aCharsetSource);
|
||||
mDocument->SetDocumentCharacterSet(aEncoding);
|
||||
mDocument->SetDocumentCharacterSet(aCharset);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,8 +23,6 @@ enum eHtml5FlushState {
|
|||
|
||||
class nsHtml5DocumentBuilder : public nsContentSink
|
||||
{
|
||||
using Encoding = mozilla::Encoding;
|
||||
template <typename T> using NotNull = mozilla::NotNull<T>;
|
||||
public:
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsHtml5DocumentBuilder,
|
||||
nsContentSink)
|
||||
|
@ -89,8 +87,7 @@ public:
|
|||
return mFlushState == eInDocUpdate;
|
||||
}
|
||||
|
||||
void SetDocumentCharsetAndSource(NotNull<const Encoding*> aEncoding,
|
||||
int32_t aCharsetSource);
|
||||
void SetDocumentCharsetAndSource(nsACString& aCharset, int32_t aCharsetSource);
|
||||
|
||||
/**
|
||||
* Sets up style sheet load / parse
|
||||
|
|
|
@ -77,7 +77,6 @@ nsHtml5MetaScanner::nsHtml5MetaScanner(nsHtml5TreeBuilder* tb)
|
|||
, charset(nullptr)
|
||||
, httpEquivState(HTTP_EQUIV_NOT_SEEN)
|
||||
, treeBuilder(tb)
|
||||
, mEncoding(nullptr)
|
||||
{
|
||||
MOZ_COUNT_CTOR(nsHtml5MetaScanner);
|
||||
}
|
||||
|
|
|
@ -6,13 +6,13 @@
|
|||
|
||||
#include "mozilla/Encoding.h"
|
||||
|
||||
const Encoding*
|
||||
nsHtml5MetaScanner::sniff(nsHtml5ByteReadable* bytes)
|
||||
void
|
||||
nsHtml5MetaScanner::sniff(nsHtml5ByteReadable* bytes, nsACString& charset)
|
||||
{
|
||||
readable = bytes;
|
||||
stateLoop(stateSave);
|
||||
readable = nullptr;
|
||||
return mEncoding;
|
||||
charset.Assign(mCharset);
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -25,20 +25,20 @@ nsHtml5MetaScanner::tryCharset(nsHtml5String charset)
|
|||
nsString charset16; // Not Auto, because using it to hold nsStringBuffer*
|
||||
charset.ToString(charset16);
|
||||
CopyUTF16toUTF8(charset16, label);
|
||||
const Encoding* encoding = Encoding::ForLabel(label);
|
||||
const mozilla::Encoding* encoding = mozilla::Encoding::ForLabel(label);
|
||||
if (!encoding) {
|
||||
return false;
|
||||
}
|
||||
if (encoding == UTF_16BE_ENCODING ||
|
||||
encoding == UTF_16LE_ENCODING) {
|
||||
mEncoding = UTF_8_ENCODING;
|
||||
mCharset.AssignLiteral("UTF-8");
|
||||
return true;
|
||||
}
|
||||
if (encoding == X_USER_DEFINED_ENCODING) {
|
||||
// WebKit/Blink hack for Indian and Armenian legacy sites
|
||||
mEncoding = WINDOWS_1252_ENCODING;
|
||||
mCharset.AssignLiteral("windows-1252");
|
||||
return true;
|
||||
}
|
||||
mEncoding = encoding;
|
||||
encoding->Name(mCharset);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
using Encoding = mozilla::Encoding;
|
||||
|
||||
private:
|
||||
const Encoding* mEncoding;
|
||||
nsCString mCharset;
|
||||
inline int32_t read()
|
||||
{
|
||||
return readable->read();
|
||||
}
|
||||
public:
|
||||
const Encoding* sniff(nsHtml5ByteReadable* bytes);
|
||||
void sniff(nsHtml5ByteReadable* bytes, nsACString& charset);
|
||||
|
|
|
@ -100,14 +100,18 @@ nsHtml5Parser::SetCommand(eParserCommands aParserCommand)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP_(void)
|
||||
nsHtml5Parser::SetDocumentCharset(NotNull<const Encoding*> aEncoding,
|
||||
nsHtml5Parser::SetDocumentCharset(const nsACString& aCharset,
|
||||
int32_t aCharsetSource)
|
||||
{
|
||||
NS_PRECONDITION(!mExecutor->HasStarted(),
|
||||
"Document charset set too late.");
|
||||
NS_PRECONDITION(GetStreamParser(), "Setting charset on a script-only parser.");
|
||||
GetStreamParser()->SetDocumentCharset(aEncoding, aCharsetSource);
|
||||
mExecutor->SetDocumentCharsetAndSource(aEncoding, aCharsetSource);
|
||||
nsAutoCString trimmed;
|
||||
trimmed.Assign(aCharset);
|
||||
trimmed.Trim(" \t\r\n\f");
|
||||
GetStreamParser()->SetDocumentCharset(trimmed, aCharsetSource);
|
||||
mExecutor->SetDocumentCharsetAndSource(trimmed,
|
||||
aCharsetSource);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -70,8 +70,15 @@ class nsHtml5Parser final : public nsIParser,
|
|||
* @param aCharset the charset of a document
|
||||
* @param aCharsetSource the source of the charset
|
||||
*/
|
||||
virtual void SetDocumentCharset(NotNull<const Encoding*> aCharset,
|
||||
int32_t aSource) override;
|
||||
NS_IMETHOD_(void) SetDocumentCharset(const nsACString& aCharset, int32_t aSource) override;
|
||||
|
||||
/**
|
||||
* Don't call. For interface compat only.
|
||||
*/
|
||||
NS_IMETHOD_(void) GetDocumentCharset(nsACString& aCharset, int32_t& aSource) override
|
||||
{
|
||||
NS_NOTREACHED("No one should call this.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channel associated with this parser
|
||||
|
|
|
@ -66,7 +66,7 @@ nsHtml5SpeculativeLoad::Perform(nsHtml5TreeOpExecutor* aExecutor)
|
|||
NS_ASSERTION(mTypeOrCharsetSourceOrDocumentMode.Length() == 1,
|
||||
"Unexpected charset source string");
|
||||
int32_t intSource = (int32_t)mTypeOrCharsetSourceOrDocumentMode.First();
|
||||
aExecutor->SetDocumentCharsetAndSource(Encoding::ForName(narrowName),
|
||||
aExecutor->SetDocumentCharsetAndSource(narrowName,
|
||||
intSource);
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -152,7 +152,6 @@ nsHtml5StreamParser::nsHtml5StreamParser(nsHtml5TreeOpExecutor* aExecutor,
|
|||
: mSniffingLength(0)
|
||||
, mBomState(eBomState::BOM_SNIFFING_NOT_STARTED)
|
||||
, mCharsetSource(kCharsetUninitialized)
|
||||
, mEncoding(WINDOWS_1252_ENCODING)
|
||||
, mReparseForbidden(false)
|
||||
, mLastBuffer(nullptr) // Will be filled when starting
|
||||
, mExecutor(aExecutor)
|
||||
|
@ -254,21 +253,23 @@ nsHtml5StreamParser::Notify(const char* aCharset, nsDetectionConfident aConf)
|
|||
NS_ASSERTION(IsParserThread(), "Wrong thread!");
|
||||
if (aConf == eBestAnswer || aConf == eSureAnswer) {
|
||||
mFeedChardet = false; // just in case
|
||||
auto encoding = Encoding::ForLabelNoReplacement(
|
||||
const Encoding* encoding = Encoding::ForLabelNoReplacement(
|
||||
nsDependentCString(aCharset));
|
||||
if (!encoding) {
|
||||
return NS_OK;
|
||||
}
|
||||
nsAutoCString charset;
|
||||
encoding->Name(charset);
|
||||
if (HasDecoder()) {
|
||||
if (mEncoding == encoding) {
|
||||
if (mCharset.Equals(charset)) {
|
||||
NS_ASSERTION(mCharsetSource < kCharsetFromAutoDetection,
|
||||
"Why are we running chardet at all?");
|
||||
mCharsetSource = kCharsetFromAutoDetection;
|
||||
mTreeBuilder->SetDocumentCharset(mEncoding, mCharsetSource);
|
||||
mTreeBuilder->SetDocumentCharset(mCharset, mCharsetSource);
|
||||
} else {
|
||||
// We've already committed to a decoder. Request a reload from the
|
||||
// docshell.
|
||||
mTreeBuilder->NeedsCharsetSwitchTo(WrapNotNull(encoding),
|
||||
mTreeBuilder->NeedsCharsetSwitchTo(charset,
|
||||
kCharsetFromAutoDetection,
|
||||
0);
|
||||
FlushTreeOpsAndDisarmTimer();
|
||||
|
@ -277,9 +278,9 @@ nsHtml5StreamParser::Notify(const char* aCharset, nsDetectionConfident aConf)
|
|||
} else {
|
||||
// Got a confident answer from the sniffing buffer. That code will
|
||||
// take care of setting up the decoder.
|
||||
mEncoding = WrapNotNull(encoding);
|
||||
mCharset.Assign(charset);
|
||||
mCharsetSource = kCharsetFromAutoDetection;
|
||||
mTreeBuilder->SetDocumentCharset(mEncoding, mCharsetSource);
|
||||
mTreeBuilder->SetDocumentCharset(mCharset, mCharsetSource);
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
|
@ -320,7 +321,7 @@ nsHtml5StreamParser::SetupDecodingAndWriteSniffingBufferAndCurrentSegment(const
|
|||
{
|
||||
NS_ASSERTION(IsParserThread(), "Wrong thread!");
|
||||
nsresult rv = NS_OK;
|
||||
mUnicodeDecoder = mEncoding->NewDecoderWithBOMRemoval();
|
||||
mUnicodeDecoder = Encoding::ForName(mCharset)->NewDecoderWithBOMRemoval();
|
||||
if (mSniffingBuffer) {
|
||||
uint32_t writeCount;
|
||||
rv = WriteStreamBytes(mSniffingBuffer.get(), mSniffingLength, &writeCount);
|
||||
|
@ -335,14 +336,14 @@ nsHtml5StreamParser::SetupDecodingAndWriteSniffingBufferAndCurrentSegment(const
|
|||
}
|
||||
|
||||
nsresult
|
||||
nsHtml5StreamParser::SetupDecodingFromBom(NotNull<const Encoding*> aEncoding)
|
||||
nsHtml5StreamParser::SetupDecodingFromBom(const char* aDecoderCharsetName)
|
||||
{
|
||||
NS_ASSERTION(IsParserThread(), "Wrong thread!");
|
||||
mEncoding = aEncoding;
|
||||
mUnicodeDecoder = mEncoding->NewDecoderWithBOMRemoval();
|
||||
mCharset.Assign(aDecoderCharsetName);
|
||||
mUnicodeDecoder = Encoding::ForName(mCharset)->NewDecoderWithBOMRemoval();
|
||||
mCharsetSource = kCharsetFromByteOrderMark;
|
||||
mFeedChardet = false;
|
||||
mTreeBuilder->SetDocumentCharset(mEncoding, mCharsetSource);
|
||||
mTreeBuilder->SetDocumentCharset(mCharset, mCharsetSource);
|
||||
mSniffingBuffer = nullptr;
|
||||
mMetaScanner = nullptr;
|
||||
mBomState = BOM_SNIFFING_OVER;
|
||||
|
@ -397,12 +398,12 @@ nsHtml5StreamParser::SniffBOMlessUTF16BasicLatin(const uint8_t* aFromSegment,
|
|||
}
|
||||
|
||||
if (byteNonZero[0]) {
|
||||
mEncoding = UTF_16LE_ENCODING;
|
||||
mCharset.AssignLiteral("UTF-16LE");
|
||||
} else {
|
||||
mEncoding = UTF_16BE_ENCODING;
|
||||
mCharset.AssignLiteral("UTF-16BE");
|
||||
}
|
||||
mCharsetSource = kCharsetFromIrreversibleAutoDetection;
|
||||
mTreeBuilder->SetDocumentCharset(mEncoding, mCharsetSource);
|
||||
mTreeBuilder->SetDocumentCharset(mCharset, mCharsetSource);
|
||||
mFeedChardet = false;
|
||||
mTreeBuilder->MaybeComplainAboutCharset("EncBomlessUtf16",
|
||||
true,
|
||||
|
@ -417,9 +418,8 @@ nsHtml5StreamParser::SetEncodingFromExpat(const char16_t* aEncoding)
|
|||
nsDependentString utf16(aEncoding);
|
||||
nsAutoCString utf8;
|
||||
CopyUTF16toUTF8(utf16, utf8);
|
||||
auto encoding = PreferredForInternalEncodingDecl(utf8);
|
||||
if (encoding) {
|
||||
mEncoding = WrapNotNull(encoding);
|
||||
if (PreferredForInternalEncodingDecl(utf8)) {
|
||||
mCharset.Assign(utf8);
|
||||
mCharsetSource = kCharsetFromMetaTag; // closest for XML
|
||||
return;
|
||||
}
|
||||
|
@ -428,7 +428,7 @@ nsHtml5StreamParser::SetEncodingFromExpat(const char16_t* aEncoding)
|
|||
// right away and let the encoding be set to UTF-8 which we'd default to
|
||||
// anyway.
|
||||
}
|
||||
mEncoding = UTF_8_ENCODING; // XML defaults to UTF-8 without a BOM
|
||||
mCharset.AssignLiteral("UTF-8"); // XML defaults to UTF-8 without a BOM
|
||||
mCharsetSource = kCharsetFromMetaTag; // means confident
|
||||
}
|
||||
|
||||
|
@ -560,7 +560,7 @@ nsHtml5StreamParser::FinalizeSniffing(const uint8_t* aFromSegment, // can be nul
|
|||
// confidently to UTF-8 in this case.
|
||||
// It is also possible that the document has an XML declaration that is
|
||||
// longer than 1024 bytes, but that case is not worth worrying about.
|
||||
mEncoding = UTF_8_ENCODING;
|
||||
mCharset.AssignLiteral("UTF-8");
|
||||
mCharsetSource = kCharsetFromMetaTag; // means confident
|
||||
}
|
||||
|
||||
|
@ -612,18 +612,18 @@ nsHtml5StreamParser::FinalizeSniffing(const uint8_t* aFromSegment, // can be nul
|
|||
}
|
||||
if (mCharsetSource == kCharsetUninitialized) {
|
||||
// Hopefully this case is never needed, but dealing with it anyway
|
||||
mEncoding = WINDOWS_1252_ENCODING;
|
||||
mCharset.AssignLiteral("windows-1252");
|
||||
mCharsetSource = kCharsetFromFallback;
|
||||
mTreeBuilder->SetDocumentCharset(mEncoding, mCharsetSource);
|
||||
mTreeBuilder->SetDocumentCharset(mCharset, mCharsetSource);
|
||||
} else if (mMode == LOAD_AS_DATA &&
|
||||
mCharsetSource == kCharsetFromFallback) {
|
||||
NS_ASSERTION(mReparseForbidden, "Reparse should be forbidden for XHR");
|
||||
NS_ASSERTION(!mFeedChardet, "Should not feed chardet for XHR");
|
||||
NS_ASSERTION(mEncoding == UTF_8_ENCODING,
|
||||
NS_ASSERTION(mCharset.EqualsLiteral("UTF-8"),
|
||||
"XHR should default to UTF-8");
|
||||
// Now mark charset source as non-weak to signal that we have a decision
|
||||
mCharsetSource = kCharsetFromDocTypeDefault;
|
||||
mTreeBuilder->SetDocumentCharset(mEncoding, mCharsetSource);
|
||||
mTreeBuilder->SetDocumentCharset(mCharset, mCharsetSource);
|
||||
}
|
||||
return SetupDecodingAndWriteSniffingBufferAndCurrentSegment(aFromSegment, aCount, aWriteCount);
|
||||
}
|
||||
|
@ -637,9 +637,9 @@ nsHtml5StreamParser::SniffStreamBytes(const uint8_t* aFromSegment,
|
|||
nsresult rv = NS_OK;
|
||||
uint32_t writeCount;
|
||||
|
||||
// mEncoding and mCharsetSource potentially have come from channel or higher
|
||||
// mCharset and mCharsetSource potentially have come from channel or higher
|
||||
// by now. If we find a BOM, SetupDecodingFromBom() will overwrite them.
|
||||
// If we don't find a BOM, the previously set values of mEncoding and
|
||||
// If we don't find a BOM, the previously set values of mCharset and
|
||||
// mCharsetSource are not modified by the BOM sniffing here.
|
||||
for (uint32_t i = 0; i < aCount && mBomState != BOM_SNIFFING_OVER; i++) {
|
||||
switch (mBomState) {
|
||||
|
@ -662,7 +662,7 @@ nsHtml5StreamParser::SniffStreamBytes(const uint8_t* aFromSegment,
|
|||
break;
|
||||
case SEEN_UTF_16_LE_FIRST_BYTE:
|
||||
if (aFromSegment[i] == 0xFE) {
|
||||
rv = SetupDecodingFromBom(UTF_16LE_ENCODING); // upper case is the raw form
|
||||
rv = SetupDecodingFromBom("UTF-16LE"); // upper case is the raw form
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
uint32_t count = aCount - (i + 1);
|
||||
rv = WriteStreamBytes(aFromSegment + (i + 1), count, &writeCount);
|
||||
|
@ -674,7 +674,7 @@ nsHtml5StreamParser::SniffStreamBytes(const uint8_t* aFromSegment,
|
|||
break;
|
||||
case SEEN_UTF_16_BE_FIRST_BYTE:
|
||||
if (aFromSegment[i] == 0xFF) {
|
||||
rv = SetupDecodingFromBom(UTF_16BE_ENCODING); // upper case is the raw form
|
||||
rv = SetupDecodingFromBom("UTF-16BE"); // upper case is the raw form
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
uint32_t count = aCount - (i + 1);
|
||||
rv = WriteStreamBytes(aFromSegment + (i + 1), count, &writeCount);
|
||||
|
@ -693,7 +693,7 @@ nsHtml5StreamParser::SniffStreamBytes(const uint8_t* aFromSegment,
|
|||
break;
|
||||
case SEEN_UTF_8_SECOND_BYTE:
|
||||
if (aFromSegment[i] == 0xBF) {
|
||||
rv = SetupDecodingFromBom(UTF_8_ENCODING); // upper case is the raw form
|
||||
rv = SetupDecodingFromBom("UTF-8"); // upper case is the raw form
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
uint32_t count = aCount - (i + 1);
|
||||
rv = WriteStreamBytes(aFromSegment + (i + 1), count, &writeCount);
|
||||
|
@ -718,13 +718,13 @@ nsHtml5StreamParser::SniffStreamBytes(const uint8_t* aFromSegment,
|
|||
|
||||
if (mBomState == BOM_SNIFFING_OVER &&
|
||||
mCharsetSource == kCharsetFromChannel) {
|
||||
// There was no BOM and the charset came from channel. mEncoding
|
||||
// There was no BOM and the charset came from channel. mCharset
|
||||
// still contains the charset from the channel as set by an
|
||||
// earlier call to SetDocumentCharset(), since we didn't find a BOM and
|
||||
// overwrite mEncoding. (Note that if the user has overridden the charset,
|
||||
// overwrite mCharset. (Note that if the user has overridden the charset,
|
||||
// we don't come here but check <meta> for XSS-dangerous charsets first.)
|
||||
mFeedChardet = false;
|
||||
mTreeBuilder->SetDocumentCharset(mEncoding, mCharsetSource);
|
||||
mTreeBuilder->SetDocumentCharset(mCharset, mCharsetSource);
|
||||
return SetupDecodingAndWriteSniffingBufferAndCurrentSegment(aFromSegment,
|
||||
aCount, aWriteCount);
|
||||
}
|
||||
|
@ -743,14 +743,15 @@ nsHtml5StreamParser::SniffStreamBytes(const uint8_t* aFromSegment,
|
|||
nsHtml5ByteReadable readable(aFromSegment, aFromSegment +
|
||||
countToSniffingLimit);
|
||||
nsAutoCString charset;
|
||||
auto encoding = mMetaScanner->sniff(&readable);
|
||||
mMetaScanner->sniff(&readable, charset);
|
||||
// Due to the way nsHtml5Portability reports OOM, ask the tree buider
|
||||
nsresult rv;
|
||||
if (NS_FAILED((rv = mTreeBuilder->IsBroken()))) {
|
||||
MarkAsBroken(rv);
|
||||
return rv;
|
||||
}
|
||||
if (encoding) {
|
||||
if (!charset.IsEmpty()) {
|
||||
const Encoding* encoding = Encoding::ForName(charset);
|
||||
// meta scan successful; honor overrides unless meta is XSS-dangerous
|
||||
if ((mCharsetSource == kCharsetFromParentForced ||
|
||||
mCharsetSource == kCharsetFromUserForced) &&
|
||||
|
@ -760,10 +761,10 @@ nsHtml5StreamParser::SniffStreamBytes(const uint8_t* aFromSegment,
|
|||
return SetupDecodingAndWriteSniffingBufferAndCurrentSegment(
|
||||
aFromSegment, aCount, aWriteCount);
|
||||
}
|
||||
mEncoding = WrapNotNull(encoding);
|
||||
mCharset.Assign(charset);
|
||||
mCharsetSource = kCharsetFromMetaPrescan;
|
||||
mFeedChardet = false;
|
||||
mTreeBuilder->SetDocumentCharset(mEncoding, mCharsetSource);
|
||||
mTreeBuilder->SetDocumentCharset(mCharset, mCharsetSource);
|
||||
return SetupDecodingAndWriteSniffingBufferAndCurrentSegment(
|
||||
aFromSegment, aCount, aWriteCount);
|
||||
}
|
||||
|
@ -781,14 +782,16 @@ nsHtml5StreamParser::SniffStreamBytes(const uint8_t* aFromSegment,
|
|||
// not the last buffer
|
||||
if (mMode == NORMAL || mMode == VIEW_SOURCE_HTML || mMode == LOAD_AS_DATA) {
|
||||
nsHtml5ByteReadable readable(aFromSegment, aFromSegment + aCount);
|
||||
auto encoding = mMetaScanner->sniff(&readable);
|
||||
nsAutoCString charset;
|
||||
mMetaScanner->sniff(&readable, charset);
|
||||
// Due to the way nsHtml5Portability reports OOM, ask the tree buider
|
||||
nsresult rv;
|
||||
if (NS_FAILED((rv = mTreeBuilder->IsBroken()))) {
|
||||
MarkAsBroken(rv);
|
||||
return rv;
|
||||
}
|
||||
if (encoding) {
|
||||
if (!charset.IsEmpty()) {
|
||||
const Encoding* encoding = Encoding::ForName(charset);
|
||||
// meta scan successful; honor overrides unless meta is XSS-dangerous
|
||||
if ((mCharsetSource == kCharsetFromParentForced ||
|
||||
mCharsetSource == kCharsetFromUserForced) &&
|
||||
|
@ -798,10 +801,10 @@ nsHtml5StreamParser::SniffStreamBytes(const uint8_t* aFromSegment,
|
|||
return SetupDecodingAndWriteSniffingBufferAndCurrentSegment(aFromSegment,
|
||||
aCount, aWriteCount);
|
||||
}
|
||||
mEncoding = WrapNotNull(encoding);
|
||||
mCharset.Assign(charset);
|
||||
mCharsetSource = kCharsetFromMetaPrescan;
|
||||
mFeedChardet = false;
|
||||
mTreeBuilder->SetDocumentCharset(mEncoding, mCharsetSource);
|
||||
mTreeBuilder->SetDocumentCharset(mCharset, mCharsetSource);
|
||||
return SetupDecodingAndWriteSniffingBufferAndCurrentSegment(aFromSegment,
|
||||
aCount, aWriteCount);
|
||||
}
|
||||
|
@ -1004,7 +1007,7 @@ nsHtml5StreamParser::OnStartRequest(nsIRequest* aRequest, nsISupports* aContext)
|
|||
mFeedChardet = false;
|
||||
|
||||
// Instantiate the converter here to avoid BOM sniffing.
|
||||
mUnicodeDecoder = mEncoding->NewDecoderWithBOMRemoval();
|
||||
mUnicodeDecoder = Encoding::ForName(mCharset)->NewDecoderWithBOMRemoval();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -1228,8 +1231,8 @@ nsHtml5StreamParser::CopySegmentsToParser(nsIInputStream *aInStream,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
const Encoding*
|
||||
nsHtml5StreamParser::PreferredForInternalEncodingDecl(const nsACString& aEncoding)
|
||||
bool
|
||||
nsHtml5StreamParser::PreferredForInternalEncodingDecl(nsACString& aEncoding)
|
||||
{
|
||||
const Encoding* newEncoding = Encoding::ForLabel(aEncoding);
|
||||
if (!newEncoding) {
|
||||
|
@ -1237,7 +1240,7 @@ nsHtml5StreamParser::PreferredForInternalEncodingDecl(const nsACString& aEncodin
|
|||
mTreeBuilder->MaybeComplainAboutCharset("EncMetaUnsupported",
|
||||
true,
|
||||
mTokenizer->getLineNumber());
|
||||
return nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (newEncoding == UTF_16BE_ENCODING ||
|
||||
|
@ -1256,7 +1259,7 @@ nsHtml5StreamParser::PreferredForInternalEncodingDecl(const nsACString& aEncodin
|
|||
newEncoding = WINDOWS_1252_ENCODING;
|
||||
}
|
||||
|
||||
if (newEncoding == mEncoding) {
|
||||
if (newEncoding == Encoding::ForName(mCharset)) {
|
||||
if (mCharsetSource < kCharsetFromMetaPrescan) {
|
||||
if (mInitialEncodingWasFromParentFrame) {
|
||||
mTreeBuilder->MaybeComplainAboutCharset("EncLateMetaFrame",
|
||||
|
@ -1270,10 +1273,11 @@ nsHtml5StreamParser::PreferredForInternalEncodingDecl(const nsACString& aEncodin
|
|||
}
|
||||
mCharsetSource = kCharsetFromMetaTag; // become confident
|
||||
mFeedChardet = false; // don't feed chardet when confident
|
||||
return nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
return newEncoding;
|
||||
newEncoding->Name(aEncoding);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -1292,8 +1296,7 @@ nsHtml5StreamParser::internalEncodingDeclaration(nsHtml5String aEncoding)
|
|||
nsAutoCString newEncoding;
|
||||
CopyUTF16toUTF8(newEncoding16, newEncoding);
|
||||
|
||||
auto encoding = PreferredForInternalEncodingDecl(newEncoding);
|
||||
if (!encoding) {
|
||||
if (!PreferredForInternalEncodingDecl(newEncoding)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1311,7 +1314,7 @@ nsHtml5StreamParser::internalEncodingDeclaration(nsHtml5String aEncoding)
|
|||
// Avoid having the chardet ask for another restart after this restart
|
||||
// request.
|
||||
mFeedChardet = false;
|
||||
mTreeBuilder->NeedsCharsetSwitchTo(WrapNotNull(encoding),
|
||||
mTreeBuilder->NeedsCharsetSwitchTo(newEncoding,
|
||||
kCharsetFromMetaTag,
|
||||
mTokenizer->getLineNumber());
|
||||
FlushTreeOpsAndDisarmTimer();
|
||||
|
|
|
@ -101,9 +101,7 @@ enum eHtml5StreamState {
|
|||
STREAM_ENDED = 2
|
||||
};
|
||||
|
||||
class nsHtml5StreamParser final : public nsICharsetDetectionObserver {
|
||||
template <typename T> using NotNull = mozilla::NotNull<T>;
|
||||
using Encoding = mozilla::Encoding;
|
||||
class nsHtml5StreamParser : public nsICharsetDetectionObserver {
|
||||
|
||||
friend class nsHtml5RequestStopper;
|
||||
friend class nsHtml5DataAvailable;
|
||||
|
@ -155,15 +153,14 @@ class nsHtml5StreamParser final : public nsICharsetDetectionObserver {
|
|||
* Call this method once you've created a parser, and want to instruct it
|
||||
* about what charset to load
|
||||
*
|
||||
* @param aEncoding the charset of a document
|
||||
* @param aCharset the charset of a document
|
||||
* @param aCharsetSource the source of the charset
|
||||
*/
|
||||
inline void SetDocumentCharset(NotNull<const Encoding*> aEncoding,
|
||||
int32_t aSource) {
|
||||
inline void SetDocumentCharset(const nsACString& aCharset, int32_t aSource) {
|
||||
NS_PRECONDITION(mStreamState == STREAM_NOT_STARTED,
|
||||
"SetDocumentCharset called too late.");
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
mEncoding = aEncoding;
|
||||
mCharset = aCharset;
|
||||
mCharsetSource = aSource;
|
||||
}
|
||||
|
||||
|
@ -197,9 +194,9 @@ class nsHtml5StreamParser final : public nsICharsetDetectionObserver {
|
|||
void DropTimer();
|
||||
|
||||
/**
|
||||
* Sets mEncoding and mCharsetSource appropriately for the XML View Source
|
||||
* Sets mCharset and mCharsetSource appropriately for the XML View Source
|
||||
* case if aEncoding names a supported rough ASCII superset and sets
|
||||
* the mEncoding and mCharsetSource to the UTF-8 default otherwise.
|
||||
* the mCharset and mCharsetSource to the UTF-8 default otherwise.
|
||||
*/
|
||||
void SetEncodingFromExpat(const char16_t* aEncoding);
|
||||
|
||||
|
@ -342,7 +339,7 @@ class nsHtml5StreamParser final : public nsICharsetDetectionObserver {
|
|||
* (UTF-16BE, UTF-16LE or UTF-8; the BOM has
|
||||
* been swallowed)
|
||||
*/
|
||||
nsresult SetupDecodingFromBom(NotNull<const Encoding*> aEncoding);
|
||||
nsresult SetupDecodingFromBom(const char* aDecoderCharsetName);
|
||||
|
||||
/**
|
||||
* Become confident or resolve and encoding name to its preferred form.
|
||||
|
@ -352,7 +349,7 @@ class nsHtml5StreamParser final : public nsICharsetDetectionObserver {
|
|||
* aEncoding and false if the parser became confident or if
|
||||
* the encoding name did not specify a usable encoding
|
||||
*/
|
||||
const Encoding* PreferredForInternalEncodingDecl(const nsACString& aEncoding);
|
||||
bool PreferredForInternalEncodingDecl(nsACString& aEncoding);
|
||||
|
||||
/**
|
||||
* Callback for mFlushTimer.
|
||||
|
@ -426,7 +423,7 @@ class nsHtml5StreamParser final : public nsICharsetDetectionObserver {
|
|||
/**
|
||||
* The character encoding in use
|
||||
*/
|
||||
NotNull<const Encoding*> mEncoding;
|
||||
nsCString mCharset;
|
||||
|
||||
/**
|
||||
* Whether reparse is forbidden
|
||||
|
|
|
@ -1078,19 +1078,17 @@ nsHtml5TreeBuilder::FlushLoads()
|
|||
}
|
||||
|
||||
void
|
||||
nsHtml5TreeBuilder::SetDocumentCharset(NotNull<const Encoding*> aEncoding,
|
||||
nsHtml5TreeBuilder::SetDocumentCharset(nsACString& aCharset,
|
||||
int32_t aCharsetSource)
|
||||
{
|
||||
if (mBuilder) {
|
||||
mBuilder->SetDocumentCharsetAndSource(aEncoding, aCharsetSource);
|
||||
mBuilder->SetDocumentCharsetAndSource(aCharset, aCharsetSource);
|
||||
} else if (mSpeculativeLoadStage) {
|
||||
nsAutoCString charset;
|
||||
aEncoding->Name(charset);
|
||||
mSpeculativeLoadQueue.AppendElement()->InitSetDocumentCharset(
|
||||
charset, aCharsetSource);
|
||||
aCharset, aCharsetSource);
|
||||
} else {
|
||||
mOpQueue.AppendElement()->Init(
|
||||
eTreeOpSetDocumentCharset, aEncoding, aCharsetSource);
|
||||
eTreeOpSetDocumentCharset, aCharset, aCharsetSource);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1105,7 +1103,7 @@ nsHtml5TreeBuilder::StreamEnded()
|
|||
}
|
||||
|
||||
void
|
||||
nsHtml5TreeBuilder::NeedsCharsetSwitchTo(NotNull<const Encoding*> aEncoding,
|
||||
nsHtml5TreeBuilder::NeedsCharsetSwitchTo(const nsACString& aCharset,
|
||||
int32_t aCharsetSource,
|
||||
int32_t aLineNumber)
|
||||
{
|
||||
|
@ -1116,7 +1114,7 @@ nsHtml5TreeBuilder::NeedsCharsetSwitchTo(NotNull<const Encoding*> aEncoding,
|
|||
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
|
||||
NS_ASSERTION(treeOp, "Tree op allocation failed.");
|
||||
treeOp->Init(eTreeOpNeedsCharsetSwitchTo,
|
||||
aEncoding,
|
||||
aCharset,
|
||||
aCharsetSource,
|
||||
aLineNumber);
|
||||
}
|
||||
|
|
|
@ -3,10 +3,8 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#define NS_HTML5_TREE_BUILDER_HANDLE_ARRAY_LENGTH 512
|
||||
private:
|
||||
using Encoding = mozilla::Encoding;
|
||||
template <typename T> using NotNull = mozilla::NotNull<T>;
|
||||
|
||||
private:
|
||||
nsHtml5OplessBuilder* mBuilder;
|
||||
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
// If mBuilder is not null, the tree op machinery is not in use and
|
||||
|
@ -106,12 +104,11 @@
|
|||
|
||||
void FlushLoads();
|
||||
|
||||
void SetDocumentCharset(NotNull<const Encoding*> aEncoding,
|
||||
int32_t aCharsetSource);
|
||||
void SetDocumentCharset(nsACString& aCharset, int32_t aCharsetSource);
|
||||
|
||||
void StreamEnded();
|
||||
|
||||
void NeedsCharsetSwitchTo(NotNull<const Encoding*> aEncoding,
|
||||
void NeedsCharsetSwitchTo(const nsACString& aEncoding,
|
||||
int32_t aSource,
|
||||
int32_t aLineNumber);
|
||||
|
||||
|
|
|
@ -720,7 +720,7 @@ nsHtml5TreeOpExecutor::Start()
|
|||
}
|
||||
|
||||
void
|
||||
nsHtml5TreeOpExecutor::NeedsCharsetSwitchTo(NotNull<const Encoding*> aEncoding,
|
||||
nsHtml5TreeOpExecutor::NeedsCharsetSwitchTo(const char* aEncoding,
|
||||
int32_t aSource,
|
||||
uint32_t aLineNumber)
|
||||
{
|
||||
|
@ -738,9 +738,7 @@ nsHtml5TreeOpExecutor::NeedsCharsetSwitchTo(NotNull<const Encoding*> aEncoding,
|
|||
|
||||
// ask the webshellservice to load the URL
|
||||
if (NS_SUCCEEDED(wss->StopDocumentLoad())) {
|
||||
nsAutoCString charset;
|
||||
aEncoding->Name(charset);
|
||||
wss->ReloadDocument(charset.get(), aSource);
|
||||
wss->ReloadDocument(aEncoding, aSource);
|
||||
}
|
||||
// if the charset switch was accepted, wss has called Terminate() on the
|
||||
// parser by now
|
||||
|
@ -914,9 +912,9 @@ nsHtml5TreeOpExecutor::ConvertIfNotPreloadedYet(const nsAString& aURL)
|
|||
}
|
||||
|
||||
nsIURI* base = BaseURIForPreload();
|
||||
auto encoding = mDocument->GetDocumentCharacterSet();
|
||||
const nsCString& charset = mDocument->GetDocumentCharacterSet();
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
nsresult rv = NS_NewURI(getter_AddRefs(uri), aURL, encoding, base);
|
||||
nsresult rv = NS_NewURI(getter_AddRefs(uri), aURL, charset.get(), base);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_WARNING("Failed to create a URI");
|
||||
return nullptr;
|
||||
|
@ -1018,9 +1016,9 @@ nsHtml5TreeOpExecutor::PreloadEndPicture()
|
|||
void
|
||||
nsHtml5TreeOpExecutor::AddBase(const nsAString& aURL)
|
||||
{
|
||||
auto encoding = mDocument->GetDocumentCharacterSet();
|
||||
const nsCString& charset = mDocument->GetDocumentCharacterSet();
|
||||
nsresult rv = NS_NewURI(getter_AddRefs(mViewSourceBaseURI), aURL,
|
||||
encoding, GetViewSourceBaseURI());
|
||||
charset.get(), GetViewSourceBaseURI());
|
||||
if (NS_FAILED(rv)) {
|
||||
mViewSourceBaseURI = nullptr;
|
||||
}
|
||||
|
@ -1032,9 +1030,9 @@ nsHtml5TreeOpExecutor::SetSpeculationBase(const nsAString& aURL)
|
|||
// the first one wins
|
||||
return;
|
||||
}
|
||||
auto encoding = mDocument->GetDocumentCharacterSet();
|
||||
const nsCString& charset = mDocument->GetDocumentCharacterSet();
|
||||
DebugOnly<nsresult> rv = NS_NewURI(getter_AddRefs(mSpeculationBaseURI), aURL,
|
||||
encoding, mDocument->GetDocumentURI());
|
||||
charset.get(), mDocument->GetDocumentURI());
|
||||
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to create a URI");
|
||||
}
|
||||
|
||||
|
|
|
@ -36,8 +36,6 @@ class nsHtml5TreeOpExecutor final : public nsHtml5DocumentBuilder,
|
|||
{
|
||||
friend class nsHtml5FlushLoopGuard;
|
||||
typedef mozilla::net::ReferrerPolicy ReferrerPolicy;
|
||||
using nsIContentSink::Encoding;
|
||||
using nsIContentSink::NotNull;
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
@ -142,9 +140,9 @@ class nsHtml5TreeOpExecutor final : public nsHtml5DocumentBuilder,
|
|||
/**
|
||||
* Don't call. For interface compat only.
|
||||
*/
|
||||
virtual void SetDocumentCharset(NotNull<const Encoding*> aEncoding) override
|
||||
{
|
||||
NS_NOTREACHED("No one should call this.");
|
||||
NS_IMETHOD SetDocumentCharset(nsACString& aCharset) override {
|
||||
NS_NOTREACHED("No one should call this.");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -186,7 +184,7 @@ class nsHtml5TreeOpExecutor final : public nsHtml5DocumentBuilder,
|
|||
|
||||
void Start();
|
||||
|
||||
void NeedsCharsetSwitchTo(NotNull<const Encoding*> aEncoding,
|
||||
void NeedsCharsetSwitchTo(const char* aEncoding,
|
||||
int32_t aSource,
|
||||
uint32_t aLineNumber);
|
||||
|
||||
|
|
|
@ -105,6 +105,7 @@ nsHtml5TreeOperation::~nsHtml5TreeOperation()
|
|||
break;
|
||||
case eTreeOpSetDocumentCharset:
|
||||
case eTreeOpNeedsCharsetSwitchTo:
|
||||
delete[] mOne.charPtr;
|
||||
break;
|
||||
case eTreeOpProcessOfflineManifest:
|
||||
free(mOne.unicharPtr);
|
||||
|
@ -788,16 +789,17 @@ nsHtml5TreeOperation::Perform(nsHtml5TreeOpExecutor* aBuilder,
|
|||
return NS_OK;
|
||||
}
|
||||
case eTreeOpSetDocumentCharset: {
|
||||
auto encoding = WrapNotNull(mOne.encoding);
|
||||
char* str = mOne.charPtr;
|
||||
int32_t charsetSource = mFour.integer;
|
||||
aBuilder->SetDocumentCharsetAndSource(encoding, charsetSource);
|
||||
nsDependentCString dependentString(str);
|
||||
aBuilder->SetDocumentCharsetAndSource(dependentString, charsetSource);
|
||||
return NS_OK;
|
||||
}
|
||||
case eTreeOpNeedsCharsetSwitchTo: {
|
||||
auto encoding = WrapNotNull(mOne.encoding);
|
||||
char* str = mOne.charPtr;
|
||||
int32_t charsetSource = mFour.integer;
|
||||
int32_t lineNumber = mTwo.integer;
|
||||
aBuilder->NeedsCharsetSwitchTo(encoding, charsetSource, (uint32_t)lineNumber);
|
||||
aBuilder->NeedsCharsetSwitchTo(str, charsetSource, (uint32_t)lineNumber);
|
||||
return NS_OK;
|
||||
}
|
||||
case eTreeOpUpdateStyleSheet: {
|
||||
|
@ -882,11 +884,11 @@ nsHtml5TreeOperation::Perform(nsHtml5TreeOpExecutor* aBuilder,
|
|||
|
||||
nsIDocument* doc = aBuilder->GetDocument();
|
||||
|
||||
auto encoding = doc->GetDocumentCharacterSet();
|
||||
const nsCString& charset = doc->GetDocumentCharacterSet();
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
nsresult rv = NS_NewURI(getter_AddRefs(uri),
|
||||
relative,
|
||||
encoding,
|
||||
charset.get(),
|
||||
aBuilder->GetViewSourceBaseURI());
|
||||
NS_ENSURE_SUCCESS(rv, NS_OK);
|
||||
|
||||
|
|
|
@ -8,14 +8,10 @@
|
|||
#include "nsHtml5DocumentMode.h"
|
||||
#include "nsHtml5HtmlAttributes.h"
|
||||
#include "mozilla/dom/FromParser.h"
|
||||
#include "mozilla/NotNull.h"
|
||||
|
||||
class nsIContent;
|
||||
class nsHtml5TreeOpExecutor;
|
||||
class nsHtml5DocumentBuilder;
|
||||
namespace mozilla {
|
||||
class Encoding;
|
||||
}
|
||||
|
||||
enum eHtml5TreeOperation {
|
||||
eTreeOpUninitialized,
|
||||
|
@ -89,9 +85,7 @@ class nsHtml5TreeOperationStringPair {
|
|||
}
|
||||
};
|
||||
|
||||
class nsHtml5TreeOperation final {
|
||||
template <typename T> using NotNull = mozilla::NotNull<T>;
|
||||
using Encoding = mozilla::Encoding;
|
||||
class nsHtml5TreeOperation {
|
||||
|
||||
public:
|
||||
/**
|
||||
|
@ -256,27 +250,6 @@ class nsHtml5TreeOperation final {
|
|||
mTwo.integer = aLineNumber;
|
||||
}
|
||||
|
||||
inline void Init(eHtml5TreeOperation aOpCode,
|
||||
NotNull<const Encoding*> aEncoding,
|
||||
int32_t aInt32)
|
||||
{
|
||||
NS_PRECONDITION(mOpCode == eTreeOpUninitialized,
|
||||
"Op code must be uninitialized when initializing.");
|
||||
|
||||
mOpCode = aOpCode;
|
||||
mOne.encoding = aEncoding;
|
||||
mFour.integer = aInt32;
|
||||
}
|
||||
|
||||
inline void Init(eHtml5TreeOperation aOpCode,
|
||||
NotNull<const Encoding*> aEncoding,
|
||||
int32_t aInt32,
|
||||
int32_t aLineNumber)
|
||||
{
|
||||
Init(aOpCode, aEncoding, aInt32);
|
||||
mTwo.integer = aLineNumber;
|
||||
}
|
||||
|
||||
inline void Init(eHtml5TreeOperation aOpCode,
|
||||
nsIContentHandle* aNode,
|
||||
nsIContentHandle* aParent,
|
||||
|
@ -534,7 +507,6 @@ class nsHtml5TreeOperation final {
|
|||
nsAHtml5TreeBuilderState* state;
|
||||
int32_t integer;
|
||||
nsresult result;
|
||||
const Encoding* encoding;
|
||||
} mOne, mTwo, mThree, mFour, mFive;
|
||||
};
|
||||
|
||||
|
|
|
@ -19,22 +19,15 @@
|
|||
#include "nsISupports.h"
|
||||
#include "nsString.h"
|
||||
#include "mozilla/FlushType.h"
|
||||
#include "mozilla/NotNull.h"
|
||||
#include "nsIDTD.h"
|
||||
|
||||
class nsParserBase;
|
||||
namespace mozilla {
|
||||
class Encoding;
|
||||
}
|
||||
|
||||
#define NS_ICONTENT_SINK_IID \
|
||||
{ 0xcf9a7cbb, 0xfcbc, 0x4e13, \
|
||||
{ 0x8e, 0xf5, 0x18, 0xef, 0x2d, 0x3d, 0x58, 0x29 } }
|
||||
|
||||
class nsIContentSink : public nsISupports {
|
||||
protected:
|
||||
using Encoding = mozilla::Encoding;
|
||||
template <typename T> using NotNull = mozilla::NotNull<T>;
|
||||
public:
|
||||
|
||||
NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICONTENT_SINK_IID)
|
||||
|
@ -110,7 +103,7 @@ public:
|
|||
* Set the document character set. This should be passed on to the
|
||||
* document itself.
|
||||
*/
|
||||
virtual void SetDocumentCharset(NotNull<const Encoding*> aEncoding) = 0;
|
||||
NS_IMETHOD SetDocumentCharset(nsACString& aCharset)=0;
|
||||
|
||||
/**
|
||||
* Returns the target object (often a document object) into which
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#include "nsTArray.h"
|
||||
#include "nsIAtom.h"
|
||||
#include "nsParserBase.h"
|
||||
#include "mozilla/NotNull.h"
|
||||
|
||||
#define NS_IPARSER_IID \
|
||||
{ 0x2c4ad90a, 0x740e, 0x4212, \
|
||||
|
@ -36,9 +35,6 @@ class nsIRequestObserver;
|
|||
class nsString;
|
||||
class nsIURI;
|
||||
class nsIChannel;
|
||||
namespace mozilla {
|
||||
class Encoding;
|
||||
}
|
||||
|
||||
enum eParserCommands {
|
||||
eViewNormal,
|
||||
|
@ -67,9 +63,6 @@ enum eStreamState {eNone,eOnStart,eOnDataAvail,eOnStop};
|
|||
* likely than not that #including this header is the wrong thing to do.
|
||||
*/
|
||||
class nsIParser : public nsParserBase {
|
||||
protected:
|
||||
using Encoding = mozilla::Encoding;
|
||||
template <typename T> using NotNull = mozilla::NotNull<T>;
|
||||
public:
|
||||
|
||||
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IPARSER_IID)
|
||||
|
@ -112,8 +105,8 @@ class nsIParser : public nsParserBase {
|
|||
* @param aCharsetSource- the soure of the chares
|
||||
* @return nada
|
||||
*/
|
||||
virtual void SetDocumentCharset(NotNull<const Encoding*> aCharset,
|
||||
int32_t aSource) = 0;
|
||||
NS_IMETHOD_(void) SetDocumentCharset(const nsACString& aCharset, int32_t aSource)=0;
|
||||
NS_IMETHOD_(void) GetDocumentCharset(nsACString& oCharset, int32_t& oSource)=0;
|
||||
|
||||
/**
|
||||
* Get the channel associated with this parser
|
||||
|
|
|
@ -126,7 +126,6 @@ public:
|
|||
* default constructor
|
||||
*/
|
||||
nsParser::nsParser()
|
||||
: mCharset(WINDOWS_1252_ENCODING)
|
||||
{
|
||||
Initialize(true);
|
||||
}
|
||||
|
@ -151,7 +150,7 @@ nsParser::Initialize(bool aConstructor)
|
|||
|
||||
mContinueEvent = nullptr;
|
||||
mCharsetSource = kCharsetUninitialized;
|
||||
mCharset = WINDOWS_1252_ENCODING;
|
||||
mCharset.AssignLiteral("windows-1252");
|
||||
mInternalState = NS_OK;
|
||||
mStreamStatus = NS_OK;
|
||||
mCommand = eViewNormal;
|
||||
|
@ -284,9 +283,8 @@ nsParser::SetCommand(eParserCommands aParserCommand)
|
|||
* @param aCharset- the charset of a document
|
||||
* @param aCharsetSource- the source of the charset
|
||||
*/
|
||||
void
|
||||
nsParser::SetDocumentCharset(NotNull<const Encoding*> aCharset,
|
||||
int32_t aCharsetSource)
|
||||
NS_IMETHODIMP_(void)
|
||||
nsParser::SetDocumentCharset(const nsACString& aCharset, int32_t aCharsetSource)
|
||||
{
|
||||
mCharset = aCharset;
|
||||
mCharsetSource = aCharsetSource;
|
||||
|
@ -296,7 +294,7 @@ nsParser::SetDocumentCharset(NotNull<const Encoding*> aCharset,
|
|||
}
|
||||
|
||||
void
|
||||
nsParser::SetSinkCharset(NotNull<const Encoding*> aCharset)
|
||||
nsParser::SetSinkCharset(nsACString& aCharset)
|
||||
{
|
||||
if (mSink) {
|
||||
mSink->SetDocumentCharset(aCharset);
|
||||
|
@ -1333,7 +1331,8 @@ ParserWriteFunc(nsIInputStream* in,
|
|||
if (pws->mNeedCharsetCheck) {
|
||||
pws->mNeedCharsetCheck = false;
|
||||
int32_t source;
|
||||
auto preferred = pws->mParser->GetDocumentCharset(source);
|
||||
nsAutoCString preferred;
|
||||
pws->mParser->GetDocumentCharset(preferred, source);
|
||||
|
||||
// This code was bogus when I found it. It expects the BOM or the XML
|
||||
// declaration to be entirely in the first network buffer. -- hsivonen
|
||||
|
@ -1345,7 +1344,7 @@ ParserWriteFunc(nsIInputStream* in,
|
|||
// The decoder will swallow the BOM. The UTF-16 will re-sniff for
|
||||
// endianness. The value of preferred is now "UTF-8", "UTF-16LE"
|
||||
// or "UTF-16BE".
|
||||
preferred = WrapNotNull(encoding);
|
||||
encoding->Name(preferred);
|
||||
source = kCharsetFromByteOrderMark;
|
||||
} else if (source < kCharsetFromChannel) {
|
||||
nsAutoCString declCharset;
|
||||
|
@ -1353,7 +1352,7 @@ ParserWriteFunc(nsIInputStream* in,
|
|||
if (ExtractCharsetFromXmlDeclaration(buf, count, declCharset)) {
|
||||
encoding = Encoding::ForLabel(declCharset);
|
||||
if (encoding) {
|
||||
preferred = WrapNotNull(encoding);
|
||||
encoding->Name(preferred);
|
||||
source = kCharsetFromMetaTag;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -129,13 +129,12 @@ class nsParser final : public nsIParser,
|
|||
* @param aCharsetSource- the source of the charset
|
||||
* @return nada
|
||||
*/
|
||||
virtual void SetDocumentCharset(NotNull<const Encoding*> aCharset,
|
||||
int32_t aSource) override;
|
||||
NS_IMETHOD_(void) SetDocumentCharset(const nsACString& aCharset, int32_t aSource) override;
|
||||
|
||||
NotNull<const Encoding*> GetDocumentCharset(int32_t& aSource)
|
||||
NS_IMETHOD_(void) GetDocumentCharset(nsACString& aCharset, int32_t& aSource) override
|
||||
{
|
||||
aCharset = mCharset;
|
||||
aSource = mCharsetSource;
|
||||
return mCharset;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -242,7 +241,7 @@ class nsParser final : public nsIParser,
|
|||
*/
|
||||
virtual nsIStreamListener* GetStreamListener() override;
|
||||
|
||||
void SetSinkCharset(NotNull<const Encoding*> aCharset);
|
||||
void SetSinkCharset(nsACString& aCharset);
|
||||
|
||||
/**
|
||||
* Removes continue parsing events
|
||||
|
@ -389,7 +388,7 @@ protected:
|
|||
uint32_t mBlocked;
|
||||
|
||||
nsString mUnusedInput;
|
||||
NotNull<const Encoding*> mCharset;
|
||||
nsCString mCharset;
|
||||
nsCString mCommandStr;
|
||||
|
||||
bool mProcessingNetworkData;
|
||||
|
|
|
@ -93,18 +93,26 @@ nsScanner::nsScanner(nsString& aFilename, bool aCreateStream)
|
|||
mUnicodeDecoder = nullptr;
|
||||
mCharsetSource = kCharsetUninitialized;
|
||||
// XML defaults to UTF-8 and about:blank is UTF-8, too.
|
||||
SetDocumentCharset(UTF_8_ENCODING, kCharsetFromDocTypeDefault);
|
||||
SetDocumentCharset(NS_LITERAL_CSTRING("UTF-8"), kCharsetFromDocTypeDefault);
|
||||
}
|
||||
|
||||
nsresult nsScanner::SetDocumentCharset(NotNull<const Encoding*> aEncoding,
|
||||
int32_t aSource)
|
||||
nsresult nsScanner::SetDocumentCharset(const nsACString& aCharset , int32_t aSource)
|
||||
{
|
||||
if (aSource < mCharsetSource) // priority is lower than the current one
|
||||
return NS_OK;
|
||||
|
||||
mCharsetSource = aSource;
|
||||
|
||||
const Encoding* encoding;
|
||||
if (aCharset.EqualsLiteral("replacement")) {
|
||||
encoding = REPLACEMENT_ENCODING;
|
||||
} else {
|
||||
encoding = Encoding::ForLabel(aCharset);
|
||||
MOZ_ASSERT(encoding, "Should never call with a bogus aCharset.");
|
||||
}
|
||||
|
||||
nsCString charsetName;
|
||||
aEncoding->Name(charsetName);
|
||||
encoding->Name(charsetName);
|
||||
if (!mCharset.IsEmpty() && charsetName.Equals(mCharset)) {
|
||||
return NS_OK; // no difference, don't change it
|
||||
}
|
||||
|
@ -113,7 +121,7 @@ nsresult nsScanner::SetDocumentCharset(NotNull<const Encoding*> aEncoding,
|
|||
|
||||
mCharset.Assign(charsetName);
|
||||
|
||||
mUnicodeDecoder = aEncoding->NewDecoderWithBOMRemoval();
|
||||
mUnicodeDecoder = encoding->NewDecoderWithBOMRemoval();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -36,9 +36,7 @@ private:
|
|||
void operator=(const nsReadEndCondition& aOther); // No assigning
|
||||
};
|
||||
|
||||
class nsScanner final {
|
||||
using Encoding = mozilla::Encoding;
|
||||
template <typename T> using NotNull = mozilla::NotNull<T>;
|
||||
class nsScanner {
|
||||
public:
|
||||
|
||||
/**
|
||||
|
@ -144,8 +142,7 @@ class nsScanner final {
|
|||
* @param aCharsetSource- where the charset info came from
|
||||
* @return
|
||||
*/
|
||||
nsresult SetDocumentCharset(NotNull<const Encoding*> aEncoding,
|
||||
int32_t aSource);
|
||||
nsresult SetDocumentCharset(const nsACString& aCharset, int32_t aSource);
|
||||
|
||||
void BindSubstring(nsScannerSubstring& aSubstring, const nsScannerIterator& aStart, const nsScannerIterator& aEnd);
|
||||
void CurrentPosition(nsScannerIterator& aPosition);
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
#include "nsCharsetSource.h"
|
||||
|
||||
using mozilla::Encoding;
|
||||
using mozilla::NotNull;
|
||||
|
||||
#define XMLNS_URI "http://www.w3.org/2000/xmlns/"
|
||||
|
||||
|
@ -629,9 +628,9 @@ nsSAXXMLReader::InitParser(nsIRequestObserver *aObserver, nsIChannel *aChannel)
|
|||
parser->SetContentSink(this);
|
||||
|
||||
int32_t charsetSource = kCharsetFromDocTypeDefault;
|
||||
auto encoding = UTF_8_ENCODING;
|
||||
TryChannelCharset(aChannel, charsetSource, encoding);
|
||||
parser->SetDocumentCharset(encoding, charsetSource);
|
||||
nsAutoCString charset(NS_LITERAL_CSTRING("UTF-8"));
|
||||
TryChannelCharset(aChannel, charsetSource, charset);
|
||||
parser->SetDocumentCharset(charset, charsetSource);
|
||||
|
||||
rv = parser->Parse(mBaseURI, aObserver);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
@ -645,7 +644,7 @@ nsSAXXMLReader::InitParser(nsIRequestObserver *aObserver, nsIChannel *aChannel)
|
|||
bool
|
||||
nsSAXXMLReader::TryChannelCharset(nsIChannel *aChannel,
|
||||
int32_t& aCharsetSource,
|
||||
NotNull<const Encoding*>& aEncoding)
|
||||
nsACString& aCharset)
|
||||
{
|
||||
if (aCharsetSource >= kCharsetFromChannel)
|
||||
return true;
|
||||
|
@ -658,7 +657,7 @@ nsSAXXMLReader::TryChannelCharset(nsIChannel *aChannel,
|
|||
if (!preferred)
|
||||
return false;
|
||||
|
||||
aEncoding = WrapNotNull(preferred);
|
||||
preferred->Name(aCharset);
|
||||
aCharsetSource = kCharsetFromChannel;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include "nsIMozSAXXMLDeclarationHandler.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/NotNull.h"
|
||||
|
||||
#define NS_SAXXMLREADER_CONTRACTID "@mozilla.org/saxparser/xmlreader;1"
|
||||
#define NS_SAXXMLREADER_CID \
|
||||
|
@ -65,8 +64,9 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
virtual void SetDocumentCharset(NotNull<const Encoding*> aEncoding) override
|
||||
NS_IMETHOD SetDocumentCharset(nsACString& aCharset) override
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
virtual nsISupports *GetTarget() override
|
||||
|
@ -87,8 +87,8 @@ private:
|
|||
nsCOMPtr<nsIRequestObserver> mParserObserver;
|
||||
bool mIsAsyncParse;
|
||||
static bool TryChannelCharset(nsIChannel *aChannel,
|
||||
int32_t& aCharsetSource,
|
||||
NotNull<const Encoding*>& aEncoding);
|
||||
int32_t& aCharsetSource,
|
||||
nsACString& aCharset);
|
||||
nsresult EnsureBaseURI();
|
||||
nsresult InitParser(nsIRequestObserver *aListener, nsIChannel *aChannel);
|
||||
nsresult SplitExpatName(const char16_t *aExpatName,
|
||||
|
|
|
@ -106,8 +106,7 @@ public:
|
|||
NS_IMETHOD WillResume(void) override;
|
||||
NS_IMETHOD SetParser(nsParserBase* aParser) override;
|
||||
virtual void FlushPendingNotifications(mozilla::FlushType aType) override { }
|
||||
virtual void SetDocumentCharset(NotNull<const Encoding*> aEncoding)
|
||||
override { }
|
||||
NS_IMETHOD SetDocumentCharset(nsACString& aCharset) override { return NS_OK; }
|
||||
virtual nsISupports *GetTarget() override { return nullptr; }
|
||||
|
||||
// nsIRDFContentSink
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
#include "nsRDFXMLParser.h"
|
||||
|
||||
#include "mozilla/Encoding.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIParser.h"
|
||||
#include "nsCharsetSource.h"
|
||||
|
@ -66,7 +65,7 @@ nsRDFXMLParser::ParseAsync(nsIRDFDataSource* aSink, nsIURI* aBaseURI, nsIStreamL
|
|||
nsCOMPtr<nsIParser> parser = do_CreateInstance(kParserCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
parser->SetDocumentCharset(UTF_8_ENCODING,
|
||||
parser->SetDocumentCharset(NS_LITERAL_CSTRING("UTF-8"),
|
||||
kCharsetFromDocTypeDefault);
|
||||
parser->SetContentSink(sink);
|
||||
|
||||
|
@ -97,7 +96,7 @@ nsRDFXMLParser::ParseString(nsIRDFDataSource* aSink, nsIURI* aBaseURI, const nsA
|
|||
nsCOMPtr<nsIParser> parser = do_CreateInstance(kParserCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
parser->SetDocumentCharset(UTF_8_ENCODING,
|
||||
parser->SetDocumentCharset(NS_LITERAL_CSTRING("UTF-8"),
|
||||
kCharsetFromOtherComponent);
|
||||
parser->SetContentSink(sink);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче