From 9042fd7a9386d2802018e1c535fe8a917e3cea76 Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Sat, 5 Mar 2005 03:35:54 +0000 Subject: [PATCH] Remove content dependency on the RDF-ness of bookmarks (since in general, they need not be RDF-enabled at all). Remove bizarre dependency of an interface we really want to expose to embeddors on nsIParser. Bug 101995 followup, r=bsmedberg, sr=alecf --- content/html/document/src/nsHTMLDocument.cpp | 53 +++++++------------ content/html/document/src/nsHTMLDocument.h | 2 - intl/chardet/public/nsICharsetResolver.idl | 47 ++++++++-------- parser/htmlparser/public/nsIParser.h | 2 +- xpfe/components/bookmarks/src/Makefile.in | 1 + .../bookmarks/src/nsBookmarksService.cpp | 10 ++-- xpfe/components/build/nsModule.cpp | 3 ++ 7 files changed, 50 insertions(+), 68 deletions(-) diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp index 549150aaa52..efeaf646c26 100644 --- a/content/html/document/src/nsHTMLDocument.cpp +++ b/content/html/document/src/nsHTMLDocument.cpp @@ -161,8 +161,6 @@ MatchElementId(nsIContent *aContent, const nsACString& aUTF8Id, const nsAString& static NS_DEFINE_CID(kCParserCID, NS_PARSER_CID); -nsIRDFService* nsHTMLDocument::gRDF; -nsrefcnt nsHTMLDocument::gRefCntRDFService = 0; PRUint32 nsHTMLDocument::gWyciwygSessionCnt = 0; static int PR_CALLBACK @@ -288,20 +286,11 @@ nsHTMLDocument::nsHTMLDocument() // NOTE! nsDocument::operator new() zeroes out all members, so don't // bother initializing members to 0. - if (gRefCntRDFService++ == 0) - { - CallGetService(kRDFServiceCID, &gRDF); - } - mDefaultElementType = kNameSpaceID_XHTML; } nsHTMLDocument::~nsHTMLDocument() { - if (--gRefCntRDFService == 0) { - NS_IF_RELEASE(gRDF); - } - if (mIdAndNameHashTable.ops) { PL_DHashTableFinish(&mIdAndNameHashTable); } @@ -516,35 +505,29 @@ nsHTMLDocument::TryBookmarkCharset(nsIDocShell* aDocShell, return PR_TRUE; } - if (!gRDF) { - return PR_FALSE; - } - - nsCOMPtr datasource; - nsresult rv = gRDF->GetDataSource("rdf:bookmarks", - getter_AddRefs(datasource)); - - if (NS_FAILED(rv)) { + if (!aChannel) { return PR_FALSE; } nsCOMPtr bookmarksResolver = - do_QueryInterface(datasource); - - if (bookmarksResolver && aDocShell && aChannel) { + do_GetService("@mozilla.org/embeddor.implemented/bookmark-charset-resolver;1"); - PRBool wantCharset; // ignored for now - nsCAutoString charset; - rv = bookmarksResolver->RequestCharset(aDocShell, - aChannel, - &aCharsetSource, - &wantCharset, - nsnull, - charset); - if (NS_SUCCEEDED(rv) && !charset.IsEmpty()) { - aCharset = charset; - return PR_TRUE; - } + if (!bookmarksResolver) { + return PR_FALSE; + } + + PRBool wantCharset; // ignored for now + nsCAutoString charset; + nsCOMPtr webNav(do_QueryInterface(aDocShell)); + nsresult rv = bookmarksResolver->RequestCharset(webNav, + aChannel, + &wantCharset, + nsnull, + charset); + if (NS_SUCCEEDED(rv) && !charset.IsEmpty()) { + aCharset = charset; + aCharsetSource = kCharsetFromBookmarks; + return PR_TRUE; } return PR_FALSE; diff --git a/content/html/document/src/nsHTMLDocument.h b/content/html/document/src/nsHTMLDocument.h index c10305144b8..9e9f5936aaf 100644 --- a/content/html/document/src/nsHTMLDocument.h +++ b/content/html/document/src/nsHTMLDocument.h @@ -281,8 +281,6 @@ protected: // ahmed 12-2 PRInt32 mTexttype; - static nsrefcnt gRefCntRDFService; - static nsIRDFService* gRDF; static PRUint32 gWyciwygSessionCnt; static PRBool TryHintCharset(nsIMarkupDocumentViewer* aMarkupDV, diff --git a/intl/chardet/public/nsICharsetResolver.idl b/intl/chardet/public/nsICharsetResolver.idl index 1e73c5f851f..f89f5045179 100644 --- a/intl/chardet/public/nsICharsetResolver.idl +++ b/intl/chardet/public/nsICharsetResolver.idl @@ -38,37 +38,38 @@ #include "nsISupports.idl" -interface nsIDocShell; +interface nsIWebNavigation; interface nsIChannel; [scriptable, uuid(d143a084-b626-4614-845f-41f3ca43a674)] interface nsICharsetResolver : nsISupports { /** - * requestCharset - * called to resolve the charset of an existing docshell. - * If the charset cannot be resolved, but the implementation is - * still curious what the final charset turned out to be, it can - * set wantCharset to true. - * If so, notifyResovedCharset will be called with the resulting - * closure + * Called to resolve the charset that should be used for parsing the + * document being loaded from aChannel. + * + * If the charset cannot be resolved, but the implementation of + * nsICharsetResolver wants to be notified of the final resolved charset + * when one is available, it can set wantCharset to true. If this is done, + * the caller of requestCharset is responsible for calling + * notifyResovedCharset and passing it the final resolved charset and the + * closure that requestCharset set. * - * @param docShell the docshell the document is being loaded in - * @param channel the channel the document is coming in from - * @param charsetSource a unique number which can be stored by the - * caller to remember which resolver actually - * resolved the charset. - * @param wantCharset gets set to true if notifyResolvedCharset should be - * called with the given closure object - * @param closure a resulting object which should be passed - * to notifyResolvedCharset - * @returns the resolved charset, or the empty string if no - * charset could be determined + * @param aWebNavigation the nsIWebNavigation the document is being loaded + * in. May be null. + * @param aChannel the channel the document is coming in from. + * @param aWantCharset gets set to true if notifyResolvedCharset should be + * called with the given closure object. + * @param aClosure a resulting object which should be passed + * to notifyResolvedCharset if wantCharset is set to + * true. + * @returns the resolved charset, or the empty string if no + * charset could be determined. */ - ACString requestCharset(in nsIDocShell docShell, in nsIChannel channel, - out long charsetSource, - out boolean wantCharset, - out nsISupports closure); + ACString requestCharset(in nsIWebNavigation aWebNavigation, + in nsIChannel aChannel, + out boolean aWantCharset, + out nsISupports aClosure); /** * notifyResolvedCharset diff --git a/parser/htmlparser/public/nsIParser.h b/parser/htmlparser/public/nsIParser.h index 4784b399549..df12c314dad 100644 --- a/parser/htmlparser/public/nsIParser.h +++ b/parser/htmlparser/public/nsIParser.h @@ -95,7 +95,7 @@ enum eParserDocType { // define Charset source constants -// note: the value order define the priority +// note: the value order defines the priority; higher numbers take priority #define kCharsetUninitialized 0 #define kCharsetFromWeakDocTypeDefault 1 #define kCharsetFromUserDefault 2 diff --git a/xpfe/components/bookmarks/src/Makefile.in b/xpfe/components/bookmarks/src/Makefile.in index 42f4552ae89..d34a16f1536 100644 --- a/xpfe/components/bookmarks/src/Makefile.in +++ b/xpfe/components/bookmarks/src/Makefile.in @@ -62,6 +62,7 @@ REQUIRES = xpcom \ chardet \ htmlparser \ locale \ + docshell \ $(NULL) CPPSRCS = nsBookmarksService.cpp diff --git a/xpfe/components/bookmarks/src/nsBookmarksService.cpp b/xpfe/components/bookmarks/src/nsBookmarksService.cpp index 11a17c6d0ea..6620f1269e8 100644 --- a/xpfe/components/bookmarks/src/nsBookmarksService.cpp +++ b/xpfe/components/bookmarks/src/nsBookmarksService.cpp @@ -87,7 +87,7 @@ #include "nsIPrefBranch.h" #include "nsIPrefBranch2.h" -#include "nsIParser.h" // for kCharsetFromBookmarks +#include "nsIWebNavigation.h" // for sorting #include "nsCollationCID.h" @@ -98,9 +98,6 @@ #include "nsAutoBuffer.h" -#include "nsIParser.h" // for kCharsetFromBookmarks - - #ifdef XP_WIN #include #include @@ -3352,9 +3349,8 @@ nsBookmarksService::IsBookmarked(const char* aURL, PRBool* aIsBookmarked) } NS_IMETHODIMP -nsBookmarksService::RequestCharset(nsIDocShell* aDocShell, +nsBookmarksService::RequestCharset(nsIWebNavigation* aWebNavigation, nsIChannel* aChannel, - PRInt32* aCharsetSource, PRBool* aWantCharset, nsISupports** aClosure, nsACString& aResult) @@ -3402,7 +3398,6 @@ nsBookmarksService::RequestCharset(nsIDocShell* aDocShell, const PRUnichar* charset; charsetLiteral->GetValueConst(&charset); LossyCopyUTF16toASCII(charset, aResult); - *aCharsetSource = kCharsetFromBookmarks; return NS_OK; } @@ -3418,6 +3413,7 @@ NS_IMETHODIMP nsBookmarksService::NotifyResolvedCharset(const nsACString& aCharset, nsISupports* aClosure) { + NS_ERROR("Unexpected call to NotifyResolvedCharset -- we never set aWantCharset to true!"); return NS_ERROR_NOT_IMPLEMENTED; } diff --git a/xpfe/components/build/nsModule.cpp b/xpfe/components/build/nsModule.cpp index 4edc0aac64b..14b0888fbc0 100644 --- a/xpfe/components/build/nsModule.cpp +++ b/xpfe/components/build/nsModule.cpp @@ -178,6 +178,9 @@ static const nsModuleComponentInfo components[] = { #if !defined(MOZ_PHOENIX) && !defined(MOZ_XULRUNNER) { "Bookmarks", NS_BOOKMARKS_SERVICE_CID, NS_BOOKMARKS_SERVICE_CONTRACTID, nsBookmarksServiceConstructor }, + { "Bookmarks", NS_BOOKMARKS_SERVICE_CID, + "@mozilla.org/embeddor.implemented/bookmark-charset-resolver;1", + nsBookmarksServiceConstructor }, { "Bookmarks", NS_BOOKMARKS_SERVICE_CID, NS_BOOKMARKS_DATASOURCE_CONTRACTID, nsBookmarksServiceConstructor }, { "Download Manager", NS_DOWNLOADMANAGER_CID, NS_DOWNLOADMANAGER_CONTRACTID,