Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1698)

Unified Diff: content/browser/web_contents/web_contents_impl.cc

Issue 10831116: Move SessionStorageNamespace entirely into NavigationController and support StoragePartitions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix content shell Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/web_contents/web_contents_impl.cc
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index 79ea7ab8605ef7f9dd485124e03e18e465cc277b..5a0cec5d20b1e3bd18d08aab95bf07bee3551130 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -18,6 +18,7 @@
#include "content/browser/browser_plugin/old/browser_plugin_host.h"
#include "content/browser/child_process_security_policy_impl.h"
#include "content/browser/debugger/devtools_manager_impl.h"
+#include "content/browser/dom_storage/dom_storage_context_impl.h"
#include "content/browser/dom_storage/session_storage_namespace_impl.h"
#include "content/browser/download/download_stats.h"
#include "content/browser/download/mhtml_generation_manager.h"
@@ -270,15 +271,31 @@ WebContents* WebContents::Create(
BrowserContext* browser_context,
SiteInstance* site_instance,
int routing_id,
+ const WebContents* base_web_contents) {
+ return WebContentsImpl::Create(
+ browser_context, site_instance, routing_id,
+ static_cast<const WebContentsImpl*>(base_web_contents));
+}
+
+WebContents* WebContents::CreateWithSessionStorage(
+ BrowserContext* browser_context,
+ SiteInstance* site_instance,
+ int routing_id,
const WebContents* base_web_contents,
- SessionStorageNamespace* session_storage_namespace) {
- return new WebContentsImpl(
- browser_context,
- site_instance,
- routing_id,
- static_cast<const WebContentsImpl*>(base_web_contents),
- NULL,
- static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace));
+ const SessionStorageNamespaceMap& session_storage_namespace_map) {
+ WebContentsImpl* new_contents = new WebContentsImpl(browser_context, NULL);
+
+ for (SessionStorageNamespaceMap::const_iterator it =
+ session_storage_namespace_map.begin();
+ it != session_storage_namespace_map.end();
+ ++it) {
+ new_contents->GetController().SetSessionStorageNamespace(it->first,
+ it->second);
+ }
+
+ new_contents->Init(browser_context, site_instance, routing_id,
+ static_cast<const WebContentsImpl*>(base_web_contents));
+ return new_contents;
}
WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
@@ -291,14 +308,9 @@ WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
WebContentsImpl::WebContentsImpl(
content::BrowserContext* browser_context,
- SiteInstance* site_instance,
- int routing_id,
- const WebContentsImpl* base_web_contents,
- WebContentsImpl* opener,
- SessionStorageNamespaceImpl* session_storage_namespace)
+ WebContentsImpl* opener)
: delegate_(NULL),
- ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
- this, browser_context, session_storage_namespace)),
+ ALLOW_THIS_IN_INITIALIZER_LIST(controller_(this, browser_context)),
render_view_host_delegate_view_(NULL),
opener_(opener),
ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this, this)),
@@ -327,43 +339,6 @@ WebContentsImpl::WebContentsImpl(
temporary_zoom_settings_(false),
content_restrictions_(0),
color_chooser_(NULL) {
- render_manager_.Init(browser_context, site_instance, routing_id);
-
- view_.reset(content::GetContentClient()->browser()->
- OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
- if (view_.get()) {
- CHECK(render_view_host_delegate_view_);
- } else {
- content::WebContentsViewDelegate* delegate =
- content::GetContentClient()->browser()->GetWebContentsViewDelegate(
- this);
- view_.reset(CreateWebContentsView(
- this, delegate, &render_view_host_delegate_view_));
- CHECK(render_view_host_delegate_view_);
- }
- CHECK(view_.get());
-
- // We have the initial size of the view be based on the size of the view of
- // the passed in WebContents.
- view_->CreateView(base_web_contents ?
- base_web_contents->GetView()->GetContainerSize() : gfx::Size());
-
- // Listen for whether our opener gets destroyed.
- if (opener_) {
- registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
- content::Source<WebContents>(opener_));
- }
-
- registrar_.Add(this,
- content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
- content::NotificationService::AllBrowserContextsAndSources());
-
-#if defined(ENABLE_JAVA_BRIDGE)
- java_bridge_dispatcher_host_manager_.reset(
- new JavaBridgeDispatcherHostManager(this));
-#endif
-
- browser_plugin_host_.reset(new content::BrowserPluginHost(this));
}
WebContentsImpl::~WebContentsImpl() {
@@ -408,6 +383,28 @@ WebContentsImpl::~WebContentsImpl() {
SetDelegate(NULL);
}
+WebContentsImpl* WebContentsImpl::Create(
+ BrowserContext* browser_context,
+ SiteInstance* site_instance,
+ int routing_id,
+ const WebContentsImpl* base_web_contents) {
+ return CreateWithOpener(browser_context, site_instance, routing_id,
+ base_web_contents, NULL);
+}
+
+WebContentsImpl* WebContentsImpl::CreateWithOpener(
+ BrowserContext* browser_context,
+ SiteInstance* site_instance,
+ int routing_id,
+ const WebContentsImpl* base_web_contents,
+ WebContentsImpl* opener) {
+ WebContentsImpl* new_contents = new WebContentsImpl(browser_context, opener);
+
+ new_contents->Init(browser_context, site_instance, routing_id,
+ static_cast<const WebContentsImpl*>(base_web_contents));
+ return new_contents;
+}
+
WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh,
const GURL& url) {
WebPreferences prefs;
@@ -618,10 +615,6 @@ WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh,
return prefs;
}
-NavigationControllerImpl& WebContentsImpl::GetControllerImpl() {
- return controller_;
-}
-
RenderViewHostManager* WebContentsImpl::GetRenderManagerForTesting() {
return &render_manager_;
}
@@ -697,11 +690,11 @@ void WebContentsImpl::RunFileChooser(
delegate_->RunFileChooser(this, params);
}
-NavigationController& WebContentsImpl::GetController() {
+NavigationControllerImpl& WebContentsImpl::GetController() {
return controller_;
}
-const NavigationController& WebContentsImpl::GetController() const {
+const NavigationControllerImpl& WebContentsImpl::GetController() const {
return controller_;
}
@@ -1015,10 +1008,10 @@ WebContents* WebContentsImpl::Clone() {
// We use our current SiteInstance since the cloned entry will use it anyway.
// We pass |this| for the |base_web_contents| to size the view correctly, and
// our own opener so that the cloned page can access it if it was before.
- WebContentsImpl* tc = new WebContentsImpl(
- GetBrowserContext(), GetSiteInstance(),
- MSG_ROUTING_NONE, this, opener_, NULL);
- tc->GetControllerImpl().CopyStateFrom(controller_);
+ WebContentsImpl* tc = CreateWithOpener(GetBrowserContext(),
+ GetSiteInstance(), MSG_ROUTING_NONE,
+ this, opener_);
+ tc->GetController().CopyStateFrom(controller_);
return tc;
}
@@ -1073,6 +1066,49 @@ void WebContentsImpl::Observe(int type,
}
}
+void WebContentsImpl::Init(BrowserContext* browser_context,
+ SiteInstance* site_instance,
+ int routing_id,
+ const WebContents* base_web_contents) {
+ render_manager_.Init(browser_context, site_instance, routing_id);
+
+ view_.reset(content::GetContentClient()->browser()->
+ OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
+ if (view_.get()) {
+ CHECK(render_view_host_delegate_view_);
+ } else {
+ content::WebContentsViewDelegate* delegate =
+ content::GetContentClient()->browser()->GetWebContentsViewDelegate(
+ this);
+ view_.reset(CreateWebContentsView(
+ this, delegate, &render_view_host_delegate_view_));
+ CHECK(render_view_host_delegate_view_);
+ }
+ CHECK(view_.get());
+
+ // We have the initial size of the view be based on the size of the view of
+ // the passed in WebContents.
+ view_->CreateView(base_web_contents ?
+ base_web_contents->GetView()->GetContainerSize() : gfx::Size());
+
+ // Listen for whether our opener gets destroyed.
+ if (opener_) {
+ registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
+ content::Source<WebContents>(opener_));
+ }
+
+ registrar_.Add(this,
+ content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
+ content::NotificationService::AllBrowserContextsAndSources());
+
+#if defined(ENABLE_JAVA_BRIDGE)
+ java_bridge_dispatcher_host_manager_.reset(
+ new JavaBridgeDispatcherHostManager(this));
+#endif
+
+ browser_plugin_host_.reset(new content::BrowserPluginHost(this));
+}
+
void WebContentsImpl::OnWebContentsDestroyed(WebContents* web_contents) {
// Clear the opener if it has been closed.
if (web_contents == opener_) {
@@ -1187,13 +1223,26 @@ void WebContentsImpl::CreateNewWindow(
// Create the new web contents. This will automatically create the new
// WebContentsView. In the future, we may want to create the view separately.
- WebContentsImpl* new_contents = new WebContentsImpl(
- GetBrowserContext(),
- site_instance,
- route_id,
- this,
- params.opener_suppressed ? NULL : this,
- static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace));
+ WebContentsImpl* new_contents =
+ CreateWithOpener(GetBrowserContext(),
+ site_instance, route_id, this,
+ params.opener_suppressed ? NULL : this);
+
+ int process_id = site_instance->GetProcess()->GetID();
+ const std::string& partition_id =
+ content::GetContentClient()->browser()
+ ->GetStoragePartitionIdForChildProcess(GetBrowserContext(),
Charlie Reis 2012/08/02 23:06:47 I think we usually put the arrow on the previous l
awong 2012/08/03 00:31:04 I'm actually not sure...for gmock, they put the .
+ process_id);
+ SessionStorageNamespaceImpl* session_storage_namespace_impl =
+ static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
+ DOMStorageContextImpl* dom_storage_context =
+ static_cast<DOMStorageContextImpl*>(
+ BrowserContext::GetDOMStorageContextByPartitionId(GetBrowserContext(),
+ partition_id));
+ CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
+ new_contents->GetController().SetSessionStorageNamespace(
+ partition_id,
+ session_storage_namespace);
new_contents->set_opener_web_ui_type(GetWebUITypeForCurrentState());
if (!params.opener_suppressed) {
@@ -1987,7 +2036,7 @@ void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
void WebContentsImpl::OnDidDisplayInsecureContent() {
content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
displayed_insecure_content_ = true;
- SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
+ SSLManager::NotifySSLInternalStateChanged(&GetController());
}
void WebContentsImpl::OnDidRunInsecureContent(
@@ -1999,7 +2048,7 @@ void WebContentsImpl::OnDidRunInsecureContent(
content::RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
controller_.ssl_manager()->DidRunInsecureContent(security_origin);
displayed_insecure_content_ = true;
- SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
+ SSLManager::NotifySSLInternalStateChanged(&GetController());
}
void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
@@ -3024,7 +3073,7 @@ int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
}
NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
- return GetControllerImpl();
+ return GetController();
}
WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {

Powered by Google App Engine
This is Rietveld 408576698