bug 655337 - part 1 - use nsIURI rather than nsIFile to specify hyphenation resources. r=mfinkle,smontagu
authorJonathan Kew <jfkthame@gmail.com>
Thu, 06 Oct 2011 16:06:32 +0100
changeset 78885 bacc2c7eee29d9bcf4b01ebf481f461e85bf44cd
parent 78884 5c044658352c04b10bc9a2a787aa13bb141cf46e
child 78886 e1eac54b1ed3849d8ca2bea4002f04936d8bb344
push id506
push userclegnitto@mozilla.com
push dateWed, 09 Nov 2011 02:03:18 +0000
treeherdermozilla-aurora@63587fc7bb93 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle, smontagu
bugs655337
milestone10.0a1
bug 655337 - part 1 - use nsIURI rather than nsIFile to specify hyphenation resources. r=mfinkle,smontagu
intl/hyphenation/public/nsHyphenationManager.h
intl/hyphenation/public/nsHyphenator.h
intl/hyphenation/src/nsHyphenationManager.cpp
intl/hyphenation/src/nsHyphenator.cpp
--- a/intl/hyphenation/public/nsHyphenationManager.h
+++ b/intl/hyphenation/public/nsHyphenationManager.h
@@ -39,16 +39,17 @@
 #define nsHyphenationManager_h__
 
 #include "nsInterfaceHashtable.h"
 #include "nsRefPtrHashtable.h"
 #include "nsHashKeys.h"
 
 class nsHyphenator;
 class nsIAtom;
+class nsIURI;
 
 class nsHyphenationManager
 {
 public:
   nsHyphenationManager();
 
   already_AddRefed<nsHyphenator> GetHyphenator(nsIAtom *aLocale);
 
@@ -60,15 +61,15 @@ private:
   ~nsHyphenationManager();
 
 protected:
   void LoadPatternList();
   void LoadPatternListFromDir(nsIFile *aDir);
   void LoadAliases();
 
   nsInterfaceHashtable<nsISupportsHashKey,nsIAtom> mHyphAliases;
-  nsInterfaceHashtable<nsISupportsHashKey,nsIFile> mPatternFiles;
+  nsInterfaceHashtable<nsISupportsHashKey,nsIURI> mPatternFiles;
   nsRefPtrHashtable<nsISupportsHashKey,nsHyphenator> mHyphenators;
 
   static nsHyphenationManager *sInstance;
 };
 
 #endif // nsHyphenationManager_h__
--- a/intl/hyphenation/public/nsHyphenator.h
+++ b/intl/hyphenation/public/nsHyphenator.h
@@ -37,22 +37,23 @@
 
 #ifndef nsHyphenator_h__
 #define nsHyphenator_h__
 
 #include "nsCOMPtr.h"
 #include "nsString.h"
 #include "nsTArray.h"
 
+class nsIURI;
 class nsIUGenCategory;
 
 class nsHyphenator
 {
 public:
-  nsHyphenator(nsIFile *aFile);
+  nsHyphenator(nsIURI *aURI);
 
   NS_INLINE_DECL_REFCOUNTING(nsHyphenator)
 
   bool IsValid();
 
   nsresult Hyphenate(const nsAString& aText, nsTArray<bool>& aHyphens);
 
 private:
--- a/intl/hyphenation/src/nsHyphenationManager.cpp
+++ b/intl/hyphenation/src/nsHyphenationManager.cpp
@@ -34,20 +34,22 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsHyphenationManager.h"
 #include "nsHyphenator.h"
 #include "nsIAtom.h"
 #include "nsIFile.h"
+#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"
 
 using namespace mozilla;
 
 #define INTL_HYPHENATIONALIAS_PREFIX "intl.hyphenation-alias."
 
 nsHyphenationManager *nsHyphenationManager::sInstance = nsnull;
@@ -84,30 +86,30 @@ nsHyphenationManager::~nsHyphenationMana
 already_AddRefed<nsHyphenator>
 nsHyphenationManager::GetHyphenator(nsIAtom *aLocale)
 {
   nsRefPtr<nsHyphenator> hyph;
   mHyphenators.Get(aLocale, getter_AddRefs(hyph));
   if (hyph) {
     return hyph.forget();
   }
-  nsCOMPtr<nsIFile> file = mPatternFiles.Get(aLocale);
-  if (!file) {
+  nsCOMPtr<nsIURI> uri = mPatternFiles.Get(aLocale);
+  if (!uri) {
     nsCOMPtr<nsIAtom> alias = mHyphAliases.Get(aLocale);
     if (alias) {
       mHyphenators.Get(alias, getter_AddRefs(hyph));
       if (hyph) {
         return hyph.forget();
       }
-      file = mPatternFiles.Get(alias);
-      if (file) {
+      uri = mPatternFiles.Get(alias);
+      if (uri) {
         aLocale = alias;
       }
     }
-    if (!file) {
+    if (!uri) {
       // In the case of a locale such as "de-DE-1996", we try replacing
       // successive trailing subtags with "-*" to find fallback patterns,
       // so "de-DE-1996" -> "de-DE-*" (and then recursively -> "de-*")
       nsAtomCString localeStr(aLocale);
       if (StringEndsWith(localeStr, NS_LITERAL_CSTRING("-*"))) {
         localeStr.Truncate(localeStr.Length() - 2);
       }
       PRInt32 i = localeStr.RFindChar('-');
@@ -115,24 +117,24 @@ nsHyphenationManager::GetHyphenator(nsIA
         localeStr.Replace(i, localeStr.Length() - i, "-*");
         nsCOMPtr<nsIAtom> fuzzyLocale = do_GetAtom(localeStr);
         return GetHyphenator(fuzzyLocale);
       } else {
         return nsnull;
       }
     }
   }
-  hyph = new nsHyphenator(file);
+  hyph = new nsHyphenator(uri);
   if (hyph->IsValid()) {
     mHyphenators.Put(aLocale, hyph);
     return hyph.forget();
   }
 #ifdef DEBUG
   nsCString msg;
-  file->GetNativePath(msg);
+  uri->GetSpec(msg);
   msg.Insert("failed to load patterns from ", 0);
   NS_WARNING(msg.get());
 #endif
   mPatternFiles.Remove(aLocale);
   return nsnull;
 }
 
 void
@@ -214,17 +216,21 @@ nsHyphenationManager::LoadPatternListFro
         locale.Replace(i, 1, '-');
       }
     }
 #ifdef DEBUG_hyph
     printf("adding hyphenation patterns for %s: %s\n", locale.get(),
            NS_ConvertUTF16toUTF8(dictName).get());
 #endif
     nsCOMPtr<nsIAtom> localeAtom = do_GetAtom(locale);
-    mPatternFiles.Put(localeAtom, file);
+    nsCOMPtr<nsIURI> uri;
+    nsresult rv = NS_NewFileURI(getter_AddRefs(uri), file);
+    if (NS_SUCCEEDED(rv)) {
+      mPatternFiles.Put(localeAtom, uri);
+    }
   }
 }
 
 void
 nsHyphenationManager::LoadAliases()
 {
   nsIPrefBranch* prefRootBranch = Preferences::GetRootBranch();
   if (!prefRootBranch) {
--- a/intl/hyphenation/src/nsHyphenator.cpp
+++ b/intl/hyphenation/src/nsHyphenator.cpp
@@ -35,32 +35,32 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsHyphenator.h"
 #include "nsIFile.h"
 #include "nsUTF8Utils.h"
 #include "nsIUGenCategory.h"
 #include "nsUnicharUtilCIID.h"
-#include "nsNetUtil.h"
+#include "nsIURI.h"
 
 #include "hyphen.h"
 
-nsHyphenator::nsHyphenator(nsIFile *aFile)
+nsHyphenator::nsHyphenator(nsIURI *aURI)
   : mDict(nsnull)
 {
-  nsCString urlSpec;
-  nsresult rv = NS_GetURLSpecFromFile(aFile, urlSpec);
+  nsCString uriSpec;
+  nsresult rv = aURI->GetSpec(uriSpec);
   if (NS_FAILED(rv)) {
     return;
   }
-  mDict = hnj_hyphen_load(urlSpec.get());
+  mDict = hnj_hyphen_load(uriSpec.get());
 #ifdef DEBUG
   if (mDict) {
-    printf("loaded hyphenation patterns from %s\n", urlSpec.get());
+    printf("loaded hyphenation patterns from %s\n", uriSpec.get());
   }
 #endif
   mCategories = do_GetService(NS_UNICHARCATEGORY_CONTRACTID, &rv);
   NS_ASSERTION(NS_SUCCEEDED(rv), "failed to get category service");
 }
 
 nsHyphenator::~nsHyphenator()
 {