feat: add session.storagePath to get path on disk for session data (#28665)
This commit is contained in:
parent
b97b973306
commit
fa61e3b119
4 changed files with 39 additions and 1 deletions
|
@ -817,6 +817,11 @@ Returns `Extension[]` - A list of all loaded extensions.
|
||||||
**Note:** This API cannot be called before the `ready` event of the `app` module
|
**Note:** This API cannot be called before the `ready` event of the `app` module
|
||||||
is emitted.
|
is emitted.
|
||||||
|
|
||||||
|
#### `ses.getStoragePath()`
|
||||||
|
|
||||||
|
A `String | null` indicating the absolute file system path where data for this
|
||||||
|
session is persisted on disk. For in memory sessions this returns `null`.
|
||||||
|
|
||||||
### Instance Properties
|
### Instance Properties
|
||||||
|
|
||||||
The following properties are available on instances of `Session`:
|
The following properties are available on instances of `Session`:
|
||||||
|
@ -830,6 +835,11 @@ code to the `setSpellCheckerLanguages` API that isn't in this array will result
|
||||||
|
|
||||||
A `Boolean` indicating whether builtin spell checker is enabled.
|
A `Boolean` indicating whether builtin spell checker is enabled.
|
||||||
|
|
||||||
|
#### `ses.storagePath` _Readonly_
|
||||||
|
|
||||||
|
A `String | null` indicating the absolute file system path where data for this
|
||||||
|
session is persisted on disk. For in memory sessions this returns `null`.
|
||||||
|
|
||||||
#### `ses.cookies` _Readonly_
|
#### `ses.cookies` _Readonly_
|
||||||
|
|
||||||
A [`Cookies`](cookies.md) object for this session.
|
A [`Cookies`](cookies.md) object for this session.
|
||||||
|
|
|
@ -964,6 +964,13 @@ v8::Local<v8::Promise> Session::CloseAllConnections() {
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
v8::Local<v8::Value> Session::GetPath(v8::Isolate* isolate) {
|
||||||
|
if (browser_context_->IsOffTheRecord()) {
|
||||||
|
return v8::Null(isolate);
|
||||||
|
}
|
||||||
|
return gin::ConvertToV8(isolate, browser_context_->GetPath());
|
||||||
|
}
|
||||||
|
|
||||||
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
||||||
base::Value Session::GetSpellCheckerLanguages() {
|
base::Value Session::GetSpellCheckerLanguages() {
|
||||||
return browser_context_->prefs()
|
return browser_context_->prefs()
|
||||||
|
@ -1188,11 +1195,13 @@ gin::ObjectTemplateBuilder Session::GetObjectTemplateBuilder(
|
||||||
#endif
|
#endif
|
||||||
.SetMethod("preconnect", &Session::Preconnect)
|
.SetMethod("preconnect", &Session::Preconnect)
|
||||||
.SetMethod("closeAllConnections", &Session::CloseAllConnections)
|
.SetMethod("closeAllConnections", &Session::CloseAllConnections)
|
||||||
|
.SetMethod("getStoragePath", &Session::GetPath)
|
||||||
.SetProperty("cookies", &Session::Cookies)
|
.SetProperty("cookies", &Session::Cookies)
|
||||||
.SetProperty("netLog", &Session::NetLog)
|
.SetProperty("netLog", &Session::NetLog)
|
||||||
.SetProperty("protocol", &Session::Protocol)
|
.SetProperty("protocol", &Session::Protocol)
|
||||||
.SetProperty("serviceWorkers", &Session::ServiceWorkerContext)
|
.SetProperty("serviceWorkers", &Session::ServiceWorkerContext)
|
||||||
.SetProperty("webRequest", &Session::WebRequest);
|
.SetProperty("webRequest", &Session::WebRequest)
|
||||||
|
.SetProperty("storagePath", &Session::GetPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* Session::GetTypeName() {
|
const char* Session::GetTypeName() {
|
||||||
|
|
|
@ -124,6 +124,7 @@ class Session : public gin::Wrappable<Session>,
|
||||||
v8::Local<v8::Value> NetLog(v8::Isolate* isolate);
|
v8::Local<v8::Value> NetLog(v8::Isolate* isolate);
|
||||||
void Preconnect(const gin_helper::Dictionary& options, gin::Arguments* args);
|
void Preconnect(const gin_helper::Dictionary& options, gin::Arguments* args);
|
||||||
v8::Local<v8::Promise> CloseAllConnections();
|
v8::Local<v8::Promise> CloseAllConnections();
|
||||||
|
v8::Local<v8::Value> GetPath(v8::Isolate* isolate);
|
||||||
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
||||||
base::Value GetSpellCheckerLanguages();
|
base::Value GetSpellCheckerLanguages();
|
||||||
void SetSpellCheckerLanguages(gin_helper::ErrorThrower thrower,
|
void SetSpellCheckerLanguages(gin_helper::ErrorThrower thrower,
|
||||||
|
|
|
@ -1090,6 +1090,24 @@ describe('session module', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('session.storagePage', () => {
|
||||||
|
it('returns a string', () => {
|
||||||
|
expect(session.defaultSession.storagePath).to.be.a('string');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns null for in memory sessions', () => {
|
||||||
|
expect(session.fromPartition('in-memory').storagePath).to.equal(null);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns different paths for partitions and the default session', () => {
|
||||||
|
expect(session.defaultSession.storagePath).to.not.equal(session.fromPartition('persist:two').storagePath);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns different paths for different partitions', () => {
|
||||||
|
expect(session.fromPartition('persist:one').storagePath).to.not.equal(session.fromPartition('persist:two').storagePath);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('ses.setSSLConfig()', () => {
|
describe('ses.setSSLConfig()', () => {
|
||||||
it('can disable cipher suites', async () => {
|
it('can disable cipher suites', async () => {
|
||||||
const ses = session.fromPartition('' + Math.random());
|
const ses = session.fromPartition('' + Math.random());
|
||||||
|
|
Loading…
Reference in a new issue