Skip to content

Commit 1a58281

Browse files
browser(firefox): don't record video outside the viewport (#6361)
1 parent 2945dac commit 1a58281

File tree

4 files changed

+9
-10
lines changed

4 files changed

+9
-10
lines changed

browser_patches/firefox/BUILD_NUMBER

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
1251
2-
Changed: [email protected] Mon 03 May 2021 05:04:07 PM PDT
1+
1252
2+
Changed: [email protected] Tue 04 May 2021 02:47:58 AM PDT

browser_patches/firefox/juggler/TargetRegistry.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,8 @@ class PageTarget {
504504
// Exclude address bar and navigation control from the video.
505505
const rect = this.linkedBrowser().getBoundingClientRect();
506506
const devicePixelRatio = this._window.devicePixelRatio;
507-
const videoSessionId = screencast.startVideoRecording(docShell, file, width, height, scale || 0, devicePixelRatio * rect.top);
507+
const viewport = this._viewportSize || this._browserContext.defaultViewportSize || {width: 0, height: 0};
508+
const videoSessionId = screencast.startVideoRecording(docShell, file, width, height, viewport.width, viewport.height, scale || 0, devicePixelRatio * rect.top);
508509
this._screencastInfo = { videoSessionId, file };
509510
this.emit(PageTarget.Events.ScreencastStarted);
510511
}

browser_patches/firefox/juggler/screencast/nsIScreencastService.idl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ interface nsIDocShell;
1212
[scriptable, uuid(d8c4d9e0-9462-445e-9e43-68d3872ad1de)]
1313
interface nsIScreencastService : nsISupports
1414
{
15-
AString startVideoRecording(in nsIDocShell docShell, in ACString fileName, in uint32_t width, in uint32_t height, in double scale, in int32_t offset_top);
15+
AString startVideoRecording(in nsIDocShell docShell, in ACString fileName, in uint32_t width, in uint32_t height, in uint32_t viewportWidth, in uint32_t viewportHeight, in double scale, in int32_t offset_top);
1616

1717
/**
1818
* Will emit 'juggler-screencast-stopped' when the video file is saved.

browser_patches/firefox/juggler/screencast/nsScreencastService.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ nsScreencastService::nsScreencastService() = default;
140140
nsScreencastService::~nsScreencastService() {
141141
}
142142

143-
nsresult nsScreencastService::StartVideoRecording(nsIDocShell* aDocShell, const nsACString& aFileName, uint32_t width, uint32_t height, double scale, int32_t offsetTop, nsAString& sessionId) {
143+
nsresult nsScreencastService::StartVideoRecording(nsIDocShell* aDocShell, const nsACString& aFileName, uint32_t width, uint32_t height, uint32_t viewportWidth, uint32_t viewportHeight, double scale, int32_t offsetTop, nsAString& sessionId) {
144144
MOZ_RELEASE_ASSERT(NS_IsMainThread(), "Screencast service must be started on the Main thread.");
145145

146146
PresShell* presShell = aDocShell->GetPresShell();
@@ -164,15 +164,13 @@ nsresult nsScreencastService::StartVideoRecording(nsIDocShell* aDocShell, const
164164
maybeScale = Some(scale);
165165

166166
gfx::IntMargin margin;
167-
// On GTK the bottom of the client rect is below the bounds and
168-
// client size is actually equal to the size of the bounds so
169-
// we don't need an adjustment.
170-
#ifndef MOZ_WIDGET_GTK
171167
auto bounds = widget->GetScreenBounds().ToUnknownRect();
172168
auto clientBounds = widget->GetClientBounds().ToUnknownRect();
169+
// The browser window has a minimum size, so it might be larger than the viewport size.
170+
clientBounds.width = std::min((int)viewportWidth, clientBounds.width);
171+
clientBounds.height = std::min((int)viewportHeight, clientBounds.height);
173172
// Crop the image to exclude frame (if any).
174173
margin = bounds - clientBounds;
175-
#endif
176174
// Crop the image to exclude controls.
177175
margin.top += offsetTop;
178176

0 commit comments

Comments
 (0)