mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 409280, nsIProtectedAuthThread is not embedding friendly Patch contributed by Christian Persch (GNOME) r=kengert, blocking1.9=mtschrep
This commit is contained in:
parent
742d0427ff
commit
8b4324d92b
@ -53,7 +53,14 @@ function onLoad()
|
|||||||
|
|
||||||
setCursor("wait");
|
setCursor("wait");
|
||||||
|
|
||||||
protectedAuthThread.login(window);
|
var obs = {
|
||||||
|
observe : function protectedAuthListenerObserve(subject, topic, data) {
|
||||||
|
if (topic == "operation-completed")
|
||||||
|
window.close();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
protectedAuthThread.login(obs);
|
||||||
|
|
||||||
} catch (exception)
|
} catch (exception)
|
||||||
{
|
{
|
||||||
|
@ -35,14 +35,15 @@
|
|||||||
* ***** END LICENSE BLOCK ***** */
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
#include "nsISupports.idl"
|
#include "nsISupports.idl"
|
||||||
#include "nsIDOMWindowInternal.idl"
|
#include "nsIObserver.idl"
|
||||||
|
#include "nsIPKCS11Slot.idl"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* nsIProtectedAuthThread
|
* nsIProtectedAuthThread
|
||||||
* This is used to communicate with the thread login on to
|
* This is used to communicate with the thread login on to
|
||||||
* a token with CKF_PROTECTED_AUTHENTICATION_PATH set.
|
* a token with CKF_PROTECTED_AUTHENTICATION_PATH set.
|
||||||
*/
|
*/
|
||||||
[scriptable, uuid(45334489-3d30-47c6-920b-0a55a313aebf)]
|
[scriptable, uuid(4bb27cb7-8984-4cee-8ce7-9b014c3d091b)]
|
||||||
interface nsIProtectedAuthThread : nsISupports
|
interface nsIProtectedAuthThread : nsISupports
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@ -51,13 +52,22 @@ interface nsIProtectedAuthThread : nsISupports
|
|||||||
* call this method as soon as the message to the user is
|
* call this method as soon as the message to the user is
|
||||||
* displayed. This will trigger login operation. No user
|
* displayed. This will trigger login operation. No user
|
||||||
* cancellation is possible during login operation.
|
* cancellation is possible during login operation.
|
||||||
|
*
|
||||||
|
* When the login is done, the observe method of @observer will
|
||||||
|
* be called on the UI thread with a topic of "login-finished"
|
||||||
|
* and null data and subject.
|
||||||
*/
|
*/
|
||||||
void login(in nsIDOMWindowInternal dialog);
|
void login(in nsIObserver observer);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The PKCS11 slot
|
||||||
|
*/
|
||||||
|
readonly attribute nsIPKCS11Slot slot;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets token to be logged in name.
|
* Gets token to be logged in name.
|
||||||
*/
|
*/
|
||||||
wstring getTokenName();
|
AString getTokenName();
|
||||||
};
|
};
|
||||||
|
|
||||||
%{ C++
|
%{ C++
|
||||||
|
@ -36,9 +36,11 @@
|
|||||||
|
|
||||||
#include "pk11func.h"
|
#include "pk11func.h"
|
||||||
#include "nsCOMPtr.h"
|
#include "nsCOMPtr.h"
|
||||||
|
#include "nsAutoPtr.h"
|
||||||
#include "nsProxiedService.h"
|
#include "nsProxiedService.h"
|
||||||
#include "nsString.h"
|
#include "nsString.h"
|
||||||
#include "nsReadableUtils.h"
|
#include "nsReadableUtils.h"
|
||||||
|
#include "nsPKCS11Slot.h"
|
||||||
#include "nsProtectedAuthThread.h"
|
#include "nsProtectedAuthThread.h"
|
||||||
|
|
||||||
NS_IMPL_THREADSAFE_ISUPPORTS1(nsProtectedAuthThread, nsIProtectedAuthThread)
|
NS_IMPL_THREADSAFE_ISUPPORTS1(nsProtectedAuthThread, nsIProtectedAuthThread)
|
||||||
@ -51,9 +53,8 @@ static void PR_CALLBACK nsProtectedAuthThreadRunner(void *arg)
|
|||||||
|
|
||||||
nsProtectedAuthThread::nsProtectedAuthThread()
|
nsProtectedAuthThread::nsProtectedAuthThread()
|
||||||
: mMutex(nsnull)
|
: mMutex(nsnull)
|
||||||
, mStatusDialogPtr(nsnull)
|
|
||||||
, mIAmRunning(PR_FALSE)
|
, mIAmRunning(PR_FALSE)
|
||||||
, mStatusDialogClosed(PR_FALSE)
|
, mStatusObserverNotified(PR_FALSE)
|
||||||
, mLoginReady(PR_FALSE)
|
, mLoginReady(PR_FALSE)
|
||||||
, mThreadHandle(nsnull)
|
, mThreadHandle(nsnull)
|
||||||
, mSlot(0)
|
, mSlot(0)
|
||||||
@ -67,31 +68,27 @@ nsProtectedAuthThread::~nsProtectedAuthThread()
|
|||||||
{
|
{
|
||||||
if (mMutex)
|
if (mMutex)
|
||||||
PR_DestroyLock(mMutex);
|
PR_DestroyLock(mMutex);
|
||||||
|
|
||||||
if (mStatusDialogPtr)
|
|
||||||
{
|
|
||||||
NS_RELEASE(mStatusDialogPtr);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsProtectedAuthThread::Login(nsIDOMWindowInternal *statusDialog)
|
NS_IMETHODIMP nsProtectedAuthThread::Login(nsIObserver *aObserver)
|
||||||
{
|
{
|
||||||
if (!mMutex)
|
NS_ENSURE_ARG(aObserver);
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
if (!statusDialog )
|
if (!mMutex)
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
|
|
||||||
if (!mSlot)
|
if (!mSlot)
|
||||||
// We need pointer to the slot
|
// We need pointer to the slot
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMWindowInternal> wi;
|
nsCOMPtr<nsIObserver> observerProxy;
|
||||||
NS_GetProxyForObject( NS_PROXY_TO_MAIN_THREAD,
|
nsresult rv = NS_GetProxyForObject(NS_PROXY_TO_MAIN_THREAD,
|
||||||
nsIDOMWindowInternal::GetIID(),
|
NS_GET_IID(nsIObserver),
|
||||||
statusDialog,
|
aObserver,
|
||||||
NS_PROXY_SYNC | NS_PROXY_ALWAYS,
|
NS_PROXY_SYNC | NS_PROXY_ALWAYS,
|
||||||
getter_AddRefs(wi));
|
getter_AddRefs(observerProxy));
|
||||||
|
if (NS_FAILED(rv))
|
||||||
|
return rv;
|
||||||
|
|
||||||
PR_Lock(mMutex);
|
PR_Lock(mMutex);
|
||||||
|
|
||||||
@ -100,10 +97,7 @@ NS_IMETHODIMP nsProtectedAuthThread::Login(nsIDOMWindowInternal *statusDialog)
|
|||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
mStatusDialogPtr = wi;
|
observerProxy.swap(mStatusObserver);
|
||||||
NS_ADDREF(mStatusDialogPtr);
|
|
||||||
wi = 0;
|
|
||||||
|
|
||||||
mIAmRunning = PR_TRUE;
|
mIAmRunning = PR_TRUE;
|
||||||
|
|
||||||
mThreadHandle = PR_CreateThread(PR_USER_THREAD, nsProtectedAuthThreadRunner, static_cast<void*>(this),
|
mThreadHandle = PR_CreateThread(PR_USER_THREAD, nsProtectedAuthThreadRunner, static_cast<void*>(this),
|
||||||
@ -118,18 +112,31 @@ NS_IMETHODIMP nsProtectedAuthThread::Login(nsIDOMWindowInternal *statusDialog)
|
|||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsProtectedAuthThread::GetTokenName(PRUnichar **_retval)
|
NS_IMETHODIMP nsProtectedAuthThread::GetTokenName(nsAString &_retval)
|
||||||
{
|
{
|
||||||
PR_Lock(mMutex);
|
PR_Lock(mMutex);
|
||||||
|
|
||||||
// Get token name
|
// Get token name
|
||||||
*_retval = UTF8ToNewUnicode(nsDependentCString(PK11_GetTokenName(mSlot)));
|
CopyUTF8toUTF16(nsDependentCString(PK11_GetTokenName(mSlot)), _retval);
|
||||||
|
|
||||||
PR_Unlock(mMutex);
|
PR_Unlock(mMutex);
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP nsProtectedAuthThread::GetSlot(nsIPKCS11Slot **_retval)
|
||||||
|
{
|
||||||
|
PR_Lock(mMutex);
|
||||||
|
|
||||||
|
nsRefPtr<nsPKCS11Slot> slot = new nsPKCS11Slot(mSlot);
|
||||||
|
|
||||||
|
PR_Unlock(mMutex);
|
||||||
|
|
||||||
|
if (!slot)
|
||||||
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
|
||||||
|
return CallQueryInterface (slot.get(), _retval);
|
||||||
|
}
|
||||||
|
|
||||||
void nsProtectedAuthThread::SetParams(PK11SlotInfo* aSlot)
|
void nsProtectedAuthThread::SetParams(PK11SlotInfo* aSlot)
|
||||||
{
|
{
|
||||||
@ -151,7 +158,7 @@ void nsProtectedAuthThread::Run(void)
|
|||||||
// it is harmless here
|
// it is harmless here
|
||||||
mLoginResult = PK11_CheckUserPassword(mSlot, 0);
|
mLoginResult = PK11_CheckUserPassword(mSlot, 0);
|
||||||
|
|
||||||
nsIDOMWindowInternal *windowToClose = 0;
|
nsIObserver *observer = nsnull;
|
||||||
|
|
||||||
PR_Lock(mMutex);
|
PR_Lock(mMutex);
|
||||||
|
|
||||||
@ -165,18 +172,18 @@ void nsProtectedAuthThread::Run(void)
|
|||||||
mSlot = 0;
|
mSlot = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mStatusDialogClosed)
|
if (!mStatusObserverNotified)
|
||||||
{
|
{
|
||||||
windowToClose = mStatusDialogPtr;
|
observer = mStatusObserver;
|
||||||
}
|
}
|
||||||
|
|
||||||
mStatusDialogPtr = 0;
|
mStatusObserver = nsnull;
|
||||||
mStatusDialogClosed = PR_TRUE;
|
mStatusObserverNotified = PR_TRUE;
|
||||||
|
|
||||||
PR_Unlock(mMutex);
|
PR_Unlock(mMutex);
|
||||||
|
|
||||||
if (windowToClose)
|
if (observer)
|
||||||
windowToClose->Close();
|
observer->Observe(nsnull, "operation-completed", nsnull);
|
||||||
}
|
}
|
||||||
|
|
||||||
void nsProtectedAuthThread::Join()
|
void nsProtectedAuthThread::Join()
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
#ifndef NSPROTECTEDAUTHTHREAD_H_
|
#ifndef NSPROTECTEDAUTHTHREAD_H_
|
||||||
#define NSPROTECTEDAUTHTHREAD_H_
|
#define NSPROTECTEDAUTHTHREAD_H_
|
||||||
|
|
||||||
|
#include <nsCOMPtr.h>
|
||||||
#include "keyhi.h"
|
#include "keyhi.h"
|
||||||
#include "nspr.h"
|
#include "nspr.h"
|
||||||
|
|
||||||
@ -47,10 +48,10 @@ class nsProtectedAuthThread : public nsIProtectedAuthThread
|
|||||||
private:
|
private:
|
||||||
PRLock *mMutex;
|
PRLock *mMutex;
|
||||||
|
|
||||||
nsIDOMWindowInternal* mStatusDialogPtr;
|
nsCOMPtr<nsIObserver> mStatusObserver;
|
||||||
|
|
||||||
PRBool mIAmRunning;
|
PRBool mIAmRunning;
|
||||||
PRBool mStatusDialogClosed;
|
PRBool mStatusObserverNotified;
|
||||||
PRBool mLoginReady;
|
PRBool mLoginReady;
|
||||||
|
|
||||||
PRThread *mThreadHandle;
|
PRThread *mThreadHandle;
|
||||||
|
Loading…
Reference in New Issue
Block a user