big part of fix for bug 101995 - remove bookmarks dependency from nsHTMLDocument

This commit is contained in:
alecf%flett.org 2003-05-29 22:11:23 +00:00
Родитель f438318e22
Коммит a08103427a
10 изменённых файлов: 157 добавлений и 42 удалений

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

@ -60,12 +60,6 @@ REQUIRES = xpcom \
plugin \
$(NULL)
ifdef MOZ_PHOENIX
REQUIRES += bookmarks
else
REQUIRES += appcomps
endif
CPPSRCS = \
nsHTMLContentSink.cpp \
nsHTMLFragmentContentSink.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<nsIBookmarksService> 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<nsICharsetResolver> 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() &&

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

@ -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,

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

@ -31,6 +31,7 @@ MODULE = chardet
XPIDLSRCS = \
nsIDocumentCharsetInfo.idl \
nsIDocCharset.idl \
nsICharsetResolver.idl \
$(NULL)
EXPORTS = \

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

@ -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 <alecf@flett.org>
*
* 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);
};

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

@ -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;

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

@ -45,6 +45,8 @@ REQUIRES = xpcom \
windowwatcher \
unicharutil \
txmgr \
chardet \
htmlparser \
locale \
$(NULL)

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

@ -93,6 +93,8 @@
#include "nsUnicharUtils.h"
#include "nsIParser.h" // for kCharsetFromBookmarks
#ifdef XP_WIN
#include <SHLOBJ.H>
#include <INTSHCUT.H>
@ -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<nsIURI> uri;
rv = aChannel->GetURI(getter_AddRefs(uri));
nsCAutoString urlSpec;
uri->GetSpec(urlSpec);
nsCOMPtr<nsIRDFLiteral> 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<nsIRDFLiteral> 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[] = "<DL><p>\n";
static const char kIndent[] = " ";
static const char kContainerIntro[] = "<DT><H3";
static const char kSpace[] = " ";
static const char kSpaceStr[] = " ";
static const char kTrueEnd[] = "true\"";
static const char kQuote[] = "\"";
static const char kQuoteStr[] = "\"";
static const char kCloseAngle[] = ">";
static const char kCloseH3[] = "</H3>\n";
static const char kHROpen[] = "<HR";
@ -5458,7 +5482,7 @@ nsBookmarksService::WriteBookmarksContainer(nsIRDFDataSource *ds,
if (NS_SUCCEEDED(rv = mInner->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;

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

@ -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

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

@ -56,6 +56,7 @@ REQUIRES = xpcom \
appshell \
browser \
txmgr \
chardet \
$(NULL)
ifndef MOZ_PHOENIX