зеркало из https://github.com/mozilla/gecko-dev.git
Bug 223310 use nsIObserver rather than nsIDOMWindowInternal in nsIKeygenThread.
r=jgmyers sr=darin
This commit is contained in:
Родитель
95479ffa2c
Коммит
f37a493b22
|
@ -48,8 +48,15 @@ function onLoad()
|
|||
}
|
||||
|
||||
setCursor("wait");
|
||||
|
||||
var obs = {
|
||||
observe : function keygenListenerObserve(subject, topic, data) {
|
||||
if (topic == "keygen-finished")
|
||||
window.close();
|
||||
}
|
||||
};
|
||||
|
||||
keygenThread.startKeyGeneration(window);
|
||||
keygenThread.startKeyGeneration(obs);
|
||||
}
|
||||
|
||||
function onClose()
|
||||
|
|
|
@ -52,5 +52,15 @@ interface nsIGeneratingKeypairInfoDialogs : nsISupports
|
|||
};
|
||||
|
||||
%{C++
|
||||
#define NS_GENERATINGKEYPAIRINFODIALOGS_CONTRACTID "@mozilla.org/nsGeneratingKeypairInfoDialogs;1"
|
||||
/**
|
||||
* This component is to be implemented by the embeddor. It is used to show
|
||||
* feedback to the user while a private key is being generated.
|
||||
*
|
||||
* This component is only ever used on the UI thread.
|
||||
*
|
||||
* INTERFACES THAT NEED TO BE IMPLEMENTED:
|
||||
* nsIGeneratingKeypairInfoDialogs
|
||||
*/
|
||||
#define NS_GENERATINGKEYPAIRINFODIALOGS_CONTRACTID \
|
||||
"@mozilla.org/nsGeneratingKeypairInfoDialogs;1"
|
||||
%}
|
||||
|
|
|
@ -38,25 +38,30 @@
|
|||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface nsIDOMWindowInternal;
|
||||
interface nsIObserver;
|
||||
|
||||
/**
|
||||
* nsIKeygenThread
|
||||
* This is used to communicate with the thread generating a key pair,
|
||||
* to be used by the dialog displaying status information.
|
||||
*/
|
||||
[scriptable, uuid(195763b8-1dd2-11b2-a843-eb44e44aaa37)]
|
||||
[scriptable, uuid(8712a243-5539-447c-9f47-8653f40c3a09)]
|
||||
interface nsIKeygenThread : nsISupports
|
||||
{
|
||||
/**
|
||||
* startKeyGeneration - run the thread
|
||||
* A user interface implementing this interface needs to
|
||||
* A user interface using this interface needs to
|
||||
* call this method as soon as the status information
|
||||
* is displaying. This will trigger key generation.
|
||||
* To allow the closure of the status information,
|
||||
* the thread needs a handle to the displayed window.
|
||||
* the thread needs a handle to an observer.
|
||||
*
|
||||
* observer will be called on the UI thread.
|
||||
* When the key generation is done, the observe method will
|
||||
* be called with a topic of "keygen-finished" and null data
|
||||
* and subject.
|
||||
*/
|
||||
void startKeyGeneration(in nsIDOMWindowInternal statusDialog);
|
||||
void startKeyGeneration(in nsIObserver observer);
|
||||
|
||||
/**
|
||||
* userCanceled - notify the thread
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
#include "nsCOMPtr.h"
|
||||
#include "nsProxiedService.h"
|
||||
#include "nsKeygenThread.h"
|
||||
#include "nsIDOMWindowInternal.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsNSSShutDown.h"
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(nsKeygenThread, nsIKeygenThread)
|
||||
|
@ -48,7 +48,6 @@ NS_IMPL_THREADSAFE_ISUPPORTS1(nsKeygenThread, nsIKeygenThread)
|
|||
|
||||
nsKeygenThread::nsKeygenThread()
|
||||
:mutex(nsnull),
|
||||
statusDialogPtr(nsnull),
|
||||
iAmRunning(PR_FALSE),
|
||||
keygenReady(PR_FALSE),
|
||||
statusDialogClosed(PR_FALSE),
|
||||
|
@ -71,10 +70,6 @@ nsKeygenThread::~nsKeygenThread()
|
|||
if (mutex) {
|
||||
PR_DestroyLock(mutex);
|
||||
}
|
||||
|
||||
if (statusDialogPtr) {
|
||||
NS_RELEASE(statusDialogPtr);
|
||||
}
|
||||
}
|
||||
|
||||
void nsKeygenThread::SetParams(
|
||||
|
@ -146,24 +141,24 @@ static void PR_CALLBACK nsKeygenThreadRunner(void *arg)
|
|||
self->Run();
|
||||
}
|
||||
|
||||
nsresult nsKeygenThread::StartKeyGeneration(nsIDOMWindowInternal *statusDialog)
|
||||
nsresult nsKeygenThread::StartKeyGeneration(nsIObserver* aObserver)
|
||||
{
|
||||
if (!mutex)
|
||||
return NS_OK;
|
||||
|
||||
if (!statusDialog )
|
||||
if (!aObserver)
|
||||
return NS_OK;
|
||||
|
||||
nsCOMPtr<nsIProxyObjectManager> proxyman(do_GetService(NS_XPCOMPROXY_CONTRACTID));
|
||||
if (!proxyman)
|
||||
return NS_OK;
|
||||
|
||||
nsCOMPtr<nsIDOMWindowInternal> wi;
|
||||
nsCOMPtr<nsIObserver> obs;
|
||||
proxyman->GetProxyForObject( NS_UI_THREAD_EVENTQ,
|
||||
nsIDOMWindowInternal::GetIID(),
|
||||
statusDialog,
|
||||
NS_GET_IID(nsIObserver),
|
||||
aObserver,
|
||||
PROXY_SYNC | PROXY_ALWAYS,
|
||||
getter_AddRefs(wi));
|
||||
getter_AddRefs(obs));
|
||||
|
||||
PR_Lock(mutex);
|
||||
|
||||
|
@ -172,9 +167,7 @@ nsresult nsKeygenThread::StartKeyGeneration(nsIDOMWindowInternal *statusDialog)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
statusDialogPtr = wi;
|
||||
NS_ADDREF(statusDialogPtr);
|
||||
wi = 0;
|
||||
observer.swap(obs);
|
||||
|
||||
iAmRunning = PR_TRUE;
|
||||
|
||||
|
@ -238,8 +231,7 @@ void nsKeygenThread::Run(void)
|
|||
// As long as key generation can't be canceled, we don't need
|
||||
// to care for cleaning this up.
|
||||
|
||||
nsIDOMWindowInternal *windowToClose = 0;
|
||||
|
||||
nsCOMPtr<nsIObserver> obs;
|
||||
PR_Lock(mutex);
|
||||
|
||||
keygenReady = PR_TRUE;
|
||||
|
@ -255,15 +247,14 @@ void nsKeygenThread::Run(void)
|
|||
wincx = 0;
|
||||
|
||||
if (!statusDialogClosed)
|
||||
windowToClose = statusDialogPtr;
|
||||
obs = observer;
|
||||
|
||||
statusDialogPtr = 0;
|
||||
statusDialogClosed = PR_TRUE;
|
||||
observer = nsnull;
|
||||
|
||||
PR_Unlock(mutex);
|
||||
|
||||
if (windowToClose)
|
||||
windowToClose->Close();
|
||||
if (obs)
|
||||
obs->Observe(nsnull, "keygen-finished", nsnull);
|
||||
}
|
||||
|
||||
void nsKeygenThread::Join()
|
||||
|
|
|
@ -43,13 +43,16 @@
|
|||
#include "nspr.h"
|
||||
|
||||
#include "nsIKeygenThread.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
class nsIObserver;
|
||||
|
||||
class nsKeygenThread : public nsIKeygenThread
|
||||
{
|
||||
private:
|
||||
PRLock *mutex;
|
||||
|
||||
nsIDOMWindowInternal* statusDialogPtr;
|
||||
nsCOMPtr<nsIObserver> observer;
|
||||
|
||||
PRBool iAmRunning;
|
||||
PRBool keygenReady;
|
||||
|
|
|
@ -154,7 +154,6 @@ interface nsIDownload : nsITransfer {
|
|||
* be stored, but which is not equal to the target file.
|
||||
*
|
||||
* INTERFACES THAT NEED TO BE IMPLEMENTED:
|
||||
* nsISupports
|
||||
* nsITransfer
|
||||
* nsIDownload
|
||||
* nsIWebProgressListener
|
||||
|
|
Загрузка…
Ссылка в новой задаче