diff --git a/atom/browser/api/atom_api_session.cc b/atom/browser/api/atom_api_session.cc index 8aa80c8951eb..d4ef984085e2 100644 --- a/atom/browser/api/atom_api_session.cc +++ b/atom/browser/api/atom_api_session.cc @@ -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(), diff --git a/spec/chromium-spec.js b/spec/chromium-spec.js index 8aeb2450bded..5d30181c2e74 100644 --- a/spec/chromium-spec.js +++ b/spec/chromium-spec.js @@ -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 () { diff --git a/spec/fixtures/pages/media-id-reset.html b/spec/fixtures/pages/media-id-reset.html new file mode 100644 index 000000000000..1a3df0fdada5 --- /dev/null +++ b/spec/fixtures/pages/media-id-reset.html @@ -0,0 +1,9 @@ + diff --git a/vendor/brightray b/vendor/brightray index 86a5d053234a..b8c8a31e9253 160000 --- a/vendor/brightray +++ b/vendor/brightray @@ -1 +1 @@ -Subproject commit 86a5d053234a3eb9b2df47087738ab0b68ac1e25 +Subproject commit b8c8a31e9253406ef410f0d253bf1507448c222d