diff --git a/dom/base/Navigator.cpp b/dom/base/Navigator.cpp index 149a62b7b6..2019eb186c 100644 --- a/dom/base/Navigator.cpp +++ b/dom/base/Navigator.cpp @@ -551,7 +551,7 @@ Navigator::Storage() } USB* -Navigator::GetUsb() +Navigator::Usb() { MOZ_ASSERT(mWindow); diff --git a/dom/base/Navigator.h b/dom/base/Navigator.h index 9201d9ae3d..46891bd7a2 100644 --- a/dom/base/Navigator.h +++ b/dom/base/Navigator.h @@ -227,7 +227,7 @@ public: bool MozE10sEnabled(); StorageManager* Storage(); - USB* GetUsb(); + USB* Usb(); static void GetAcceptLanguages(nsTArray& aLanguages); diff --git a/dom/usb/USBAlternateInterface.h b/dom/usb/USBAlternateInterface.h new file mode 100644 index 0000000000..fc75d77a43 --- /dev/null +++ b/dom/usb/USBAlternateInterface.h @@ -0,0 +1,38 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +#ifndef mozilla_dom_USBAlternateInterface_h +#define mozilla_dom_USBAlternateInterface_h + +#include "mozilla/dom/Nullable.h" +#include "mozilla/dom/USBAlternateInterfaceBinding.h" +#include "mozilla/dom/USBEndpoint.h" +#include "nsCOMPtr.h" +#include "nsCycleCollectionParticipant.h" +#include "nsString.h" +#include "nsTArray.h" +#include "nsWrapperCache.h" + +namespace mozilla { namespace dom { +class USBAlternateInterface final : public nsISupports, public nsWrapperCache +{ +public: + USBAlternateInterface(nsIGlobalObject*, uint8_t, uint8_t, uint8_t, uint8_t, + nsTArray>&&); + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(USBAlternateInterface) + nsISupports* GetParentObject() const { return mOwner; } + uint8_t AlternateSetting() const { return mSetting; } + uint8_t InterfaceClass() const { return mClass; } + uint8_t InterfaceSubclass() const { return mSubclass; } + uint8_t InterfaceProtocol() const { return mProtocol; } + void GetInterfaceName(Nullable& aValue) const { aValue = mName; } + void GetEndpoints(nsTArray>& aValue) const { aValue = mEndpoints; } + JSObject* WrapObject(JSContext*, JS::Handle) override; +private: + ~USBAlternateInterface() = default; + nsCOMPtr mOwner; + uint8_t mSetting, mClass, mSubclass, mProtocol; + Nullable mName; + nsTArray> mEndpoints; +}; +} } +#endif // mozilla_dom_USBAlternateInterface_h diff --git a/dom/usb/USBConfiguration.h b/dom/usb/USBConfiguration.h new file mode 100644 index 0000000000..1f93406766 --- /dev/null +++ b/dom/usb/USBConfiguration.h @@ -0,0 +1,35 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +#ifndef mozilla_dom_USBConfiguration_h +#define mozilla_dom_USBConfiguration_h + +#include "mozilla/dom/Nullable.h" +#include "mozilla/dom/USBConfigurationBinding.h" +#include "mozilla/dom/USBInterface.h" +#include "nsCOMPtr.h" +#include "nsCycleCollectionParticipant.h" +#include "nsString.h" +#include "nsTArray.h" +#include "nsWrapperCache.h" + +namespace mozilla { namespace dom { +class USBConfiguration final : public nsISupports, public nsWrapperCache +{ +public: + USBConfiguration(nsIGlobalObject*, uint8_t, + nsTArray>&&); + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(USBConfiguration) + nsISupports* GetParentObject() const { return mOwner; } + uint8_t ConfigurationValue() const { return mValue; } + void GetConfigurationName(Nullable& aValue) const { aValue = mName; } + void GetInterfaces(nsTArray>& aValue) const { aValue = mInterfaces; } + JSObject* WrapObject(JSContext*, JS::Handle) override; +private: + ~USBConfiguration() = default; + nsCOMPtr mOwner; + uint8_t mValue; + Nullable mName; + nsTArray> mInterfaces; +}; +} } +#endif // mozilla_dom_USBConfiguration_h diff --git a/dom/usb/USBDescriptors.h b/dom/usb/USBDescriptors.h index 277802e245..c973fad24b 100644 --- a/dom/usb/USBDescriptors.h +++ b/dom/usb/USBDescriptors.h @@ -3,198 +3,11 @@ #ifndef mozilla_dom_USBDescriptors_h #define mozilla_dom_USBDescriptors_h -#include "mozilla/ErrorResult.h" -#include "mozilla/dom/Nullable.h" -#include "mozilla/dom/USBBinding.h" -#include "mozilla/dom/USBAlternateInterfaceBinding.h" -#include "mozilla/dom/USBConfigurationBinding.h" -#include "mozilla/dom/USBEndpointBinding.h" -#include "mozilla/dom/USBInterfaceBinding.h" -#include "mozilla/dom/USBInTransferResultBinding.h" -#include "mozilla/dom/USBOutTransferResultBinding.h" -#include "nsCOMPtr.h" -#include "nsCycleCollectionParticipant.h" -#include "nsString.h" -#include "nsTArray.h" -#include "nsWrapperCache.h" - -namespace mozilla { -namespace dom { - -class USBEndpoint final : public nsISupports, public nsWrapperCache -{ -public: - USBEndpoint(nsIGlobalObject* aOwner, uint8_t aNumber, - USBDirection aDirection, USBEndpointType aType, - uint16_t aPacketSize); - - NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(USBEndpoint) - - nsISupports* GetParentObject() const { return mOwner; } - uint8_t EndpointNumber() const { return mNumber; } - USBDirection Direction() const { return mDirection; } - USBEndpointType Type() const { return mType; } - uint16_t PacketSize() const { return mPacketSize; } - - JSObject* WrapObject(JSContext* aCx, - JS::Handle aGivenProto) override; - -private: - ~USBEndpoint() = default; - - nsCOMPtr mOwner; - uint8_t mNumber; - USBDirection mDirection; - USBEndpointType mType; - uint16_t mPacketSize; -}; - -class USBAlternateInterface final : public nsISupports, public nsWrapperCache -{ -public: - USBAlternateInterface(nsIGlobalObject* aOwner, uint8_t aSetting, - uint8_t aClass, uint8_t aSubclass, uint8_t aProtocol, - nsTArray>&& aEndpoints); - - NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(USBAlternateInterface) - - nsISupports* GetParentObject() const { return mOwner; } - uint8_t AlternateSetting() const { return mSetting; } - uint8_t InterfaceClass() const { return mClass; } - uint8_t InterfaceSubclass() const { return mSubclass; } - uint8_t InterfaceProtocol() const { return mProtocol; } - void GetInterfaceName(Nullable& aValue) const - { aValue = mName; } - void GetEndpoints(nsTArray>& aValue) const - { aValue = mEndpoints; } - - JSObject* WrapObject(JSContext* aCx, - JS::Handle aGivenProto) override; - -private: - ~USBAlternateInterface() = default; - - nsCOMPtr mOwner; - uint8_t mSetting; - uint8_t mClass; - uint8_t mSubclass; - uint8_t mProtocol; - Nullable mName; - nsTArray> mEndpoints; -}; - -class USBInterface final : public nsISupports, public nsWrapperCache -{ -public: - USBInterface(nsIGlobalObject* aOwner, uint8_t aNumber, - nsTArray>&& aAlternates); - - NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(USBInterface) - - nsISupports* GetParentObject() const { return mOwner; } - uint8_t InterfaceNumber() const { return mNumber; } - USBAlternateInterface* GetAlternate() const { return mAlternate; } - void SetAlternate(uint8_t aSetting); - void GetAlternates(nsTArray>& aValue) const - { aValue = mAlternates; } - bool Claimed() const { return mClaimed; } - void SetClaimed(bool aClaimed) { mClaimed = aClaimed; } - - JSObject* WrapObject(JSContext* aCx, - JS::Handle aGivenProto) override; - -private: - ~USBInterface() = default; - - nsCOMPtr mOwner; - uint8_t mNumber; - RefPtr mAlternate; - nsTArray> mAlternates; - bool mClaimed; -}; - -class USBConfiguration final : public nsISupports, public nsWrapperCache -{ -public: - USBConfiguration(nsIGlobalObject* aOwner, uint8_t aValue, - nsTArray>&& aInterfaces); - - NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(USBConfiguration) - - nsISupports* GetParentObject() const { return mOwner; } - uint8_t ConfigurationValue() const { return mValue; } - void GetConfigurationName(Nullable& aValue) const - { aValue = mName; } - void GetInterfaces(nsTArray>& aValue) const - { aValue = mInterfaces; } - - JSObject* WrapObject(JSContext* aCx, - JS::Handle aGivenProto) override; - -private: - ~USBConfiguration() = default; - - nsCOMPtr mOwner; - uint8_t mValue; - Nullable mName; - nsTArray> mInterfaces; -}; - -class USBInTransferResult final : public nsISupports, public nsWrapperCache -{ -public: - USBInTransferResult(nsIGlobalObject* aOwner, USBTransferStatus aStatus, - const nsTArray& aData); - - NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(USBInTransferResult) - - nsISupports* GetParentObject() const { return mOwner; } - USBTransferStatus Status() const { return mStatus; } - void GetData(JSContext* aCx, JS::MutableHandle aData, - ErrorResult& aRv); - - JSObject* WrapObject(JSContext* aCx, - JS::Handle aGivenProto) override; - -private: - ~USBInTransferResult(); - - nsCOMPtr mOwner; - USBTransferStatus mStatus; - nsTArray mRawData; - JS::Heap mData; -}; - -class USBOutTransferResult final : public nsISupports, public nsWrapperCache -{ -public: - USBOutTransferResult(nsIGlobalObject* aOwner, USBTransferStatus aStatus, - uint32_t aBytesWritten); - - NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(USBOutTransferResult) - - nsISupports* GetParentObject() const { return mOwner; } - USBTransferStatus Status() const { return mStatus; } - uint32_t BytesWritten() const { return mBytesWritten; } - - JSObject* WrapObject(JSContext* aCx, - JS::Handle aGivenProto) override; - -private: - ~USBOutTransferResult() = default; - - nsCOMPtr mOwner; - USBTransferStatus mStatus; - uint32_t mBytesWritten; -}; - -} // namespace dom -} // namespace mozilla +#include "mozilla/dom/USBAlternateInterface.h" +#include "mozilla/dom/USBConfiguration.h" +#include "mozilla/dom/USBEndpoint.h" +#include "mozilla/dom/USBInTransferResult.h" +#include "mozilla/dom/USBInterface.h" +#include "mozilla/dom/USBOutTransferResult.h" #endif // mozilla_dom_USBDescriptors_h diff --git a/dom/usb/USBEndpoint.h b/dom/usb/USBEndpoint.h new file mode 100644 index 0000000000..aa5a7fc267 --- /dev/null +++ b/dom/usb/USBEndpoint.h @@ -0,0 +1,33 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +#ifndef mozilla_dom_USBEndpoint_h +#define mozilla_dom_USBEndpoint_h + +#include "mozilla/dom/USBBinding.h" +#include "mozilla/dom/USBEndpointBinding.h" +#include "nsCOMPtr.h" +#include "nsCycleCollectionParticipant.h" +#include "nsWrapperCache.h" + +namespace mozilla { namespace dom { +class USBEndpoint final : public nsISupports, public nsWrapperCache +{ +public: + USBEndpoint(nsIGlobalObject*, uint8_t, USBDirection, USBEndpointType, uint16_t); + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(USBEndpoint) + nsISupports* GetParentObject() const { return mOwner; } + uint8_t EndpointNumber() const { return mNumber; } + USBDirection Direction() const { return mDirection; } + USBEndpointType Type() const { return mType; } + uint16_t PacketSize() const { return mPacketSize; } + JSObject* WrapObject(JSContext*, JS::Handle) override; +private: + ~USBEndpoint() = default; + nsCOMPtr mOwner; + uint8_t mNumber; + USBDirection mDirection; + USBEndpointType mType; + uint16_t mPacketSize; +}; +} } +#endif // mozilla_dom_USBEndpoint_h diff --git a/dom/usb/USBInTransferResult.h b/dom/usb/USBInTransferResult.h new file mode 100644 index 0000000000..8cf61268d7 --- /dev/null +++ b/dom/usb/USBInTransferResult.h @@ -0,0 +1,33 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +#ifndef mozilla_dom_USBInTransferResult_h +#define mozilla_dom_USBInTransferResult_h + +#include "mozilla/ErrorResult.h" +#include "mozilla/dom/USBBinding.h" +#include "mozilla/dom/USBInTransferResultBinding.h" +#include "nsCOMPtr.h" +#include "nsCycleCollectionParticipant.h" +#include "nsTArray.h" +#include "nsWrapperCache.h" + +namespace mozilla { namespace dom { +class USBInTransferResult final : public nsISupports, public nsWrapperCache +{ +public: + USBInTransferResult(nsIGlobalObject*, USBTransferStatus, + const nsTArray&); + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(USBInTransferResult) + nsISupports* GetParentObject() const { return mOwner; } + USBTransferStatus Status() const { return mStatus; } + void GetData(JSContext*, JS::MutableHandle, ErrorResult&); + JSObject* WrapObject(JSContext*, JS::Handle) override; +private: + ~USBInTransferResult(); + nsCOMPtr mOwner; + USBTransferStatus mStatus; + nsTArray mRawData; + JS::Heap mData; +}; +} } +#endif // mozilla_dom_USBInTransferResult_h diff --git a/dom/usb/USBInterface.h b/dom/usb/USBInterface.h new file mode 100644 index 0000000000..df0ba0023f --- /dev/null +++ b/dom/usb/USBInterface.h @@ -0,0 +1,37 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +#ifndef mozilla_dom_USBInterface_h +#define mozilla_dom_USBInterface_h + +#include "mozilla/dom/USBInterfaceBinding.h" +#include "mozilla/dom/USBAlternateInterface.h" +#include "nsCOMPtr.h" +#include "nsCycleCollectionParticipant.h" +#include "nsTArray.h" +#include "nsWrapperCache.h" + +namespace mozilla { namespace dom { +class USBInterface final : public nsISupports, public nsWrapperCache +{ +public: + USBInterface(nsIGlobalObject*, uint8_t, + nsTArray>&&); + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(USBInterface) + nsISupports* GetParentObject() const { return mOwner; } + uint8_t InterfaceNumber() const { return mNumber; } + USBAlternateInterface* GetAlternate() const { return mAlternate; } + void SetAlternate(uint8_t); + void GetAlternates(nsTArray>& aValue) const { aValue = mAlternates; } + bool Claimed() const { return mClaimed; } + void SetClaimed(bool aClaimed) { mClaimed = aClaimed; } + JSObject* WrapObject(JSContext*, JS::Handle) override; +private: + ~USBInterface() = default; + nsCOMPtr mOwner; + uint8_t mNumber; + RefPtr mAlternate; + nsTArray> mAlternates; + bool mClaimed; +}; +} } +#endif // mozilla_dom_USBInterface_h diff --git a/dom/usb/USBOutTransferResult.h b/dom/usb/USBOutTransferResult.h new file mode 100644 index 0000000000..9e228cf792 --- /dev/null +++ b/dom/usb/USBOutTransferResult.h @@ -0,0 +1,29 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +#ifndef mozilla_dom_USBOutTransferResult_h +#define mozilla_dom_USBOutTransferResult_h + +#include "mozilla/dom/USBBinding.h" +#include "mozilla/dom/USBOutTransferResultBinding.h" +#include "nsCOMPtr.h" +#include "nsCycleCollectionParticipant.h" +#include "nsWrapperCache.h" + +namespace mozilla { namespace dom { +class USBOutTransferResult final : public nsISupports, public nsWrapperCache +{ +public: + USBOutTransferResult(nsIGlobalObject*, USBTransferStatus, uint32_t); + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(USBOutTransferResult) + nsISupports* GetParentObject() const { return mOwner; } + USBTransferStatus Status() const { return mStatus; } + uint32_t BytesWritten() const { return mBytesWritten; } + JSObject* WrapObject(JSContext*, JS::Handle) override; +private: + ~USBOutTransferResult() = default; + nsCOMPtr mOwner; + USBTransferStatus mStatus; + uint32_t mBytesWritten; +}; +} } +#endif // mozilla_dom_USBOutTransferResult_h diff --git a/dom/usb/moz.build b/dom/usb/moz.build index ec8da04a74..a674a4efe6 100644 --- a/dom/usb/moz.build +++ b/dom/usb/moz.build @@ -3,8 +3,14 @@ EXPORTS.mozilla.dom += [ 'USB.h', 'USBBackend.h', + 'USBAlternateInterface.h', + 'USBConfiguration.h', 'USBDescriptors.h', 'USBDevice.h', + 'USBEndpoint.h', + 'USBInTransferResult.h', + 'USBInterface.h', + 'USBOutTransferResult.h', ] UNIFIED_SOURCES += [