Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: eliminate DecrementCapturerCount patch #35710

Merged
merged 2 commits into from Oct 5, 2022

Conversation

codebytere
Copy link
Member

@codebytere codebytere commented Sep 16, 2022

Description of Change

Refactors webContents.{increment|decrement}CapturerCount to remove usage of private WebContents::DecrementCapturerCount exposed via patch. We now store the handle received from calls to IncrementCapturerCount and api::WebContents::DecrementCaptureCount now calls RunAndReset on the stored capture handle.

Functionality previously exposed through webContents.{increment|decrement}CapturerCount has now been folded into webContents.capturePage.

Checklist

Release Notes

Notes: none.

@codebytere codebytere added the semver/patch backwards-compatible bug fixes label Sep 16, 2022
@codebytere codebytere requested review from a team as code owners September 16, 2022 18:22
@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Sep 16, 2022
@codebytere codebytere changed the title refactor: eliminate DecrementCapturerCount patch refactor: eliminate DecrementCapturerCount patch Sep 16, 2022
shell/browser/api/electron_api_web_contents.cc Outdated Show resolved Hide resolved
shell/browser/api/electron_api_web_contents.cc Outdated Show resolved Hide resolved
shell/browser/api/electron_api_web_contents.h Outdated Show resolved Hide resolved
@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Sep 17, 2022
@deepak1556
Copy link
Member

deepak1556 commented Sep 19, 2022

What is the necessity to allow for multiple increment capture count calls during the lifetime of a capture session ? When the API was exposed #21679 it didn't showcase an example that required multiple calls to the increment API. Also chromium's contract for the API https://source.chromium.org/chromium/chromium/src/+/main:content/public/browser/web_contents.h;l=627-661; states

  1. Increment capture count is needed to disable the renderer optimizations when backgrounded or occluded
  2. Each increment capture count call should have a corresponding decrement capture count call.

With that being the case, wouldn't the following suffice

  • Before starting webContents.capturePage() allow users to call webContents.IncrementCapturerCount() with hidden/awake state and store the generated capture handle.
capture_handle_ = web_contents()->IncrementCapturerCount(size, stay_hidden, stay_awake);
  • If there is already a capture session in progress which can be verified with content::WebContents::IsBeingCaptured(), the call to webContents.IncrementCapturerCount() can throw an error.

  • Reset the capture handle if set, when api::webContents::OnCapturePageDone() is called

My current concern is that callers of the Electron API are responsible to balance out the increment/decrement calls and if they don't, webContents will end up with a weird visibility state. Instead of relying on users to understand the inner details of the chromium API, we could perform the balancing automatically with only a single increment capturer count for a capture session. This would allow us to remove both the api::webContents::DecrementCapturerCount API and its corresponding patch. Also, I don't see any usages of multiple increment capture counts within Chromium, so if there is a need for it in Electron would be good to have a test or example in the docs. I think that when the API was created in #21679, DecrementCapturerCount was still a public API and it was exposed alongside others as default.

@codebytere
Copy link
Member Author

@deepak1556 you're right imo - i was mostly keying off comments in the previous PR to restore this behavior. I'd also personally prefer to only maintain one at any given time and store it as such. I'll update the PR.

@ckerr
Copy link
Member

ckerr commented Sep 21, 2022

My current concern is that callers of the Electron API are responsible to balance out the increment/decrement calls and if they don't, webContents will end up with a weird visibility state. Instead of relying on users to understand the inner details of the chromium API, we could perform the balancing automatically with only a single increment capturer count for a capture session.

I like the idea that increment + decrement is done internally when the promise is created + settled. It feels like having this in public API is a footgun with no real advantage?

What would you all think if we:

  1. handle increment / decrement internally
  2. make the public increment / decrement API no-ops so that it doesn't interfere with the internal work in previous step
  3. deprecate the public increment / decrement API for future removal

@codebytere
Copy link
Member Author

codebytere commented Sep 21, 2022

@ckerr i'm good with that! i agree it opens up more avenues for potential issues than anything else. However, i do think users would potentially want to control values of stayAwake & stayHidden 🤔 so i'd want to think about what workflows/needs we might be preventing w/ this change. So i'd be at minimum in favor of removing decrementCapturerCount, but i think incrementCapturerCount still serves a potential need.

@ckerr
Copy link
Member

ckerr commented Sep 21, 2022

However, i do think users would potentially want to control values of stayAwake & stayHidden

Just brainstorming here so feel free to push back, but maybe stayAwake and stayHidden could be optional args to capturePage(), defaulting to false when not provided?

Is there any use case for incrementCapturerCount() other than as a precursor for capturePage()?

@codebytere
Copy link
Member Author

@ckerr ooh good idea!! I pushed the decrement removal/deprecation - @deepak1556 thoughts on removing incrementCapturerCount as well and proceeding with @ckerr's idea above?

@deepak1556
Copy link
Member

I like the idea to unify incrementCaptureCount with capturePage. I also don't see any usages outside of the capture context.

@codebytere codebytere force-pushed the refactor-increment-count branch 2 times, most recently from 829ba8a to af8a66f Compare September 22, 2022 17:05
@codebytere codebytere added semver/minor backwards-compatible functionality and removed semver/patch backwards-compatible bug fixes labels Sep 22, 2022
@electron-cation electron-cation bot added api-review/requested 🗳 new-pr 🌱 PR opened in the last 24 hours labels Sep 22, 2022
docs/breaking-changes.md Show resolved Hide resolved
docs/breaking-changes.md Show resolved Hide resolved
filenames.auto.gni Outdated Show resolved Hide resolved
shell/browser/api/electron_api_web_contents.cc Outdated Show resolved Hide resolved
shell/browser/api/electron_api_web_contents.cc Outdated Show resolved Hide resolved
shell/browser/api/electron_api_web_contents.cc Outdated Show resolved Hide resolved
docs/api/web-contents.md Outdated Show resolved Hide resolved
@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Sep 23, 2022
@codebytere codebytere requested a review from a team as a code owner September 26, 2022 08:37
@codebytere codebytere force-pushed the refactor-increment-count branch 2 times, most recently from cfbb817 to cb1f2dc Compare September 26, 2022 08:48
docs/api/web-contents.md Outdated Show resolved Hide resolved
docs/api/web-contents.md Show resolved Hide resolved
docs/breaking-changes.md Show resolved Hide resolved
docs/breaking-changes.md Outdated Show resolved Hide resolved
docs/breaking-changes.md Outdated Show resolved Hide resolved
docs/api/web-contents.md Outdated Show resolved Hide resolved
docs/api/web-contents.md Outdated Show resolved Hide resolved
@nornagon
Copy link
Member

nice, very glad to have these methods go away.

@codebytere codebytere force-pushed the refactor-increment-count branch 4 times, most recently from df767c5 to 00cde4e Compare September 26, 2022 22:21
Copy link
Contributor

@jkleinsc jkleinsc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API LGTM

Copy link
Member

@nornagon nornagon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we have a test for stayhidden/stayawake?

@codebytere
Copy link
Member Author

@nornagon i can try but stayAwake isn't really testable here and nearly all our documentVisibility tests are disabled/flaky.

Copy link
Member

@nornagon nornagon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API LGTM

@codebytere
Copy link
Member Author

Alright well for some reason cation is struggling here but merging given two API LGTMs and all concerns addressed.

@codebytere codebytere merged commit faafcc7 into main Oct 5, 2022
@codebytere codebytere deleted the refactor-increment-count branch October 5, 2022 17:51
@release-clerk
Copy link

release-clerk bot commented Oct 5, 2022

No Release Notes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants