EmbedPromptService.h 4.31 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/* -*- 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/. */

#ifndef __EmbedPromptService_h
#define __EmbedPromptService_h

#include "nsIPrompt.h"
#include "nsIPromptFactory.h"
#include "nsIAuthPrompt2.h"
#include "mozilla/RefPtr.h"
#include "nsIDOMWindow.h"
#include "nsCOMPtr.h"
#include "nsStringGlue.h"
#include "nsICancelable.h"
#include "nsIAuthInformation.h"
#include "nsDataHashtable.h"
#include "nsIEmbedAppService.h"
#include "nsIChannel.h"
21 22
#include "nsWeakReference.h"
#include "nsIObserver.h"
23 24 25
#include <map>
#include <string>

26 27
class nsIObserverService;

28 29 30 31 32 33 34
namespace mozilla {
namespace embedlite {

class EmbedPromptResponse
{
public:
    EmbedPromptResponse()
35 36 37
      : accepted(false),
        checkvalue(false),
        dontsave(false)
38 39 40 41 42
    {}
    virtual ~EmbedPromptResponse() {}

    bool accepted;
    bool checkvalue;
43
    bool dontsave;
44 45 46 47 48
    nsString promptvalue;
    nsString username;
    nsString password;
};

49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
class IDestroyNotification
{
public:
    virtual void OnDestroyNotification() = 0;
};

class EmbedPromptOuterObserver : public nsIObserver, public nsSupportsWeakReference
{
public:
    EmbedPromptOuterObserver(IDestroyNotification* aNotifier, nsIDOMWindow* aWin);

    NS_DECL_ISUPPORTS
    NS_DECL_NSIOBSERVER
    void OnDestroy();
private:
64
    virtual ~EmbedPromptOuterObserver();
65 66 67 68 69 70
    IDestroyNotification* mNotifier;
    nsCOMPtr<nsIDOMWindow> mWin;
    nsCOMPtr<nsIObserverService> mService;
};

class EmbedPromptService : public nsIPrompt, public nsIEmbedMessageListener, public IDestroyNotification
71 72 73 74 75 76 77
{
public:
    EmbedPromptService(nsIDOMWindow* aWin);

    NS_DECL_ISUPPORTS
    NS_DECL_NSIPROMPT
    NS_DECL_NSIEMBEDMESSAGELISTENER
78 79 80

    virtual void OnDestroyNotification();

81
private:
82
    virtual ~EmbedPromptService();
83 84 85
    void CancelResponse();
    uint32_t CheckWinID();

86 87 88 89
    nsCOMPtr<nsIDOMWindow> mWin;
    int mModalDepth;
    nsCOMPtr<nsIEmbedAppService> mService;
    std::map<uint32_t, EmbedPromptResponse> mResponseMap;
90
    RefPtr<EmbedPromptOuterObserver> mOuterService;
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
};

class EmbedAuthPromptService;
class EmbedAsyncAuthPrompt
{
public:
    EmbedAsyncAuthPrompt(nsICancelable* aCancelable, nsIChannel* aChannel,
                         nsIAuthInformation* aAuthInfo, uint32_t aLevel,
                         bool aInProgress)
        : mChannel(aChannel)
        , mAuthInfo(aAuthInfo)
        , mLevel(aLevel)
        , mInProgress(aInProgress)
        , mService(NULL)
    {
        consumers.AppendElement(aCancelable);
    }

109
    nsTArray<nsRefPtr<nsICancelable>> consumers;
110 111 112 113 114 115 116
    nsIDOMWindow* mWin;
    nsCOMPtr<nsIChannel> mChannel;
    nsCOMPtr<nsIAuthInformation> mAuthInfo;
    uint32_t mLevel;
    bool mInProgress;
    nsCString mHashKey;
    RefPtr<EmbedAuthPromptService> mService;
117
    virtual ~EmbedAsyncAuthPrompt() {}
118 119
};

120
class EmbedAuthPromptService : public nsIAuthPrompt2, public nsIEmbedMessageListener, public IDestroyNotification
121 122 123 124 125 126 127 128 129 130 131 132 133 134
{
public:
    EmbedAuthPromptService(nsIDOMWindow* aWin);

    NS_DECL_ISUPPORTS
    NS_DECL_NSIAUTHPROMPT2
    NS_DECL_NSIEMBEDMESSAGELISTENER

    nsresult DoSendAsyncPrompt(EmbedAsyncAuthPrompt* mPrompt);

    void DoResponseAsyncPrompt(EmbedAsyncAuthPrompt* aPrompt,
                               const bool& confirmed,
                               const nsString& username,
                               const nsString& password);
135
    virtual void OnDestroyNotification();
136 137

private:
138
    virtual ~EmbedAuthPromptService();
139
    void DoAsyncPrompt();
140 141
    void CancelResponse();
    uint32_t CheckWinID();
142 143 144 145 146 147 148

    nsCOMPtr<nsIDOMWindow> mWin;
    std::map<std::string, EmbedAsyncAuthPrompt*> asyncPrompts;
    std::map<void*, bool> asyncPromptInProgress;
    nsCOMPtr<nsIEmbedAppService> mService;
    int mModalDepth;
    std::map<uint32_t, EmbedPromptResponse> mResponseMap;
149
    RefPtr<EmbedPromptOuterObserver> mOuterService;
150 151
};

152
class EmbedPromptFactory : public nsIPromptFactory
153 154 155 156 157 158
{
public:
    EmbedPromptFactory();

    NS_DECL_ISUPPORTS
    NS_DECL_NSIPROMPTFACTORY
159 160
private:
    virtual ~EmbedPromptFactory();
161 162 163 164 165 166 167 168
};

}}

#define EMBED_LITE_PROMPT_SERVICE_CID \
 {0x6781a4b0, 0x6cfa, 0x11e2, {0x8c, 0x9c, 0x33, 0x95, 0x8b, 0xdf, 0x7a, 0xb6}}

#endif /* __EmbedPromptService_h */