Bug 1420427 - Stop using native charset in URLPreloader. r=kmag, a=ritu FENNEC_57_0_1_BUILD1 FENNEC_57_0_1_RELEASE FIREFOX_57_0_1_BUILD2 FIREFOX_57_0_1_RELEASE
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Tue, 28 Nov 2017 00:21:00 +0900
changeset 435391 d2e449c73daca64d8c8185590750873b1cfcd412
parent 435390 83885c5b00ed4947579565a404e252bc7e077cb3
child 435392 8d3d36b5b73ff421ae5a2662db669a19f63d43b5
push id1597
push userryanvm@gmail.com
push dateTue, 28 Nov 2017 22:25:54 +0000
treeherdermozilla-release@d2e449c73dac [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag, ritu
bugs1420427
milestone57.0.1
Bug 1420427 - Stop using native charset in URLPreloader. r=kmag, a=ritu MozReview-Commit-ID: 5CidUcXLCjP
js/xpconnect/loader/URLPreloader.cpp
js/xpconnect/loader/URLPreloader.h
xpcom/base/nsINIParser.cpp
xpcom/base/nsINIParser.h
--- a/js/xpconnect/loader/URLPreloader.cpp
+++ b/js/xpconnect/loader/URLPreloader.cpp
@@ -175,17 +175,17 @@ URLPreloader::GetCacheFile(const nsAStri
     MOZ_TRY(cacheFile->AppendNative(NS_LITERAL_CSTRING("startupCache")));
     Unused << cacheFile->Create(nsIFile::DIRECTORY_TYPE, 0777);
 
     MOZ_TRY(cacheFile->Append(NS_LITERAL_STRING("urlCache") + suffix));
 
     return Move(cacheFile);
 }
 
-static const uint8_t URL_MAGIC[] = "mozURLcachev001";
+static const uint8_t URL_MAGIC[] = "mozURLcachev002";
 
 Result<nsCOMPtr<nsIFile>, nsresult>
 URLPreloader::FindCacheFile()
 {
     nsCOMPtr<nsIFile> cacheFile;
     MOZ_TRY_VAR(cacheFile, GetCacheFile(NS_LITERAL_STRING(".bin")));
 
     bool exists;
@@ -511,23 +511,16 @@ URLPreloader::ReadURI(nsIURI* uri, ReadT
 
 /* static */ Result<const nsCString, nsresult>
 URLPreloader::ReadFile(nsIFile* file, ReadType readType)
 {
     return Read(CacheKey(file), readType);
 }
 
 /* static */ Result<const nsCString, nsresult>
-URLPreloader::ReadFile(const nsACString& path, ReadType readType)
-{
-    CacheKey key(CacheKey::TypeFile, path);
-    return Read(key, readType);
-}
-
-/* static */ Result<const nsCString, nsresult>
 URLPreloader::Read(FileLocation& location, ReadType readType)
 {
     if (location.IsZip()) {
         if (location.GetBaseZip()) {
             nsCString path;
             location.GetPath(path);
             return ReadZip(location.GetBaseZip(), path);
         }
@@ -599,20 +592,20 @@ URLPreloader::ResolveURI(nsIURI* uri)
     // Try for a file URI.
     if (scheme.EqualsLiteral("file")) {
         nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(resolved);
         MOZ_ASSERT(fileURL);
 
         nsCOMPtr<nsIFile> file;
         MOZ_TRY(fileURL->GetFile(getter_AddRefs(file)));
 
-        nsCString path;
-        MOZ_TRY(file->GetNativePath(path));
+        nsString path;
+        MOZ_TRY(file->GetPath(path));
 
-        return CacheKey(CacheKey::TypeFile, path);
+        return CacheKey(CacheKey::TypeFile, NS_ConvertUTF16toUTF8(path));
     }
 
     // Not a file or Omnijar URI, so currently unsupported.
     return Err(NS_ERROR_INVALID_ARG);
 }
 
 size_t
 URLPreloader::ShallowSizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf)
@@ -623,17 +616,18 @@ URLPreloader::ShallowSizeOfIncludingThis
             mCachedURLs.ShallowSizeOfExcludingThis(mallocSizeOf));
 }
 
 Result<FileLocation, nsresult>
 URLPreloader::CacheKey::ToFileLocation()
 {
     if (mType == TypeFile) {
         nsCOMPtr<nsIFile> file;
-        MOZ_TRY(NS_NewNativeLocalFile(mPath, false, getter_AddRefs(file)));
+        MOZ_TRY(NS_NewLocalFile(NS_ConvertUTF8toUTF16(mPath), false,
+                                getter_AddRefs(file)));
         return Move(FileLocation(file));
     }
 
     RefPtr<nsZipArchive> zip = Archive();
     return Move(FileLocation(zip, mPath.get()));
 }
 
 Result<const nsCString, nsresult>
--- a/js/xpconnect/loader/URLPreloader.h
+++ b/js/xpconnect/loader/URLPreloader.h
@@ -72,18 +72,16 @@ public:
     // given location is not supported by the cache, the entries will be read
     // synchronously, and not stored in the cache.
     static Result<const nsCString, nsresult> Read(FileLocation& location, ReadType readType = Forget);
 
     static Result<const nsCString, nsresult> ReadURI(nsIURI* uri, ReadType readType = Forget);
 
     static Result<const nsCString, nsresult> ReadFile(nsIFile* file, ReadType readType = Forget);
 
-    static Result<const nsCString, nsresult> ReadFile(const nsACString& path, ReadType readType = Forget);
-
     static Result<const nsCString, nsresult> ReadZip(nsZipArchive* archive,
                                                      const nsACString& path,
                                                      ReadType readType = Forget);
 
 private:
     struct CacheKey;
 
     Result<const nsCString, nsresult> ReadInternal(const CacheKey& key, ReadType readType);
@@ -154,17 +152,19 @@ private:
 
         CacheKey(EntryType type, const nsACString& path)
             : mType(type), mPath(path)
         {}
 
         explicit CacheKey(nsIFile* file)
           : mType(TypeFile)
         {
-            MOZ_ALWAYS_SUCCEEDS(file->GetNativePath(mPath));
+            nsString path;
+            MOZ_ALWAYS_SUCCEEDS(file->GetPath(path));
+            CopyUTF16toUTF8(path, mPath);
         }
 
         explicit inline CacheKey(InputBuffer& buffer);
 
         // Encodes or decodes the cache key for storage in a session cache file.
         template <typename Buffer>
         void Code(Buffer& buffer)
         {
--- a/xpcom/base/nsINIParser.cpp
+++ b/xpcom/base/nsINIParser.cpp
@@ -62,25 +62,16 @@ nsresult
 nsINIParser::Init(nsIFile* aFile)
 {
   nsCString result;
   MOZ_TRY_VAR(result, URLPreloader::ReadFile(aFile));
 
   return InitFromString(result);
 }
 
-nsresult
-nsINIParser::Init(const char* aPath)
-{
-  nsCString result;
-  MOZ_TRY_VAR(result, URLPreloader::ReadFile(nsDependentCString(aPath)));
-
-  return InitFromString(result);
-}
-
 static const char kNL[] = "\r\n";
 static const char kEquals[] = "=";
 static const char kWhitespace[] = " \t";
 static const char kRBracket[] = "]";
 
 nsresult
 nsINIParser::InitFromString(const nsCString& aStr)
 {
--- a/xpcom/base/nsINIParser.h
+++ b/xpcom/base/nsINIParser.h
@@ -31,24 +31,16 @@ public:
    * Initialize the INIParser with a nsIFile. If this method fails, no
    * other methods should be called. This method reads and parses the file,
    * the class does not hold a file handle open. An instance must only be
    * initialized once.
    */
   nsresult Init(nsIFile* aFile);
 
   /**
-   * Initialize the INIParser with a file path. If this method fails, no
-   * other methods should be called. This method reads and parses the file,
-   * the class does not hold a file handle open. An instance must only
-   * be initialized once.
-   */
-  nsresult Init(const char* aPath);
-
-  /**
    * Callback for GetSections
    * @return false to stop enumeration, or true to continue.
    */
   typedef bool (*INISectionCallback)(const char* aSection, void* aClosure);
 
   /**
    * Enumerate the sections within the INI file.
    */