mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 995385 - Ensure that NSS is initialzed for CryptoTasks. r=dkeeler
This commit is contained in:
parent
84b4f71b33
commit
7b6d82be69
@ -5,6 +5,7 @@
|
|||||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
#include "CryptoTask.h"
|
#include "CryptoTask.h"
|
||||||
|
#include "nsNSSComponent.h"
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
|
|
||||||
@ -18,6 +19,29 @@ CryptoTask::~CryptoTask()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
CryptoTask::Dispatch(const nsACString& taskThreadName)
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(taskThreadName.Length() <= 15);
|
||||||
|
|
||||||
|
// Ensure that NSS is initialized, since presumably CalculateResult
|
||||||
|
// will use NSS functions
|
||||||
|
if (!EnsureNSSInitializedChromeOrContent()) {
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Can't add 'this' as the event to run, since mThread may not be set yet
|
||||||
|
nsresult rv = NS_NewThread(getter_AddRefs(mThread), nullptr,
|
||||||
|
nsIThreadManager::DEFAULT_STACK_SIZE);
|
||||||
|
if (NS_FAILED(rv)) {
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_SetThreadName(mThread, taskThreadName);
|
||||||
|
// Note: event must not null out mThread!
|
||||||
|
return mThread->Dispatch(this, NS_DISPATCH_NORMAL);
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
CryptoTask::Run()
|
CryptoTask::Run()
|
||||||
{
|
{
|
||||||
|
@ -50,15 +50,11 @@ public:
|
|||||||
{
|
{
|
||||||
static_assert(LEN <= 15,
|
static_assert(LEN <= 15,
|
||||||
"Thread name must be no more than 15 characters");
|
"Thread name must be no more than 15 characters");
|
||||||
// Can't add 'this' as the event to run, since mThread may not be set yet
|
return Dispatch(NS_LITERAL_CSTRING(taskThreadName));
|
||||||
nsresult rv = NS_NewNamedThread(taskThreadName, getter_AddRefs(mThread));
|
|
||||||
if (NS_SUCCEEDED(rv)) {
|
|
||||||
// Note: event must not null out mThread!
|
|
||||||
rv = mThread->Dispatch(this, NS_DISPATCH_NORMAL);
|
|
||||||
}
|
|
||||||
return rv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsresult Dispatch(const nsACString& taskThreadName);
|
||||||
|
|
||||||
void Skip()
|
void Skip()
|
||||||
{
|
{
|
||||||
virtualDestroyNSSReference();
|
virtualDestroyNSSReference();
|
||||||
|
@ -127,6 +127,40 @@ nsTokenEventRunnable::Run()
|
|||||||
|
|
||||||
bool nsPSMInitPanic::isPanic = false;
|
bool nsPSMInitPanic::isPanic = false;
|
||||||
|
|
||||||
|
// This function can be called from chrome or content processes
|
||||||
|
// to ensure that NSS is initialized.
|
||||||
|
bool EnsureNSSInitializedChromeOrContent()
|
||||||
|
{
|
||||||
|
nsresult rv;
|
||||||
|
if (XRE_GetProcessType() == GeckoProcessType_Default) {
|
||||||
|
nsCOMPtr<nsISupports> nss = do_GetService(PSM_COMPONENT_CONTRACTID, &rv);
|
||||||
|
if (NS_FAILED(rv)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!NS_IsMainThread()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NSS_IsInitialized()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NSS_NoDB_Init(nullptr) != SECSuccess) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NS_FAILED(mozilla::psm::InitializeCipherSuite())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
mozilla::psm::DisableMD5();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// We must ensure that the nsNSSComponent has been loaded before
|
// We must ensure that the nsNSSComponent has been loaded before
|
||||||
// creating any other components.
|
// creating any other components.
|
||||||
bool EnsureNSSInitialized(EnsureNSSOperator op)
|
bool EnsureNSSInitialized(EnsureNSSOperator op)
|
||||||
|
@ -61,6 +61,8 @@ enum EnsureNSSOperator
|
|||||||
nssEnsureOnChromeOnly = 101
|
nssEnsureOnChromeOnly = 101
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern bool EnsureNSSInitializedChromeOrContent();
|
||||||
|
|
||||||
extern bool EnsureNSSInitialized(EnsureNSSOperator op);
|
extern bool EnsureNSSInitialized(EnsureNSSOperator op);
|
||||||
|
|
||||||
class nsNSSComponent;
|
class nsNSSComponent;
|
||||||
|
Loading…
Reference in New Issue
Block a user