]> khamidou — GitHub mirrors - electron.git/commitdiff
create partitionId with encodedURIcomponent
authorRobo <hop2deep@gmail.com>
Mon, 31 Aug 2015 18:23:31 +0000 (23:53 +0530)
committerRobo <hop2deep@gmail.com>
Thu, 3 Sep 2015 15:19:29 +0000 (20:49 +0530)
atom/browser/atom_browser_main_parts.cc
atom/browser/atom_browser_main_parts.h
atom/browser/lib/guest-view-manager.coffee
docs/api/web-view-tag.md
spec/fixtures/pages/partition/one.html
spec/fixtures/pages/partition/two.html [deleted file]
spec/webview-spec.coffee

index 189fc938698e478ec73f6b7736d420447676fcc6..4463115cfee505201b201dbda624c43acfce72f4 100644 (file)
@@ -28,15 +28,17 @@ namespace atom {
 
 namespace {
 
-const base::FilePath::CharType kStoragePartitionDirName[] = "Partitions";
+const base::FilePath::CharType kStoragePartitionDirname[] = "Partitions";
 
 void GetStoragePartitionConfig(const GURL& partition,
                                base::FilePath* partition_path,
                                bool* in_memory,
                                std::string* id) {
   *in_memory = (partition.path() != "/persist");
-  *id = partition.query();
-  *partition_path = base::FilePath(kStoragePartitionDirName).AppendASCII(*id);
+  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
@@ -55,7 +57,6 @@ AtomBrowserMainParts::AtomBrowserMainParts()
 }
 
 AtomBrowserMainParts::~AtomBrowserMainParts() {
-  STLDeleteValues(&browser_context_map_);
   for (const auto& callback : destruction_callbacks_)
     callback.Run();
 }
@@ -72,14 +73,13 @@ content::BrowserContext* AtomBrowserMainParts::GetBrowserContextForPartition(
   bool in_memory;
   base::FilePath partition_path;
   GetStoragePartitionConfig(partition, &partition_path, &in_memory, &id);
-  auto item = browser_context_map_.find(id);
-  if (item != browser_context_map_.end())
-    return item->second;
-
-  auto browser_context = CreateBrowserContext();
-  browser_context->Initialize(partition_path, in_memory);
-  browser_context_map_[id] = browser_context;
-  return browser_context;
+  if (browser_context_map_.contains(id))
+    return browser_context_map_.get(id);
+
+  scoped_ptr<brightray::BrowserContext> browser_context(CreateBrowserContext());
+  browser_context->Initialize(partition_path.value(), in_memory);
+  browser_context_map_.set(id, browser_context.Pass());
+  return browser_context_map_.get(id);
 }
 
 void AtomBrowserMainParts::RegisterDestructionCallback(
index 993340bfb42259489c8675124674d7a48ed39544..d952f432882f134a56f6f755cfd9adfeeea80749 100644 (file)
@@ -10,6 +10,7 @@
 #include <string>
 
 #include "base/callback.h"
+#include "base/containers/scoped_ptr_hash_map.h"
 #include "base/timer/timer.h"
 #include "brightray/browser/browser_main_parts.h"
 #include "content/public/browser/browser_context.h"
@@ -78,7 +79,8 @@ class AtomBrowserMainParts : public brightray::BrowserMainParts {
   std::list<base::Closure> destruction_callbacks_;
 
   // partition_id => browser_context
-  std::map<std::string, content::BrowserContext*> browser_context_map_;
+  base::ScopedPtrHashMap<std::string, scoped_ptr<brightray::BrowserContext>>
+      browser_context_map_;
 
   static AtomBrowserMainParts* self_;
 
index 8d86e8fae9111a7b3f9456eababdc6ed479b538c..2f1c8312155a48489ee6d24166c8fe3693c8bfe5 100644 (file)
@@ -1,4 +1,3 @@
-crypto = require 'crypto'
 ipc = require 'ipc'
 webContents = require 'web-contents'
 webViewManager = null  # Doesn't exist in early initialization.
@@ -41,12 +40,16 @@ getNextInstanceId = (webContents) ->
 
 # Generate URL encoded partition id.
 getPartitionId = (partition) ->
-  persist = partition.startsWith('persist:')
   # Guest site url will be chrome-guest://fake-host/{persist}?{partitionId}
   partitionId = "chrome-guest://fake-host/"
   if partition
-    partitionId += if persist then 'persist?' else '?'
-    partitionId += crypto.createHash('sha256').update(partition).digest('hex')
+    persist = partition.startsWith('persist:')
+    if persist
+      partition = partition.substring('persist:'.length)
+      partitionId += 'persist?'
+    else
+      partitionId += '?'
+    partitionId += encodeURIComponent(partition)
   return partitionId
 
 # Create a new guest instance.
index cafcc5762e7aa916426b74e0926a8b6d9e85ade9..c1b1f705e95b461d6387d101d705a1b43ba7174f 100644 (file)
@@ -142,7 +142,8 @@ Sets the storage partition used by the `webview`. If the storage partition ID st
 the `webview` will use a persistent storage partition available to all `webview` in the app with
 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.
+can share the same storage partition. If the storage partition ID is unset then default storage
+of the app will be used.
 
 This value can only be modified before the first navigation, since the storage partition of an active
 renderer process cannot change. Subsequent attempts to modify the value will fail with a
index 765f721883f355df978a9f7f749a3cc812ecf559..ad22c341df951c2267292b2640c88a424cc88a90 100644 (file)
@@ -1,5 +1,4 @@
 <script>
-window.localStorage.setItem('test', 'one');
 const item = window.localStorage.getItem('test');
 console.log([item, window.localStorage.length].join(' '));
 </script>
diff --git a/spec/fixtures/pages/partition/two.html b/spec/fixtures/pages/partition/two.html
deleted file mode 100644 (file)
index ad22c34..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-<script>
-const item = window.localStorage.getItem('test');
-console.log([item, window.localStorage.length].join(' '));
-</script>
index ae8cd5d45579cc61e2ebb07a71cbdc40fef6a976..486efaa6ffb4a82ec87c4713247f4a035874329c 100644 (file)
@@ -155,30 +155,25 @@ describe '<webview> tag', ->
       document.body.appendChild webview
 
   describe 'partition attribute', ->
-    isolatedWebview = null
-    beforeEach ->
-      isolatedWebview = new WebView
-
-    afterEach ->
-      document.body.removeChild isolatedWebview
-
     it 'isolates storage for different id', (done) ->
       listener = (e) ->
-        document.body.appendChild isolatedWebview
-        webview.removeEventListener 'did-finish-load', listener
-      listener2 = (e) ->
-        assert.equal e.message, "one 1"
-        webview.removeEventListener 'console-message', listener2
-      listener3 = (e) ->
         assert.equal e.message, " 0"
-        isolatedWebview.removeEventListener 'console-message', listener3
+        webview.removeEventListener 'console-message', listener
         done()
-      webview.addEventListener 'did-finish-load', listener
-      webview.addEventListener 'console-message', listener2
+      window.localStorage.setItem 'test', 'one'
+      webview.addEventListener 'console-message', listener
+      webview.src = "file://#{fixtures}/pages/partition/one.html"
+      webview.partition = "test"
+      document.body.appendChild webview
+
+    it 'uses current session storage when no id is provided', (done) ->
+      listener = (e) ->
+        assert.equal e.message, "one 1"
+        webview.removeEventListener 'console-message', listener
+        done()
+      window.localStorage.setItem 'test', 'one'
+      webview.addEventListener 'console-message', listener
       webview.src = "file://#{fixtures}/pages/partition/one.html"
-      isolatedWebview.addEventListener 'console-message', listener3
-      isolatedWebview.setAttribute 'partition', 'test'
-      isolatedWebview.src = "file://#{fixtures}/pages/partition/two.html"
       document.body.appendChild webview
 
   describe 'new-window event', ->