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 | #ifndef nsRDFQuery_h__ |
michael@0 | 7 | #define nsRDFQuery_h__ |
michael@0 | 8 | |
michael@0 | 9 | #include "nsAutoPtr.h" |
michael@0 | 10 | #include "nsISimpleEnumerator.h" |
michael@0 | 11 | #include "nsCycleCollectionParticipant.h" |
michael@0 | 12 | #include "mozilla/Attributes.h" |
michael@0 | 13 | |
michael@0 | 14 | #define NS_ITEMPLATERDFQUERY_IID \ |
michael@0 | 15 | {0x8929ff60, 0x1c9c, 0x4d87, \ |
michael@0 | 16 | { 0xac, 0x02, 0x09, 0x14, 0x15, 0x3b, 0x48, 0xc4 }} |
michael@0 | 17 | |
michael@0 | 18 | /** |
michael@0 | 19 | * A compiled query in the RDF query processor. This interface should not be |
michael@0 | 20 | * used directly outside of the RDF query processor. |
michael@0 | 21 | */ |
michael@0 | 22 | class nsITemplateRDFQuery : public nsISupports |
michael@0 | 23 | { |
michael@0 | 24 | public: |
michael@0 | 25 | NS_DECLARE_STATIC_IID_ACCESSOR(NS_ITEMPLATERDFQUERY_IID) |
michael@0 | 26 | |
michael@0 | 27 | // return the processor the query was created from |
michael@0 | 28 | virtual nsXULTemplateQueryProcessorRDF* Processor() = 0; // not addrefed |
michael@0 | 29 | |
michael@0 | 30 | // return the member variable for the query |
michael@0 | 31 | virtual nsIAtom* GetMemberVariable() = 0; // not addrefed |
michael@0 | 32 | |
michael@0 | 33 | // return the <query> node the query was compiled from |
michael@0 | 34 | virtual void GetQueryNode(nsIDOMNode** aQueryNode) = 0; |
michael@0 | 35 | |
michael@0 | 36 | // remove any results that are cached by the query |
michael@0 | 37 | virtual void ClearCachedResults() = 0; |
michael@0 | 38 | }; |
michael@0 | 39 | |
michael@0 | 40 | class nsRDFQuery MOZ_FINAL : public nsITemplateRDFQuery |
michael@0 | 41 | { |
michael@0 | 42 | public: |
michael@0 | 43 | |
michael@0 | 44 | nsRDFQuery(nsXULTemplateQueryProcessorRDF* aProcessor) |
michael@0 | 45 | : mProcessor(aProcessor), |
michael@0 | 46 | mSimple(false), |
michael@0 | 47 | mRoot(nullptr), |
michael@0 | 48 | mCachedResults(nullptr) |
michael@0 | 49 | { } |
michael@0 | 50 | |
michael@0 | 51 | ~nsRDFQuery() { Finish(); } |
michael@0 | 52 | |
michael@0 | 53 | NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
michael@0 | 54 | NS_DECL_CYCLE_COLLECTION_CLASS(nsRDFQuery) |
michael@0 | 55 | |
michael@0 | 56 | /** |
michael@0 | 57 | * Retrieve the root node in the rule network |
michael@0 | 58 | * @return the root node in the rule network |
michael@0 | 59 | */ |
michael@0 | 60 | TestNode* GetRoot() { return mRoot; } |
michael@0 | 61 | |
michael@0 | 62 | void SetRoot(TestNode* aRoot) { mRoot = aRoot; } |
michael@0 | 63 | |
michael@0 | 64 | void GetQueryNode(nsIDOMNode** aQueryNode) MOZ_OVERRIDE |
michael@0 | 65 | { |
michael@0 | 66 | *aQueryNode = mQueryNode; |
michael@0 | 67 | NS_IF_ADDREF(*aQueryNode); |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | void SetQueryNode(nsIDOMNode* aQueryNode) |
michael@0 | 71 | { |
michael@0 | 72 | mQueryNode = aQueryNode; |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | // an optimization is used when several queries all use the simple query |
michael@0 | 76 | // syntax. Since simple queries can only generate one possible set of |
michael@0 | 77 | // results, they only need to be calculated once and reused for every |
michael@0 | 78 | // simple query. The results may be cached in the query for this purpose. |
michael@0 | 79 | // If successful, this method takes ownership of aInstantiations. |
michael@0 | 80 | nsresult SetCachedResults(nsXULTemplateQueryProcessorRDF* aProcessor, |
michael@0 | 81 | const InstantiationSet& aInstantiations); |
michael@0 | 82 | |
michael@0 | 83 | // grab the cached results, if any, causing the caller to take ownership |
michael@0 | 84 | // of them. This also has the effect of setting the cached results in this |
michael@0 | 85 | // nsRDFQuery to null. |
michael@0 | 86 | void UseCachedResults(nsISimpleEnumerator** aResults); |
michael@0 | 87 | |
michael@0 | 88 | // clear the cached results |
michael@0 | 89 | void ClearCachedResults() MOZ_OVERRIDE |
michael@0 | 90 | { |
michael@0 | 91 | mCachedResults = nullptr; |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | nsXULTemplateQueryProcessorRDF* Processor() MOZ_OVERRIDE { return mProcessor; } |
michael@0 | 95 | |
michael@0 | 96 | nsIAtom* GetMemberVariable() MOZ_OVERRIDE { return mMemberVariable; } |
michael@0 | 97 | |
michael@0 | 98 | bool IsSimple() { return mSimple; } |
michael@0 | 99 | |
michael@0 | 100 | void SetSimple() { mSimple = true; } |
michael@0 | 101 | |
michael@0 | 102 | // the reference and member variables for the query |
michael@0 | 103 | nsCOMPtr<nsIAtom> mRefVariable; |
michael@0 | 104 | nsCOMPtr<nsIAtom> mMemberVariable; |
michael@0 | 105 | |
michael@0 | 106 | protected: |
michael@0 | 107 | |
michael@0 | 108 | nsXULTemplateQueryProcessorRDF* mProcessor; |
michael@0 | 109 | |
michael@0 | 110 | // true if the query is a simple rule (one with a default query) |
michael@0 | 111 | bool mSimple; |
michael@0 | 112 | |
michael@0 | 113 | /** |
michael@0 | 114 | * The root node in the network for this query |
michael@0 | 115 | */ |
michael@0 | 116 | TestNode *mRoot; |
michael@0 | 117 | |
michael@0 | 118 | // the <query> node |
michael@0 | 119 | nsCOMPtr<nsIDOMNode> mQueryNode; |
michael@0 | 120 | |
michael@0 | 121 | // used for simple rules since their results are all determined in one step |
michael@0 | 122 | nsCOMPtr<nsISimpleEnumerator> mCachedResults; |
michael@0 | 123 | |
michael@0 | 124 | void Finish(); |
michael@0 | 125 | }; |
michael@0 | 126 | |
michael@0 | 127 | NS_DEFINE_STATIC_IID_ACCESSOR(nsITemplateRDFQuery, NS_ITEMPLATERDFQUERY_IID) |
michael@0 | 128 | |
michael@0 | 129 | #endif // nsRDFQuery_h__ |