From 56320c5c9a61e045f60c3f65fcc36c2beab3fc64 Mon Sep 17 00:00:00 2001 From: "alecf%flett.org" Date: Thu, 29 May 2003 22:11:23 +0000 Subject: [PATCH] big part of fix for bug 101995 - remove bookmarks dependency from nsHTMLDocument git-svn-id: svn://10.0.0.236/trunk@143055 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/html/document/src/Makefile.in | 6 -- .../html/document/src/nsHTMLDocument.cpp | 29 ++++--- .../html/document/src/nsHTMLDocument.h | 3 +- mozilla/intl/chardet/public/Makefile.in | 1 + .../chardet/public/nsICharsetResolver.idl | 83 +++++++++++++++++++ .../bookmarks/public/nsIBookmarksService.idl | 2 - .../xpfe/components/bookmarks/src/Makefile.in | 2 + .../bookmarks/src/nsBookmarksService.cpp | 68 ++++++++++----- .../bookmarks/src/nsBookmarksService.h | 4 + mozilla/xpfe/components/build/Makefile.in | 1 + 10 files changed, 157 insertions(+), 42 deletions(-) create mode 100644 mozilla/intl/chardet/public/nsICharsetResolver.idl diff --git a/mozilla/content/html/document/src/Makefile.in b/mozilla/content/html/document/src/Makefile.in index 32cdf4f4482..a19211b99e8 100644 --- a/mozilla/content/html/document/src/Makefile.in +++ b/mozilla/content/html/document/src/Makefile.in @@ -60,12 +60,6 @@ REQUIRES = xpcom \ plugin \ $(NULL) -ifdef MOZ_PHOENIX -REQUIRES += bookmarks -else -REQUIRES += appcomps -endif - CPPSRCS = \ nsHTMLContentSink.cpp \ nsHTMLFragmentContentSink.cpp \ diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp index 04f7db6956f..35ac6b0f157 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp @@ -120,7 +120,7 @@ #include "nsContentUtils.h" #include "nsIDocumentCharsetInfo.h" #include "nsIDocumentEncoder.h" //for outputting selection -#include "nsIBookmarksService.h" +#include "nsICharsetResolver.h" #include "nsICachingChannel.h" #include "nsICacheEntryDescriptor.h" #include "nsIXMLContent.h" //for createelementNS @@ -559,7 +559,8 @@ nsHTMLDocument::TryCacheCharset(nsICacheEntryDescriptor* aCacheDescriptor, } PRBool -nsHTMLDocument::TryBookmarkCharset(nsAFlatCString* aUrlSpec, +nsHTMLDocument::TryBookmarkCharset(nsIDocShell* aDocShell, + nsIChannel* aChannel, PRInt32& aCharsetSource, nsAString& aCharset) { @@ -579,15 +580,21 @@ nsHTMLDocument::TryBookmarkCharset(nsAFlatCString* aUrlSpec, return PR_FALSE; } - nsCOMPtr bookmarks(do_QueryInterface(datasource)); - if (bookmarks && aUrlSpec) { - nsXPIDLString pBookmarkedCharset; - rv = bookmarks->GetLastCharset(aUrlSpec->get(), - getter_Copies(pBookmarkedCharset)); - if (NS_SUCCEEDED(rv) && (rv != NS_RDF_NO_VALUE)) { - aCharset = pBookmarkedCharset; - aCharsetSource = kCharsetFromBookmarks; + nsCOMPtr bookmarksResolver = + do_QueryInterface(datasource); + + if (bookmarksResolver && aDocShell && aChannel) { + PRBool wantCharset; // ignored for now + nsCAutoString charset; + rv = bookmarksResolver->RequestCharset(aDocShell, + aChannel, + &aCharsetSource, + &wantCharset, + nsnull, + charset); + if (NS_SUCCEEDED(rv) && !charset.IsEmpty()) { + aCharset = NS_ConvertASCIItoUCS2(charset); return PR_TRUE; } } @@ -904,7 +911,7 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand, // "Content-Type" header). } else if (!scheme.Equals(NS_LITERAL_CSTRING("about")) && // don't try to access bookmarks for about:blank - TryBookmarkCharset(&urlSpec, charsetSource, charset)) { + TryBookmarkCharset(docShell, aChannel, charsetSource, charset)) { // Use the bookmark's charset. } else if (cacheDescriptor && !urlSpec.IsEmpty() && diff --git a/mozilla/content/html/document/src/nsHTMLDocument.h b/mozilla/content/html/document/src/nsHTMLDocument.h index 421ce81ca0e..f2bfd65815b 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.h +++ b/mozilla/content/html/document/src/nsHTMLDocument.h @@ -303,7 +303,8 @@ protected: static PRBool TryCacheCharset(nsICacheEntryDescriptor* aCacheDescriptor, PRInt32& aCharsetSource, nsAString& aCharset); - static PRBool TryBookmarkCharset(nsAFlatCString* aUrlSpec, + static PRBool TryBookmarkCharset(nsIDocShell* aDocShell, + nsIChannel* aChannel, PRInt32& aCharsetSource, nsAString& aCharset); static PRBool TryParentCharset(nsIDocumentCharsetInfo* aDocInfo, diff --git a/mozilla/intl/chardet/public/Makefile.in b/mozilla/intl/chardet/public/Makefile.in index 002e5f8c01a..3b381a6c7b2 100644 --- a/mozilla/intl/chardet/public/Makefile.in +++ b/mozilla/intl/chardet/public/Makefile.in @@ -31,6 +31,7 @@ MODULE = chardet XPIDLSRCS = \ nsIDocumentCharsetInfo.idl \ nsIDocCharset.idl \ + nsICharsetResolver.idl \ $(NULL) EXPORTS = \ diff --git a/mozilla/intl/chardet/public/nsICharsetResolver.idl b/mozilla/intl/chardet/public/nsICharsetResolver.idl new file mode 100644 index 00000000000..1e73c5f851f --- /dev/null +++ b/mozilla/intl/chardet/public/nsICharsetResolver.idl @@ -0,0 +1,83 @@ +/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Character Set Resolver interface + * + * The Initial Developer of the Original Code is + * Netscape Communications Corp. + * Portions created by the Initial Developer are Copyright (C) 2003 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Alec Flett + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsISupports.idl" + +interface nsIDocShell; +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 + * + * @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 + */ + ACString requestCharset(in nsIDocShell docShell, in nsIChannel channel, + out long charsetSource, + out boolean wantCharset, + out nsISupports closure); + + /** + * notifyResolvedCharset + * + * some implementations may request that they be notified when the + * charset is actually detected. + * + * @param charset the detected charset + * @param closure the closre returned by detectCharset() above + */ + void notifyResolvedCharset(in ACString charset, in nsISupports closure); +}; diff --git a/mozilla/xpfe/components/bookmarks/public/nsIBookmarksService.idl b/mozilla/xpfe/components/bookmarks/public/nsIBookmarksService.idl index 88652450217..87a53cbb036 100644 --- a/mozilla/xpfe/components/bookmarks/public/nsIBookmarksService.idl +++ b/mozilla/xpfe/components/bookmarks/public/nsIBookmarksService.idl @@ -100,8 +100,6 @@ interface nsIBookmarksService : nsISupports string resolveKeyword(in wstring aName); - wstring getLastCharset(in string aURL); - void importSystemBookmarks(in nsIRDFResource aParentFolder); readonly attribute nsITransactionManager transactionManager; diff --git a/mozilla/xpfe/components/bookmarks/src/Makefile.in b/mozilla/xpfe/components/bookmarks/src/Makefile.in index b780ff3a3e1..eb4e63af71d 100644 --- a/mozilla/xpfe/components/bookmarks/src/Makefile.in +++ b/mozilla/xpfe/components/bookmarks/src/Makefile.in @@ -45,6 +45,8 @@ REQUIRES = xpcom \ windowwatcher \ unicharutil \ txmgr \ + chardet \ + htmlparser \ locale \ $(NULL) diff --git a/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.cpp b/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.cpp index 75c493f0db3..573310581f6 100644 --- a/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.cpp +++ b/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.cpp @@ -93,6 +93,8 @@ #include "nsUnicharUtils.h" +#include "nsIParser.h" // for kCharsetFromBookmarks + #ifdef XP_WIN #include #include @@ -3269,18 +3271,28 @@ nsBookmarksService::IsBookmarked(const char* aURL, PRBool* aIsBookmarked) } NS_IMETHODIMP -nsBookmarksService::GetLastCharset(const char* aURL, PRUnichar** aLastCharset) +nsBookmarksService::RequestCharset(nsIDocShell* aDocShell, + nsIChannel* aChannel, + PRInt32* aCharsetSource, + PRBool* aWantCharset, + nsISupports** aClosure, + nsACString& aResult) { - NS_PRECONDITION(aURL != nsnull, "null ptr"); - if (! aURL) - return NS_ERROR_NULL_POINTER; - NS_ENSURE_ARG_POINTER(aLastCharset); - if (!mInner) return NS_ERROR_UNEXPECTED; + *aWantCharset = PR_FALSE; + *aClosure = nsnull; + nsresult rv; + + nsCOMPtr uri; + rv = aChannel->GetURI(getter_AddRefs(uri)); + + nsCAutoString urlSpec; + uri->GetSpec(urlSpec); + nsCOMPtr urlLiteral; - nsresult rv = gRDF->GetLiteral(NS_ConvertUTF8toUCS2(aURL).get(), + rv = gRDF->GetLiteral(NS_ConvertUTF8toUCS2(urlSpec).get(), getter_AddRefs(urlLiteral)); if (NS_FAILED(rv)) return rv; @@ -3306,14 +3318,26 @@ nsBookmarksService::GetLastCharset(const char* aURL, PRUnichar** aLastCharset) if (charsetNode) { nsCOMPtr charsetLiteral = do_QueryInterface(charsetNode); if (charsetLiteral) { - return charsetLiteral->GetValue(aLastCharset); + const PRUnichar* charset; + charsetLiteral->GetValueConst(&charset); + aResult = NS_LossyConvertUCS2toASCII(charset); + *aCharsetSource = kCharsetFromBookmarks; + + return NS_OK; } } } } - *aLastCharset = nsnull; - return NS_RDF_NO_VALUE; + aResult.Truncate(); + return NS_OK; +} + +NS_IMETHODIMP +nsBookmarksService::NotifyResolvedCharset(const nsACString& aCharset, + nsISupports* aClosure) +{ + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP @@ -5354,9 +5378,9 @@ nsBookmarksService::WriteBookmarks(nsIFile* aBookmarksFile, static const char kBookmarkIntro[] = "

