Bug 685236 - Stop using GetNativePath in nsPluginDirWin.cpp. r=jimm draft
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Sat, 16 Dec 2017 00:22:58 +0900
changeset 748086 d175a56b5aaaa54002212f6b73cbd3a49bad7619
parent 748085 dff1c10f20e54b2c5cb1c4c14e6a77fcf20f18d8
child 748087 59d5a2bf3d318fd61763d97ae5cb7fd8c0169aaa
push id97067
push userVYV03354@nifty.ne.jp
push dateSun, 28 Jan 2018 02:40:47 +0000
reviewersjimm
bugs685236
milestone60.0a1
Bug 685236 - Stop using GetNativePath in nsPluginDirWin.cpp. r=jimm MozReview-Commit-ID: 2eFSKhCEk48
dom/plugins/base/nsPluginsDirWin.cpp
--- a/dom/plugins/base/nsPluginsDirWin.cpp
+++ b/dom/plugins/base/nsPluginsDirWin.cpp
@@ -232,43 +232,35 @@ static bool CanLoadPlugin(char16ptr_t aB
 #endif
 }
 
 /* nsPluginsDir implementation */
 
 // The file name must be in the form "np*.dll"
 bool nsPluginsDir::IsPluginFile(nsIFile* file)
 {
-  nsAutoCString path;
-  if (NS_FAILED(file->GetNativePath(path)))
+  nsAutoString path;
+  if (NS_FAILED(file->GetPath(path)))
     return false;
 
-  const char *cPath = path.get();
-
   // this is most likely a path, so skip to the filename
-  const char* filename = PL_strrchr(cPath, '\\');
-  if (filename)
-    ++filename;
-  else
-    filename = cPath;
-
-  char* extension = PL_strrchr(filename, '.');
-  if (extension)
-    ++extension;
+  auto filename = Substring(path, path.RFindChar('\\') + 1);
+  // The file name must have at least one character between "np" and ".dll".
+  if (filename.Length() < 7) {
+    return false;
+  }
 
-  uint32_t fullLength = strlen(filename);
-  uint32_t extLength = extension ? strlen(extension) : 0;
-  if (fullLength >= 7 && extLength == 3) {
-    if (!PL_strncasecmp(filename, "np", 2) && !PL_strncasecmp(extension, "dll", 3)) {
-      // don't load OJI-based Java plugins
-      if (!PL_strncasecmp(filename, "npoji", 5) ||
-          !PL_strncasecmp(filename, "npjava", 6))
-        return false;
-      return true;
-    }
+  ToLowerCase(filename);
+  if (StringBeginsWith(filename, NS_LITERAL_STRING("np")) &&
+      StringEndsWith(filename, NS_LITERAL_STRING(".dll"))) {
+    // don't load OJI-based Java plugins
+    if (StringBeginsWith(filename, NS_LITERAL_STRING("npoji")) ||
+        StringBeginsWith(filename, NS_LITERAL_STRING("npjava")))
+      return false;
+    return true;
   }
 
   return false;
 }
 
 /* nsPluginFile implementation */
 
 nsPluginFile::nsPluginFile(nsIFile* file)