Pass partition name instead of path to BrowserContext
This commit is contained in:
parent
f2bdca31b3
commit
3773f81fd5
7 changed files with 35 additions and 56 deletions
|
@ -38,29 +38,21 @@ moveLastToFirst = (list) ->
|
|||
getNextInstanceId = (webContents) ->
|
||||
++nextInstanceId
|
||||
|
||||
# Generate URL encoded partition id.
|
||||
getPartitionId = (partition) ->
|
||||
# Guest site url will be chrome-guest://fake-host/{persist}?{partitionId}
|
||||
partitionId = "chrome-guest://fake-host/"
|
||||
if partition
|
||||
persist = partition.startsWith('persist:')
|
||||
if persist
|
||||
partition = partition.substring('persist:'.length)
|
||||
partitionId += 'persist?'
|
||||
else
|
||||
# Just to differentiate from same persistant ID
|
||||
partition += "_temp"
|
||||
partitionId += '?'
|
||||
partitionId += encodeURIComponent(partition)
|
||||
return partitionId
|
||||
# Parse the partition string.
|
||||
parsePartition = (partition) ->
|
||||
return ['', false] unless partition
|
||||
if partition.startsWith 'persist:'
|
||||
[partition.substr('persist:'.length), false]
|
||||
else
|
||||
[partition, true]
|
||||
|
||||
# Create a new guest instance.
|
||||
createGuest = (embedder, params) ->
|
||||
webViewManager ?= process.atomBinding 'web_view_manager'
|
||||
|
||||
id = getNextInstanceId embedder
|
||||
partitionId = getPartitionId params.partition
|
||||
guest = webContents.create {isGuest: true, partition: partitionId, embedder}
|
||||
[partition, inMemory] = parsePartition params.partition
|
||||
guest = webContents.create {isGuest: true, partition, inMemory, embedder}
|
||||
guestInstances[id] = {guest, embedder}
|
||||
|
||||
# Destroy guest when the embedder is gone or navigated.
|
||||
|
@ -138,7 +130,6 @@ attachGuest = (embedder, elementInstanceId, guestInstanceId, params) ->
|
|||
'plugins': params.plugins
|
||||
'web-security': !params.disablewebsecurity
|
||||
webPreferences['preload-url'] = params.preload if params.preload
|
||||
webPreferences['partition'] = getPartitionId(params.partition) if params.partition
|
||||
webViewManager.addGuest guestInstanceId, elementInstanceId, embedder, guest, webPreferences
|
||||
|
||||
guest.attachParams = params
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue