Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/browser/GeckoDirectoryProvider.cpp
blob: f59d26a646c2fbd7505cdb9efa6d33f4f07014e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "GeckoDirectoryProvider.h"

#include <nsCOMPtr.h>
#include <nsIIOService.h>
#include <nsNetUtil.h>
#include <nsArrayEnumerator.h>
#include <nsILocalFile.h>
#include <nsDirectoryServiceDefs.h>
#include <nsIToolkitChromeRegistry.h>
#include <nsIDirectoryService.h>
#include <nsCOMArray.h>

#include <glib.h>

NS_IMPL_ISUPPORTS2 (GeckoDirectoryProvider,
                    nsIDirectoryServiceProvider,
                    nsIDirectoryServiceProvider2)

GeckoDirectoryProvider::GeckoDirectoryProvider(const char *sugar_path,
                                               const char *profile_path)
{
    mComponentPath = g_build_filename
            (sugar_path, "mozilla", "components", NULL);
    mCompregPath = g_build_filename
            (profile_path, "compreg.dat", NULL);
}

GeckoDirectoryProvider::~GeckoDirectoryProvider()
{
    if(mComponentPath)
        g_free(mComponentPath);
    if(mCompregPath)
        g_free(mCompregPath);
}

/* nsIFile getFile (in string prop, out PRBool persistent); */
NS_IMETHODIMP
GeckoDirectoryProvider::GetFile (const char *prop,
                                 PRBool *persistent,
                                 nsIFile **_retval)
{
    nsresult rv = NS_ERROR_FAILURE;
    nsCOMPtr<nsILocalFile> file;

    if (!strcmp(prop, NS_XPCOM_COMPONENT_REGISTRY_FILE)) {
        rv = NS_NewNativeLocalFile(nsDependentCString(mCompregPath),
                                   PR_TRUE,
                                   getter_AddRefs(file));
    }

    if (NS_SUCCEEDED(rv) && file) {
        NS_ADDREF(*_retval = file);
        return NS_OK;
    }

    return NS_ERROR_FAILURE;
}

/* nsISimpleEnumerator getFiles (in string aProperty); */
NS_IMETHODIMP
GeckoDirectoryProvider::GetFiles (const char *aProperty, nsISimpleEnumerator **aResult)
{
    nsresult rv = NS_ERROR_FAILURE;

    if (!strcmp(aProperty, NS_XPCOM_COMPONENT_DIR_LIST)) {
        if (mComponentPath) {
            nsCOMPtr<nsILocalFile> componentDir;
            rv = NS_NewNativeLocalFile(nsDependentCString(mComponentPath),
                                       PR_TRUE,
                                       getter_AddRefs(componentDir));
            NS_ENSURE_SUCCESS (rv, rv);

            nsCOMArray<nsIFile> array;

            rv = array.AppendObject (componentDir);
            NS_ENSURE_SUCCESS (rv, rv);

            rv = NS_NewArrayEnumerator (aResult, array);
            NS_ENSURE_SUCCESS (rv, rv);

            rv = NS_SUCCESS_AGGREGATE_RESULT;
        }
    }
    
    return rv;
}