]> khamidou — GitHub mirrors - electron.git/commitdiff
Pass partition name instead of path to BrowserContext
authorCheng Zhao <zcbenz@gmail.com>
Sat, 5 Sep 2015 11:47:44 +0000 (19:47 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Sun, 6 Sep 2015 02:53:39 +0000 (10:53 +0800)
atom/browser/api/atom_api_web_contents.cc
atom/browser/atom_browser_main_parts.cc
atom/browser/atom_browser_main_parts.h
atom/browser/lib/guest-view-manager.coffee
atom/browser/web_contents_preferences.cc
atom/browser/web_contents_preferences.h
vendor/brightray

index d724d1ea4c1ca1e5229d845885864a89226d14de..d8201973fd83cc83f641193c8f521d0cfcb92317 100644 (file)
@@ -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());
 
index 806c12b7eace4d10ab29a16ad2db8d9a9d711068..5fae6da14b21eac4a5ae60c50e1989a1fc06348b 100644 (file)
 
 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(
index d952f432882f134a56f6f755cfd9adfeeea80749..b7b179cf806f7757f8cbaa9060a8dda738699041 100644 (file)
@@ -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.
index 961da8ad1920b3d90f01f91acd754b57d95b1de7..c7ec439f96f0f6d6dc3375f5fbc8fc73ec78d730 100644 (file)
@@ -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
index ab7a700cc284961eb773e54c3a18347a9fbc7a65..19ea826a5ff7f371e57033ea3ebc731778006f80 100644 (file)
@@ -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);
 }
 
index 1053dd9c1087ebb47df54653d01e4fd44c93b58b..310456725aafed7e28c48d355c46981ad588522e 100644 (file)
@@ -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|).
index 4d8f5d879d484db54895c3456ded3a3d3246415d..55bab304fd1c92a79e636bca0313f7cbda000c06 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 4d8f5d879d484db54895c3456ded3a3d3246415d
+Subproject commit 55bab304fd1c92a79e636bca0313f7cbda000c06