2013-09-16 06:50:24 +04:00
|
|
|
/* -*- 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 IMAGECAPTURE_H
|
|
|
|
#define IMAGECAPTURE_H
|
|
|
|
|
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
|
|
|
#include "mozilla/dom/ImageCaptureBinding.h"
|
2015-05-19 21:15:34 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2013-09-16 06:50:24 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
#ifndef IC_LOG
|
2015-11-15 16:49:01 +03:00
|
|
|
LogModule* GetICLog();
|
2015-06-04 01:25:57 +03:00
|
|
|
#define IC_LOG(...) MOZ_LOG(GetICLog(), mozilla::LogLevel::Debug, (__VA_ARGS__))
|
2013-09-16 06:50:24 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
|
2015-05-12 15:09:51 +03:00
|
|
|
class Blob;
|
2013-09-16 06:50:24 +04:00
|
|
|
class VideoStreamTrack;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of https://dvcs.w3.org/hg/dap/raw-file/default/media-stream-
|
|
|
|
* capture/ImageCapture.html.
|
|
|
|
* The ImageCapture accepts a VideoStreamTrack as input source. The image will
|
|
|
|
* be sent back as a JPG format via Blob event.
|
|
|
|
*
|
|
|
|
* All the functions in ImageCapture are run in main thread.
|
2014-09-09 02:17:00 +04:00
|
|
|
*
|
|
|
|
* There are two ways to capture image, MediaEngineSource and MediaStreamGraph.
|
2016-10-04 21:16:28 +03:00
|
|
|
* When the implementation of MediaEngineSource supports TakePhoto(),
|
|
|
|
* it uses the platform camera to grab image. Otherwise, it falls back
|
2014-09-09 02:17:00 +04:00
|
|
|
* to the MediaStreamGraph way.
|
2013-09-16 06:50:24 +04:00
|
|
|
*/
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class ImageCapture final : public DOMEventTargetHelper
|
2013-09-16 06:50:24 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ImageCapture, DOMEventTargetHelper)
|
|
|
|
|
|
|
|
IMPL_EVENT_HANDLER(photo)
|
|
|
|
IMPL_EVENT_HANDLER(error)
|
|
|
|
|
|
|
|
// WebIDL members.
|
|
|
|
void TakePhoto(ErrorResult& aResult);
|
|
|
|
|
|
|
|
// The MediaStream passed into the constructor.
|
|
|
|
VideoStreamTrack* GetVideoStreamTrack() const;
|
|
|
|
|
|
|
|
// nsWrapperCache member
|
2016-01-18 06:50:29 +03:00
|
|
|
JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override
|
2013-09-16 06:50:24 +04:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
return ImageCaptureBinding::Wrap(aCx, this, aGivenProto);
|
2013-09-16 06:50:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ImageCapture class members
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowInner* GetParentObject() { return GetOwner(); }
|
2013-09-16 06:50:24 +04:00
|
|
|
|
|
|
|
static already_AddRefed<ImageCapture> Constructor(const GlobalObject& aGlobal,
|
|
|
|
VideoStreamTrack& aTrack,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
ImageCapture(VideoStreamTrack* aVideoStreamTrack,
|
|
|
|
nsPIDOMWindowInner* aOwnerWindow);
|
2013-09-16 06:50:24 +04:00
|
|
|
|
|
|
|
// Post a Blob event to script.
|
2015-05-12 15:09:51 +03:00
|
|
|
nsresult PostBlobEvent(Blob* aBlob);
|
2013-09-16 06:50:24 +04:00
|
|
|
|
|
|
|
// Post an error event to script.
|
|
|
|
// aErrorCode should be one of error codes defined in ImageCaptureError.h.
|
|
|
|
// aReason is the nsresult which maps to a error string in dom/base/domerr.msg.
|
|
|
|
nsresult PostErrorEvent(uint16_t aErrorCode, nsresult aReason = NS_OK);
|
|
|
|
|
|
|
|
bool CheckPrincipal();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~ImageCapture();
|
|
|
|
|
2014-09-09 02:17:00 +04:00
|
|
|
// Capture image by MediaEngine. If it's not support taking photo, this function
|
|
|
|
// should return NS_ERROR_NOT_IMPLEMENTED.
|
|
|
|
nsresult TakePhotoByMediaEngine();
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<VideoStreamTrack> mVideoStreamTrack;
|
2013-09-16 06:50:24 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // IMAGECAPTURE_H
|