Bug 564535 - permission manager needs to be remoted [r=dwitte]

This commit is contained in:
Alon Zakai 2010-07-15 10:04:25 -04:00
Родитель 827c369faf
Коммит 3a1ca13d73
5 изменённых файлов: 125 добавлений и 1 удалений

Просмотреть файл

@ -267,6 +267,23 @@ ContentProcessParent::RecvGetChildList(const nsCString& domain,
return true;
}
bool
ContentProcessParent::RecvTestPermission(const IPC::URI& aUri,
const nsCString& aType,
const PRBool& aExact,
PRUint32* retValue)
{
EnsurePermissionService();
nsCOMPtr<nsIURI> uri = aUri;
if (aExact) {
mPermissionService->TestExactPermission(uri, aType.get(), retValue);
} else {
mPermissionService->TestPermission(uri, aType.get(), retValue);
}
return true;
}
void
ContentProcessParent::EnsurePrefService()
{
@ -278,6 +295,18 @@ ContentProcessParent::EnsurePrefService()
}
}
void
ContentProcessParent::EnsurePermissionService()
{
nsresult rv;
if (!mPermissionService) {
mPermissionService = do_GetService(
NS_PERMISSIONMANAGER_CONTRACTID, &rv);
NS_ASSERTION(NS_SUCCEEDED(rv),
"We lost permissionService in the Chrome process !");
}
}
NS_IMPL_THREADSAFE_ISUPPORTS2(ContentProcessParent,
nsIObserver,
nsIThreadObserver)

Просмотреть файл

@ -48,6 +48,7 @@
#include "nsIThreadInternal.h"
#include "mozilla/Monitor.h"
#include "nsIPrefService.h"
#include "nsIPermissionManager.h"
namespace mozilla {
@ -136,7 +137,13 @@ private:
virtual bool RecvGetChildList(const nsCString& domain,
nsTArray<nsCString>* list, nsresult* rv);
virtual bool RecvTestPermission(const IPC::URI& aUri,
const nsCString& aType,
const PRBool& aExact,
PRUint32* retValue);
void EnsurePrefService();
void EnsurePermissionService();
mozilla::Monitor mMonitor;
@ -148,6 +155,7 @@ private:
bool mIsAlive;
nsCOMPtr<nsIPrefBranch> mPrefService;
nsCOMPtr<nsIPermissionManager> mPermissionService;
};
} // namespace dom

Просмотреть файл

@ -42,10 +42,12 @@ include protocol PNecko;
include "mozilla/TabTypes.h";
include "mozilla/chrome/RegistryMessageUtils.h";
include "mozilla/net/NeckoMessageUtils.h";
using ChromePackage;
using ResourceMapping;
using OverrideMapping;
using IPC::URI;
namespace mozilla {
namespace dom {
@ -71,7 +73,9 @@ child:
parent:
PNecko();
// prefs-related messages ...
// Services remoting
// PrefService messages
sync GetPrefType(nsCString prefName) returns (PRInt32 retValue, nsresult rv);
sync GetBoolPref(nsCString prefName) returns (PRBool retValue, nsresult rv);
sync GetIntPref(nsCString prefName) returns (PRInt32 retValue, nsresult rv);
@ -80,6 +84,9 @@ parent:
sync PrefHasUserValue(nsCString prefName) returns (PRBool retValue, nsresult rv);
sync PrefIsLocked(nsCString prefName) returns (PRBool retValue, nsresult rv);
sync GetChildList(nsCString domain) returns (nsCString[] list, nsresult rv);
// PermissionsManager messages
sync TestPermission(URI uri, nsCString type, PRBool exact) returns (PRUint32 retValue);
};
}

Просмотреть файл

