Don't do IO in nsPluginsDir::IsPluginFile on Mac r+a=josh
authorTaras Glek <tglek@mozilla.com>
Mon, 27 Dec 2010 11:15:15 -0800
changeset 59688 eaa44c83914fdf9d6c9807ee80ad40716186c65a
parent 59687 4f4b4a3222bb42cc5c98f827693553a241c6bf70
child 59689 8f8b1db55800a150d11fecf9063c5d7fd16fa4b4
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone2.0b9pre
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
Don't do IO in nsPluginsDir::IsPluginFile on Mac r+a=josh
modules/plugin/base/src/nsPluginsDirDarwin.cpp
--- a/modules/plugin/base/src/nsPluginsDirDarwin.cpp
+++ b/modules/plugin/base/src/nsPluginsDirDarwin.cpp
@@ -113,55 +113,17 @@ PRBool nsPluginsDir::IsPluginFile(nsIFil
   /*
    * Don't load the VDP fake plugin, to avoid tripping a bad bug in OS X
    * 10.5.3 (see bug 436575).
    */
   if (!strcmp(fileName.get(), "VerifiedDownloadPlugin.plugin")) {
     NS_WARNING("Preventing load of VerifiedDownloadPlugin.plugin (see bug 436575)");
     return PR_FALSE;
   }
-    
-  CFURLRef pluginURL = NULL;
-  if (NS_FAILED(toCFURLRef(file, pluginURL)))
-    return PR_FALSE;
-  
-  PRBool isPluginFile = PR_FALSE;
-
-  CFBundleRef pluginBundle = ::CFBundleCreate(kCFAllocatorDefault, pluginURL);
-  if (pluginBundle) {
-    UInt32 packageType, packageCreator;
-    ::CFBundleGetPackageInfo(pluginBundle, &packageType, &packageCreator);
-    if (packageType == 'BRPL' || packageType == 'IEPL' || packageType == 'NSPL') {
-#ifdef MOZ_IPC
-      // Get path to plugin as a C string.
-      char executablePath[PATH_MAX];
-      executablePath[0] = '\0';
-      if (!::CFURLGetFileSystemRepresentation(pluginURL, true, (UInt8*)&executablePath, PATH_MAX)) {
-        executablePath[0] = '\0';
-      }
-
-      uint32 pluginLibArchitectures;
-      nsresult rv = mozilla::ipc::GeckoChildProcessHost::GetArchitecturesForBinary(executablePath, &pluginLibArchitectures);
-      if (NS_FAILED(rv)) {
-        return PR_FALSE;
-      }
-
-      uint32 containerArchitectures = mozilla::ipc::GeckoChildProcessHost::GetSupportedArchitecturesForProcessType(GeckoProcessType_Plugin);
-
-      // Consider the plugin architecture valid if there is any overlap in the masks.
-      isPluginFile = !!(containerArchitectures & pluginLibArchitectures);
-#else
-      isPluginFile = !!::CFBundlePreflightExecutable(pluginBundle, NULL);
-#endif
-    }
-    ::CFRelease(pluginBundle);
-  }
-
-  ::CFRelease(pluginURL);
-  return isPluginFile;
+  return PR_TRUE;
 }
 
 // Caller is responsible for freeing returned buffer.
 static char* CFStringRefToUTF8Buffer(CFStringRef cfString)
 {
   int bufferLength = ::CFStringGetLength(cfString) + 1;
   char* newBuffer = static_cast<char*>(NS_Alloc(bufferLength));
   if (newBuffer && !::CFStringGetCString(cfString, newBuffer, bufferLength, kCFStringEncodingUTF8)) {
@@ -480,25 +442,71 @@ public:
   {
     return (mRefNum > 0);
   }
 private:
   short mRefNum;
 };
 #endif
 
+static PRBool IsCompatibleArch(nsIFile *file)
+{
+  CFURLRef pluginURL = NULL;
+  if (NS_FAILED(toCFURLRef(file, pluginURL)))
+    return PR_FALSE;
+  
+  PRBool isPluginFile = PR_FALSE;
+
+  CFBundleRef pluginBundle = ::CFBundleCreate(kCFAllocatorDefault, pluginURL);
+  if (pluginBundle) {
+    UInt32 packageType, packageCreator;
+    ::CFBundleGetPackageInfo(pluginBundle, &packageType, &packageCreator);
+    if (packageType == 'BRPL' || packageType == 'IEPL' || packageType == 'NSPL') {
+#ifdef MOZ_IPC
+      // Get path to plugin as a C string.
+      char executablePath[PATH_MAX];
+      executablePath[0] = '\0';
+      if (!::CFURLGetFileSystemRepresentation(pluginURL, true, (UInt8*)&executablePath, PATH_MAX)) {
+        executablePath[0] = '\0';
+      }
+
+      uint32 pluginLibArchitectures;
+      nsresult rv = mozilla::ipc::GeckoChildProcessHost::GetArchitecturesForBinary(executablePath, &pluginLibArchitectures);
+      if (NS_FAILED(rv)) {
+        return PR_FALSE;
+      }
+
+      uint32 containerArchitectures = mozilla::ipc::GeckoChildProcessHost::GetSupportedArchitecturesForProcessType(GeckoProcessType_Plugin);
+
+      // Consider the plugin architecture valid if there is any overlap in the masks.
+      isPluginFile = !!(containerArchitectures & pluginLibArchitectures);
+#else
+      isPluginFile = !!::CFBundlePreflightExecutable(pluginBundle, NULL);
+#endif
+    }
+    ::CFRelease(pluginBundle);
+  }
+
+  ::CFRelease(pluginURL);
+  return isPluginFile;
+}
+
 /**
  * Obtains all of the information currently available for this plugin.
  */
 nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info, PRLibrary **outLibrary)
 {
   *outLibrary = nsnull;
 
   nsresult rv = NS_OK;
 
+  if (!IsCompatibleArch(mPlugin)) {
+      return NS_ERROR_FAILURE;
+  }
+
   // clear out the info, except for the first field.
   memset(&info, 0, sizeof(info));
 
 #ifndef __LP64__
   // Try to open a resource fork in case we have to use it.
   nsAutoCloseResourceObject resourceObject(mPlugin);
   bool resourceOpened = resourceObject.ResourceOpened();
 #endif