feat: promisify session.clearStorageData() (#17249)
This commit is contained in:
parent
d34f81972d
commit
bbfa63fd9d
7 changed files with 57 additions and 20 deletions
|
@ -328,11 +328,6 @@ void AllowNTLMCredentialsForDomainsInIO(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnClearStorageDataDone(const base::Closure& callback) {
|
|
||||||
if (!callback.is_null())
|
|
||||||
callback.Run();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DownloadIdCallback(content::DownloadManager* download_manager,
|
void DownloadIdCallback(content::DownloadManager* download_manager,
|
||||||
const base::FilePath& path,
|
const base::FilePath& path,
|
||||||
const std::vector<GURL>& url_chain,
|
const std::vector<GURL>& url_chain,
|
||||||
|
@ -429,12 +424,13 @@ void Session::DoCacheAction(const net::CompletionCallback& callback) {
|
||||||
action, callback));
|
action, callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::ClearStorageData(mate::Arguments* args) {
|
v8::Local<v8::Promise> Session::ClearStorageData(mate::Arguments* args) {
|
||||||
// clearStorageData([options, callback])
|
v8::Isolate* isolate = args->isolate();
|
||||||
|
util::Promise promise(isolate);
|
||||||
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
||||||
ClearStorageDataOptions options;
|
ClearStorageDataOptions options;
|
||||||
base::Closure callback;
|
|
||||||
args->GetNext(&options);
|
args->GetNext(&options);
|
||||||
args->GetNext(&callback);
|
|
||||||
|
|
||||||
auto* storage_partition =
|
auto* storage_partition =
|
||||||
content::BrowserContext::GetStoragePartition(browser_context(), nullptr);
|
content::BrowserContext::GetStoragePartition(browser_context(), nullptr);
|
||||||
|
@ -443,9 +439,13 @@ void Session::ClearStorageData(mate::Arguments* args) {
|
||||||
// https://w3c.github.io/mediacapture-main/#dom-mediadeviceinfo-deviceid
|
// https://w3c.github.io/mediacapture-main/#dom-mediadeviceinfo-deviceid
|
||||||
MediaDeviceIDSalt::Reset(browser_context()->prefs());
|
MediaDeviceIDSalt::Reset(browser_context()->prefs());
|
||||||
}
|
}
|
||||||
storage_partition->ClearData(options.storage_types, options.quota_types,
|
|
||||||
options.origin, base::Time(), base::Time::Max(),
|
storage_partition->ClearData(
|
||||||
base::Bind(&OnClearStorageDataDone, callback));
|
options.storage_types, options.quota_types, options.origin, base::Time(),
|
||||||
|
base::Time::Max(),
|
||||||
|
base::Bind(util::CopyablePromise::ResolveEmptyCopyablePromise,
|
||||||
|
util::CopyablePromise(promise)));
|
||||||
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::FlushStorageData() {
|
void Session::FlushStorageData() {
|
||||||
|
|
|
@ -66,7 +66,7 @@ class Session : public mate::TrackableObject<Session>,
|
||||||
const ResolveProxyHelper::ResolveProxyCallback& callback);
|
const ResolveProxyHelper::ResolveProxyCallback& callback);
|
||||||
template <CacheAction action>
|
template <CacheAction action>
|
||||||
void DoCacheAction(const net::CompletionCallback& callback);
|
void DoCacheAction(const net::CompletionCallback& callback);
|
||||||
void ClearStorageData(mate::Arguments* args);
|
v8::Local<v8::Promise> ClearStorageData(mate::Arguments* args);
|
||||||
void FlushStorageData();
|
void FlushStorageData();
|
||||||
void SetProxy(const mate::Dictionary& options, const base::Closure& callback);
|
void SetProxy(const mate::Dictionary& options, const base::Closure& callback);
|
||||||
void SetDownloadPath(const base::FilePath& path);
|
void SetDownloadPath(const base::FilePath& path);
|
||||||
|
|
|
@ -15,7 +15,6 @@ When a majority of affected functions are migrated, this flag will be enabled by
|
||||||
- [inAppPurchase.getProducts(productIDs, callback)](https://github.com/electron/electron/blob/master/docs/api/in-app-purchase.md#getProducts)
|
- [inAppPurchase.getProducts(productIDs, callback)](https://github.com/electron/electron/blob/master/docs/api/in-app-purchase.md#getProducts)
|
||||||
- [ses.getCacheSize(callback)](https://github.com/electron/electron/blob/master/docs/api/session.md#getCacheSize)
|
- [ses.getCacheSize(callback)](https://github.com/electron/electron/blob/master/docs/api/session.md#getCacheSize)
|
||||||
- [ses.clearCache(callback)](https://github.com/electron/electron/blob/master/docs/api/session.md#clearCache)
|
- [ses.clearCache(callback)](https://github.com/electron/electron/blob/master/docs/api/session.md#clearCache)
|
||||||
- [ses.clearStorageData([options, callback])](https://github.com/electron/electron/blob/master/docs/api/session.md#clearStorageData)
|
|
||||||
- [ses.setProxy(config, callback)](https://github.com/electron/electron/blob/master/docs/api/session.md#setProxy)
|
- [ses.setProxy(config, callback)](https://github.com/electron/electron/blob/master/docs/api/session.md#setProxy)
|
||||||
- [ses.resolveProxy(url, callback)](https://github.com/electron/electron/blob/master/docs/api/session.md#resolveProxy)
|
- [ses.resolveProxy(url, callback)](https://github.com/electron/electron/blob/master/docs/api/session.md#resolveProxy)
|
||||||
- [ses.clearHostResolverCache([callback])](https://github.com/electron/electron/blob/master/docs/api/session.md#clearHostResolverCache)
|
- [ses.clearHostResolverCache([callback])](https://github.com/electron/electron/blob/master/docs/api/session.md#clearHostResolverCache)
|
||||||
|
@ -47,6 +46,7 @@ When a majority of affected functions are migrated, this flag will be enabled by
|
||||||
- [dialog.showSaveDialog([browserWindow, ]options[, callback])](https://github.com/electron/electron/blob/master/docs/api/dialog.md#showSaveDialog)
|
- [dialog.showSaveDialog([browserWindow, ]options[, callback])](https://github.com/electron/electron/blob/master/docs/api/dialog.md#showSaveDialog)
|
||||||
- [netLog.stopLogging([callback])](https://github.com/electron/electron/blob/master/docs/api/net-log.md#stopLogging)
|
- [netLog.stopLogging([callback])](https://github.com/electron/electron/blob/master/docs/api/net-log.md#stopLogging)
|
||||||
- [protocol.isProtocolHandled(scheme, callback)](https://github.com/electron/electron/blob/master/docs/api/protocol.md#isProtocolHandled)
|
- [protocol.isProtocolHandled(scheme, callback)](https://github.com/electron/electron/blob/master/docs/api/protocol.md#isProtocolHandled)
|
||||||
|
- [ses.clearStorageData([options, callback])](https://github.com/electron/electron/blob/master/docs/api/session.md#clearStorageData)
|
||||||
- [shell.openExternal(url[, options, callback])](https://github.com/electron/electron/blob/master/docs/api/shell.md#openExternal)
|
- [shell.openExternal(url[, options, callback])](https://github.com/electron/electron/blob/master/docs/api/shell.md#openExternal)
|
||||||
- [webviewTag.capturePage([rect, ]callback)](https://github.com/electron/electron/blob/master/docs/api/webview-tag.md#capturePage)
|
- [webviewTag.capturePage([rect, ]callback)](https://github.com/electron/electron/blob/master/docs/api/webview-tag.md#capturePage)
|
||||||
- [webviewTag.printToPDF(options, callback)](https://github.com/electron/electron/blob/master/docs/api/webview-tag.md#printToPDF)
|
- [webviewTag.printToPDF(options, callback)](https://github.com/electron/electron/blob/master/docs/api/webview-tag.md#printToPDF)
|
||||||
|
|
|
@ -106,7 +106,7 @@ Callback is invoked with the session's current cache size.
|
||||||
|
|
||||||
Clears the session’s HTTP cache.
|
Clears the session’s HTTP cache.
|
||||||
|
|
||||||
#### `ses.clearStorageData([options, callback])`
|
#### `ses.clearStorageData([options,] callback)`
|
||||||
|
|
||||||
* `options` Object (optional)
|
* `options` Object (optional)
|
||||||
* `origin` String (optional) - Should follow `window.location.origin`’s representation
|
* `origin` String (optional) - Should follow `window.location.origin`’s representation
|
||||||
|
@ -118,7 +118,22 @@ Clears the session’s HTTP cache.
|
||||||
`temporary`, `persistent`, `syncable`.
|
`temporary`, `persistent`, `syncable`.
|
||||||
* `callback` Function (optional) - Called when operation is done.
|
* `callback` Function (optional) - Called when operation is done.
|
||||||
|
|
||||||
Clears the data of web storages.
|
Clears the storage data for the current session.
|
||||||
|
|
||||||
|
**[Deprecated Soon](promisification.md)**
|
||||||
|
|
||||||
|
#### `ses.clearStorageData([options])`
|
||||||
|
|
||||||
|
* `options` Object (optional)
|
||||||
|
* `origin` String (optional) - Should follow `window.location.origin`’s representation
|
||||||
|
`scheme://host:port`.
|
||||||
|
* `storages` String[] (optional) - The types of storages to clear, can contain:
|
||||||
|
`appcache`, `cookies`, `filesystem`, `indexdb`, `localstorage`,
|
||||||
|
`shadercache`, `websql`, `serviceworkers`, `cachestorage`.
|
||||||
|
* `quotas` String[] (optional) - The types of quotas to clear, can contain:
|
||||||
|
`temporary`, `persistent`, `syncable`.
|
||||||
|
|
||||||
|
Returns `Promise<void>` - resolves when the storage data has been cleared.
|
||||||
|
|
||||||
#### `ses.flushStorageData()`
|
#### `ses.flushStorageData()`
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,8 @@ Session.prototype._init = function () {
|
||||||
app.emit('session-created', this)
|
app.emit('session-created', this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Session.prototype.clearStorageData = deprecate.promisify(Session.prototype.clearStorageData)
|
||||||
|
|
||||||
Cookies.prototype.flushStore = deprecate.promisify(Cookies.prototype.flushStore)
|
Cookies.prototype.flushStore = deprecate.promisify(Cookies.prototype.flushStore)
|
||||||
Cookies.prototype.get = deprecate.promisify(Cookies.prototype.get)
|
Cookies.prototype.get = deprecate.promisify(Cookies.prototype.get)
|
||||||
Cookies.prototype.remove = deprecate.promisify(Cookies.prototype.remove)
|
Cookies.prototype.remove = deprecate.promisify(Cookies.prototype.remove)
|
||||||
|
|
|
@ -324,6 +324,26 @@ describe('session module', () => {
|
||||||
describe('ses.clearStorageData(options)', () => {
|
describe('ses.clearStorageData(options)', () => {
|
||||||
fixtures = path.resolve(__dirname, 'fixtures')
|
fixtures = path.resolve(__dirname, 'fixtures')
|
||||||
it('clears localstorage data', (done) => {
|
it('clears localstorage data', (done) => {
|
||||||
|
ipcMain.on('count', (event, count) => {
|
||||||
|
ipcMain.removeAllListeners('count')
|
||||||
|
assert.strictEqual(count, 0)
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
w.webContents.on('did-finish-load', () => {
|
||||||
|
const options = {
|
||||||
|
origin: 'file://',
|
||||||
|
storages: ['localstorage'],
|
||||||
|
quotas: ['persistent']
|
||||||
|
}
|
||||||
|
w.webContents.session.clearStorageData(options).then(() => {
|
||||||
|
w.webContents.send('getcount')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
w.loadFile(path.join(fixtures, 'api', 'localstorage.html'))
|
||||||
|
})
|
||||||
|
|
||||||
|
// TODO(codebytere): remove when promisification is complete
|
||||||
|
it('clears localstorage data (callback)', (done) => {
|
||||||
ipcMain.on('count', (event, count) => {
|
ipcMain.on('count', (event, count) => {
|
||||||
ipcMain.removeAllListeners('count')
|
ipcMain.removeAllListeners('count')
|
||||||
assert.strictEqual(count, 0)
|
assert.strictEqual(count, 0)
|
||||||
|
|
|
@ -184,7 +184,7 @@ describe('chromium feature', () => {
|
||||||
done()
|
done()
|
||||||
}).catch((error) => done(error))
|
}).catch((error) => done(error))
|
||||||
} else {
|
} else {
|
||||||
ses.clearStorageData(options, () => {
|
ses.clearStorageData(options).then(() => {
|
||||||
w.webContents.reload()
|
w.webContents.reload()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -225,7 +225,7 @@ describe('chromium feature', () => {
|
||||||
assert.strictEqual(message, 'Hello from serviceWorker!')
|
assert.strictEqual(message, 'Hello from serviceWorker!')
|
||||||
session.fromPartition('sw-file-scheme-spec').clearStorageData({
|
session.fromPartition('sw-file-scheme-spec').clearStorageData({
|
||||||
storages: ['serviceworkers']
|
storages: ['serviceworkers']
|
||||||
}, () => done())
|
}).then(() => done())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
w.webContents.on('crashed', () => done(new Error('WebContents crashed.')))
|
w.webContents.on('crashed', () => done(new Error('WebContents crashed.')))
|
||||||
|
@ -264,8 +264,8 @@ describe('chromium feature', () => {
|
||||||
assert.strictEqual(message, 'Hello from serviceWorker!')
|
assert.strictEqual(message, 'Hello from serviceWorker!')
|
||||||
customSession.clearStorageData({
|
customSession.clearStorageData({
|
||||||
storages: ['serviceworkers']
|
storages: ['serviceworkers']
|
||||||
}, () => {
|
}).then(() => {
|
||||||
customSession.protocol.uninterceptProtocol('file', (error) => done(error))
|
customSession.protocol.uninterceptProtocol('file', error => done(error))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue