Bug 557225 - Load the plugin-container from the App Bundle. r=cjones
authorBenoit Girard <b56girard@gmail.com>
Mon, 19 Jul 2010 18:35:45 -0400
changeset 47971 8274ab91c0743f333480f6c66a8498f719f3f883
parent 47970 a02255a3f06a20555a02d37e6c7725ad7929365c
child 47972 0e61db1928963efb12b996330ca3bd2c047f8c86
push idunknown
push userunknown
push dateunknown
reviewerscjones
bugs557225
milestone2.0b2pre
Bug 557225 - Load the plugin-container from the App Bundle. r=cjones
ipc/app/defs.mk
ipc/app/macbuild/Contents/Info.plist.in
ipc/chromium/src/base/process_util.h
ipc/chromium/src/base/process_util_mac.mm
ipc/glue/GeckoChildProcessHost.cpp
ipc/glue/Makefile.in
--- a/ipc/app/defs.mk
+++ b/ipc/app/defs.mk
@@ -30,8 +30,9 @@
 # decision by deleting the provisions above and replace them with the notice
 # and other provisions required by the GPL or the LGPL. If you do not delete
 # the provisions above, a recipient may use your version of this file under
 # the terms of any one of the MPL, the GPL or the LGPL.
 #
 # ***** END LICENSE BLOCK *****
 
 MOZ_CHILD_PROCESS_NAME := plugin-container$(BIN_SUFFIX)
+MOZ_CHILD_PROCESS_BUNDLE := plugin-container.app/Contents/MacOS/
--- a/ipc/app/macbuild/Contents/Info.plist.in
+++ b/ipc/app/macbuild/Contents/Info.plist.in
@@ -13,10 +13,12 @@
 	<key>CFBundlePackageType</key>
 	<string>APPL</string>
 	<key>CFBundleSignature</key>
 	<string>????</string>
 	<key>CFBundleVersion</key>
 	<string>1.0</string>
 	<key>LSMinimumSystemVersion</key>
 	<string>10.5</string>
+	<key>LSUIElement</key>
+	<string>1</string>
 </dict>
 </plist>
