Bug 391346 nsMorkHistoryImporter contains potentially unsafe static cast plus fix some compiler warnings such as integer constant overflow r=Mano

This commit is contained in:
neil@parkwaycc.co.uk 2007-08-15 08:50:22 -07:00
parent 841bf02591
commit 9616047979
8 changed files with 21 additions and 111 deletions

View File

@ -1131,7 +1131,7 @@ interface nsINavHistoryQueryOptions : nsISupports
nsINavHistoryQueryOptions clone();
};
[scriptable, uuid(ac992686-b98a-40e1-b104-7b1ff8f0c016)]
[scriptable, uuid(c5846d2c-5340-4cfb-9c0d-c15feca939ce)]
interface nsINavHistoryService : nsISupports
{
/**
@ -1328,23 +1328,12 @@ interface nsINavHistoryService : nsISupports
* history is disabled if the browser.history_expire_days pref is 0
*/
readonly attribute boolean historyDisabled;
};
/**
* nsIMorkHistoryImporter is a service which handles importing old
* history files.
*/
[scriptable, uuid(be935aed-6929-4e44-be29-17ec89e5c8bd)]
interface nsIMorkHistoryImporter : nsISupports
{
/**
* Import the given Mork history file.
* @param file The Mork history file to import
* @param history A reference to the nsINavHistoryService. This is
* supplied since the importer is invoked during
* history service initialization.
*/
void importHistory(in nsIFile file, in nsINavHistoryService history);
void importHistory(in nsIFile file);
};
/**

View File

@ -36,15 +36,13 @@
*
* ***** END LICENSE BLOCK ***** */
#include "nsMorkHistoryImporter.h"
#include "nsMorkReader.h"
#include "nsNavHistory.h"
#include "mozStorageHelper.h"
#include "prprf.h"
#include "nsNetUtil.h"
#include "nsTArray.h"
NS_IMPL_ISUPPORTS1(nsMorkHistoryImporter, nsIMorkHistoryImporter)
// Columns for entry (non-meta) history rows
enum {
kURLColumn,
@ -95,11 +93,11 @@ SwapBytes(PRUnichar *buffer)
}
}
// Enumerator callback to add a table row to the NavHistoryService
/* static */ PLDHashOperator PR_CALLBACK
nsMorkHistoryImporter::AddToHistoryCB(const nsCSubstring &aRowID,
const nsTArray<nsCString> *aValues,
void *aData)
// Enumerator callback to add a table row to history
static PLDHashOperator PR_CALLBACK
AddToHistoryCB(const nsCSubstring &aRowID,
const nsTArray<nsCString> *aValues,
void *aData)
{
TableReadClosure *data = static_cast<TableReadClosure*>(aData);
const nsMorkReader *reader = data->reader;
@ -166,15 +164,16 @@ nsMorkHistoryImporter::AddToHistoryCB(const nsCSubstring &aRowID,
return PL_DHASH_NEXT;
}
// nsNavHistory::ImportHistory
//
// ImportHistory is the main entry point to the importer.
// It sets up the file stream and loops over the lines in the file to
// parse them, then adds the resulting row set to history.
//
NS_IMETHODIMP
nsMorkHistoryImporter::ImportHistory(nsIFile *aFile,
nsINavHistoryService *aHistory)
nsNavHistory::ImportHistory(nsIFile* aFile)
{
NS_ENSURE_TRUE(aFile && aHistory, NS_ERROR_NULL_POINTER);
NS_ENSURE_TRUE(aFile, NS_ERROR_NULL_POINTER);
// Check that the file exists before we try to open it
PRBool exists;
@ -192,8 +191,7 @@ nsMorkHistoryImporter::ImportHistory(nsIFile *aFile,
NS_ENSURE_SUCCESS(rv, rv);
// Gather up the column ids so we don't need to find them on each row
nsNavHistory *history = static_cast<nsNavHistory*>(aHistory);
TableReadClosure data(&reader, history);
TableReadClosure data(&reader, this);
const nsTArray<nsMorkReader::MorkColumn> &columns = reader.GetColumns();
for (PRUint32 i = 0; i < columns.Length(); ++i) {
const nsCSubstring &name = columns[i].name;
@ -229,18 +227,18 @@ nsMorkHistoryImporter::ImportHistory(nsIFile *aFile,
}
// Now add the results to history
mozIStorageConnection *conn = history->GetStorageConnection();
mozIStorageConnection *conn = GetStorageConnection();
NS_ENSURE_TRUE(conn, NS_ERROR_NOT_INITIALIZED);
mozStorageTransaction transaction(conn, PR_FALSE);
#ifdef IN_MEMORY_LINKS
mozIStorageConnection *memoryConn = history->GetMemoryStorageConnection();
mozIStorageConnection *memoryConn = GetMemoryStorageConnection();
mozStorageTransaction memTransaction(memoryConn, PR_FALSE);
#endif
reader.EnumerateRows(AddToHistoryCB, &data);
// Make sure we don't have any duplicate items in the database.
rv = history->RemoveDuplicateURIs();
rv = RemoveDuplicateURIs();
NS_ENSURE_SUCCESS(rv, rv);
#ifdef IN_MEMORY_LINKS

View File

@ -1,66 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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 Places.
*
* The Initial Developer of the Original Code is
* Google Inc.
* Portions created by the Initial Developer are Copyright (C) 2006
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Brian Ryner <bryner@brianryner.com> (original author)
*
* 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 ***** */
#ifndef nsMorkHistoryImporter_h_
#define nsMorkHistoryImporter_h_
#include "nsINavHistoryService.h"
#include "nsMorkReader.h"
template<class E> class nsTArray;
// The nsMorkHistoryImporter object parses a Mork-format history file and
// adds the history items to the NavHistoryService. It is invoked the first
// time the history service is created for a given profile, if a Mork history
// (history.dat) file exists.
class nsMorkHistoryImporter : public nsIMorkHistoryImporter
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIMORKHISTORYIMPORTER
private:
// Enumerator callback to add a single row to the NavHistory.
static PLDHashOperator PR_CALLBACK
AddToHistoryCB(const nsCSubstring &aRowID,
const nsTArray<nsCString> *aValues,
void *aData);
};
#endif // nsMorkHistoryImporter_h_

View File

@ -39,7 +39,6 @@
#include <stdio.h>
#include "nsNavHistory.h"
#include "nsNavBookmarks.h"
#include "nsMorkHistoryImporter.h"
#include "nsAnnotationService.h"
#include "nsIArray.h"
@ -388,14 +387,11 @@ nsNavHistory::Init()
observerService->AddObserver(this, gXpcomShutdown, PR_FALSE);
if (doImport) {
nsCOMPtr<nsIMorkHistoryImporter> importer = new nsMorkHistoryImporter();
NS_ENSURE_TRUE(importer, NS_ERROR_OUT_OF_MEMORY);
nsCOMPtr<nsIFile> historyFile;
rv = NS_GetSpecialDirectory(NS_APP_HISTORY_50_FILE,
getter_AddRefs(historyFile));
if (NS_SUCCEEDED(rv) && historyFile) {
importer->ImportHistory(historyFile, this);
ImportHistory(historyFile);
}
}

View File

@ -87,7 +87,7 @@
#define QUERYUPDATE_COMPLEX 2
#define QUERYUPDATE_COMPLEX_WITH_BOOKMARKS 3
class AutoCompleteIntermediateResult;
struct AutoCompleteIntermediateResult;
class AutoCompleteResultComparator;
class mozIAnnotationService;
class nsNavHistory;

View File

@ -88,7 +88,7 @@ struct nsNavHistoryExpireRecord {
// Expiration policy amounts (in microseconds)
const PRTime EXPIRATION_POLICY_DAYS = (7 * 86400 * PR_MSEC_PER_SEC);
const PRTime EXPIRATION_POLICY_WEEKS = (30 * 86400 * PR_MSEC_PER_SEC);
const PRTime EXPIRATION_POLICY_MONTHS = (180 * 86400 * PR_MSEC_PER_SEC);
const PRTime EXPIRATION_POLICY_MONTHS = ((PRTime)180 * 86400 * PR_MSEC_PER_SEC);
// nsNavHistoryExpire::nsNavHistoryExpire
//

View File

@ -44,7 +44,7 @@
class mozIStorageConnection;
class nsNavHistory;
class nsNavHistoryExpireRecord;
struct nsNavHistoryExpireRecord;
class nsNavHistoryExpire
{

View File

@ -5,14 +5,12 @@
#include "nsNavHistory.h"
#include "nsNavBookmarks.h"
#include "nsFaviconService.h"
#include "nsMorkHistoryImporter.h"
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsNavHistory, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAnnoProtocolHandler)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsAnnotationService, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsNavBookmarks, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsFaviconService, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMorkHistoryImporter)
static const nsModuleComponentInfo components[] =
{
@ -51,11 +49,6 @@ static const nsModuleComponentInfo components[] =
NS_FAVICONSERVICE_CONTRACTID,
nsFaviconServiceConstructor },
{ "Mork History Importer",
NS_MORKHISTORYIMPORTER_CID,
NS_MORKHISTORYIMPORTER_CONTRACTID,
nsMorkHistoryImporterConstructor },
};
NS_IMPL_NSGETMODULE(nsPlacesModule, components)