Teaching XBL how to load files. r=mini-me

This commit is contained in:
hyatt%netscape.com 2000-01-12 09:57:45 +00:00
Родитель 4efd17c17e
Коммит 69df4a2d4a
2 изменённых файлов: 118 добавлений и 0 удалений

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

@ -11,6 +11,8 @@
#include "nsParserCIID.h"
#include "nsNetUtil.h"
#include "plstr.h"
#include "nsIContent.h"
#include "nsIDocument.h"
// nsProxyStream
// A helper class used for synchronous parsing of URLs.
@ -85,6 +87,12 @@ public:
nsXBLService();
virtual ~nsXBLService();
// This method checks the hashtable and then calls FetchBindingDocument on a miss.
NS_IMETHOD GetBindingDocument(nsCAutoString& aURLStr, nsIDocument** aResult);
// This method synchronously loads and parses an XBL file.
NS_IMETHOD FetchBindingDocument(nsIURI* aURI, nsIDocument** aResult);
protected:
// This URIkey class is used to hash URLs into an XBL binding
// cache.
@ -155,6 +163,13 @@ nsXBLService::~nsXBLService(void)
NS_IMETHODIMP
nsXBLService::LoadBindings(nsIContent* aContent, const nsString& aURL)
{
nsresult rv;
nsCAutoString url = aURL;
nsCOMPtr<nsIDocument> document;
if (NS_FAILED(rv = GetBindingDocument(url, getter_AddRefs(document)))) {
NS_ERROR("Failed loading an XBL document for content node.");
return rv;
}
return NS_OK;
}
@ -164,6 +179,50 @@ nsXBLService::LoadBindings(nsIContent* aContent, const nsString& aURL)
NS_IMETHODIMP
nsXBLService::GetContentList(nsIContent* aContent, nsISupportsArray** aResult)
{
// XXX Implement me!
return NS_OK;
}
// Internal helper methods ////////////////////////////////////////////////////////////////
NS_IMETHODIMP nsXBLService::GetBindingDocument(nsCAutoString& aURLStr, nsIDocument** aResult)
{
nsCOMPtr<nsIDocument> document;
if (aURLStr != nsCAutoString("")) {
nsCOMPtr<nsIURL> uri;
nsComponentManager::CreateInstance("component://netscape/network/standard-url",
nsnull,
NS_GET_IID(nsIURL),
getter_AddRefs(uri));
uri->SetSpec(aURLStr);
// XXX Obtain the # marker and remove it from the URL.
// We've got a file. Check our key binding file cache.
nsIURIKey key(uri);
document = dont_AddRef(NS_STATIC_CAST(nsIDocument*, mBindingTable->Get(&key)));
if (!document) {
FetchBindingDocument(uri, getter_AddRefs(document));
if (document) {
// Put the key binding doc into our table.
mBindingTable->Put(&key, document);
}
else return NS_ERROR_FAILURE;
}
}
*aResult = document;
NS_IF_ADDREF(*aResult);
return NS_OK;
}
NS_IMETHODIMP
nsXBLService::FetchBindingDocument(nsIURI* aURI, nsIDocument** aResult)
{
*aResult = nsnull;
return NS_OK;
}

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

@ -11,6 +11,8 @@
#include "nsParserCIID.h"
#include "nsNetUtil.h"
#include "plstr.h"
#include "nsIContent.h"
#include "nsIDocument.h"
// nsProxyStream
// A helper class used for synchronous parsing of URLs.
@ -85,6 +87,12 @@ public:
nsXBLService();
virtual ~nsXBLService();
// This method checks the hashtable and then calls FetchBindingDocument on a miss.
NS_IMETHOD GetBindingDocument(nsCAutoString& aURLStr, nsIDocument** aResult);
// This method synchronously loads and parses an XBL file.
NS_IMETHOD FetchBindingDocument(nsIURI* aURI, nsIDocument** aResult);
protected:
// This URIkey class is used to hash URLs into an XBL binding
// cache.
@ -155,6 +163,13 @@ nsXBLService::~nsXBLService(void)
NS_IMETHODIMP
nsXBLService::LoadBindings(nsIContent* aContent, const nsString& aURL)
{
nsresult rv;
nsCAutoString url = aURL;
nsCOMPtr<nsIDocument> document;
if (NS_FAILED(rv = GetBindingDocument(url, getter_AddRefs(document)))) {
NS_ERROR("Failed loading an XBL document for content node.");
return rv;
}
return NS_OK;
}
@ -164,6 +179,50 @@ nsXBLService::LoadBindings(nsIContent* aContent, const nsString& aURL)
NS_IMETHODIMP
nsXBLService::GetContentList(nsIContent* aContent, nsISupportsArray** aResult)
{
// XXX Implement me!
return NS_OK;
}
// Internal helper methods ////////////////////////////////////////////////////////////////
NS_IMETHODIMP nsXBLService::GetBindingDocument(nsCAutoString& aURLStr, nsIDocument** aResult)
{
nsCOMPtr<nsIDocument> document;
if (aURLStr != nsCAutoString("")) {
nsCOMPtr<nsIURL> uri;
nsComponentManager::CreateInstance("component://netscape/network/standard-url",
nsnull,
NS_GET_IID(nsIURL),
getter_AddRefs(uri));
uri->SetSpec(aURLStr);
// XXX Obtain the # marker and remove it from the URL.
// We've got a file. Check our key binding file cache.
nsIURIKey key(uri);
document = dont_AddRef(NS_STATIC_CAST(nsIDocument*, mBindingTable->Get(&key)));
if (!document) {
FetchBindingDocument(uri, getter_AddRefs(document));
if (document) {
// Put the key binding doc into our table.
mBindingTable->Put(&key, document);
}
else return NS_ERROR_FAILURE;
}
}
*aResult = document;
NS_IF_ADDREF(*aResult);
return NS_OK;
}
NS_IMETHODIMP
nsXBLService::FetchBindingDocument(nsIURI* aURI, nsIDocument** aResult)
{
*aResult = nsnull;
return NS_OK;
}