bug 655337 - part 2 - don't unpack hyphenation patterns on android, look for them in omnijar. r=mfinkle,bsmedberg,smontagu
☠☠ backed out by e6b75c79c618 ☠ ☠
authorJonathan Kew <jfkthame@gmail.com>
Thu, 06 Oct 2011 16:06:36 +0100
changeset 79591 e1eac54b1ed3849d8ca2bea4002f04936d8bb344
parent 79590 bacc2c7eee29d9bcf4b01ebf481f461e85bf44cd
child 79592 ef14ce8520821fa77baf7a1de39628ea46d0ed82
push id434
push userclegnitto@mozilla.com
push dateWed, 21 Dec 2011 12:10:54 +0000
treeherdermozilla-beta@bddb6ed8dd47 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle, bsmedberg, smontagu
bugs655337
milestone10.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
bug 655337 - part 2 - don't unpack hyphenation patterns on android, look for them in omnijar. r=mfinkle,bsmedberg,smontagu
embedding/android/GeckoApp.java
intl/hyphenation/public/nsHyphenationManager.h
intl/hyphenation/src/nsHyphenationManager.cpp
xpcom/build/Omnijar.h
--- a/embedding/android/GeckoApp.java
+++ b/embedding/android/GeckoApp.java
@@ -603,26 +603,16 @@ abstract public class GeckoApp
         Enumeration<? extends ZipEntry> zipEntries = zip.entries();
         while (zipEntries.hasMoreElements()) {
             ZipEntry entry = zipEntries.nextElement();
             if (entry.getName().startsWith("extensions/") && entry.getName().endsWith(".xpi")) {
                 Log.i("GeckoAppJava", "installing extension : " + entry.getName());
                 unpackFile(zip, buf, entry, entry.getName());
             }
         }