--- a/ipc/chromium/src/base/process_util.h
+++ b/ipc/chromium/src/base/process_util.h
@@ -129,17 +129,17 @@ bool LaunchApp(const std::wstring& cmdli
 //
 // Note that the first argument in argv must point to the filename,
 // and must be fully specified.
 typedef std::vector<std::pair<int, int> > file_handle_mapping_vector;
 bool LaunchApp(const std::vector<std::string>& argv,
                const file_handle_mapping_vector& fds_to_remap,
                bool wait, ProcessHandle* process_handle);
 
-#if defined(CHROMIUM_MOZILLA_BUILD) && defined(OS_LINUX)
+#if defined(CHROMIUM_MOZILLA_BUILD) && (defined(OS_LINUX) || defined(OS_MACOSX))
 typedef std::map<std::string, std::string> environment_map;
 bool LaunchApp(const std::vector<std::string>& argv,
                const file_handle_mapping_vector& fds_to_remap,
                const environment_map& env_vars_to_set,
                bool wait, ProcessHandle* process_handle);
 #endif
 #endif
 
--- a/ipc/chromium/src/base/process_util_mac.mm
+++ b/ipc/chromium/src/base/process_util_mac.mm
@@ -16,31 +16,51 @@
 
 #include "base/eintr_wrapper.h"
 #include "base/logging.h"
 #include "base/string_util.h"
 #include "base/time.h"
 
 namespace base {
 
+#if defined(CHROMIUM_MOZILLA_BUILD)
 bool LaunchApp(const std::vector<std::string>& argv,
                const file_handle_mapping_vector& fds_to_remap,
                bool wait, ProcessHandle* process_handle) {
+  return LaunchApp(argv, fds_to_remap, environment_map(),
+                   wait, process_handle);
+}
+#endif
+
+bool LaunchApp(const std::vector<std::string>& argv,
+               const file_handle_mapping_vector& fds_to_remap,
+#if defined(CHROMIUM_MOZILLA_BUILD)
+               const environment_map& env_vars_to_set,
+#endif
+               bool wait, ProcessHandle* process_handle) {
   bool retval = true;
 
   char* argv_copy[argv.size() + 1];
   for (size_t i = 0; i < argv.size(); i++) {
     argv_copy[i] = const_cast<char*>(argv[i].c_str());
   }
   argv_copy[argv.size()] = NULL;
 
   // Make sure we don't leak any FDs to the child process by marking all FDs
   // as close-on-exec.
   SetAllFDsToCloseOnExec();
 
+#if defined(CHROMIUM_MOZILLA_BUILD)
+    for (environment_map::const_iterator it = env_vars_to_set.begin();
+         it != env_vars_to_set.end(); ++it) {
+      if (setenv(it->first.c_str(), it->second.c_str(), 1/*overwrite*/))
+        exit(127);
+    }
+#endif
+
   posix_spawn_file_actions_t file_actions;
   if (posix_spawn_file_actions_init(&file_actions) != 0) {
     return false;
   }
 
   // Turn fds_to_remap array into a set of dup2 calls.
   for (file_handle_mapping_vector::const_iterator it = fds_to_remap.begin();
        it != fds_to_remap.end();
--- a/ipc/glue/GeckoChildProcessHost.cpp
+++ b/ipc/glue/GeckoChildProcessHost.cpp
@@ -214,46 +214,55 @@ GeckoChildProcessHost::PerformAsyncLaunc
 #if defined(OS_POSIX)
   // For POSIX, we have to be extremely anal about *not* using
   // std::wstring in code compiled with Mozilla's -fshort-wchar
   // configuration, because chromium is compiled with -fno-short-wchar
   // and passing wstrings from one config to the other is unsafe.  So
   // we split the logic here.
 
   FilePath exePath;
-#ifdef OS_LINUX
+#if defined(OS_LINUX) || defined(OS_MACOSX)
   base::environment_map newEnvVars;
 #endif
 
   nsCOMPtr<nsIProperties> directoryService(do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID));
   nsCOMPtr<nsIFile> greDir;
   nsresult rv = directoryService->Get(NS_GRE_DIR, NS_GET_IID(nsIFile), getter_AddRefs(greDir));
   if (NS_SUCCEEDED(rv)) {
     nsCString path;
     greDir->GetNativePath(path);
     exePath = FilePath(path.get());
 #ifdef OS_LINUX
 #ifdef ANDROID
     path += "/lib";
 #endif
     newEnvVars["LD_LIBRARY_PATH"] = path.get();
+#elif OS_MACOSX
+    newEnvVars["DYLD_LIBRARY_PATH"] = path.get();
 #endif
 #ifdef MOZ_OMNIJAR
     // Make sure the child process can find the omnijar
     // See ScopedXPCOMStartup::Initialize in nsAppRunner.cpp
     nsCAutoString omnijarPath;
     if (mozilla::OmnijarPath())
       mozilla::OmnijarPath()->GetNativePath(omnijarPath);
     newEnvVars["OMNIJAR_PATH"] = omnijarPath.get();
 #endif
   }
   else {
     exePath = FilePath(CommandLine::ForCurrentProcess()->argv()[0]);
     exePath = exePath.DirName();
   }
+
+#ifdef OS_MACOSX
+  // We need to use an App Bundle on OS X so that we can hide
+  // the dock icon. See Bug 557225
+  exePath = exePath.AppendASCII(MOZ_CHILD_PROCESS_BUNDLE);
+#endif
+
   exePath = exePath.AppendASCII(MOZ_CHILD_PROCESS_NAME);
 
 #ifdef ANDROID
   // The java wrapper unpacks this for us but can't make it executable
   chmod(exePath.value().c_str(), 0700);
 #endif
 
   // remap the IPC socket fd to a well-known int, as the OS does for
@@ -292,17 +301,17 @@ GeckoChildProcessHost::PerformAsyncLaunc
 #  elif defined(XP_MACOSX)
   // Call the stub for initialization side effects.  Eventually this
   // code will be unified with that above.
   CrashReporter::CreateNotificationPipeForChild();
 #  endif  // OS_LINUX
 #endif
 
   base::LaunchApp(childArgv, mFileMap,
-#ifdef OS_LINUX
+#if defined(OS_LINUX) || defined(OS_MACOSX)
                   newEnvVars,
 #endif
                   false, &process);
 
 //--------------------------------------------------
 #elif defined(OS_WIN)
 
   FilePath exePath =
--- a/ipc/glue/Makefile.in
+++ b/ipc/glue/Makefile.in
@@ -89,17 +89,18 @@ CPPSRCS += \
   SharedMemory_windows.cpp \
   WindowsMessageLoop.cpp \
   $(NULL)
 else
 CPPSRCS += SharedMemory_posix.cpp
 endif
 
 include $(topsrcdir)/ipc/app/defs.mk
-DEFINES += -DMOZ_CHILD_PROCESS_NAME="\"$(MOZ_CHILD_PROCESS_NAME)\""
+DEFINES += -DMOZ_CHILD_PROCESS_NAME=\"$(MOZ_CHILD_PROCESS_NAME)\"
+DEFINES += -DMOZ_CHILD_PROCESS_BUNDLE=\"$(MOZ_CHILD_PROCESS_BUNDLE)\"
 
 include $(topsrcdir)/config/config.mk
 include $(topsrcdir)/ipc/chromium/chromium-config.mk
 
 include $(topsrcdir)/config/rules.mk
 
 # Since we get the value of MOZ_CHILD_PROCESS_NAME from another file make sure
 # to rebuild if that file changes.