use embedders' browser context when partition is not specified
This commit is contained in:
parent
150b540e72
commit
da5bac42f3
3 changed files with 13 additions and 7 deletions
|
@ -159,12 +159,17 @@ WebContents::WebContents(const mate::Dictionary& options) {
|
|||
|
||||
type_ = is_guest ? WEB_VIEW : BROWSER_WINDOW;
|
||||
|
||||
content::BrowserContext* browser_context =
|
||||
AtomBrowserMainParts::Get()->browser_context();
|
||||
content::WebContents* web_contents;
|
||||
if (is_guest) {
|
||||
GURL guest_site;
|
||||
options.Get("partition", &guest_site);
|
||||
auto browser_context =
|
||||
AtomBrowserMainParts::Get()->GetBrowserContextForPartition(guest_site);
|
||||
// use hosts' browser_context when no partition is specified.
|
||||
if (!guest_site.query().empty()) {
|
||||
browser_context = AtomBrowserMainParts::Get()
|
||||
->GetBrowserContextForPartition(guest_site);
|
||||
}
|
||||
auto site_instance =
|
||||
content::SiteInstance::CreateForURL(browser_context, guest_site);
|
||||
content::WebContents::CreateParams params(browser_context, site_instance);
|
||||
|
@ -172,7 +177,6 @@ WebContents::WebContents(const mate::Dictionary& options) {
|
|||
params.guest_delegate = guest_delegate_.get();
|
||||
web_contents = content::WebContents::Create(params);
|
||||
} else {
|
||||
auto browser_context = AtomBrowserMainParts::Get()->browser_context();
|
||||
content::WebContents::CreateParams params(browser_context);
|
||||
web_contents = content::WebContents::Create(params);
|
||||
}
|
||||
|
|
|
@ -40,12 +40,14 @@ getNextInstanceId = (webContents) ->
|
|||
++nextInstanceId
|
||||
|
||||
# Generate URL encoded partition id.
|
||||
getPartitionId = (partition='default') ->
|
||||
getPartitionId = (partition) ->
|
||||
persist = partition.startsWith('persist:')
|
||||
# Guest site url will be chrome-guest://fake-host/{persist}?{partitionId}
|
||||
partitionId = "chrome-guest://fake-host/"
|
||||
partitionId += if persist then 'persist?' else '?'
|
||||
partitionId += crypto.createHash('sha256').update(partition).digest('hex')
|
||||
if partition
|
||||
partitionId += if persist then 'persist?' else '?'
|
||||
partitionId += crypto.createHash('sha256').update(partition).digest('hex')
|
||||
return partitionId
|
||||
|
||||
# Create a new guest instance.
|
||||
createGuest = (embedder, params) ->
|
||||
|
|
|
@ -140,7 +140,7 @@ If "on", the guest page will have web security disabled.
|
|||
|
||||
Sets the storage partition used by the `webview`. If the storage partition ID starts with `persist:`,
|
||||
the `webview` will use a persistent storage partition available to all `webview` in the app with
|
||||
the same storage partition ID. If the ID is unset or if there is no `persist:` prefix, the `webview` will
|
||||
the same storage partition ID. if there is no `persist:` prefix, the `webview` will
|
||||
use an in-memory storage partition. By assigning the same partition ID, multiple `webview`
|
||||
can share the same storage partition.
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue