mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-28 04:35:33 +00:00
Bug 459781 - create our string bundle in a more sane way
This changeset only creates the string bundle when we need it, and only in one place as opposed to two separate places. r=dietrich
This commit is contained in:
parent
fa8ebfbf47
commit
1bf6dc8334
@ -105,20 +105,12 @@ NS_IMPL_ISUPPORTS3(nsNavBookmarks,
|
||||
nsresult
|
||||
nsNavBookmarks::Init()
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIStringBundleService> bundleService =
|
||||
do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = bundleService->CreateBundle("chrome://places/locale/places.properties",
|
||||
getter_AddRefs(mBundle));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsNavHistory *history = History();
|
||||
NS_ENSURE_TRUE(history, NS_ERROR_OUT_OF_MEMORY);
|
||||
mDBConn = history->GetStorageConnection();
|
||||
mozStorageTransaction transaction(mDBConn, PR_FALSE);
|
||||
|
||||
rv = InitStatements();
|
||||
nsresult rv = InitStatements();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = FillBookmarksHash();
|
||||
@ -546,34 +538,37 @@ nsNavBookmarks::InitRoots()
|
||||
nsresult
|
||||
nsNavBookmarks::InitDefaults()
|
||||
{
|
||||
nsIStringBundle *bundle = History()->GetBundle();
|
||||
NS_ENSURE_TRUE(bundle, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
// Bookmarks Menu
|
||||
nsXPIDLString bookmarksTitle;
|
||||
nsresult rv = mBundle->GetStringFromName(NS_LITERAL_STRING("BookmarksMenuFolderTitle").get(),
|
||||
getter_Copies(bookmarksTitle));
|
||||
nsresult rv = bundle->GetStringFromName(NS_LITERAL_STRING("BookmarksMenuFolderTitle").get(),
|
||||
getter_Copies(bookmarksTitle));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = SetItemTitle(mBookmarksRoot, NS_ConvertUTF16toUTF8(bookmarksTitle));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Bookmarks Toolbar
|
||||
nsXPIDLString toolbarTitle;
|
||||
rv = mBundle->GetStringFromName(NS_LITERAL_STRING("BookmarksToolbarFolderTitle").get(),
|
||||
getter_Copies(toolbarTitle));
|
||||
rv = bundle->GetStringFromName(NS_LITERAL_STRING("BookmarksToolbarFolderTitle").get(),
|
||||
getter_Copies(toolbarTitle));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = SetItemTitle(mToolbarFolder, NS_ConvertUTF16toUTF8(toolbarTitle));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Unsorted Bookmarks
|
||||
nsXPIDLString unfiledTitle;
|
||||
rv = mBundle->GetStringFromName(NS_LITERAL_STRING("UnsortedBookmarksFolderTitle").get(),
|
||||
getter_Copies(unfiledTitle));
|
||||
rv = bundle->GetStringFromName(NS_LITERAL_STRING("UnsortedBookmarksFolderTitle").get(),
|
||||
getter_Copies(unfiledTitle));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = SetItemTitle(mUnfiledRoot, NS_ConvertUTF16toUTF8(unfiledTitle));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Tags
|
||||
nsXPIDLString tagsTitle;
|
||||
rv = mBundle->GetStringFromName(NS_LITERAL_STRING("TagsFolderTitle").get(),
|
||||
getter_Copies(tagsTitle));
|
||||
rv = bundle->GetStringFromName(NS_LITERAL_STRING("TagsFolderTitle").get(),
|
||||
getter_Copies(tagsTitle));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = SetItemTitle(mTagRoot, NS_ConvertUTF16toUTF8(tagsTitle));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
@ -41,7 +41,6 @@
|
||||
|
||||
#include "nsINavBookmarksService.h"
|
||||
#include "nsIAnnotationService.h"
|
||||
#include "nsIStringBundle.h"
|
||||
#include "nsITransaction.h"
|
||||
#include "nsNavHistory.h"
|
||||
#include "nsNavHistoryResult.h" // need for Int64 hashtable
|
||||
@ -213,8 +212,6 @@ private:
|
||||
nsCOMPtr<mozIStorageStatement> mDBGetKeywordForBookmark;
|
||||
nsCOMPtr<mozIStorageStatement> mDBGetURIForKeyword;
|
||||
|
||||
nsCOMPtr<nsIStringBundle> mBundle;
|
||||
|
||||
class RemoveFolderTransaction : public nsITransaction {
|
||||
public:
|
||||
RemoveFolderTransaction(PRInt64 aID) : mID(aID) {}
|
||||
|
@ -450,15 +450,6 @@ nsNavHistory::Init()
|
||||
mLastSessionID = 1;
|
||||
}
|
||||
|
||||
// string bundle for localization
|
||||
nsCOMPtr<nsIStringBundleService> bundleService =
|
||||
do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = bundleService->CreateBundle(
|
||||
"chrome://places/locale/places.properties",
|
||||
getter_AddRefs(mBundle));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// initialize idle timer
|
||||
InitializeIdleTimer();
|
||||
|
||||
@ -6562,12 +6553,16 @@ nsNavHistory::TitleForDomain(const nsCString& domain, nsACString& aTitle)
|
||||
void
|
||||
nsNavHistory::GetAgeInDaysString(PRInt32 aInt, const PRUnichar *aName, nsACString& aResult)
|
||||
{
|
||||
nsIStringBundle *bundle = GetBundle();
|
||||
if (!bundle)
|
||||
aResult.Truncate(0);
|
||||
|
||||
nsAutoString intString;
|
||||
intString.AppendInt(aInt);
|
||||
const PRUnichar* strings[1] = { intString.get() };
|
||||
nsXPIDLString value;
|
||||
nsresult rv = mBundle->FormatStringFromName(aName, strings,
|
||||
1, getter_Copies(value));
|
||||
nsresult rv = bundle->FormatStringFromName(aName, strings,
|
||||
1, getter_Copies(value));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
CopyUTF16toUTF8(value, aResult);
|
||||
else
|
||||
@ -6577,8 +6572,12 @@ nsNavHistory::GetAgeInDaysString(PRInt32 aInt, const PRUnichar *aName, nsACStrin
|
||||
void
|
||||
nsNavHistory::GetStringFromName(const PRUnichar *aName, nsACString& aResult)
|
||||
{
|
||||
nsIStringBundle *bundle = GetBundle();
|
||||
if (!bundle)
|
||||
aResult.Truncate(0);
|
||||
|
||||
nsXPIDLString value;
|
||||
nsresult rv = mBundle->GetStringFromName(aName, getter_Copies(value));
|
||||
nsresult rv = bundle->GetStringFromName(aName, getter_Copies(value));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
CopyUTF16toUTF8(value, aResult);
|
||||
else
|
||||
@ -7372,6 +7371,23 @@ nsNavHistory::GetCollation()
|
||||
return mCollation;
|
||||
}
|
||||
|
||||
nsIStringBundle *
|
||||
nsNavHistory::GetBundle()
|
||||
{
|
||||
if (mBundle)
|
||||
return mBundle;
|
||||
|
||||
nsCOMPtr<nsIStringBundleService> bundleService =
|
||||
do_GetService(NS_STRINGBUNDLE_CONTRACTID);
|
||||
NS_ENSURE_TRUE(bundleService, nsnull);
|
||||
nsresult rv = bundleService->CreateBundle(
|
||||
"chrome://places/locale/places.properties",
|
||||
getter_AddRefs(mBundle));
|
||||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
|
||||
return mBundle;
|
||||
}
|
||||
|
||||
// nsICharsetResolver **********************************************************
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -239,10 +239,11 @@ public:
|
||||
* These functions return non-owning references to the locale-specific
|
||||
* objects for places components.
|
||||
*/
|
||||
nsIStringBundle* GetBundle()
|
||||
{ return mBundle; }
|
||||
nsIStringBundle* GetBundle();
|
||||
nsICollation* GetCollation();
|
||||
void GetStringFromName(const PRUnichar* aName, nsACString& aResult);
|
||||
void GetAgeInDaysString(PRInt32 aInt, const PRUnichar *aName,
|
||||
nsACString& aResult);
|
||||
|
||||
// returns true if history has been disabled
|
||||
PRBool IsHistoryDisabled() { return mExpireDaysMax == 0; }
|
||||
@ -586,9 +587,6 @@ protected:
|
||||
nsNavHistoryQueryOptions* aOptions,
|
||||
nsCOMArray<nsNavHistoryResultNode>* aResults);
|
||||
|
||||
void GetAgeInDaysString(PRInt32 aInt, const PRUnichar *aName,
|
||||
nsACString& aResult);
|
||||
|
||||
void TitleForDomain(const nsCString& domain, nsACString& aTitle);
|
||||
|
||||
nsresult SetPageTitleInternal(nsIURI* aURI, const nsAString& aTitle);
|
||||
|
Loading…
Reference in New Issue
Block a user