Bug 784805 - Set the process name (comm) to the app name. r=cjones

This commit is contained in:
Dave Hylands 2012-09-10 21:30:33 -07:00
parent c2faa7ed89
commit faf42254b1
7 changed files with 103 additions and 0 deletions

View File

@ -95,6 +95,7 @@
#include "nsDOMFile.h"
#include "nsIRemoteBlob.h"
#include "ProcessUtils.h"
#include "StructuredCloneUtils.h"
#include "URIUtils.h"
#include "nsIScriptSecurityManager.h"
@ -296,6 +297,11 @@ ContentChild::Init(MessageLoop* aIOLoop,
GetCurrentProcId(),
startBackground ? hal::PROCESS_PRIORITY_BACKGROUND:
hal::PROCESS_PRIORITY_FOREGROUND);
if (mIsForApp && !mIsForBrowser) {
SetThisProcessName("(App)");
} else {
SetThisProcessName("Browser");
}
return true;
}

View File

@ -23,11 +23,13 @@
#include "mozilla/layout/RenderFrameChild.h"
#include "mozilla/StaticPtr.h"
#include "mozilla/unused.h"
#include "mozIApplication.h"
#include "nsComponentManagerUtils.h"
#include "nsComponentManagerUtils.h"
#include "nsContentUtils.h"
#include "nsEmbedCID.h"
#include "nsEventListenerManager.h"
#include "nsIAppsService.h"
#include "nsIBaseWindow.h"
#include "nsIComponentManager.h"
#include "nsIDOMClassInfo.h"
@ -677,6 +679,39 @@ TabChild::~TabChild()
}
}
void
TabChild::SetProcessNameToAppName()
{
if (mIsBrowserElement || (mAppId == nsIScriptSecurityManager::NO_APP_ID)) {
return;
}
nsCOMPtr<nsIAppsService> appsService =
do_GetService(APPS_SERVICE_CONTRACTID);
if (!appsService) {
NS_WARNING("No AppsService");
return;
}
nsresult rv;
nsCOMPtr<mozIDOMApplication> domApp;
rv = appsService->GetAppByLocalId(mAppId, getter_AddRefs(domApp));
if (NS_FAILED(rv) || !domApp) {
NS_WARNING("GetAppByLocalId failed");
return;
}
nsCOMPtr<mozIApplication> app = do_QueryInterface(domApp);
if (!app) {
NS_WARNING("app isn't a mozIApplication");
return;
}
nsAutoString appName;
rv = app->GetName(appName);
if (NS_FAILED(rv)) {
NS_WARNING("Failed to retrieve app name");
return;
}
SetThisProcessName(NS_LossyConvertUTF16toASCII(appName).get());
}
bool
TabChild::IsRootContentDocument()
{
@ -698,6 +733,7 @@ bool
TabChild::RecvLoadURL(const nsCString& uri)
{
printf("loading %s, %d\n", uri.get(), NS_IsMainThread());
SetProcessNameToAppName();
nsresult rv = mWebNav->LoadURI(NS_ConvertUTF8toUTF16(uri).get(),
nsIWebNavigation::LOAD_FLAGS_NONE,

View File

@ -48,6 +48,7 @@
#include "nsITabChild.h"
#include "mozilla/Attributes.h"
#include "FrameMetrics.h"
#include "ProcessUtils.h"
struct gfxMatrix;
@ -309,6 +310,7 @@ private:
bool InitTabChildGlobal(FrameScriptLoading aScriptLoading = DEFAULT_LOAD_SCRIPTS);
bool InitRenderingState();
void DestroyWindow();
void SetProcessNameToAppName();
// Call RecvShow(nsIntSize(0, 0)) and block future calls to RecvShow().
void DoFakeShow();

View File

@ -105,6 +105,12 @@ ifeq ($(OS_TARGET),Android)
CPPSRCS += SharedMemoryBasic_android.cpp
endif #}
ifeq ($(OS_ARCH),Linux)
CPPSRCS += ProcessUtils_linux.cpp
else
CPPSRCS += ProcessUtils_none.cpp
endif
include $(topsrcdir)/ipc/app/defs.mk
DEFINES += -DMOZ_CHILD_PROCESS_NAME=\"$(MOZ_CHILD_PROCESS_NAME)\"
DEFINES += -DMOZ_CHILD_PROCESS_BUNDLE=\"$(MOZ_CHILD_PROCESS_BUNDLE)\"

17
ipc/glue/ProcessUtils.h Normal file
View File

@ -0,0 +1,17 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_ipc_ProcessUtils_h
#define mozilla_ipc_ProcessUtils_h
namespace mozilla {
namespace ipc {
void SetThisProcessName(const char *aName);
} // namespace ipc
} // namespace mozilla
#endif // ifndef mozilla_ipc_ProcessUtils_h

View File

@ -0,0 +1,20 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "ProcessUtils.h"
#include "nsString.h"
#include <sys/prctl.h>
namespace mozilla {
namespace ipc {
void SetThisProcessName(const char *aName)
{
prctl(PR_SET_NAME, (unsigned long)aName, 0uL, 0uL, 0uL);
}
} // namespace ipc
} // namespace mozilla

View File

@ -0,0 +1,16 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "ProcessUtils.h"
namespace mozilla {
namespace ipc {
void SetThisProcessName(const char *aString)
{
(void)aString;
}
} // namespace ipc
} // namespace mozilla