From 3de3fb53bde269496e0971d359aaa4d9ee5c29bf Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Sat, 3 Dec 2016 16:44:33 +0530 Subject: [PATCH 1/5] session: reset media device id salt when cookies are cleared --- atom/browser/api/atom_api_session.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/atom/browser/api/atom_api_session.cc b/atom/browser/api/atom_api_session.cc index 96fcca561d9d..cc33890a233c 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" @@ -389,6 +390,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(), From e043dabcb870b269686ab6e7a11729ca80080339 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Sun, 4 Dec 2016 00:22:57 +0530 Subject: [PATCH 2/5] add spec --- spec/chromium-spec.js | 33 +++++++++++++++++++++++++ spec/fixtures/pages/media-id-reset.html | 9 +++++++ 2 files changed, 42 insertions(+) create mode 100644 spec/fixtures/pages/media-id-reset.html diff --git a/spec/chromium-spec.js b/spec/chromium-spec.js index 8aeb2450bded..899eff871588 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,38 @@ 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'] + } + let 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() + }) + } 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 @@ + From cae601a682de95ddb6f08dfb16741828f29bee1e Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 12 Dec 2016 13:12:45 -0800 Subject: [PATCH 3/5] Upgrade brightray for media device salt fix --- vendor/brightray | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 04da9257ef345549a8c28e53963a1c33b3ec96c8 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 12 Dec 2016 13:32:27 -0800 Subject: [PATCH 4/5] Catch any close window errors --- spec/chromium-spec.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/chromium-spec.js b/spec/chromium-spec.js index 899eff871588..bfda4f2cdd41 100644 --- a/spec/chromium-spec.js +++ b/spec/chromium-spec.js @@ -133,6 +133,8 @@ describe('chromium feature', function () { closeWindow(w).then(function () { w = null done() + }).catch(function (error) { + done(error) }) } else { ses.clearStorageData(options, function () { From 04e873f78e2f8f3da181fbef06d6a9a834629b57 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 12 Dec 2016 13:33:14 -0800 Subject: [PATCH 5/5] Make deviceIds const --- spec/chromium-spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/chromium-spec.js b/spec/chromium-spec.js index bfda4f2cdd41..5d30181c2e74 100644 --- a/spec/chromium-spec.js +++ b/spec/chromium-spec.js @@ -116,7 +116,7 @@ describe('chromium feature', function () { origin: null, storages: ['cookies'] } - let deviceIds = [] + const deviceIds = [] const ses = session.fromPartition('persist:media-device-id') let w = new BrowserWindow({ show: false,