diff --git a/browser_patches/firefox/BUILD_NUMBER b/browser_patches/firefox/BUILD_NUMBER index 8cea824fe8..0d1f9f219f 100644 --- a/browser_patches/firefox/BUILD_NUMBER +++ b/browser_patches/firefox/BUILD_NUMBER @@ -1,2 +1,2 @@ -1190 -Changed: joel.einbinder@gmail.com Tue 13 Oct 2020 09:08:57 AM PDT +1191 +Changed: yurys@chromium.org Wed Oct 14 16:12:19 PDT 2020 diff --git a/browser_patches/firefox/juggler/protocol/PageHandler.js b/browser_patches/firefox/juggler/protocol/PageHandler.js index 5feb2ae733..201e07b7ae 100644 --- a/browser_patches/firefox/juggler/protocol/PageHandler.js +++ b/browser_patches/firefox/juggler/protocol/PageHandler.js @@ -121,7 +121,7 @@ class PageHandler { _onScreencastStarted() { 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) { diff --git a/browser_patches/firefox/juggler/screencast/nsIScreencastService.idl b/browser_patches/firefox/juggler/screencast/nsIScreencastService.idl index acac1bd3bd..d3a82a7cda 100644 --- a/browser_patches/firefox/juggler/screencast/nsIScreencastService.idl +++ b/browser_patches/firefox/juggler/screencast/nsIScreencastService.idl @@ -12,10 +12,10 @@ interface nsIDocShell; [scriptable, uuid(d8c4d9e0-9462-445e-9e43-68d3872ad1de)] 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. */ - void stopVideoRecording(in long sessionId); + void stopVideoRecording(in AString sessionId); }; diff --git a/browser_patches/firefox/juggler/screencast/nsScreencastService.cpp b/browser_patches/firefox/juggler/screencast/nsScreencastService.cpp index e4b6fadf86..c4923eba35 100644 --- a/browser_patches/firefox/juggler/screencast/nsScreencastService.cpp +++ b/browser_patches/firefox/juggler/screencast/nsScreencastService.cpp @@ -12,6 +12,7 @@ #include "mozilla/StaticPtr.h" #include "nsIDocShell.h" #include "nsIObserverService.h" +#include "nsIRandomGenerator.h" #include "nsISupportsPrimitives.h" #include "nsThreadManager.h" #include "nsView.h" @@ -34,7 +35,7 @@ namespace { StaticRefPtr gScreencastService; -rtc::scoped_refptr CreateWindowCapturer(nsIWidget* widget, int sessionId) { +rtc::scoped_refptr CreateWindowCapturer(nsIWidget* widget) { if (gfxPlatform::IsHeadless()) { HeadlessWidget* headlessWidget = static_cast(widget); return HeadlessWindowCapturer::Create(headlessWidget); @@ -47,19 +48,35 @@ rtc::scoped_refptr CreateWindowCapturer(nsIWidget* w nsCString windowId; windowId.AppendPrintf("%" PRIuPTR, rawWindowId); 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 observerService = mozilla::services::GetObserverService(); if (!observerService) { fprintf(stderr, "NotifyScreencastStopped error: no observer service\n"); return; } - nsString id; - id.AppendPrintf("%" PRIi32, sessionId); - observerService->NotifyObservers(nullptr, "juggler-screencast-stopped", id.get()); + observerService->NotifyObservers(nullptr, "juggler-screencast-stopped", sessionId.get()); +} + +nsresult generateUid(nsString& uid) { + nsresult rv = NS_OK; + nsCOMPtr 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() { } -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."); - *sessionId = -1; PresShell* presShell = aDocShell->GetPresShell(); if (!presShell) @@ -138,8 +154,7 @@ nsresult nsScreencastService::StartVideoRecording(nsIDocShell* aDocShell, const return NS_ERROR_UNEXPECTED; nsIWidget* widget = view->GetWidget(); - *sessionId = ++mLastSessionId; - rtc::scoped_refptr capturer = CreateWindowCapturer(widget, *sessionId); + rtc::scoped_refptr capturer = CreateWindowCapturer(widget); if (!capturer) return NS_ERROR_FAILURE; @@ -171,11 +186,17 @@ nsresult nsScreencastService::StartVideoRecording(nsIDocShell* aDocShell, const if (!session->Start()) 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; } -nsresult nsScreencastService::StopVideoRecording(int32_t sessionId) { +nsresult nsScreencastService::StopVideoRecording(const nsAString& aSessionId) { + nsString sessionId(aSessionId); auto it = mIdToSession.find(sessionId); if (it == mIdToSession.end()) return NS_ERROR_INVALID_ARG; diff --git a/browser_patches/firefox/juggler/screencast/nsScreencastService.h b/browser_patches/firefox/juggler/screencast/nsScreencastService.h index c9df1a1138..082416ca74 100644 --- a/browser_patches/firefox/juggler/screencast/nsScreencastService.h +++ b/browser_patches/firefox/juggler/screencast/nsScreencastService.h @@ -5,7 +5,7 @@ #pragma once #include -#include +#include #include "nsIScreencastService.h" namespace mozilla { @@ -23,8 +23,7 @@ class nsScreencastService final : public nsIScreencastService { ~nsScreencastService(); class Session; - int mLastSessionId = 0; - std::unordered_map> mIdToSession; + std::map> mIdToSession; }; } // namespace mozilla