diff --git a/dom/events/ImageCaptureError.cpp b/dom/events/ImageCaptureError.cpp new file mode 100644 index 000000000000..d81d39093ef0 --- /dev/null +++ b/dom/events/ImageCaptureError.cpp @@ -0,0 +1,59 @@ +/* -*- Mode: C++; 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/. */ + +#include "mozilla/dom/ImageCaptureError.h" +#include "mozilla/dom/ImageCaptureErrorEventBinding.h" + +namespace mozilla { +namespace dom { + +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(ImageCaptureError, mParent) +NS_IMPL_CYCLE_COLLECTING_ADDREF(ImageCaptureError) +NS_IMPL_CYCLE_COLLECTING_RELEASE(ImageCaptureError) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ImageCaptureError) + NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY + NS_INTERFACE_MAP_ENTRY(nsISupports) +NS_INTERFACE_MAP_END + +ImageCaptureError::ImageCaptureError(nsISupports* aParent, + uint16_t aCode, + const nsAString& aMessage) + : mParent(aParent) + , mMessage(aMessage) + , mCode(aCode) +{ + SetIsDOMBinding(); +} + +ImageCaptureError::~ImageCaptureError() +{ +} + +nsISupports* +ImageCaptureError::GetParentObject() const +{ + return mParent; +} + +JSObject* +ImageCaptureError::WrapObject(JSContext* aCx) +{ + return ImageCaptureErrorBinding::Wrap(aCx, this); +} + +uint16_t +ImageCaptureError::Code() const +{ + return mCode; +} + +void +ImageCaptureError::GetMessage(nsAString& retval) const +{ + retval = mMessage; +} + +} // namespace dom +} // namespace mozilla diff --git a/dom/events/ImageCaptureError.h b/dom/events/ImageCaptureError.h new file mode 100644 index 000000000000..c0b4eb9cd601 --- /dev/null +++ b/dom/events/ImageCaptureError.h @@ -0,0 +1,58 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim:set ts=2 sw=2 sts=2 et cindent: */ +/* 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/. */ + +#ifndef mozilla_dom_ImageCaptureError_h +#define mozilla_dom_ImageCaptureError_h + +#include "mozilla/Attributes.h" +#include "nsCOMPtr.h" +#include "nsString.h" +#include "nsWrapperCache.h" + +namespace mozilla { +namespace dom { + +/** + * This is the implementation of ImageCaptureError on W3C specification + * https://dvcs.w3.org/hg/dap/raw-file/default/media-stream-capture/ImageCapture.html#idl-def-ImageCaptureError. + * This object should be generated by ImageCapture object only. + */ +class ImageCaptureError MOZ_FINAL : public nsISupports, + public nsWrapperCache +{ +public: + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ImageCaptureError) + + ImageCaptureError(nsISupports* aParent, uint16_t aCode, const nsAString& aMessage); + + nsISupports* GetParentObject() const; + + virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; + + uint16_t Code() const; + + enum { + FRAME_GRAB_ERROR = 1, + SETTINGS_ERROR = 2, + PHOTO_ERROR = 3, + ERROR_UNKNOWN = 4, + }; + + void GetMessage(nsAString& retval) const; + +private: + ~ImageCaptureError(); + + nsCOMPtr mParent; + nsString mMessage; + uint16_t mCode; +}; + +} // namespace dom +} // namespace mozilla + +#endif // mozilla_dom_ImageCaptureError_h diff --git a/dom/events/moz.build b/dom/events/moz.build index 7ac39995ae4c..7dff5c9d78c0 100644 --- a/dom/events/moz.build +++ b/dom/events/moz.build @@ -44,6 +44,7 @@ EXPORTS.mozilla.dom += [ 'Event.h', 'EventTarget.h', 'FocusEvent.h', + 'ImageCaptureError.h', 'InputEvent.h', 'KeyboardEvent.h', 'MessageEvent.h', @@ -86,6 +87,7 @@ UNIFIED_SOURCES += [ 'EventListenerService.cpp', 'EventTarget.cpp', 'FocusEvent.cpp', + 'ImageCaptureError.cpp', 'IMEContentObserver.cpp', 'IMEStateManager.cpp', 'InputEvent.cpp', diff --git a/dom/events/test/test_all_synthetic_events.html b/dom/events/test/test_all_synthetic_events.html index 92d88b40d2e1..764336bfd43b 100644 --- a/dom/events/test/test_all_synthetic_events.html +++ b/dom/events/test/test_all_synthetic_events.html @@ -195,6 +195,10 @@ const kEventConstructors = { return new IDBVersionChangeEvent(aName, aProps); }, }, + ImageCaptureErrorEvent: { create: function (aName, aProps) { + return new ImageCaptureErrorEvent(aName, aProps); + }, + }, InputEvent: { create: function (aName, aProps) { return new InputEvent(aName, aProps); }, diff --git a/dom/tests/mochitest/general/test_interfaces.html b/dom/tests/mochitest/general/test_interfaces.html index 707739b119b1..9471bbc7bf2d 100644 --- a/dom/tests/mochitest/general/test_interfaces.html +++ b/dom/tests/mochitest/general/test_interfaces.html @@ -595,6 +595,8 @@ var interfaceNamesInGlobalScope = "IDBVersionChangeEvent", // IMPORTANT: Do not change this list without review from a DOM peer! "Image", +// IMPORTANT: Do not change this list without review from a DOM peer! + "ImageCaptureErrorEvent", // IMPORTANT: Do not change this list without review from a DOM peer! "ImageData", // IMPORTANT: Do not change this list without review from a DOM peer! diff --git a/dom/webidl/ImageCaptureErrorEvent.webidl b/dom/webidl/ImageCaptureErrorEvent.webidl new file mode 100644 index 000000000000..86d3216d8d62 --- /dev/null +++ b/dom/webidl/ImageCaptureErrorEvent.webidl @@ -0,0 +1,31 @@ +/* -*- 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 + * https://dvcs.w3.org/hg/dap/raw-file/default/media-stream-capture/ImageCapture.html + * + * Copyright © 2012-2014 W3C® (MIT, ERCIM, Keio, Beihang), All Rights Reserved. + * W3C liability, trademark and document use rules apply. + */ + +[Constructor(DOMString type, optional ImageCaptureErrorEventInit imageCaptureErrorInitDict)] +interface ImageCaptureErrorEvent : Event { + readonly attribute ImageCaptureError? imageCaptureError; +}; + +dictionary ImageCaptureErrorEventInit : EventInit { + ImageCaptureError? imageCaptureError = null; +}; + +[NoInterfaceObject] +interface ImageCaptureError { + const unsigned short FRAME_GRAB_ERROR = 1; + const unsigned short SETTINGS_ERROR = 2; + const unsigned short PHOTO_ERROR = 3; + const unsigned short ERROR_UNKNOWN = 4; + readonly attribute unsigned short code; + readonly attribute DOMString message; +}; + diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index 7959d65243b7..deb373accdaa 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -652,6 +652,7 @@ GENERATED_EVENTS_WEBIDL_FILES = [ 'ErrorEvent.webidl', 'HashChangeEvent.webidl', 'IccChangeEvent.webidl', + 'ImageCaptureErrorEvent.webidl', 'MediaStreamEvent.webidl', 'MediaStreamTrackEvent.webidl', 'MozApplicationEvent.webidl',