зеркало из https://github.com/mozilla/gecko-dev.git
Merge b2g-inbound to m-c
This commit is contained in:
Коммит
5c34d25a48
|
@ -1,4 +1,4 @@
|
||||||
{
|
{
|
||||||
"revision": "7669b3265def0eed0473acd938897704007afaf3",
|
"revision": "5e7a8bbe525c0a43852770665ce9498fdb93ea81",
|
||||||
"repo_path": "/integration/gaia-central"
|
"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,
|
* 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/. */
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
#include "Crypto.h"
|
#include "Crypto.h"
|
||||||
#include "nsIDOMClassInfo.h"
|
|
||||||
#include "DOMError.h"
|
#include "DOMError.h"
|
||||||
#include "nsString.h"
|
#include "nsString.h"
|
||||||
#include "jsapi.h"
|
|
||||||
#include "jsfriendapi.h"
|
#include "jsfriendapi.h"
|
||||||
#include "nsIServiceManager.h"
|
#include "nsIServiceManager.h"
|
||||||
#include "nsCOMPtr.h"
|
#include "nsCOMPtr.h"
|
||||||
#include "nsIRandomGenerator.h"
|
#include "nsIRandomGenerator.h"
|
||||||
|
|
||||||
#include "mozilla/dom/ContentChild.h"
|
#include "mozilla/dom/ContentChild.h"
|
||||||
|
#include "mozilla/dom/CryptoBinding.h"
|
||||||
|
|
||||||
using mozilla::dom::ContentChild;
|
using mozilla::dom::ContentChild;
|
||||||
|
|
||||||
|
@ -20,18 +19,21 @@ using namespace js::ArrayBufferView;
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
namespace dom {
|
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(nsISupports)
|
||||||
NS_INTERFACE_MAP_ENTRY(nsIDOMCrypto)
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCrypto)
|
||||||
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(Crypto)
|
|
||||||
NS_INTERFACE_MAP_END
|
NS_INTERFACE_MAP_END
|
||||||
|
|
||||||
NS_IMPL_ADDREF(Crypto)
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(Crypto)
|
||||||
NS_IMPL_RELEASE(Crypto)
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(Crypto)
|
||||||
|
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(Crypto, mWindow)
|
||||||
|
|
||||||
Crypto::Crypto()
|
Crypto::Crypto()
|
||||||
{
|
{
|
||||||
MOZ_COUNT_CTOR(Crypto);
|
MOZ_COUNT_CTOR(Crypto);
|
||||||
|
SetIsDOMBinding();
|
||||||
}
|
}
|
||||||
|
|
||||||
Crypto::~Crypto()
|
Crypto::~Crypto()
|
||||||
|
@ -39,23 +41,25 @@ Crypto::~Crypto()
|
||||||
MOZ_COUNT_DTOR(Crypto);
|
MOZ_COUNT_DTOR(Crypto);
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
void
|
||||||
Crypto::GetRandomValues(const JS::Value& aData, JSContext *cx,
|
Crypto::Init(nsIDOMWindow* aWindow)
|
||||||
JS::Value* _retval)
|
{
|
||||||
|
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");
|
NS_ABORT_IF_FALSE(NS_IsMainThread(), "Called on the wrong thread");
|
||||||
|
|
||||||
// Make sure this is a JavaScript object
|
JS::Rooted<JSObject*> view(aCx, aArray.Obj());
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Throw if the wrong type of ArrayBufferView is passed in
|
// Throw if the wrong type of ArrayBufferView is passed in
|
||||||
// (Part of the Web Crypto API spec)
|
// (Part of the Web Crypto API spec)
|
||||||
|
@ -69,29 +73,28 @@ Crypto::GetRandomValues(const JS::Value& aData, JSContext *cx,
|
||||||
case TYPE_UINT32:
|
case TYPE_UINT32:
|
||||||
break;
|
break;
|
||||||
default:
|
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) {
|
if (dataLen == 0) {
|
||||||
NS_WARNING("ArrayBufferView length is 0, cannot continue");
|
NS_WARNING("ArrayBufferView length is 0, cannot continue");
|
||||||
return NS_OK;
|
return view;
|
||||||
} else if (dataLen > 65536) {
|
} 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);
|
uint8_t* data = aArray.Data();
|
||||||
NS_ENSURE_TRUE(dataptr, NS_ERROR_FAILURE);
|
|
||||||
unsigned char* data =
|
|
||||||
static_cast<unsigned char*>(dataptr);
|
|
||||||
|
|
||||||
if (XRE_GetProcessType() != GeckoProcessType_Default) {
|
if (XRE_GetProcessType() != GeckoProcessType_Default) {
|
||||||
InfallibleTArray<uint8_t> randomValues;
|
InfallibleTArray<uint8_t> randomValues;
|
||||||
// Tell the parent process to generate random values via PContent
|
// Tell the parent process to generate random values via PContent
|
||||||
ContentChild* cc = ContentChild::GetSingleton();
|
ContentChild* cc = ContentChild::GetSingleton();
|
||||||
if (!cc->SendGetRandomValues(dataLen, &randomValues)) {
|
if (!cc->SendGetRandomValues(dataLen, &randomValues)) {
|
||||||
return NS_ERROR_FAILURE;
|
aRv.Throw(NS_ERROR_FAILURE);
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
NS_ASSERTION(dataLen == randomValues.Length(),
|
NS_ASSERTION(dataLen == randomValues.Length(),
|
||||||
"Invalid length returned from parent process!");
|
"Invalid length returned from parent process!");
|
||||||
|
@ -100,28 +103,21 @@ Crypto::GetRandomValues(const JS::Value& aData, JSContext *cx,
|
||||||
uint8_t *buf = GetRandomValues(dataLen);
|
uint8_t *buf = GetRandomValues(dataLen);
|
||||||
|
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
return NS_ERROR_FAILURE;
|
aRv.Throw(NS_ERROR_FAILURE);
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(data, buf, dataLen);
|
memcpy(data, buf, dataLen);
|
||||||
NS_Free(buf);
|
NS_Free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
*_retval = OBJECT_TO_JSVAL(view);
|
return view;
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef MOZ_DISABLE_CRYPTOLEGACY
|
#ifndef MOZ_DISABLE_CRYPTOLEGACY
|
||||||
// Stub out the legacy nsIDOMCrypto methods. The actual
|
// Stub out the legacy nsIDOMCrypto methods. The actual
|
||||||
// implementations are in security/manager/ssl/src/nsCrypto.{cpp,h}
|
// implementations are in security/manager/ssl/src/nsCrypto.{cpp,h}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
Crypto::GetVersion(nsAString & aVersion)
|
|
||||||
{
|
|
||||||
return NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
Crypto::GetEnableSmartCardEvents(bool *aEnableSmartCardEvents)
|
Crypto::GetEnableSmartCardEvents(bool *aEnableSmartCardEvents)
|
||||||
{
|
{
|
||||||
|
@ -133,61 +129,14 @@ Crypto::SetEnableSmartCardEvents(bool aEnableSmartCardEvents)
|
||||||
{
|
{
|
||||||
return NS_ERROR_NOT_IMPLEMENTED;
|
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
|
#endif
|
||||||
|
|
||||||
uint8_t*
|
/* static */ uint8_t*
|
||||||
Crypto::GetRandomValues(uint32_t aLength)
|
Crypto::GetRandomValues(uint32_t aLength)
|
||||||
{
|
{
|
||||||
nsCOMPtr<nsIRandomGenerator> randomGenerator;
|
nsCOMPtr<nsIRandomGenerator> randomGenerator;
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
randomGenerator =
|
randomGenerator = do_GetService("@mozilla.org/security/random-generator;1");
|
||||||
do_GetService("@mozilla.org/security/random-generator;1");
|
|
||||||
NS_ENSURE_TRUE(randomGenerator, nullptr);
|
NS_ENSURE_TRUE(randomGenerator, nullptr);
|
||||||
|
|
||||||
uint8_t* buf;
|
uint8_t* buf;
|
||||||
|
|
|
@ -8,25 +8,89 @@
|
||||||
#include "nsIDOMCrypto.h"
|
#include "nsIDOMCrypto.h"
|
||||||
#else
|
#else
|
||||||
#include "nsIDOMCryptoLegacy.h"
|
#include "nsIDOMCryptoLegacy.h"
|
||||||
|
#include "nsIDOMCRMFObject.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "nsPIDOMWindow.h"
|
||||||
|
#include "nsWrapperCache.h"
|
||||||
|
#include "mozilla/dom/BindingDeclarations.h"
|
||||||
|
#include "mozilla/dom/TypedArray.h"
|
||||||
#define NS_DOMCRYPTO_CID \
|
#define NS_DOMCRYPTO_CID \
|
||||||
{0x929d9320, 0x251e, 0x11d4, { 0x8a, 0x7c, 0x00, 0x60, 0x08, 0xc8, 0x44, 0xc3} }
|
{0x929d9320, 0x251e, 0x11d4, { 0x8a, 0x7c, 0x00, 0x60, 0x08, 0xc8, 0x44, 0xc3} }
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
namespace dom {
|
namespace dom {
|
||||||
|
|
||||||
class Crypto : public nsIDOMCrypto
|
class Crypto : public nsIDOMCrypto,
|
||||||
|
public nsWrapperCache
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Crypto();
|
Crypto();
|
||||||
virtual ~Crypto();
|
virtual ~Crypto();
|
||||||
|
|
||||||
NS_DECL_ISUPPORTS
|
|
||||||
NS_DECL_NSIDOMCRYPTO
|
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*
|
static uint8_t*
|
||||||
GetRandomValues(uint32_t aLength);
|
GetRandomValues(uint32_t aLength);
|
||||||
|
|
||||||
|
private:
|
||||||
|
nsCOMPtr<nsPIDOMWindow> mWindow;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace dom
|
} // namespace dom
|
||||||
|
|
|
@ -955,7 +955,7 @@ Navigator::GetDeviceStorages(const nsAString& aType,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsDOMDeviceStorage::CreateDeviceStoragesFor(mWindow, aType, aStores, false);
|
nsDOMDeviceStorage::CreateDeviceStoragesFor(mWindow, aType, aStores);
|
||||||
|
|
||||||
mDeviceStorageStores.AppendElements(aStores);
|
mDeviceStorageStores.AppendElements(aStores);
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,9 +160,6 @@
|
||||||
#include "nsIDOMXULCommandDispatcher.h"
|
#include "nsIDOMXULCommandDispatcher.h"
|
||||||
#ifndef MOZ_DISABLE_CRYPTOLEGACY
|
#ifndef MOZ_DISABLE_CRYPTOLEGACY
|
||||||
#include "nsIDOMCRMFObject.h"
|
#include "nsIDOMCRMFObject.h"
|
||||||
#include "nsIDOMCryptoLegacy.h"
|
|
||||||
#else
|
|
||||||
#include "nsIDOMCrypto.h"
|
|
||||||
#endif
|
#endif
|
||||||
#include "nsIControllers.h"
|
#include "nsIControllers.h"
|
||||||
#include "nsISelection.h"
|
#include "nsISelection.h"
|
||||||
|
@ -319,7 +316,6 @@ const uint32_t kDOMClassInfo_##_dom_class##_interfaces = \
|
||||||
#ifndef MOZ_DISABLE_CRYPTOLEGACY
|
#ifndef MOZ_DISABLE_CRYPTOLEGACY
|
||||||
DOMCI_DATA_NO_CLASS(CRMFObject)
|
DOMCI_DATA_NO_CLASS(CRMFObject)
|
||||||
#endif
|
#endif
|
||||||
DOMCI_DATA_NO_CLASS(Crypto)
|
|
||||||
|
|
||||||
DOMCI_DATA_NO_CLASS(ContentFrameMessageManager)
|
DOMCI_DATA_NO_CLASS(ContentFrameMessageManager)
|
||||||
DOMCI_DATA_NO_CLASS(ChromeMessageBroadcaster)
|
DOMCI_DATA_NO_CLASS(ChromeMessageBroadcaster)
|
||||||
|
@ -502,8 +498,6 @@ static nsDOMClassInfoData sClassInfoData[] = {
|
||||||
NS_DEFINE_CLASSINFO_DATA(CRMFObject, nsDOMGenericSH,
|
NS_DEFINE_CLASSINFO_DATA(CRMFObject, nsDOMGenericSH,
|
||||||
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
||||||
#endif
|
#endif
|
||||||
NS_DEFINE_CLASSINFO_DATA(Crypto, nsDOMGenericSH,
|
|
||||||
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
|
||||||
|
|
||||||
// DOM Chrome Window class.
|
// DOM Chrome Window class.
|
||||||
NS_DEFINE_CLASSINFO_DATA(ChromeWindow, nsWindowSH,
|
NS_DEFINE_CLASSINFO_DATA(ChromeWindow, nsWindowSH,
|
||||||
|
@ -1340,10 +1334,6 @@ nsDOMClassInfo::Init()
|
||||||
DOM_CLASSINFO_MAP_END
|
DOM_CLASSINFO_MAP_END
|
||||||
#endif
|
#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_MAP_BEGIN_NO_CLASS_IF(ChromeWindow, nsIDOMWindow)
|
||||||
DOM_CLASSINFO_WINDOW_MAP_ENTRIES(true)
|
DOM_CLASSINFO_WINDOW_MAP_ENTRIES(true)
|
||||||
DOM_CLASSINFO_MAP_ENTRY(nsIDOMChromeWindow)
|
DOM_CLASSINFO_MAP_ENTRY(nsIDOMChromeWindow)
|
||||||
|
|
|
@ -45,7 +45,6 @@ DOMCI_CLASS(TreeContentView)
|
||||||
#ifndef MOZ_DISABLE_CRYPTOLEGACY
|
#ifndef MOZ_DISABLE_CRYPTOLEGACY
|
||||||
DOMCI_CLASS(CRMFObject)
|
DOMCI_CLASS(CRMFObject)
|
||||||
#endif
|
#endif
|
||||||
DOMCI_CLASS(Crypto)
|
|
||||||
|
|
||||||
// DOM Chrome Window class, almost identical to Window
|
// DOM Chrome Window class, almost identical to Window
|
||||||
DOMCI_CLASS(ChromeWindow)
|
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(mPersonalbar)
|
||||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mStatusbar)
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mStatusbar)
|
||||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mScrollbars)
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mScrollbars)
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCrypto)
|
||||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||||
|
|
||||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindow)
|
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(mPersonalbar)
|
||||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mStatusbar)
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mStatusbar)
|
||||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mScrollbars)
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mScrollbars)
|
||||||
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mCrypto)
|
||||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||||
|
|
||||||
struct TraceData
|
struct TraceData
|
||||||
|
@ -3878,10 +3880,13 @@ nsGlobalWindow::GetCrypto(nsIDOMCrypto** aCrypto)
|
||||||
|
|
||||||
if (!mCrypto) {
|
if (!mCrypto) {
|
||||||
#ifndef MOZ_DISABLE_CRYPTOLEGACY
|
#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
|
#else
|
||||||
mCrypto = new Crypto();
|
mCrypto = new Crypto();
|
||||||
#endif
|
#endif
|
||||||
|
mCrypto->Init(this);
|
||||||
}
|
}
|
||||||
NS_IF_ADDREF(*aCrypto = mCrypto);
|
NS_IF_ADDREF(*aCrypto = mCrypto);
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
|
|
@ -206,6 +206,11 @@ DOMInterfaces = {
|
||||||
'headerFile': 'nsGeoPosition.h'
|
'headerFile': 'nsGeoPosition.h'
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'Crypto' : {
|
||||||
|
'implicitJSContext': [ 'generateCRMFRequest', 'signText' ],
|
||||||
|
'headerFile': 'Crypto.h'
|
||||||
|
},
|
||||||
|
|
||||||
'CSS': {
|
'CSS': {
|
||||||
'concrete': False,
|
'concrete': False,
|
||||||
},
|
},
|
||||||
|
|
|
@ -50,9 +50,10 @@ public:
|
||||||
DeviceStorageFile(const nsAString& aStorageType,
|
DeviceStorageFile(const nsAString& aStorageType,
|
||||||
const nsAString& aStorageName,
|
const nsAString& aStorageName,
|
||||||
const nsAString& aPath);
|
const nsAString& aPath);
|
||||||
// Used for enumerations. When you call Enumerate, you can pass in a directory to enumerate
|
// Used for enumerations. When you call Enumerate, you can pass in a
|
||||||
// and the results that are returned are relative to that directory, files related to an
|
// directory to enumerate and the results that are returned are relative to
|
||||||
// enumeration need to know the "root of the enumeration" directory.
|
// that directory, files related to an enumeration need to know the "root of
|
||||||
|
// the enumeration" directory.
|
||||||
DeviceStorageFile(const nsAString& aStorageType,
|
DeviceStorageFile(const nsAString& aStorageType,
|
||||||
const nsAString& aStorageName,
|
const nsAString& aStorageName,
|
||||||
const nsAString& aRootDir,
|
const nsAString& aRootDir,
|
||||||
|
@ -61,15 +62,15 @@ public:
|
||||||
void SetPath(const nsAString& aPath);
|
void SetPath(const nsAString& aPath);
|
||||||
void SetEditable(bool aEditable);
|
void SetEditable(bool aEditable);
|
||||||
|
|
||||||
static already_AddRefed<DeviceStorageFile> CreateUnique(nsAString& aFileName,
|
static already_AddRefed<DeviceStorageFile>
|
||||||
uint32_t aFileType,
|
CreateUnique(nsAString& aFileName,
|
||||||
uint32_t aFileAttributes);
|
uint32_t aFileType,
|
||||||
|
uint32_t aFileAttributes);
|
||||||
|
|
||||||
NS_DECL_THREADSAFE_ISUPPORTS
|
NS_DECL_THREADSAFE_ISUPPORTS
|
||||||
|
|
||||||
bool IsAvailable();
|
bool IsAvailable();
|
||||||
bool IsComposite();
|
void GetFullPath(nsAString& aFullPath);
|
||||||
void GetCompositePath(nsAString& aCompositePath);
|
|
||||||
|
|
||||||
// we want to make sure that the names of file can't reach
|
// we want to make sure that the names of file can't reach
|
||||||
// outside of the type of storage the user asked for.
|
// outside of the type of storage the user asked for.
|
||||||
|
@ -102,7 +103,6 @@ private:
|
||||||
void Init();
|
void Init();
|
||||||
void NormalizeFilePath();
|
void NormalizeFilePath();
|
||||||
void AppendRelativePath(const nsAString& aPath);
|
void AppendRelativePath(const nsAString& aPath);
|
||||||
void GetStatusInternal(nsAString& aStorageName, nsAString& aStatus);
|
|
||||||
void AccumDirectoryUsage(nsIFile* aFile,
|
void AccumDirectoryUsage(nsIFile* aFile,
|
||||||
uint64_t* aPicturesSoFar,
|
uint64_t* aPicturesSoFar,
|
||||||
uint64_t* aVideosSoFar,
|
uint64_t* aVideosSoFar,
|
||||||
|
@ -153,11 +153,14 @@ public:
|
||||||
|
|
||||||
NS_DECL_NSIOBSERVER
|
NS_DECL_NSIOBSERVER
|
||||||
NS_DECL_NSIDOMEVENTTARGET
|
NS_DECL_NSIDOMEVENTTARGET
|
||||||
virtual void AddEventListener(const nsAString& aType,
|
|
||||||
nsIDOMEventListener* aListener,
|
virtual void
|
||||||
bool aUseCapture,
|
AddEventListener(const nsAString& aType,
|
||||||
const mozilla::dom::Nullable<bool>& aWantsUntrusted,
|
nsIDOMEventListener* aListener,
|
||||||
ErrorResult& aRv) MOZ_OVERRIDE;
|
bool aUseCapture,
|
||||||
|
const mozilla::dom::Nullable<bool>& aWantsUntrusted,
|
||||||
|
ErrorResult& aRv) MOZ_OVERRIDE;
|
||||||
|
|
||||||
virtual void RemoveEventListener(const nsAString& aType,
|
virtual void RemoveEventListener(const nsAString& aType,
|
||||||
nsIDOMEventListener* aListener,
|
nsIDOMEventListener* aListener,
|
||||||
bool aUseCapture,
|
bool aUseCapture,
|
||||||
|
@ -165,14 +168,17 @@ public:
|
||||||
|
|
||||||
nsDOMDeviceStorage();
|
nsDOMDeviceStorage();
|
||||||
|
|
||||||
nsresult Init(nsPIDOMWindow* aWindow, const nsAString& aType,
|
|
||||||
nsTArray<nsRefPtr<nsDOMDeviceStorage> >& aStores);
|
|
||||||
nsresult Init(nsPIDOMWindow* aWindow, const nsAString& aType,
|
nsresult Init(nsPIDOMWindow* aWindow, const nsAString& aType,
|
||||||
const nsAString& aVolName);
|
const nsAString& aVolName);
|
||||||
|
|
||||||
bool IsAvailable();
|
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
|
// WebIDL
|
||||||
nsPIDOMWindow*
|
nsPIDOMWindow*
|
||||||
|
@ -228,24 +234,26 @@ public:
|
||||||
|
|
||||||
// Uses XPCOM GetStorageName
|
// Uses XPCOM GetStorageName
|
||||||
|
|
||||||
static void CreateDeviceStorageFor(nsPIDOMWindow* aWin,
|
static void
|
||||||
const nsAString& aType,
|
CreateDeviceStorageFor(nsPIDOMWindow* aWin,
|
||||||
nsDOMDeviceStorage** aStore);
|
const nsAString& aType,
|
||||||
|
nsDOMDeviceStorage** aStore);
|
||||||
|
|
||||||
|
static void
|
||||||
|
CreateDeviceStoragesFor(nsPIDOMWindow* aWin,
|
||||||
|
const nsAString& aType,
|
||||||
|
nsTArray<nsRefPtr<nsDOMDeviceStorage> >& aStores);
|
||||||
|
|
||||||
static void CreateDeviceStoragesFor(nsPIDOMWindow* aWin,
|
|
||||||
const nsAString& aType,
|
|
||||||
nsTArray<nsRefPtr<nsDOMDeviceStorage> >& aStores,
|
|
||||||
bool aCompositeComponent);
|
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
|
|
||||||
static void GetOrderedVolumeNames(nsTArray<nsString>& aVolumeNames);
|
static void GetOrderedVolumeNames(nsTArray<nsString>& aVolumeNames);
|
||||||
|
|
||||||
static void GetWritableStorageName(const nsAString& aStorageType,
|
static void GetDefaultStorageName(const nsAString& aStorageType,
|
||||||
nsAString &aStorageName);
|
nsAString &aStorageName);
|
||||||
|
|
||||||
static bool ParseCompositePath(const nsAString& aCompositePath,
|
static bool ParseFullPath(const nsAString& aFullPath,
|
||||||
nsAString& aOutStorageName,
|
nsAString& aOutStorageName,
|
||||||
nsAString& aOutStoragePath);
|
nsAString& aOutStoragePath);
|
||||||
private:
|
private:
|
||||||
~nsDOMDeviceStorage();
|
~nsDOMDeviceStorage();
|
||||||
|
|
||||||
|
@ -268,25 +276,11 @@ private:
|
||||||
nsString mStorageType;
|
nsString mStorageType;
|
||||||
nsCOMPtr<nsIFile> mRootDirectory;
|
nsCOMPtr<nsIFile> mRootDirectory;
|
||||||
nsString mStorageName;
|
nsString mStorageName;
|
||||||
bool mCompositeComponent;
|
|
||||||
|
|
||||||
// A composite device storage object is one which front-ends for multiple
|
already_AddRefed<nsDOMDeviceStorage> GetStorage(const nsAString& aFullPath,
|
||||||
// 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,
|
|
||||||
nsAString& aOutStoragePath);
|
nsAString& aOutStoragePath);
|
||||||
already_AddRefed<nsDOMDeviceStorage> GetStorageByName(const nsAString &aStorageName);
|
already_AddRefed<nsDOMDeviceStorage>
|
||||||
|
GetStorageByName(const nsAString &aStorageName);
|
||||||
|
|
||||||
nsCOMPtr<nsIPrincipal> mPrincipal;
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
||||||
|
|
||||||
|
@ -306,8 +300,7 @@ private:
|
||||||
static mozilla::StaticRefPtr<VolumeNameCache> sVolumeNameCache;
|
static mozilla::StaticRefPtr<VolumeNameCache> sVolumeNameCache;
|
||||||
|
|
||||||
#ifdef MOZ_WIDGET_GONK
|
#ifdef MOZ_WIDGET_GONK
|
||||||
void DispatchMountChangeEvent(nsAString& aVolumeName,
|
void DispatchMountChangeEvent(nsAString& aVolumeStatus);
|
||||||
nsAString& aVolumeStatus);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// nsIDOMDeviceStorage.type
|
// nsIDOMDeviceStorage.type
|
||||||
|
|
|
@ -33,7 +33,8 @@ DeviceStorageRequestChild::~DeviceStorageRequestChild() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
DeviceStorageRequestChild::Recv__delete__(const DeviceStorageResponseValue& aValue)
|
DeviceStorageRequestChild::
|
||||||
|
Recv__delete__(const DeviceStorageResponseValue& aValue)
|
||||||
{
|
{
|
||||||
if (mCallback) {
|
if (mCallback) {
|
||||||
mCallback->RequestComplete();
|
mCallback->RequestComplete();
|
||||||
|
@ -51,11 +52,11 @@ DeviceStorageRequestChild::Recv__delete__(const DeviceStorageResponseValue& aVal
|
||||||
|
|
||||||
case DeviceStorageResponseValue::TSuccessResponse:
|
case DeviceStorageResponseValue::TSuccessResponse:
|
||||||
{
|
{
|
||||||
nsString compositePath;
|
nsString fullPath;
|
||||||
mFile->GetCompositePath(compositePath);
|
mFile->GetFullPath(fullPath);
|
||||||
AutoJSContext cx;
|
AutoJSContext cx;
|
||||||
JS::Rooted<JS::Value> result(cx,
|
JS::Rooted<JS::Value> result(cx,
|
||||||
StringToJsval(mRequest->GetOwner(), compositePath));
|
StringToJsval(mRequest->GetOwner(), fullPath));
|
||||||
mRequest->FireSuccess(result);
|
mRequest->FireSuccess(result);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -105,14 +106,14 @@ DeviceStorageRequestChild::Recv__delete__(const DeviceStorageResponseValue& aVal
|
||||||
case DeviceStorageResponseValue::TEnumerationResponse:
|
case DeviceStorageResponseValue::TEnumerationResponse:
|
||||||
{
|
{
|
||||||
EnumerationResponse r = aValue;
|
EnumerationResponse r = aValue;
|
||||||
nsDOMDeviceStorageCursor* cursor = static_cast<nsDOMDeviceStorageCursor*>(mRequest.get());
|
nsDOMDeviceStorageCursor* cursor
|
||||||
|
= static_cast<nsDOMDeviceStorageCursor*>(mRequest.get());
|
||||||
|
|
||||||
uint32_t count = r.paths().Length();
|
uint32_t count = r.paths().Length();
|
||||||
for (uint32_t i = 0; i < count; i++) {
|
for (uint32_t i = 0; i < count; i++) {
|
||||||
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(r.type(),
|
nsRefPtr<DeviceStorageFile> dsf
|
||||||
r.paths()[i].storageName(),
|
= new DeviceStorageFile(r.type(), r.paths()[i].storageName(),
|
||||||
r.rootdir(),
|
r.rootdir(), r.paths()[i].name());
|
||||||
r.paths()[i].name());
|
|
||||||
cursor->mFiles.AppendElement(dsf);
|
cursor->mFiles.AppendElement(dsf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,7 +132,8 @@ DeviceStorageRequestChild::Recv__delete__(const DeviceStorageResponseValue& aVal
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DeviceStorageRequestChild::SetCallback(DeviceStorageRequestChildCallback *aCallback)
|
DeviceStorageRequestChild::
|
||||||
|
SetCallback(DeviceStorageRequestChildCallback *aCallback)
|
||||||
{
|
{
|
||||||
mCallback = aCallback;
|
mCallback = aCallback;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,14 +18,16 @@ namespace mozilla {
|
||||||
namespace dom {
|
namespace dom {
|
||||||
namespace devicestorage {
|
namespace devicestorage {
|
||||||
|
|
||||||
DeviceStorageRequestParent::DeviceStorageRequestParent(const DeviceStorageParams& aParams)
|
DeviceStorageRequestParent::DeviceStorageRequestParent(
|
||||||
|
const DeviceStorageParams& aParams)
|
||||||
: mParams(aParams)
|
: mParams(aParams)
|
||||||
, mMutex("DeviceStorageRequestParent::mMutex")
|
, mMutex("DeviceStorageRequestParent::mMutex")
|
||||||
, mActorDestoryed(false)
|
, mActorDestoryed(false)
|
||||||
{
|
{
|
||||||
MOZ_COUNT_CTOR(DeviceStorageRequestParent);
|
MOZ_COUNT_CTOR(DeviceStorageRequestParent);
|
||||||
|
|
||||||
DebugOnly<DeviceStorageUsedSpaceCache*> usedSpaceCache = DeviceStorageUsedSpaceCache::CreateOrGet();
|
DebugOnly<DeviceStorageUsedSpaceCache*> usedSpaceCache
|
||||||
|
= DeviceStorageUsedSpaceCache::CreateOrGet();
|
||||||
NS_ASSERTION(usedSpaceCache, "DeviceStorageUsedSpaceCache is null");
|
NS_ASSERTION(usedSpaceCache, "DeviceStorageUsedSpaceCache is null");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +50,8 @@ DeviceStorageRequestParent::Dispatch()
|
||||||
|
|
||||||
nsRefPtr<CancelableRunnable> r = new WriteFileEvent(this, dsf, stream);
|
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");
|
NS_ASSERTION(target, "Must have stream transport service");
|
||||||
target->Dispatch(r, NS_DISPATCH_NORMAL);
|
target->Dispatch(r, NS_DISPATCH_NORMAL);
|
||||||
break;
|
break;
|
||||||
|
@ -58,10 +61,12 @@ DeviceStorageRequestParent::Dispatch()
|
||||||
{
|
{
|
||||||
DeviceStorageGetParams p = mParams;
|
DeviceStorageGetParams p = mParams;
|
||||||
nsRefPtr<DeviceStorageFile> dsf =
|
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);
|
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");
|
NS_ASSERTION(target, "Must have stream transport service");
|
||||||
target->Dispatch(r, NS_DISPATCH_NORMAL);
|
target->Dispatch(r, NS_DISPATCH_NORMAL);
|
||||||
break;
|
break;
|
||||||
|
@ -75,7 +80,8 @@ DeviceStorageRequestParent::Dispatch()
|
||||||
new DeviceStorageFile(p.type(), p.storageName(), p.relpath());
|
new DeviceStorageFile(p.type(), p.storageName(), p.relpath());
|
||||||
nsRefPtr<CancelableRunnable> r = new DeleteFileEvent(this, dsf);
|
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");
|
NS_ASSERTION(target, "Must have stream transport service");
|
||||||
target->Dispatch(r, NS_DISPATCH_NORMAL);
|
target->Dispatch(r, NS_DISPATCH_NORMAL);
|
||||||
break;
|
break;
|
||||||
|
@ -89,7 +95,8 @@ DeviceStorageRequestParent::Dispatch()
|
||||||
new DeviceStorageFile(p.type(), p.storageName());
|
new DeviceStorageFile(p.type(), p.storageName());
|
||||||
nsRefPtr<FreeSpaceFileEvent> r = new FreeSpaceFileEvent(this, dsf);
|
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");
|
NS_ASSERTION(target, "Must have stream transport service");
|
||||||
target->Dispatch(r, NS_DISPATCH_NORMAL);
|
target->Dispatch(r, NS_DISPATCH_NORMAL);
|
||||||
break;
|
break;
|
||||||
|
@ -97,7 +104,8 @@ DeviceStorageRequestParent::Dispatch()
|
||||||
|
|
||||||
case DeviceStorageParams::TDeviceStorageUsedSpaceParams:
|
case DeviceStorageParams::TDeviceStorageUsedSpaceParams:
|
||||||
{
|
{
|
||||||
DeviceStorageUsedSpaceCache* usedSpaceCache = DeviceStorageUsedSpaceCache::CreateOrGet();
|
DeviceStorageUsedSpaceCache* usedSpaceCache
|
||||||
|
= DeviceStorageUsedSpaceCache::CreateOrGet();
|
||||||
NS_ASSERTION(usedSpaceCache, "DeviceStorageUsedSpaceCache is null");
|
NS_ASSERTION(usedSpaceCache, "DeviceStorageUsedSpaceCache is null");
|
||||||
|
|
||||||
DeviceStorageUsedSpaceParams p = mParams;
|
DeviceStorageUsedSpaceParams p = mParams;
|
||||||
|
@ -116,7 +124,8 @@ DeviceStorageRequestParent::Dispatch()
|
||||||
|
|
||||||
nsRefPtr<DeviceStorageFile> dsf =
|
nsRefPtr<DeviceStorageFile> dsf =
|
||||||
new DeviceStorageFile(p.type(), p.storageName());
|
new DeviceStorageFile(p.type(), p.storageName());
|
||||||
nsRefPtr<PostAvailableResultEvent> r = new PostAvailableResultEvent(this, dsf);
|
nsRefPtr<PostAvailableResultEvent> r
|
||||||
|
= new PostAvailableResultEvent(this, dsf);
|
||||||
NS_DispatchToMainThread(r);
|
NS_DispatchToMainThread(r);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -125,10 +134,13 @@ DeviceStorageRequestParent::Dispatch()
|
||||||
{
|
{
|
||||||
DeviceStorageEnumerationParams p = mParams;
|
DeviceStorageEnumerationParams p = mParams;
|
||||||
nsRefPtr<DeviceStorageFile> dsf
|
nsRefPtr<DeviceStorageFile> dsf
|
||||||
= new DeviceStorageFile(p.type(), p.storageName(), p.rootdir(), NS_LITERAL_STRING(""));
|
= new DeviceStorageFile(p.type(), p.storageName(),
|
||||||
nsRefPtr<CancelableRunnable> r = new EnumerateFileEvent(this, dsf, p.since());
|
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");
|
NS_ASSERTION(target, "Must have stream transport service");
|
||||||
target->Dispatch(r, NS_DISPATCH_NORMAL);
|
target->Dispatch(r, NS_DISPATCH_NORMAL);
|
||||||
break;
|
break;
|
||||||
|
@ -142,7 +154,8 @@ DeviceStorageRequestParent::Dispatch()
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
DeviceStorageRequestParent::EnsureRequiredPermissions(mozilla::dom::ContentParent* aParent)
|
DeviceStorageRequestParent::EnsureRequiredPermissions(
|
||||||
|
mozilla::dom::ContentParent* aParent)
|
||||||
{
|
{
|
||||||
if (mozilla::Preferences::GetBool("device.storage.testing", false)) {
|
if (mozilla::Preferences::GetBool("device.storage.testing", false)) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -224,7 +237,8 @@ DeviceStorageRequestParent::EnsureRequiredPermissions(mozilla::dom::ContentParen
|
||||||
}
|
}
|
||||||
|
|
||||||
nsAutoCString permissionName;
|
nsAutoCString permissionName;
|
||||||
nsresult rv = DeviceStorageTypeChecker::GetPermissionForType(type, permissionName);
|
nsresult rv = DeviceStorageTypeChecker::GetPermissionForType(type,
|
||||||
|
permissionName);
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -264,14 +278,16 @@ DeviceStorageRequestParent::ActorDestroy(ActorDestroyReason)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceStorageRequestParent::PostFreeSpaceResultEvent::PostFreeSpaceResultEvent(DeviceStorageRequestParent* aParent,
|
DeviceStorageRequestParent::PostFreeSpaceResultEvent::PostFreeSpaceResultEvent(
|
||||||
uint64_t aFreeSpace)
|
DeviceStorageRequestParent* aParent,
|
||||||
|
uint64_t aFreeSpace)
|
||||||
: CancelableRunnable(aParent)
|
: CancelableRunnable(aParent)
|
||||||
, mFreeSpace(aFreeSpace)
|
, mFreeSpace(aFreeSpace)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceStorageRequestParent::PostFreeSpaceResultEvent::~PostFreeSpaceResultEvent() {}
|
DeviceStorageRequestParent::PostFreeSpaceResultEvent::
|
||||||
|
~PostFreeSpaceResultEvent() {}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
DeviceStorageRequestParent::PostFreeSpaceResultEvent::CancelableRun() {
|
DeviceStorageRequestParent::PostFreeSpaceResultEvent::CancelableRun() {
|
||||||
|
@ -282,16 +298,18 @@ DeviceStorageRequestParent::PostFreeSpaceResultEvent::CancelableRun() {
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceStorageRequestParent::PostUsedSpaceResultEvent::PostUsedSpaceResultEvent(DeviceStorageRequestParent* aParent,
|
DeviceStorageRequestParent::PostUsedSpaceResultEvent::
|
||||||
const nsAString& aType,
|
PostUsedSpaceResultEvent(DeviceStorageRequestParent* aParent,
|
||||||
uint64_t aUsedSpace)
|
const nsAString& aType,
|
||||||
|
uint64_t aUsedSpace)
|
||||||
: CancelableRunnable(aParent)
|
: CancelableRunnable(aParent)
|
||||||
, mType(aType)
|
, mType(aType)
|
||||||
, mUsedSpace(aUsedSpace)
|
, mUsedSpace(aUsedSpace)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceStorageRequestParent::PostUsedSpaceResultEvent::~PostUsedSpaceResultEvent() {}
|
DeviceStorageRequestParent::PostUsedSpaceResultEvent::
|
||||||
|
~PostUsedSpaceResultEvent() {}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
DeviceStorageRequestParent::PostUsedSpaceResultEvent::CancelableRun() {
|
DeviceStorageRequestParent::PostUsedSpaceResultEvent::CancelableRun() {
|
||||||
|
@ -302,8 +320,8 @@ DeviceStorageRequestParent::PostUsedSpaceResultEvent::CancelableRun() {
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceStorageRequestParent::PostErrorEvent::PostErrorEvent(DeviceStorageRequestParent* aParent,
|
DeviceStorageRequestParent::PostErrorEvent::
|
||||||
const char* aError)
|
PostErrorEvent(DeviceStorageRequestParent* aParent, const char* aError)
|
||||||
: CancelableRunnable(aParent)
|
: CancelableRunnable(aParent)
|
||||||
{
|
{
|
||||||
CopyASCIItoUTF16(aError, mError);
|
CopyASCIItoUTF16(aError, mError);
|
||||||
|
@ -320,7 +338,8 @@ DeviceStorageRequestParent::PostErrorEvent::CancelableRun() {
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceStorageRequestParent::PostSuccessEvent::PostSuccessEvent(DeviceStorageRequestParent* aParent)
|
DeviceStorageRequestParent::PostSuccessEvent::
|
||||||
|
PostSuccessEvent(DeviceStorageRequestParent* aParent)
|
||||||
: CancelableRunnable(aParent)
|
: CancelableRunnable(aParent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -336,11 +355,12 @@ DeviceStorageRequestParent::PostSuccessEvent::CancelableRun() {
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceStorageRequestParent::PostBlobSuccessEvent::PostBlobSuccessEvent(DeviceStorageRequestParent* aParent,
|
DeviceStorageRequestParent::PostBlobSuccessEvent::
|
||||||
DeviceStorageFile* aFile,
|
PostBlobSuccessEvent(DeviceStorageRequestParent* aParent,
|
||||||
uint32_t aLength,
|
DeviceStorageFile* aFile,
|
||||||
nsACString& aMimeType,
|
uint32_t aLength,
|
||||||
uint64_t aLastModifiedDate)
|
nsACString& aMimeType,
|
||||||
|
uint64_t aLastModifiedDate)
|
||||||
: CancelableRunnable(aParent)
|
: CancelableRunnable(aParent)
|
||||||
, mLength(aLength)
|
, mLength(aLength)
|
||||||
, mLastModificationDate(aLastModifiedDate)
|
, mLastModificationDate(aLastModifiedDate)
|
||||||
|
@ -358,9 +378,11 @@ DeviceStorageRequestParent::PostBlobSuccessEvent::CancelableRun() {
|
||||||
nsString mime;
|
nsString mime;
|
||||||
CopyASCIItoUTF16(mMimeType, mime);
|
CopyASCIItoUTF16(mMimeType, mime);
|
||||||
|
|
||||||
nsString compositePath;
|
nsString fullPath;
|
||||||
mFile->GetCompositePath(compositePath);
|
mFile->GetFullPath(fullPath);
|
||||||
nsCOMPtr<nsIDOMBlob> blob = new nsDOMFileFile(compositePath, mime, mLength, mFile->mFile, mLastModificationDate);
|
nsCOMPtr<nsIDOMBlob> blob = new nsDOMFileFile(fullPath, mime, mLength,
|
||||||
|
mFile->mFile,
|
||||||
|
mLastModificationDate);
|
||||||
|
|
||||||
ContentParent* cp = static_cast<ContentParent*>(mParent->Manager());
|
ContentParent* cp = static_cast<ContentParent*>(mParent->Manager());
|
||||||
BlobParent* actor = cp->GetOrCreateActorForBlob(blob);
|
BlobParent* actor = cp->GetOrCreateActorForBlob(blob);
|
||||||
|
@ -377,10 +399,11 @@ DeviceStorageRequestParent::PostBlobSuccessEvent::CancelableRun() {
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceStorageRequestParent::PostEnumerationSuccessEvent::PostEnumerationSuccessEvent(DeviceStorageRequestParent* aParent,
|
DeviceStorageRequestParent::PostEnumerationSuccessEvent::
|
||||||
const nsAString& aStorageType,
|
PostEnumerationSuccessEvent(DeviceStorageRequestParent* aParent,
|
||||||
const nsAString& aRelPath,
|
const nsAString& aStorageType,
|
||||||
InfallibleTArray<DeviceStorageFileValue>& aPaths)
|
const nsAString& aRelPath,
|
||||||
|
InfallibleTArray<DeviceStorageFileValue>& aPaths)
|
||||||
: CancelableRunnable(aParent)
|
: CancelableRunnable(aParent)
|
||||||
, mStorageType(aStorageType)
|
, mStorageType(aStorageType)
|
||||||
, mRelPath(aRelPath)
|
, mRelPath(aRelPath)
|
||||||
|
@ -388,7 +411,8 @@ DeviceStorageRequestParent::PostEnumerationSuccessEvent::PostEnumerationSuccessE
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceStorageRequestParent::PostEnumerationSuccessEvent::~PostEnumerationSuccessEvent() {}
|
DeviceStorageRequestParent::PostEnumerationSuccessEvent::
|
||||||
|
~PostEnumerationSuccessEvent() {}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
DeviceStorageRequestParent::PostEnumerationSuccessEvent::CancelableRun() {
|
DeviceStorageRequestParent::PostEnumerationSuccessEvent::CancelableRun() {
|
||||||
|
@ -399,9 +423,10 @@ DeviceStorageRequestParent::PostEnumerationSuccessEvent::CancelableRun() {
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceStorageRequestParent::WriteFileEvent::WriteFileEvent(DeviceStorageRequestParent* aParent,
|
DeviceStorageRequestParent::WriteFileEvent::
|
||||||
DeviceStorageFile* aFile,
|
WriteFileEvent(DeviceStorageRequestParent* aParent,
|
||||||
nsIInputStream* aInputStream)
|
DeviceStorageFile* aFile,
|
||||||
|
nsIInputStream* aInputStream)
|
||||||
: CancelableRunnable(aParent)
|
: CancelableRunnable(aParent)
|
||||||
, mFile(aFile)
|
, mFile(aFile)
|
||||||
, mInputStream(aInputStream)
|
, mInputStream(aInputStream)
|
||||||
|
@ -428,7 +453,8 @@ DeviceStorageRequestParent::WriteFileEvent::CancelableRun()
|
||||||
bool check = false;
|
bool check = false;
|
||||||
mFile->mFile->Exists(&check);
|
mFile->mFile->Exists(&check);
|
||||||
if (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);
|
NS_DispatchToMainThread(event);
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
@ -447,8 +473,8 @@ DeviceStorageRequestParent::WriteFileEvent::CancelableRun()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DeviceStorageRequestParent::DeleteFileEvent::DeleteFileEvent(DeviceStorageRequestParent* aParent,
|
DeviceStorageRequestParent::DeleteFileEvent::
|
||||||
DeviceStorageFile* aFile)
|
DeleteFileEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile)
|
||||||
: CancelableRunnable(aParent)
|
: CancelableRunnable(aParent)
|
||||||
, mFile(aFile)
|
, mFile(aFile)
|
||||||
{
|
{
|
||||||
|
@ -480,8 +506,9 @@ DeviceStorageRequestParent::DeleteFileEvent::CancelableRun()
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceStorageRequestParent::FreeSpaceFileEvent::FreeSpaceFileEvent(DeviceStorageRequestParent* aParent,
|
DeviceStorageRequestParent::FreeSpaceFileEvent::
|
||||||
DeviceStorageFile* aFile)
|
FreeSpaceFileEvent(DeviceStorageRequestParent* aParent,
|
||||||
|
DeviceStorageFile* aFile)
|
||||||
: CancelableRunnable(aParent)
|
: CancelableRunnable(aParent)
|
||||||
, mFile(aFile)
|
, mFile(aFile)
|
||||||
{
|
{
|
||||||
|
@ -507,8 +534,9 @@ DeviceStorageRequestParent::FreeSpaceFileEvent::CancelableRun()
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceStorageRequestParent::UsedSpaceFileEvent::UsedSpaceFileEvent(DeviceStorageRequestParent* aParent,
|
DeviceStorageRequestParent::UsedSpaceFileEvent::
|
||||||
DeviceStorageFile* aFile)
|
UsedSpaceFileEvent(DeviceStorageRequestParent* aParent,
|
||||||
|
DeviceStorageFile* aFile)
|
||||||
: CancelableRunnable(aParent)
|
: CancelableRunnable(aParent)
|
||||||
, mFile(aFile)
|
, mFile(aFile)
|
||||||
{
|
{
|
||||||
|
@ -528,7 +556,8 @@ DeviceStorageRequestParent::UsedSpaceFileEvent::CancelableRun()
|
||||||
&musicUsage, &totalUsage);
|
&musicUsage, &totalUsage);
|
||||||
nsCOMPtr<nsIRunnable> r;
|
nsCOMPtr<nsIRunnable> r;
|
||||||
if (mFile->mStorageType.EqualsLiteral(DEVICESTORAGE_PICTURES)) {
|
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)) {
|
else if (mFile->mStorageType.EqualsLiteral(DEVICESTORAGE_VIDEOS)) {
|
||||||
r = new PostUsedSpaceResultEvent(mParent, mFile->mStorageType, videosUsage);
|
r = new PostUsedSpaceResultEvent(mParent, mFile->mStorageType, videosUsage);
|
||||||
|
@ -542,12 +571,13 @@ DeviceStorageRequestParent::UsedSpaceFileEvent::CancelableRun()
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceStorageRequestParent::ReadFileEvent::ReadFileEvent(DeviceStorageRequestParent* aParent,
|
DeviceStorageRequestParent::ReadFileEvent::
|
||||||
DeviceStorageFile* aFile)
|
ReadFileEvent(DeviceStorageRequestParent* aParent, DeviceStorageFile* aFile)
|
||||||
: CancelableRunnable(aParent)
|
: CancelableRunnable(aParent)
|
||||||
, mFile(aFile)
|
, mFile(aFile)
|
||||||
{
|
{
|
||||||
nsCOMPtr<nsIMIMEService> mimeService = do_GetService(NS_MIMESERVICE_CONTRACTID);
|
nsCOMPtr<nsIMIMEService> mimeService
|
||||||
|
= do_GetService(NS_MIMESERVICE_CONTRACTID);
|
||||||
if (mimeService) {
|
if (mimeService) {
|
||||||
nsresult rv = mimeService->GetTypeFromFile(mFile->mFile, mMimeType);
|
nsresult rv = mimeService->GetTypeFromFile(mFile->mFile, mMimeType);
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
|
@ -591,14 +621,16 @@ DeviceStorageRequestParent::ReadFileEvent::CancelableRun()
|
||||||
return NS_OK;
|
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);
|
NS_DispatchToMainThread(r);
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceStorageRequestParent::EnumerateFileEvent::EnumerateFileEvent(DeviceStorageRequestParent* aParent,
|
DeviceStorageRequestParent::EnumerateFileEvent::
|
||||||
DeviceStorageFile* aFile,
|
EnumerateFileEvent(DeviceStorageRequestParent* aParent,
|
||||||
uint64_t aSince)
|
DeviceStorageFile* aFile,
|
||||||
|
uint64_t aSince)
|
||||||
: CancelableRunnable(aParent)
|
: CancelableRunnable(aParent)
|
||||||
, mFile(aFile)
|
, mFile(aFile)
|
||||||
, mSince(aSince)
|
, mSince(aSince)
|
||||||
|
@ -636,14 +668,16 @@ DeviceStorageRequestParent::EnumerateFileEvent::CancelableRun()
|
||||||
values.AppendElement(dsvf);
|
values.AppendElement(dsvf);
|
||||||
}
|
}
|
||||||
|
|
||||||
r = new PostEnumerationSuccessEvent(mParent, mFile->mStorageType, mFile->mRootDir, values);
|
r = new PostEnumerationSuccessEvent(mParent, mFile->mStorageType,
|
||||||
|
mFile->mRootDir, values);
|
||||||
NS_DispatchToMainThread(r);
|
NS_DispatchToMainThread(r);
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DeviceStorageRequestParent::PostPathResultEvent::PostPathResultEvent(DeviceStorageRequestParent* aParent,
|
DeviceStorageRequestParent::PostPathResultEvent::
|
||||||
const nsAString& aPath)
|
PostPathResultEvent(DeviceStorageRequestParent* aParent,
|
||||||
|
const nsAString& aPath)
|
||||||
: CancelableRunnable(aParent)
|
: CancelableRunnable(aParent)
|
||||||
, mPath(aPath)
|
, mPath(aPath)
|
||||||
{
|
{
|
||||||
|
@ -663,14 +697,16 @@ DeviceStorageRequestParent::PostPathResultEvent::CancelableRun()
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceStorageRequestParent::PostAvailableResultEvent::PostAvailableResultEvent(DeviceStorageRequestParent* aParent,
|
DeviceStorageRequestParent::PostAvailableResultEvent::
|
||||||
DeviceStorageFile* aFile)
|
PostAvailableResultEvent(DeviceStorageRequestParent* aParent,
|
||||||
|
DeviceStorageFile* aFile)
|
||||||
: CancelableRunnable(aParent)
|
: CancelableRunnable(aParent)
|
||||||
, mFile(aFile)
|
, mFile(aFile)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceStorageRequestParent::PostAvailableResultEvent::~PostAvailableResultEvent()
|
DeviceStorageRequestParent::PostAvailableResultEvent::
|
||||||
|
~PostAvailableResultEvent()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -5,8 +5,10 @@
|
||||||
|
|
||||||
#include "nsISupports.idl"
|
#include "nsISupports.idl"
|
||||||
|
|
||||||
[scriptable, uuid(a0a3bc68-eab3-4e66-b5cb-b1d86765119c)]
|
interface nsIDOMWindow;
|
||||||
|
|
||||||
|
[uuid(729cfcad-11b4-4338-b97e-5c023ae295fa)]
|
||||||
interface nsIDOMCrypto : nsISupports
|
interface nsIDOMCrypto : nsISupports
|
||||||
{
|
{
|
||||||
[implicit_jscontext] jsval getRandomValues(in jsval aData);
|
[notxpcom] void init(in nsIDOMWindow window);
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,23 +6,11 @@
|
||||||
#include "domstubs.idl"
|
#include "domstubs.idl"
|
||||||
|
|
||||||
interface nsIDOMCRMFObject;
|
interface nsIDOMCRMFObject;
|
||||||
|
interface nsIDOMWindow;
|
||||||
|
|
||||||
[scriptable, uuid(e1df1d4d-41ef-4225-934a-107c5d612686)]
|
[uuid(c25ecf08-3f46-4420-bee4-8505792fd63a)]
|
||||||
interface nsIDOMCrypto : nsISupports
|
interface nsIDOMCrypto : nsISupports
|
||||||
{
|
{
|
||||||
readonly attribute DOMString version;
|
[notxpcom] void init(in nsIDOMWindow window);
|
||||||
attribute boolean enableSmartCardEvents;
|
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.setCLIR = function fakeSetCLIR(options) {
|
||||||
worker.RIL[REQUEST_SET_CLIR](0, {
|
worker.RIL[REQUEST_SET_CLIR](0, {
|
||||||
|
rilMessageType: "setCLIR",
|
||||||
rilRequestError: ERROR_SUCCESS
|
rilRequestError: ERROR_SUCCESS
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -63,6 +64,7 @@ add_test(function test_setCLIR_generic_failure() {
|
||||||
|
|
||||||
worker.RIL.setCLIR = function fakeSetCLIR(options) {
|
worker.RIL.setCLIR = function fakeSetCLIR(options) {
|
||||||
worker.RIL[REQUEST_SET_CLIR](0, {
|
worker.RIL[REQUEST_SET_CLIR](0, {
|
||||||
|
rilMessageType: "setCLIR",
|
||||||
rilRequestError: ERROR_GENERIC_FAILURE
|
rilRequestError: ERROR_GENERIC_FAILURE
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -95,6 +97,7 @@ add_test(function test_getCLIR_n0_m1() {
|
||||||
2 // Length.
|
2 // Length.
|
||||||
];
|
];
|
||||||
worker.RIL[REQUEST_GET_CLIR](1, {
|
worker.RIL[REQUEST_GET_CLIR](1, {
|
||||||
|
rilMessageType: "setCLIR",
|
||||||
rilRequestError: ERROR_SUCCESS
|
rilRequestError: ERROR_SUCCESS
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -126,6 +129,7 @@ add_test(function test_getCLIR_error_generic_failure_invalid_length() {
|
||||||
0 // Length (invalid one).
|
0 // Length (invalid one).
|
||||||
];
|
];
|
||||||
worker.RIL[REQUEST_GET_CLIR](1, {
|
worker.RIL[REQUEST_GET_CLIR](1, {
|
||||||
|
rilMessageType: "setCLIR",
|
||||||
rilRequestError: ERROR_SUCCESS
|
rilRequestError: ERROR_SUCCESS
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -125,7 +125,7 @@ function onWindowLoad()
|
||||||
window.crypto.getRandomValues(null);
|
window.crypto.getRandomValues(null);
|
||||||
}
|
}
|
||||||
catch (ex) {
|
catch (ex) {
|
||||||
var test = ex.toString().search(/1003/);
|
var test = ex.toString().search(/1003|TypeError/);
|
||||||
ok((test > -1), "Expected TYPE_ERR, got " + ex + ".");
|
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,
|
ok("disableRightClick" in window.crypto,
|
||||||
"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>
|
</script>
|
||||||
</body></html>
|
</body></html>
|
||||||
|
|
|
@ -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)
|
$(NULL)
|
||||||
|
|
||||||
preprocessed_webidl_files = \
|
preprocessed_webidl_files = \
|
||||||
|
Crypto.webidl \
|
||||||
Navigator.webidl \
|
Navigator.webidl \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,6 @@ members = [
|
||||||
#
|
#
|
||||||
# Note that many implementations of interfaces in this directory
|
# Note that many implementations of interfaces in this directory
|
||||||
# use GetCurrentNativeCallContext, notably:
|
# use GetCurrentNativeCallContext, notably:
|
||||||
# - nsIDOMCrypto.{generateCRMFRequest,signText}
|
|
||||||
# - nsIDOMLocation.reload
|
# - nsIDOMLocation.reload
|
||||||
# - nsIDOMNSHistory.go
|
# - nsIDOMNSHistory.go
|
||||||
# - nsIDOMJSPluginArray.refresh
|
# - nsIDOMJSPluginArray.refresh
|
||||||
|
|
|
@ -74,9 +74,11 @@
|
||||||
|
|
||||||
#include "nsNSSCertHelper.h"
|
#include "nsNSSCertHelper.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include "nsWrapperCacheInlines.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace mozilla;
|
using namespace mozilla;
|
||||||
|
using namespace mozilla::dom;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* These are the most common error strings that are returned
|
* These are the most common error strings that are returned
|
||||||
|
@ -256,8 +258,14 @@ nsCrypto::~nsCrypto()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
void
|
||||||
nsCrypto::SetEnableSmartCardEvents(bool aEnable)
|
nsCrypto::Init(nsIDOMWindow* aWindow)
|
||||||
|
{
|
||||||
|
mozilla::dom::Crypto::Init(aWindow);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
nsCrypto::SetEnableSmartCardEvents(bool aEnable, ErrorResult& aRv)
|
||||||
{
|
{
|
||||||
nsresult rv = NS_OK;
|
nsresult rv = NS_OK;
|
||||||
|
|
||||||
|
@ -269,17 +277,31 @@ nsCrypto::SetEnableSmartCardEvents(bool aEnable)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
return rv;
|
aRv.Throw(rv);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mEnableSmartCardEvents = aEnable;
|
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
|
NS_IMETHODIMP
|
||||||
nsCrypto::GetEnableSmartCardEvents(bool *aEnable)
|
nsCrypto::GetEnableSmartCardEvents(bool *aEnable)
|
||||||
{
|
{
|
||||||
*aEnable = mEnableSmartCardEvents;
|
*aEnable = EnableSmartCardEvents();
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -294,11 +316,10 @@ ns_can_escrow(nsKeyGenType keyGenType)
|
||||||
|
|
||||||
//Retrieve crypto.version so that callers know what
|
//Retrieve crypto.version so that callers know what
|
||||||
//version of PSM this is.
|
//version of PSM this is.
|
||||||
NS_IMETHODIMP
|
void
|
||||||
nsCrypto::GetVersion(nsAString& aVersion)
|
nsCrypto::GetVersion(nsString& aVersion)
|
||||||
{
|
{
|
||||||
aVersion.Assign(NS_LITERAL_STRING(PSM_VERSION_STRING).get());
|
aVersion.Assign(NS_LITERAL_STRING(PSM_VERSION_STRING));
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1831,101 +1852,47 @@ GetISupportsFromContext(JSContext *cx)
|
||||||
|
|
||||||
//The top level method which is a member of nsIDOMCrypto
|
//The top level method which is a member of nsIDOMCrypto
|
||||||
//for generate a base64 encoded CRMF request.
|
//for generate a base64 encoded CRMF request.
|
||||||
NS_IMETHODIMP
|
already_AddRefed<nsIDOMCRMFObject>
|
||||||
nsCrypto::GenerateCRMFRequest(nsIDOMCRMFObject** aReturn)
|
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;
|
nsNSSShutDownPreventionLock locker;
|
||||||
*aReturn = nullptr;
|
nsCOMPtr<nsIDOMCRMFObject> crmf;
|
||||||
nsresult nrv;
|
nsresult nrv;
|
||||||
nsCOMPtr<nsIXPConnect> xpc(do_GetService(nsIXPConnect::GetCID(), &nrv));
|
|
||||||
NS_ENSURE_SUCCESS(nrv, nrv);
|
|
||||||
|
|
||||||
nsAXPCNativeCallContext *ncc = nullptr;
|
uint32_t argc = aArgs.Length();
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get all of the parameters.
|
* Get all of the parameters.
|
||||||
*/
|
*/
|
||||||
if (argc < 5 || ((argc-5) % 3) != 0) {
|
if (argc % 3 != 0) {
|
||||||
JS_ReportError(cx, "%s%s", JS_ERROR,
|
aRv.ThrowNotEnoughArgsError();
|
||||||
"incorrect number of parameters");
|
return nullptr;
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (JSVAL_IS_NULL(argv[0])) {
|
if (aReqDN.IsVoid()) {
|
||||||
JS_ReportError(cx, "%s%s", JS_ERROR, "no DN specified");
|
NS_WARNING("no DN specified");
|
||||||
return NS_ERROR_FAILURE;
|
aRv.Throw(NS_ERROR_FAILURE);
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSString *jsString = JS_ValueToString(cx,argv[0]);
|
if (aJsCallback.IsVoid()) {
|
||||||
NS_ENSURE_TRUE(jsString, NS_ERROR_OUT_OF_MEMORY);
|
NS_WARNING("no completion function specified");
|
||||||
argv[0] = STRING_TO_JSVAL(jsString);
|
aRv.Throw(NS_ERROR_FAILURE);
|
||||||
JSAutoByteString reqDN(cx,jsString);
|
return nullptr;
|
||||||
NS_ENSURE_TRUE(!!reqDN, NS_ERROR_OUT_OF_MEMORY);
|
}
|
||||||
|
|
||||||
JSAutoByteString regToken;
|
JS::RootedObject script_obj(aContext, GetWrapper());
|
||||||
if (!JSVAL_IS_NULL(argv[1])) {
|
if (MOZ_UNLIKELY(!script_obj)) {
|
||||||
jsString = JS_ValueToString(cx, argv[1]);
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
||||||
NS_ENSURE_TRUE(jsString, NS_ERROR_OUT_OF_MEMORY);
|
return nullptr;
|
||||||
argv[1] = STRING_TO_JSVAL(jsString);
|
|
||||||
regToken.encodeLatin1(cx, jsString);
|
|
||||||
NS_ENSURE_TRUE(!!regToken, NS_ERROR_OUT_OF_MEMORY);
|
|
||||||
}
|
}
|
||||||
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
|
//Put up some UI warning that someone is trying to
|
||||||
//escrow the private key.
|
//escrow the private key.
|
||||||
|
@ -1934,29 +1901,36 @@ nsCrypto::GenerateCRMFRequest(nsIDOMCRMFObject** aReturn)
|
||||||
nsNSSCertificate *escrowCert = nullptr;
|
nsNSSCertificate *escrowCert = nullptr;
|
||||||
nsCOMPtr<nsIX509Cert> nssCert;
|
nsCOMPtr<nsIX509Cert> nssCert;
|
||||||
bool willEscrow = false;
|
bool willEscrow = false;
|
||||||
if (!!eaCert) {
|
if (!aEaCert.IsVoid()) {
|
||||||
SECItem certDer = {siBuffer, nullptr, 0};
|
SECItem certDer = {siBuffer, nullptr, 0};
|
||||||
SECStatus srv = ATOB_ConvertAsciiToItem(&certDer, eaCert.ptr());
|
SECStatus srv = ATOB_ConvertAsciiToItem(&certDer, aEaCert.get());
|
||||||
if (srv != SECSuccess) {
|
if (srv != SECSuccess) {
|
||||||
return NS_ERROR_FAILURE;
|
aRv.Throw(NS_ERROR_FAILURE);
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
ScopedCERTCertificate cert(CERT_NewTempCertificate(CERT_GetDefaultCertDB(),
|
ScopedCERTCertificate cert(CERT_NewTempCertificate(CERT_GetDefaultCertDB(),
|
||||||
&certDer, nullptr,
|
&certDer, nullptr,
|
||||||
false, true));
|
false, true));
|
||||||
if (!cert)
|
if (!cert) {
|
||||||
return NS_ERROR_FAILURE;
|
aRv.Throw(NS_ERROR_FAILURE);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
escrowCert = nsNSSCertificate::Create(cert);
|
escrowCert = nsNSSCertificate::Create(cert);
|
||||||
nssCert = escrowCert;
|
nssCert = escrowCert;
|
||||||
if (!nssCert)
|
if (!nssCert) {
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMCryptoDialogs> dialogs;
|
nsCOMPtr<nsIDOMCryptoDialogs> dialogs;
|
||||||
nsresult rv = getNSSDialogs(getter_AddRefs(dialogs),
|
nsresult rv = getNSSDialogs(getter_AddRefs(dialogs),
|
||||||
NS_GET_IID(nsIDOMCryptoDialogs),
|
NS_GET_IID(nsIDOMCryptoDialogs),
|
||||||
NS_DOMCRYPTODIALOGS_CONTRACTID);
|
NS_DOMCRYPTODIALOGS_CONTRACTID);
|
||||||
if (NS_FAILED(rv))
|
if (NS_FAILED(rv)) {
|
||||||
return rv;
|
aRv.Throw(rv);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
bool okay=false;
|
bool okay=false;
|
||||||
{
|
{
|
||||||
|
@ -1968,27 +1942,32 @@ nsCrypto::GenerateCRMFRequest(nsIDOMCRMFObject** aReturn)
|
||||||
dialogs->ConfirmKeyEscrow(nssCert, &okay);
|
dialogs->ConfirmKeyEscrow(nssCert, &okay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!okay)
|
if (!okay) {
|
||||||
return NS_OK;
|
aRv.Throw(NS_ERROR_FAILURE);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
willEscrow = true;
|
willEscrow = true;
|
||||||
}
|
}
|
||||||
nsCOMPtr<nsIInterfaceRequestor> uiCxt = new PipUIContext;
|
nsCOMPtr<nsIInterfaceRequestor> uiCxt = new PipUIContext;
|
||||||
int32_t numRequests = (argc - 5)/3;
|
int32_t numRequests = argc / 3;
|
||||||
nsKeyPairInfo *keyids = new nsKeyPairInfo[numRequests];
|
nsKeyPairInfo *keyids = new nsKeyPairInfo[numRequests];
|
||||||
memset(keyids, 0, sizeof(nsKeyPairInfo)*numRequests);
|
memset(keyids, 0, sizeof(nsKeyPairInfo)*numRequests);
|
||||||
int keyInfoIndex;
|
int keyInfoIndex;
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
PK11SlotInfo *slot = nullptr;
|
PK11SlotInfo *slot = nullptr;
|
||||||
// Go through all of the arguments and generate the appropriate key pairs.
|
// Go through all of the arguments and generate the appropriate key pairs.
|
||||||
for (i=5,keyInfoIndex=0; i<argc; i+=3,keyInfoIndex++) {
|
for (i=0,keyInfoIndex=0; i<argc; i+=3,keyInfoIndex++) {
|
||||||
nrv = cryptojs_ReadArgsAndGenerateKey(cx, &argv[i], &keyids[keyInfoIndex],
|
nrv = cryptojs_ReadArgsAndGenerateKey(aContext,
|
||||||
uiCxt, &slot, willEscrow);
|
const_cast<JS::Value*>(&aArgs[i]),
|
||||||
|
&keyids[keyInfoIndex],
|
||||||
|
uiCxt, &slot, willEscrow);
|
||||||
|
|
||||||
if (NS_FAILED(nrv)) {
|
if (NS_FAILED(nrv)) {
|
||||||
if (slot)
|
if (slot)
|
||||||
PK11_FreeSlot(slot);
|
PK11_FreeSlot(slot);
|
||||||
nsFreeKeyPairInfo(keyids,numRequests);
|
nsFreeKeyPairInfo(keyids,numRequests);
|
||||||
return nrv;
|
aRv.Throw(nrv);
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// By this time we'd better have a slot for the key gen.
|
// By this time we'd better have a slot for the key gen.
|
||||||
|
@ -1997,24 +1976,23 @@ nsCrypto::GenerateCRMFRequest(nsIDOMCRMFObject** aReturn)
|
||||||
PK11_FreeSlot(slot);
|
PK11_FreeSlot(slot);
|
||||||
|
|
||||||
char *encodedRequest = nsCreateReqFromKeyPairs(keyids,numRequests,
|
char *encodedRequest = nsCreateReqFromKeyPairs(keyids,numRequests,
|
||||||
reqDN.ptr(),regToken.ptr(),
|
const_cast<char*>(aReqDN.get()),
|
||||||
authenticator.ptr(),
|
const_cast<char*>(aRegToken.get()),
|
||||||
|
const_cast<char*>(aAuthenticator.get()),
|
||||||
escrowCert);
|
escrowCert);
|
||||||
#ifdef DEBUG_javi
|
#ifdef DEBUG_javi
|
||||||
printf ("Created the folloing CRMF request:\n%s\n", encodedRequest);
|
printf ("Created the folloing CRMF request:\n%s\n", encodedRequest);
|
||||||
#endif
|
#endif
|
||||||
if (!encodedRequest) {
|
if (!encodedRequest) {
|
||||||
nsFreeKeyPairInfo(keyids, numRequests);
|
nsFreeKeyPairInfo(keyids, numRequests);
|
||||||
return NS_ERROR_FAILURE;
|
aRv.Throw(NS_ERROR_FAILURE);
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
nsCRMFObject *newObject = new nsCRMFObject();
|
nsCRMFObject *newObject = new nsCRMFObject();
|
||||||
newObject->SetCRMFRequest(encodedRequest);
|
newObject->SetCRMFRequest(encodedRequest);
|
||||||
*aReturn = newObject;
|
crmf = newObject;
|
||||||
//Give a reference to the returnee.
|
|
||||||
NS_ADDREF(*aReturn);
|
|
||||||
nsFreeKeyPairInfo(keyids, numRequests);
|
nsFreeKeyPairInfo(keyids, numRequests);
|
||||||
|
|
||||||
//
|
|
||||||
// Post an event on the UI queue so that the JS gets called after
|
// 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?
|
// 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,
|
// 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.
|
// when the request has been generated.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
nsCOMPtr<nsIScriptSecurityManager> secMan =
|
nsCOMPtr<nsIScriptSecurityManager> secMan =
|
||||||
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID);
|
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;
|
nsCOMPtr<nsIPrincipal> principals;
|
||||||
nsresult rv = secMan->GetSubjectPrincipal(getter_AddRefs(principals));
|
nsresult rv = secMan->GetSubjectPrincipal(getter_AddRefs(principals));
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
if (NS_FAILED(nrv)) {
|
||||||
NS_ENSURE_TRUE(principals, NS_ERROR_UNEXPECTED);
|
aRv.Throw(nrv);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
if (MOZ_UNLIKELY(!principals)) {
|
||||||
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
nsCryptoRunArgs *args = new nsCryptoRunArgs();
|
nsCryptoRunArgs *args = new nsCryptoRunArgs();
|
||||||
|
|
||||||
args->m_cx = cx;
|
args->m_cx = aContext;
|
||||||
args->m_kungFuDeathGrip = GetISupportsFromContext(cx);
|
args->m_kungFuDeathGrip = GetISupportsFromContext(aContext);
|
||||||
args->m_scope = JS_GetParent(script_obj);
|
args->m_scope = JS_GetParent(script_obj);
|
||||||
|
if (!aJsCallback.IsVoid()) {
|
||||||
args->m_jsCallback.Adopt(!!jsCallback ? nsCRT::strdup(jsCallback.ptr()) : 0);
|
args->m_jsCallback = aJsCallback;
|
||||||
|
}
|
||||||
args->m_principals = principals;
|
args->m_principals = principals;
|
||||||
|
|
||||||
nsCryptoRunnable *cryptoRunnable = new nsCryptoRunnable(args);
|
nsCryptoRunnable *cryptoRunnable = new nsCryptoRunnable(args);
|
||||||
|
|
||||||
rv = NS_DispatchToMainThread(cryptoRunnable);
|
rv = NS_DispatchToMainThread(cryptoRunnable);
|
||||||
if (NS_FAILED(rv))
|
if (NS_FAILED(rv)) {
|
||||||
|
aRv.Throw(rv);
|
||||||
delete cryptoRunnable;
|
delete cryptoRunnable;
|
||||||
|
}
|
||||||
|
|
||||||
return rv;
|
return crmf.forget();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2227,14 +2216,14 @@ nsCertListCount(CERTCertList *certList)
|
||||||
return numCerts;
|
return numCerts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Import user certificates that arrive as a CMMF base64 encoded
|
//Import user certificates that arrive as a CMMF base64 encoded
|
||||||
//string.
|
//string.
|
||||||
NS_IMETHODIMP
|
void
|
||||||
nsCrypto::ImportUserCertificates(const nsAString& aNickname,
|
nsCrypto::ImportUserCertificates(const nsAString& aNickname,
|
||||||
const nsAString& aCmmfResponse,
|
const nsAString& aCmmfResponse,
|
||||||
bool aDoForcedBackup,
|
bool aDoForcedBackup,
|
||||||
nsAString& aReturn)
|
nsAString& aReturn,
|
||||||
|
ErrorResult& aRv)
|
||||||
{
|
{
|
||||||
nsNSSShutDownPreventionLock locker;
|
nsNSSShutDownPreventionLock locker;
|
||||||
char *nickname=nullptr, *cmmfResponse=nullptr;
|
char *nickname=nullptr, *cmmfResponse=nullptr;
|
||||||
|
@ -2425,20 +2414,24 @@ nsCrypto::ImportUserCertificates(const nsAString& aNickname,
|
||||||
if (certRepContent) {
|
if (certRepContent) {
|
||||||
CMMF_DestroyCertRepContent(certRepContent);
|
CMMF_DestroyCertRepContent(certRepContent);
|
||||||
}
|
}
|
||||||
return rv;
|
|
||||||
|
if (NS_FAILED(rv)) {
|
||||||
|
aRv.Throw(rv);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
void
|
||||||
nsCrypto::PopChallengeResponse(const nsAString& aChallenge,
|
nsCrypto::PopChallengeResponse(const nsAString& aChallenge,
|
||||||
nsAString& aReturn)
|
nsAString& aReturn,
|
||||||
|
ErrorResult& aRv)
|
||||||
{
|
{
|
||||||
return NS_ERROR_NOT_IMPLEMENTED;
|
aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
void
|
||||||
nsCrypto::Random(int32_t aNumBytes, nsAString& aReturn)
|
nsCrypto::Random(int32_t aNumBytes, nsAString& aReturn, ErrorResult& aRv)
|
||||||
{
|
{
|
||||||
return NS_ERROR_NOT_IMPLEMENTED;
|
aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -2472,46 +2465,27 @@ void signTextOutputCallback(void *arg, const char *buf, unsigned long len)
|
||||||
((nsCString*)arg)->Append(buf, len);
|
((nsCString*)arg)->Append(buf, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
void
|
||||||
nsCrypto::SignText(const nsAString& aStringToSign, const nsAString& aCaOption,
|
nsCrypto::SignText(JSContext* aContext,
|
||||||
nsAString& aResult)
|
const nsAString& aStringToSign,
|
||||||
|
const nsAString& aCaOption,
|
||||||
|
const Sequence<nsCString>& aArgs,
|
||||||
|
nsAString& aReturn)
|
||||||
{
|
{
|
||||||
// XXX This code should return error codes, but we're keeping this
|
// XXX This code should return error codes, but we're keeping this
|
||||||
// backwards compatible with NS4.x and so we can't throw exceptions.
|
// backwards compatible with NS4.x and so we can't throw exceptions.
|
||||||
NS_NAMED_LITERAL_STRING(internalError, "error:internalError");
|
NS_NAMED_LITERAL_STRING(internalError, "error:internalError");
|
||||||
|
|
||||||
aResult.Truncate();
|
aReturn.Truncate();
|
||||||
|
|
||||||
nsAXPCNativeCallContext* ncc = nullptr;
|
uint32_t argc = aArgs.Length();
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!aCaOption.EqualsLiteral("auto") &&
|
if (!aCaOption.EqualsLiteral("auto") &&
|
||||||
!aCaOption.EqualsLiteral("ask")) {
|
!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;
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// It was decided to always behave as if "ask" were specified.
|
// 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;
|
nsCOMPtr<nsIInterfaceRequestor> uiContext = new PipUIContext;
|
||||||
if (!uiContext) {
|
if (!uiContext) {
|
||||||
aResult.Append(internalError);
|
aReturn.Append(internalError);
|
||||||
|
|
||||||
return NS_OK;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bestOnly = true;
|
bool bestOnly = true;
|
||||||
|
@ -2530,74 +2504,55 @@ nsCrypto::SignText(const nsAString& aStringToSign, const nsAString& aCaOption,
|
||||||
CERT_FindUserCertsByUsage(CERT_GetDefaultCertDB(), certUsageEmailSigner,
|
CERT_FindUserCertsByUsage(CERT_GetDefaultCertDB(), certUsageEmailSigner,
|
||||||
bestOnly, validOnly, uiContext);
|
bestOnly, validOnly, uiContext);
|
||||||
|
|
||||||
uint32_t numCAs = argc - 2;
|
uint32_t numCAs = argc;
|
||||||
if (numCAs > 0) {
|
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]);
|
nsAutoArrayPtr<char*> caNames(new char*[numCAs]);
|
||||||
if (!caNames) {
|
if (!caNames) {
|
||||||
aResult.Append(internalError);
|
aReturn.Append(internalError);
|
||||||
return NS_OK;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t i;
|
||||||
for (i = 0; i < numCAs; ++i)
|
for (i = 0; i < numCAs; ++i)
|
||||||
caNames[i] = caNameBytes[i].ptr();
|
caNames[i] = const_cast<char*>(aArgs[i].get());
|
||||||
|
|
||||||
if (certList &&
|
if (certList &&
|
||||||
CERT_FilterCertListByCANames(certList, numCAs, caNames,
|
CERT_FilterCertListByCANames(certList, numCAs, caNames,
|
||||||
certUsageEmailSigner) != SECSuccess) {
|
certUsageEmailSigner) != SECSuccess) {
|
||||||
aResult.Append(internalError);
|
aReturn.Append(internalError);
|
||||||
|
|
||||||
return NS_OK;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!certList || CERT_LIST_EMPTY(certList)) {
|
if (!certList || CERT_LIST_EMPTY(certList)) {
|
||||||
aResult.AppendLiteral("error:noMatchingCert");
|
aReturn.AppendLiteral("error:noMatchingCert");
|
||||||
|
|
||||||
return NS_OK;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIFormSigningDialog> fsd =
|
nsCOMPtr<nsIFormSigningDialog> fsd =
|
||||||
do_CreateInstance(NS_FORMSIGNINGDIALOG_CONTRACTID);
|
do_CreateInstance(NS_FORMSIGNINGDIALOG_CONTRACTID);
|
||||||
if (!fsd) {
|
if (!fsd) {
|
||||||
aResult.Append(internalError);
|
aReturn.Append(internalError);
|
||||||
|
|
||||||
return NS_OK;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIDocument> document;
|
nsCOMPtr<nsIDocument> document;
|
||||||
GetDocumentFromContext(cx, getter_AddRefs(document));
|
GetDocumentFromContext(aContext, getter_AddRefs(document));
|
||||||
if (!document) {
|
if (!document) {
|
||||||
aResult.Append(internalError);
|
aReturn.Append(internalError);
|
||||||
|
|
||||||
return NS_OK;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the hostname from the URL of the document.
|
// Get the hostname from the URL of the document.
|
||||||
nsIURI* uri = document->GetDocumentURI();
|
nsIURI* uri = document->GetDocumentURI();
|
||||||
if (!uri) {
|
if (!uri) {
|
||||||
aResult.Append(internalError);
|
aReturn.Append(internalError);
|
||||||
|
|
||||||
return NS_OK;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
|
@ -2605,9 +2560,9 @@ nsCrypto::SignText(const nsAString& aStringToSign, const nsAString& aCaOption,
|
||||||
nsCString host;
|
nsCString host;
|
||||||
rv = uri->GetHost(host);
|
rv = uri->GetHost(host);
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
aResult.Append(internalError);
|
aReturn.Append(internalError);
|
||||||
|
|
||||||
return NS_OK;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t numberOfCerts = 0;
|
int32_t numberOfCerts = 0;
|
||||||
|
@ -2620,9 +2575,9 @@ nsCrypto::SignText(const nsAString& aStringToSign, const nsAString& aCaOption,
|
||||||
ScopedCERTCertNicknames nicknames(getNSSCertNicknamesFromCertList(certList));
|
ScopedCERTCertNicknames nicknames(getNSSCertNicknamesFromCertList(certList));
|
||||||
|
|
||||||
if (!nicknames) {
|
if (!nicknames) {
|
||||||
aResult.Append(internalError);
|
aReturn.Append(internalError);
|
||||||
|
|
||||||
return NS_OK;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_ASSERTION(nicknames->numnicknames == numberOfCerts,
|
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]);
|
nsAutoArrayPtr<PRUnichar*> certNicknameList(new PRUnichar*[nicknames->numnicknames * 2]);
|
||||||
if (!certNicknameList) {
|
if (!certNicknameList) {
|
||||||
aResult.Append(internalError);
|
aReturn.Append(internalError);
|
||||||
|
|
||||||
return NS_OK;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PRUnichar** certDetailsList = certNicknameList.get() + nicknames->numnicknames;
|
PRUnichar** certDetailsList = certNicknameList.get() + nicknames->numnicknames;
|
||||||
|
@ -2661,9 +2616,9 @@ nsCrypto::SignText(const nsAString& aStringToSign, const nsAString& aCaOption,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (certsToUse == 0) {
|
if (certsToUse == 0) {
|
||||||
aResult.Append(internalError);
|
aReturn.Append(internalError);
|
||||||
|
|
||||||
return NS_OK;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_ConvertUTF8toUTF16 utf16Host(host);
|
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
|
if (NS_FAILED(rv)) { // something went wrong inside the tryAgain loop
|
||||||
aResult.Append(internalError);
|
aReturn.Append(internalError);
|
||||||
|
|
||||||
return NS_OK;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (canceled) {
|
if (canceled) {
|
||||||
aResult.AppendLiteral("error:userCancel");
|
aReturn.AppendLiteral("error:userCancel");
|
||||||
|
|
||||||
return NS_OK;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SECKEYPrivateKey* privKey = PK11_FindKeyByAnyCert(signingCert, uiContext);
|
SECKEYPrivateKey* privKey = PK11_FindKeyByAnyCert(signingCert, uiContext);
|
||||||
if (!privKey) {
|
if (!privKey) {
|
||||||
aResult.Append(internalError);
|
aReturn.Append(internalError);
|
||||||
|
|
||||||
return NS_OK;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsAutoCString charset(document->GetDocumentCharacterSet());
|
nsAutoCString charset(document->GetDocumentCharacterSet());
|
||||||
|
@ -2755,9 +2710,9 @@ nsCrypto::SignText(const nsAString& aStringToSign, const nsAString& aCaOption,
|
||||||
rv = encoder->Convert(PromiseFlatString(aStringToSign).get(),
|
rv = encoder->Convert(PromiseFlatString(aStringToSign).get(),
|
||||||
getter_Copies(buffer));
|
getter_Copies(buffer));
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
aResult.Append(internalError);
|
aReturn.Append(internalError);
|
||||||
|
|
||||||
return NS_OK;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -2767,9 +2722,9 @@ nsCrypto::SignText(const nsAString& aStringToSign, const nsAString& aCaOption,
|
||||||
|
|
||||||
HASHContext *hc = HASH_Create(HASH_AlgSHA1);
|
HASHContext *hc = HASH_Create(HASH_AlgSHA1);
|
||||||
if (!hc) {
|
if (!hc) {
|
||||||
aResult.Append(internalError);
|
aReturn.Append(internalError);
|
||||||
|
|
||||||
return NS_OK;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char hash[SHA1_LENGTH];
|
unsigned char hash[SHA1_LENGTH];
|
||||||
|
@ -2804,9 +2759,9 @@ nsCrypto::SignText(const nsAString& aStringToSign, const nsAString& aCaOption,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (srv != SECSuccess) {
|
if (srv != SECSuccess) {
|
||||||
aResult.Append(internalError);
|
aReturn.Append(internalError);
|
||||||
|
|
||||||
return NS_OK;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SECItem binary_item;
|
SECItem binary_item;
|
||||||
|
@ -2816,25 +2771,26 @@ nsCrypto::SignText(const nsAString& aStringToSign, const nsAString& aCaOption,
|
||||||
|
|
||||||
char *result = NSSBase64_EncodeItem(nullptr, nullptr, 0, &binary_item);
|
char *result = NSSBase64_EncodeItem(nullptr, nullptr, 0, &binary_item);
|
||||||
if (result) {
|
if (result) {
|
||||||
AppendASCIItoUTF16(result, aResult);
|
AppendASCIItoUTF16(result, aReturn);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
aResult.Append(internalError);
|
aReturn.Append(internalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
PORT_Free(result);
|
PORT_Free(result);
|
||||||
|
|
||||||
return NS_OK;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Logout out of all installed PKCS11 tokens.
|
void
|
||||||
NS_IMETHODIMP
|
nsCrypto::Logout(ErrorResult& aRv)
|
||||||
nsCrypto::Logout()
|
|
||||||
{
|
{
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
nsCOMPtr<nsINSSComponent> nssComponent(do_GetService(kNSSComponentCID, &rv));
|
nsCOMPtr<nsINSSComponent> nssComponent(do_GetService(kNSSComponentCID, &rv));
|
||||||
if (NS_FAILED(rv))
|
if (NS_FAILED(rv)) {
|
||||||
return rv;
|
aRv.Throw(rv);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
nsNSSShutDownPreventionLock locker;
|
nsNSSShutDownPreventionLock locker;
|
||||||
|
@ -2842,20 +2798,16 @@ nsCrypto::Logout()
|
||||||
SSL_ClearSessionCache();
|
SSL_ClearSessionCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
return nssComponent->LogoutAuthenticatedPK11();
|
rv = nssComponent->LogoutAuthenticatedPK11();
|
||||||
|
if (NS_FAILED(rv)) {
|
||||||
|
aRv.Throw(rv);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
void
|
||||||
nsCrypto::DisableRightClick()
|
nsCrypto::DisableRightClick(ErrorResult& aRv)
|
||||||
{
|
{
|
||||||
return NS_ERROR_NOT_IMPLEMENTED;
|
aRv.Throw(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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCRMFObject::nsCRMFObject()
|
nsCRMFObject::nsCRMFObject()
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
#ifndef _nsCrypto_h_
|
#ifndef _nsCrypto_h_
|
||||||
#define _nsCrypto_h_
|
#define _nsCrypto_h_
|
||||||
|
|
||||||
|
#include "mozilla/dom/BindingDeclarations.h"
|
||||||
|
#include "mozilla/ErrorResult.h"
|
||||||
#ifndef MOZ_DISABLE_CRYPTOLEGACY
|
#ifndef MOZ_DISABLE_CRYPTOLEGACY
|
||||||
#include "Crypto.h"
|
#include "Crypto.h"
|
||||||
#include "nsCOMPtr.h"
|
#include "nsCOMPtr.h"
|
||||||
|
@ -23,7 +25,6 @@
|
||||||
class nsIPSMComponent;
|
class nsIPSMComponent;
|
||||||
class nsIDOMScriptObjectFactory;
|
class nsIDOMScriptObjectFactory;
|
||||||
|
|
||||||
|
|
||||||
class nsCRMFObject : public nsIDOMCRMFObject
|
class nsCRMFObject : public nsIDOMCRMFObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -41,7 +42,6 @@ private:
|
||||||
nsString mBase64Request;
|
nsString mBase64Request;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class nsCrypto: public mozilla::dom::Crypto
|
class nsCrypto: public mozilla::dom::Crypto
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -54,6 +54,46 @@ public:
|
||||||
// implements the legacy methods.
|
// implements the legacy methods.
|
||||||
NS_DECL_NSIDOMCRYPTO
|
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:
|
private:
|
||||||
static already_AddRefed<nsIPrincipal> GetScriptPrincipal(JSContext *cx);
|
static already_AddRefed<nsIPrincipal> GetScriptPrincipal(JSContext *cx);
|
||||||
|
|
||||||
|
|
|
@ -125,11 +125,14 @@ DebuggerTransport.prototype = {
|
||||||
|
|
||||||
onStopRequest:
|
onStopRequest:
|
||||||
makeInfallible(function DT_onStopRequest(aRequest, aContext, aStatus) {
|
makeInfallible(function DT_onStopRequest(aRequest, aContext, aStatus) {
|
||||||
this.close();
|
let self = this;
|
||||||
if (this.hooks) {
|
Services.tm.currentThread.dispatch(makeInfallible(function() {
|
||||||
this.hooks.onClosed(aStatus);
|
self.close();
|
||||||
this.hooks = null;
|
if (self.hooks) {
|
||||||
}
|
self.hooks.onClosed(aStatus);
|
||||||
|
self.hooks = null;
|
||||||
|
}
|
||||||
|
}, "DebuggerTransport instance's this.close"), 0);
|
||||||
}, "DebuggerTransport.prototype.onStopRequest"),
|
}, "DebuggerTransport.prototype.onStopRequest"),
|
||||||
|
|
||||||
onDataAvailable:
|
onDataAvailable:
|
||||||
|
|
Загрузка…
Ссылка в новой задаче