Bug 829543 - Rename hintCharset to reloadEncoding and remove unnecessary code. r=emk

Differential Revision: https://phabricator.services.mozilla.com/D113639
This commit is contained in:
Henri Sivonen 2021-04-28 12:15:47 +00:00
Родитель f58f702a2f
Коммит 217757f82d
7 изменённых файлов: 53 добавлений и 128 удалений

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

@ -8209,8 +8209,8 @@ nsresult nsDocShell::SetupNewViewer(nsIContentViewer* aNewViewer,
NS_ERROR_FAILURE);
nsCOMPtr<nsIDocShell> 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<nsIContentViewer> 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<const mozilla::Encoding*> aEncoding, int32_t aSource) {
// XXX hack. keep the aCharset and aSource wait to pick it up
nsCOMPtr<nsIContentViewer> 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) {

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

@ -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<const mozilla::Encoding*> aEncoding, int32_t aSource);
nsresult CharsetChangeStopDocumentLoad();
nsDOMNavigationTiming* GetNavigationTiming() const;

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

@ -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++

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

@ -182,22 +182,21 @@ void nsHTMLDocument::ResetToURI(nsIURI* aURI, nsILoadGroup* aLoadGroup,
SetContentTypeInternal(nsDependentCString("text/html"));
}
void nsHTMLDocument::TryHintCharset(nsIContentViewer* aCv,
int32_t& aCharsetSource,
NotNull<const Encoding*>& aEncoding) {
void nsHTMLDocument::TryReloadCharset(nsIContentViewer* aCv,
int32_t& aCharsetSource,
NotNull<const Encoding*>& 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);
}

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

@ -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<const Encoding*>& aEncoding);
static void TryReloadCharset(nsIContentViewer* aCv, int32_t& aCharsetSource,
NotNull<const Encoding*>& aEncoding);
void TryUserForcedCharset(nsIContentViewer* aCv, nsIDocShell* aDocShell,
int32_t& aCharsetSource,
NotNull<const Encoding*>& aEncoding);
@ -182,9 +181,6 @@ class nsHTMLDocument : public mozilla::dom::Document {
NotNull<const Encoding*>& aEncoding);
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);
// Load flags of the document's channel
uint32_t mLoadFlags;

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

@ -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<nsDocShell> child = docShell->GetInProcessChildAt(i)) {
if (nsCOMPtr<nsIContentViewer> 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<nsDocShell> child = docShell->GetInProcessChildAt(i)) {
if (nsCOMPtr<nsIContentViewer> 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,

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

@ -905,9 +905,7 @@ void nsHtml5TreeOpExecutor::NeedsCharsetSwitchTo(
nsDocShell* docShell = static_cast<nsDocShell*>(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