First-stage fix for dogfood bug 49012. r=ben

This commit is contained in:
hyatt%netscape.com 2000-08-17 08:11:11 +00:00
Родитель bfa6381945
Коммит c60a2f7d07
21 изменённых файлов: 173 добавлений и 28 удалений

Просмотреть файл

@ -2346,6 +2346,14 @@ nsDocument::RemoveBinding(nsIDOMElement* aContent, const nsString& aURL)
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsDocument::LoadBindingDocument(const nsString& aURL)
{
if (mBindingManager)
return mBindingManager->LoadBindingDocument(aURL);
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsDocument::GetAnonymousNodes(nsIDOMElement* aElement, nsIDOMNodeList** aResult)
{

Просмотреть файл

@ -576,7 +576,7 @@ nsGenericDOMDataNode::ConvertContentToXIF(const nsIContent *aOuterContent,
nsCOMPtr<nsIDOMSelection> sel;
aConverter->GetSelection(getter_AddRefs(sel));
if (sel && mDocument->IsInSelection(sel,content))
if (sel && mDocument && mDocument->IsInSelection(sel,content))
{
nsCOMPtr<nsIEnumerator> enumerator;
if (NS_SUCCEEDED(sel->GetEnumerator(getter_AddRefs(enumerator)))) {

Просмотреть файл

@ -61,6 +61,7 @@ public:
NS_IMETHOD AddLayeredBinding(nsIContent* aContent, const nsString& aURL) = 0;
NS_IMETHOD RemoveLayeredBinding(nsIContent* aContent, const nsString& aURL) = 0;
NS_IMETHOD LoadBindingDocument(const nsString& aURL) = 0;
NS_IMETHOD AddToAttachedQueue(nsIXBLBinding* aBinding)=0;
NS_IMETHOD ClearAttachedQueue()=0;

Просмотреть файл

@ -72,6 +72,10 @@ public:
NS_IMETHOD GetXBLDocumentInfo(const nsCString& aURLStr, nsIContent* aBoundElement, nsIXBLDocumentInfo** aResult)=0;
// This method checks the hashtable and then calls FetchBindingDocument on a miss.
NS_IMETHOD LoadBindingDocumentInfo(nsIContent* aBoundElement, const nsCString& aURI, const nsCString& aRef,
PRBool aForceSyncLoad, nsIXBLDocumentInfo** aResult) = 0;
};
#endif // nsIXBLService_h__

Просмотреть файл

@ -165,6 +165,7 @@ public:
NS_IMETHOD AddLayeredBinding(nsIContent* aContent, const nsString& aURL);
NS_IMETHOD RemoveLayeredBinding(nsIContent* aContent, const nsString& aURL);
NS_IMETHOD LoadBindingDocument(const nsString& aURL);
NS_IMETHOD AddToAttachedQueue(nsIXBLBinding* aBinding);
NS_IMETHOD ClearAttachedQueue();
@ -369,6 +370,25 @@ nsBindingManager::RemoveLayeredBinding(nsIContent* aContent, const nsString& aUR
return NS_OK;
}
NS_IMETHODIMP
nsBindingManager::LoadBindingDocument(const nsString& aURL)
{
// First we need to load our binding.
nsresult rv;
NS_WITH_SERVICE(nsIXBLService, xblService, "component://netscape/xbl", &rv);
if (!xblService)
return rv;
// Load the binding doc.
nsCString url; url.AssignWithConversion(aURL);
nsCOMPtr<nsIXBLDocumentInfo> info;
xblService->LoadBindingDocumentInfo(nsnull, url, "", PR_TRUE, getter_AddRefs(info));
if (!info)
return NS_ERROR_FAILURE;
return NS_OK;
}
NS_IMETHODIMP
nsBindingManager::AddToAttachedQueue(nsIXBLBinding* aBinding)
{

Просмотреть файл

@ -818,7 +818,7 @@ NS_IMETHODIMP nsXBLService::GetBindingInternal(nsIContent* aBoundElement,
uri.Truncate(indx);
nsCOMPtr<nsIXBLDocumentInfo> docInfo;
GetBindingDocumentInfo(aBoundElement, uri, ref, getter_AddRefs(docInfo));
LoadBindingDocumentInfo(aBoundElement, uri, ref, PR_FALSE, getter_AddRefs(docInfo));
if (!docInfo)
return NS_ERROR_FAILURE;
@ -903,8 +903,8 @@ NS_IMETHODIMP nsXBLService::GetBindingInternal(nsIContent* aBoundElement,
}
NS_IMETHODIMP
nsXBLService::GetBindingDocumentInfo(nsIContent* aBoundElement, const nsCString& aURLStr, const nsCString& aRef,
nsIXBLDocumentInfo** aResult)
nsXBLService::LoadBindingDocumentInfo(nsIContent* aBoundElement, const nsCString& aURLStr, const nsCString& aRef,
PRBool aForceSyncLoad, nsIXBLDocumentInfo** aResult)
{
nsresult rv;
@ -928,8 +928,9 @@ nsXBLService::GetBindingDocumentInfo(nsIContent* aBoundElement, const nsCString&
bindingManager->GetXBLDocumentInfo(aURLStr, getter_AddRefs(info));
nsCOMPtr<nsIAtom> tagName;
aBoundElement->GetTag(*getter_AddRefs(tagName));
if (!info && (tagName.get() != kScrollbarAtom)) {
if (aBoundElement)
aBoundElement->GetTag(*getter_AddRefs(tagName));
if (!info && (tagName.get() != kScrollbarAtom) && !aForceSyncLoad) {
// The third line of defense is to investigate whether or not the
// document is currently being loaded asynchronously. If so, there's no
// document yet, but we need to glom on our request so that it will be
@ -961,7 +962,7 @@ nsXBLService::GetBindingDocumentInfo(nsIContent* aBoundElement, const nsCString&
getter_AddRefs(uri));
uri->SetSpec(aURLStr);
nsCOMPtr<nsIDocument> document;
FetchBindingDocument(aBoundElement, uri, aRef, getter_AddRefs(document));
FetchBindingDocument(aBoundElement, uri, aRef, aForceSyncLoad, getter_AddRefs(document));
if (document) {
NS_NewXBLDocumentInfo(document, getter_AddRefs(info));
@ -1003,7 +1004,8 @@ nsXBLService::GetBindingDocumentInfo(nsIContent* aBoundElement, const nsCString&
}
NS_IMETHODIMP
nsXBLService::FetchBindingDocument(nsIContent* aBoundElement, nsIURI* aURI, const nsCString& aRef, nsIDocument** aResult)
nsXBLService::FetchBindingDocument(nsIContent* aBoundElement, nsIURI* aURI, const nsCString& aRef,
PRBool aForceSyncLoad, nsIDocument** aResult)
{
// Initialize our out pointer to nsnull
*aResult = nsnull;
@ -1041,7 +1043,7 @@ nsXBLService::FetchBindingDocument(nsIContent* aBoundElement, nsIURI* aURI, cons
nsCOMPtr<nsIAtom> tagName;
aBoundElement->GetTag(*getter_AddRefs(tagName));
if (tagName.get() != kScrollbarAtom) {
if (tagName.get() != kScrollbarAtom && !aForceSyncLoad) {
// We can be asynchronous
nsXBLStreamListener* xblListener = new nsXBLStreamListener(listener, boundDoc, doc);

Просмотреть файл

@ -71,18 +71,20 @@ class nsXBLService : public nsIXBLService, public nsIMemoryPressureObserver
NS_IMETHOD GetXBLDocumentInfo(const nsCString& aURLStr, nsIContent* aBoundElement, nsIXBLDocumentInfo** aResult);
// This method checks the hashtable and then calls FetchBindingDocument on a miss.
NS_IMETHOD LoadBindingDocumentInfo(nsIContent* aBoundElement, const nsCString& aURI, const nsCString& aRef,
PRBool aForceSyncLoad, nsIXBLDocumentInfo** aResult);
NS_DECL_NSIMEMORYPRESSUREOBSERVER
public:
nsXBLService();
virtual ~nsXBLService();
// This method checks the hashtable and then calls FetchBindingDocument on a miss.
NS_IMETHOD GetBindingDocumentInfo(nsIContent* aBoundElement, const nsCString& aURI, const nsCString& aRef,
nsIXBLDocumentInfo** aResult);
// This method synchronously loads and parses an XBL file.
NS_IMETHOD FetchBindingDocument(nsIContent* aBoundElement, nsIURI* aURI, const nsCString& aRef, nsIDocument** aResult);
NS_IMETHOD FetchBindingDocument(nsIContent* aBoundElement, nsIURI* aURI, const nsCString& aRef,
PRBool aForceSyncLoad, nsIDocument** aResult);
// This method loads a binding doc and then builds the specific binding required. It
// can also peek without building.

Просмотреть файл

@ -2977,6 +2977,14 @@ nsXULDocument::RemoveBinding(nsIDOMElement* aContent, const nsString& aURL)
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsXULDocument::LoadBindingDocument(const nsString& aURL)
{
if (mBindingManager)
return mBindingManager->LoadBindingDocument(aURL);
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsXULDocument::GetAnonymousNodes(nsIDOMElement* aElement, nsIDOMNodeList** aResult)
{

Просмотреть файл

@ -44,6 +44,8 @@ public:
NS_IMETHOD AddBinding(nsIDOMElement* aElt, const nsString& aBindingURL)=0;
NS_IMETHOD RemoveBinding(nsIDOMElement* aElt, const nsString& aBindingURL)=0;
NS_IMETHOD LoadBindingDocument(const nsString& aDocumentURL)=0;
};
@ -51,6 +53,7 @@ public:
NS_IMETHOD GetAnonymousNodes(nsIDOMElement* aElt, nsIDOMNodeList** aReturn); \
NS_IMETHOD AddBinding(nsIDOMElement* aElt, const nsString& aBindingURL); \
NS_IMETHOD RemoveBinding(nsIDOMElement* aElt, const nsString& aBindingURL); \
NS_IMETHOD LoadBindingDocument(const nsString& aDocumentURL); \
@ -58,6 +61,7 @@ public:
NS_IMETHOD GetAnonymousNodes(nsIDOMElement* aElt, nsIDOMNodeList** aReturn) { return _to GetAnonymousNodes(aElt, aReturn); } \
NS_IMETHOD AddBinding(nsIDOMElement* aElt, const nsString& aBindingURL) { return _to AddBinding(aElt, aBindingURL); } \
NS_IMETHOD RemoveBinding(nsIDOMElement* aElt, const nsString& aBindingURL) { return _to RemoveBinding(aElt, aBindingURL); } \
NS_IMETHOD LoadBindingDocument(const nsString& aDocumentURL) { return _to LoadBindingDocument(aDocumentURL); } \
#endif // nsIDOMDocumentXBL_h__

Просмотреть файл

@ -79,6 +79,8 @@ interface DocumentXBL {
NodeList getAnonymousNodes(in Element elt);
void addBinding(in Element elt, in DOMString bindingURL);
void removeBinding(in Element elt, in DOMString bindingURL);
void loadBindingDocument(in DOMString documentURL);
};
interface NSDocument {

Просмотреть файл

@ -260,6 +260,7 @@ enum nsDOMProp {
NS_DOM_PROP_DOCUMENTVIEW_DEFAULTVIEW,
NS_DOM_PROP_DOCUMENTXBL_ADDBINDING,
NS_DOM_PROP_DOCUMENTXBL_GETANONYMOUSNODES,
NS_DOM_PROP_DOCUMENTXBL_LOADBINDINGDOCUMENT,
NS_DOM_PROP_DOCUMENTXBL_REMOVEBINDING,
NS_DOM_PROP_DOMEXCEPTION_CODE,
NS_DOM_PROP_DOMEXCEPTION_MESSAGE,

Просмотреть файл

@ -258,6 +258,7 @@
"documentview.defaultview", \
"documentxbl.addbinding", \
"documentxbl.getanonymousnodes", \
"documentxbl.loadbindingdocument", \
"documentxbl.removebinding", \
"domexception.code", \
"domexception.message", \

Просмотреть файл

@ -1182,6 +1182,52 @@ DocumentXBLRemoveBinding(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
}
//
// Native method LoadBindingDocument
//
PR_STATIC_CALLBACK(JSBool)
DocumentXBLLoadBindingDocument(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMDocument *privateThis = (nsIDOMDocument*)nsJSUtils::nsGetNativeThis(cx, obj);
nsCOMPtr<nsIDOMDocumentXBL> nativeThis;
nsresult result = NS_OK;
if (NS_OK != privateThis->QueryInterface(kIDocumentXBLIID, getter_AddRefs(nativeThis))) {
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR);
}
nsAutoString b0;
// If there's no private data, this must be the prototype, so ignore
if (!nativeThis) {
return JS_TRUE;
}
{
*rval = JSVAL_NULL;
nsIScriptSecurityManager *secMan = nsJSUtils::nsGetSecurityManager(cx, obj);
if (!secMan)
return PR_FALSE;
result = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_DOCUMENTXBL_LOADBINDINGDOCUMENT, PR_FALSE);
if (NS_FAILED(result)) {
return nsJSUtils::nsReportError(cx, obj, result);
}
if (argc < 1) {
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR);
}
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
result = nativeThis->LoadBindingDocument(b0);
if (NS_FAILED(result)) {
return nsJSUtils::nsReportError(cx, obj, result);
}
*rval = JSVAL_VOID;
}
return JS_TRUE;
}
//
// Native method CreateElementWithNameSpace
//
@ -1378,6 +1424,7 @@ static JSFunctionSpec DocumentMethods[] =
{"getAnonymousNodes", DocumentXBLGetAnonymousNodes, 1},
{"addBinding", DocumentXBLAddBinding, 2},
{"removeBinding", DocumentXBLRemoveBinding, 2},
{"loadBindingDocument", DocumentXBLLoadBindingDocument, 1},
{"createElementWithNameSpace", NSDocumentCreateElementWithNameSpace, 2},
{"createRange", NSDocumentCreateRange, 0},
{"load", NSDocumentLoad, 1},

Просмотреть файл

@ -2346,6 +2346,14 @@ nsDocument::RemoveBinding(nsIDOMElement* aContent, const nsString& aURL)
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsDocument::LoadBindingDocument(const nsString& aURL)
{
if (mBindingManager)
return mBindingManager->LoadBindingDocument(aURL);
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsDocument::GetAnonymousNodes(nsIDOMElement* aElement, nsIDOMNodeList** aResult)
{

Просмотреть файл

@ -576,7 +576,7 @@ nsGenericDOMDataNode::ConvertContentToXIF(const nsIContent *aOuterContent,
nsCOMPtr<nsIDOMSelection> sel;
aConverter->GetSelection(getter_AddRefs(sel));
if (sel && mDocument->IsInSelection(sel,content))
if (sel && mDocument && mDocument->IsInSelection(sel,content))
{
nsCOMPtr<nsIEnumerator> enumerator;
if (NS_SUCCEEDED(sel->GetEnumerator(getter_AddRefs(enumerator)))) {

Просмотреть файл

@ -61,6 +61,7 @@ public:
NS_IMETHOD AddLayeredBinding(nsIContent* aContent, const nsString& aURL) = 0;
NS_IMETHOD RemoveLayeredBinding(nsIContent* aContent, const nsString& aURL) = 0;
NS_IMETHOD LoadBindingDocument(const nsString& aURL) = 0;
NS_IMETHOD AddToAttachedQueue(nsIXBLBinding* aBinding)=0;
NS_IMETHOD ClearAttachedQueue()=0;

Просмотреть файл

@ -72,6 +72,10 @@ public:
NS_IMETHOD GetXBLDocumentInfo(const nsCString& aURLStr, nsIContent* aBoundElement, nsIXBLDocumentInfo** aResult)=0;
// This method checks the hashtable and then calls FetchBindingDocument on a miss.
NS_IMETHOD LoadBindingDocumentInfo(nsIContent* aBoundElement, const nsCString& aURI, const nsCString& aRef,
PRBool aForceSyncLoad, nsIXBLDocumentInfo** aResult) = 0;
};
#endif // nsIXBLService_h__

Просмотреть файл

@ -165,6 +165,7 @@ public:
NS_IMETHOD AddLayeredBinding(nsIContent* aContent, const nsString& aURL);
NS_IMETHOD RemoveLayeredBinding(nsIContent* aContent, const nsString& aURL);
NS_IMETHOD LoadBindingDocument(const nsString& aURL);
NS_IMETHOD AddToAttachedQueue(nsIXBLBinding* aBinding);
NS_IMETHOD ClearAttachedQueue();
@ -369,6 +370,25 @@ nsBindingManager::RemoveLayeredBinding(nsIContent* aContent, const nsString& aUR
return NS_OK;
}
NS_IMETHODIMP
nsBindingManager::LoadBindingDocument(const nsString& aURL)
{
// First we need to load our binding.
nsresult rv;
NS_WITH_SERVICE(nsIXBLService, xblService, "component://netscape/xbl", &rv);
if (!xblService)
return rv;
// Load the binding doc.
nsCString url; url.AssignWithConversion(aURL);
nsCOMPtr<nsIXBLDocumentInfo> info;
xblService->LoadBindingDocumentInfo(nsnull, url, "", PR_TRUE, getter_AddRefs(info));
if (!info)
return NS_ERROR_FAILURE;
return NS_OK;
}
NS_IMETHODIMP
nsBindingManager::AddToAttachedQueue(nsIXBLBinding* aBinding)
{

Просмотреть файл

@ -818,7 +818,7 @@ NS_IMETHODIMP nsXBLService::GetBindingInternal(nsIContent* aBoundElement,
uri.Truncate(indx);
nsCOMPtr<nsIXBLDocumentInfo> docInfo;
GetBindingDocumentInfo(aBoundElement, uri, ref, getter_AddRefs(docInfo));
LoadBindingDocumentInfo(aBoundElement, uri, ref, PR_FALSE, getter_AddRefs(docInfo));
if (!docInfo)
return NS_ERROR_FAILURE;
@ -903,8 +903,8 @@ NS_IMETHODIMP nsXBLService::GetBindingInternal(nsIContent* aBoundElement,
}
NS_IMETHODIMP
nsXBLService::GetBindingDocumentInfo(nsIContent* aBoundElement, const nsCString& aURLStr, const nsCString& aRef,
nsIXBLDocumentInfo** aResult)
nsXBLService::LoadBindingDocumentInfo(nsIContent* aBoundElement, const nsCString& aURLStr, const nsCString& aRef,
PRBool aForceSyncLoad, nsIXBLDocumentInfo** aResult)
{
nsresult rv;
@ -928,8 +928,9 @@ nsXBLService::GetBindingDocumentInfo(nsIContent* aBoundElement, const nsCString&
bindingManager->GetXBLDocumentInfo(aURLStr, getter_AddRefs(info));
nsCOMPtr<nsIAtom> tagName;
aBoundElement->GetTag(*getter_AddRefs(tagName));
if (!info && (tagName.get() != kScrollbarAtom)) {
if (aBoundElement)
aBoundElement->GetTag(*getter_AddRefs(tagName));
if (!info && (tagName.get() != kScrollbarAtom) && !aForceSyncLoad) {
// The third line of defense is to investigate whether or not the
// document is currently being loaded asynchronously. If so, there's no
// document yet, but we need to glom on our request so that it will be
@ -961,7 +962,7 @@ nsXBLService::GetBindingDocumentInfo(nsIContent* aBoundElement, const nsCString&
getter_AddRefs(uri));
uri->SetSpec(aURLStr);
nsCOMPtr<nsIDocument> document;
FetchBindingDocument(aBoundElement, uri, aRef, getter_AddRefs(document));
FetchBindingDocument(aBoundElement, uri, aRef, aForceSyncLoad, getter_AddRefs(document));
if (document) {
NS_NewXBLDocumentInfo(document, getter_AddRefs(info));
@ -1003,7 +1004,8 @@ nsXBLService::GetBindingDocumentInfo(nsIContent* aBoundElement, const nsCString&
}
NS_IMETHODIMP
nsXBLService::FetchBindingDocument(nsIContent* aBoundElement, nsIURI* aURI, const nsCString& aRef, nsIDocument** aResult)
nsXBLService::FetchBindingDocument(nsIContent* aBoundElement, nsIURI* aURI, const nsCString& aRef,
PRBool aForceSyncLoad, nsIDocument** aResult)
{
// Initialize our out pointer to nsnull
*aResult = nsnull;
@ -1041,7 +1043,7 @@ nsXBLService::FetchBindingDocument(nsIContent* aBoundElement, nsIURI* aURI, cons
nsCOMPtr<nsIAtom> tagName;
aBoundElement->GetTag(*getter_AddRefs(tagName));
if (tagName.get() != kScrollbarAtom) {
if (tagName.get() != kScrollbarAtom && !aForceSyncLoad) {
// We can be asynchronous
nsXBLStreamListener* xblListener = new nsXBLStreamListener(listener, boundDoc, doc);

Просмотреть файл

@ -71,18 +71,20 @@ class nsXBLService : public nsIXBLService, public nsIMemoryPressureObserver
NS_IMETHOD GetXBLDocumentInfo(const nsCString& aURLStr, nsIContent* aBoundElement, nsIXBLDocumentInfo** aResult);
// This method checks the hashtable and then calls FetchBindingDocument on a miss.
NS_IMETHOD LoadBindingDocumentInfo(nsIContent* aBoundElement, const nsCString& aURI, const nsCString& aRef,
PRBool aForceSyncLoad, nsIXBLDocumentInfo** aResult);
NS_DECL_NSIMEMORYPRESSUREOBSERVER
public:
nsXBLService();
virtual ~nsXBLService();
// This method checks the hashtable and then calls FetchBindingDocument on a miss.
NS_IMETHOD GetBindingDocumentInfo(nsIContent* aBoundElement, const nsCString& aURI, const nsCString& aRef,
nsIXBLDocumentInfo** aResult);
// This method synchronously loads and parses an XBL file.
NS_IMETHOD FetchBindingDocument(nsIContent* aBoundElement, nsIURI* aURI, const nsCString& aRef, nsIDocument** aResult);
NS_IMETHOD FetchBindingDocument(nsIContent* aBoundElement, nsIURI* aURI, const nsCString& aRef,
PRBool aForceSyncLoad, nsIDocument** aResult);
// This method loads a binding doc and then builds the specific binding required. It
// can also peek without building.

Просмотреть файл

@ -2977,6 +2977,14 @@ nsXULDocument::RemoveBinding(nsIDOMElement* aContent, const nsString& aURL)
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsXULDocument::LoadBindingDocument(const nsString& aURL)
{
if (mBindingManager)
return mBindingManager->LoadBindingDocument(aURL);
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsXULDocument::GetAnonymousNodes(nsIDOMElement* aElement, nsIDOMNodeList** aResult)
{