@ -77,4 +77,6 @@ ifdef ENABLE_TESTS
TOOL_DIRS += test
endif
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/ipc/chromium/chromium-config.mk
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -37,6 +37,9 @@
*
* ***** END LICENSE BLOCK ***** */
#ifdef MOZ_IPC
#include "mozilla/dom/ContentProcessChild.h"
#endif
#include "nsPermissionManager.h"
#include "nsPermission.h"
#include "nsCRT.h"
@ -54,6 +57,41 @@
#include "mozIStorageConnection.h"
#include "mozStorageHelper.h"
#include "mozStorageCID.h"
#include "nsXULAppAPI.h"
#ifdef MOZ_IPC
static PRBool
IsChildProcess()
{
return XRE_GetProcessType() == GeckoProcessType_Content;
}
/**
* @returns The child process object, or if we are not in the child
* process, nsnull.
*/
static mozilla::dom::ContentProcessChild*
ChildProcess()
{
if (IsChildProcess()) {
mozilla::dom::ContentProcessChild* cpc =
mozilla::dom::ContentProcessChild::GetSingleton();
if (!cpc)
NS_RUNTIMEABORT("Content Process is NULL!");
return cpc;
}
return nsnull;
}
#endif
#define ENSURE_NOT_CHILD_PROCESS \
PR_BEGIN_MACRO \
if (IsChildProcess()) { \
NS_ERROR("cannot set permission from content process"); \
return NS_ERROR_NOT_AVAILABLE; \
} \
PR_END_MACRO
////////////////////////////////////////////////////////////////////////////////
@ -122,6 +160,12 @@ nsPermissionManager::Init()
return NS_ERROR_OUT_OF_MEMORY;
}
#ifdef MOZ_IPC
// Child will route messages to parent, so no need for further initialization
if (IsChildProcess())
return NS_OK;
#endif
// ignore failure here, since it's non-fatal (we can run fine without
// persistent storage - e.g. if there's no profile).
// XXX should we tell the user about this?
@ -316,6 +360,10 @@ nsPermissionManager::Add(nsIURI *aURI,
PRUint32 aExpireType,
PRInt64 aExpireTime)
{
#ifdef MOZ_IPC
ENSURE_NOT_CHILD_PROCESS;
#endif
NS_ENSURE_ARG_POINTER(aURI);
NS_ENSURE_ARG_POINTER(aType);
NS_ENSURE_TRUE(aExpireType == nsIPermissionManager::EXPIRE_NEVER ||
@ -487,6 +535,10 @@ NS_IMETHODIMP
nsPermissionManager::Remove(const nsACString &aHost,
const char *aType)
{
#ifdef MOZ_IPC
ENSURE_NOT_CHILD_PROCESS;
#endif
NS_ENSURE_ARG_POINTER(aType);
// AddInternal() handles removal, just let it do the work
@ -503,6 +555,10 @@ nsPermissionManager::Remove(const nsACString &aHost,
NS_IMETHODIMP
nsPermissionManager::RemoveAll()
{
#ifdef MOZ_IPC
ENSURE_NOT_CHILD_PROCESS;
#endif
nsresult rv = RemoveAllInternal();
NotifyObservers(nsnull, NS_LITERAL_STRING("cleared").get());
return rv;
@ -534,6 +590,13 @@ nsPermissionManager::TestExactPermission(nsIURI *aURI,
const char *aType,
PRUint32 *aPermission)
{
#ifdef MOZ_IPC
mozilla::dom::ContentProcessChild* cpc = ChildProcess();
if (cpc) {
return cpc->SendTestPermission(IPC::URI(aURI), nsDependentCString(aType), PR_TRUE,
aPermission) ? NS_OK : NS_ERROR_FAILURE;
}
#endif
return CommonTestPermission(aURI, aType, aPermission, PR_TRUE);
}
@ -542,6 +605,13 @@ nsPermissionManager::TestPermission(nsIURI *aURI,
const char *aType,
PRUint32 *aPermission)
{
#ifdef MOZ_IPC
mozilla::dom::ContentProcessChild* cpc = ChildProcess();
if (cpc) {
return cpc->SendTestPermission(IPC::URI(aURI), nsDependentCString(aType), PR_FALSE,
aPermission) ? NS_OK : NS_ERROR_FAILURE;
}
#endif
return CommonTestPermission(aURI, aType, aPermission, PR_FALSE);
}
@ -645,6 +715,10 @@ AddPermissionsToList(nsHostEntry *entry, void *arg)
NS_IMETHODIMP nsPermissionManager::GetEnumerator(nsISimpleEnumerator **aEnum)
{
#ifdef MOZ_IPC
ENSURE_NOT_CHILD_PROCESS;
#endif
// roll an nsCOMArray of all our permissions, then hand out an enumerator
nsCOMArray<nsIPermission> array;
nsGetEnumeratorData data(&array, &mTypeArray);
@ -656,6 +730,10 @@ NS_IMETHODIMP nsPermissionManager::GetEnumerator(nsISimpleEnumerator **aEnum)
NS_IMETHODIMP nsPermissionManager::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *someData)
{
#ifdef MOZ_IPC
ENSURE_NOT_CHILD_PROCESS;
#endif
if (!nsCRT::strcmp(aTopic, "profile-before-change")) {
// The profile is about to change,
// or is going away because the application is shutting down.