Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/dom/ImageCapture.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim:set ts=2 sw=2 sts=2 et cindent: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef IMAGECAPTURE_H
8
#define IMAGECAPTURE_H
9
10
#include "mozilla/DOMEventTargetHelper.h"
11
#include "mozilla/dom/ImageCaptureBinding.h"
12
#include "mozilla/Logging.h"
13
14
namespace mozilla {
15
16
#ifndef IC_LOG
17
LogModule* GetICLog();
18
#define IC_LOG(...) MOZ_LOG(GetICLog(), mozilla::LogLevel::Debug, (__VA_ARGS__))
19
#endif
20
21
namespace dom {
22
23
class Blob;
24
class VideoStreamTrack;
25
26
/**
27
 *  Implementation of https://dvcs.w3.org/hg/dap/raw-file/default/media-stream-
28
 *  capture/ImageCapture.html.
29
 *  The ImageCapture accepts a VideoStreamTrack as input source. The image will
30
 *  be sent back as a JPG format via Blob event.
31
 *
32
 *  All the functions in ImageCapture are run in main thread.
33
 *
34
 *  There are two ways to capture image, MediaEngineSource and MediaStreamGraph.
35
 *  When the implementation of MediaEngineSource supports TakePhoto(),
36
 *  it uses the platform camera to grab image. Otherwise, it falls back
37
 *  to the MediaStreamGraph way.
38
 */
39
40
class ImageCapture final : public DOMEventTargetHelper
41
{
42
public:
43
  NS_DECL_ISUPPORTS_INHERITED
44
  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ImageCapture, DOMEventTargetHelper)
45
46
  IMPL_EVENT_HANDLER(photo)
47
  IMPL_EVENT_HANDLER(error)
48
49
  // WebIDL members.
50
  void TakePhoto(ErrorResult& aResult);
51
52
  // The MediaStream passed into the constructor.
53
  VideoStreamTrack* GetVideoStreamTrack() const;
54
55
  // nsWrapperCache member
56
  JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override
57
0
  {
58
0
    return ImageCapture_Binding::Wrap(aCx, this, aGivenProto);
59
0
  }
60
61
  // ImageCapture class members
62
0
  nsPIDOMWindowInner* GetParentObject() { return GetOwner(); }
63
64
  static already_AddRefed<ImageCapture> Constructor(const GlobalObject& aGlobal,
65
                                                    VideoStreamTrack& aTrack,
66
                                                    ErrorResult& aRv);
67
68
  ImageCapture(VideoStreamTrack* aVideoStreamTrack,
69
               nsPIDOMWindowInner* aOwnerWindow);
70
71
  // Post a Blob event to script.
72
  nsresult PostBlobEvent(Blob* aBlob);
73
74
  // Post an error event to script.
75
  // aErrorCode should be one of error codes defined in ImageCaptureError.h.
76
  // aReason is the nsresult which maps to a error string in dom/base/domerr.msg.
77
  nsresult PostErrorEvent(uint16_t aErrorCode, nsresult aReason = NS_OK);
78
79
  bool CheckPrincipal();
80
81
protected:
82
  virtual ~ImageCapture();
83
84
  // Capture image by MediaEngine. If it's not support taking photo, this function
85
  // should return NS_ERROR_NOT_IMPLEMENTED.
86
  nsresult TakePhotoByMediaEngine();
87
88
  RefPtr<VideoStreamTrack> mVideoStreamTrack;
89
};
90
91
} // namespace dom
92
} // namespace mozilla
93
94
#endif // IMAGECAPTURE_H