EmbedPromptRegister.cpp 3.13 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "EmbedPromptRegister.h"

#include "nsServiceManagerUtils.h"
#include "nsIObserverService.h"
#include "EmbedPromptService.h"
#include "nsIComponentRegistrar.h"
#include "nsIComponentManager.h"
#include "mozilla/ModuleUtils.h"
15
#include "../widgetfactory/EmbedliteGenericFactory.h"
16 17 18 19
#include "nsComponentManagerUtils.h"

#include "nsILoginManager.h"
#include "nsIFormHistory.h"
20
#include "nsWidgetsCID.h"
21
#include "nsAlertsService.h"
22 23 24 25

using namespace mozilla::embedlite;

NS_GENERIC_FACTORY_CONSTRUCTOR(EmbedPromptFactory)
26
NS_GENERIC_FACTORY_CONSTRUCTOR(nsEmbedAlertsService)
27 28 29 30 31 32 33 34 35

EmbedPromptRegister::EmbedPromptRegister()
{
}

EmbedPromptRegister::~EmbedPromptRegister()
{
}

36
NS_IMPL_ISUPPORTS(EmbedPromptRegister, nsIObserver, nsISupportsWeakReference)
37 38 39 40 41 42 43 44 45 46 47 48

nsresult
EmbedPromptRegister::Init()
{
    nsCOMPtr<nsIComponentRegistrar> cr;
    nsresult rv = NS_GetComponentRegistrar(getter_AddRefs(cr));
    NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);

    nsCOMPtr<nsIComponentManager> cm;
    rv = NS_GetComponentManager (getter_AddRefs (cm));
    NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);

49
    nsCOMPtr<nsIFactory> f = new mozilla::embedlite::EmbedliteGenericFactory(EmbedPromptFactoryConstructor);
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
    if (!f) {
        NS_WARNING("Unable to create factory for component");
        return NS_ERROR_FAILURE;
    }

    nsCOMPtr<nsIFactory> oldFactory = do_GetClassObject("@mozilla.org/prompter;1");
    if (oldFactory) {
        nsCID* cid = NULL;
        rv = cr->ContractIDToCID("@mozilla.org/prompter;1", &cid);
        if (!NS_FAILED(rv)) {
            rv = cr->UnregisterFactory(*cid, oldFactory.get());
            NS_Free(cid);
            if (NS_FAILED(rv)) {
                return NS_ERROR_FAILURE;
            }
        }
    }

    nsCID promptCID = EMBED_LITE_PROMPT_SERVICE_CID;
    rv = cr->RegisterFactory(promptCID, "EmbedLite Prompt",
                             "@mozilla.org/prompter;1", f);

72
    f = new mozilla::embedlite::EmbedliteGenericFactory(nsEmbedAlertsServiceConstructor);
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
    if (!f) {
        NS_WARNING("Unable to create factory for component");
        return NS_ERROR_FAILURE;
    }
    oldFactory = do_GetClassObject("@mozilla.org/alerts-service;1");
    if (oldFactory) {
        nsCID* cid = NULL;
        rv = cr->ContractIDToCID("@mozilla.org/alerts-service;1", &cid);
        if (!NS_FAILED(rv)) {
            rv = cr->UnregisterFactory(*cid, oldFactory.get());
            NS_Free(cid);
            if (NS_FAILED(rv)) {
                return NS_ERROR_FAILURE;
            }
        }
    }

    nsCID alertsCID = NS_EMBED_ALERTS_SERVICE_CID;
Tatiana Meshkova's avatar
Tatiana Meshkova committed
91
    rv = cr->RegisterFactory(alertsCID, "EmbedLite Alerts Service",
92
                             "@mozilla.org/alerts-service;1", f);
93 94 95 96 97 98 99

    return NS_OK;
}

NS_IMETHODIMP
EmbedPromptRegister::Observe(nsISupports *aSubject,
                            const char *aTopic,
100
                            const char16_t *aData)
101 102 103
{
    return NS_OK;
}