mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-14 14:02:47 +00:00
Bug 938597 - Include pref name in the error message for operations that cannot happen in content processes. r=bsmedberg
This commit is contained in:
parent
0cc7ebea02
commit
99562b2b72
@ -48,6 +48,21 @@
|
||||
#include "nsIMemoryReporter.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
#define ENSURE_MAIN_PROCESS(message, pref) do { \
|
||||
if (MOZ_UNLIKELY(XRE_GetProcessType() != GeckoProcessType_Default)) { \
|
||||
nsPrintfCString msg("ENSURE_MAIN_PROCESS failed. %s %s", message, pref); \
|
||||
NS_WARNING(msg.get()); \
|
||||
return NS_ERROR_NOT_AVAILABLE; \
|
||||
} \
|
||||
} while (0);
|
||||
#else
|
||||
#define ENSURE_MAIN_PROCESS(message, pref) \
|
||||
if (MOZ_UNLIKELY(XRE_GetProcessType() != GeckoProcessType_Default)) { \
|
||||
return NS_ERROR_NOT_AVAILABLE; \
|
||||
}
|
||||
#endif
|
||||
|
||||
class PrefCallback;
|
||||
|
||||
namespace mozilla {
|
||||
@ -586,7 +601,7 @@ NS_IMETHODIMP
|
||||
Preferences::ResetPrefs()
|
||||
{
|
||||
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
||||
NS_ERROR("cannot set prefs from content process");
|
||||
NS_ERROR("cannot reset prefs from content process");
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
@ -603,7 +618,7 @@ NS_IMETHODIMP
|
||||
Preferences::ResetUserPrefs()
|
||||
{
|
||||
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
||||
NS_ERROR("cannot set prefs from content process");
|
||||
NS_ERROR("cannot reset user prefs from content process");
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
@ -615,7 +630,7 @@ NS_IMETHODIMP
|
||||
Preferences::SavePrefFile(nsIFile *aFile)
|
||||
{
|
||||
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
||||
NS_ERROR("cannot save prefs from content process");
|
||||
NS_ERROR("cannot save pref file from content process");
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
@ -1437,7 +1452,7 @@ Preferences::GetComplex(const char* aPref, const nsIID &aType, void** aResult)
|
||||
nsresult
|
||||
Preferences::SetCString(const char* aPref, const char* aValue)
|
||||
{
|
||||
NS_ENSURE_TRUE(XRE_GetProcessType() == GeckoProcessType_Default, NS_ERROR_NOT_AVAILABLE);
|
||||
ENSURE_MAIN_PROCESS("Cannot SetCString from content process:", aPref);
|
||||
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
|
||||
return PREF_SetCharPref(aPref, aValue, false);
|
||||
}
|
||||
@ -1446,7 +1461,7 @@ Preferences::SetCString(const char* aPref, const char* aValue)
|
||||
nsresult
|
||||
Preferences::SetCString(const char* aPref, const nsACString &aValue)
|
||||
{
|
||||
NS_ENSURE_TRUE(XRE_GetProcessType() == GeckoProcessType_Default, NS_ERROR_NOT_AVAILABLE);
|
||||
ENSURE_MAIN_PROCESS("Cannot SetCString from content process:", aPref);
|
||||
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
|
||||
return PREF_SetCharPref(aPref, PromiseFlatCString(aValue).get(), false);
|
||||
}
|
||||
@ -1455,7 +1470,7 @@ Preferences::SetCString(const char* aPref, const nsACString &aValue)
|
||||
nsresult
|
||||
Preferences::SetString(const char* aPref, const PRUnichar* aValue)
|
||||
{
|
||||
NS_ENSURE_TRUE(XRE_GetProcessType() == GeckoProcessType_Default, NS_ERROR_NOT_AVAILABLE);
|
||||
ENSURE_MAIN_PROCESS("Cannot SetString from content process:", aPref);
|
||||
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
|
||||
return PREF_SetCharPref(aPref, NS_ConvertUTF16toUTF8(aValue).get(), false);
|
||||
}
|
||||
@ -1464,7 +1479,7 @@ Preferences::SetString(const char* aPref, const PRUnichar* aValue)
|
||||
nsresult
|
||||
Preferences::SetString(const char* aPref, const nsAString &aValue)
|
||||
{
|
||||
NS_ENSURE_TRUE(XRE_GetProcessType() == GeckoProcessType_Default, NS_ERROR_NOT_AVAILABLE);
|
||||
ENSURE_MAIN_PROCESS("Cannot SetString from content process:", aPref);
|
||||
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
|
||||
return PREF_SetCharPref(aPref, NS_ConvertUTF16toUTF8(aValue).get(), false);
|
||||
}
|
||||
@ -1473,7 +1488,7 @@ Preferences::SetString(const char* aPref, const nsAString &aValue)
|
||||
nsresult
|
||||
Preferences::SetBool(const char* aPref, bool aValue)
|
||||
{
|
||||
NS_ENSURE_TRUE(XRE_GetProcessType() == GeckoProcessType_Default, NS_ERROR_NOT_AVAILABLE);
|
||||
ENSURE_MAIN_PROCESS("Cannot SetBool from content process:", aPref);
|
||||
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
|
||||
return PREF_SetBoolPref(aPref, aValue, false);
|
||||
}
|
||||
@ -1482,7 +1497,7 @@ Preferences::SetBool(const char* aPref, bool aValue)
|
||||
nsresult
|
||||
Preferences::SetInt(const char* aPref, int32_t aValue)
|
||||
{
|
||||
NS_ENSURE_TRUE(XRE_GetProcessType() == GeckoProcessType_Default, NS_ERROR_NOT_AVAILABLE);
|
||||
ENSURE_MAIN_PROCESS("Cannot SetInt from content process:", aPref);
|
||||
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
|
||||
return PREF_SetIntPref(aPref, aValue, false);
|
||||
}
|
||||
@ -1500,7 +1515,7 @@ Preferences::SetComplex(const char* aPref, const nsIID &aType,
|
||||
nsresult
|
||||
Preferences::ClearUser(const char* aPref)
|
||||
{
|
||||
NS_ENSURE_TRUE(XRE_GetProcessType() == GeckoProcessType_Default, NS_ERROR_NOT_AVAILABLE);
|
||||
ENSURE_MAIN_PROCESS("Cannot ClearUser from content process:", aPref);
|
||||
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
|
||||
return PREF_ClearUserPref(aPref);
|
||||
}
|
||||
@ -1882,3 +1897,5 @@ Preferences::GetDefaultType(const char* aPref)
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#undef ENSURE_MAIN_PROCESS
|
||||
|
@ -31,6 +31,21 @@
|
||||
|
||||
#include "nsIConsoleService.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
#define ENSURE_MAIN_PROCESS(message, pref) do { \
|
||||
if (GetContentChild()) { \
|
||||
nsPrintfCString msg("ENSURE_MAIN_PROCESS failed. %s %s", message, pref); \
|
||||
NS_ERROR(msg.get()); \
|
||||
return NS_ERROR_NOT_AVAILABLE; \
|
||||
} \
|
||||
} while (0);
|
||||
#else
|
||||
#define ENSURE_MAIN_PROCESS(message, pref) \
|
||||
if (GetContentChild()) { \
|
||||
return NS_ERROR_NOT_AVAILABLE; \
|
||||
}
|
||||
#endif
|
||||
|
||||
// 1 MB should be enough for everyone.
|
||||
static const uint32_t MAX_PREF_LENGTH = 1 * 1024 * 1024;
|
||||
// Actually, 4kb should be enough for everyone.
|
||||
@ -140,11 +155,7 @@ NS_IMETHODIMP nsPrefBranch::GetBoolPref(const char *aPrefName, bool *_retval)
|
||||
|
||||
NS_IMETHODIMP nsPrefBranch::SetBoolPref(const char *aPrefName, bool aValue)
|
||||
{
|
||||
if (GetContentChild()) {
|
||||
NS_ERROR("cannot set pref from content process");
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
ENSURE_MAIN_PROCESS("Cannot SetBoolPref from content process:", aPrefName);
|
||||
NS_ENSURE_ARG(aPrefName);
|
||||
const char *pref = getPrefName(aPrefName);
|
||||
return PREF_SetBoolPref(pref, aValue, mIsDefault);
|
||||
@ -182,11 +193,7 @@ NS_IMETHODIMP nsPrefBranch::SetCharPref(const char *aPrefName, const char *aValu
|
||||
nsresult nsPrefBranch::SetCharPrefInternal(const char *aPrefName, const char *aValue)
|
||||
|
||||
{
|
||||
if (GetContentChild()) {
|
||||
NS_ERROR("cannot set pref from content process");
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
ENSURE_MAIN_PROCESS("Cannot SetCharPref from content process:", aPrefName);
|
||||
NS_ENSURE_ARG(aPrefName);
|
||||
NS_ENSURE_ARG(aValue);
|
||||
const char *pref = getPrefName(aPrefName);
|
||||
@ -202,11 +209,7 @@ NS_IMETHODIMP nsPrefBranch::GetIntPref(const char *aPrefName, int32_t *_retval)
|
||||
|
||||
NS_IMETHODIMP nsPrefBranch::SetIntPref(const char *aPrefName, int32_t aValue)
|
||||
{
|
||||
if (GetContentChild()) {
|
||||
NS_ERROR("cannot set pref from content process");
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
ENSURE_MAIN_PROCESS("Cannot SetIntPref from content process:", aPrefName);
|
||||
NS_ENSURE_ARG(aPrefName);
|
||||
const char *pref = getPrefName(aPrefName);
|
||||
return PREF_SetIntPref(pref, aValue, mIsDefault);
|
||||
@ -391,11 +394,7 @@ nsresult nsPrefBranch::CheckSanityOfStringLength(const char* aPrefName, const ui
|
||||
|
||||
NS_IMETHODIMP nsPrefBranch::SetComplexValue(const char *aPrefName, const nsIID & aType, nsISupports *aValue)
|
||||
{
|
||||
if (GetContentChild()) {
|
||||
NS_ERROR("cannot set pref from content process");
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
ENSURE_MAIN_PROCESS("Cannot SetComplexValue from content process:", aPrefName);
|
||||
NS_ENSURE_ARG(aPrefName);
|
||||
|
||||
nsresult rv = NS_NOINTERFACE;
|
||||
@ -491,11 +490,7 @@ NS_IMETHODIMP nsPrefBranch::SetComplexValue(const char *aPrefName, const nsIID &
|
||||
|
||||
NS_IMETHODIMP nsPrefBranch::ClearUserPref(const char *aPrefName)
|
||||
{
|
||||
if (GetContentChild()) {
|
||||
NS_ERROR("cannot set pref from content process");
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
ENSURE_MAIN_PROCESS("Cannot ClearUserPref from content process:", aPrefName);
|
||||
NS_ENSURE_ARG(aPrefName);
|
||||
const char *pref = getPrefName(aPrefName);
|
||||
return PREF_ClearUserPref(pref);
|
||||
@ -512,11 +507,7 @@ NS_IMETHODIMP nsPrefBranch::PrefHasUserValue(const char *aPrefName, bool *_retva
|
||||
|
||||
NS_IMETHODIMP nsPrefBranch::LockPref(const char *aPrefName)
|
||||
{
|
||||
if (GetContentChild()) {
|
||||
NS_ERROR("cannot lock pref from content process");
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
ENSURE_MAIN_PROCESS("Cannot LockPref from content process:", aPrefName);
|
||||
NS_ENSURE_ARG(aPrefName);
|
||||
const char *pref = getPrefName(aPrefName);
|
||||
return PREF_LockPref(pref, true);
|
||||
@ -524,11 +515,7 @@ NS_IMETHODIMP nsPrefBranch::LockPref(const char *aPrefName)
|
||||
|
||||
NS_IMETHODIMP nsPrefBranch::PrefIsLocked(const char *aPrefName, bool *_retval)
|
||||
{
|
||||
if (GetContentChild()) {
|
||||
NS_ERROR("cannot check lock pref from content process");
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
ENSURE_MAIN_PROCESS("Cannot check PrefIsLocked from content process:", aPrefName);
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
NS_ENSURE_ARG(aPrefName);
|
||||
const char *pref = getPrefName(aPrefName);
|
||||
@ -538,11 +525,7 @@ NS_IMETHODIMP nsPrefBranch::PrefIsLocked(const char *aPrefName, bool *_retval)
|
||||
|
||||
NS_IMETHODIMP nsPrefBranch::UnlockPref(const char *aPrefName)
|
||||
{
|
||||
if (GetContentChild()) {
|
||||
NS_ERROR("cannot unlock pref from content process");
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
ENSURE_MAIN_PROCESS("Cannot UnlockPref from content process:", aPrefName);
|
||||
NS_ENSURE_ARG(aPrefName);
|
||||
const char *pref = getPrefName(aPrefName);
|
||||
return PREF_LockPref(pref, false);
|
||||
@ -556,11 +539,7 @@ NS_IMETHODIMP nsPrefBranch::ResetBranch(const char *aStartingAt)
|
||||
|
||||
NS_IMETHODIMP nsPrefBranch::DeleteBranch(const char *aStartingAt)
|
||||
{
|
||||
if (GetContentChild()) {
|
||||
NS_ERROR("cannot set pref from content process");
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
ENSURE_MAIN_PROCESS("Cannot DeleteBranch from content process:", aStartingAt);
|
||||
NS_ENSURE_ARG(aStartingAt);
|
||||
const char *pref = getPrefName(aStartingAt);
|
||||
return PREF_DeleteBranch(pref);
|
||||
@ -921,3 +900,5 @@ NS_IMETHODIMP nsRelativeFilePref::SetRelativeToKey(const nsACString& aRelativeTo
|
||||
mRelativeToKey.Assign(aRelativeToKey);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#undef ENSURE_MAIN_PROCESS
|
Loading…
x
Reference in New Issue
Block a user