diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index d724d1ea4c1c..d8201973fd83 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -161,19 +161,21 @@ WebContents::WebContents(v8::Isolate* isolate, type_ = is_guest ? WEB_VIEW : BROWSER_WINDOW; + // TODO(zcbenz): Use host's BrowserContext when no partition is specified. content::BrowserContext* browser_context = AtomBrowserMainParts::Get()->browser_context(); content::WebContents* web_contents; if (is_guest) { - GURL guest_site; - options.Get("partition", &guest_site); - // use hosts' browser_context when no partition is specified. - if (!guest_site.query().empty()) { + std::string partition; + bool in_memory = false; + options.Get("partition", &partition); + options.Get("inMemory", &in_memory); + if (!partition.empty()) { browser_context = AtomBrowserMainParts::Get() - ->GetBrowserContextForPartition(guest_site); + ->GetBrowserContextForPartition(partition, in_memory); } - auto site_instance = - content::SiteInstance::CreateForURL(browser_context, guest_site); + content::SiteInstance* site_instance = content::SiteInstance::CreateForURL( + browser_context, GURL("chrome-guest://fake-host")); content::WebContents::CreateParams params(browser_context, site_instance); guest_delegate_.reset(new WebViewGuestDelegate); params.guest_delegate = guest_delegate_.get(); @@ -190,7 +192,7 @@ WebContents::WebContents(v8::Isolate* isolate, // Save the preferences. base::DictionaryValue web_preferences; mate::ConvertFromV8(isolate, options.GetHandle(), &web_preferences); - new WebContentsPreferences(web_contents, std::move(web_preferences)); + new WebContentsPreferences(web_contents, &web_preferences); web_contents->SetUserAgentOverride(GetBrowserContext()->GetUserAgent()); diff --git a/atom/browser/atom_browser_main_parts.cc b/atom/browser/atom_browser_main_parts.cc index 806c12b7eace..5fae6da14b21 100644 --- a/atom/browser/atom_browser_main_parts.cc +++ b/atom/browser/atom_browser_main_parts.cc @@ -26,24 +26,6 @@ namespace atom { -namespace { - -const base::FilePath::CharType kStoragePartitionDirname[] = - FILE_PATH_LITERAL("Partitions"); - -void GetStoragePartitionConfig(const GURL& partition, - base::FilePath* partition_path, - bool* in_memory, - std::string* id) { - *in_memory = (partition.path() != "/persist"); - net::UnescapeRule::Type flags = - net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS; - *id = net::UnescapeURLComponent(partition.query(), flags); - *partition_path = base::FilePath(kStoragePartitionDirname).AppendASCII(*id); -} - -} // namespace - // static AtomBrowserMainParts* AtomBrowserMainParts::self_ = NULL; @@ -69,18 +51,20 @@ AtomBrowserMainParts* AtomBrowserMainParts::Get() { } content::BrowserContext* AtomBrowserMainParts::GetBrowserContextForPartition( - const GURL& partition) { - std::string id; - bool in_memory; - base::FilePath partition_path; - GetStoragePartitionConfig(partition, &partition_path, &in_memory, &id); - if (browser_context_map_.contains(id)) - return browser_context_map_.get(id); + const std::string& partition, bool in_memory) { + if (browser_context_map_.contains(partition)) + return browser_context_map_.get(partition); scoped_ptr browser_context(CreateBrowserContext()); +<<<<<<< HEAD browser_context->Initialize(partition_path.AsUTF8Unsafe(), in_memory); browser_context_map_.set(id, browser_context.Pass()); return browser_context_map_.get(id); +======= + browser_context->Initialize(partition, in_memory); + browser_context_map_.set(partition, browser_context.Pass()); + return browser_context_map_.get(partition); +>>>>>>> Pass partition name instead of path to BrowserContext } void AtomBrowserMainParts::RegisterDestructionCallback( diff --git a/atom/browser/atom_browser_main_parts.h b/atom/browser/atom_browser_main_parts.h index d952f432882f..b7b179cf806f 100644 --- a/atom/browser/atom_browser_main_parts.h +++ b/atom/browser/atom_browser_main_parts.h @@ -35,7 +35,7 @@ class AtomBrowserMainParts : public brightray::BrowserMainParts { // Returns the BrowserContext associated with the partition. content::BrowserContext* GetBrowserContextForPartition( - const GURL& partition); + const std::string& partition, bool in_memory); // Register a callback that should be destroyed before JavaScript environment // gets destroyed. diff --git a/atom/browser/lib/guest-view-manager.coffee b/atom/browser/lib/guest-view-manager.coffee index 961da8ad1920..c7ec439f96f0 100644 --- a/atom/browser/lib/guest-view-manager.coffee +++ b/atom/browser/lib/guest-view-manager.coffee @@ -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 diff --git a/atom/browser/web_contents_preferences.cc b/atom/browser/web_contents_preferences.cc index ab7a700cc284..19ea826a5ff7 100644 --- a/atom/browser/web_contents_preferences.cc +++ b/atom/browser/web_contents_preferences.cc @@ -4,6 +4,8 @@ #include "atom/browser/web_contents_preferences.h" +#include + #include "atom/common/options_switches.h" #include "base/command_line.h" #include "base/strings/string_number_conversions.h" @@ -36,8 +38,8 @@ const char* kWebRuntimeFeatures[] = { WebContentsPreferences::WebContentsPreferences( content::WebContents* web_contents, - base::DictionaryValue&& web_preferences) { - web_preferences_.Swap(&web_preferences); + base::DictionaryValue* web_preferences) { + web_preferences_.Swap(web_preferences); web_contents->SetUserData(kWebPreferencesKey, this); } diff --git a/atom/browser/web_contents_preferences.h b/atom/browser/web_contents_preferences.h index 1053dd9c1087..310456725aaf 100644 --- a/atom/browser/web_contents_preferences.h +++ b/atom/browser/web_contents_preferences.h @@ -34,7 +34,7 @@ class WebContentsPreferences content::WebContents* web_contents, content::WebPreferences* prefs); WebContentsPreferences(content::WebContents* web_contents, - base::DictionaryValue&& web_preferences); + base::DictionaryValue* web_preferences); ~WebContentsPreferences() override; // $.extend(|web_preferences_|, |new_web_preferences|). diff --git a/vendor/brightray b/vendor/brightray index 4d8f5d879d48..55bab304fd1c 160000 --- a/vendor/brightray +++ b/vendor/brightray @@ -1 +1 @@ -Subproject commit 4d8f5d879d484db54895c3456ded3a3d3246415d +Subproject commit 55bab304fd1c92a79e636bca0313f7cbda000c06