зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
0a11de7e87
Коммит
68794e5c6e
|
@ -9392,8 +9392,8 @@ nsDocShell::SetupNewViewer(nsIContentViewer* aNewViewer)
|
|||
NS_ERROR_FAILURE);
|
||||
nsCOMPtr<nsIDocShell> parent(do_QueryInterface(parentAsItem));
|
||||
|
||||
nsAutoCString forceCharset;
|
||||
nsAutoCString hintCharset;
|
||||
const Encoding* forceCharset = nullptr;
|
||||
const Encoding* hintCharset = nullptr;
|
||||
int32_t hintCharsetSource;
|
||||
int32_t minFontSize;
|
||||
float textZoom;
|
||||
|
@ -9428,10 +9428,8 @@ nsDocShell::SetupNewViewer(nsIContentViewer* aNewViewer)
|
|||
if (oldCv) {
|
||||
newCv = aNewViewer;
|
||||
if (newCv) {
|
||||
NS_ENSURE_SUCCESS(oldCv->GetForceCharacterSet(forceCharset),
|
||||
NS_ERROR_FAILURE);
|
||||
NS_ENSURE_SUCCESS(oldCv->GetHintCharacterSet(hintCharset),
|
||||
NS_ERROR_FAILURE);
|
||||
forceCharset = oldCv->GetForceCharset();
|
||||
hintCharset = oldCv->GetHintCharset();
|
||||
NS_ENSURE_SUCCESS(oldCv->GetHintCharacterSetSource(&hintCharsetSource),
|
||||
NS_ERROR_FAILURE);
|
||||
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
|
||||
// viewer
|
||||
if (newCv) {
|
||||
NS_ENSURE_SUCCESS(newCv->SetForceCharacterSet(forceCharset),
|
||||
NS_ERROR_FAILURE);
|
||||
NS_ENSURE_SUCCESS(newCv->SetHintCharacterSet(hintCharset),
|
||||
NS_ERROR_FAILURE);
|
||||
newCv->SetForceCharset(forceCharset);
|
||||
newCv->SetHintCharset(hintCharset);
|
||||
NS_ENSURE_SUCCESS(newCv->SetHintCharacterSetSource(hintCharsetSource),
|
||||
NS_ERROR_FAILURE);
|
||||
NS_ENSURE_SUCCESS(newCv->SetMinFontSize(minFontSize),
|
||||
|
|
|
@ -21,6 +21,9 @@ class nsIPresShell;
|
|||
class nsPresContext;
|
||||
class nsView;
|
||||
class nsDOMNavigationTiming;
|
||||
namespace mozilla {
|
||||
class Encoding;
|
||||
}
|
||||
%}
|
||||
|
||||
[ptr] native nsIWidgetPtr(nsIWidget);
|
||||
|
@ -30,6 +33,7 @@ class nsDOMNavigationTiming;
|
|||
[ptr] native nsViewPtr(nsView);
|
||||
[ptr] native nsDOMNavigationTimingPtr(nsDOMNavigationTiming);
|
||||
[ref] native nsIContentViewerTArray(nsTArray<nsCOMPtr<nsIContentViewer> >);
|
||||
[ptr] native Encoding(const mozilla::Encoding);
|
||||
|
||||
[scriptable, builtinclass, uuid(2da17016-7851-4a45-a7a8-00b360e01595)]
|
||||
interface nsIContentViewer : nsISupports
|
||||
|
@ -282,4 +286,9 @@ interface nsIContentViewer : nsISupports
|
|||
* Restore the viewer's natural media type
|
||||
*/
|
||||
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
|
||||
IsAsciiCompatible(const Encoding* aEncoding)
|
||||
{
|
||||
|
@ -300,21 +286,17 @@ nsHTMLDocument::TryHintCharset(nsIContentViewer* aCv,
|
|||
nsresult rv = aCv->GetHintCharacterSetSource(&requestCharsetSource);
|
||||
|
||||
if(NS_SUCCEEDED(rv) && kCharsetUninitialized != requestCharsetSource) {
|
||||
nsAutoCString requestCharset;
|
||||
rv = aCv->GetHintCharacterSet(requestCharset);
|
||||
auto requestCharset = aCv->GetHintCharset();
|
||||
aCv->SetHintCharacterSetSource((int32_t)(kCharsetUninitialized));
|
||||
|
||||
if (requestCharsetSource <= aCharsetSource)
|
||||
return;
|
||||
|
||||
if (NS_SUCCEEDED(rv) && !requestCharset.IsEmpty()) {
|
||||
auto encoding = Encoding::ForName(requestCharset);
|
||||
if (IsAsciiCompatible(encoding)) {
|
||||
aCharsetSource = requestCharsetSource;
|
||||
aEncoding = encoding;
|
||||
}
|
||||
return;
|
||||
if (requestCharset && IsAsciiCompatible(requestCharset)) {
|
||||
aCharsetSource = requestCharsetSource;
|
||||
aEncoding = WrapNotNull(requestCharset);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
@ -327,8 +309,6 @@ nsHTMLDocument::TryUserForcedCharset(nsIContentViewer* aCv,
|
|||
int32_t& aCharsetSource,
|
||||
NotNull<const Encoding*>& aEncoding)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if(kCharsetFromUserForced <= aCharsetSource)
|
||||
return;
|
||||
|
||||
|
@ -337,16 +317,15 @@ nsHTMLDocument::TryUserForcedCharset(nsIContentViewer* aCv,
|
|||
return;
|
||||
}
|
||||
|
||||
nsAutoCString forceCharsetFromDocShell;
|
||||
const Encoding* forceCharsetFromDocShell = nullptr;
|
||||
if (aCv) {
|
||||
// XXX mailnews-only
|
||||
rv = aCv->GetForceCharacterSet(forceCharsetFromDocShell);
|
||||
forceCharsetFromDocShell = aCv->GetForceCharset();
|
||||
}
|
||||
|
||||
if(NS_SUCCEEDED(rv) &&
|
||||
!forceCharsetFromDocShell.IsEmpty() &&
|
||||
if(forceCharsetFromDocShell &&
|
||||
IsAsciiCompatible(forceCharsetFromDocShell)) {
|
||||
aEncoding = Encoding::ForName(forceCharsetFromDocShell);
|
||||
aEncoding = WrapNotNull(forceCharsetFromDocShell);
|
||||
aCharsetSource = kCharsetFromUserForced;
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -402,9 +402,9 @@ protected:
|
|||
|
||||
/* character set member data */
|
||||
int32_t mHintCharsetSource;
|
||||
nsCString mHintCharset;
|
||||
nsCString mForceCharacterSet;
|
||||
|
||||
const Encoding* mHintCharset;
|
||||
const Encoding* mForceCharacterSet;
|
||||
|
||||
bool mIsPageMode;
|
||||
bool mInitializedForPrintPreview;
|
||||
bool mHidden;
|
||||
|
@ -542,6 +542,8 @@ nsDocumentViewer::nsDocumentViewer()
|
|||
#endif // DEBUG
|
||||
#endif // NS_PRINTING
|
||||
mHintCharsetSource(kCharsetUninitialized),
|
||||
mHintCharset(nullptr),
|
||||
mForceCharacterSet(nullptr),
|
||||
mIsPageMode(false),
|
||||
mInitializedForPrintPreview(false),
|
||||
mHidden(false),
|
||||
|
@ -3364,15 +3366,27 @@ nsDocumentViewer::StopEmulatingMedium()
|
|||
|
||||
NS_IMETHODIMP nsDocumentViewer::GetForceCharacterSet(nsACString& aForceCharacterSet)
|
||||
{
|
||||
aForceCharacterSet = mForceCharacterSet;
|
||||
auto encoding = nsDocumentViewer::GetForceCharset();
|
||||
if (encoding) {
|
||||
encoding->Name(aForceCharacterSet);
|
||||
} else {
|
||||
aForceCharacterSet.Truncate();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* [noscript,notxpcom] Encoding getForceCharset (); */
|
||||
NS_IMETHODIMP_(const Encoding *)
|
||||
nsDocumentViewer::GetForceCharset()
|
||||
{
|
||||
return mForceCharacterSet;
|
||||
}
|
||||
|
||||
static void
|
||||
SetChildForceCharacterSet(nsIContentViewer* aChild, void* aClosure)
|
||||
{
|
||||
const nsACString* charset = static_cast<nsACString*>(aClosure);
|
||||
aChild->SetForceCharacterSet(*charset);
|
||||
auto encoding = static_cast<const Encoding*>(aClosure);
|
||||
aChild->SetForceCharset(encoding);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -3391,29 +3405,42 @@ nsDocumentViewer::SetForceCharacterSet(const nsACString& aForceCharacterSet)
|
|||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
}
|
||||
if (encoding) {
|
||||
encoding->Name(mForceCharacterSet);
|
||||
} else {
|
||||
mForceCharacterSet.Truncate();
|
||||
}
|
||||
// now set the force char set on all children of mContainer
|
||||
CallChildren(SetChildForceCharacterSet, (void*) &aForceCharacterSet);
|
||||
nsDocumentViewer::SetForceCharset(encoding);
|
||||
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)
|
||||
{
|
||||
|
||||
if(kCharsetUninitialized == mHintCharsetSource) {
|
||||
aHintCharacterSet.Truncate();
|
||||
auto encoding = nsDocumentViewer::GetHintCharset();
|
||||
if (encoding) {
|
||||
encoding->Name(aHintCharacterSet);
|
||||
} else {
|
||||
aHintCharacterSet = mHintCharset;
|
||||
// this can't possibly be right. we can't set a value just because somebody got a related value!
|
||||
//mHintCharsetSource = kCharsetUninitialized;
|
||||
aHintCharacterSet.Truncate();
|
||||
}
|
||||
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_ENSURE_ARG_POINTER(aHintCharacterSetSource);
|
||||
|
@ -3441,8 +3468,8 @@ nsDocumentViewer::SetHintCharacterSetSource(int32_t aHintCharacterSetSource)
|
|||
static void
|
||||
SetChildHintCharacterSet(nsIContentViewer* aChild, void* aClosure)
|
||||
{
|
||||
const nsACString* charset = static_cast<nsACString*>(aClosure);
|
||||
aChild->SetHintCharacterSet(*charset);
|
||||
auto encoding = static_cast<const Encoding*>(aClosure);
|
||||
aChild->SetHintCharset(encoding);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -3461,16 +3488,19 @@ nsDocumentViewer::SetHintCharacterSet(const nsACString& aHintCharacterSet)
|
|||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
}
|
||||
if (encoding) {
|
||||
encoding->Name(mHintCharset);
|
||||
} else {
|
||||
mHintCharset.Truncate();
|
||||
}
|
||||
// now set the hint char set on all children of mContainer
|
||||
CallChildren(SetChildHintCharacterSet, (void*) &aHintCharacterSet);
|
||||
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 hint char set on all children of mContainer
|
||||
CallChildren(SetChildHintCharacterSet, (void*) aEncoding);
|
||||
}
|
||||
|
||||
static void
|
||||
AppendChildSubtree(nsIContentViewer* aChild, void* aClosure)
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче