Bug 519686: Build localized bookmarks data for multi-locale builds and use it, attempt #2 with bustage fix, r=mfinkle/pike
authorGavin Sharp <gavin@gavinsharp.com>
Fri, 16 Oct 2009 12:42:40 -0400
changeset 65680 22014317e8974ad138a3d67b82eea535ef218b89
parent 65679 dd0dec5e133c0dba8490fab6e98282000e32766d
child 65681 99069a98c82e606aa3030d5e08ae2ee622cb119b
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle, pike
bugs519686
Bug 519686: Build localized bookmarks data for multi-locale builds and use it, attempt #2 with bustage fix, r=mfinkle/pike
mobile/components/BrowserStartup.js
mobile/locales/Makefile.in
mobile/locales/jar.mn
--- a/mobile/components/BrowserStartup.js
+++ b/mobile/components/BrowserStartup.js
@@ -77,32 +77,45 @@ BrowserStartup.prototype = {
     let importBookmarks = databaseStatus == histsvc.DATABASE_STATUS_CREATE ||
                           databaseStatus == histsvc.DATABASE_STATUS_CORRUPT;
 
     if (!importBookmarks)
       return;
 
     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
   observe: function(aSubject, aTopic, aData) {
     switch (aTopic) {
       case "places-init-complete":
         this._initDefaultBookmarks();
         this._observerService.removeObserver(this, "places-init-complete");
--- a/mobile/locales/Makefile.in
+++ b/mobile/locales/Makefile.in
@@ -87,38 +87,36 @@ libs-%:
 	$(NSINSTALL) -D $(DIST)/install
 	@$(MAKE) -C ../../toolkit/locales libs-$* BOTH_MANIFESTS=1
 	@$(MAKE) libs AB_CD=$* XPI_NAME=locale-$* PREF_DIR=defaults/preferences BOTH_MANIFESTS=1
 	@$(MAKE) -C $(DEPTH)/$(MOZ_BRANDING_DIRECTORY)/locales AB_CD=$* XPI_NAME=locale-$* BOTH_MANIFESTS=1
 
 # Tailored target to just add the chrome processing for multi-locale builds
 chrome-%:
 	@$(MAKE) -C $(DEPTH)/toolkit/locales chrome-$*
+	@$(MAKE) -B bookmarks.json AB_CD=$*
 	@$(MAKE) chrome AB_CD=$*
 	@$(MAKE) -C $(DEPTH)/$(MOZ_BRANDING_DIRECTORY)/locales chrome AB_CD=$*
 
 # This is a generic target that will make a langpack and repack tarball
 # builds. It is called from the tinderbox scripts. Alter it with caution.
 
 installers-%: clobber-% langpack-% repackage-zip-%
 	@echo "repackaging done"
 
 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 ;
+export:: bookmarks.json
 
 ifdef MOZ_UPDATER
 ifdef LOCALE_MERGEDIR
 UPDATER_INI := $(firstword $(wildcard $(LOCALE_MERGEDIR)/updater/updater.ini) \
        $(wildcard $(LOCALE_SRCDIR)/updater/updater.ini) \
        $(srcdir)/en-US/updater/updater.ini )
 else
 UPDATER_INI := $(addprefix $(LOCALE_SRCDIR)/,updater/updater.ini)
--- a/mobile/locales/jar.mn
+++ b/mobile/locales/jar.mn
@@ -8,15 +8,16 @@
   locale/@AB_CD@/browser/browser.properties       (%chrome/browser.properties)
   locale/@AB_CD@/browser/firstrun.dtd             (%chrome/firstrun.dtd)
   locale/@AB_CD@/browser/search.properties        (%chrome/search.properties)
   locale/@AB_CD@/browser/region.properties        (%chrome/region.properties)
   locale/@AB_CD@/browser/preferences.dtd          (%chrome/preferences.dtd)
   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)
 % override chrome://global/locale/netErrorApp.dtd chrome://browser/locale/netError.dtd
 # work around for bug 514817
   locale/@AB_CD@/browser/aboutRights.dtd          (%chrome/overrides/aboutRights.dtd)
 % override chrome://global/locale/aboutRights.dtd chrome://browser/locale/aboutRights.dtd