From 511eec13fbecfae987078e31e291b0ed9bb221e4 Mon Sep 17 00:00:00 2001 From: "bsmedberg%covad.net" Date: Sat, 4 Dec 2004 18:25:46 +0000 Subject: [PATCH] Bug 273089 - Add a scriptable getter to the nsXULAppAPI information r=darin git-svn-id: svn://10.0.0.236/trunk@166247 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/toolkit/xre/Makefile.in | 8 +- mozilla/toolkit/xre/nsAppRunner.cpp | 101 ++++++++++++++++++++++++++ mozilla/toolkit/xre/nsIXULAppInfo.idl | 84 +++++++++++++++++++++ mozilla/toolkit/xre/nsXULAppAPI.h | 6 ++ 4 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 mozilla/toolkit/xre/nsIXULAppInfo.idl diff --git a/mozilla/toolkit/xre/Makefile.in b/mozilla/toolkit/xre/Makefile.in index bbcc8e8ca82..5ebfdda792a 100644 --- a/mozilla/toolkit/xre/Makefile.in +++ b/mozilla/toolkit/xre/Makefile.in @@ -88,7 +88,10 @@ endif FORCE_STATIC_LIB = 1 -XPIDLSRCS = nsINativeAppSupport.idl +XPIDLSRCS = \ + nsINativeAppSupport.idl \ + nsIXULAppInfo.idl \ + $(NULL) EXPORTS = nsXULAppAPI.h @@ -103,6 +106,9 @@ CPPSRCS = \ nsNativeAppSupportBase.cpp \ $(NULL) +BUILD_ID = $(shell cat $(DEPTH)/config/build_number) +DEFINES += -DBUILD_ID=\"$(BUILD_ID)\" + ifeq ($(MOZ_WIDGET_TOOLKIT),windows) CPPSRCS += nsNativeAppSupportWin.cpp DEFINES += -DWIN32_LEAN_AND_MEAN diff --git a/mozilla/toolkit/xre/nsAppRunner.cpp b/mozilla/toolkit/xre/nsAppRunner.cpp index a8b19db361f..644354d10ab 100644 --- a/mozilla/toolkit/xre/nsAppRunner.cpp +++ b/mozilla/toolkit/xre/nsAppRunner.cpp @@ -84,6 +84,7 @@ #include "nsIWindowCreator.h" #include "nsIWindowMediator.h" #include "nsIWindowWatcher.h" +#include "nsIXULAppInfo.h" #include "nsCRT.h" #include "nsCOMPtr.h" @@ -840,6 +841,92 @@ DumpHelp() DumpArbitraryHelp(); } +/** + * The nsXULAppInfo object implements nsIFactory so that it can be its own + * singleton. + */ +class nsXULAppInfo : public nsIXULAppInfo, + public nsIFactory +{ +public: + NS_DECL_ISUPPORTS_INHERITED + NS_DECL_NSIXULAPPINFO + NS_DECL_NSIFACTORY +}; + +NS_IMPL_QUERY_INTERFACE2(nsXULAppInfo, + nsIXULAppInfo, + nsIFactory) + +NS_IMETHODIMP_(nsrefcnt) +nsXULAppInfo::AddRef() +{ + return 1; +} + +NS_IMETHODIMP_(nsrefcnt) +nsXULAppInfo::Release() +{ + return 1; +} + +NS_IMETHODIMP +nsXULAppInfo::GetVendor(nsACString& aResult) +{ + aResult.Assign(gAppData->appVendor ? gAppData->appVendor : ""); + + return NS_OK; +} + +NS_IMETHODIMP +nsXULAppInfo::GetName(nsACString& aResult) +{ + aResult.Assign(gAppData->appName); + + return NS_OK; +} + +NS_IMETHODIMP +nsXULAppInfo::GetVersion(nsACString& aResult) +{ + aResult.Assign(gAppData->appVersion ? gAppData->appVersion : ""); + + return NS_OK; +} + +NS_IMETHODIMP +nsXULAppInfo::GetAppBuildID(nsACString& aResult) +{ + aResult.Assign(gAppData->appBuildID ? gAppData->appBuildID : ""); + + return NS_OK; +} + +NS_IMETHODIMP +nsXULAppInfo::GetGeckoBuildID(nsACString& aResult) +{ + aResult.Assign(BUILD_ID); + + return NS_OK; +} + +NS_IMETHODIMP +nsXULAppInfo::CreateInstance(nsISupports* aOuter, + REFNSIID aIID, + void** aResult) +{ + NS_ENSURE_NO_AGGREGATION(aOuter); + + return QueryInterface(aIID, aResult); +} + +NS_IMETHODIMP +nsXULAppInfo::LockFactory(PRBool aLock) +{ + return NS_OK; +} + +static const nsXULAppInfo kAppInfo; /** * Because we're starting/stopping XPCOM several times in different scenarios, @@ -874,6 +961,11 @@ ScopedXPCOMStartup::~ScopedXPCOMStartup() } } +// {95d89e3e-a169-41a3-8e56-719978e15b12} +static const nsCID kAppInfoCID = + { 0x95d89e3e, 0xa169, 0x41a3, { 0x8e, 0x56, 0x71, 0x99, 0x78, 0xe1, 0x5b, 0x12 } }; + + nsresult ScopedXPCOMStartup::Initialize() { @@ -886,6 +978,15 @@ ScopedXPCOMStartup::Initialize() NS_ERROR("Couldn't start xpcom!"); mServiceManager = nsnull; } + else { + nsCOMPtr reg = + do_QueryInterface(mServiceManager); + NS_ASSERTION(reg, "Service Manager doesn't QI to Registrar."); + + reg->RegisterFactory(kAppInfoCID, "nsXULAppInfo", + XULAPPINFO_SERVICE_CONTRACTID, + NS_CONST_CAST(nsXULAppInfo*,&kAppInfo)); + } return rv; } diff --git a/mozilla/toolkit/xre/nsIXULAppInfo.idl b/mozilla/toolkit/xre/nsIXULAppInfo.idl new file mode 100644 index 00000000000..a09b4579374 --- /dev/null +++ b/mozilla/toolkit/xre/nsIXULAppInfo.idl @@ -0,0 +1,84 @@ +/* ***** 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 XUL bootstrap code. + * + * The Initial Developer of the Original Code is + * Benjamin Smedberg + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * 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 ***** */ + +#include "nsISupports.idl" + +/** + * A scriptable interface to the nsXULAppAPI structure. + * + * @status IN-FLUX This interface *will* change before it stabilizes. Use at your + * own risk. + */ + +[scriptable, uuid(e781bdd9-bc92-4deb-a1e8-8cbf94365ef9)] +interface nsIXULAppInfo : nsISupports +{ + /** + * The name of the application vendor. This is ASCII, and is normally + * mixed-case; e.g. "Mozilla". It may not be specified, resulting in the + * empty string. + */ + readonly attribute ACString vendor; + + /** + * The name of the application. This is ASCII, and is normally mixed-case; + * e.g. "Firefox". + */ + readonly attribute ACString name; + + /** + * The version of the application. By tradition, this is in the form + * .. with an optonal trailing + + */ + readonly attribute ACString version; + + /** + * The build ID/date of the application. For xulrunner applications, + * this will be different than the build ID of gecko. Be careful + * about which one you want. It is in the form YYYYMMDDHH. + */ + readonly attribute ACString appBuildID; + + /** + * Thie build ID/date of gecko and the xulrunner. + */ + readonly attribute ACString geckoBuildID; + + /** + * XXXTodo: add app UUID and em-enablement prefs. Also + * think about adding safe-mode. + */ +}; diff --git a/mozilla/toolkit/xre/nsXULAppAPI.h b/mozilla/toolkit/xre/nsXULAppAPI.h index 4bd1f7439d0..f411b6b05a1 100644 --- a/mozilla/toolkit/xre/nsXULAppAPI.h +++ b/mozilla/toolkit/xre/nsXULAppAPI.h @@ -103,6 +103,12 @@ struct nsXREAppData PRUint32 flags; }; +/** + * The contract id for the nsIXULAppInfo service. + */ +#define XULAPPINFO_SERVICE_CONTRACTID \ + "@mozilla.org/xre/app-info;1" + /** * Begin an XUL application. Does not return until the user exits the * application.