Skip to content

Commit 3e8d2f2

Browse files
author
vladimir%pobox.com
committed
b=235665, aggregation broken in bookmarks [gecko only bits], r=axel,shaver,others,sr=shaver
1 parent 24ef3c1 commit 3e8d2f2

File tree

9 files changed

+214
-11
lines changed

9 files changed

+214
-11
lines changed

content/shared/public/nsXULAtomList.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,3 +309,4 @@ XUL_ATOM(hidechrome, "hidechrome")
309309
XUL_ATOM(popupset, "popupset")
310310
XUL_ATOM(parsetype, "parsetype")
311311
XUL_ATOM(canvas, "canvas")
312+
XUL_ATOM(infer, "infer")

content/xul/templates/src/nsXULContentBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ nsXULContentBuilder::BuildContentFromTemplate(nsIContent *aTemplateNode,
802802
rv = NS_ERROR_UNEXPECTED;
803803

804804
if (gXULSortService && isResourceElement) {
805-
rv = gXULSortService->InsertContainerNode(mDB, &sortState,
805+
rv = gXULSortService->InsertContainerNode(mCompDB, &sortState,
806806
mRoot, aResourceNode,
807807
aRealNode, realKid,
808808
aNotify);

content/xul/templates/src/nsXULTemplateBuilder.cpp

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
#include "nsINameSpace.h"
7878
#include "nsINameSpaceManager.h"
7979
#include "nsIRDFCompositeDataSource.h"
80+
#include "nsIRDFInferDataSource.h"
8081
#include "nsIRDFContainerUtils.h"
8182
#include "nsIXULDocument.h"
8283
#include "nsIXULTemplateBuilder.h"
@@ -149,6 +150,7 @@ PRLogModuleInfo* gXULTemplateLog;
149150

150151
nsXULTemplateBuilder::nsXULTemplateBuilder(void)
151152
: mDB(nsnull),
153+
mCompDB(nsnull),
152154
mRoot(nsnull),
153155
mUpdateBatchNest(0),
154156
mRulesCompiled(PR_FALSE),
@@ -220,7 +222,7 @@ nsXULTemplateBuilder::GetRoot(nsIDOMElement** aResult)
220222
NS_IMETHODIMP
221223
nsXULTemplateBuilder::GetDatabase(nsIRDFCompositeDataSource** aResult)
222224
{
223-
NS_IF_ADDREF(*aResult = mDB.get());
225+
NS_IF_ADDREF(*aResult = mCompDB.get());
224226
return NS_OK;
225227
}
226228

@@ -248,7 +250,7 @@ nsXULTemplateBuilder::Refresh()
248250
nsresult rv;
249251

250252
nsCOMPtr<nsISimpleEnumerator> dslist;
251-
rv = mDB->GetDataSources(getter_AddRefs(dslist));
253+
rv = mCompDB->GetDataSources(getter_AddRefs(dslist));
252254
NS_ENSURE_SUCCESS(rv, rv);
253255

254256
PRBool hasMore;
@@ -350,6 +352,7 @@ nsXULTemplateBuilder::DocumentWillBeDestroyed(nsIDocument *aDocument)
350352
if (mDB) {
351353
mDB->RemoveObserver(this);
352354
mDB = nsnull;
355+
mCompDB = nsnull;
353356
}
354357

355358
mRoot = nsnull;
@@ -668,12 +671,15 @@ nsXULTemplateBuilder::LoadDataSources(nsIDocument* doc)
668671

669672
if (mDB) {
670673
mDB->RemoveObserver(this);
674+
675+
// we'll set it again later, after we create a new composite ds
676+
mDB = nsnull;
671677
}
672678

673679
// create a database for the builder
674-
mDB = do_CreateInstance(NS_RDF_DATASOURCE_CONTRACTID_PREFIX "composite-datasource");
680+
mCompDB = do_CreateInstance(NS_RDF_DATASOURCE_CONTRACTID_PREFIX "composite-datasource");
675681

676-
if (! mDB) {
682+
if (! mCompDB) {
677683
NS_ERROR("unable to construct new composite data source");
678684
return NS_ERROR_UNEXPECTED;
679685
}
@@ -682,12 +688,12 @@ nsXULTemplateBuilder::LoadDataSources(nsIDocument* doc)
682688
nsAutoString coalesce;
683689
mRoot->GetAttr(kNameSpaceID_None, nsXULAtoms::coalesceduplicatearcs, coalesce);
684690
if (coalesce.EqualsLiteral("false"))
685-
mDB->SetCoalesceDuplicateArcs(PR_FALSE);
691+
mCompDB->SetCoalesceDuplicateArcs(PR_FALSE);
686692

687693
nsAutoString allowneg;
688694
mRoot->GetAttr(kNameSpaceID_None, nsXULAtoms::allownegativeassertions, allowneg);
689695
if (allowneg.EqualsLiteral("false"))
690-
mDB->SetAllowNegativeAssertions(PR_FALSE);
696+
mCompDB->SetAllowNegativeAssertions(PR_FALSE);
691697

692698
// Grab the doc's principal...
693699
nsIPrincipal *docPrincipal = doc->GetPrincipal();
@@ -706,7 +712,7 @@ nsXULTemplateBuilder::LoadDataSources(nsIDocument* doc)
706712
nsCOMPtr<nsIRDFDataSource> localstore;
707713
rv = gRDFService->GetDataSource("rdf:local-store", getter_AddRefs(localstore));
708714
if (NS_SUCCEEDED(rv)) {
709-
rv = mDB->AddDataSource(localstore);
715+
rv = mCompDB->AddDataSource(localstore);
710716
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to add local store to db");
711717
if (NS_FAILED(rv)) return rv;
712718
}
@@ -793,9 +799,28 @@ nsXULTemplateBuilder::LoadDataSources(nsIDocument* doc)
793799
continue;
794800
}
795801

796-
mDB->AddDataSource(ds);
802+
mCompDB->AddDataSource(ds);
797803
}
798804

805+
// check if we were given an inference engine type
806+
nsAutoString infer;
807+
mRoot->GetAttr(kNameSpaceID_None, nsXULAtoms::infer, infer);
808+
if (!infer.IsEmpty()) {
809+
nsCString inferContractID(NS_RDF_INFER_DATASOURCE_CONTRACTID_PREFIX);
810+
AppendUTF16toUTF8(infer, inferContractID);
811+
nsCOMPtr<nsIRDFInferDataSource> inferDB = do_CreateInstance(inferContractID.get());
812+
813+
if (inferDB) {
814+
inferDB->SetBaseDataSource(mCompDB);
815+
mDB = do_QueryInterface(inferDB);
816+
} else {
817+
NS_WARNING("failed to construct inference engine specified on template");
818+
}
819+
}
820+
821+
if (!mDB)
822+
mDB = mCompDB;
823+
799824
nsCOMPtr<nsIXULDocument> xuldoc = do_QueryInterface(doc);
800825
if (xuldoc)
801826
xuldoc->SetTemplateBuilderFor(mRoot, this);

content/xul/templates/src/nsXULTemplateBuilder.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,8 @@ class nsXULTemplateBuilder : public nsIXULTemplateBuilder,
301301
protected:
302302
// We are an observer of the composite datasource. The cycle is
303303
// broken when the document is destroyed.
304-
nsCOMPtr<nsIRDFCompositeDataSource> mDB;
304+
nsCOMPtr<nsIRDFDataSource> mDB;
305+
nsCOMPtr<nsIRDFCompositeDataSource> mCompDB;
305306

306307
// Circular reference, broken when the document is destroyed.
307308
nsCOMPtr<nsIContent> mRoot;

rdf/base/idl/Makefile.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ XPIDLSRCS = \
6464
nsIRDFXMLSerializer.idl \
6565
nsIRDFXMLSink.idl \
6666
nsIRDFXMLSource.idl \
67+
nsIRDFInferDataSource.idl \
6768
$(NULL)
6869

6970
include $(topsrcdir)/config/rules.mk
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2+
/* ***** BEGIN LICENSE BLOCK *****
3+
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
4+
*
5+
* The contents of this file are subject to the Mozilla Public License Version
6+
* 1.1 (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
* http://www.mozilla.org/MPL/
9+
*
10+
* Software distributed under the License is distributed on an "AS IS" basis,
11+
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12+
* for the specific language governing rights and limitations under the
13+
* License.
14+
*
15+
* The Original Code is mozilla.org code.
16+
*
17+
* The Initial Developer of the Original Code is
18+
* Vladimir Vukicevic <vladimir@pobox.com>
19+
* Portions created by the Initial Developer are Copyright (C) 2004
20+
* the Initial Developer. All Rights Reserved.
21+
*
22+
* Contributor(s):
23+
*
24+
* Alternatively, the contents of this file may be used under the terms of
25+
* either the GNU General Public License Version 2 or later (the "GPL"), or
26+
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27+
* in which case the provisions of the GPL or the LGPL are applicable instead
28+
* of those above. If you wish to allow use of your version of this file only
29+
* under the terms of either the GPL or the LGPL, and not to allow others to
30+
* use your version of this file under the terms of the MPL, indicate your
31+
* decision by deleting the provisions above and replace them with the notice
32+
* and other provisions required by the GPL or the LGPL. If you do not delete
33+
* the provisions above, a recipient may use your version of this file under
34+
* the terms of any one of the MPL, the GPL or the LGPL.
35+
*
36+
* ***** END LICENSE BLOCK ***** */
37+
38+
#include "nsIRDFDataSource.idl"
39+
40+
/**
41+
* An nsIRDFInferDataSource is implemented by a infer engine. This
42+
* engine mimics assertions in addition to those in the baseDataSource
43+
* according to a particular vocabulary.
44+
* Infer engines have contract IDs in the form of
45+
* "@mozilla.org/rdf/infer-datasource;1?engine="
46+
*/
47+
48+
[scriptable, uuid(2b04860f-4017-40f6-8a57-784a1e35077a)]
49+
interface nsIRDFInferDataSource : nsIRDFDataSource {
50+
/**
51+
*
52+
* The wrapped datasource.
53+
*
54+
* The InferDataSource contains all arcs from the wrapped
55+
* datasource plus those infered by the vocabulary implemented
56+
* by the InferDataSource.
57+
*/
58+
attribute nsIRDFDataSource baseDataSource;
59+
};
60+

rdf/base/public/rdf.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static const char kURI##prefix##_##name[] = ns #name
7070
#define RDF_NAMESPACE_URI "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
7171
#define WEB_NAMESPACE_URI "http://home.netscape.com/WEB-rdf#"
7272
#define NC_NAMESPACE_URI "http://home.netscape.com/NC-rdf#"
73-
73+
#define DEVMO_NAMESPACE_URI_PREFIX "http://developer.mozilla.org/rdf/vocabulary/"
7474

7575
/**
7676
* @name Standard RDF error codes
@@ -103,6 +103,7 @@ static const char kURI##prefix##_##name[] = ns #name
103103
#define NS_RDF_DATASOURCE_CONTRACTID_PREFIX NS_RDF_DATASOURCE_CONTRACTID "?name="
104104
#define NS_RDF_RESOURCE_FACTORY_CONTRACTID "@mozilla.org/rdf/resource-factory;1"
105105
#define NS_RDF_RESOURCE_FACTORY_CONTRACTID_PREFIX NS_RDF_RESOURCE_FACTORY_CONTRACTID "?name="
106+
#define NS_RDF_INFER_DATASOURCE_CONTRACTID_PREFIX NS_RDF_CONTRACTID "/infer-datasource;1?engine="
106107

107108
// contract ID is in the form
108109
// @mozilla.org/rdf/delegate-factory;1?key=<key>&scheme=<scheme>

xpcom/ds/nsEnumeratorUtils.cpp

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,90 @@ NS_NewSingletonEnumerator(nsISimpleEnumerator* *result,
164164

165165
////////////////////////////////////////////////////////////////////////////////
166166

167+
nsUnionEnumerator::nsUnionEnumerator(nsISimpleEnumerator* firstEnumerator,
168+
nsISimpleEnumerator* secondEnumerator)
169+
: mFirstEnumerator(firstEnumerator),
170+
mSecondEnumerator(secondEnumerator),
171+
mConsumed(PR_FALSE), mAtSecond(PR_FALSE)
172+
{
173+
}
174+
175+
nsUnionEnumerator::~nsUnionEnumerator()
176+
{
177+
}
178+
179+
NS_IMPL_ISUPPORTS1(nsUnionEnumerator, nsISimpleEnumerator)
180+
181+
NS_IMETHODIMP
182+
nsUnionEnumerator::HasMoreElements(PRBool* aResult)
183+
{
184+
NS_PRECONDITION(aResult != 0, "null ptr");
185+
if (! aResult)
186+
return NS_ERROR_NULL_POINTER;
187+
188+
nsresult rv;
189+
190+
if (mConsumed) {
191+
*aResult = PR_FALSE;
192+
return NS_OK;
193+
}
194+
195+
if (! mAtSecond) {
196+
rv = mFirstEnumerator->HasMoreElements(aResult);
197+
if (NS_FAILED(rv)) return rv;
198+
199+
if (*aResult)
200+
return NS_OK;
201+
202+
mAtSecond = PR_TRUE;
203+
}
204+
205+
rv = mSecondEnumerator->HasMoreElements(aResult);
206+
if (NS_FAILED(rv)) return rv;
207+
208+
if (*aResult)
209+
return NS_OK;
167210

211+
*aResult = PR_FALSE;
212+
mConsumed = PR_TRUE;
213+
return NS_OK;
214+
}
215+
216+
NS_IMETHODIMP
217+
nsUnionEnumerator::GetNext(nsISupports** aResult)
218+
{
219+
NS_PRECONDITION(aResult != 0, "null ptr");
220+
if (! aResult)
221+
return NS_ERROR_NULL_POINTER;
222+
223+
if (mConsumed)
224+
return NS_ERROR_UNEXPECTED;
225+
226+
if (! mAtSecond)
227+
return mFirstEnumerator->GetNext(aResult);
228+
229+
return mSecondEnumerator->GetNext(aResult);
230+
}
231+
232+
extern "C" NS_COM nsresult
233+
NS_NewUnionEnumerator(nsISimpleEnumerator* *result,
234+
nsISimpleEnumerator* firstEnumerator,
235+
nsISimpleEnumerator* secondEnumerator)
236+
{
237+
*result = nsnull;
238+
if (! firstEnumerator) {
239+
*result = secondEnumerator;
240+
} else if (! secondEnumerator) {
241+
*result = firstEnumerator;
242+
} else {
243+
nsUnionEnumerator* enumer = new nsUnionEnumerator(firstEnumerator, secondEnumerator);
244+
if (enumer == nsnull)
245+
return NS_ERROR_OUT_OF_MEMORY;
246+
*result = enumer;
247+
}
248+
NS_ADDREF(*result);
249+
return NS_OK;
250+
}
251+
252+
253+
////////////////////////////////////////////////////////////////////////////////

xpcom/ds/nsEnumeratorUtils.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,32 @@ NS_NewSingletonEnumerator(nsISimpleEnumerator* *result,
9393

9494
////////////////////////////////////////////////////////////////////////
9595

96+
class NS_COM nsUnionEnumerator : public nsISimpleEnumerator
97+
{
98+
public:
99+
NS_DECL_ISUPPORTS
100+
101+
// nsISimpleEnumerator methods
102+
NS_IMETHOD HasMoreElements(PRBool* aResult);
103+
NS_IMETHOD GetNext(nsISupports** aResult);
104+
105+
nsUnionEnumerator(nsISimpleEnumerator* firstEnumerator,
106+
nsISimpleEnumerator* secondEnumerator);
107+
108+
private:
109+
~nsUnionEnumerator();
110+
111+
protected:
112+
nsCOMPtr<nsISimpleEnumerator> mFirstEnumerator, mSecondEnumerator;
113+
PRBool mConsumed;
114+
PRBool mAtSecond;
115+
};
116+
117+
extern "C" NS_COM nsresult
118+
NS_NewUnionEnumerator(nsISimpleEnumerator* *result,
119+
nsISimpleEnumerator* firstEnumerator,
120+
nsISimpleEnumerator* secondEnumerator);
121+
122+
////////////////////////////////////////////////////////////////////////
123+
96124
#endif /* nsEnumeratorUtils_h__ */

0 commit comments

Comments
 (0)