From c77efb58c1ff08d366c1173f7e613133a15d0b68 Mon Sep 17 00:00:00 2001 From: Jiten Thakkar Date: Tue, 4 Oct 2011 16:31:00 -0400 Subject: [PATCH] Bug 683245 - Make navigator.buildID and navigator.version work in content processes. r=bsmedberg --- dom/ipc/ContentChild.cpp | 8 ++++++++ dom/ipc/ContentChild.h | 14 ++++++++++++++ dom/ipc/ContentParent.cpp | 9 +++++++++ dom/ipc/Makefile.in | 1 + dom/ipc/PContent.ipdl | 2 ++ toolkit/xre/nsAppRunner.cpp | 27 ++++++++++++++++++++++++++- 6 files changed, 60 insertions(+), 1 deletion(-) diff --git a/dom/ipc/ContentChild.cpp b/dom/ipc/ContentChild.cpp index ea0f50f72eed..31cc370db770 100644 --- a/dom/ipc/ContentChild.cpp +++ b/dom/ipc/ContentChild.cpp @@ -789,5 +789,13 @@ ContentChild::RecvCycleCollect() return true; } +bool +ContentChild::RecvAppInfo(const nsCString& version, const nsCString& buildID) +{ + mAppInfo.version.Assign(version); + mAppInfo.buildID.Assign(buildID); + return true; +} + } // namespace dom } // namespace mozilla diff --git a/dom/ipc/ContentChild.h b/dom/ipc/ContentChild.h index bb9dab77e365..21c58398e290 100644 --- a/dom/ipc/ContentChild.h +++ b/dom/ipc/ContentChild.h @@ -64,6 +64,12 @@ public: ContentChild(); virtual ~ContentChild(); + struct AppInfo + { + nsCString version; + nsCString buildID; + }; + bool Init(MessageLoop* aIOLoop, base::ProcessHandle aParentHandle, IPC::Channel* aChannel); @@ -74,6 +80,10 @@ public: return sSingleton; } + const AppInfo& GetAppInfo() { + return mAppInfo; + } + /* if you remove this, please talk to cjones or dougt */ virtual bool RecvDummy(Shmem& foo) { return true; } @@ -154,6 +164,8 @@ public: virtual bool RecvGarbageCollect(); virtual bool RecvCycleCollect(); + virtual bool RecvAppInfo(const nsCString& version, const nsCString& buildID); + #ifdef ANDROID gfxIntSize GetScreenSize() { return mScreenSize; } #endif @@ -181,6 +193,8 @@ private: gfxIntSize mScreenSize; #endif + AppInfo mAppInfo; + static ContentChild* sSingleton; DISALLOW_EVIL_CONSTRUCTORS(ContentChild); diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index c12590b8d89e..6e3ad411a0ad 100644 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -71,6 +71,7 @@ #include "nsIScriptError.h" #include "nsConsoleMessage.h" #include "nsAppDirectoryServiceDefs.h" +#include "nsAppRunner.h" #include "IDBFactory.h" #if defined(MOZ_SYDNEYAUDIO) #include "AudioParent.h" @@ -427,6 +428,14 @@ ContentParent::ContentParent() static_cast(registrySvc.get()); chromeRegistry->SendRegisteredChrome(this); mMessageManager = nsFrameMessageManager::NewProcessMessageManager(this); + + if (gAppData) { + nsCString version(gAppData->version); + nsCString buildID(gAppData->buildID); + + //Sending all information to content process + SendAppInfo(version, buildID); + } } ContentParent::~ContentParent() diff --git a/dom/ipc/Makefile.in b/dom/ipc/Makefile.in index 4c2dc2f0d138..c672a27b8ce8 100644 --- a/dom/ipc/Makefile.in +++ b/dom/ipc/Makefile.in @@ -107,6 +107,7 @@ LOCAL_INCLUDES += \ -I$(srcdir)/../indexedDB \ -I$(topsrcdir)/extensions/cookie \ -I$(topsrcdir)/dom/base \ + -I$(topsrcdir)/toolkit/xre \ $(NULL) DEFINES += -DBIN_SUFFIX='"$(BIN_SUFFIX)"' diff --git a/dom/ipc/PContent.ipdl b/dom/ipc/PContent.ipdl index 015830eb8f45..c25da4c17168 100644 --- a/dom/ipc/PContent.ipdl +++ b/dom/ipc/PContent.ipdl @@ -143,6 +143,8 @@ child: */ ActivateA11y(); + AppInfo(nsCString version, nsCString buildID); + parent: PNecko(); diff --git a/toolkit/xre/nsAppRunner.cpp b/toolkit/xre/nsAppRunner.cpp index c21ed074a232..2aee3de949f1 100644 --- a/toolkit/xre/nsAppRunner.cpp +++ b/toolkit/xre/nsAppRunner.cpp @@ -60,6 +60,7 @@ #endif // MOZ_WIDGET_QT #include "mozilla/dom/ContentParent.h" +#include "mozilla/dom/ContentChild.h" #include "nsAppRunner.h" #include "nsUpdateDriver.h" @@ -253,6 +254,7 @@ static char **gQtOnlyArgv; #include "BinaryPath.h" using mozilla::dom::ContentParent; +using mozilla::dom::ContentChild; // Save literal putenv string to environment variable. static void @@ -607,7 +609,8 @@ NS_INTERFACE_MAP_BEGIN(nsXULAppInfo) #ifdef MOZ_CRASHREPORTER NS_INTERFACE_MAP_ENTRY(nsICrashReporter) #endif - NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIXULAppInfo, gAppData) + NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIXULAppInfo, gAppData || + XRE_GetProcessType() == GeckoProcessType_Content) NS_INTERFACE_MAP_END NS_IMETHODIMP_(nsrefcnt) @@ -625,6 +628,10 @@ nsXULAppInfo::Release() NS_IMETHODIMP nsXULAppInfo::GetVendor(nsACString& aResult) { + if (XRE_GetProcessType() == GeckoProcessType_Content) { + NS_WARNING("Attempt to get unavailable information in content process."); + return NS_ERROR_NOT_AVAILABLE; + } aResult.Assign(gAppData->vendor); return NS_OK; @@ -633,6 +640,10 @@ nsXULAppInfo::GetVendor(nsACString& aResult) NS_IMETHODIMP nsXULAppInfo::GetName(nsACString& aResult) { + if (XRE_GetProcessType() == GeckoProcessType_Content) { + NS_WARNING("Attempt to get unavailable information in content process."); + return NS_ERROR_NOT_AVAILABLE; + } aResult.Assign(gAppData->name); return NS_OK; @@ -641,6 +652,10 @@ nsXULAppInfo::GetName(nsACString& aResult) NS_IMETHODIMP nsXULAppInfo::GetID(nsACString& aResult) { + if (XRE_GetProcessType() == GeckoProcessType_Content) { + NS_WARNING("Attempt to get unavailable information in content process."); + return NS_ERROR_NOT_AVAILABLE; + } aResult.Assign(gAppData->ID); return NS_OK; @@ -649,6 +664,11 @@ nsXULAppInfo::GetID(nsACString& aResult) NS_IMETHODIMP nsXULAppInfo::GetVersion(nsACString& aResult) { + if (XRE_GetProcessType() == GeckoProcessType_Content) { + ContentChild* cc = ContentChild::GetSingleton(); + aResult = cc->GetAppInfo().version; + return NS_OK; + } aResult.Assign(gAppData->version); return NS_OK; @@ -665,6 +685,11 @@ nsXULAppInfo::GetPlatformVersion(nsACString& aResult) NS_IMETHODIMP nsXULAppInfo::GetAppBuildID(nsACString& aResult) { + if (XRE_GetProcessType() == GeckoProcessType_Content) { + ContentChild* cc = ContentChild::GetSingleton(); + aResult = cc->GetAppInfo().buildID; + return NS_OK; + } aResult.Assign(gAppData->buildID); return NS_OK;