Bug 1210517 - Create nsVariant directly rather than via do_CreateInstance(). r=froydnj

The goal here is to leave creation stuff mostly for JS, so we can
convert it entirely over to a non-threadsafe cycle-collected version
without breaking any existing C++ users.

I didn't do this for a remaining use in nsGlobalWindow.h to avoid
including nsVariant.h all over the place.
This commit is contained in:
Andrew McCreight 2015-10-07 08:17:42 -07:00
parent fdec90f014
commit 0ff7248107
20 changed files with 60 additions and 107 deletions

View File

@ -57,6 +57,7 @@
#include "TabParent.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/HTMLAreaElement.h"
#include "nsVariant.h"
using namespace mozilla::dom;
@ -726,11 +727,9 @@ DragDataProducer::AddString(DataTransfer* aDataTransfer,
const nsAString& aData,
nsIPrincipal* aPrincipal)
{
nsCOMPtr<nsIWritableVariant> variant = do_CreateInstance(NS_VARIANT_CONTRACTID);
if (variant) {
variant->SetAsAString(aData);
aDataTransfer->SetDataWithPrincipal(aFlavor, variant, 0, aPrincipal);
}
nsRefPtr<nsVariant> variant = new nsVariant();
variant->SetAsAString(aData);
aDataTransfer->SetDataWithPrincipal(aFlavor, variant, 0, aPrincipal);
}
nsresult
@ -784,12 +783,10 @@ DragDataProducer::AddStringsToDataTransfer(nsIContent* aDragNode,
// a new flavor so as not to confuse anyone who is really registered
// for image/gif or image/jpg.
if (mImage) {
nsCOMPtr<nsIWritableVariant> variant = do_CreateInstance(NS_VARIANT_CONTRACTID);
if (variant) {
variant->SetAsISupports(mImage);
aDataTransfer->SetDataWithPrincipal(NS_LITERAL_STRING(kNativeImageMime),
variant, 0, principal);
}
nsRefPtr<nsVariant> variant = new nsVariant();
variant->SetAsISupports(mImage);
aDataTransfer->SetDataWithPrincipal(NS_LITERAL_STRING(kNativeImageMime),
variant, 0, principal);
// assume the image comes from a file, and add a file promise. We
// register ourselves as a nsIFlavorDataProvider, and will use the
@ -798,12 +795,10 @@ DragDataProducer::AddStringsToDataTransfer(nsIContent* aDragNode,
nsCOMPtr<nsIFlavorDataProvider> dataProvider =
new nsContentAreaDragDropDataProvider();
if (dataProvider) {
nsCOMPtr<nsIWritableVariant> variant = do_CreateInstance(NS_VARIANT_CONTRACTID);
if (variant) {
variant->SetAsISupports(dataProvider);
aDataTransfer->SetDataWithPrincipal(NS_LITERAL_STRING(kFilePromiseMime),
variant, 0, principal);
}
nsRefPtr<nsVariant> variant = new nsVariant();
variant->SetAsISupports(dataProvider);
aDataTransfer->SetDataWithPrincipal(NS_LITERAL_STRING(kFilePromiseMime),
variant, 0, principal);
}
AddString(aDataTransfer, NS_LITERAL_STRING(kFilePromiseURLMime),

View File

@ -10,7 +10,6 @@
#include "DataTransfer.h"
#include "nsIDOMDocument.h"
#include "nsIVariant.h"
#include "nsISupportsPrimitives.h"
#include "nsIScriptSecurityManager.h"
#include "mozilla/dom/DOMStringList.h"
@ -24,6 +23,7 @@
#include "nsIScriptContext.h"
#include "nsIDocument.h"
#include "nsIScriptGlobalObject.h"
#include "nsVariant.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/DataTransferBinding.h"
#include "mozilla/dom/Directory.h"
@ -435,12 +435,7 @@ void
DataTransfer::SetData(const nsAString& aFormat, const nsAString& aData,
ErrorResult& aRv)
{
nsCOMPtr<nsIWritableVariant> variant = do_CreateInstance(NS_VARIANT_CONTRACTID);
if (!variant) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return;
}
nsRefPtr<nsVariant> variant = new nsVariant();
variant->SetAsAString(aData);
aRv = MozSetDataAt(aFormat, variant, 0);
@ -1350,9 +1345,7 @@ DataTransfer::FillInExternalData(TransferItem& aItem, uint32_t aIndex)
if (!data)
return;
nsCOMPtr<nsIWritableVariant> variant = do_CreateInstance(NS_VARIANT_CONTRACTID);
if (!variant)
return;
nsRefPtr<nsVariant> variant = new nsVariant();
nsCOMPtr<nsISupportsString> supportsstr = do_QueryInterface(data);
if (supportsstr) {

View File

@ -63,6 +63,7 @@
#include "nsReadableUtils.h"
#include "nsUnicharUtils.h"
#include "nsLayoutUtils.h"
#include "nsVariant.h"
#include "nsIDOMMutationEvent.h"
#include "mozilla/ContentEvents.h"
@ -807,9 +808,7 @@ UploadLastDir::StoreLastUsedDirectory(nsIDocument* aDoc, nsIFile* aDir)
aDir->GetPath(unicodePath);
if (unicodePath.IsEmpty()) // nothing to do
return NS_OK;
nsCOMPtr<nsIWritableVariant> prefValue = do_CreateInstance(NS_VARIANT_CONTRACTID);
if (!prefValue)
return NS_ERROR_OUT_OF_MEMORY;
nsRefPtr<nsVariant> prefValue = new nsVariant();
prefValue->SetAsAString(unicodePath);
// Use the document's current load context to ensure that the content pref

View File

@ -13,6 +13,7 @@
#include "mozilla/dom/Event.h"
#include "mozilla/ClearOnShutdown.h"
#include "nsComponentManagerUtils.h"
#include "nsVariant.h"
#include "nsVideoFrame.h"
#include "nsIFrame.h"
#include "nsTArrayHelpers.h"
@ -214,8 +215,7 @@ TextTrackManager::UpdateCueDisplay()
mTextTracks->UpdateAndGetShowingCues(activeCues);
if (activeCues.Length() > 0) {
nsCOMPtr<nsIWritableVariant> jsCues =
do_CreateInstance("@mozilla.org/variant;1");
nsRefPtr<nsVariant> jsCues = new nsVariant();
jsCues->SetAsArray(nsIDataType::VTYPE_INTERFACE,
&NS_GET_IID(nsIDOMEventTarget),

View File

@ -85,6 +85,7 @@
#include "nsMemoryInfoDumper.h"
#include "nsServiceManagerUtils.h"
#include "nsStyleSheetService.h"
#include "nsVariant.h"
#include "nsXULAppAPI.h"
#include "nsIScriptError.h"
#include "nsIConsoleService.h"
@ -2864,9 +2865,7 @@ ContentChild::RecvInvokeDragSession(nsTArray<IPCDataTransfer>&& aTransfers,
auto& items = aTransfers[i].items();
for (uint32_t j = 0; j < items.Length(); ++j) {
const IPCDataTransferItem& item = items[j];
nsCOMPtr<nsIWritableVariant> variant =
do_CreateInstance(NS_VARIANT_CONTRACTID);
NS_ENSURE_TRUE(variant, false);
nsRefPtr<nsVariant> variant = new nsVariant();
if (item.data().type() == IPCDataTransferData::TnsString) {
const nsString& data = item.data().get_nsString();
variant->SetAsAString(data);

View File

@ -63,6 +63,7 @@
#include "nsIXULWindow.h"
#include "nsIRemoteBrowser.h"
#include "nsViewManager.h"
#include "nsVariant.h"
#include "nsIWidget.h"
#include "nsIWindowMediator.h"
#include "nsIWindowWatcher.h"
@ -3541,7 +3542,7 @@ TabParent::RecvInvokeDragSession(nsTArray<IPCDataTransfer>&& aTransfers,
}
mDragAreaX = aDragAreaX;
mDragAreaY = aDragAreaY;
esm->BeginTrackingRemoteDragGesture(mFrameElement);
return true;
@ -3554,11 +3555,7 @@ TabParent::AddInitialDnDDataTo(DataTransfer* aDataTransfer)
nsTArray<DataTransferItem>& itemArray = mInitialDataTransferItems[i];
for (uint32_t j = 0; j < itemArray.Length(); ++j) {
DataTransferItem& item = itemArray[j];
nsCOMPtr<nsIWritableVariant> variant =
do_CreateInstance(NS_VARIANT_CONTRACTID);
if (!variant) {
break;
}
nsRefPtr<nsVariant> variant = new nsVariant();
// Special case kFilePromiseMime so that we get the right
// nsIFlavorDataProvider for it.
if (item.mFlavor.EqualsLiteral(kFilePromiseMime)) {

View File

@ -50,6 +50,7 @@
#include "Latency.h"
#include "nsProxyRelease.h"
#include "nsNullPrincipal.h"
#include "nsVariant.h"
// For PR_snprintf
#include "prprf.h"
@ -2203,7 +2204,7 @@ MediaManager::AnonymizeId(nsAString& aId, const nsACString& aOriginKey)
already_AddRefed<nsIWritableVariant>
MediaManager::ToJSArray(SourceSet& aDevices)
{
nsCOMPtr<nsIWritableVariant> var = do_CreateInstance("@mozilla.org/variant;1");
nsRefPtr<nsVariant> var = new nsVariant();
size_t len = aDevices.Length();
if (len) {
nsTArray<nsIMediaDevice*> tmp(len);

View File

@ -69,10 +69,9 @@ DeletedMessageInfo::GetDeletedMessageIds(nsIVariant** aDeletedMessageIds)
return NS_OK;
}
nsresult rv;
mDeletedMessageIds = do_CreateInstance(NS_VARIANT_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
mDeletedMessageIds = new nsVariant();
nsresult rv;
rv = mDeletedMessageIds->SetAsArray(nsIDataType::VTYPE_INT32,
nullptr,
length,
@ -103,10 +102,9 @@ DeletedMessageInfo::GetDeletedThreadIds(nsIVariant** aDeletedThreadIds)
return NS_OK;
}
nsresult rv;
mDeletedThreadIds = do_CreateInstance(NS_VARIANT_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
mDeletedThreadIds = new nsVariant();
nsresult rv;
rv = mDeletedThreadIds->SetAsArray(nsIDataType::VTYPE_UINT64,
nullptr,
length,

View File

@ -20,7 +20,7 @@
#include "mozIStorageValueArray.h"
#include "mozIStorageFunction.h"
#include "nsIObserverService.h"
#include "nsIVariant.h"
#include "nsVariant.h"
#include "mozilla/IOInterposer.h"
#include "mozilla/Services.h"
@ -403,10 +403,7 @@ nsReverseStringSQLFunction::OnFunctionCall(
nsAutoCString result;
ReverseString(stringToReverse, result);
nsCOMPtr<nsIWritableVariant> outVar(do_CreateInstance(
NS_VARIANT_CONTRACTID, &rv));
NS_ENSURE_SUCCESS(rv, rv);
nsRefPtr<nsVariant> outVar(new nsVariant());
rv = outVar->SetAsAUTF8String(result);
NS_ENSURE_SUCCESS(rv, rv);

View File

@ -10,9 +10,9 @@
#include "nsIInputStream.h"
#include "nsIScriptSecurityManager.h"
#include "nsIURLFormatter.h"
#include "nsIVariant.h"
#include "nsIXMLHttpRequest.h"
#include "nsNetUtil.h"
#include "nsVariant.h"
UploadStumbleRunnable::UploadStumbleRunnable(nsIInputStream* aUploadData)
: mUploadInputStream(aUploadData)
@ -34,8 +34,7 @@ nsresult
UploadStumbleRunnable::Upload()
{
nsresult rv;
nsCOMPtr<nsIWritableVariant> variant = do_CreateInstance("@mozilla.org/variant;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsRefPtr<nsVariant> variant = new nsVariant();
rv = variant->SetAsISupports(mUploadInputStream);
NS_ENSURE_SUCCESS(rv, rv);

View File

@ -9,7 +9,6 @@
#include "nsIDOMEvent.h"
#include "nsIDOMEventListener.h"
#include "nsIRunnable.h"
#include "nsIVariant.h"
#include "nsIXMLHttpRequest.h"
#include "nsIXPConnect.h"
@ -24,6 +23,7 @@
#include "nsFormData.h"
#include "nsJSUtils.h"
#include "nsThreadUtils.h"
#include "nsVariant.h"
#include "RuntimeService.h"
#include "WorkerPrivate.h"
@ -1527,9 +1527,7 @@ SendRunnable::MainThreadRun()
}
}
else {
nsCOMPtr<nsIWritableVariant> wvariant =
do_CreateInstance(NS_VARIANT_CONTRACTID);
NS_ENSURE_TRUE(wvariant, NS_ERROR_UNEXPECTED);
nsRefPtr<nsVariant> wvariant = new nsVariant();
if (NS_FAILED(wvariant->SetAsAString(mStringBody))) {
MOZ_ASSERT(false, "This should never fail!");

View File

@ -34,6 +34,7 @@
#include "nsIScriptSecurityManager.h"
#include "nsJSUtils.h"
#include "nsIXPConnect.h"
#include "nsVariant.h"
#include "mozilla/dom/DocumentFragment.h"
#include "mozilla/dom/XSLTProcessorBinding.h"
@ -845,9 +846,7 @@ txMozillaXSLTProcessor::SetParameter(const nsAString & aNamespaceURI,
rv = xpathResult->Clone(getter_AddRefs(clone));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIWritableVariant> variant =
do_CreateInstance("@mozilla.org/variant;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsRefPtr<nsVariant> variant = new nsVariant();
rv = variant->SetAsISupports(clone);
NS_ENSURE_SUCCESS(rv, rv);

View File

@ -9,7 +9,7 @@
#include "nsUnicharUtils.h"
#include "nsArrayUtils.h"
#include "nsIVariant.h"
#include "nsVariant.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsIURI.h"
@ -110,7 +110,7 @@ nsXULTemplateResultSetStorage::FillColumnValues(nsCOMArray<nsIVariant>& aArray)
int32_t count = mColumnNames.Count();
for (int32_t c = 0; c < count; c++) {
nsCOMPtr<nsIWritableVariant> value = do_CreateInstance("@mozilla.org/variant;1");
nsRefPtr<nsVariant> value = new nsVariant();
int32_t type;
mStatement->GetTypeOfIndex(c, &type);

View File

@ -35,7 +35,7 @@
#include "nsITextServicesDocument.h" // for nsITextServicesDocument
#include "nsITextServicesFilter.h" // for nsITextServicesFilter
#include "nsIURI.h" // for nsIURI
#include "nsIVariant.h" // for nsIWritableVariant, etc
#include "nsVariant.h" // for nsIWritableVariant, etc
#include "nsLiteralString.h" // for NS_LITERAL_STRING, etc
#include "nsMemory.h" // for nsMemory
#include "nsRange.h"
@ -201,8 +201,7 @@ StoreCurrentDictionary(nsIEditor* aEditor, const nsAString& aDictionary)
rv = docUri->GetSpec(docUriSpec);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIWritableVariant> prefValue = do_CreateInstance(NS_VARIANT_CONTRACTID);
NS_ENSURE_TRUE(prefValue, NS_ERROR_OUT_OF_MEMORY);
nsRefPtr<nsVariant> prefValue = new nsVariant();
prefValue->SetAsAString(aDictionary);
nsCOMPtr<nsIContentPrefService2> contentPrefService =

View File

@ -44,6 +44,7 @@
#include "nsContainerFrame.h"
#include "nsView.h"
#include "nsViewManager.h"
#include "nsVariant.h"
#include "nsWidgetsCID.h"
#include "nsBoxFrame.h"
#include "nsIURL.h"
@ -4635,10 +4636,7 @@ nsTreeBodyFrame::FireRowCountChangedEvent(int32_t aIndex, int32_t aCount)
// Set 'count' data - the number of changed rows.
propBag->SetPropertyAsInt32(NS_LITERAL_STRING("count"), aCount);
nsCOMPtr<nsIWritableVariant> detailVariant(
do_CreateInstance("@mozilla.org/variant;1"));
if (!detailVariant)
return;
nsRefPtr<nsVariant> detailVariant(new nsVariant());
detailVariant->SetAsISupports(propBag);
treeEvent->InitCustomEvent(NS_LITERAL_STRING("TreeRowCountChanged"),
@ -4707,10 +4705,7 @@ nsTreeBodyFrame::FireInvalidateEvent(int32_t aStartRowIdx, int32_t aEndRowIdx,
endColIdx);
}
nsCOMPtr<nsIWritableVariant> detailVariant(
do_CreateInstance("@mozilla.org/variant;1"));
if (!detailVariant)
return;
nsRefPtr<nsVariant> detailVariant(new nsVariant());
detailVariant->SetAsISupports(propBag);
treeEvent->InitCustomEvent(NS_LITERAL_STRING("TreeInvalidated"),

View File

@ -18,6 +18,7 @@
#include "nsPlacesIndexes.h"
#include "nsPlacesTriggers.h"
#include "nsPlacesMacros.h"
#include "nsVariant.h"
#include "SQLFunctions.h"
#include "Helpers.h"
@ -420,9 +421,7 @@ NS_IMETHODIMP DatabaseShutdown::GetState(nsIPropertyBag** aState)
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
// Put `mState` in field `progress`
nsCOMPtr<nsIWritableVariant> progress =
do_CreateInstance(NS_VARIANT_CONTRACTID, &rv);
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
nsRefPtr<nsVariant> progress = new nsVariant();
rv = progress->SetAsUint8(mState);
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
@ -440,9 +439,7 @@ NS_IMETHODIMP DatabaseShutdown::GetState(nsIPropertyBag** aState)
return NS_OK;
}
nsCOMPtr<nsIWritableVariant> barrier =
do_CreateInstance(NS_VARIANT_CONTRACTID, &rv);
if (NS_WARN_IF(NS_FAILED(rv))) return rv;
nsRefPtr<nsVariant> barrier = new nsVariant();
rv = barrier->SetAsInterface(NS_GET_IID(nsIPropertyBag), barrierState);
if (NS_WARN_IF(NS_FAILED(rv))) return rv;

View File

@ -16,6 +16,7 @@
#include "nsPrintfCString.h"
#include "nsNavHistory.h"
#include "mozilla/Likely.h"
#include "nsVariant.h"
using namespace mozilla::storage;
@ -703,9 +704,7 @@ namespace places {
nsAutoString src;
aArguments->GetString(0, src);
nsCOMPtr<nsIWritableVariant> result =
do_CreateInstance("@mozilla.org/variant;1");
NS_ENSURE_STATE(result);
nsRefPtr<nsVariant> result = new nsVariant();
if (src.Length()>1) {
src.Truncate(src.Length() - 1);
@ -761,9 +760,7 @@ namespace places {
nsAutoString src;
aArguments->GetString(0, src);
nsCOMPtr<nsIWritableVariant> result =
do_CreateInstance("@mozilla.org/variant;1");
NS_ENSURE_STATE(result);
nsRefPtr<nsVariant> result = new nsVariant();
if (StringBeginsWith(src, NS_LITERAL_STRING("http://")))
src.Cut(0, 7);
@ -835,9 +832,7 @@ namespace places {
navHistory->DispatchFrecencyChangedNotification(spec, newFrecency, guid,
hidden, lastVisitDate);
nsCOMPtr<nsIWritableVariant> result =
do_CreateInstance("@mozilla.org/variant;1");
NS_ENSURE_STATE(result);
nsRefPtr<nsVariant> result = new nsVariant();
rv = result->SetAsInt32(newFrecency);
NS_ENSURE_SUCCESS(rv, rv);
result.forget(_result);

View File

@ -18,6 +18,7 @@
#include "nsNetUtil.h"
#include "nsTArray.h"
#include "prprf.h"
#include "nsVariant.h"
using namespace mozilla;
@ -1130,13 +1131,11 @@ NS_IMETHODIMP nsNavHistoryQuery::GetTags(nsIVariant **aTags)
{
NS_ENSURE_ARG_POINTER(aTags);
nsresult rv;
nsCOMPtr<nsIWritableVariant> out = do_CreateInstance(NS_VARIANT_CONTRACTID,
&rv);
NS_ENSURE_SUCCESS(rv, rv);
nsRefPtr<nsVariant> out = new nsVariant();
uint32_t arrayLen = mTags.Length();
nsresult rv;
if (arrayLen == 0)
rv = out->SetAsEmptyArray();
else {

View File

@ -11,7 +11,7 @@
#include "nsAppRunner.h"
#include "nsIWritablePropertyBag.h"
#include "nsIFile.h"
#include "nsIVariant.h"
#include "nsVariant.h"
#include "nsCOMPtr.h"
#include "nsString.h"
#include "prproces.h"
@ -691,12 +691,7 @@ SetOSApplyToDir(nsIUpdate* update, const nsACString& osApplyToDir)
return;
}
nsCOMPtr<nsIWritableVariant> variant =
do_CreateInstance("@mozilla.org/variant;1", &rv);
if (NS_FAILED(rv)) {
return;
}
nsRefPtr<nsVariant> variant = new nsVariant();
rv = variant->SetAsACString(osApplyToDir);
if (NS_FAILED(rv)) {
return;

View File

@ -7,7 +7,6 @@
#include "nsArrayEnumerator.h"
#include "nsCOMArray.h"
#include "nsIFile.h"
#include "nsIVariant.h"
#include "nsMIMEInfoWin.h"
#include "nsNetUtil.h"
#include <windows.h>
@ -22,6 +21,7 @@
#include "nsOSHelperAppService.h"
#include "nsUnicharUtils.h"
#include "nsITextToSubURI.h"
#include "nsVariant.h"
#define RUNDLL32_EXE L"\\rundll32.exe"
@ -172,15 +172,13 @@ nsMIMEInfoWin::GetEnumerator(nsISimpleEnumerator* *_retval)
static nsresult GetIconURLVariant(nsIFile* aApplication, nsIVariant* *_retval)
{
nsresult rv = CallCreateInstance("@mozilla.org/variant;1", _retval);
if (NS_FAILED(rv))
return rv;
nsAutoCString fileURLSpec;
NS_GetURLSpecFromFile(aApplication, fileURLSpec);
nsAutoCString iconURLSpec; iconURLSpec.AssignLiteral("moz-icon://");
iconURLSpec += fileURLSpec;
nsCOMPtr<nsIWritableVariant> writable(do_QueryInterface(*_retval));
nsRefPtr<nsVariant> writable(new nsVariant());
writable->SetAsAUTF8String(iconURLSpec);
writable.forget(_retval);
return NS_OK;
}