From 02e5a2d5d29ea30980689573066a95ba7a1fde64 Mon Sep 17 00:00:00 2001 From: Gavin Sharp Date: Thu, 8 Oct 2009 17:43:51 -0400 Subject: [PATCH] Bug 519686: Build localized bookmarks data for multi-locale builds and use it, r=mfinkle/pike --- mobile/components/BrowserStartup.js | 43 +++++++++++++++++++---------- mobile/locales/Makefile.in | 7 ++--- mobile/locales/jar.mn | 1 + 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/mobile/components/BrowserStartup.js b/mobile/components/BrowserStartup.js index 4f01b8189371..c50059c3cd9e 100644 --- a/mobile/components/BrowserStartup.js +++ b/mobile/components/BrowserStartup.js @@ -82,22 +82,35 @@ BrowserStartup.prototype = { Cu.import("resource://gre/modules/utils.js"); - // Get bookmarks.html file location - let dirService = Cc["@mozilla.org/file/directory_service;1"]. - getService(Ci.nsIProperties); + try { + let observer = { + onStreamComplete : function(aLoader, aContext, aStatus, aLength, aResult) { + let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]. + createInstance(Ci.nsIScriptableUnicodeConverter); + let jsonStr = ""; + try { + converter.charset = "UTF-8"; + jsonStr = converter.convertFromByteArray(aResult, aResult.length); - let bookmarksFile = dirService.get("profDef", Ci.nsILocalFile); - bookmarksFile.append("bookmarks.json"); - if (bookmarksFile.exists()) { - // import the file - try { - PlacesUtils.restoreBookmarksFromJSONFile(bookmarksFile); - } catch (err) { - // Report the error, but ignore it. - Cu.reportError("bookmarks.json file could be corrupt. " + err); - } - } else - Cu.reportError("Unable to find default bookmarks.json file."); + PlacesUtils.restoreBookmarksFromJSONString(jsonStr, true); + } catch (ex) { + Cu.reportError("Failed to parse default bookmarks from bookmarks.json: " + err); + } + } + }; + + let ioSvc = Cc["@mozilla.org/network/io-service;1"]. + getService(Ci.nsIIOService); + let uri = ioSvc.newURI("chrome://browser/locale/bookmarks.json", null, null); + let channel = ioSvc.newChannelFromURI(uri); + let sl = Cc["@mozilla.org/network/stream-loader;1"]. + createInstance(Ci.nsIStreamLoader); + sl.init(observer); + channel.asyncOpen(sl, channel); + } catch (err) { + // Report the error, but ignore it. + Cu.reportError("Failed to load default bookmarks from bookmarks.json: " + err); + } }, // nsIObserver diff --git a/mobile/locales/Makefile.in b/mobile/locales/Makefile.in index 421c3eb65049..eb78fe6b2b04 100644 --- a/mobile/locales/Makefile.in +++ b/mobile/locales/Makefile.in @@ -103,17 +103,14 @@ installers-%: clobber-% langpack-% repackage-zip-% NO_JA_JP_MAC_AB_CD := $(if $(filter ja-JP-mac, $(AB_CD)),ja,$(AB_CD)) -%/defaults/profile/bookmarks.json: bookmarks.inc generic/profile/bookmarks.json.in - $(SYSINSTALL) -D $(dir $@) +bookmarks.json: bookmarks.inc generic/profile/bookmarks.json.in $(PYTHON) $(topsrcdir)/config/Preprocessor.py \ -I $< \ -DAB_CD=$(NO_JA_JP_MAC_AB_CD) \ $(srcdir)/generic/profile/bookmarks.json.in \ > $@ -libs:: $(FINAL_TARGET)/defaults/profile/bookmarks.json ; - -install:: $(DESTDIR)$(mozappdir)/defaults/profile/bookmarks.json ; +libs realchrome:: bookmarks.json ifdef MOZ_UPDATER ifdef LOCALE_MERGEDIR diff --git a/mobile/locales/jar.mn b/mobile/locales/jar.mn index 9daf1da165bc..b8124b341b38 100644 --- a/mobile/locales/jar.mn +++ b/mobile/locales/jar.mn @@ -13,6 +13,7 @@ locale/@AB_CD@/browser/checkbox.dtd (%chrome/checkbox.dtd) locale/@AB_CD@/browser/notification.dtd (%chrome/notification.dtd) locale/@AB_CD@/browser/prompt.dtd (%chrome/prompt.dtd) + locale/@AB_CD@/browser/bookmarks.json (bookmarks.json) # Fennec-specific overrides of generic strings * locale/@AB_CD@/browser/netError.dtd (%chrome/overrides/netError.dtd)