NS_IMETHODIMP nsHTTPIndex::ArcLabelsOut(nsIRDFResource *aSource, nsISimpleEnumerator **_retval) { nsresult rv = NS_ERROR_UNEXPECTED; *_retval = nsnull; nsCOMPtr<nsISupportsArray> array; rv = NS_NewISupportsArray(getter_AddRefs(array)); if (NS_FAILED(rv)) return rv; if (isWellknownContainerURI(aSource)) { array->AppendElement(kNC_Child); } if (mInner) { nsCOMPtr<nsISimpleEnumerator> anonArcs; rv = mInner->ArcLabelsOut(aSource, getter_AddRefs(anonArcs)); PRBool hasResults = PR_TRUE; while (NS_SUCCEEDED(rv) && NS_SUCCEEDED(anonArcs->HasMoreElements(&hasResults)) && hasResults == PR_TRUE) { nsCOMPtr<nsISupports> anonArc; if (NS_FAILED(anonArcs->GetNext(getter_AddRefs(anonArc)))) break; array->AppendElement(anonArc); } } return NS_NewArrayEnumerator(_retval, array); }
NS_IMETHODIMP nsHTTPIndex::GetTargets(nsIRDFResource *aSource, nsIRDFResource *aProperty, PRBool aTruthValue, nsISimpleEnumerator **_retval) { nsresult rv = NS_ERROR_UNEXPECTED; if (mInner) { rv = mInner->GetTargets(aSource, aProperty, aTruthValue, _retval); } else { rv = NS_NewEmptyEnumerator(_retval); } if ((aProperty == kNC_Child) && isWellknownContainerURI(aSource)) { PRBool doNetworkRequest = PR_TRUE; if (NS_SUCCEEDED(rv) && (_retval)) { // check and see if we already have data for the search in question; // if we do, don't bother doing the search again PRBool hasResults; if (NS_SUCCEEDED((*_retval)->HasMoreElements(&hasResults)) && hasResults) doNetworkRequest = PR_FALSE; } // Note: if we need to do a network request, do it out-of-band // (because the XUL template builder isn't re-entrant) // by using a global connection list and an immediately-firing timer if (doNetworkRequest && mConnectionList) { PRInt32 connectionIndex = mConnectionList->IndexOf(aSource); if (connectionIndex < 0) { // add aSource into list of connections to make mConnectionList->AppendElement(aSource); // if we don't have a timer about to fire, create one // which should fire as soon as possible (out-of-band) if (!mTimer) { mTimer = do_CreateInstance("@mozilla.org/timer;1", &rv); NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create a timer"); if (NS_SUCCEEDED(rv)) { mTimer->InitWithFuncCallback(nsHTTPIndex::FireTimer, this, 1, nsITimer::TYPE_ONE_SHOT); // Note: don't addref "this" as we'll cancel the // timer in the httpIndex destructor } } } } } return(rv); }
NS_IMETHODIMP nsHTTPIndex::HasArcOut(nsIRDFResource *aSource, nsIRDFResource *aArc, PRBool *result) { if (aArc == kNC_Child && isWellknownContainerURI(aSource)) { *result = PR_TRUE; return NS_OK; } if (mInner) { return mInner->HasArcOut(aSource, aArc, result); } *result = PR_FALSE; return NS_OK; }
NS_IMETHODIMP nsHTTPIndex::GetTarget(nsIRDFResource *aSource, nsIRDFResource *aProperty, PRBool aTruthValue, nsIRDFNode **_retval) { nsresult rv = NS_ERROR_UNEXPECTED; *_retval = nsnull; if ((aTruthValue) && (aProperty == kNC_Child) && isWellknownContainerURI(aSource)) { // fake out the generic builder (i.e. return anything in this case) // so that search containers never appear to be empty NS_IF_ADDREF(aSource); *_retval = aSource; return(NS_OK); } if (mInner) { rv = mInner->GetTarget(aSource, aProperty, aTruthValue, _retval); } return(rv); }