-
-        // copy any hyphenation dictionaries file into a hyphenation/ directory
-        Enumeration<? extends ZipEntry> hyphenEntries = zip.entries();
-        while (hyphenEntries.hasMoreElements()) {
-            ZipEntry entry = hyphenEntries.nextElement();
-            if (entry.getName().startsWith("hyphenation/")) {
-                Log.i("GeckoAppJava", "installing hyphenation : " + entry.getName());
-                unpackFile(zip, buf, entry, entry.getName());
-            }
-        }
     }
 
     void removeFiles() throws IOException {
         BufferedReader reader = new BufferedReader(
             new FileReader(new File(sGREDir, "removed-files")));
         try {
             for (String removedFileName = reader.readLine(); 
                  removedFileName != null; removedFileName = reader.readLine()) {
--- a/intl/hyphenation/public/nsHyphenationManager.h
+++ b/intl/hyphenation/public/nsHyphenationManager.h
@@ -36,16 +36,17 @@
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsHyphenationManager_h__
 #define nsHyphenationManager_h__
 
 #include "nsInterfaceHashtable.h"
 #include "nsRefPtrHashtable.h"
 #include "nsHashKeys.h"
+#include "mozilla/Omnijar.h"
 
 class nsHyphenator;
 class nsIAtom;
 class nsIURI;
 
 class nsHyphenationManager
 {
 public:
@@ -57,16 +58,17 @@ public:
 
   static void Shutdown();
 
 private:
   ~nsHyphenationManager();
 
 protected:
   void LoadPatternList();
+  void LoadPatternListFromOmnijar(mozilla::Omnijar::Type aType);
   void LoadPatternListFromDir(nsIFile *aDir);
   void LoadAliases();
 
   nsInterfaceHashtable<nsISupportsHashKey,nsIAtom> mHyphAliases;
   nsInterfaceHashtable<nsISupportsHashKey,nsIURI> mPatternFiles;
   nsRefPtrHashtable<nsISupportsHashKey,nsHyphenator> mHyphenators;
 
   static nsHyphenationManager *sInstance;
--- a/intl/hyphenation/src/nsHyphenationManager.cpp
+++ b/intl/hyphenation/src/nsHyphenationManager.cpp
@@ -42,16 +42,17 @@
 #include "nsIURI.h"
 #include "nsIProperties.h"
 #include "nsISimpleEnumerator.h"
 #include "nsIDirectoryEnumerator.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsNetUtil.h"
 #include "nsUnicharUtils.h"
 #include "mozilla/Preferences.h"
+#include "nsZipArchive.h"
 
 using namespace mozilla;
 
 #define INTL_HYPHENATIONALIAS_PREFIX "intl.hyphenation-alias."
 
 nsHyphenationManager *nsHyphenationManager::sInstance = nsnull;
 
 nsHyphenationManager*
@@ -137,72 +138,127 @@ nsHyphenationManager::GetHyphenator(nsIA
   return nsnull;
 }
 
 void
 nsHyphenationManager::LoadPatternList()
 {
   mPatternFiles.Clear();
   mHyphenators.Clear();
-  
-  nsresult rv;
-  
+
+  LoadPatternListFromOmnijar(Omnijar::GRE);
+  LoadPatternListFromOmnijar(Omnijar::APP);
+
   nsCOMPtr<nsIProperties> dirSvc =
     do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID);
   if (!dirSvc) {
     return;
   }
-  
+
+  nsresult rv;
   nsCOMPtr<nsIFile> greDir;
   rv = dirSvc->Get(NS_GRE_DIR,
                    NS_GET_IID(nsIFile), getter_AddRefs(greDir));
   if (NS_SUCCEEDED(rv)) {
     greDir->AppendNative(NS_LITERAL_CSTRING("hyphenation"));
     LoadPatternListFromDir(greDir);
   }
-  
+
   nsCOMPtr<nsIFile> appDir;
   rv = dirSvc->Get(NS_XPCOM_CURRENT_PROCESS_DIR,
                    NS_GET_IID(nsIFile), getter_AddRefs(appDir));
   if (NS_SUCCEEDED(rv)) {
     appDir->AppendNative(NS_LITERAL_CSTRING("hyphenation"));
     bool equals;
     if (NS_SUCCEEDED(appDir->Equals(greDir, &equals)) && !equals) {
       LoadPatternListFromDir(appDir);
     }
   }
 }
 
 void
+nsHyphenationManager::LoadPatternListFromOmnijar(Omnijar::Type aType)
+{
+  nsZipArchive *zip = Omnijar::GetReader(aType);
+  if (!zip) {
+    return;
+  }
+
+  nsZipFind *find;
+  zip->FindInit("hyphenation/hyph_*.dic", &find);
+  if (!find) {
+    return;
+  }
+
+  nsCString base;
+  nsresult rv = Omnijar::GetURIString(aType, base);
+  if (NS_FAILED(rv)) {
+    return;
+  }
+
+  const char *result;
+  PRUint16 len;
+  while (NS_SUCCEEDED(find->FindNext(&result, &len))) {
+    nsCString uriString(base);
+    uriString.Append(result, len);
+    nsCOMPtr<nsIURI> uri;
+    rv = NS_NewURI(getter_AddRefs(uri), uriString);
+    if (NS_FAILED(rv)) {
+      continue;
+    }
+    nsCString locale;
+    rv = uri->GetPath(locale);
+    if (NS_FAILED(rv)) {
+      continue;
+    }
+    ToLowerCase(locale);
+    locale.SetLength(locale.Length() - 4); // strip ".dic"
+    locale.Cut(0, locale.RFindChar('/') + 1); // strip directory
+    if (StringBeginsWith(locale, NS_LITERAL_CSTRING("hyph_"))) {
+      locale.Cut(0, 5);
+    }
+    for (PRUint32 i = 0; i < locale.Length(); ++i) {
+      if (locale[i] == '_') {
+        locale.Replace(i, 1, '-');
+      }
+    }
+    nsCOMPtr<nsIAtom> localeAtom = do_GetAtom(locale);
+    if (NS_SUCCEEDED(rv)) {
+      mPatternFiles.Put(localeAtom, uri);
+    }
+  }
+}
+
+void
 nsHyphenationManager::LoadPatternListFromDir(nsIFile *aDir)
 {
   nsresult rv;
-  
+
   bool check = false;
   rv = aDir->Exists(&check);
   if (NS_FAILED(rv) || !check) {
     return;
   }
-  
+
   rv = aDir->IsDirectory(&check);
   if (NS_FAILED(rv) || !check) {
     return;
   }
 
   nsCOMPtr<nsISimpleEnumerator> e;
   rv = aDir->GetDirectoryEntries(getter_AddRefs(e));
   if (NS_FAILED(rv)) {
     return;
   }
-  
+
   nsCOMPtr<nsIDirectoryEnumerator> files(do_QueryInterface(e));
   if (!files) {
     return;
   }
-  
+
   nsCOMPtr<nsIFile> file;
   while (NS_SUCCEEDED(files->GetNextFile(getter_AddRefs(file))) && file){
     nsAutoString dictName;
     file->GetLeafName(dictName);
     NS_ConvertUTF16toUTF8 locale(dictName);
     ToLowerCase(locale);
     if (!StringEndsWith(locale, NS_LITERAL_CSTRING(".dic"))) {
       continue;
--- a/xpcom/build/Omnijar.h
+++ b/xpcom/build/Omnijar.h
@@ -38,18 +38,18 @@
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef mozilla_Omnijar_h
 #define mozilla_Omnijar_h
 
 #include "nscore.h"
 #include "nsCOMPtr.h"
 #include "nsString.h"
+#include "nsIFile.h"
 
-class nsIFile;
 class nsZipArchive;
 class nsIURI;
 
 namespace mozilla {
 
 class Omnijar {
 private:
 /**