diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index b41dbc6703f0..c6d2442fae51 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -8209,8 +8209,8 @@ nsresult nsDocShell::SetupNewViewer(nsIContentViewer* aNewViewer, NS_ERROR_FAILURE); nsCOMPtr parent(do_QueryInterface(parentAsItem)); - const Encoding* hintCharset = nullptr; - int32_t hintCharsetSource = kCharsetUninitialized; + const Encoding* reloadEncoding = nullptr; + int32_t reloadEncodingSource = kCharsetUninitialized; // |newMUDV| also serves as a flag to set the data from the above vars nsCOMPtr newCv; @@ -8239,9 +8239,8 @@ nsresult nsDocShell::SetupNewViewer(nsIContentViewer* aNewViewer, if (oldCv) { newCv = aNewViewer; if (newCv) { - hintCharset = oldCv->GetHintCharset(); - NS_ENSURE_SUCCESS(oldCv->GetHintCharacterSetSource(&hintCharsetSource), - NS_ERROR_FAILURE); + reloadEncoding = + oldCv->GetReloadEncodingAndSource(&reloadEncodingSource); } } } @@ -8295,9 +8294,7 @@ nsresult nsDocShell::SetupNewViewer(nsIContentViewer* aNewViewer, // If we have old state to copy, set the old state onto the new content // viewer if (newCv) { - newCv->SetHintCharset(hintCharset); - NS_ENSURE_SUCCESS(newCv->SetHintCharacterSetSource(hintCharsetSource), - NS_ERROR_FAILURE); + newCv->SetReloadEncodingAndSource(reloadEncoding, reloadEncodingSource); } NS_ENSURE_TRUE(mContentViewer, NS_ERROR_FAILURE); @@ -13069,18 +13066,16 @@ bool nsDocShell::PluginsAllowedInCurrentDoc() { // This functions is only called when a new charset is detected in loading a // document. -nsresult nsDocShell::CharsetChangeReloadDocument(const char* aCharset, - int32_t aSource) { +nsresult nsDocShell::CharsetChangeReloadDocument( + mozilla::NotNull aEncoding, int32_t aSource) { // XXX hack. keep the aCharset and aSource wait to pick it up nsCOMPtr cv; NS_ENSURE_SUCCESS(GetContentViewer(getter_AddRefs(cv)), NS_ERROR_FAILURE); if (cv) { - int32_t hint; - cv->GetHintCharacterSetSource(&hint); - if (aSource > hint) { - nsCString charset(aCharset); - cv->SetHintCharacterSet(charset); - cv->SetHintCharacterSetSource(aSource); + int32_t source; + Unused << cv->GetReloadEncodingAndSource(&source); + if (aSource > source) { + cv->SetReloadEncodingAndSource(aEncoding, aSource); if (eCharsetReloadRequested != mCharsetReloadState) { mCharsetReloadState = eCharsetReloadRequested; switch (mLoadType) { diff --git a/docshell/base/nsDocShell.h b/docshell/base/nsDocShell.h index 987195361762..c36291b084e8 100644 --- a/docshell/base/nsDocShell.h +++ b/docshell/base/nsDocShell.h @@ -8,7 +8,9 @@ #define nsDocShell_h__ #include "Units.h" +#include "mozilla/Encoding.h" #include "mozilla/Maybe.h" +#include "mozilla/NotNull.h" #include "mozilla/ScrollbarPreferences.h" #include "mozilla/TimelineConsumers.h" #include "mozilla/UniquePtr.h" @@ -333,8 +335,8 @@ class nsDocShell final : public nsDocLoader, nsresult SetHTMLEditorInternal(mozilla::HTMLEditor* aHTMLEditor); // Handle page navigation due to charset changes - nsresult CharsetChangeReloadDocument(const char* aCharset = nullptr, - int32_t aSource = kCharsetUninitialized); + nsresult CharsetChangeReloadDocument( + mozilla::NotNull aEncoding, int32_t aSource); nsresult CharsetChangeStopDocumentLoad(); nsDOMNavigationTiming* GetNavigationTiming() const; diff --git a/docshell/base/nsIContentViewer.idl b/docshell/base/nsIContentViewer.idl index dd1bda876823..b7bd59efc9e0 100644 --- a/docshell/base/nsIContentViewer.idl +++ b/docshell/base/nsIContentViewer.idl @@ -263,16 +263,6 @@ interface nsIContentViewer : nsISupports */ attribute boolean authorStyleDisabled; - /** - * XXX comm-central only: bug 829543. - */ - attribute ACString hintCharacterSet; - - /** - * XXX comm-central only: bug 829543. - */ - attribute int32_t hintCharacterSetSource; - /** * Requests the size of the content to the container. */ @@ -288,8 +278,9 @@ interface nsIContentViewer : nsISupports void getContentSizeConstrained(in long maxWidth, in long maxHeight, out long width, out long height); - [noscript, notxpcom] Encoding getHintCharset(); - [noscript, notxpcom] void setHintCharset(in Encoding aEncoding); + [noscript, notxpcom] Encoding getReloadEncodingAndSource(out int32_t aSource); + [noscript, notxpcom] void setReloadEncodingAndSource(in Encoding aEncoding, in int32_t aSource); + [noscript, notxpcom] void forgetReloadEncoding(); }; %{C++ diff --git a/dom/html/nsHTMLDocument.cpp b/dom/html/nsHTMLDocument.cpp index f1f76604a996..675d32bbb15c 100644 --- a/dom/html/nsHTMLDocument.cpp +++ b/dom/html/nsHTMLDocument.cpp @@ -182,22 +182,21 @@ void nsHTMLDocument::ResetToURI(nsIURI* aURI, nsILoadGroup* aLoadGroup, SetContentTypeInternal(nsDependentCString("text/html")); } -void nsHTMLDocument::TryHintCharset(nsIContentViewer* aCv, - int32_t& aCharsetSource, - NotNull& aEncoding) { +void nsHTMLDocument::TryReloadCharset(nsIContentViewer* aCv, + int32_t& aCharsetSource, + NotNull& aEncoding) { if (aCv) { - int32_t requestCharsetSource; - nsresult rv = aCv->GetHintCharacterSetSource(&requestCharsetSource); + int32_t reloadEncodingSource; + const auto reloadEncoding = + aCv->GetReloadEncodingAndSource(&reloadEncodingSource); + if (kCharsetUninitialized != reloadEncodingSource) { + aCv->ForgetReloadEncoding(); - if (NS_SUCCEEDED(rv) && kCharsetUninitialized != requestCharsetSource) { - auto requestCharset = aCv->GetHintCharset(); - aCv->SetHintCharacterSetSource((int32_t)(kCharsetUninitialized)); + if (reloadEncodingSource <= aCharsetSource) return; - if (requestCharsetSource <= aCharsetSource) return; - - if (requestCharset && IsAsciiCompatible(requestCharset)) { - aCharsetSource = requestCharsetSource; - aEncoding = WrapNotNull(requestCharset); + if (reloadEncoding && IsAsciiCompatible(reloadEncoding)) { + aCharsetSource = reloadEncodingSource; + aEncoding = WrapNotNull(reloadEncoding); } } } @@ -464,7 +463,7 @@ nsresult nsHTMLDocument::StartDocumentLoad(const char* aCommand, // The following will try to get the character encoding from various // sources. Each Try* function will return early if the source is already // at least as large as any of the sources it might look at. Some of - // these functions (like TryHintCharset and TryParentCharset) can set + // these functions (like TryReloadCharset and TryParentCharset) can set // charsetSource to various values depending on where the charset they // end up finding originally comes from. @@ -480,7 +479,7 @@ nsresult nsHTMLDocument::StartDocumentLoad(const char* aCommand, TryUserForcedCharset(cv, docShell, charsetSource, encoding); - TryHintCharset(cv, charsetSource, encoding); // For encoding reload + TryReloadCharset(cv, charsetSource, encoding); // For encoding reload TryParentCharset(docShell, charsetSource, encoding); } diff --git a/dom/html/nsHTMLDocument.h b/dom/html/nsHTMLDocument.h index f23a062addcf..62fd6686c462 100644 --- a/dom/html/nsHTMLDocument.h +++ b/dom/html/nsHTMLDocument.h @@ -171,9 +171,8 @@ class nsHTMLDocument : public mozilla::dom::Document { /** # of forms in the document, synchronously set */ int32_t mNumForms; - static void TryHintCharset(nsIContentViewer* aContentViewer, - int32_t& aCharsetSource, - NotNull& aEncoding); + static void TryReloadCharset(nsIContentViewer* aCv, int32_t& aCharsetSource, + NotNull& aEncoding); void TryUserForcedCharset(nsIContentViewer* aCv, nsIDocShell* aDocShell, int32_t& aCharsetSource, NotNull& aEncoding); @@ -182,9 +181,6 @@ class nsHTMLDocument : public mozilla::dom::Document { NotNull& aEncoding); void TryParentCharset(nsIDocShell* aDocShell, int32_t& charsetSource, NotNull& aEncoding); - void TryTLD(int32_t& aCharsetSource, NotNull& aCharset); - static void TryFallback(int32_t& aCharsetSource, - NotNull& aEncoding); // Load flags of the document's channel uint32_t mLoadFlags; diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index 084fb2527c73..568fb2d711e7 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -463,8 +463,8 @@ class nsDocumentViewer final : public nsIContentViewer, #endif // NS_PRINTING /* character set member data */ - int32_t mHintCharsetSource; - const Encoding* mHintCharset; + int32_t mReloadEncodingSource; + const Encoding* mReloadEncoding; bool mIsPageMode; bool mInitializedForPrintPreview; @@ -527,8 +527,8 @@ nsDocumentViewer::nsDocumentViewer() #ifdef NS_PRINTING mClosingWhilePrinting(false), #endif // NS_PRINTING - mHintCharsetSource(kCharsetUninitialized), - mHintCharset(nullptr), + mReloadEncodingSource(kCharsetUninitialized), + mReloadEncoding(nullptr), mIsPageMode(false), mInitializedForPrintPreview(false), mHidden(false) { @@ -2564,83 +2564,27 @@ nsDocumentViewer::GetAuthorStyleDisabled(bool* aStyleDisabled) { return NS_OK; } -NS_IMETHODIMP nsDocumentViewer::GetHintCharacterSet( - nsACString& aHintCharacterSet) { - auto encoding = nsDocumentViewer::GetHintCharset(); - if (encoding) { - encoding->Name(aHintCharacterSet); - } else { - aHintCharacterSet.Truncate(); - } - return NS_OK; -} - /* [noscript,notxpcom] Encoding getHintCharset (); */ NS_IMETHODIMP_(const Encoding*) -nsDocumentViewer::GetHintCharset() { - if (kCharsetUninitialized == mHintCharsetSource) { +nsDocumentViewer::GetReloadEncodingAndSource(int32_t* aSource) { + *aSource = mReloadEncodingSource; + if (kCharsetUninitialized == mReloadEncodingSource) { return nullptr; } - // this can't possibly be right. we can't set a value just because somebody - // got a related value! - // mHintCharsetSource = kCharsetUninitialized; - return mHintCharset; + return mReloadEncoding; } -NS_IMETHODIMP nsDocumentViewer::GetHintCharacterSetSource( - int32_t* aHintCharacterSetSource) { - NS_ENSURE_ARG_POINTER(aHintCharacterSetSource); - *aHintCharacterSetSource = mHintCharsetSource; - return NS_OK; -} - -NS_IMETHODIMP -nsDocumentViewer::SetHintCharacterSetSource(int32_t aHintCharacterSetSource) { - mHintCharsetSource = aHintCharacterSetSource; - - // now set the force char set on all children of mContainer - if (RefPtr docShell = nsDocShell::Cast(mContainer)) { - int32_t n = docShell->GetInProcessChildCount(); - for (int32_t i = 0; i < n; i++) { - if (RefPtr child = docShell->GetInProcessChildAt(i)) { - if (nsCOMPtr childCV = child->GetContentViewer()) { - childCV->SetHintCharacterSetSource(aHintCharacterSetSource); - } - } - } - } - return NS_OK; -} - -NS_IMETHODIMP -nsDocumentViewer::SetHintCharacterSet(const nsACString& aHintCharacterSet) { - // The empty string means no hint. - const Encoding* encoding = nullptr; - if (!aHintCharacterSet.IsEmpty()) { - if (!(encoding = Encoding::ForLabel(aHintCharacterSet))) { - // Reject unknown labels - return NS_ERROR_INVALID_ARG; - } - } - nsDocumentViewer::SetHintCharset(encoding); - return NS_OK; -} - -/* [noscript,notxpcom] void setHintCharset (in Encoding aEncoding); */ NS_IMETHODIMP_(void) -nsDocumentViewer::SetHintCharset(const Encoding* aEncoding) { - mHintCharset = aEncoding; - // now set the force char set on all children of mContainer - if (RefPtr docShell = nsDocShell::Cast(mContainer)) { - int32_t n = docShell->GetInProcessChildCount(); - for (int32_t i = 0; i < n; i++) { - if (RefPtr child = docShell->GetInProcessChildAt(i)) { - if (nsCOMPtr childCV = child->GetContentViewer()) { - childCV->SetHintCharset(aEncoding); - } - } - } - } +nsDocumentViewer::SetReloadEncodingAndSource(const Encoding* aEncoding, + int32_t aSource) { + mReloadEncoding = aEncoding; + mReloadEncodingSource = aSource; +} + +NS_IMETHODIMP_(void) +nsDocumentViewer::ForgetReloadEncoding() { + mReloadEncoding = nullptr; + mReloadEncodingSource = kCharsetUninitialized; } nsresult nsDocumentViewer::GetContentSizeInternal(int32_t* aWidth, diff --git a/parser/html/nsHtml5TreeOpExecutor.cpp b/parser/html/nsHtml5TreeOpExecutor.cpp index 70c13fea7246..3aee51e46267 100644 --- a/parser/html/nsHtml5TreeOpExecutor.cpp +++ b/parser/html/nsHtml5TreeOpExecutor.cpp @@ -905,9 +905,7 @@ void nsHtml5TreeOpExecutor::NeedsCharsetSwitchTo( nsDocShell* docShell = static_cast(mDocShell.get()); if (NS_SUCCEEDED(docShell->CharsetChangeStopDocumentLoad())) { - nsAutoCString charset; - aEncoding->Name(charset); - docShell->CharsetChangeReloadDocument(charset.get(), aSource); + docShell->CharsetChangeReloadDocument(aEncoding, aSource); } // if the charset switch was accepted, mDocShell has called Terminate() on the // parser by now