Bug 1212148 - Outline DialogValueHolder::Get() and create the variant directly. r=bz

This commit is contained in:
Andrew McCreight 2015-10-07 13:11:09 -07:00
parent 5779c5c236
commit b8efcfd366
2 changed files with 23 additions and 20 deletions

View File

@ -42,6 +42,7 @@
#include "WindowNamedPropertiesHandler.h"
#include "nsFrameSelection.h"
#include "nsNetUtil.h"
#include "nsVariant.h"
// Helper Classes
#include "nsJSUtils.h"
@ -559,6 +560,27 @@ nsTimeout::HasRefCntOne()
return mRefCnt.get() == 1;
}
static already_AddRefed<nsIVariant>
CreateVoidVariant()
{
nsRefPtr<nsVariant> writable = new nsVariant();
writable->SetAsVoid();
return writable.forget();
}
nsresult
DialogValueHolder::Get(nsIPrincipal* aSubject, nsIVariant** aResult)
{
nsCOMPtr<nsIVariant> result;
if (aSubject->SubsumesConsideringDomain(mOrigin)) {
result = mValue;
} else {
result = CreateVoidVariant();
}
result.forget(aResult);
return NS_OK;
}
namespace mozilla {
namespace dom {
extern uint64_t

View File

@ -241,15 +241,6 @@ struct IdleObserverHolder
}
};
static inline already_AddRefed<nsIVariant>
CreateVoidVariant()
{
nsCOMPtr<nsIWritableVariant> writable =
do_CreateInstance(NS_VARIANT_CONTRACTID);
writable->SetAsVoid();
return writable.forget();
}
// Helper class to manage modal dialog arguments and all their quirks.
//
// Given our clunky embedding APIs, modal dialog arguments need to be passed
@ -271,17 +262,7 @@ public:
DialogValueHolder(nsIPrincipal* aSubject, nsIVariant* aValue)
: mOrigin(aSubject)
, mValue(aValue) {}
nsresult Get(nsIPrincipal* aSubject, nsIVariant** aResult)
{
nsCOMPtr<nsIVariant> result;
if (aSubject->SubsumesConsideringDomain(mOrigin)) {
result = mValue;
} else {
result = CreateVoidVariant();
}
result.forget(aResult);
return NS_OK;
}
nsresult Get(nsIPrincipal* aSubject, nsIVariant** aResult);
void Get(JSContext* aCx, JS::Handle<JSObject*> aScope, nsIPrincipal* aSubject,
JS::MutableHandle<JS::Value> aResult, mozilla::ErrorResult& aError)
{