Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "nsXULTemplateResultSetRDF.h" |
michael@0 | 7 | #include "nsXULTemplateQueryProcessorRDF.h" |
michael@0 | 8 | |
michael@0 | 9 | NS_IMPL_ISUPPORTS(nsXULTemplateResultSetRDF, nsISimpleEnumerator) |
michael@0 | 10 | |
michael@0 | 11 | NS_IMETHODIMP |
michael@0 | 12 | nsXULTemplateResultSetRDF::HasMoreElements(bool *aResult) |
michael@0 | 13 | { |
michael@0 | 14 | *aResult = true; |
michael@0 | 15 | |
michael@0 | 16 | nsCOMPtr<nsIRDFNode> node; |
michael@0 | 17 | |
michael@0 | 18 | if (! mInstantiations || ! mQuery) { |
michael@0 | 19 | *aResult = false; |
michael@0 | 20 | return NS_OK; |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | if (mCheckedNext) { |
michael@0 | 24 | if (!mCurrent || mCurrent == &(mInstantiations->mHead)) |
michael@0 | 25 | *aResult = false; |
michael@0 | 26 | return NS_OK; |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | mCheckedNext = true; |
michael@0 | 30 | |
michael@0 | 31 | do { |
michael@0 | 32 | if (mCurrent) { |
michael@0 | 33 | mCurrent = mCurrent->mNext; |
michael@0 | 34 | if (mCurrent == &(mInstantiations->mHead)) { |
michael@0 | 35 | *aResult = false; |
michael@0 | 36 | return NS_OK; |
michael@0 | 37 | } |
michael@0 | 38 | } |
michael@0 | 39 | else { |
michael@0 | 40 | *aResult = ! mInstantiations->Empty(); |
michael@0 | 41 | if (*aResult) |
michael@0 | 42 | mCurrent = mInstantiations->mHead.mNext; |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | // get the value of the member variable. If it is not set, skip |
michael@0 | 46 | // the result and move on to the next result |
michael@0 | 47 | if (mCurrent) { |
michael@0 | 48 | mCurrent->mInstantiation.mAssignments. |
michael@0 | 49 | GetAssignmentFor(mQuery->mMemberVariable, getter_AddRefs(node)); |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | // only resources may be used as results |
michael@0 | 53 | mResource = do_QueryInterface(node); |
michael@0 | 54 | } while (! mResource); |
michael@0 | 55 | |
michael@0 | 56 | return NS_OK; |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | NS_IMETHODIMP |
michael@0 | 60 | nsXULTemplateResultSetRDF::GetNext(nsISupports **aResult) |
michael@0 | 61 | { |
michael@0 | 62 | if (!aResult) |
michael@0 | 63 | return NS_ERROR_NULL_POINTER; |
michael@0 | 64 | |
michael@0 | 65 | if (!mCurrent || !mCheckedNext) |
michael@0 | 66 | return NS_ERROR_FAILURE; |
michael@0 | 67 | |
michael@0 | 68 | nsRefPtr<nsXULTemplateResultRDF> nextresult = |
michael@0 | 69 | new nsXULTemplateResultRDF(mQuery, mCurrent->mInstantiation, mResource); |
michael@0 | 70 | if (!nextresult) |
michael@0 | 71 | return NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 72 | |
michael@0 | 73 | // add the supporting memory elements to the processor's map. These are |
michael@0 | 74 | // used to remove the results when an assertion is removed from the graph |
michael@0 | 75 | mProcessor->AddMemoryElements(mCurrent->mInstantiation, nextresult); |
michael@0 | 76 | |
michael@0 | 77 | mCheckedNext = false; |
michael@0 | 78 | |
michael@0 | 79 | *aResult = nextresult; |
michael@0 | 80 | NS_ADDREF(*aResult); |
michael@0 | 81 | |
michael@0 | 82 | return NS_OK; |
michael@0 | 83 | } |