| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/mediacapturefromelement/HTMLCanvasElementCapture.h" | 5 #include "modules/mediacapturefromelement/HTMLCanvasElementCapture.h" |
| 6 | 6 |
| 7 #include "core/dom/ExceptionCode.h" | 7 #include "core/dom/ExceptionCode.h" |
| 8 #include "core/html/HTMLCanvasElement.h" | 8 #include "core/html/HTMLCanvasElement.h" |
| 9 #include "modules/mediacapturefromelement/CanvasCaptureMediaStreamTrack.h" | 9 #include "modules/mediacapturefromelement/CanvasCaptureMediaStreamTrack.h" |
| 10 #include "modules/mediastream/MediaStream.h" | 10 #include "modules/mediastream/MediaStream.h" |
| 11 #include "public/platform/Platform.h" | 11 #include "public/platform/Platform.h" |
| 12 #include "public/platform/WebCanvasCaptureHandler.h" | 12 #include "public/platform/WebCanvasCaptureHandler.h" |
| 13 #include "public/platform/WebMediaStream.h" | 13 #include "public/platform/WebMediaStream.h" |
| 14 #include "public/platform/WebMediaStreamTrack.h" | 14 #include "public/platform/WebMediaStreamTrack.h" |
| 15 #include "wtf/PtrUtil.h" | |
| 16 #include <memory> | |
| 17 | 15 |
| 18 namespace { | 16 namespace { |
| 19 const double kDefaultFrameRate = 60.0; | 17 const double kDefaultFrameRate = 60.0; |
| 20 } // anonymous namespace | 18 } // anonymous namespace |
| 21 | 19 |
| 22 namespace blink { | 20 namespace blink { |
| 23 | 21 |
| 24 MediaStream* HTMLCanvasElementCapture::captureStream(HTMLCanvasElement& element,
ExceptionState& exceptionState) | 22 MediaStream* HTMLCanvasElementCapture::captureStream(HTMLCanvasElement& element,
ExceptionState& exceptionState) |
| 25 { | 23 { |
| 26 return HTMLCanvasElementCapture::captureStream(element, false, 0, exceptionS
tate); | 24 return HTMLCanvasElementCapture::captureStream(element, false, 0, exceptionS
tate); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 38 | 36 |
| 39 MediaStream* HTMLCanvasElementCapture::captureStream(HTMLCanvasElement& element,
bool givenFrameRate, double frameRate, ExceptionState& exceptionState) | 37 MediaStream* HTMLCanvasElementCapture::captureStream(HTMLCanvasElement& element,
bool givenFrameRate, double frameRate, ExceptionState& exceptionState) |
| 40 { | 38 { |
| 41 if (!element.originClean()) { | 39 if (!element.originClean()) { |
| 42 exceptionState.throwSecurityError("Canvas is not origin-clean."); | 40 exceptionState.throwSecurityError("Canvas is not origin-clean."); |
| 43 return nullptr; | 41 return nullptr; |
| 44 } | 42 } |
| 45 | 43 |
| 46 WebMediaStreamTrack track; | 44 WebMediaStreamTrack track; |
| 47 const WebSize size(element.width(), element.height()); | 45 const WebSize size(element.width(), element.height()); |
| 48 std::unique_ptr<WebCanvasCaptureHandler> handler; | 46 OwnPtr<WebCanvasCaptureHandler> handler; |
| 49 if (givenFrameRate) | 47 if (givenFrameRate) |
| 50 handler = wrapUnique(Platform::current()->createCanvasCaptureHandler(siz
e, frameRate, &track)); | 48 handler = adoptPtr(Platform::current()->createCanvasCaptureHandler(size,
frameRate, &track)); |
| 51 else | 49 else |
| 52 handler = wrapUnique(Platform::current()->createCanvasCaptureHandler(siz
e, kDefaultFrameRate, &track)); | 50 handler = adoptPtr(Platform::current()->createCanvasCaptureHandler(size,
kDefaultFrameRate, &track)); |
| 53 | 51 |
| 54 if (!handler) { | 52 if (!handler) { |
| 55 exceptionState.throwDOMException(NotSupportedError, "No CanvasCapture ha
ndler can be created."); | 53 exceptionState.throwDOMException(NotSupportedError, "No CanvasCapture ha
ndler can be created."); |
| 56 return nullptr; | 54 return nullptr; |
| 57 } | 55 } |
| 58 | 56 |
| 59 CanvasCaptureMediaStreamTrack* canvasTrack; | 57 CanvasCaptureMediaStreamTrack* canvasTrack; |
| 60 if (givenFrameRate) | 58 if (givenFrameRate) |
| 61 canvasTrack = CanvasCaptureMediaStreamTrack::create(track, &element, std
::move(handler), frameRate); | 59 canvasTrack = CanvasCaptureMediaStreamTrack::create(track, &element, std
::move(handler), frameRate); |
| 62 else | 60 else |
| 63 canvasTrack = CanvasCaptureMediaStreamTrack::create(track, &element, std
::move(handler)); | 61 canvasTrack = CanvasCaptureMediaStreamTrack::create(track, &element, std
::move(handler)); |
| 64 // We want to capture a frame in the beginning. | 62 // We want to capture a frame in the beginning. |
| 65 canvasTrack->requestFrame(); | 63 canvasTrack->requestFrame(); |
| 66 | 64 |
| 67 MediaStreamTrackVector tracks; | 65 MediaStreamTrackVector tracks; |
| 68 tracks.append(canvasTrack); | 66 tracks.append(canvasTrack); |
| 69 return MediaStream::create(element.getExecutionContext(), tracks); | 67 return MediaStream::create(element.getExecutionContext(), tracks); |
| 70 } | 68 } |
| 71 | 69 |
| 72 } // namespace blink | 70 } // namespace blink |
| OLD | NEW |