fix: allow persistent media salts (#22386) (#22569)

This commit is contained in:
Erick Zhao
2020-03-05 19:39:23 -08:00
committed by GitHub
parent 691ddb3f67
commit df6faec72e
3 changed files with 29 additions and 2 deletions

View File

@@ -718,6 +718,14 @@ void ElectronBrowserClient::GetAdditionalWebUISchemes(
additional_schemes->push_back(content::kChromeDevToolsScheme);
}
bool ElectronBrowserClient::ArePersistentMediaDeviceIDsAllowed(
content::BrowserContext* browser_context,
const GURL& scope,
const GURL& site_for_cookies,
const base::Optional<url::Origin>& top_frame_origin) {
return true;
}
void ElectronBrowserClient::SiteInstanceDeleting(
content::SiteInstance* site_instance) {
// We are storing weak_ptr, is it fundamental to maintain the map up-to-date

View File

@@ -228,6 +228,11 @@ class ElectronBrowserClient : public content::ContentBrowserClient,
scoped_refptr<net::HttpResponseHeaders> response_headers,
bool first_auth_attempt,
LoginAuthRequiredCallback auth_required_callback) override;
bool ArePersistentMediaDeviceIDsAllowed(
content::BrowserContext* browser_context,
const GURL& scope,
const GURL& site_for_cookies,
const base::Optional<url::Origin>& top_frame_origin) override;
// content::RenderProcessHostObserver:
void RenderProcessHostDestroyed(content::RenderProcessHost* host) override;

View File

@@ -697,6 +697,21 @@ describe('chromium features', () => {
expect(labels.some((l: any) => l)).to.be.false()
})
it('returns the same device ids across reloads', async () => {
const ses = session.fromPartition('persist:media-device-id')
const w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true,
session: ses
}
})
w.loadFile(path.join(fixturesPath, 'pages', 'media-id-reset.html'))
const [, firstDeviceIds] = await emittedOnce(ipcMain, 'deviceIds')
const [, secondDeviceIds] = await emittedOnce(ipcMain, 'deviceIds', () => w.webContents.reload())
expect(firstDeviceIds).to.deep.equal(secondDeviceIds)
})
it('can return new device id when cookie storage is cleared', async () => {
const ses = session.fromPartition('persist:media-device-id')
const w = new BrowserWindow({
@@ -709,8 +724,7 @@ describe('chromium features', () => {
w.loadFile(path.join(fixturesPath, 'pages', 'media-id-reset.html'))
const [, firstDeviceIds] = await emittedOnce(ipcMain, 'deviceIds')
await ses.clearStorageData({ storages: ['cookies'] })
w.webContents.reload()
const [, secondDeviceIds] = await emittedOnce(ipcMain, 'deviceIds')
const [, secondDeviceIds] = await emittedOnce(ipcMain, 'deviceIds', () => w.webContents.reload())
expect(firstDeviceIds).to.not.deep.equal(secondDeviceIds)
})
})