Bug 1420427 - Stop using native charset in URLPreloader. r=kmag
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Tue, 28 Nov 2017 00:21:00 +0900
changeset 393975 345fe119b8cfd315bee3de6c93fd748a92801a62
parent 393974 07b5a8b9c8a778b5081f57deb745c6eebcbcd814
child 393976 40099ea55a1358d39ef49e7b53cd6daf5aead75f
push id32989
push userdluca@mozilla.com
push dateWed, 29 Nov 2017 10:09:52 +0000
treeherdermozilla-central@40b464eb6b31 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1420427
milestone59.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 1420427 - Stop using native charset in URLPreloader. r=kmag 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.
    */