From 65d0350b8cc60cfb2cf8a572fc1bc6e4667cc7f6 Mon Sep 17 00:00:00 2001 From: "bstell%netscape.com" Date: Thu, 17 May 2001 02:12:51 +0000 Subject: [PATCH] bug 79608, r=ftang, sr=vidur for the embedding API: add get/set charset git-svn-id: svn://10.0.0.236/trunk@95194 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/docshell/base/nsDocShell.cpp | 46 ++++++++++++++++++++++++++++ mozilla/docshell/base/nsDocShell.h | 3 ++ 2 files changed, 49 insertions(+) diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index 5d0767c5491..a34789209c9 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -216,6 +216,7 @@ NS_INTERFACE_MAP_BEGIN(nsDocShell) NS_INTERFACE_MAP_ENTRY(nsIBaseWindow) NS_INTERFACE_MAP_ENTRY(nsIScrollable) NS_INTERFACE_MAP_ENTRY(nsITextScroll) + NS_INTERFACE_MAP_ENTRY(nsIDocCharset) NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor) NS_INTERFACE_MAP_ENTRY(nsIScriptGlobalObjectOwner) NS_INTERFACE_MAP_ENTRY(nsIRefreshURI) @@ -1015,6 +1016,51 @@ nsDocShell::SetParentURIContentListener(nsIURIContentListener * aParent) return mContentListener->SetParentContentListener(aParent); } +NS_IMETHODIMP +nsDocShell::GetCharset(PRUnichar** aCharset) +{ + NS_ENSURE_ARG_POINTER(aCharset); + *aCharset = nsnull; + + nsCOMPtr presShell; + nsCOMPtr doc; + GetPresShell(getter_AddRefs(presShell)); + NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE); + presShell->GetDocument(getter_AddRefs(doc)); + NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE); + nsAutoString charset; + NS_ENSURE_SUCCESS(doc->GetDocumentCharacterSet(charset), NS_ERROR_FAILURE); + *aCharset = charset.ToNewUnicode(); + + return NS_OK; +} + +NS_IMETHODIMP +nsDocShell::SetCharset(const PRUnichar* aCharset) +{ + // set the default charset + nsCOMPtr viewer; + GetContentViewer(getter_AddRefs(viewer)); + if (viewer) { + nsCOMPtr muDV(do_QueryInterface(viewer)); + if (muDV) { + NS_ENSURE_SUCCESS(muDV->SetDefaultCharacterSet(aCharset), + NS_ERROR_FAILURE); + } + } + + // set the charset override + nsCOMPtr dcInfo; + GetDocumentCharsetInfo(getter_AddRefs(dcInfo)); + if (dcInfo) { + nsCOMPtr csAtom; + csAtom = dont_AddRef(NS_NewAtom(aCharset)); + dcInfo->SetForcedCharset(csAtom); + } + + return NS_OK; +} + NS_IMETHODIMP nsDocShell::GetDocumentCharsetInfo(nsIDocumentCharsetInfo ** aDocumentCharsetInfo) diff --git a/mozilla/docshell/base/nsDocShell.h b/mozilla/docshell/base/nsDocShell.h index 6142eedcbe2..27b29d572c7 100644 --- a/mozilla/docshell/base/nsDocShell.h +++ b/mozilla/docshell/base/nsDocShell.h @@ -55,6 +55,7 @@ // Interfaces Needed #include "nsIDocumentCharsetInfo.h" +#include "nsIDocCharset.h" #include "nsIGlobalHistory.h" #include "nsIInterfaceRequestor.h" #include "nsIPrompt.h" @@ -151,6 +152,7 @@ class nsDocShell : public nsIDocShell, public nsIBaseWindow, public nsIScrollable, public nsITextScroll, + public nsIDocCharset, public nsIContentViewerContainer, public nsIInterfaceRequestor, public nsIScriptGlobalObjectOwner, @@ -174,6 +176,7 @@ public: NS_DECL_NSIBASEWINDOW NS_DECL_NSISCROLLABLE NS_DECL_NSITEXTSCROLL + NS_DECL_NSIDOCCHARSET NS_DECL_NSIINTERFACEREQUESTOR NS_DECL_NSISCRIPTGLOBALOBJECTOWNER NS_DECL_NSIWEBPROGRESSLISTENER