diff --git a/mozilla/nsprpub/pr/include/prenv.h b/mozilla/nsprpub/pr/include/prenv.h index c7c88a9567c..6bed8d5851e 100644 --- a/mozilla/nsprpub/pr/include/prenv.h +++ b/mozilla/nsprpub/pr/include/prenv.h @@ -35,6 +35,10 @@ PR_BEGIN_EXTERN_C */ PR_EXTERN(char*) PR_GetEnv(const char *var); +#ifdef XP_MAC +PR_EXTERN(PRIntn) PR_PutEnv(const char *string); +#endif + PR_END_EXTERN_C #endif /* prenv_h___ */ diff --git a/mozilla/nsprpub/pr/src/misc/prenv.c b/mozilla/nsprpub/pr/src/misc/prenv.c index e0db2d6da42..c09fe7d2f87 100644 --- a/mozilla/nsprpub/pr/src/misc/prenv.c +++ b/mozilla/nsprpub/pr/src/misc/prenv.c @@ -55,3 +55,18 @@ PR_IMPLEMENT(char*) PR_GetEnv(const char *var) _PR_UNLOCK_ENV(); return ev; } + +#ifdef XP_MAC +PR_IMPLEMENT(PRIntn) PR_PutEnv(const char *string) +{ + PRIntn result; + + if (!_pr_initialized) _PR_ImplicitInitialization(); + + _PR_LOCK_ENV(); + result = _PR_MD_PUT_ENV(string); + _PR_UNLOCK_ENV(); + return result; +} +#endif + diff --git a/mozilla/xpfe/appshell/src/nsCommandLineServiceMac.cpp b/mozilla/xpfe/appshell/src/nsCommandLineServiceMac.cpp index 40a96c4f164..8ad74468a86 100644 --- a/mozilla/xpfe/appshell/src/nsCommandLineServiceMac.cpp +++ b/mozilla/xpfe/appshell/src/nsCommandLineServiceMac.cpp @@ -44,6 +44,7 @@ static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); // NSPR #include "prmem.h" #include "plstr.h" +#include "prenv.h" // Universal #include @@ -139,6 +140,8 @@ private: OSErr AddToCommandLine(const char* inOptionString, const FSSpec& inFileSpec); + void AddToEnvironmentVars(const char* inArgText); + OSErr DispatchURLToNewBrowser(const char* url); OSErr HandleOpenURLEvent(const AppleEvent &inAppleEvent, @@ -488,6 +491,13 @@ OSErr nsAppleEventHandler::AddToCommandLine(const char* inArgText) return noErr; } +//---------------------------------------------------------------------------------------- +void nsAppleEventHandler::AddToEnvironmentVars(const char* inArgText) +//---------------------------------------------------------------------------------------- +{ + (void)PR_PutEnv(inArgText); +} + //---------------------------------------------------------------------------------------- OSErr nsAppleEventHandler::HandleOpen1Doc(const FSSpec& inFileSpec, OSType inFileType) //---------------------------------------------------------------------------------------- @@ -501,15 +511,34 @@ OSErr nsAppleEventHandler::HandleOpen1Doc(const FSSpec& inFileSpec, OSType inFil nsInputFileStream s(inFileSpec); if (s.is_open()) { + Boolean foundArgs = false; char chars[1024]; - s.readline(chars, sizeof(chars)); - // Does the text in it have the right prefix? const char* kCommandLinePrefix = "ARGS:"; - if (PL_strstr(chars, kCommandLinePrefix) == chars) - { - return AddToCommandLine(chars + PL_strlen(kCommandLinePrefix)); - // That's all we have to do. - } + const char* kEnvVarLinePrefix = "ENV:"; + s.readline(chars, sizeof(chars)); + + do + { // See if there are any command line or environment var settings + if (PL_strstr(chars, kCommandLinePrefix) == chars) + { + (void)AddToCommandLine(chars + PL_strlen(kCommandLinePrefix)); + foundArgs = true; + } + else if (PL_strstr(chars, kEnvVarLinePrefix) == chars) + { + (void)AddToEnvironmentVars(chars + PL_strlen(kEnvVarLinePrefix)); + foundArgs = true; + } + + // Clear the buffer and get the next line from the command line file + chars[0] = '\0'; + s.readline(chars, sizeof(chars)); + } while (PL_strlen(chars)); + + // If we found a command line or environment vars we want to return now + // raather than trying to open the file as a URL + if (foundArgs) + return noErr; } } // If it's not a command-line argument, and we are starting up the application, diff --git a/mozilla/xpfe/components/startup/src/nsCommandLineServiceMac.cpp b/mozilla/xpfe/components/startup/src/nsCommandLineServiceMac.cpp index 40a96c4f164..8ad74468a86 100644 --- a/mozilla/xpfe/components/startup/src/nsCommandLineServiceMac.cpp +++ b/mozilla/xpfe/components/startup/src/nsCommandLineServiceMac.cpp @@ -44,6 +44,7 @@ static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); // NSPR #include "prmem.h" #include "plstr.h" +#include "prenv.h" // Universal #include @@ -139,6 +140,8 @@ private: OSErr AddToCommandLine(const char* inOptionString, const FSSpec& inFileSpec); + void AddToEnvironmentVars(const char* inArgText); + OSErr DispatchURLToNewBrowser(const char* url); OSErr HandleOpenURLEvent(const AppleEvent &inAppleEvent, @@ -488,6 +491,13 @@ OSErr nsAppleEventHandler::AddToCommandLine(const char* inArgText) return noErr; } +//---------------------------------------------------------------------------------------- +void nsAppleEventHandler::AddToEnvironmentVars(const char* inArgText) +//---------------------------------------------------------------------------------------- +{ + (void)PR_PutEnv(inArgText); +} + //---------------------------------------------------------------------------------------- OSErr nsAppleEventHandler::HandleOpen1Doc(const FSSpec& inFileSpec, OSType inFileType) //---------------------------------------------------------------------------------------- @@ -501,15 +511,34 @@ OSErr nsAppleEventHandler::HandleOpen1Doc(const FSSpec& inFileSpec, OSType inFil nsInputFileStream s(inFileSpec); if (s.is_open()) { + Boolean foundArgs = false; char chars[1024]; - s.readline(chars, sizeof(chars)); - // Does the text in it have the right prefix? const char* kCommandLinePrefix = "ARGS:"; - if (PL_strstr(chars, kCommandLinePrefix) == chars) - { - return AddToCommandLine(chars + PL_strlen(kCommandLinePrefix)); - // That's all we have to do. - } + const char* kEnvVarLinePrefix = "ENV:"; + s.readline(chars, sizeof(chars)); + + do + { // See if there are any command line or environment var settings + if (PL_strstr(chars, kCommandLinePrefix) == chars) + { + (void)AddToCommandLine(chars + PL_strlen(kCommandLinePrefix)); + foundArgs = true; + } + else if (PL_strstr(chars, kEnvVarLinePrefix) == chars) + { + (void)AddToEnvironmentVars(chars + PL_strlen(kEnvVarLinePrefix)); + foundArgs = true; + } + + // Clear the buffer and get the next line from the command line file + chars[0] = '\0'; + s.readline(chars, sizeof(chars)); + } while (PL_strlen(chars)); + + // If we found a command line or environment vars we want to return now + // raather than trying to open the file as a URL + if (foundArgs) + return noErr; } } // If it's not a command-line argument, and we are starting up the application,