Move SessionStorageNamespace entirely into NavigationController and support StoragePartitions.
Previously, WebContents, NavigationController, and RenderViewHost all exposed
APIs that allowed one to retrieve the SessionStorageNamespace associated with
them. This is confusing because there were too many ways to access the object.
After this change, the SessionStorageNamespace is only exposed by the
NavigationController.
Conceptually a SessionStorageNamespace belongs to a WebContents but we store
it in NavigationController because on tab duplication, the
NavigationController becomes the authoritative state of the tab.
Also, to support StoragePartitions, the NavigationController
now maintains a map of partition_id -> SessionStorageNamespace. Someone
requesting a SessionStorageNamespace must either know which StoragePartition
they are coming from, or which child process they are acting on behalf of.
This change also changes the way TabContents and WebContents are created.
1) We now have explicitly separate creation methods for prepopulating
with SessionStorage and creating with an opener.
2) Some of the WebContentImpl construct has been moved into an Init()
function to avoid accidental calls to virtual functions by subobjects.
TBR-ing all the directories where I just remove a NULL.
TBR=sky,stevenjb,dominich,brettw,satorux,kalman
BUG=85121
Review URL: https://chromiumcodereview.appspot.com/10831116
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151379 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/content/public/browser/browser_context.h b/content/public/browser/browser_context.h
index 9f003d8..cfe4d53 100644
--- a/content/public/browser/browser_context.h
+++ b/content/public/browser/browser_context.h
@@ -53,6 +53,8 @@
BrowserContext* browser_context);
static DOMStorageContext* GetDOMStorageContext(
BrowserContext* browser_context, int renderer_child_id);
+ static content::DOMStorageContext* GetDOMStorageContextByPartitionId(
+ BrowserContext* browser_context, const std::string& partition_id);
static IndexedDBContext* GetIndexedDBContext(BrowserContext* browser_context);
static webkit_database::DatabaseTracker* GetDatabaseTracker(
BrowserContext* browser_context);
diff --git a/content/public/browser/content_browser_client.cc b/content/public/browser/content_browser_client.cc
index 0e96a038..a84c6dc 100644
--- a/content/public/browser/content_browser_client.cc
+++ b/content/public/browser/content_browser_client.cc
@@ -161,11 +161,25 @@
}
std::string ContentBrowserClient::GetStoragePartitionIdForChildProcess(
- content::BrowserContext* browser_context,
+ BrowserContext* browser_context,
int child_process_id) {
return std::string();
}
+std::string ContentBrowserClient::GetStoragePartitionIdForSiteInstance(
+ BrowserContext* browser_context,
+ content::SiteInstance* instance) {
+ return std::string();
+}
+
+bool ContentBrowserClient::IsValidStoragePartitionId(
+ BrowserContext* browser_context,
+ const std::string& partition_id) {
+ // Since the GetStoragePartitionIdForChildProcess() only generates empty
+ // strings, we should only ever see empty strings coming back.
+ return partition_id.empty();
+}
+
MediaObserver* ContentBrowserClient::GetMediaObserver() {
return NULL;
}
diff --git a/content/public/browser/content_browser_client.h b/content/public/browser/content_browser_client.h
index f5e6849..9337174 100644
--- a/content/public/browser/content_browser_client.h
+++ b/content/public/browser/content_browser_client.h
@@ -274,6 +274,21 @@
content::BrowserContext* browser_context,
int child_process_id);
+ // Same as GetStoragePartitionIdForChildProcess(), but uses a SiteInstance
+ // instead.
+ //
+ // TODO(ajwong): Replace all uses of GetStoragePartitionIdForChildProcess()
+ // with this one.
+ virtual std::string GetStoragePartitionIdForSiteInstance(
+ content::BrowserContext* browser_context,
+ content::SiteInstance* instance);
+
+ // Allows the embedder to provide a validation check for |partition_id|s.
+ // This domain of valid entries should match the range of outputs for
+ // GetStoragePartitionIdForChildProcess().
+ virtual bool IsValidStoragePartitionId(BrowserContext* browser_context,
+ const std::string& partition_id);
+
// Create and return a new quota permission context.
virtual QuotaPermissionContext* CreateQuotaPermissionContext();
diff --git a/content/public/browser/navigation_controller.h b/content/public/browser/navigation_controller.h
index a1bed25..19c2fa93 100644
--- a/content/public/browser/navigation_controller.h
+++ b/content/public/browser/navigation_controller.h
@@ -5,9 +5,11 @@
#ifndef CONTENT_PUBLIC_BROWSER_NAVIGATION_CONTROLLER_H_
#define CONTENT_PUBLIC_BROWSER_NAVIGATION_CONTROLLER_H_
+#include <map>
#include <string>
#include <vector>
+#include "base/memory/ref_counted.h"
#include "base/string16.h"
#include "content/common/content_export.h"
#include "content/public/browser/global_request_id.h"
@@ -23,6 +25,11 @@
class WebContents;
struct Referrer;
+// Used to store the mapping of a StoragePartition id to
+// SessionStorageNamespace.
+typedef std::map<std::string, scoped_refptr<SessionStorageNamespace> >
+ SessionStorageNamespaceMap;
+
// A NavigationController maintains the back-forward list for a WebContents and
// manages all navigation within that list.
//
@@ -228,8 +235,14 @@
// Random --------------------------------------------------------------------
- // The session storage namespace that all child render views should use.
- virtual SessionStorageNamespace* GetSessionStorageNamespace() const = 0;
+ // Returns all the SessionStorageNamespace objects that this
+ // NavigationController knows about.
+ virtual const SessionStorageNamespaceMap&
+ GetSessionStorageNamespaceMap() const = 0;
+
+ // TODO(ajwong): Remove this once prerendering, instant, and session restore
+ // are migrated.
+ virtual SessionStorageNamespace* GetDefaultSessionStorageNamespace() = 0;
// Sets the max restored page ID this NavigationController has seen, if it
// was restored from a previous session.
diff --git a/content/public/browser/render_view_host.h b/content/public/browser/render_view_host.h
index 61deb7a..f3f6f26 100644
--- a/content/public/browser/render_view_host.h
+++ b/content/public/browser/render_view_host.h
@@ -217,8 +217,6 @@
// RenderView. See BindingsPolicy for details.
virtual int GetEnabledBindings() const = 0;
- virtual SessionStorageNamespace* GetSessionStorageNamespace() = 0;
-
virtual SiteInstance* GetSiteInstance() const = 0;
// Requests the renderer to evaluate an xpath to a frame and insert css
diff --git a/content/public/browser/web_contents.h b/content/public/browser/web_contents.h
index 5f65201..c6f55f5 100644
--- a/content/public/browser/web_contents.h
+++ b/content/public/browser/web_contents.h
@@ -10,6 +10,7 @@
#include "base/process_util.h"
#include "base/string16.h"
#include "content/common/content_export.h"
+#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/page_navigator.h"
#include "content/public/browser/save_page_type.h"
#include "content/public/browser/web_ui.h"
@@ -35,11 +36,9 @@
class BrowserContext;
class InterstitialPage;
-class NavigationController;
class RenderProcessHost;
class RenderViewHost;
class RenderWidgetHostView;
-class SessionStorageNamespace;
class SiteInstance;
class WebContentsDelegate;
class WebContentsView;
@@ -51,17 +50,28 @@
// |base_web_contents| is used if we want to size the new WebContents's view
// based on the view of an existing WebContents. This can be NULL if not
// needed.
- //
- // The session storage namespace parameter allows multiple render views and
- // web contentses to share the same session storage (part of the WebStorage
- // spec) space. This is useful when restoring tabs, but most callers should
- // pass in NULL which will cause a new SessionStorageNamespace to be created.
CONTENT_EXPORT static WebContents* Create(
BrowserContext* browser_context,
SiteInstance* site_instance,
int routing_id,
+ const WebContents* base_web_contents);
+
+ // Similar to Create() above but should be used when you need to prepopulate
+ // the SessionStorageNamespaceMap of the WebContents. This can happen if
+ // you duplicate a WebContents, try to reconstitute it from a saved state,
+ // or when you create a new WebContents based on another one (eg., when
+ // servicing a window.open() call).
+ //
+ // You do not want to call this. If you think you do, make sure you completely
+ // understand when SessionStorageNamespace objects should be cloned, why
+ // they should not be shared by multiple WebContents, and what bad things
+ // can happen if you share the object.
+ CONTENT_EXPORT static WebContents* CreateWithSessionStorage(
+ BrowserContext* browser_context,
+ SiteInstance* site_instance,
+ int routing_id,
const WebContents* base_web_contents,
- SessionStorageNamespace* session_storage_namespace);
+ const SessionStorageNamespaceMap& session_storage_namespace_map);
// Returns a WebContents that wraps the RenderViewHost, or NULL if the
// render view host's delegate isn't a WebContents.