Skip to content

refactor: decouple api::WebRequest from api::BrowserContext - #48848

Merged
ckerr merged 7 commits into
mainfrom
refactor/decouple-WebRequest-and-BrowserContext
Nov 9, 2025
Merged

ckerr merged 7 commits into
mainfrom
refactor/decouple-WebRequest-and-BrowserContext

Conversation

@ckerr

@ckerr ckerr commented Nov 7, 2025 •

Copy link
Copy Markdown
Member

Description of Change

Followup of #48792.
Prerequisite of #48762.

Simplify the lifecycle of api::WebRequest.

tldr: api::WebRequest is created and owned by an api::Session in a 1:1 relationship.

  • Use base::PassKey<> to ensure api::WebRequest can only be instantiated by api::Session
  • Rename Session::CreateFrom() to Session::FromOrCreate() for clarity & symmetry with other Electron classes
  • Refactor api::WebRequest::FromOrCreate() to just call api::Session::FromOrCreate()->WebRequest()
  • Stop attaching api::WebRequest pointers to content::BrowserContext via base::UserData
  • Remove now-unused method api::WebRequest::From()
  • Remove now-unused field api::WebRequest::browser_context_

CC @codebytere, @deepak1556

Checklist

Release Notes

Notes: none.

…eate()

This is both clearer and more consistent with other classes
@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Nov 7, 2025
@ckerr
ckerr force-pushed the refactor/decouple-WebRequest-and-BrowserContext branch from 8fc4a6b to 3e3c69d Compare November 7, 2025 22:41
@ckerr
ckerr force-pushed the refactor/decouple-WebRequest-and-BrowserContext branch from 3e3c69d to 102e656 Compare November 7, 2025 22:46
@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently label Nov 8, 2025
@ckerr
ckerr merged commit 519187d into main Nov 9, 2025
@ckerr
ckerr deleted the refactor/decouple-WebRequest-and-BrowserContext branch November 9, 2025 14:07
@release-clerk

release-clerk Bot commented Nov 9, 2025

Copy link
Copy Markdown

No Release Notes

Comment on lines +1696 to +1697
DCHECK(false);
return {};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Expecting a DCHECK that is always false but returning a null value in release builds seems to contradict, would this be better with NOTREACHED ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm fine with making this NOTREACHED

nilayarya pushed a commit to nilayarya/electron that referenced this pull request Nov 21, 2025
…tron#48848)

* refactor: rename api::Session::CreateFrom() to api::Session::FromOrCreate()

This is both clearer and more consistent with other classes

* refactor: add Session::FromOrCreate(content::BrowserContext*)

* refactor: reimplement api::WebRequest::FromOrCreate() using api::Session::FromOrCreate()

* refactor: use base::PassKey to ensure WebRequest is only instantiated by Session

* refactor: remove WebRequest::From()

no longer needed; Session already guarantees uniqueness

* refactor: remove unused isolate arg from WebRequest ctor

* refactor: do not attach WebRequest to BrowserContext

no longer needed now that access goes through Session
nilayarya added a commit to nilayarya/electron that referenced this pull request Nov 21, 2025
…tron#48848)

* refactor: rename api::Session::CreateFrom() to api::Session::FromOrCreate()

This is both clearer and more consistent with other classes

* refactor: add Session::FromOrCreate(content::BrowserContext*)

* refactor: reimplement api::WebRequest::FromOrCreate() using api::Session::FromOrCreate()

* refactor: use base::PassKey to ensure WebRequest is only instantiated by Session

* refactor: remove WebRequest::From()

no longer needed; Session already guarantees uniqueness

* refactor: remove unused isolate arg from WebRequest ctor

* refactor: do not attach WebRequest to BrowserContext

no longer needed now that access goes through Session
nilayarya added a commit to nilayarya/electron that referenced this pull request Nov 21, 2025
…tron#48848)

* refactor: rename api::Session::CreateFrom() to api::Session::FromOrCreate()

This is both clearer and more consistent with other classes

* refactor: add Session::FromOrCreate(content::BrowserContext*)

* refactor: reimplement api::WebRequest::FromOrCreate() using api::Session::FromOrCreate()

* refactor: use base::PassKey to ensure WebRequest is only instantiated by Session

* refactor: remove WebRequest::From()

no longer needed; Session already guarantees uniqueness

* refactor: remove unused isolate arg from WebRequest ctor

* refactor: do not attach WebRequest to BrowserContext

no longer needed now that access goes through Session
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants