mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
browser(firefox): use 16-byte long uid instead of ordinal as screencast id (#4147)
This commit is contained in:
parent
e9f5477d52
commit
3c32c1683a
@ -1,2 +1,2 @@
|
|||||||
1190
|
1191
|
||||||
Changed: joel.einbinder@gmail.com Tue 13 Oct 2020 09:08:57 AM PDT
|
Changed: yurys@chromium.org Wed Oct 14 16:12:19 PDT 2020
|
||||||
|
@ -121,7 +121,7 @@ class PageHandler {
|
|||||||
|
|
||||||
_onScreencastStarted() {
|
_onScreencastStarted() {
|
||||||
const info = this._pageTarget.screencastInfo();
|
const info = this._pageTarget.screencastInfo();
|
||||||
this._session.emitEvent('Page.screencastStarted', { screencastId: '' + info.videoSessionId, file: info.file });
|
this._session.emitEvent('Page.screencastStarted', { screencastId: info.videoSessionId, file: info.file });
|
||||||
}
|
}
|
||||||
|
|
||||||
_onDialogOpened(dialog) {
|
_onDialogOpened(dialog) {
|
||||||
|
@ -12,10 +12,10 @@ interface nsIDocShell;
|
|||||||
[scriptable, uuid(d8c4d9e0-9462-445e-9e43-68d3872ad1de)]
|
[scriptable, uuid(d8c4d9e0-9462-445e-9e43-68d3872ad1de)]
|
||||||
interface nsIScreencastService : nsISupports
|
interface nsIScreencastService : nsISupports
|
||||||
{
|
{
|
||||||
long startVideoRecording(in nsIDocShell docShell, in ACString fileName, in uint32_t width, in uint32_t height, in double scale, in int32_t offset_top);
|
AString startVideoRecording(in nsIDocShell docShell, in ACString fileName, in uint32_t width, in uint32_t height, in double scale, in int32_t offset_top);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Will emit 'juggler-screencast-stopped' when the video file is saved.
|
* Will emit 'juggler-screencast-stopped' when the video file is saved.
|
||||||
*/
|
*/
|
||||||
void stopVideoRecording(in long sessionId);
|
void stopVideoRecording(in AString sessionId);
|
||||||
};
|
};
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "mozilla/StaticPtr.h"
|
#include "mozilla/StaticPtr.h"
|
||||||
#include "nsIDocShell.h"
|
#include "nsIDocShell.h"
|
||||||
#include "nsIObserverService.h"
|
#include "nsIObserverService.h"
|
||||||
|
#include "nsIRandomGenerator.h"
|
||||||
#include "nsISupportsPrimitives.h"
|
#include "nsISupportsPrimitives.h"
|
||||||
#include "nsThreadManager.h"
|
#include "nsThreadManager.h"
|
||||||
#include "nsView.h"
|
#include "nsView.h"
|
||||||
@ -34,7 +35,7 @@ namespace {
|
|||||||
|
|
||||||
StaticRefPtr<nsScreencastService> gScreencastService;
|
StaticRefPtr<nsScreencastService> gScreencastService;
|
||||||
|
|
||||||
rtc::scoped_refptr<webrtc::VideoCaptureModule> CreateWindowCapturer(nsIWidget* widget, int sessionId) {
|
rtc::scoped_refptr<webrtc::VideoCaptureModule> CreateWindowCapturer(nsIWidget* widget) {
|
||||||
if (gfxPlatform::IsHeadless()) {
|
if (gfxPlatform::IsHeadless()) {
|
||||||
HeadlessWidget* headlessWidget = static_cast<HeadlessWidget*>(widget);
|
HeadlessWidget* headlessWidget = static_cast<HeadlessWidget*>(widget);
|
||||||
return HeadlessWindowCapturer::Create(headlessWidget);
|
return HeadlessWindowCapturer::Create(headlessWidget);
|
||||||
@ -47,19 +48,35 @@ rtc::scoped_refptr<webrtc::VideoCaptureModule> CreateWindowCapturer(nsIWidget* w
|
|||||||
nsCString windowId;
|
nsCString windowId;
|
||||||
windowId.AppendPrintf("%" PRIuPTR, rawWindowId);
|
windowId.AppendPrintf("%" PRIuPTR, rawWindowId);
|
||||||
bool captureCursor = false;
|
bool captureCursor = false;
|
||||||
return webrtc::DesktopCaptureImpl::Create(sessionId, windowId.get(), webrtc::CaptureDeviceType::Window, captureCursor);
|
static int moduleId = 0;
|
||||||
|
return webrtc::DesktopCaptureImpl::Create(++moduleId, windowId.get(), webrtc::CaptureDeviceType::Window, captureCursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotifyScreencastStopped(int32_t sessionId) {
|
void NotifyScreencastStopped(const nsString& sessionId) {
|
||||||
nsCOMPtr<nsIObserverService> observerService = mozilla::services::GetObserverService();
|
nsCOMPtr<nsIObserverService> observerService = mozilla::services::GetObserverService();
|
||||||
if (!observerService) {
|
if (!observerService) {
|
||||||
fprintf(stderr, "NotifyScreencastStopped error: no observer service\n");
|
fprintf(stderr, "NotifyScreencastStopped error: no observer service\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsString id;
|
observerService->NotifyObservers(nullptr, "juggler-screencast-stopped", sessionId.get());
|
||||||
id.AppendPrintf("%" PRIi32, sessionId);
|
}
|
||||||
observerService->NotifyObservers(nullptr, "juggler-screencast-stopped", id.get());
|
|
||||||
|
nsresult generateUid(nsString& uid) {
|
||||||
|
nsresult rv = NS_OK;
|
||||||
|
nsCOMPtr<nsIRandomGenerator> rg = do_GetService("@mozilla.org/security/random-generator;1", &rv);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
uint8_t* buffer;
|
||||||
|
const int kLen = 16;
|
||||||
|
rv = rg->GenerateRandomBytes(kLen, &buffer);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
for (int i = 0; i < kLen; i++) {
|
||||||
|
uid.AppendPrintf("%" PRIx8, buffer[i]);
|
||||||
|
}
|
||||||
|
free(buffer);
|
||||||
|
return rv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,9 +140,8 @@ nsScreencastService::nsScreencastService() = default;
|
|||||||
nsScreencastService::~nsScreencastService() {
|
nsScreencastService::~nsScreencastService() {
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult nsScreencastService::StartVideoRecording(nsIDocShell* aDocShell, const nsACString& aFileName, uint32_t width, uint32_t height, double scale, int32_t offsetTop, int32_t* sessionId) {
|
nsresult nsScreencastService::StartVideoRecording(nsIDocShell* aDocShell, const nsACString& aFileName, uint32_t width, uint32_t height, double scale, int32_t offsetTop, nsAString& sessionId) {
|
||||||
MOZ_RELEASE_ASSERT(NS_IsMainThread(), "Screencast service must be started on the Main thread.");
|
MOZ_RELEASE_ASSERT(NS_IsMainThread(), "Screencast service must be started on the Main thread.");
|
||||||
*sessionId = -1;
|
|
||||||
|
|
||||||
PresShell* presShell = aDocShell->GetPresShell();
|
PresShell* presShell = aDocShell->GetPresShell();
|
||||||
if (!presShell)
|
if (!presShell)
|
||||||
@ -138,8 +154,7 @@ nsresult nsScreencastService::StartVideoRecording(nsIDocShell* aDocShell, const
|
|||||||
return NS_ERROR_UNEXPECTED;
|
return NS_ERROR_UNEXPECTED;
|
||||||
nsIWidget* widget = view->GetWidget();
|
nsIWidget* widget = view->GetWidget();
|
||||||
|
|
||||||
*sessionId = ++mLastSessionId;
|
rtc::scoped_refptr<webrtc::VideoCaptureModule> capturer = CreateWindowCapturer(widget);
|
||||||
rtc::scoped_refptr<webrtc::VideoCaptureModule> capturer = CreateWindowCapturer(widget, *sessionId);
|
|
||||||
if (!capturer)
|
if (!capturer)
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
|
|
||||||
@ -171,11 +186,17 @@ nsresult nsScreencastService::StartVideoRecording(nsIDocShell* aDocShell, const
|
|||||||
if (!session->Start())
|
if (!session->Start())
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
|
|
||||||
mIdToSession.emplace(*sessionId, std::move(session));
|
nsString uid;
|
||||||
|
nsresult rv = generateUid(uid);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
sessionId = uid;
|
||||||
|
mIdToSession.emplace(uid, std::move(session));
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult nsScreencastService::StopVideoRecording(int32_t sessionId) {
|
nsresult nsScreencastService::StopVideoRecording(const nsAString& aSessionId) {
|
||||||
|
nsString sessionId(aSessionId);
|
||||||
auto it = mIdToSession.find(sessionId);
|
auto it = mIdToSession.find(sessionId);
|
||||||
if (it == mIdToSession.end())
|
if (it == mIdToSession.end())
|
||||||
return NS_ERROR_INVALID_ARG;
|
return NS_ERROR_INVALID_ARG;
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <unordered_map>
|
#include <map>
|
||||||
#include "nsIScreencastService.h"
|
#include "nsIScreencastService.h"
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
@ -23,8 +23,7 @@ class nsScreencastService final : public nsIScreencastService {
|
|||||||
~nsScreencastService();
|
~nsScreencastService();
|
||||||
|
|
||||||
class Session;
|
class Session;
|
||||||
int mLastSessionId = 0;
|
std::map<nsString, std::unique_ptr<Session>> mIdToSession;
|
||||||
std::unordered_map<int, std::unique_ptr<Session>> mIdToSession;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace mozilla
|
} // namespace mozilla
|
||||||
|
Loading…
x
Reference in New Issue
Block a user