Chromium Code Reviews| Index: content/browser/web_contents/navigation_controller_impl.cc |
| diff --git a/content/browser/web_contents/navigation_controller_impl.cc b/content/browser/web_contents/navigation_controller_impl.cc |
| index 557180f7158a0902b09976469c225d1723ca6f6c..46fe09116ae13e9a146926b5d6bda5c00c3ceb15 100644 |
| --- a/content/browser/web_contents/navigation_controller_impl.cc |
| +++ b/content/browser/web_contents/navigation_controller_impl.cc |
| @@ -1,4 +1,4 @@ |
| -// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| + // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
|
Charlie Reis
2012/08/02 23:06:47
Extra space
awong
2012/08/03 00:31:04
Done.
|
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| @@ -22,12 +22,14 @@ |
| #include "content/browser/web_contents/web_contents_impl.h" |
| #include "content/common/view_messages.h" |
| #include "content/public/browser/browser_context.h" |
| +#include "content/public/browser/content_browser_client.h" |
| #include "content/public/browser/invalidate_type.h" |
| #include "content/public/browser/navigation_details.h" |
| #include "content/public/browser/notification_service.h" |
| #include "content/public/browser/notification_types.h" |
| #include "content/public/browser/user_metrics.h" |
| #include "content/public/browser/web_contents_delegate.h" |
| +#include "content/public/common/content_client.h" |
| #include "content/public/common/content_constants.h" |
| #include "content/public/common/url_constants.h" |
| #include "net/base/escape.h" |
| @@ -37,12 +39,14 @@ |
| using content::BrowserContext; |
| using content::DOMStorageContext; |
| +using content::GetContentClient; |
| using content::GlobalRequestID; |
| using content::NavigationController; |
| using content::NavigationEntry; |
| using content::NavigationEntryImpl; |
| using content::RenderViewHostImpl; |
| using content::SessionStorageNamespace; |
| +using content::SessionStorageNamespaceMap; |
| using content::SiteInstance; |
| using content::UserMetricsAction; |
| using content::WebContents; |
| @@ -178,8 +182,7 @@ void NavigationController::DisablePromptOnRepost() { |
| NavigationControllerImpl::NavigationControllerImpl( |
| WebContentsImpl* web_contents, |
| - BrowserContext* browser_context, |
| - SessionStorageNamespaceImpl* session_storage_namespace) |
| + BrowserContext* browser_context) |
| : browser_context_(browser_context), |
| pending_entry_(NULL), |
| last_committed_entry_index_(-1), |
| @@ -189,14 +192,8 @@ NavigationControllerImpl::NavigationControllerImpl( |
| max_restored_page_id_(-1), |
| ALLOW_THIS_IN_INITIALIZER_LIST(ssl_manager_(this)), |
| needs_reload_(false), |
| - session_storage_namespace_(session_storage_namespace), |
| pending_reload_(NO_RELOAD) { |
| DCHECK(browser_context_); |
| - if (!session_storage_namespace_) { |
| - session_storage_namespace_ = new SessionStorageNamespaceImpl( |
| - static_cast<DOMStorageContextImpl*>( |
| - BrowserContext::GetDefaultDOMStorageContext(browser_context_))); |
| - } |
| } |
| NavigationControllerImpl::~NavigationControllerImpl() { |
| @@ -1131,7 +1128,15 @@ void NavigationControllerImpl::CopyStateFrom( |
| needs_reload_ = true; |
| InsertEntriesFrom(source, source.GetEntryCount()); |
| - session_storage_namespace_ = source.session_storage_namespace_->Clone(); |
| + for (SessionStorageNamespaceMap::const_iterator it = |
| + source.session_storage_namespace_map_.begin(); |
| + it != source.session_storage_namespace_map_.end(); |
| + ++it) { |
| + SessionStorageNamespaceImpl* source_namespace = |
| + static_cast<SessionStorageNamespaceImpl*>(it->second.get()); |
| + session_storage_namespace_map_.insert( |
| + make_pair(it->first, source_namespace->Clone())); |
| + } |
| FinishRestore(source.last_committed_entry_index_, false); |
| @@ -1211,6 +1216,8 @@ void NavigationControllerImpl::CopyStateFromAndPrune( |
| web_contents_->UpdateMaxPageIDForSiteInstance(site_instance.get(), |
| max_page_id); |
| } |
| + |
| + // TODO(ajwong): Do we need to handle SessionStorage here? |
|
Charlie Reis
2012/08/02 23:06:47
I would think so. We want all the SessionStorageN
awong
2012/08/03 00:31:04
I'm actually not sure....the prerenderer and insta
Charlie Reis
2012/08/03 22:11:28
Should be easy to check manually, right? Just set
awong
2012/08/04 01:01:32
At this point, I think I understand instant and pr
|
| } |
| void NavigationControllerImpl::PruneAllButActive() { |
| @@ -1252,6 +1259,24 @@ void NavigationControllerImpl::PruneAllButActive() { |
| } |
| } |
| +void NavigationControllerImpl::SetSessionStorageNamespace( |
| + const std::string& partition_id, |
| + content::SessionStorageNamespace* session_storage_namespace) { |
| + if (!session_storage_namespace) { |
|
Charlie Reis
2012/08/02 23:06:47
nit: No braces
awong
2012/08/03 00:31:04
Done.
|
| + return; |
| + } |
| + |
| + // We can't overwrite an existing SessionStorage without violating spec. |
| + // Attempts to do so may give a tab access to another tab's session storage |
| + // so die hard on an error. |
| + bool successful_insert = session_storage_namespace_map_.insert( |
| + make_pair(partition_id, |
| + static_cast<SessionStorageNamespaceImpl*>( |
| + session_storage_namespace))) |
| + .second; |
| + CHECK(successful_insert) << "Cannot replace existing SessionStorageNamespace"; |
| +} |
| + |
| void NavigationControllerImpl::SetMaxRestoredPageID(int32 max_id) { |
| max_restored_page_id_ = max_id; |
| } |
| @@ -1261,8 +1286,32 @@ int32 NavigationControllerImpl::GetMaxRestoredPageID() const { |
| } |
| SessionStorageNamespace* |
| - NavigationControllerImpl::GetSessionStorageNamespace() const { |
| - return session_storage_namespace_; |
| +NavigationControllerImpl::GetSessionStorageNamespace(int renderer_id) { |
| + const std::string& partition_id = |
| + GetContentClient()->browser()->GetStoragePartitionIdForChildProcess( |
| + browser_context_, |
| + renderer_id); |
| + |
| + SessionStorageNamespaceMap::const_iterator it = |
| + session_storage_namespace_map_.find(partition_id); |
| + if (it != session_storage_namespace_map_.end()) { |
|
Charlie Reis
2012/08/02 23:06:47
nit: No braces
awong
2012/08/03 00:31:04
Done.
|
| + return it->second.get(); |
| + } |
| + |
| + // Create one if no one has accessed session storage for this partition yet. |
| + SessionStorageNamespaceImpl* session_storage_namespace = |
| + new SessionStorageNamespaceImpl( |
| + static_cast<DOMStorageContextImpl*>( |
| + BrowserContext::GetDOMStorageContext(browser_context_, |
| + renderer_id))); |
| + session_storage_namespace_map_[partition_id] = session_storage_namespace; |
| + |
| + return session_storage_namespace; |
| +} |
| + |
| +const SessionStorageNamespaceMap& |
| +NavigationControllerImpl::GetSessionStorageNamespaceMap() const { |
| + return session_storage_namespace_map_; |
| } |
| bool NavigationControllerImpl::NeedsReload() const { |