Skip to content

Commit ee04c7f

Browse files
fix: allow persistent media salts (electron#22386)
* fix: allow persistent media salts * chore: add regression test for persistent media device ids across reloads
1 parent fc54db1 commit ee04c7f

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

shell/browser/electron_browser_client.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,14 @@ bool ElectronBrowserClient::ShouldUseProcessPerSite(
872872
#endif
873873
}
874874

875+
bool ElectronBrowserClient::ArePersistentMediaDeviceIDsAllowed(
876+
content::BrowserContext* browser_context,
877+
const GURL& scope,
878+
const GURL& site_for_cookies,
879+
const base::Optional<url::Origin>& top_frame_origin) {
880+
return true;
881+
}
882+
875883
void ElectronBrowserClient::SiteInstanceDeleting(
876884
content::SiteInstance* site_instance) {
877885
// We are storing weak_ptr, is it fundamental to maintain the map up-to-date

shell/browser/electron_browser_client.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,11 @@ class ElectronBrowserClient : public content::ContentBrowserClient,
246246
const GURL& site_url) override;
247247
bool ShouldUseProcessPerSite(content::BrowserContext* browser_context,
248248
const GURL& effective_url) override;
249+
bool ArePersistentMediaDeviceIDsAllowed(
250+
content::BrowserContext* browser_context,
251+
const GURL& scope,
252+
const GURL& site_for_cookies,
253+
const base::Optional<url::Origin>& top_frame_origin) override;
249254

250255
// content::RenderProcessHostObserver:
251256
void RenderProcessHostDestroyed(content::RenderProcessHost* host) override;

spec-main/chromium-spec.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,21 @@ describe('chromium features', () => {
694694
expect(labels.some((l: any) => l)).to.be.false()
695695
})
696696

697+
it('returns the same device ids across reloads', async () => {
698+
const ses = session.fromPartition('persist:media-device-id')
699+
const w = new BrowserWindow({
700+
show: false,
701+
webPreferences: {
702+
nodeIntegration: true,
703+
session: ses
704+
}
705+
})
706+
w.loadFile(path.join(fixturesPath, 'pages', 'media-id-reset.html'))
707+
const [, firstDeviceIds] = await emittedOnce(ipcMain, 'deviceIds')
708+
const [, secondDeviceIds] = await emittedOnce(ipcMain, 'deviceIds', () => w.webContents.reload())
709+
expect(firstDeviceIds).to.deep.equal(secondDeviceIds)
710+
})
711+
697712
it('can return new device id when cookie storage is cleared', async () => {
698713
const ses = session.fromPartition('persist:media-device-id')
699714
const w = new BrowserWindow({
@@ -706,8 +721,7 @@ describe('chromium features', () => {
706721
w.loadFile(path.join(fixturesPath, 'pages', 'media-id-reset.html'))
707722
const [, firstDeviceIds] = await emittedOnce(ipcMain, 'deviceIds')
708723
await ses.clearStorageData({ storages: ['cookies'] })
709-
w.webContents.reload()
710-
const [, secondDeviceIds] = await emittedOnce(ipcMain, 'deviceIds')
724+
const [, secondDeviceIds] = await emittedOnce(ipcMain, 'deviceIds', () => w.webContents.reload())
711725
expect(firstDeviceIds).to.not.deep.equal(secondDeviceIds)
712726
})
713727
})

0 commit comments

Comments
 (0)