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
|
@ -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());
|
||||
|
||||
|
|
|
@ -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<brightray::BrowserContext> 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(
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
#include "atom/browser/web_contents_preferences.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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|).
|
||||
|
|
2
vendor/brightray
vendored
2
vendor/brightray
vendored
|
@ -1 +1 @@
|
|||
Subproject commit 4d8f5d879d484db54895c3456ded3a3d3246415d
|
||||
Subproject commit 55bab304fd1c92a79e636bca0313f7cbda000c06
|
Loading…
Reference in a new issue