From da5bac42f3efb9f28ed9dbb00747ba6052bc6250 Mon Sep 17 00:00:00 2001 From: Robo Date: Fri, 28 Aug 2015 13:00:50 +0530 Subject: [PATCH] use embedders' browser context when partition is not specified --- atom/browser/api/atom_api_web_contents.cc | 10 +++++++--- atom/browser/lib/guest-view-manager.coffee | 8 +++++--- docs/api/web-view-tag.md | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index da33451c1e..7cefe8e45e 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -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); } diff --git a/atom/browser/lib/guest-view-manager.coffee b/atom/browser/lib/guest-view-manager.coffee index c0a87a7ac1..8d86e8fae9 100644 --- a/atom/browser/lib/guest-view-manager.coffee +++ b/atom/browser/lib/guest-view-manager.coffee @@ -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) -> diff --git a/docs/api/web-view-tag.md b/docs/api/web-view-tag.md index ec85296552..cafcc5762e 100644 --- a/docs/api/web-view-tag.md +++ b/docs/api/web-view-tag.md @@ -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.