bug 655337 - part 2 - don't unpack hyphenation patterns on android, look for them in omnijar. r=mfinkle,bsmedberg,smontagu
authorJonathan Kew <jfkthame@gmail.com>
Thu, 06 Oct 2011 16:06:36 +0100
changeset 79604 ef08991a3411a1974f26329d58442bda353d3137
parent 79603 70433779ffa7ccfcc82571d9e0051edc7a40023b
child 79605 5e51a2a6ef4f56a1bd63c9a89aa3986bcaefc7df
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
@@ -601,26 +601,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,129 @@ 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)
+{
+  nsCString base;
+  nsresult rv = Omnijar::GetURIString(aType, base);
+  if (NS_FAILED(rv)) {
+    return;
+  }
+
+  nsZipArchive *zip = Omnijar::GetReader(aType);
+  if (!zip) {
+    return;
+  }
+
+  nsZipFind *find;
+  zip->FindInit("hyphenation/hyph_*.dic", &find);
+  if (!find) {
+    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);
+    }
+  }
+
+  delete find;
+}
+
+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:
 /**