This commit is contained in:
Carsten "Tomcat" Book 2013-08-05 11:22:48 +02:00
Родитель 992792ad07 4aea830dd1
Коммит 5c34d25a48
23 изменённых файлов: 1014 добавлений и 917 удалений

Просмотреть файл

@ -1,4 +1,4 @@
{
"revision": "7669b3265def0eed0473acd938897704007afaf3",
"revision": "5e7a8bbe525c0a43852770665ce9498fdb93ea81",
"repo_path": "/integration/gaia-central"
}

Просмотреть файл

@ -2,16 +2,15 @@
* 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 "Crypto.h"
#include "nsIDOMClassInfo.h"
#include "DOMError.h"
#include "nsString.h"
#include "jsapi.h"
#include "jsfriendapi.h"
#include "nsIServiceManager.h"
#include "nsCOMPtr.h"
#include "nsIRandomGenerator.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/CryptoBinding.h"
using mozilla::dom::ContentChild;
@ -20,18 +19,21 @@ using namespace js::ArrayBufferView;
namespace mozilla {
namespace dom {
NS_INTERFACE_MAP_BEGIN(Crypto)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Crypto)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_ENTRY(nsIDOMCrypto)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(Crypto)
NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(Crypto)
NS_IMPL_RELEASE(Crypto)
NS_IMPL_CYCLE_COLLECTING_ADDREF(Crypto)
NS_IMPL_CYCLE_COLLECTING_RELEASE(Crypto)
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(Crypto, mWindow)
Crypto::Crypto()
{
MOZ_COUNT_CTOR(Crypto);
SetIsDOMBinding();
}
Crypto::~Crypto()
@ -39,23 +41,25 @@ Crypto::~Crypto()
MOZ_COUNT_DTOR(Crypto);
}
NS_IMETHODIMP
Crypto::GetRandomValues(const JS::Value& aData, JSContext *cx,
JS::Value* _retval)
void
Crypto::Init(nsIDOMWindow* aWindow)
{
mWindow = do_QueryInterface(aWindow);
MOZ_ASSERT(mWindow);
}
/* virtual */ JSObject*
Crypto::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
{
return CryptoBinding::Wrap(aCx, aScope, this);
}
JSObject *
Crypto::GetRandomValues(JSContext* aCx, ArrayBufferView& aArray, ErrorResult& aRv)
{
NS_ABORT_IF_FALSE(NS_IsMainThread(), "Called on the wrong thread");
// Make sure this is a JavaScript object
if (!aData.isObject()) {
return NS_ERROR_DOM_NOT_OBJECT_ERR;
}
JS::Rooted<JSObject*> view(cx, &aData.toObject());
// Make sure this object is an ArrayBufferView
if (!JS_IsTypedArrayObject(view)) {
return NS_ERROR_DOM_TYPE_MISMATCH_ERR;
}
JS::Rooted<JSObject*> view(aCx, aArray.Obj());
// Throw if the wrong type of ArrayBufferView is passed in
// (Part of the Web Crypto API spec)
@ -69,29 +73,28 @@ Crypto::GetRandomValues(const JS::Value& aData, JSContext *cx,
case TYPE_UINT32:
break;
default:
return NS_ERROR_DOM_TYPE_MISMATCH_ERR;
aRv.Throw(NS_ERROR_DOM_TYPE_MISMATCH_ERR);
return nullptr;
}
uint32_t dataLen = JS_GetTypedArrayByteLength(view);
uint32_t dataLen = aArray.Length();
if (dataLen == 0) {
NS_WARNING("ArrayBufferView length is 0, cannot continue");
return NS_OK;
return view;
} else if (dataLen > 65536) {
return NS_ERROR_DOM_QUOTA_EXCEEDED_ERR;
aRv.Throw(NS_ERROR_DOM_QUOTA_EXCEEDED_ERR);
return nullptr;
}
void *dataptr = JS_GetArrayBufferViewData(view);
NS_ENSURE_TRUE(dataptr, NS_ERROR_FAILURE);
unsigned char* data =
static_cast<unsigned char*>(dataptr);
uint8_t* data = aArray.Data();
if (XRE_GetProcessType() != GeckoProcessType_Default) {
InfallibleTArray<uint8_t> randomValues;
// Tell the parent process to generate random values via PContent
ContentChild* cc = ContentChild::GetSingleton();
if (!cc->SendGetRandomValues(dataLen, &randomValues)) {
return NS_ERROR_FAILURE;
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
NS_ASSERTION(dataLen == randomValues.Length(),
"Invalid length returned from parent process!");
@ -100,28 +103,21 @@ Crypto::GetRandomValues(const JS::Value& aData, JSContext *cx,
uint8_t *buf = GetRandomValues(dataLen);
if (!buf) {
return NS_ERROR_FAILURE;
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
memcpy(data, buf, dataLen);
NS_Free(buf);
}
*_retval = OBJECT_TO_JSVAL(view);
return NS_OK;
return view;
}
#ifndef MOZ_DISABLE_CRYPTOLEGACY
// Stub out the legacy nsIDOMCrypto methods. The actual
// implementations are in security/manager/ssl/src/nsCrypto.{cpp,h}
NS_IMETHODIMP
Crypto::GetVersion(nsAString & aVersion)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
Crypto::GetEnableSmartCardEvents(bool *aEnableSmartCardEvents)
{
@ -133,61 +129,14 @@ Crypto::SetEnableSmartCardEvents(bool aEnableSmartCardEvents)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
Crypto::GenerateCRMFRequest(nsIDOMCRMFObject * *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
Crypto::ImportUserCertificates(const nsAString & nickname,
const nsAString & cmmfResponse,
bool doForcedBackup, nsAString & _retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
Crypto::PopChallengeResponse(const nsAString & challenge,
nsAString & _retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
Crypto::Random(int32_t numBytes, nsAString & _retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
Crypto::SignText(const nsAString & stringToSign, const nsAString & caOption,
nsAString & _retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
Crypto::Logout()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
Crypto::DisableRightClick()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
#endif
uint8_t*
/* static */ uint8_t*
Crypto::GetRandomValues(uint32_t aLength)
{
nsCOMPtr<nsIRandomGenerator> randomGenerator;
nsresult rv;
randomGenerator =
do_GetService("@mozilla.org/security/random-generator;1");
randomGenerator = do_GetService("@mozilla.org/security/random-generator;1");
NS_ENSURE_TRUE(randomGenerator, nullptr);
uint8_t* buf;

Просмотреть файл

@ -8,25 +8,89 @@
#include "nsIDOMCrypto.h"
#else
#include "nsIDOMCryptoLegacy.h"
#include "nsIDOMCRMFObject.h"
#endif
#include "nsPIDOMWindow.h"
#include "nsWrapperCache.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/TypedArray.h"
#define NS_DOMCRYPTO_CID \
{0x929d9320, 0x251e, 0x11d4, { 0x8a, 0x7c, 0x00, 0x60, 0x08, 0xc8, 0x44, 0xc3} }
namespace mozilla {
namespace dom {
class Crypto : public nsIDOMCrypto
class Crypto : public nsIDOMCrypto,
public nsWrapperCache
{
public:
Crypto();
virtual ~Crypto();
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMCRYPTO
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Crypto)
JSObject *
GetRandomValues(JSContext* aCx, ArrayBufferView& aArray, ErrorResult& aRv);
#ifndef MOZ_DISABLE_CRYPTOLEGACY
virtual bool EnableSmartCardEvents() = 0;
virtual void SetEnableSmartCardEvents(bool aEnable, ErrorResult& aRv) = 0;
virtual void GetVersion(nsString& aVersion) = 0;
virtual already_AddRefed<nsIDOMCRMFObject>
GenerateCRMFRequest(JSContext* aContext,
const nsCString& aReqDN,
const nsCString& aRegToken,
const nsCString& aAuthenticator,
const nsCString& aEaCert,
const nsCString& aJsCallback,
const Sequence<JS::Value>& aArgs,
ErrorResult& aRv) = 0;
virtual void ImportUserCertificates(const nsAString& aNickname,
const nsAString& aCmmfResponse,
bool aDoForcedBackup,
nsAString& aReturn,
ErrorResult& aRv) = 0;
virtual void PopChallengeResponse(const nsAString& aChallenge,
nsAString& aReturn,
ErrorResult& aRv) = 0;
virtual void Random(int32_t aNumBytes, nsAString& aReturn, ErrorResult& aRv) = 0;
virtual void SignText(JSContext* aContext,
const nsAString& aStringToSign,
const nsAString& aCaOption,
const Sequence<nsCString>& aArgs,
nsAString& aReturn) = 0;
virtual void Logout(ErrorResult& aRv) = 0;
virtual void DisableRightClick(ErrorResult& aRv) = 0;
#endif
// WebIDL
nsPIDOMWindow*
GetParentObject() const
{
return mWindow;
}
virtual JSObject*
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
static uint8_t*
GetRandomValues(uint32_t aLength);
private:
nsCOMPtr<nsPIDOMWindow> mWindow;
};
} // namespace dom

Просмотреть файл

@ -955,7 +955,7 @@ Navigator::GetDeviceStorages(const nsAString& aType,
return;
}
nsDOMDeviceStorage::CreateDeviceStoragesFor(mWindow, aType, aStores, false);
nsDOMDeviceStorage::CreateDeviceStoragesFor(mWindow, aType, aStores);
mDeviceStorageStores.AppendElements(aStores);
}

Просмотреть файл

@ -160,9 +160,6 @@
#include "nsIDOMXULCommandDispatcher.h"
#ifndef MOZ_DISABLE_CRYPTOLEGACY
#include "nsIDOMCRMFObject.h"
#include "nsIDOMCryptoLegacy.h"
#else
#include "nsIDOMCrypto.h"
#endif
#include "nsIControllers.h"
#include "nsISelection.h"
@ -319,7 +316,6 @@ const uint32_t kDOMClassInfo_##_dom_class##_interfaces = \
#ifndef MOZ_DISABLE_CRYPTOLEGACY
DOMCI_DATA_NO_CLASS(CRMFObject)
#endif
DOMCI_DATA_NO_CLASS(Crypto)
DOMCI_DATA_NO_CLASS(ContentFrameMessageManager)
DOMCI_DATA_NO_CLASS(ChromeMessageBroadcaster)
@ -502,8 +498,6 @@ static nsDOMClassInfoData sClassInfoData[] = {
NS_DEFINE_CLASSINFO_DATA(CRMFObject, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
#endif
NS_DEFINE_CLASSINFO_DATA(Crypto, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
// DOM Chrome Window class.
NS_DEFINE_CLASSINFO_DATA(ChromeWindow, nsWindowSH,
@ -1340,10 +1334,6 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_END
#endif
DOM_CLASSINFO_MAP_BEGIN(Crypto, nsIDOMCrypto)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMCrypto)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(ChromeWindow, nsIDOMWindow)
DOM_CLASSINFO_WINDOW_MAP_ENTRIES(true)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMChromeWindow)

Просмотреть файл

@ -45,7 +45,6 @@ DOMCI_CLASS(TreeContentView)
#ifndef MOZ_DISABLE_CRYPTOLEGACY
DOMCI_CLASS(CRMFObject)
#endif
DOMCI_CLASS(Crypto)
// DOM Chrome Window class, almost identical to Window
DOMCI_CLASS(ChromeWindow)

Просмотреть файл

@ -1679,6 +1679,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsGlobalWindow)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPersonalbar)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mStatusbar)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mScrollbars)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCrypto)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindow)
@ -1733,6 +1734,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindow)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mPersonalbar)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mStatusbar)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mScrollbars)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mCrypto)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
struct TraceData
@ -3878,10 +3880,13 @@ nsGlobalWindow::GetCrypto(nsIDOMCrypto** aCrypto)
if (!mCrypto) {
#ifndef MOZ_DISABLE_CRYPTOLEGACY
mCrypto = do_CreateInstance(NS_CRYPTO_CONTRACTID);
nsresult rv;
mCrypto = do_CreateInstance(NS_CRYPTO_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
#else
mCrypto = new Crypto();
#endif
mCrypto->Init(this);
}
NS_IF_ADDREF(*aCrypto = mCrypto);
return NS_OK;

Просмотреть файл

@ -206,6 +206,11 @@ DOMInterfaces = {
'headerFile': 'nsGeoPosition.h'
},
'Crypto' : {
'implicitJSContext': [ 'generateCRMFRequest', 'signText' ],
'headerFile': 'Crypto.h'
},
'CSS': {
'concrete': False,
},

Просмотреть файл

@ -50,9 +50,10 @@ public:
DeviceStorageFile(const nsAString& aStorageType,
const nsAString& aStorageName,
const nsAString& aPath);
// Used for enumerations. When you call Enumerate, you can pass in a directory to enumerate
// and the results that are returned are relative to that directory, files related to an
// enumeration need to know the "root of the enumeration" directory.
// Used for enumerations. When you call Enumerate, you can pass in a
// directory to enumerate and the results that are returned are relative to
// that directory, files related to an enumeration need to know the "root of
// the enumeration" directory.
DeviceStorageFile(const nsAString& aStorageType,
const nsAString& aStorageName,
const nsAString& aRootDir,
@ -61,15 +62,15 @@ public:
void SetPath(const nsAString& aPath);
void SetEditable(bool aEditable);
static already_AddRefed<DeviceStorageFile> CreateUnique(nsAString& aFileName,
static already_AddRefed<DeviceStorageFile>
CreateUnique(nsAString& aFileName,
uint32_t aFileType,
uint32_t aFileAttributes);
NS_DECL_THREADSAFE_ISUPPORTS
bool IsAvailable();
bool IsComposite();
void GetCompositePath(nsAString& aCompositePath);
void GetFullPath(nsAString& aFullPath);
// we want to make sure that the names of file can't reach
// outside of the type of storage the user asked for.
@ -102,7 +103,6 @@ private:
void Init();
void NormalizeFilePath();
void AppendRelativePath(const nsAString& aPath);
void GetStatusInternal(nsAString& aStorageName, nsAString& aStatus);
void AccumDirectoryUsage(nsIFile* aFile,
uint64_t* aPicturesSoFar,
uint64_t* aVideosSoFar,
@ -153,11 +153,14 @@ public:
NS_DECL_NSIOBSERVER
NS_DECL_NSIDOMEVENTTARGET
virtual void AddEventListener(const nsAString& aType,
virtual void
AddEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,
bool aUseCapture,
const mozilla::dom::Nullable<bool>& aWantsUntrusted,
ErrorResult& aRv) MOZ_OVERRIDE;
virtual void RemoveEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,
bool aUseCapture,
@ -165,14 +168,17 @@ public:
nsDOMDeviceStorage();
nsresult Init(nsPIDOMWindow* aWindow, const nsAString& aType,
nsTArray<nsRefPtr<nsDOMDeviceStorage> >& aStores);
nsresult Init(nsPIDOMWindow* aWindow, const nsAString& aType,
const nsAString& aVolName);
bool IsAvailable();
bool IsFullPath(const nsAString& aPath)
{
return aPath.Length() > 0 && aPath.CharAt(0) == '/';
}
void SetRootDirectoryForType(const nsAString& aType, const nsAString& aVolName);
void SetRootDirectoryForType(const nsAString& aType,
const nsAString& aVolName);
// WebIDL
nsPIDOMWindow*
@ -228,22 +234,24 @@ public:
// Uses XPCOM GetStorageName
static void CreateDeviceStorageFor(nsPIDOMWindow* aWin,
static void
CreateDeviceStorageFor(nsPIDOMWindow* aWin,
const nsAString& aType,
nsDOMDeviceStorage** aStore);
static void CreateDeviceStoragesFor(nsPIDOMWindow* aWin,
static void
CreateDeviceStoragesFor(nsPIDOMWindow* aWin,
const nsAString& aType,
nsTArray<nsRefPtr<nsDOMDeviceStorage> >& aStores,
bool aCompositeComponent);
nsTArray<nsRefPtr<nsDOMDeviceStorage> >& aStores);
void Shutdown();
static void GetOrderedVolumeNames(nsTArray<nsString>& aVolumeNames);
static void GetWritableStorageName(const nsAString& aStorageType,
static void GetDefaultStorageName(const nsAString& aStorageType,
nsAString &aStorageName);
static bool ParseCompositePath(const nsAString& aCompositePath,
static bool ParseFullPath(const nsAString& aFullPath,
nsAString& aOutStorageName,
nsAString& aOutStoragePath);
private:
@ -268,25 +276,11 @@ private:
nsString mStorageType;
nsCOMPtr<nsIFile> mRootDirectory;
nsString mStorageName;
bool mCompositeComponent;
// A composite device storage object is one which front-ends for multiple
// real storage objects. The real storage objects will each be stored in
// mStores and will each have a unique mStorageName. The composite storage
// object will have mStorageName == "", and mRootDirectory will be null.
//
// Note that on desktop (or other non-gonk), composite storage areas
// don't exist, and mStorageName will also be "".
//
// A device storage object which is stored in mStores is considered to be
// a composite component.
bool IsComposite() { return mStores.Length() > 0; }
bool IsCompositeComponent() { return mCompositeComponent; }
nsTArray<nsRefPtr<nsDOMDeviceStorage> > mStores;
already_AddRefed<nsDOMDeviceStorage> GetStorage(const nsAString& aCompositePath,
already_AddRefed<nsDOMDeviceStorage> GetStorage(const nsAString& aFullPath,
nsAString& aOutStoragePath);
already_AddRefed<nsDOMDeviceStorage> GetStorageByName(const nsAString &aStorageName);
already_AddRefed<nsDOMDeviceStorage>
GetStorageByName(const nsAString &aStorageName);
nsCOMPtr<nsIPrincipal> mPrincipal;
@ -306,8 +300,7 @@ private:
static mozilla::StaticRefPtr<VolumeNameCache> sVolumeNameCache;
#ifdef MOZ_WIDGET_GONK
void DispatchMountChangeEvent(nsAString& aVolumeName,
nsAString& aVolumeStatus);
void DispatchMountChangeEvent(nsAString& aVolumeStatus);
#endif
// nsIDOMDeviceStorage.type

Просмотреть файл

@ -33,7 +33,8 @@ DeviceStorageRequestChild::~DeviceStorageRequestChild() {
}
bool
DeviceStorageRequestChild::Recv__delete__(const DeviceStorageResponseValue& aValue)
DeviceStorageRequestChild::
Recv__delete__(const DeviceStorageResponseValue& aValue)
{
if (mCallback) {
mCallback->RequestComplete();
@ -51,11 +52,11 @@ DeviceStorageRequestChild::Recv__delete__(const DeviceStorageResponseValue& aVal
case DeviceStorageResponseValue::TSuccessResponse:
{
nsString compositePath;
mFile->GetCompositePath(compositePath);
nsString fullPath;
mFile->GetFullPath(fullPath);
AutoJSContext cx;
JS::Rooted<JS::Value> result(cx,
StringToJsval(mRequest->GetOwner(), compositePath));
StringToJsval(mRequest->GetOwner(), fullPath));
mRequest->FireSuccess(result);
break;
}
@ -105,14 +106,14 @@ DeviceStorageRequestChild::Recv__delete__(const DeviceStorageResponseValue& aVal
case DeviceStorageResponseValue::TEnumerationResponse:
{
EnumerationResponse r = aValue;
nsDOMDeviceStorageCursor* cursor = static_cast<nsDOMDeviceStorageCursor*>(mRequest.get());
nsDOMDeviceStorageCursor* cursor
= static_cast<nsDOMDeviceStorageCursor*>(mRequest.get());
uint32_t count = r.paths().Length();
for (uint32_t i = 0; i < count; i++) {
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(r.type(),
r.paths()[i].storageName(),
r.rootdir(),
r.paths()[i].name());
nsRefPtr<DeviceStorageFile> dsf
= new DeviceStorageFile(r.type(), r.paths()[i].storageName(),
r.rootdir(), r.paths()[i].name());
cursor->mFiles.AppendElement(dsf);
}
@ -131,7 +132,8 @@ DeviceStorageRequestChild::Recv__delete__(const DeviceStorageResponseValue& aVal
}
void
DeviceStorageRequestChild::SetCallback(DeviceStorageRequestChildCallback *aCallback)
DeviceStorageRequestChild::
SetCallback(DeviceStorageRequestChildCallback *aCallback)
{
mCallback = aCallback;
}

Просмотреть файл

@ -18,14 +18,16 @@ namespace mozilla {
namespace dom {
namespace devicestorage {
DeviceStorageRequestParent::DeviceStorageRequestParent(const DeviceStorageParams& aParams)
DeviceStorageRequestParent::DeviceStorageRequestParent(
const DeviceStorageParams& aParams)
: mParams(aParams)
, mMutex("DeviceStorageRequestParent::mMutex")
, mActorDestoryed(false)
{
MOZ_COUNT_CTOR(DeviceStorageRequestParent);
DebugOnly<DeviceStorageUsedSpaceCache*> usedSpaceCache = DeviceStorageUsedSpaceCache::CreateOrGet();
DebugOnly<DeviceStorageUsedSpaceCache*> usedSpaceCache
= DeviceStorageUsedSpaceCache::CreateOrGet();
NS_ASSERTION(usedSpaceCache, "DeviceStorageUsedSpaceCache is null");
}
@ -48,7 +50,8 @@ DeviceStorageRequestParent::Dispatch()
nsRefPtr<CancelableRunnable> r = new WriteFileEvent(this, dsf, stream);
nsCOMPtr<nsIEventTarget> target = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
nsCOMPtr<nsIEventTarget> target
= do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
NS_ASSERTION(target, "Must have stream transport service");
target->Dispatch(r, NS_DISPATCH_NORMAL);
break;
@ -58,10 +61,12 @@ DeviceStorageRequestParent::Dispatch()
{
DeviceStorageGetParams p = mParams;
nsRefPtr<DeviceStorageFile> dsf =
new DeviceStorageFile(p.type(), p.storageName(), p.rootDir(), p.relpath());
new DeviceStorageFile(p.type(), p.storageName(),
p.rootDir(), p.relpath());
nsRefPtr<CancelableRunnable> r = new ReadFileEvent(this, dsf);
nsCOMPtr<nsIEventTarget> target = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
nsCOMPtr<nsIEventTarget> target
= do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
NS_ASSERTION(target, "Must have stream transport service");
target->Dispatch(r, NS_DISPATCH_NORMAL);
break;
@ -75,7 +80,8 @@ DeviceStorageRequestParent::Dispatch()
new DeviceStorageFile(p.type(), p.storageName(), p.relpath());
nsRefPtr<CancelableRunnable> r = new DeleteFileEvent(this, dsf);
nsCOMPtr<nsIEventTarget> target = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
nsCOMPtr<nsIEventTarget> target
= do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
NS_ASSERTION(target, "Must have stream transport service");
target->Dispatch(r, NS_DISPATCH_NORMAL);
break;
@ -89,7 +95,8 @@ DeviceStorageRequestParent::Dispatch()
new DeviceStorageFile(p.type(), p.storageName());
nsRefPtr<FreeSpaceFileEvent> r = new FreeSpaceFileEvent(this, dsf);
nsCOMPtr<nsIEventTarget> target = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
nsCOMPtr<nsIEventTarget> target
= do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
NS_ASSERTION(target, "Must have stream transport service");
target->Dispatch(r, NS_DISPATCH_NORMAL);
break;
@ -97,7 +104,8 @@ DeviceStorageRequestParent::Dispatch()
case DeviceStorageParams::TDeviceStorageUsedSpaceParams:
{
DeviceStorageUsedSpaceCache* usedSpaceCache = DeviceStorageUsedSpaceCache::CreateOrGet();
DeviceStorageUsedSpaceCache* usedSpaceCache
= DeviceStorageUsedSpaceCache::CreateOrGet();
NS_ASSERTION(usedSpaceCache, "DeviceStorageUsedSpaceCache is null");
DeviceStorageUsedSpaceParams p = mParams;
@ -116,7 +124,8 @@ DeviceStorageRequestParent::Dispatch()
nsRefPtr<DeviceStorageFile> dsf =
new DeviceStorageFile(p.type(), p.storageName());
nsRefPtr<PostAvailableResultEvent> r = new PostAvailableResultEvent(this, dsf);
nsRefPtr<PostAvailableResultEvent> r
= new PostAvailableResultEvent(this, dsf);
NS_DispatchToMainThread(r);
break;
}
@ -125,10 +134,13 @@ DeviceStorageRequestParent::Dispatch()
{
DeviceStorageEnumerationParams p = mParams;
nsRefPtr<DeviceStorageFile> dsf
= new DeviceStorageFile(p.type(), p.storageName(), p.rootdir(), NS_LITERAL_STRING(""));
nsRefPtr<CancelableRunnable> r = new EnumerateFileEvent(this, dsf, p.since());
= new DeviceStorageFile(p.type(), p.storageName(),
p.rootdir(), NS_LITERAL_STRING(""));
nsRefPtr<CancelableRunnable> r
= new EnumerateFileEvent(this, dsf, p.since());
nsCOMPtr<nsIEventTarget> target = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
nsCOMPtr<nsIEventTarget> target
= do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
NS_ASSERTION(target, "Must have stream transport service");
target->Dispatch(r, NS_DISPATCH_NORMAL);
break;
@ -142,7 +154,8 @@ DeviceStorageRequestParent::Dispatch()
}
bool
DeviceStorageRequestParent::EnsureRequiredPermissions(mozilla::dom::ContentParent* aParent)
DeviceStorageRequestParent::EnsureRequiredPermissions(
mozilla::dom::ContentParent* aParent)
{
if (mozilla::Preferences::GetBool("device.storage.testing", false)) {
return true;
@ -224,7 +237,8 @@ DeviceStorageRequestParent::EnsureRequiredPermissions(mozilla::dom::ContentParen
}
nsAutoCString permissionName;
nsresult rv = DeviceStorageTypeChecker::GetPermissionForType(type, permissionName);
nsresult rv = DeviceStorageTypeChecker::GetPermissionForType(type,
permissionName);
if (NS_FAILED(rv)) {
return false;
}
@ -264,14 +278,16 @@ DeviceStorageRequestParent::ActorDestroy(ActorDestroyReason)
}
}
DeviceStorageRequestParent::PostFreeSpaceResultEvent::PostFreeSpaceResultEvent(DeviceStorageRequestParent* aParent,
DeviceStorageRequestParent::PostFreeSpaceResultEvent::PostFreeSpaceResultEvent(
DeviceStorageRequestParent* aParent,
uint64_t aFreeSpace)
: CancelableRunnable(aParent)
, mFreeSpace(aFreeSpace)
{
}
DeviceStorageRequestParent::PostFreeSpaceResultEvent::~PostFreeSpaceResultEvent() {}
DeviceStorageRequestParent::PostFreeSpaceResultEvent::
~PostFreeSpaceResultEvent() {}
nsresult
DeviceStorageRequestParent::PostFreeSpaceResultEvent::CancelableRun() {
@ -282,7 +298,8 @@ DeviceStorageRequestParent::PostFreeSpaceResultEvent::CancelableRun() {
return NS_OK;
}
DeviceStorageRequestParent::PostUsedSpaceResultEvent::PostUsedSpaceResultEvent(DeviceStorageRequestParent* aParent,
DeviceStorageRequestParent::PostUsedSpaceResultEvent::
PostUsedSpaceResultEvent(DeviceStorageRequestParent* aParent,
const nsAString& aType,
uint64_t aUsedSpace)
: CancelableRunnable(aParent)
@ -291,7 +308,8 @@ DeviceStorageRequestParent::PostUsedSpaceResultEvent::PostUsedSpaceResultEvent(D
{
}
DeviceStorageRequestParent::PostUsedSpaceResultEvent::~PostUsedSpaceResultEvent() {}
DeviceStorageRequestParent::PostUsedSpaceResultEvent::
~PostUsedSpaceResultEvent() {}
nsresult
DeviceStorageRequestParent::PostUsedSpaceResultEvent::CancelableRun() {
@ -302,8 +320,8 @@ DeviceStorageRequestParent::PostUsedSpaceResultEvent::CancelableRun() {
return NS_OK;
}
DeviceStorageRequestParent::PostErrorEvent::PostErrorEvent(DeviceStorageRequestParent* aParent,
const char* aError)
DeviceStorageRequestParent::PostErrorEvent::
PostErrorEvent(DeviceStorageRequestParent* aParent, const char* aError)
: CancelableRunnable(aParent)
{
CopyASCIItoUTF16(aError, mError);
@ -320,7 +338,8 @@ DeviceStorageRequestParent::PostErrorEvent::CancelableRun() {
return NS_OK;
}
DeviceStorageRequestParent::PostSuccessEvent::PostSuccessEvent(DeviceStorageRequestParent* aParent)
DeviceStorageRequestParent::PostSuccessEvent::
PostSuccessEvent(DeviceStorageRequestParent* aParent)
: CancelableRunnable(aParent)
{
}
@ -336,7 +355,8 @@ DeviceStorageRequestParent::PostSuccessEvent::CancelableRun() {
return NS_OK;
}
DeviceStorageRequestParent::PostBlobSuccessEvent::PostBlobSuccessEvent(DeviceStorageRequestParent* aParent,
DeviceStorageRequestParent::PostBlobSuccessEvent::
PostBlobSuccessEvent(DeviceStorageRequestParent* aParent,
DeviceStorageFile* aFile,
uint32_t aLength,
nsACString& aMimeType,
@ -358,9 +378,11 @@ DeviceStorageRequestParent::PostBlobSuccessEvent::CancelableRun() {
nsString mime;
CopyASCIItoUTF16(mMimeType, mime);
nsString compositePath;
mFile->GetCompositePath(compositePath);
nsCOMPtr<nsIDOMBlob> blob = new nsDOMFileFile(compositePath, mime, mLength, mFile->mFile, mLastModificationDate);
nsString fullPath;
mFile->GetFullPath(fullPath);
nsCOMPtr<nsIDOMBlob> blob = new nsDOMFileFile(fullPath, mime, mLength,
mFile->mFile,
mLastModificationDate);
ContentParent* cp = static_cast<ContentParent*>(mParent->Manager());
BlobParent* actor = cp->GetOrCreateActorForBlob(blob);
@ -377,7 +399,8 @@ DeviceStorageRequestParent::PostBlobSuccessEvent::CancelableRun() {
return NS_OK;
}
DeviceStorageRequestParent::PostEnumerationSuccessEvent::PostEnumerationSuccessEvent(DeviceStorageRequestParent* aParent,
DeviceStorageRequestParent::PostEnumerationSuccessEvent::
PostEnumerationSuccessEvent(DeviceStorageRequestParent* aParent,
const nsAString& aStorageType,
const nsAString& aRelPath,
InfallibleTArray<DeviceStorageFileValue>& aPaths)
@ -388,7 +411,8 @@ DeviceStorageRequestParent::PostEnumerationSuccessEvent::PostEnumerationSuccessE
{
}
DeviceStorageRequestParent::PostEnumerationSuccessEvent::~PostEnumerationSuccessEvent() {}
DeviceStorageRequestParent::PostEnumerationSuccessEvent::
~PostEnumerationSuccessEvent() {}
nsresult
DeviceStorageRequestParent::PostEnumerationSuccessEvent::CancelableRun() {
@ -399,7 +423,8 @@ DeviceStorageRequestParent::PostEnumerationSuccessEvent::CancelableRun() {
return NS_OK;
}
DeviceStorageRequestParent::WriteFileEvent::WriteFileEvent(DeviceStorageRequestParent* aParent,
DeviceStorageRequestParent::WriteFileEvent::
WriteFileEvent(DeviceStorageRequestParent* aParent,
DeviceStorageFile* aFile,
nsIInputStream* aInputStream)
: CancelableRunnable(aParent)
@ -428,7 +453,8 @@ DeviceStorageRequestParent::WriteFileEvent::CancelableRun()
bool check = false;
mFile->mFile->Exists(&check);
if (check) {
nsCOMPtr<PostErrorEvent> event = new PostErrorEvent(mParent, POST_ERROR_EVENT_FILE_EXISTS);
nsCOMPtr<PostErrorEvent> event
= new PostErrorEvent(mParent, POST_ERROR_EVENT_FILE_EXISTS);
NS_DispatchToMainThread(event);
return NS_OK;
}
@ -447,8 +473,8 @@ DeviceStorageRequestParent::WriteFileEvent::CancelableRun()
}
DeviceStorageRequestParent::DeleteFileEvent::DeleteFileEvent(DeviceStorageRequestParent* aParent,
DeviceStorageFile* aFile)
DeviceStorageRequestParent::DeleteFileEvent::
DeleteFileEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile)
: CancelableRunnable(aParent)
, mFile(aFile)
{
@ -480,7 +506,8 @@ DeviceStorageRequestParent::DeleteFileEvent::CancelableRun()
return NS_OK;
}
DeviceStorageRequestParent::FreeSpaceFileEvent::FreeSpaceFileEvent(DeviceStorageRequestParent* aParent,
DeviceStorageRequestParent::FreeSpaceFileEvent::
FreeSpaceFileEvent(DeviceStorageRequestParent* aParent,
DeviceStorageFile* aFile)
: CancelableRunnable(aParent)
, mFile(aFile)
@ -507,7 +534,8 @@ DeviceStorageRequestParent::FreeSpaceFileEvent::CancelableRun()
return NS_OK;
}
DeviceStorageRequestParent::UsedSpaceFileEvent::UsedSpaceFileEvent(DeviceStorageRequestParent* aParent,
DeviceStorageRequestParent::UsedSpaceFileEvent::
UsedSpaceFileEvent(DeviceStorageRequestParent* aParent,
DeviceStorageFile* aFile)
: CancelableRunnable(aParent)
, mFile(aFile)
@ -528,7 +556,8 @@ DeviceStorageRequestParent::UsedSpaceFileEvent::CancelableRun()
&musicUsage, &totalUsage);
nsCOMPtr<nsIRunnable> r;
if (mFile->mStorageType.EqualsLiteral(DEVICESTORAGE_PICTURES)) {
r = new PostUsedSpaceResultEvent(mParent, mFile->mStorageType, picturesUsage);
r = new PostUsedSpaceResultEvent(mParent, mFile->mStorageType,
picturesUsage);
}
else if (mFile->mStorageType.EqualsLiteral(DEVICESTORAGE_VIDEOS)) {
r = new PostUsedSpaceResultEvent(mParent, mFile->mStorageType, videosUsage);
@ -542,12 +571,13 @@ DeviceStorageRequestParent::UsedSpaceFileEvent::CancelableRun()
return NS_OK;
}
DeviceStorageRequestParent::ReadFileEvent::ReadFileEvent(DeviceStorageRequestParent* aParent,
DeviceStorageFile* aFile)
DeviceStorageRequestParent::ReadFileEvent::
ReadFileEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile)
: CancelableRunnable(aParent)
, mFile(aFile)
{
nsCOMPtr<nsIMIMEService> mimeService = do_GetService(NS_MIMESERVICE_CONTRACTID);
nsCOMPtr<nsIMIMEService> mimeService
= do_GetService(NS_MIMESERVICE_CONTRACTID);
if (mimeService) {
nsresult rv = mimeService->GetTypeFromFile(mFile->mFile, mMimeType);
if (NS_FAILED(rv)) {
@ -591,12 +621,14 @@ DeviceStorageRequestParent::ReadFileEvent::CancelableRun()
return NS_OK;
}
r = new PostBlobSuccessEvent(mParent, mFile, static_cast<uint64_t>(fileSize), mMimeType, modDate);
r = new PostBlobSuccessEvent(mParent, mFile, static_cast<uint64_t>(fileSize),
mMimeType, modDate);
NS_DispatchToMainThread(r);
return NS_OK;
}
DeviceStorageRequestParent::EnumerateFileEvent::EnumerateFileEvent(DeviceStorageRequestParent* aParent,
DeviceStorageRequestParent::EnumerateFileEvent::
EnumerateFileEvent(DeviceStorageRequestParent* aParent,
DeviceStorageFile* aFile,
uint64_t aSince)
: CancelableRunnable(aParent)
@ -636,13 +668,15 @@ DeviceStorageRequestParent::EnumerateFileEvent::CancelableRun()
values.AppendElement(dsvf);
}
r = new PostEnumerationSuccessEvent(mParent, mFile->mStorageType, mFile->mRootDir, values);
r = new PostEnumerationSuccessEvent(mParent, mFile->mStorageType,
mFile->mRootDir, values);
NS_DispatchToMainThread(r);
return NS_OK;
}
DeviceStorageRequestParent::PostPathResultEvent::PostPathResultEvent(DeviceStorageRequestParent* aParent,
DeviceStorageRequestParent::PostPathResultEvent::
PostPathResultEvent(DeviceStorageRequestParent* aParent,
const nsAString& aPath)
: CancelableRunnable(aParent)
, mPath(aPath)
@ -663,14 +697,16 @@ DeviceStorageRequestParent::PostPathResultEvent::CancelableRun()
return NS_OK;
}
DeviceStorageRequestParent::PostAvailableResultEvent::PostAvailableResultEvent(DeviceStorageRequestParent* aParent,
DeviceStorageRequestParent::PostAvailableResultEvent::
PostAvailableResultEvent(DeviceStorageRequestParent* aParent,
DeviceStorageFile* aFile)
: CancelableRunnable(aParent)
, mFile(aFile)
{
}
DeviceStorageRequestParent::PostAvailableResultEvent::~PostAvailableResultEvent()
DeviceStorageRequestParent::PostAvailableResultEvent::
~PostAvailableResultEvent()
{
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -5,8 +5,10 @@
#include "nsISupports.idl"
[scriptable, uuid(a0a3bc68-eab3-4e66-b5cb-b1d86765119c)]
interface nsIDOMWindow;
[uuid(729cfcad-11b4-4338-b97e-5c023ae295fa)]
interface nsIDOMCrypto : nsISupports
{
[implicit_jscontext] jsval getRandomValues(in jsval aData);
[notxpcom] void init(in nsIDOMWindow window);
};

Просмотреть файл

@ -6,23 +6,11 @@
#include "domstubs.idl"
interface nsIDOMCRMFObject;
interface nsIDOMWindow;
[scriptable, uuid(e1df1d4d-41ef-4225-934a-107c5d612686)]
[uuid(c25ecf08-3f46-4420-bee4-8505792fd63a)]
interface nsIDOMCrypto : nsISupports
{
readonly attribute DOMString version;
[notxpcom] void init(in nsIDOMWindow window);
attribute boolean enableSmartCardEvents;
nsIDOMCRMFObject generateCRMFRequest(/* ... */);
DOMString importUserCertificates(in DOMString nickname,
in DOMString cmmfResponse,
in boolean doForcedBackup);
DOMString popChallengeResponse(in DOMString challenge);
DOMString random(in long numBytes);
DOMString signText(in DOMString stringToSign,
in DOMString caOption /* ... */);
void logout();
void disableRightClick();
[implicit_jscontext] jsval getRandomValues(in jsval aData);
};

Просмотреть файл

@ -41,6 +41,7 @@ add_test(function test_setCLIR_success() {
worker.RIL.setCLIR = function fakeSetCLIR(options) {
worker.RIL[REQUEST_SET_CLIR](0, {
rilMessageType: "setCLIR",
rilRequestError: ERROR_SUCCESS
});
};
@ -63,6 +64,7 @@ add_test(function test_setCLIR_generic_failure() {
worker.RIL.setCLIR = function fakeSetCLIR(options) {
worker.RIL[REQUEST_SET_CLIR](0, {
rilMessageType: "setCLIR",
rilRequestError: ERROR_GENERIC_FAILURE
});
};
@ -95,6 +97,7 @@ add_test(function test_getCLIR_n0_m1() {
2 // Length.
];
worker.RIL[REQUEST_GET_CLIR](1, {
rilMessageType: "setCLIR",
rilRequestError: ERROR_SUCCESS
});
};
@ -126,6 +129,7 @@ add_test(function test_getCLIR_error_generic_failure_invalid_length() {
0 // Length (invalid one).
];
worker.RIL[REQUEST_GET_CLIR](1, {
rilMessageType: "setCLIR",
rilRequestError: ERROR_SUCCESS
});
};

Просмотреть файл

@ -125,7 +125,7 @@ function onWindowLoad()
window.crypto.getRandomValues(null);
}
catch (ex) {
var test = ex.toString().search(/1003/);
var test = ex.toString().search(/1003|TypeError/);
ok((test > -1), "Expected TYPE_ERR, got " + ex + ".");
}

Просмотреть файл

@ -24,5 +24,33 @@ ok("signText" in window.crypto, "signText in window.crypto");
ok("disableRightClick" in window.crypto,
"disableRightClick in window.crypto");
function jsCallback () {
}
try {
window.crypto.generateCRMFRequest(null, null, null, null, jsCallback.toString());
ok(false, "window.crypto.generateCRMFRequest failed, should throw error");
} catch (e) {
ok(e.toString().search(/Failure/) > -1,
"Expected error: ReqDN cannot be null");
}
try {
window.crypto.generateCRMFRequest(document.documentElement, null, null, null,
null);
ok(false, "window.crypto.generateCRMFRequest failed, should throw error");
} catch (e) {
ok(e.toString().search(/Failure/) > -1,
"Expected error: jsCallback cannot be null");
}
try {
window.crypto.generateCRMFRequest(document.documentElement, null, null, null,
jsCallback.toString(), 1024);
ok(false, "window.crypto.generateCRMFRequest failed, should throw error");
} catch (e) {
ok(e.toString().search(/TypeError/) > -1,
"Expected error: Not enough arguments");
}
</script>
</body></html>

63
dom/webidl/Crypto.webidl Normal file
Просмотреть файл

@ -0,0 +1,63 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/.
*
* The origin of this IDL file is
* http://www.w3.org/TR/WebCryptoAPI/
*/
[NoInterfaceObject]
interface RandomSource {
[Throws]
ArrayBufferView getRandomValues(ArrayBufferView array);
};
Crypto implements RandomSource;
interface Crypto {
};
#ifndef MOZ_DISABLE_CRYPTOLEGACY
interface CRMFObject;
[NoInterfaceObject]
interface CryptoLegacy {
readonly attribute DOMString version;
[SetterThrows]
attribute boolean enableSmartCardEvents;
[Throws]
CRMFObject generateCRMFRequest(ByteString? reqDN,
ByteString? regToken,
ByteString? authenticator,
ByteString? eaCert,
ByteString? jsCallback,
any... args);
[Throws]
DOMString importUserCertificates(DOMString nickname,
DOMString cmmfResponse,
boolean doForcedBackup);
[Throws]
DOMString popChallengeResponse(DOMString challenge);
[Throws]
DOMString random(long numBytes);
DOMString signText(DOMString stringToSign,
DOMString caOption,
ByteString... args);
[Throws]
void logout();
[Throws]
void disableRightClick();
};
Crypto implements CryptoLegacy;
#endif // !MOZ_DISABLE_CRYPTOLEGACY

Просмотреть файл

@ -9,6 +9,7 @@ generated_webidl_files = \
$(NULL)
preprocessed_webidl_files = \
Crypto.webidl \
Navigator.webidl \
$(NULL)

Просмотреть файл

@ -19,7 +19,6 @@ members = [
#
# Note that many implementations of interfaces in this directory
# use GetCurrentNativeCallContext, notably:
# - nsIDOMCrypto.{generateCRMFRequest,signText}
# - nsIDOMLocation.reload
# - nsIDOMNSHistory.go
# - nsIDOMJSPluginArray.refresh

Просмотреть файл

@ -74,9 +74,11 @@
#include "nsNSSCertHelper.h"
#include <algorithm>
#include "nsWrapperCacheInlines.h"
#endif
using namespace mozilla;
using namespace mozilla::dom;
/*
* These are the most common error strings that are returned
@ -256,8 +258,14 @@ nsCrypto::~nsCrypto()
{
}
NS_IMETHODIMP
nsCrypto::SetEnableSmartCardEvents(bool aEnable)
void
nsCrypto::Init(nsIDOMWindow* aWindow)
{
mozilla::dom::Crypto::Init(aWindow);
}
void
nsCrypto::SetEnableSmartCardEvents(bool aEnable, ErrorResult& aRv)
{
nsresult rv = NS_OK;
@ -269,17 +277,31 @@ nsCrypto::SetEnableSmartCardEvents(bool aEnable)
}
if (NS_FAILED(rv)) {
return rv;
aRv.Throw(rv);
return;
}
mEnableSmartCardEvents = aEnable;
return NS_OK;
}
NS_IMETHODIMP
nsCrypto::SetEnableSmartCardEvents(bool aEnable)
{
ErrorResult rv;
SetEnableSmartCardEvents(aEnable, rv);
return rv.ErrorCode();
}
bool
nsCrypto::EnableSmartCardEvents()
{
return mEnableSmartCardEvents;
}
NS_IMETHODIMP
nsCrypto::GetEnableSmartCardEvents(bool *aEnable)
{
*aEnable = mEnableSmartCardEvents;
*aEnable = EnableSmartCardEvents();
return NS_OK;
}
@ -294,11 +316,10 @@ ns_can_escrow(nsKeyGenType keyGenType)
//Retrieve crypto.version so that callers know what
//version of PSM this is.
NS_IMETHODIMP
nsCrypto::GetVersion(nsAString& aVersion)
void
nsCrypto::GetVersion(nsString& aVersion)
{
aVersion.Assign(NS_LITERAL_STRING(PSM_VERSION_STRING).get());
return NS_OK;
aVersion.Assign(NS_LITERAL_STRING(PSM_VERSION_STRING));
}
/*
@ -1831,101 +1852,47 @@ GetISupportsFromContext(JSContext *cx)
//The top level method which is a member of nsIDOMCrypto
//for generate a base64 encoded CRMF request.
NS_IMETHODIMP
nsCrypto::GenerateCRMFRequest(nsIDOMCRMFObject** aReturn)
already_AddRefed<nsIDOMCRMFObject>
nsCrypto::GenerateCRMFRequest(JSContext* aContext,
const nsCString& aReqDN,
const nsCString& aRegToken,
const nsCString& aAuthenticator,
const nsCString& aEaCert,
const nsCString& aJsCallback,
const Sequence<JS::Value>& aArgs,
ErrorResult& aRv)
{
nsNSSShutDownPreventionLock locker;
*aReturn = nullptr;
nsCOMPtr<nsIDOMCRMFObject> crmf;
nsresult nrv;
nsCOMPtr<nsIXPConnect> xpc(do_GetService(nsIXPConnect::GetCID(), &nrv));
NS_ENSURE_SUCCESS(nrv, nrv);
nsAXPCNativeCallContext *ncc = nullptr;
nrv = xpc->GetCurrentNativeCallContext(&ncc);
NS_ENSURE_SUCCESS(nrv, nrv);
if (!ncc)
return NS_ERROR_NOT_AVAILABLE;
uint32_t argc;
ncc->GetArgc(&argc);
JS::Value *argv = nullptr;
nrv = ncc->GetArgvPtr(&argv);
NS_ENSURE_SUCCESS(nrv, nrv);
JSContext *cx;
nrv = ncc->GetJSContext(&cx);
NS_ENSURE_SUCCESS(nrv, nrv);
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
uint32_t argc = aArgs.Length();
/*
* Get all of the parameters.
*/
if (argc < 5 || ((argc-5) % 3) != 0) {
JS_ReportError(cx, "%s%s", JS_ERROR,
"incorrect number of parameters");
return NS_ERROR_FAILURE;
if (argc % 3 != 0) {
aRv.ThrowNotEnoughArgsError();
return nullptr;
}
if (JSVAL_IS_NULL(argv[0])) {
JS_ReportError(cx, "%s%s", JS_ERROR, "no DN specified");
return NS_ERROR_FAILURE;
if (aReqDN.IsVoid()) {
NS_WARNING("no DN specified");
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
JSString *jsString = JS_ValueToString(cx,argv[0]);
NS_ENSURE_TRUE(jsString, NS_ERROR_OUT_OF_MEMORY);
argv[0] = STRING_TO_JSVAL(jsString);
JSAutoByteString reqDN(cx,jsString);
NS_ENSURE_TRUE(!!reqDN, NS_ERROR_OUT_OF_MEMORY);
if (aJsCallback.IsVoid()) {
NS_WARNING("no completion function specified");
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
JSAutoByteString regToken;
if (!JSVAL_IS_NULL(argv[1])) {
jsString = JS_ValueToString(cx, argv[1]);
NS_ENSURE_TRUE(jsString, NS_ERROR_OUT_OF_MEMORY);
argv[1] = STRING_TO_JSVAL(jsString);
regToken.encodeLatin1(cx, jsString);
NS_ENSURE_TRUE(!!regToken, NS_ERROR_OUT_OF_MEMORY);
JS::RootedObject script_obj(aContext, GetWrapper());
if (MOZ_UNLIKELY(!script_obj)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
JSAutoByteString authenticator;
if (!JSVAL_IS_NULL(argv[2])) {
jsString = JS_ValueToString(cx, argv[2]);
NS_ENSURE_TRUE(jsString, NS_ERROR_OUT_OF_MEMORY);
argv[2] = STRING_TO_JSVAL(jsString);
authenticator.encodeLatin1(cx, jsString);
NS_ENSURE_TRUE(!!authenticator, NS_ERROR_OUT_OF_MEMORY);
}
JSAutoByteString eaCert;
if (!JSVAL_IS_NULL(argv[3])) {
jsString = JS_ValueToString(cx, argv[3]);
NS_ENSURE_TRUE(jsString, NS_ERROR_OUT_OF_MEMORY);
argv[3] = STRING_TO_JSVAL(jsString);
eaCert.encodeLatin1(cx, jsString);
NS_ENSURE_TRUE(!!eaCert, NS_ERROR_OUT_OF_MEMORY);
}
if (JSVAL_IS_NULL(argv[4])) {
JS_ReportError(cx, "%s%s", JS_ERROR, "no completion "
"function specified");
return NS_ERROR_FAILURE;
}
jsString = JS_ValueToString(cx, argv[4]);
NS_ENSURE_TRUE(jsString, NS_ERROR_OUT_OF_MEMORY);
argv[4] = STRING_TO_JSVAL(jsString);
JSAutoByteString jsCallback(cx, jsString);
NS_ENSURE_TRUE(!!jsCallback, NS_ERROR_OUT_OF_MEMORY);
nrv = xpc->WrapNative(cx, JS::CurrentGlobalOrNull(cx),
static_cast<nsIDOMCrypto *>(this),
NS_GET_IID(nsIDOMCrypto), getter_AddRefs(holder));
NS_ENSURE_SUCCESS(nrv, nrv);
JS::RootedObject script_obj(cx, holder->GetJSObject());
NS_ENSURE_STATE(script_obj);
//Put up some UI warning that someone is trying to
//escrow the private key.
@ -1934,29 +1901,36 @@ nsCrypto::GenerateCRMFRequest(nsIDOMCRMFObject** aReturn)
nsNSSCertificate *escrowCert = nullptr;
nsCOMPtr<nsIX509Cert> nssCert;
bool willEscrow = false;
if (!!eaCert) {
if (!aEaCert.IsVoid()) {
SECItem certDer = {siBuffer, nullptr, 0};
SECStatus srv = ATOB_ConvertAsciiToItem(&certDer, eaCert.ptr());
SECStatus srv = ATOB_ConvertAsciiToItem(&certDer, aEaCert.get());
if (srv != SECSuccess) {
return NS_ERROR_FAILURE;
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
ScopedCERTCertificate cert(CERT_NewTempCertificate(CERT_GetDefaultCertDB(),
&certDer, nullptr,
false, true));
if (!cert)
return NS_ERROR_FAILURE;
if (!cert) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
escrowCert = nsNSSCertificate::Create(cert);
nssCert = escrowCert;
if (!nssCert)
return NS_ERROR_OUT_OF_MEMORY;
if (!nssCert) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return nullptr;
}
nsCOMPtr<nsIDOMCryptoDialogs> dialogs;
nsresult rv = getNSSDialogs(getter_AddRefs(dialogs),
NS_GET_IID(nsIDOMCryptoDialogs),
NS_DOMCRYPTODIALOGS_CONTRACTID);
if (NS_FAILED(rv))
return rv;
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return nullptr;
}
bool okay=false;
{
@ -1968,27 +1942,32 @@ nsCrypto::GenerateCRMFRequest(nsIDOMCRMFObject** aReturn)
dialogs->ConfirmKeyEscrow(nssCert, &okay);
}
}
if (!okay)
return NS_OK;
if (!okay) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
willEscrow = true;
}
nsCOMPtr<nsIInterfaceRequestor> uiCxt = new PipUIContext;
int32_t numRequests = (argc - 5)/3;
int32_t numRequests = argc / 3;
nsKeyPairInfo *keyids = new nsKeyPairInfo[numRequests];
memset(keyids, 0, sizeof(nsKeyPairInfo)*numRequests);
int keyInfoIndex;
uint32_t i;
PK11SlotInfo *slot = nullptr;
// Go through all of the arguments and generate the appropriate key pairs.
for (i=5,keyInfoIndex=0; i<argc; i+=3,keyInfoIndex++) {
nrv = cryptojs_ReadArgsAndGenerateKey(cx, &argv[i], &keyids[keyInfoIndex],
for (i=0,keyInfoIndex=0; i<argc; i+=3,keyInfoIndex++) {
nrv = cryptojs_ReadArgsAndGenerateKey(aContext,
const_cast<JS::Value*>(&aArgs[i]),
&keyids[keyInfoIndex],
uiCxt, &slot, willEscrow);
if (NS_FAILED(nrv)) {
if (slot)
PK11_FreeSlot(slot);
nsFreeKeyPairInfo(keyids,numRequests);
return nrv;
aRv.Throw(nrv);
return nullptr;
}
}
// By this time we'd better have a slot for the key gen.
@ -1997,24 +1976,23 @@ nsCrypto::GenerateCRMFRequest(nsIDOMCRMFObject** aReturn)
PK11_FreeSlot(slot);
char *encodedRequest = nsCreateReqFromKeyPairs(keyids,numRequests,
reqDN.ptr(),regToken.ptr(),
authenticator.ptr(),
const_cast<char*>(aReqDN.get()),
const_cast<char*>(aRegToken.get()),
const_cast<char*>(aAuthenticator.get()),
escrowCert);
#ifdef DEBUG_javi
printf ("Created the folloing CRMF request:\n%s\n", encodedRequest);
#endif
if (!encodedRequest) {
nsFreeKeyPairInfo(keyids, numRequests);
return NS_ERROR_FAILURE;
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
nsCRMFObject *newObject = new nsCRMFObject();
newObject->SetCRMFRequest(encodedRequest);
*aReturn = newObject;
//Give a reference to the returnee.
NS_ADDREF(*aReturn);
crmf = newObject;
nsFreeKeyPairInfo(keyids, numRequests);
//
// Post an event on the UI queue so that the JS gets called after
// we return control to the JS layer. Why do we have to this?
// Because when this API was implemented for PSM 1.x w/ Communicator,
@ -2025,32 +2003,43 @@ nsCrypto::GenerateCRMFRequest(nsIDOMCRMFObject** aReturn)
// when the request has been generated.
//
nsCOMPtr<nsIScriptSecurityManager> secMan =
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID);
NS_ENSURE_TRUE(secMan, NS_ERROR_UNEXPECTED);
if (MOZ_UNLIKELY(!secMan)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
nsCOMPtr<nsIPrincipal> principals;
nsresult rv = secMan->GetSubjectPrincipal(getter_AddRefs(principals));
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(principals, NS_ERROR_UNEXPECTED);
if (NS_FAILED(nrv)) {
aRv.Throw(nrv);
return nullptr;
}
if (MOZ_UNLIKELY(!principals)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
nsCryptoRunArgs *args = new nsCryptoRunArgs();
args->m_cx = cx;
args->m_kungFuDeathGrip = GetISupportsFromContext(cx);
args->m_cx = aContext;
args->m_kungFuDeathGrip = GetISupportsFromContext(aContext);
args->m_scope = JS_GetParent(script_obj);
args->m_jsCallback.Adopt(!!jsCallback ? nsCRT::strdup(jsCallback.ptr()) : 0);
if (!aJsCallback.IsVoid()) {
args->m_jsCallback = aJsCallback;
}
args->m_principals = principals;
nsCryptoRunnable *cryptoRunnable = new nsCryptoRunnable(args);
rv = NS_DispatchToMainThread(cryptoRunnable);
if (NS_FAILED(rv))
if (NS_FAILED(rv)) {
aRv.Throw(rv);
delete cryptoRunnable;
}
return rv;
return crmf.forget();
}
@ -2227,14 +2216,14 @@ nsCertListCount(CERTCertList *certList)
return numCerts;
}
//Import user certificates that arrive as a CMMF base64 encoded
//string.
NS_IMETHODIMP
void
nsCrypto::ImportUserCertificates(const nsAString& aNickname,
const nsAString& aCmmfResponse,
bool aDoForcedBackup,
nsAString& aReturn)
nsAString& aReturn,
ErrorResult& aRv)
{
nsNSSShutDownPreventionLock locker;
char *nickname=nullptr, *cmmfResponse=nullptr;
@ -2425,20 +2414,24 @@ nsCrypto::ImportUserCertificates(const nsAString& aNickname,
if (certRepContent) {
CMMF_DestroyCertRepContent(certRepContent);
}
return rv;
if (NS_FAILED(rv)) {
aRv.Throw(rv);
}
}
NS_IMETHODIMP
void
nsCrypto::PopChallengeResponse(const nsAString& aChallenge,
nsAString& aReturn)
nsAString& aReturn,
ErrorResult& aRv)
{
return NS_ERROR_NOT_IMPLEMENTED;
aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
}
NS_IMETHODIMP
nsCrypto::Random(int32_t aNumBytes, nsAString& aReturn)
void
nsCrypto::Random(int32_t aNumBytes, nsAString& aReturn, ErrorResult& aRv)
{
return NS_ERROR_NOT_IMPLEMENTED;
aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
}
static void
@ -2472,46 +2465,27 @@ void signTextOutputCallback(void *arg, const char *buf, unsigned long len)
((nsCString*)arg)->Append(buf, len);
}
NS_IMETHODIMP
nsCrypto::SignText(const nsAString& aStringToSign, const nsAString& aCaOption,
nsAString& aResult)
void
nsCrypto::SignText(JSContext* aContext,
const nsAString& aStringToSign,
const nsAString& aCaOption,
const Sequence<nsCString>& aArgs,
nsAString& aReturn)
{
// XXX This code should return error codes, but we're keeping this
// backwards compatible with NS4.x and so we can't throw exceptions.
NS_NAMED_LITERAL_STRING(internalError, "error:internalError");
aResult.Truncate();
aReturn.Truncate();
nsAXPCNativeCallContext* ncc = nullptr;
nsCOMPtr<nsIXPConnect> xpc(do_GetService(nsIXPConnect::GetCID()));
if (xpc) {
xpc->GetCurrentNativeCallContext(&ncc);
}
if (!ncc) {
aResult.Append(internalError);
return NS_OK;
}
uint32_t argc;
ncc->GetArgc(&argc);
JSContext *cx;
ncc->GetJSContext(&cx);
if (!cx) {
aResult.Append(internalError);
return NS_OK;
}
uint32_t argc = aArgs.Length();
if (!aCaOption.EqualsLiteral("auto") &&
!aCaOption.EqualsLiteral("ask")) {
JS_ReportError(cx, "%s%s", JS_ERROR, "caOption argument must be ask or auto");
NS_WARNING("caOption argument must be ask or auto");
aReturn.Append(internalError);
aResult.Append(internalError);
return NS_OK;
return;
}
// It was decided to always behave as if "ask" were specified.
@ -2519,9 +2493,9 @@ nsCrypto::SignText(const nsAString& aStringToSign, const nsAString& aCaOption,
nsCOMPtr<nsIInterfaceRequestor> uiContext = new PipUIContext;
if (!uiContext) {
aResult.Append(internalError);
aReturn.Append(internalError);
return NS_OK;
return;
}
bool bestOnly = true;
@ -2530,74 +2504,55 @@ nsCrypto::SignText(const nsAString& aStringToSign, const nsAString& aCaOption,
CERT_FindUserCertsByUsage(CERT_GetDefaultCertDB(), certUsageEmailSigner,
bestOnly, validOnly, uiContext);
uint32_t numCAs = argc - 2;
uint32_t numCAs = argc;
if (numCAs > 0) {
JS::Value *argv = nullptr;
ncc->GetArgvPtr(&argv);
nsAutoArrayPtr<JSAutoByteString> caNameBytes(new JSAutoByteString[numCAs]);
if (!caNameBytes) {
aResult.Append(internalError);
return NS_OK;
}
JSAutoRequest ar(cx);
uint32_t i;
for (i = 2; i < argc; ++i) {
JSString *caName = JS_ValueToString(cx, argv[i]);
NS_ENSURE_TRUE(caName, NS_ERROR_OUT_OF_MEMORY);
argv[i] = STRING_TO_JSVAL(caName);
caNameBytes[i - 2].encodeLatin1(cx, caName);
NS_ENSURE_TRUE(!!caNameBytes[i - 2], NS_ERROR_OUT_OF_MEMORY);
}
nsAutoArrayPtr<char*> caNames(new char*[numCAs]);
if (!caNames) {
aResult.Append(internalError);
return NS_OK;
aReturn.Append(internalError);
return;
}
uint32_t i;
for (i = 0; i < numCAs; ++i)
caNames[i] = caNameBytes[i].ptr();
caNames[i] = const_cast<char*>(aArgs[i].get());
if (certList &&
CERT_FilterCertListByCANames(certList, numCAs, caNames,
certUsageEmailSigner) != SECSuccess) {
aResult.Append(internalError);
aReturn.Append(internalError);
return NS_OK;
return;
}
}
if (!certList || CERT_LIST_EMPTY(certList)) {
aResult.AppendLiteral("error:noMatchingCert");
aReturn.AppendLiteral("error:noMatchingCert");
return NS_OK;
return;
}
nsCOMPtr<nsIFormSigningDialog> fsd =
do_CreateInstance(NS_FORMSIGNINGDIALOG_CONTRACTID);
if (!fsd) {
aResult.Append(internalError);
aReturn.Append(internalError);
return NS_OK;
return;
}
nsCOMPtr<nsIDocument> document;
GetDocumentFromContext(cx, getter_AddRefs(document));
GetDocumentFromContext(aContext, getter_AddRefs(document));
if (!document) {
aResult.Append(internalError);
aReturn.Append(internalError);
return NS_OK;
return;
}
// Get the hostname from the URL of the document.
nsIURI* uri = document->GetDocumentURI();
if (!uri) {
aResult.Append(internalError);
aReturn.Append(internalError);
return NS_OK;
return;
}
nsresult rv;
@ -2605,9 +2560,9 @@ nsCrypto::SignText(const nsAString& aStringToSign, const nsAString& aCaOption,
nsCString host;
rv = uri->GetHost(host);
if (NS_FAILED(rv)) {
aResult.Append(internalError);
aReturn.Append(internalError);
return NS_OK;
return;
}
int32_t numberOfCerts = 0;
@ -2620,9 +2575,9 @@ nsCrypto::SignText(const nsAString& aStringToSign, const nsAString& aCaOption,
ScopedCERTCertNicknames nicknames(getNSSCertNicknamesFromCertList(certList));
if (!nicknames) {
aResult.Append(internalError);
aReturn.Append(internalError);
return NS_OK;
return;
}
NS_ASSERTION(nicknames->numnicknames == numberOfCerts,
@ -2630,9 +2585,9 @@ nsCrypto::SignText(const nsAString& aStringToSign, const nsAString& aCaOption,
nsAutoArrayPtr<PRUnichar*> certNicknameList(new PRUnichar*[nicknames->numnicknames * 2]);
if (!certNicknameList) {
aResult.Append(internalError);
aReturn.Append(internalError);
return NS_OK;
return;
}
PRUnichar** certDetailsList = certNicknameList.get() + nicknames->numnicknames;
@ -2661,9 +2616,9 @@ nsCrypto::SignText(const nsAString& aStringToSign, const nsAString& aCaOption,
}
if (certsToUse == 0) {
aResult.Append(internalError);
aReturn.Append(internalError);
return NS_OK;
return;
}
NS_ConvertUTF8toUTF16 utf16Host(host);
@ -2714,22 +2669,22 @@ nsCrypto::SignText(const nsAString& aStringToSign, const nsAString& aCaOption,
}
if (NS_FAILED(rv)) { // something went wrong inside the tryAgain loop
aResult.Append(internalError);
aReturn.Append(internalError);
return NS_OK;
return;
}
if (canceled) {
aResult.AppendLiteral("error:userCancel");
aReturn.AppendLiteral("error:userCancel");
return NS_OK;
return;
}
SECKEYPrivateKey* privKey = PK11_FindKeyByAnyCert(signingCert, uiContext);
if (!privKey) {
aResult.Append(internalError);
aReturn.Append(internalError);
return NS_OK;
return;
}
nsAutoCString charset(document->GetDocumentCharacterSet());
@ -2755,9 +2710,9 @@ nsCrypto::SignText(const nsAString& aStringToSign, const nsAString& aCaOption,
rv = encoder->Convert(PromiseFlatString(aStringToSign).get(),
getter_Copies(buffer));
if (NS_FAILED(rv)) {
aResult.Append(internalError);
aReturn.Append(internalError);
return NS_OK;
return;
}
}
else {
@ -2767,9 +2722,9 @@ nsCrypto::SignText(const nsAString& aStringToSign, const nsAString& aCaOption,
HASHContext *hc = HASH_Create(HASH_AlgSHA1);
if (!hc) {
aResult.Append(internalError);
aReturn.Append(internalError);
return NS_OK;
return;
}
unsigned char hash[SHA1_LENGTH];
@ -2804,9 +2759,9 @@ nsCrypto::SignText(const nsAString& aStringToSign, const nsAString& aCaOption,
}
if (srv != SECSuccess) {
aResult.Append(internalError);
aReturn.Append(internalError);
return NS_OK;
return;
}
SECItem binary_item;
@ -2816,25 +2771,26 @@ nsCrypto::SignText(const nsAString& aStringToSign, const nsAString& aCaOption,
char *result = NSSBase64_EncodeItem(nullptr, nullptr, 0, &binary_item);
if (result) {
AppendASCIItoUTF16(result, aResult);
AppendASCIItoUTF16(result, aReturn);
}
else {
aResult.Append(internalError);
aReturn.Append(internalError);
}
PORT_Free(result);
return NS_OK;
return;
}
//Logout out of all installed PKCS11 tokens.
NS_IMETHODIMP
nsCrypto::Logout()
void
nsCrypto::Logout(ErrorResult& aRv)
{
nsresult rv;
nsCOMPtr<nsINSSComponent> nssComponent(do_GetService(kNSSComponentCID, &rv));
if (NS_FAILED(rv))
return rv;
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return;
}
{
nsNSSShutDownPreventionLock locker;
@ -2842,20 +2798,16 @@ nsCrypto::Logout()
SSL_ClearSessionCache();
}
return nssComponent->LogoutAuthenticatedPK11();
rv = nssComponent->LogoutAuthenticatedPK11();
if (NS_FAILED(rv)) {
aRv.Throw(rv);
}
}
NS_IMETHODIMP
nsCrypto::DisableRightClick()
void
nsCrypto::DisableRightClick(ErrorResult& aRv)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsCrypto::GetRandomValues(const JS::Value& aData, JSContext *cx,
JS::Value* _retval)
{
return mozilla::dom::Crypto::GetRandomValues(aData, cx, _retval);
aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
}
nsCRMFObject::nsCRMFObject()

Просмотреть файл

@ -6,6 +6,8 @@
#ifndef _nsCrypto_h_
#define _nsCrypto_h_
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/ErrorResult.h"
#ifndef MOZ_DISABLE_CRYPTOLEGACY
#include "Crypto.h"
#include "nsCOMPtr.h"
@ -23,7 +25,6 @@
class nsIPSMComponent;
class nsIDOMScriptObjectFactory;
class nsCRMFObject : public nsIDOMCRMFObject
{
public:
@ -41,7 +42,6 @@ private:
nsString mBase64Request;
};
class nsCrypto: public mozilla::dom::Crypto
{
public:
@ -54,6 +54,46 @@ public:
// implements the legacy methods.
NS_DECL_NSIDOMCRYPTO
virtual bool EnableSmartCardEvents() MOZ_OVERRIDE;
virtual void SetEnableSmartCardEvents(bool aEnable,
mozilla::ErrorResult& aRv) MOZ_OVERRIDE;
virtual void GetVersion(nsString& aVersion) MOZ_OVERRIDE;
virtual already_AddRefed<nsIDOMCRMFObject>
GenerateCRMFRequest(JSContext* aContext,
const nsCString& aReqDN,
const nsCString& aRegToken,
const nsCString& aAuthenticator,
const nsCString& aEaCert,
const nsCString& aJsCallback,
const mozilla::dom::Sequence<JS::Value>& aArgs,
mozilla::ErrorResult& aRv) MOZ_OVERRIDE;
virtual void ImportUserCertificates(const nsAString& aNickname,
const nsAString& aCmmfResponse,
bool aDoForcedBackup,
nsAString& aReturn,
mozilla::ErrorResult& aRv) MOZ_OVERRIDE;
virtual void PopChallengeResponse(const nsAString& aChallenge,
nsAString& aReturn,
mozilla::ErrorResult& aRv) MOZ_OVERRIDE;
virtual void Random(int32_t aNumBytes,
nsAString& aReturn,
mozilla::ErrorResult& aRv) MOZ_OVERRIDE;
virtual void SignText(JSContext* aContext,
const nsAString& aStringToSign,
const nsAString& aCaOption,
const mozilla::dom::Sequence<nsCString>& aArgs,
nsAString& aReturn) MOZ_OVERRIDE;
virtual void Logout(mozilla::ErrorResult& aRv) MOZ_OVERRIDE;
virtual void DisableRightClick(mozilla::ErrorResult& aRv) MOZ_OVERRIDE;
private:
static already_AddRefed<nsIPrincipal> GetScriptPrincipal(JSContext *cx);

Просмотреть файл

@ -125,11 +125,14 @@ DebuggerTransport.prototype = {
onStopRequest:
makeInfallible(function DT_onStopRequest(aRequest, aContext, aStatus) {
this.close();
if (this.hooks) {
this.hooks.onClosed(aStatus);
this.hooks = null;
let self = this;
Services.tm.currentThread.dispatch(makeInfallible(function() {
self.close();
if (self.hooks) {
self.hooks.onClosed(aStatus);
self.hooks = null;
}
}, "DebuggerTransport instance's this.close"), 0);
}, "DebuggerTransport.prototype.onStopRequest"),
onDataAvailable: