Merge pull request #8137 from deepak1556/media_device_id_patch

session: reset media device id salt when cookies are cleared
This commit is contained in:
Kevin Sawicki 2016-12-12 13:34:24 -08:00 committed by GitHub
commit b08bc02cde
4 changed files with 51 additions and 1 deletions

View file

@ -29,6 +29,7 @@
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/threading/thread_task_runner_handle.h"
#include "brightray/browser/media/media_device_id_salt.h"
#include "brightray/browser/net/devtools_network_conditions.h"
#include "brightray/browser/net/devtools_network_controller_handle.h"
#include "chrome/common/pref_names.h"
@ -477,6 +478,11 @@ void Session::ClearStorageData(mate::Arguments* args) {
auto storage_partition =
content::BrowserContext::GetStoragePartition(browser_context(), nullptr);
if (options.storage_types & StoragePartition::REMOVE_DATA_MASK_COOKIES) {
// Reset media device id salt when cookies are cleared.
// https://w3c.github.io/mediacapture-main/#dom-mediadeviceinfo-deviceid
brightray::MediaDeviceIDSalt::Reset(browser_context()->prefs());
}
storage_partition->ClearData(
options.storage_types, options.quota_types, options.origin,
content::StoragePartition::OriginMatcherFunction(),

View file

@ -4,6 +4,7 @@ const path = require('path')
const ws = require('ws')
const url = require('url')
const remote = require('electron').remote
const {closeWindow} = require('./window-helpers')
const {BrowserWindow, ipcMain, protocol, session, webContents} = remote
@ -109,6 +110,40 @@ describe('chromium feature', function () {
}
}).catch(done)
})
it('can return new device id when cookie storage is cleared', function (done) {
const options = {
origin: null,
storages: ['cookies']
}
const deviceIds = []
const ses = session.fromPartition('persist:media-device-id')
let w = new BrowserWindow({
show: false,
webPreferences: {
session: ses
}
})
w.webContents.on('ipc-message', function (event, args) {
if (args[0] === 'deviceIds') {
deviceIds.push(args[1])
}
if (deviceIds.length === 2) {
assert.notDeepEqual(deviceIds[0], deviceIds[1])
closeWindow(w).then(function () {
w = null
done()
}).catch(function (error) {
done(error)
})
} else {
ses.clearStorageData(options, function () {
w.webContents.reload()
})
}
})
w.loadURL('file://' + fixtures + '/pages/media-id-reset.html')
})
})
describe('navigator.language', function () {

View file

@ -0,0 +1,9 @@
<script>
const {ipcRenderer} = require('electron')
navigator.mediaDevices.enumerateDevices().then((devices) => {
return devices.map((device) => device.deviceId)
.filter((deviceId) => deviceId !== "default")
}).then((deviceIds) => {
ipcRenderer.send('deviceIds', deviceIds)
})
</script>

2
vendor/brightray vendored

@ -1 +1 @@
Subproject commit 86a5d053234a3eb9b2df47087738ab0b68ac1e25
Subproject commit b8c8a31e9253406ef410f0d253bf1507448c222d