Bug 666510 - Move the code for OS X app bundles from GRE_GetGREPathWithProperties to stub. r=bsmedberg, a=asa
authorMatthew Gertner <matthew.gertner@gmail.com>
Sat, 02 Jul 2011 16:47:55 +0200
changeset 70531 65ed6316d72dcabecd886318e53fdbf357c26e82
parent 70522 bb311256b95bfac3551d687abf5da65e6c2d5471
child 70532 fda101def1ec85e6b2a102a77fa9a565cf06c6fe
push id1
push usersledru@mozilla.com
push dateThu, 04 Dec 2014 17:57:20 +0000
reviewersbsmedberg, asa
bugs666510
milestone6.0
Bug 666510 - Move the code for OS X app bundles from GRE_GetGREPathWithProperties to stub. r=bsmedberg, a=asa
xulrunner/stub/nsXULStub.cpp
--- a/xulrunner/stub/nsXULStub.cpp
+++ b/xulrunner/stub/nsXULStub.cpp
@@ -358,31 +358,77 @@ main(int argc, char **argv)
   nsINIParser parser;
   rv = parser.Init(iniPath);
   if (NS_FAILED(rv)) {
     fprintf(stderr, "Could not read application.ini\n");
     return 1;
   }
 
   if (!greFound) {
-    Output(PR_FALSE,
-           "Could not find the Mozilla runtime.\n");
+#ifdef XP_MACOSX
+    // Check for <bundle>/Contents/Frameworks/XUL.framework/libxpcom.dylib
+    CFURLRef fwurl = CFBundleCopyPrivateFrameworksURL(appBundle);
+    CFURLRef absfwurl = nsnull;
+    if (fwurl) {
+      absfwurl = CFURLCopyAbsoluteURL(fwurl);
+      CFRelease(fwurl);
+    }
+
+    if (absfwurl) {
+      CFURLRef xulurl =
+        CFURLCreateCopyAppendingPathComponent(NULL, absfwurl,
+                                              CFSTR("XUL.Framework"),
+                                              PR_TRUE);
+
+      if (xulurl) {
+        CFURLRef xpcomurl =
+          CFURLCreateCopyAppendingPathComponent(NULL, xulurl,
+                                                CFSTR("libxpcom.dylib"),
+                                                PR_FALSE);
+
+        if (xpcomurl) {
+          char tbuffer[MAXPATHLEN];
+
+          if (CFURLGetFileSystemRepresentation(xpcomurl, PR_TRUE,
+                                               (UInt8*) tbuffer,
+                                               sizeof(tbuffer)) &&
+              access(tbuffer, R_OK | X_OK) == 0) {
+            if (realpath(tbuffer, greDir)) {
+              greFound = PR_TRUE;
+            }
+            else {
+              greDir[0] = '\0';
+            }
+          }
+
+          CFRelease(xpcomurl);
+        }
+
+        CFRelease(xulurl);
+      }
+
+      CFRelease(absfwurl);
+    }
+#endif
+    if (!greFound) {
+      Output(PR_FALSE, "Could not find the Mozilla runtime.\n");
       return 1;
+    }
   }
 
 #ifdef XP_OS2
   // On OS/2 we need to set BEGINLIBPATH to be able to find XULRunner DLLs
   strcpy(tmpPath, greDir);
   lastSlash = strrchr(tmpPath, PATH_SEPARATOR_CHAR);
   if (lastSlash) {
     *lastSlash = '\0';
   }
   DosSetExtLIBPATH(tmpPath, BEGIN_LIBPATH);
 #endif
-
+  
   rv = XPCOMGlueStartup(greDir);
   if (NS_FAILED(rv)) {
     if (rv == NS_ERROR_OUT_OF_MEMORY) {
       char applicationName[2000] = "this application";
       parser.GetString("App", "Name", applicationName, sizeof(applicationName));
       Output(PR_TRUE, "Not enough memory available to start %s.\n",
              applicationName);
     } else {