\n"; static const char kIndent[] = " "; static const char kContainerIntro[] = "

HasAssertion(child, kNC_FolderType, kNC_NewBookmarkFolder, PR_TRUE, &hasType)) && (hasType == PR_TRUE)) { - rv = strm->Write(kSpace, sizeof(kSpace)-1, &dummy); + rv = strm->Write(kSpaceStr, sizeof(kSpaceStr)-1, &dummy); rv |= strm->Write(kNewBookmarkFolderEquals, sizeof(kNewBookmarkFolderEquals)-1, &dummy); rv |= strm->Write(kTrueEnd, sizeof(kTrueEnd)-1, &dummy); if (NS_FAILED(rv)) break; @@ -5466,7 +5490,7 @@ nsBookmarksService::WriteBookmarksContainer(nsIRDFDataSource *ds, if (NS_SUCCEEDED(rv = mInner->HasAssertion(child, kNC_FolderType, kNC_NewSearchFolder, PR_TRUE, &hasType)) && (hasType == PR_TRUE)) { - rv = strm->Write(kSpace, sizeof(kSpace)-1, &dummy); + rv = strm->Write(kSpaceStr, sizeof(kSpaceStr)-1, &dummy); rv |= strm->Write(kNewSearchFolderEquals, sizeof(kNewSearchFolderEquals)-1, &dummy); rv |= strm->Write(kTrueEnd, sizeof(kTrueEnd)-1, &dummy); if (NS_FAILED(rv)) break; @@ -5474,7 +5498,7 @@ nsBookmarksService::WriteBookmarksContainer(nsIRDFDataSource *ds, if (NS_SUCCEEDED(rv = mInner->HasAssertion(child, kNC_FolderType, kNC_PersonalToolbarFolder, PR_TRUE, &hasType)) && (hasType == PR_TRUE)) { - rv = strm->Write(kSpace, sizeof(kSpace)-1, &dummy); + rv = strm->Write(kSpaceStr, sizeof(kSpaceStr)-1, &dummy); rv |= strm->Write(kPersonalToolbarFolderEquals, sizeof(kPersonalToolbarFolderEquals)-1, &dummy); rv |= strm->Write(kTrueEnd, sizeof(kTrueEnd)-1, &dummy); if (NS_FAILED(rv)) break; @@ -5483,7 +5507,7 @@ nsBookmarksService::WriteBookmarksContainer(nsIRDFDataSource *ds, if (NS_SUCCEEDED(rv = mInner->HasArcOut(child, kNC_FolderGroup, &hasType)) && (hasType == PR_TRUE)) { - rv = strm->Write(kSpace, sizeof(kSpace)-1, &dummy); + rv = strm->Write(kSpaceStr, sizeof(kSpaceStr)-1, &dummy); rv |= strm->Write(kFolderGroupEquals, sizeof(kFolderGroupEquals)-1, &dummy); rv |= strm->Write(kTrueEnd, sizeof(kTrueEnd)-1, &dummy); if (NS_FAILED(rv)) break; @@ -5494,10 +5518,10 @@ nsBookmarksService::WriteBookmarksContainer(nsIRDFDataSource *ds, rv = child->GetValueConst(&id); if (NS_SUCCEEDED(rv) && (id)) { - rv = strm->Write(kSpace, sizeof(kSpace)-1, &dummy); + rv = strm->Write(kSpaceStr, sizeof(kSpaceStr)-1, &dummy); rv |= strm->Write(kIDEquals, sizeof(kIDEquals)-1, &dummy); rv |= strm->Write(id, strlen(id), &dummy); - rv |= strm->Write(kQuote, sizeof(kQuote)-1, &dummy); + rv |= strm->Write(kQuoteStr, sizeof(kQuoteStr)-1, &dummy); if (NS_FAILED(rv)) break; } @@ -5591,10 +5615,10 @@ nsBookmarksService::WriteBookmarksContainer(nsIRDFDataSource *ds, rv = child->GetValueConst(&id); if (NS_SUCCEEDED(rv) && (id)) { - rv = strm->Write(kSpace, sizeof(kSpace)-1, &dummy); + rv = strm->Write(kSpaceStr, sizeof(kSpaceStr)-1, &dummy); rv |= strm->Write(kIDEquals, sizeof(kIDEquals)-1, &dummy); rv |= strm->Write(id, strlen(id), &dummy); - rv |= strm->Write(kQuote, sizeof(kQuote)-1, &dummy); + rv |= strm->Write(kQuoteStr, sizeof(kQuoteStr)-1, &dummy); if (NS_FAILED(rv)) break; } @@ -5776,7 +5800,7 @@ nsBookmarksService::WriteBookmarkProperties(nsIRDFDataSource *ds, { if (isFirst == PR_FALSE) { - rv |= strm->Write(kSpace, sizeof(kSpace)-1, &dummy); + rv |= strm->Write(kSpaceStr, sizeof(kSpaceStr)-1, &dummy); } if (property == kNC_Description) @@ -5799,7 +5823,7 @@ nsBookmarksService::WriteBookmarkProperties(nsIRDFDataSource *ds, { rv |= strm->Write(htmlAttrib, strlen(htmlAttrib), &dummy); rv |= strm->Write(attribute, strlen(attribute), &dummy); - rv |= strm->Write(kQuote, sizeof(kQuote)-1, &dummy); + rv |= strm->Write(kQuoteStr, sizeof(kQuoteStr)-1, &dummy); } nsCRT::free(attribute); attribute = nsnull; diff --git a/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.h b/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.h index e5d9750544e..e32fc3d7f97 100644 --- a/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.h +++ b/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.h @@ -58,6 +58,7 @@ #include "nsICacheService.h" #include "nsICacheSession.h" #include "nsITransactionManager.h" +#include "nsICharsetResolver.h" class nsIOutputStream; @@ -72,6 +73,7 @@ class nsBookmarksService : public nsIBookmarksService, public nsIRDFRemoteDataSource, public nsIRDFPropagatableDataSource, public nsIStreamListener, + public nsICharsetResolver, public nsIRDFObserver, public nsIObserver, public nsSupportsWeakReference @@ -195,6 +197,8 @@ protected: // nsIStreamListener methods: NS_DECL_NSISTREAMLISTENER + NS_DECL_NSICHARSETRESOLVER + // nsIObserver methods: NS_DECL_NSIOBSERVER diff --git a/mozilla/xpfe/components/build/Makefile.in b/mozilla/xpfe/components/build/Makefile.in index 07d8743a7e2..e5f230f7fab 100644 --- a/mozilla/xpfe/components/build/Makefile.in +++ b/mozilla/xpfe/components/build/Makefile.in @@ -56,6 +56,7 @@ REQUIRES = xpcom \ appshell \ browser \ txmgr \ + chardet \ $(NULL) ifndef MOZ_PHOENIX