diff --git a/browser/app/Makefile.in b/browser/app/Makefile.in index cba371d0c63..638fa2fda88 100644 --- a/browser/app/Makefile.in +++ b/browser/app/Makefile.in @@ -73,6 +73,7 @@ CPPSRCS = nsBrowserApp.cpp LOCAL_INCLUDES += -I$(topsrcdir)/toolkit/xre LOCAL_INCLUDES += -I$(topsrcdir)/xpcom/base LOCAL_INCLUDES += -I$(topsrcdir)/xpcom/build +LOCAL_INCLUDES += -I$(DEPTH)/build DEFINES += -DXPCOM_GLUE STL_FLAGS= diff --git a/browser/app/nsBrowserApp.cpp b/browser/app/nsBrowserApp.cpp index d0f1c3c44ab..5df1289b8cc 100644 --- a/browser/app/nsBrowserApp.cpp +++ b/browser/app/nsBrowserApp.cpp @@ -36,8 +36,8 @@ * * ***** END LICENSE BLOCK ***** */ +#include "application.ini.h" #include "nsXPCOMGlue.h" -#include "nsXULAppAPI.h" #if defined(XP_WIN) #include #include @@ -140,20 +140,7 @@ static const nsDynamicFunctionLoad kXULFuncs[] = { static int do_main(const char *exePath, int argc, char* argv[]) { nsCOMPtr appini; -#ifdef XP_WIN - // exePath comes from mozilla::BinaryPath::Get, which returns a UTF-8 - // encoded path, so it is safe to convert it - nsresult rv = NS_NewLocalFile(NS_ConvertUTF8toUTF16(exePath), false, - getter_AddRefs(appini)); -#else - nsresult rv = NS_NewNativeLocalFile(nsDependentCString(exePath), false, - getter_AddRefs(appini)); -#endif - if (NS_FAILED(rv)) { - return 255; - } - - appini->SetNativeLeafName(NS_LITERAL_CSTRING("application.ini")); + nsresult rv; // Allow firefox.exe to launch XULRunner apps via -app // Note that -app must be the *first* argument. @@ -188,15 +175,32 @@ static int do_main(const char *exePath, int argc, char* argv[]) argc -= 2; } - nsXREAppData *appData; - rv = XRE_CreateAppData(appini, &appData); - if (NS_FAILED(rv)) { - Output("Couldn't read application.ini"); - return 255; + int result; + if (appini) { + nsXREAppData *appData; + rv = XRE_CreateAppData(appini, &appData); + if (NS_FAILED(rv)) { + Output("Couldn't read application.ini"); + return 255; + } + result = XRE_main(argc, argv, appData); + XRE_FreeAppData(appData); + } else { +#ifdef XP_WIN + // exePath comes from mozilla::BinaryPath::Get, which returns a UTF-8 + // encoded path, so it is safe to convert it + rv = NS_NewLocalFile(NS_ConvertUTF8toUTF16(exePath), PR_FALSE, + getter_AddRefs(appini)); +#else + rv = NS_NewNativeLocalFile(nsDependentCString(exePath), PR_FALSE, + getter_AddRefs(appini)); +#endif + if (NS_FAILED(rv)) { + return 255; + } + result = XRE_main(argc, argv, &sAppData); } - int result = XRE_main(argc, argv, appData); - XRE_FreeAppData(appData); return result; } @@ -240,6 +244,8 @@ int main(int argc, char* argv[]) Output("Couldn't load XPCOM.\n"); return 255; } + // Reset exePath so that it is the directory name and not the xpcom dll name + *lastSlash = 0; rv = XPCOMGlueLoadXULFunctions(kXULFuncs); if (NS_FAILED(rv)) { diff --git a/browser/confvars.sh b/browser/confvars.sh index e67254d7644..cb045970777 100755 --- a/browser/confvars.sh +++ b/browser/confvars.sh @@ -54,3 +54,4 @@ MOZ_OFFICIAL_BRANDING_DIRECTORY=browser/branding/official MOZ_APP_ID={ec8030f7-c20a-464f-9b0e-13a3a9e97384} MOZ_PROFILE_MIGRATOR=1 MOZ_EXTENSION_MANAGER=1 +MOZ_APP_STATIC_INI=1 diff --git a/build/Makefile.in b/build/Makefile.in index d7b04aa902e..428c1ae15e2 100644 --- a/build/Makefile.in +++ b/build/Makefile.in @@ -71,15 +71,19 @@ DIST_FILES = application.ini ifdef LIBXUL_SDK GRE_MILESTONE = $(shell $(PYTHON) $(topsrcdir)/config/printconfigsetting.py $(LIBXUL_DIST)/bin/platform.ini Build Milestone) +APP_INI_DEPS = $(LIBXUL_DIST)/bin/platform.ini else GRE_MILESTONE = $(shell tail -n 1 $(topsrcdir)/config/milestone.txt 2>/dev/null || tail -1 $(topsrcdir)/config/milestone.txt) +APP_INI_DEPS = $(topsrcdir)/config/milestone.txt endif APP_BUILDID := $(shell cat $(DEPTH)/config/buildid) +APP_INI_DEPS += $(DEPTH)/config/buildid DEFINES += -DGRE_MILESTONE=$(GRE_MILESTONE) -DAPP_BUILDID=$(APP_BUILDID) DEFINES += -DMOZ_APP_VERSION="$(MOZ_APP_VERSION)" +APP_INI_DEPS += $(DEPTH)/config/autoconf.mk MOZ_SOURCE_STAMP ?= $(firstword $(shell hg -R $(topsrcdir) parent --template="{node|short}\n" 2>/dev/null)) ifdef MOZ_SOURCE_STAMP @@ -150,6 +154,19 @@ leaktest.py: leaktest.py.in chmod +x $@ GARBAGE += leaktest.py +ifdef MOZ_APP_BASENAME +application.ini: application.ini.in $(APP_INI_DEPS) + $(PYTHON) $(topsrcdir)/config/Preprocessor.py $(DEFINES) $< > $@ +GARBAGE += application.ini + +ifdef MOZ_APP_STATIC_INI +application.ini.h: appini_header.py application.ini + $(PYTHON) $^ > $@ +export:: application.ini.h +GARBAGE += application.ini.h +endif +endif + libs:: $(_LEAKTEST_FILES) $(INSTALL) $^ $(_LEAKTEST_DIR) diff --git a/build/appini_header.py b/build/appini_header.py new file mode 100644 index 00000000000..0fa7763a81e --- /dev/null +++ b/build/appini_header.py @@ -0,0 +1,86 @@ +# ***** BEGIN LICENSE BLOCK ***** +# Version: MPL 1.1/GPL 2.0/LGPL 2.1 +# +# The contents of this file are subject to the Mozilla Public License Version +# 1.1 (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +# for the specific language governing rights and limitations under the +# License. +# +# The Original Code is a build helper for libraries +# +# The Initial Developer of the Original Code is +# the Mozilla Foundation +# Portions created by the Initial Developer are Copyright (C) 2011 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# Mike Hommey +# +# Alternatively, the contents of this file may be used under the terms of +# either the GNU General Public License Version 2 or later (the "GPL"), or +# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), +# in which case the provisions of the GPL or the LGPL are applicable instead +# of those above. If you wish to allow use of your version of this file only +# under the terms of either the GPL or the LGPL, and not to allow others to +# use your version of this file under the terms of the MPL, indicate your +# 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 ***** + +'''Parses a given application.ini file and outputs the corresponding + XULAppData structure as a C++ header file''' + +import ConfigParser +import sys + +def main(file): + config = ConfigParser.RawConfigParser() + config.read(file) + flags = set() + try: + if config.getint('XRE', 'EnableExtensionManager') == 1: + flags.add('NS_XRE_ENABLE_EXTENSION_MANAGER') + except: pass + try: + if config.getint('XRE', 'EnableProfileMigrator') == 1: + flags.add('NS_XRE_ENABLE_PROFILE_MIGRATOR') + except: pass + try: + if config.getint('Crash Reporter', 'Enabled') == 1: + flags.add('NS_XRE_ENABLE_CRASH_REPORTER') + except: pass + appdata = dict(("%s:%s" % (s, o), config.get(s, o)) for s in config.sections() for o in config.options(s)) + appdata['flags'] = ' | '.join(flags) if flags else '0' + appdata['App:profile'] = '"%s"' % appdata['App:profile'] if 'App:profile' in appdata else 'NULL' + + print '''#include "nsXULAppAPI.h" + static const nsXREAppData sAppData = { + sizeof(nsXREAppData), + NULL, // directory + "%(App:vendor)s", + "%(App:name)s", + "%(App:version)s", + "%(App:buildid)s", + "%(App:id)s", + NULL, // copyright + %(flags)s, + NULL, // xreDirectory + "%(Gecko:minversion)s", + "%(Gecko:maxversion)s", + "%(Crash Reporter:serverurl)s", + %(App:profile)s + };''' % appdata + +if __name__ == '__main__': + if len(sys.argv) != 1: + main(sys.argv[1]) + else: + print >>sys.stderr, "Usage: %s /path/to/application.ini" % sys.argv[0] diff --git a/build/application.ini b/build/application.ini.in similarity index 92% rename from build/application.ini rename to build/application.ini.in index 06f64467069..8f1233978df 100644 --- a/build/application.ini +++ b/build/application.ini.in @@ -1,3 +1,8 @@ +#if MOZ_APP_STATIC_INI +; This file is not used. If you modify it and want the application to use +; your modifications, start with the "-app /path/to/application.ini" +; argument. +#endif #if 0 ; ***** BEGIN LICENSE BLOCK ***** ; Version: MPL 1.1/GPL 2.0/LGPL 2.1 diff --git a/config/autoconf.mk.in b/config/autoconf.mk.in index 1b02e7da761..17608a5e370 100644 --- a/config/autoconf.mk.in +++ b/config/autoconf.mk.in @@ -58,6 +58,7 @@ MOZ_EXTENSION_MANAGER = @MOZ_EXTENSION_MANAGER@ MOZ_APP_UA_NAME = @MOZ_APP_UA_NAME@ MOZ_APP_VERSION = @MOZ_APP_VERSION@ MOZ_UA_BUILDID = @MOZ_UA_BUILDID@ +MOZ_APP_STATIC_INI = @MOZ_APP_STATIC_INI@ MOZ_PKG_SPECIAL = @MOZ_PKG_SPECIAL@ diff --git a/configure.in b/configure.in index 29064ed5ef0..54a33551276 100644 --- a/configure.in +++ b/configure.in @@ -8535,6 +8535,13 @@ AC_SUBST(FIREFOX_VERSION) AC_DEFINE_UNQUOTED(MOZ_UA_BUILDID, "$MOZ_UA_BUILDID") AC_SUBST(MOZ_UA_BUILDID) +# We can't use the static application.ini data when building against +# a libxul SDK. +if test -n "$LIBXUL_SDK"; then + MOZ_APP_STATIC_INI= +fi +AC_SUBST(MOZ_APP_STATIC_INI) + AC_SUBST(MOZ_PKG_SPECIAL) AC_SUBST(MOZILLA_OFFICIAL) diff --git a/embedding/android/GeckoApp.java b/embedding/android/GeckoApp.java index c6254c7c92e..48a9a2412f2 100644 --- a/embedding/android/GeckoApp.java +++ b/embedding/android/GeckoApp.java @@ -618,7 +618,6 @@ abstract public class GeckoApp // This file may not be there, so just log any errors and move on Log.w(LOG_FILE_NAME, "error removing files", ex); } - unpackFile(zip, buf, null, "application.ini"); try { unpackFile(zip, buf, null, "update.locale"); } catch (Exception e) {/* this is non-fatal */} diff --git a/mobile/xul/app/Makefile.in b/mobile/xul/app/Makefile.in index d796096ddbe..3f510328da8 100644 --- a/mobile/xul/app/Makefile.in +++ b/mobile/xul/app/Makefile.in @@ -55,6 +55,7 @@ CPPSRCS = nsBrowserApp.cpp LOCAL_INCLUDES += -I$(topsrcdir)/toolkit/xre LOCAL_INCLUDES += -I$(topsrcdir)/xpcom/base LOCAL_INCLUDES += -I$(topsrcdir)/xpcom/build +LOCAL_INCLUDES += -I$(DEPTH)/build DEFINES += -DXPCOM_GLUE STL_FLAGS= diff --git a/mobile/xul/app/nsBrowserApp.cpp b/mobile/xul/app/nsBrowserApp.cpp index dfc445ca660..4212e61dde7 100644 --- a/mobile/xul/app/nsBrowserApp.cpp +++ b/mobile/xul/app/nsBrowserApp.cpp @@ -36,8 +36,8 @@ * * ***** END LICENSE BLOCK ***** */ +#include "application.ini.h" #include "nsXPCOMGlue.h" -#include "nsXULAppAPI.h" #if defined(XP_WIN) #include #include @@ -147,20 +147,7 @@ static const nsDynamicFunctionLoad kXULFuncs[] = { static int do_main(const char *exePath, int argc, char* argv[]) { nsCOMPtr appini; -#ifdef XP_WIN - // exePath comes from mozilla::BinaryPath::Get, which returns a UTF-8 - // encoded path, so it is safe to convert it - nsresult rv = NS_NewLocalFile(NS_ConvertUTF8toUTF16(exePath), false, - getter_AddRefs(appini)); -#else - nsresult rv = NS_NewNativeLocalFile(nsDependentCString(exePath), false, - getter_AddRefs(appini)); -#endif - if (NS_FAILED(rv)) { - return 255; - } - - appini->SetNativeLeafName(NS_LITERAL_CSTRING("application.ini")); + nsresult rv; // Allow firefox.exe to launch XULRunner apps via -app // Note that -app must be the *first* argument. @@ -195,15 +182,32 @@ static int do_main(const char *exePath, int argc, char* argv[]) argc -= 2; } - nsXREAppData *appData; - rv = XRE_CreateAppData(appini, &appData); - if (NS_FAILED(rv)) { - Output("Couldn't read application.ini"); - return 255; + int result; + if (appini) { + nsXREAppData *appData; + rv = XRE_CreateAppData(appini, &appData); + if (NS_FAILED(rv)) { + Output("Couldn't read application.ini"); + return 255; + } + result = XRE_main(argc, argv, appData); + XRE_FreeAppData(appData); + } else { +#ifdef XP_WIN + // exePath comes from mozilla::BinaryPath::Get, which returns a UTF-8 + // encoded path, so it is safe to convert it + rv = NS_NewLocalFile(NS_ConvertUTF8toUTF16(exePath), PR_FALSE, + getter_AddRefs(appini)); +#else + rv = NS_NewNativeLocalFile(nsDependentCString(exePath), PR_FALSE, + getter_AddRefs(appini)); +#endif + if (NS_FAILED(rv)) { + return 255; + } + result = XRE_main(argc, argv, &sAppData); } - int result = XRE_main(argc, argv, appData); - XRE_FreeAppData(appData); return result; } @@ -269,6 +273,8 @@ int main(int argc, char* argv[]) Output("Couldn't load XPCOM.\n"); return 255; } + // Reset exePath so that it is the directory name and not the xpcom dll name + *lastSlash = 0; rv = XPCOMGlueLoadXULFunctions(kXULFuncs); if (NS_FAILED(rv)) { diff --git a/mobile/xul/confvars.sh b/mobile/xul/confvars.sh index a3ce9ecaefd..1f4968e37ac 100644 --- a/mobile/xul/confvars.sh +++ b/mobile/xul/confvars.sh @@ -70,3 +70,4 @@ MOZ_USE_NATIVE_POPUP_WINDOWS=1 MOZ_APP_ID={a23983c0-fd0e-11dc-95ff-0800200c9a66} MOZ_EXTENSION_MANAGER=1 +MOZ_APP_STATIC_INI=1 diff --git a/toolkit/xre/Makefile.in b/toolkit/xre/Makefile.in index 7b5996f095d..f15e0f9bcb9 100644 --- a/toolkit/xre/Makefile.in +++ b/toolkit/xre/Makefile.in @@ -200,6 +200,11 @@ LOCAL_INCLUDES += \ -I$(topsrcdir)/config \ $(NULL) +ifdef MOZ_APP_STATIC_INI +LOCAL_INCLUDES += -I$(DEPTH)/build +DEFINES += -DMOZ_APP_STATIC_INI +endif + CXXFLAGS += $(TK_CFLAGS) $(MOZ_DBUS_CFLAGS) $(MOZ_DBUS_GLIB_CFLAGS) ifeq ($(MOZ_WIDGET_TOOLKIT),gtk2) diff --git a/toolkit/xre/nsAndroidStartup.cpp b/toolkit/xre/nsAndroidStartup.cpp index 0d302032f35..f0dcec14632 100644 --- a/toolkit/xre/nsAndroidStartup.cpp +++ b/toolkit/xre/nsAndroidStartup.cpp @@ -39,6 +39,8 @@ * * ***** END LICENSE BLOCK ***** */ +#include "application.ini.h" + #include #include @@ -90,37 +92,6 @@ GeckoStart(void *data) return 0; } - nsresult rv; - nsCOMPtr appini; - char* greHome = getenv("GRE_HOME"); - if (!greHome) { - LOG("Failed to get GRE_HOME from the env vars"); - return 0; - } - nsCAutoString appini_path(greHome); - appini_path.AppendLiteral("/application.ini"); - rv = NS_NewNativeLocalFile(appini_path, false, getter_AddRefs(appini)); - if (NS_FAILED(rv)) { - LOG("Failed to create nsILocalFile for appdata\n"); - return 0; - } - - nsXREAppData *appData; - rv = XRE_CreateAppData(appini, &appData); - if (NS_FAILED(rv)) { - LOG("Failed to load application.ini from %s\n", appini_path.get()); - return 0; - } - - nsCOMPtr xreDir; - rv = NS_NewNativeLocalFile(nsDependentCString(greHome), false, getter_AddRefs(xreDir)); - if (NS_FAILED(rv)) { - LOG("Failed to create nsIFile for xreDirectory"); - return 0; - } - - appData->xreDirectory = xreDir.get(); - nsTArray targs; char *arg = strtok(static_cast(data), " "); while (arg) { @@ -129,13 +100,11 @@ GeckoStart(void *data) } targs.AppendElement(static_cast(nsnull)); - int result = XRE_main(targs.Length() - 1, targs.Elements(), appData); + int result = XRE_main(targs.Length() - 1, targs.Elements(), &sAppData); if (result) LOG("XRE_main returned %d", result); - XRE_FreeAppData(appData); - mozilla::AndroidBridge::Bridge()->NotifyXreExit(); free(targs[0]); diff --git a/toolkit/xre/nsAppRunner.cpp b/toolkit/xre/nsAppRunner.cpp index 85497a67619..07790c1bd8d 100644 --- a/toolkit/xre/nsAppRunner.cpp +++ b/toolkit/xre/nsAppRunner.cpp @@ -2767,6 +2767,10 @@ XRE_main(int argc, char* argv[], const nsXREAppData* aAppData) return 2; } + if (!appData.directory) { + NS_IF_ADDREF(appData.directory = appData.xreDirectory); + } + if (appData.size > offsetof(nsXREAppData, minVersion)) { if (!appData.minVersion) { Output(true, "Error: Gecko:MinVersion not specified in application.ini\n"); diff --git a/xpcom/build/BinaryPath.h b/xpcom/build/BinaryPath.h index 4128c6cf86d..0d657fc3d14 100644 --- a/xpcom/build/BinaryPath.h +++ b/xpcom/build/BinaryPath.h @@ -94,6 +94,20 @@ private: return rv; } +#elif defined(ANDROID) + static nsresult Get(const char *argv0, char aResult[MAXPATHLEN]) + { + // On Android, we use the GRE_HOME variable that is set by the Java + // bootstrap code. + const char *greHome = getenv("GRE_HOME"); + if (!greHome) + return NS_ERROR_FAILURE; + + snprintf(aResult, MAXPATHLEN, "%s/%s", greHome, "dummy"); + aResult[MAXPATHLEN] = '\0'; + return NS_OK; + } + #elif defined(XP_UNIX) static nsresult Get(const char *argv0, char aResult[MAXPATHLEN]) {