more stubbing out of dynamic overlays r=pavlov

This commit is contained in:
hyatt%netscape.com 1999-10-26 10:03:13 +00:00
parent 01e6506fdf
commit edef87131c
5 changed files with 243 additions and 31 deletions

View File

@ -22,13 +22,13 @@
#include "nsISupports.idl"
#include "nsIURL.idl"
#include "nsIEnumerator.idl"
[scriptable, uuid(D8C7D8A1-E84C-11d2-BF87-00105A1B0627)]
interface nsIChromeRegistry : nsISupports
{
void convertChromeURL(in nsIURI aChromeURL);
long getOverlayCount(in nsIURI aChromeURL);
nsIURI getOverlayAt(in nsIURI aChromeURL, in long aIndex);
nsISimpleEnumerator getOverlays(in nsIURI aChromeURL);
};

View File

@ -33,6 +33,7 @@
#include "nsHashtable.h"
#include "nsString.h"
#include "nsXPIDLString.h"
#include "nsISimpleEnumerator.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
@ -60,6 +61,41 @@ DEFINE_RDF_VOCAB(CHROME_NAMESPACE_URI, CHROME, name);
void BreakProviderAndRemainingFromPath(const char* i_path, char** o_provider, char** o_remaining);
////////////////////////////////////////////////////////////////////////////////
class nsOverlayEnumerator : public nsISimpleEnumerator
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSISIMPLEENUMERATOR
nsOverlayEnumerator(nsISimpleEnumerator *aArcs);
virtual ~nsOverlayEnumerator();
private:
nsCOMPtr<nsISimpleEnumerator> mArcs;
};
NS_IMPL_ISUPPORTS1(nsOverlayEnumerator, nsISimpleEnumerator)
nsOverlayEnumerator::nsOverlayEnumerator(nsISimpleEnumerator *aArcs)
{
NS_INIT_REFCNT();
mArcs = aArcs;
}
nsOverlayEnumerator::~nsOverlayEnumerator()
{
}
NS_IMETHODIMP nsOverlayEnumerator::HasMoreElements(PRBool *aIsTrue)
{
return NS_OK;
}
NS_IMETHODIMP nsOverlayEnumerator::GetNext(nsISupports **aResult)
{
return NS_OK;
}
class nsChromeRegistry : public nsIChromeRegistry
{
@ -352,21 +388,93 @@ nsChromeRegistry::ConvertChromeURL(nsIURI* aChromeURL)
return NS_OK;
}
NS_IMETHODIMP nsChromeRegistry::GetOverlayCount(nsIURI *aChromeURL, PRInt32 *aResult)
NS_IMETHODIMP nsChromeRegistry::GetOverlays(nsIURI *aChromeURL, nsISimpleEnumerator **aResult)
{
*aResult = nsnull;
nsresult rv;
if (!mDataSourceTable)
{
*aResult = 0;
return NS_OK;
// Obtain the package, provider and remaining from the URL
nsXPIDLCString package, provider, remaining;
#if 0 // This change happens when we switch to using chrome://skin@global/foo..
rv = aChromeURL->GetHost(getter_Copies(package));
if (NS_FAILED(rv)) return rv;
rv = aChromeURL->GetPreHost(getter_Copies(provider));
if (NS_FAILED(rv)) return rv;
rv = aChromeURL->GetPath(getter_Copies(remaining));
if (NS_FAILED(rv)) return rv;
#else // For now however...
rv = aChromeURL->GetHost(getter_Copies(package));
if (NS_FAILED(rv)) return rv;
nsXPIDLCString tempPath;
rv = aChromeURL->GetPath(getter_Copies(tempPath));
if (NS_FAILED(rv)) return rv;
BreakProviderAndRemainingFromPath(
(const char*)tempPath,
getter_Copies(provider),
getter_Copies(remaining));
#endif
// Construct the lookup string-
// which is basically chrome:// + package + provider
nsAutoString lookup("chrome://");
lookup += package; // no trailing slash here
NS_ASSERTION(*provider == '/', "No leading slash here!");
//definitely have a leading slash...
if (*provider != '/')
lookup += '/';
lookup += provider;
// end it on a slash if none is present
if (lookup.CharAt(lookup.Length()-1) != '/')
lookup += '/';
// Get the chromeResource from this lookup string
nsCOMPtr<nsIRDFResource> chromeResource;
if (NS_FAILED(rv = GetPackageTypeResource(lookup, getter_AddRefs(chromeResource)))) {
NS_ERROR("Unable to retrieve the resource corresponding to the chrome skin or content.");
return rv;
}
return NS_OK;
}
nsCAutoString overlayFile;
// Retrieve the mInner data source.
overlayFile = "resource:/chrome/";
overlayFile += package;
overlayFile += provider; // provider already has a / in the front of it
overlayFile += "/";
overlayFile += "overlays.rdf";
void *data = mDataSourceTable->Get(&nsStringKey(overlayFile));
if (data)
{
nsCOMPtr<nsIRDFDataSource> dataSource;
nsISupports *supports = NS_STATIC_CAST(nsISupports*, data);
dataSource = do_QueryInterface(supports);
if (dataSource)
{
nsCOMPtr<nsISimpleEnumerator> arcs;
dataSource->ArcLabelsOut(chromeResource, getter_AddRefs(arcs));
*aResult = new nsOverlayEnumerator(arcs);
NS_ADDREF(*aResult);
}
}
NS_IMETHODIMP nsChromeRegistry::GetOverlayAt(nsIURI *aChromeURL, PRInt32 aIndex, nsIURI **aResult)
{
if (!mDataSourceTable)
return NS_OK;
return NS_OK;
}

View File

@ -8,6 +8,7 @@
#include "nsISupports.h"
#include "nsIURI.h"
#include "nsrootidl.h"
#include "nsIEnumerator.h"
#include "nsIURL.h"
/* starting interface: nsIChromeRegistry */
@ -25,24 +26,19 @@ class nsIChromeRegistry : public nsISupports {
/* void convertChromeURL (in nsIURI aChromeURL); */
NS_IMETHOD ConvertChromeURL(nsIURI *aChromeURL) = 0;
/* long getOverlayCount (in nsIURI aChromeURL); */
NS_IMETHOD GetOverlayCount(nsIURI *aChromeURL, PRInt32 *_retval) = 0;
/* nsIURI getOverlayAt (in nsIURI aChromeURL, in long aIndex); */
NS_IMETHOD GetOverlayAt(nsIURI *aChromeURL, PRInt32 aIndex, nsIURI **_retval) = 0;
/* nsISimpleEnumerator getOverlays (in nsIURI aChromeURL); */
NS_IMETHOD GetOverlays(nsIURI *aChromeURL, nsISimpleEnumerator **_retval) = 0;
};
/* Use this macro when declaring classes that implement this interface. */
#define NS_DECL_NSICHROMEREGISTRY \
NS_IMETHOD ConvertChromeURL(nsIURI *aChromeURL); \
NS_IMETHOD GetOverlayCount(nsIURI *aChromeURL, PRInt32 *_retval); \
NS_IMETHOD GetOverlayAt(nsIURI *aChromeURL, PRInt32 aIndex, nsIURI **_retval);
NS_IMETHOD GetOverlays(nsIURI *aChromeURL, nsISimpleEnumerator **_retval);
/* Use this macro to declare functions that forward the behavior of this interface to another object. */
#define NS_FORWARD_NSICHROMEREGISTRY(_to) \
NS_IMETHOD ConvertChromeURL(nsIURI *aChromeURL) { return _to ## ConvertChromeURL(aChromeURL); } \
NS_IMETHOD GetOverlayCount(nsIURI *aChromeURL, PRInt32 *_retval) { return _to ## GetOverlayCount(aChromeURL, _retval); } \
NS_IMETHOD GetOverlayAt(nsIURI *aChromeURL, PRInt32 aIndex, nsIURI **_retval) { return _to ## GetOverlayAt(aChromeURL, aIndex, _retval); }
NS_IMETHOD GetOverlays(nsIURI *aChromeURL, nsISimpleEnumerator **_retval) { return _to ## GetOverlays(aChromeURL, _retval); }
// for component registration
// {D8C7D8A2-E84C-11d2-BF87-00105A1B0627}

View File

@ -22,13 +22,13 @@
#include "nsISupports.idl"
#include "nsIURL.idl"
#include "nsIEnumerator.idl"
[scriptable, uuid(D8C7D8A1-E84C-11d2-BF87-00105A1B0627)]
interface nsIChromeRegistry : nsISupports
{
void convertChromeURL(in nsIURI aChromeURL);
long getOverlayCount(in nsIURI aChromeURL);
nsIURI getOverlayAt(in nsIURI aChromeURL, in long aIndex);
nsISimpleEnumerator getOverlays(in nsIURI aChromeURL);
};

View File

@ -33,6 +33,7 @@
#include "nsHashtable.h"
#include "nsString.h"
#include "nsXPIDLString.h"
#include "nsISimpleEnumerator.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
@ -60,6 +61,41 @@ DEFINE_RDF_VOCAB(CHROME_NAMESPACE_URI, CHROME, name);
void BreakProviderAndRemainingFromPath(const char* i_path, char** o_provider, char** o_remaining);
////////////////////////////////////////////////////////////////////////////////
class nsOverlayEnumerator : public nsISimpleEnumerator
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSISIMPLEENUMERATOR
nsOverlayEnumerator(nsISimpleEnumerator *aArcs);
virtual ~nsOverlayEnumerator();
private:
nsCOMPtr<nsISimpleEnumerator> mArcs;
};
NS_IMPL_ISUPPORTS1(nsOverlayEnumerator, nsISimpleEnumerator)
nsOverlayEnumerator::nsOverlayEnumerator(nsISimpleEnumerator *aArcs)
{
NS_INIT_REFCNT();
mArcs = aArcs;
}
nsOverlayEnumerator::~nsOverlayEnumerator()
{
}
NS_IMETHODIMP nsOverlayEnumerator::HasMoreElements(PRBool *aIsTrue)
{
return NS_OK;
}
NS_IMETHODIMP nsOverlayEnumerator::GetNext(nsISupports **aResult)
{
return NS_OK;
}
class nsChromeRegistry : public nsIChromeRegistry
{
@ -352,21 +388,93 @@ nsChromeRegistry::ConvertChromeURL(nsIURI* aChromeURL)
return NS_OK;
}
NS_IMETHODIMP nsChromeRegistry::GetOverlayCount(nsIURI *aChromeURL, PRInt32 *aResult)
NS_IMETHODIMP nsChromeRegistry::GetOverlays(nsIURI *aChromeURL, nsISimpleEnumerator **aResult)
{
*aResult = nsnull;
nsresult rv;
if (!mDataSourceTable)
{
*aResult = 0;
return NS_OK;
// Obtain the package, provider and remaining from the URL
nsXPIDLCString package, provider, remaining;
#if 0 // This change happens when we switch to using chrome://skin@global/foo..
rv = aChromeURL->GetHost(getter_Copies(package));
if (NS_FAILED(rv)) return rv;
rv = aChromeURL->GetPreHost(getter_Copies(provider));
if (NS_FAILED(rv)) return rv;
rv = aChromeURL->GetPath(getter_Copies(remaining));
if (NS_FAILED(rv)) return rv;
#else // For now however...
rv = aChromeURL->GetHost(getter_Copies(package));
if (NS_FAILED(rv)) return rv;
nsXPIDLCString tempPath;
rv = aChromeURL->GetPath(getter_Copies(tempPath));
if (NS_FAILED(rv)) return rv;
BreakProviderAndRemainingFromPath(
(const char*)tempPath,
getter_Copies(provider),
getter_Copies(remaining));
#endif
// Construct the lookup string-
// which is basically chrome:// + package + provider
nsAutoString lookup("chrome://");
lookup += package; // no trailing slash here
NS_ASSERTION(*provider == '/', "No leading slash here!");
//definitely have a leading slash...
if (*provider != '/')
lookup += '/';
lookup += provider;
// end it on a slash if none is present
if (lookup.CharAt(lookup.Length()-1) != '/')
lookup += '/';
// Get the chromeResource from this lookup string
nsCOMPtr<nsIRDFResource> chromeResource;
if (NS_FAILED(rv = GetPackageTypeResource(lookup, getter_AddRefs(chromeResource)))) {
NS_ERROR("Unable to retrieve the resource corresponding to the chrome skin or content.");
return rv;
}
return NS_OK;
}
nsCAutoString overlayFile;
// Retrieve the mInner data source.
overlayFile = "resource:/chrome/";
overlayFile += package;
overlayFile += provider; // provider already has a / in the front of it
overlayFile += "/";
overlayFile += "overlays.rdf";
void *data = mDataSourceTable->Get(&nsStringKey(overlayFile));
if (data)
{
nsCOMPtr<nsIRDFDataSource> dataSource;
nsISupports *supports = NS_STATIC_CAST(nsISupports*, data);
dataSource = do_QueryInterface(supports);
if (dataSource)
{
nsCOMPtr<nsISimpleEnumerator> arcs;
dataSource->ArcLabelsOut(chromeResource, getter_AddRefs(arcs));
*aResult = new nsOverlayEnumerator(arcs);
NS_ADDREF(*aResult);
}
}
NS_IMETHODIMP nsChromeRegistry::GetOverlayAt(nsIURI *aChromeURL, PRInt32 aIndex, nsIURI **aResult)
{
if (!mDataSourceTable)
return NS_OK;
return NS_OK;
}