Bug 1376164 - Turn nsDocumentViewer::mHintCharset and mForceCharacterSet into const mozilla::Encoding*. r=hsivonen

MozReview-Commit-ID: HTi2eNwDH99

--HG--
extra : rebase_source : 13c702981c188a395b6026883c3731e816f55240
This commit is contained in:
Masatoshi Kimura 2017-06-25 22:46:08 +09:00
Родитель 0a11de7e87
Коммит 68794e5c6e
4 изменённых файлов: 82 добавлений и 68 удалений

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

@ -9392,8 +9392,8 @@ nsDocShell::SetupNewViewer(nsIContentViewer* aNewViewer)
NS_ERROR_FAILURE); NS_ERROR_FAILURE);
nsCOMPtr<nsIDocShell> parent(do_QueryInterface(parentAsItem)); nsCOMPtr<nsIDocShell> parent(do_QueryInterface(parentAsItem));
nsAutoCString forceCharset; const Encoding* forceCharset = nullptr;
nsAutoCString hintCharset; const Encoding* hintCharset = nullptr;
int32_t hintCharsetSource; int32_t hintCharsetSource;
int32_t minFontSize; int32_t minFontSize;
float textZoom; float textZoom;
@ -9428,10 +9428,8 @@ nsDocShell::SetupNewViewer(nsIContentViewer* aNewViewer)
if (oldCv) { if (oldCv) {
newCv = aNewViewer; newCv = aNewViewer;
if (newCv) { if (newCv) {
NS_ENSURE_SUCCESS(oldCv->GetForceCharacterSet(forceCharset), forceCharset = oldCv->GetForceCharset();
NS_ERROR_FAILURE); hintCharset = oldCv->GetHintCharset();
NS_ENSURE_SUCCESS(oldCv->GetHintCharacterSet(hintCharset),
NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(oldCv->GetHintCharacterSetSource(&hintCharsetSource), NS_ENSURE_SUCCESS(oldCv->GetHintCharacterSetSource(&hintCharsetSource),
NS_ERROR_FAILURE); NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(oldCv->GetMinFontSize(&minFontSize), NS_ENSURE_SUCCESS(oldCv->GetMinFontSize(&minFontSize),
@ -9498,10 +9496,8 @@ nsDocShell::SetupNewViewer(nsIContentViewer* aNewViewer)
// If we have old state to copy, set the old state onto the new content // If we have old state to copy, set the old state onto the new content
// viewer // viewer
if (newCv) { if (newCv) {
NS_ENSURE_SUCCESS(newCv->SetForceCharacterSet(forceCharset), newCv->SetForceCharset(forceCharset);
NS_ERROR_FAILURE); newCv->SetHintCharset(hintCharset);
NS_ENSURE_SUCCESS(newCv->SetHintCharacterSet(hintCharset),
NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(newCv->SetHintCharacterSetSource(hintCharsetSource), NS_ENSURE_SUCCESS(newCv->SetHintCharacterSetSource(hintCharsetSource),
NS_ERROR_FAILURE); NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(newCv->SetMinFontSize(minFontSize), NS_ENSURE_SUCCESS(newCv->SetMinFontSize(minFontSize),

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

@ -21,6 +21,9 @@ class nsIPresShell;
class nsPresContext; class nsPresContext;
class nsView; class nsView;
class nsDOMNavigationTiming; class nsDOMNavigationTiming;
namespace mozilla {
class Encoding;
}
%} %}
[ptr] native nsIWidgetPtr(nsIWidget); [ptr] native nsIWidgetPtr(nsIWidget);
@ -30,6 +33,7 @@ class nsDOMNavigationTiming;
[ptr] native nsViewPtr(nsView); [ptr] native nsViewPtr(nsView);
[ptr] native nsDOMNavigationTimingPtr(nsDOMNavigationTiming); [ptr] native nsDOMNavigationTimingPtr(nsDOMNavigationTiming);
[ref] native nsIContentViewerTArray(nsTArray<nsCOMPtr<nsIContentViewer> >); [ref] native nsIContentViewerTArray(nsTArray<nsCOMPtr<nsIContentViewer> >);
[ptr] native Encoding(const mozilla::Encoding);
[scriptable, builtinclass, uuid(2da17016-7851-4a45-a7a8-00b360e01595)] [scriptable, builtinclass, uuid(2da17016-7851-4a45-a7a8-00b360e01595)]
interface nsIContentViewer : nsISupports interface nsIContentViewer : nsISupports
@ -282,4 +286,9 @@ interface nsIContentViewer : nsISupports
* Restore the viewer's natural media type * Restore the viewer's natural media type
*/ */
void stopEmulatingMedium(); void stopEmulatingMedium();
[noscript, notxpcom] Encoding getHintCharset();
[noscript, notxpcom] void setHintCharset(in Encoding aEncoding);
[noscript, notxpcom] Encoding getForceCharset();
[noscript, notxpcom] void setForceCharset(in Encoding aEncoding);
}; };

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

@ -150,20 +150,6 @@ static bool ConvertToMidasInternalCommand(const nsAString & inCommandID,
// = // =
// ================================================================== // ==================================================================
static bool
IsAsciiCompatible(const nsACString& aPreferredName)
{
// HZ and UTF-7 are no longer in mozilla-central, but keeping them here
// just in case for the benefit of comm-central.
return !(aPreferredName.LowerCaseEqualsLiteral("utf-16") ||
aPreferredName.LowerCaseEqualsLiteral("utf-16be") ||
aPreferredName.LowerCaseEqualsLiteral("utf-16le") ||
aPreferredName.LowerCaseEqualsLiteral("replacement") ||
aPreferredName.LowerCaseEqualsLiteral("hz-gb-2312") ||
aPreferredName.LowerCaseEqualsLiteral("utf-7") ||
aPreferredName.LowerCaseEqualsLiteral("x-imap4-modified-utf7"));
}
static bool static bool
IsAsciiCompatible(const Encoding* aEncoding) IsAsciiCompatible(const Encoding* aEncoding)
{ {
@ -300,23 +286,19 @@ nsHTMLDocument::TryHintCharset(nsIContentViewer* aCv,
nsresult rv = aCv->GetHintCharacterSetSource(&requestCharsetSource); nsresult rv = aCv->GetHintCharacterSetSource(&requestCharsetSource);
if(NS_SUCCEEDED(rv) && kCharsetUninitialized != requestCharsetSource) { if(NS_SUCCEEDED(rv) && kCharsetUninitialized != requestCharsetSource) {
nsAutoCString requestCharset; auto requestCharset = aCv->GetHintCharset();
rv = aCv->GetHintCharacterSet(requestCharset);
aCv->SetHintCharacterSetSource((int32_t)(kCharsetUninitialized)); aCv->SetHintCharacterSetSource((int32_t)(kCharsetUninitialized));
if (requestCharsetSource <= aCharsetSource) if (requestCharsetSource <= aCharsetSource)
return; return;
if (NS_SUCCEEDED(rv) && !requestCharset.IsEmpty()) { if (requestCharset && IsAsciiCompatible(requestCharset)) {
auto encoding = Encoding::ForName(requestCharset);
if (IsAsciiCompatible(encoding)) {
aCharsetSource = requestCharsetSource; aCharsetSource = requestCharsetSource;
aEncoding = encoding; aEncoding = WrapNotNull(requestCharset);
} }
return; return;
} }
} }
}
return; return;
} }
@ -327,8 +309,6 @@ nsHTMLDocument::TryUserForcedCharset(nsIContentViewer* aCv,
int32_t& aCharsetSource, int32_t& aCharsetSource,
NotNull<const Encoding*>& aEncoding) NotNull<const Encoding*>& aEncoding)
{ {
nsresult rv = NS_OK;
if(kCharsetFromUserForced <= aCharsetSource) if(kCharsetFromUserForced <= aCharsetSource)
return; return;
@ -337,16 +317,15 @@ nsHTMLDocument::TryUserForcedCharset(nsIContentViewer* aCv,
return; return;
} }
nsAutoCString forceCharsetFromDocShell; const Encoding* forceCharsetFromDocShell = nullptr;
if (aCv) { if (aCv) {
// XXX mailnews-only // XXX mailnews-only
rv = aCv->GetForceCharacterSet(forceCharsetFromDocShell); forceCharsetFromDocShell = aCv->GetForceCharset();
} }
if(NS_SUCCEEDED(rv) && if(forceCharsetFromDocShell &&
!forceCharsetFromDocShell.IsEmpty() &&
IsAsciiCompatible(forceCharsetFromDocShell)) { IsAsciiCompatible(forceCharsetFromDocShell)) {
aEncoding = Encoding::ForName(forceCharsetFromDocShell); aEncoding = WrapNotNull(forceCharsetFromDocShell);
aCharsetSource = kCharsetFromUserForced; aCharsetSource = kCharsetFromUserForced;
return; return;
} }

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

@ -402,8 +402,8 @@ protected:
/* character set member data */ /* character set member data */
int32_t mHintCharsetSource; int32_t mHintCharsetSource;
nsCString mHintCharset; const Encoding* mHintCharset;
nsCString mForceCharacterSet; const Encoding* mForceCharacterSet;
bool mIsPageMode; bool mIsPageMode;
bool mInitializedForPrintPreview; bool mInitializedForPrintPreview;
@ -542,6 +542,8 @@ nsDocumentViewer::nsDocumentViewer()
#endif // DEBUG #endif // DEBUG
#endif // NS_PRINTING #endif // NS_PRINTING
mHintCharsetSource(kCharsetUninitialized), mHintCharsetSource(kCharsetUninitialized),
mHintCharset(nullptr),
mForceCharacterSet(nullptr),
mIsPageMode(false), mIsPageMode(false),
mInitializedForPrintPreview(false), mInitializedForPrintPreview(false),
mHidden(false), mHidden(false),
@ -3364,15 +3366,27 @@ nsDocumentViewer::StopEmulatingMedium()
NS_IMETHODIMP nsDocumentViewer::GetForceCharacterSet(nsACString& aForceCharacterSet) NS_IMETHODIMP nsDocumentViewer::GetForceCharacterSet(nsACString& aForceCharacterSet)
{ {
aForceCharacterSet = mForceCharacterSet; auto encoding = nsDocumentViewer::GetForceCharset();
if (encoding) {
encoding->Name(aForceCharacterSet);
} else {
aForceCharacterSet.Truncate();
}
return NS_OK; return NS_OK;
} }
/* [noscript,notxpcom] Encoding getForceCharset (); */
NS_IMETHODIMP_(const Encoding *)
nsDocumentViewer::GetForceCharset()
{
return mForceCharacterSet;
}
static void static void
SetChildForceCharacterSet(nsIContentViewer* aChild, void* aClosure) SetChildForceCharacterSet(nsIContentViewer* aChild, void* aClosure)
{ {
const nsACString* charset = static_cast<nsACString*>(aClosure); auto encoding = static_cast<const Encoding*>(aClosure);
aChild->SetForceCharacterSet(*charset); aChild->SetForceCharset(encoding);
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -3391,29 +3405,42 @@ nsDocumentViewer::SetForceCharacterSet(const nsACString& aForceCharacterSet)
return NS_ERROR_INVALID_ARG; return NS_ERROR_INVALID_ARG;
} }
} }
if (encoding) { nsDocumentViewer::SetForceCharset(encoding);
encoding->Name(mForceCharacterSet);
} else {
mForceCharacterSet.Truncate();
}
// now set the force char set on all children of mContainer
CallChildren(SetChildForceCharacterSet, (void*) &aForceCharacterSet);
return NS_OK; return NS_OK;
} }
/* [noscript,notxpcom] void setForceCharset (in Encoding aEncoding); */
NS_IMETHODIMP_(void)
nsDocumentViewer::SetForceCharset(const Encoding *aEncoding)
{
mForceCharacterSet = aEncoding;
// now set the force char set on all children of mContainer
CallChildren(SetChildForceCharacterSet, (void*) aEncoding);
}
NS_IMETHODIMP nsDocumentViewer::GetHintCharacterSet(nsACString& aHintCharacterSet) NS_IMETHODIMP nsDocumentViewer::GetHintCharacterSet(nsACString& aHintCharacterSet)
{ {
auto encoding = nsDocumentViewer::GetHintCharset();
if(kCharsetUninitialized == mHintCharsetSource) { if (encoding) {
aHintCharacterSet.Truncate(); encoding->Name(aHintCharacterSet);
} else { } else {
aHintCharacterSet = mHintCharset; aHintCharacterSet.Truncate();
// this can't possibly be right. we can't set a value just because somebody got a related value!
//mHintCharsetSource = kCharsetUninitialized;
} }
return NS_OK; return NS_OK;
} }
/* [noscript,notxpcom] Encoding getHintCharset (); */
NS_IMETHODIMP_(const Encoding *)
nsDocumentViewer::GetHintCharset()
{
if(kCharsetUninitialized == mHintCharsetSource) {
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;
}
NS_IMETHODIMP nsDocumentViewer::GetHintCharacterSetSource(int32_t *aHintCharacterSetSource) NS_IMETHODIMP nsDocumentViewer::GetHintCharacterSetSource(int32_t *aHintCharacterSetSource)
{ {
NS_ENSURE_ARG_POINTER(aHintCharacterSetSource); NS_ENSURE_ARG_POINTER(aHintCharacterSetSource);
@ -3441,8 +3468,8 @@ nsDocumentViewer::SetHintCharacterSetSource(int32_t aHintCharacterSetSource)
static void static void
SetChildHintCharacterSet(nsIContentViewer* aChild, void* aClosure) SetChildHintCharacterSet(nsIContentViewer* aChild, void* aClosure)
{ {
const nsACString* charset = static_cast<nsACString*>(aClosure); auto encoding = static_cast<const Encoding*>(aClosure);
aChild->SetHintCharacterSet(*charset); aChild->SetHintCharset(encoding);
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -3461,16 +3488,19 @@ nsDocumentViewer::SetHintCharacterSet(const nsACString& aHintCharacterSet)
return NS_ERROR_INVALID_ARG; return NS_ERROR_INVALID_ARG;
} }
} }
if (encoding) { nsDocumentViewer::SetHintCharset(encoding);
encoding->Name(mHintCharset);
} else {
mHintCharset.Truncate();
}
// now set the hint char set on all children of mContainer
CallChildren(SetChildHintCharacterSet, (void*) &aHintCharacterSet);
return NS_OK; return NS_OK;
} }
/* [noscript,notxpcom] void setHintCharset (in Encoding aEncoding); */
NS_IMETHODIMP_(void)
nsDocumentViewer::SetHintCharset(const Encoding *aEncoding)
{
mHintCharset = aEncoding;
// now set the hint char set on all children of mContainer
CallChildren(SetChildHintCharacterSet, (void*) aEncoding);
}
static void static void
AppendChildSubtree(nsIContentViewer* aChild, void* aClosure) AppendChildSubtree(nsIContentViewer* aChild, void* aClosure)
{ {