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

Side by Side Diff: content/browser/web_contents/navigation_controller_impl.cc

Issue 10831116: Move SessionStorageNamespace entirely into NavigationController and support StoragePartitions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merged Created 8 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/web_contents/navigation_controller_impl.h" 5 #include "content/browser/web_contents/navigation_controller_impl.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/string_number_conversions.h" // Temporary 9 #include "base/string_number_conversions.h" // Temporary
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/time.h" 11 #include "base/time.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "content/browser/browser_url_handler_impl.h" 13 #include "content/browser/browser_url_handler_impl.h"
14 #include "content/browser/child_process_security_policy_impl.h" 14 #include "content/browser/child_process_security_policy_impl.h"
15 #include "content/browser/dom_storage/dom_storage_context_impl.h" 15 #include "content/browser/dom_storage/dom_storage_context_impl.h"
16 #include "content/browser/dom_storage/session_storage_namespace_impl.h" 16 #include "content/browser/dom_storage/session_storage_namespace_impl.h"
17 #include "content/browser/renderer_host/render_view_host_impl.h" // Temporary 17 #include "content/browser/renderer_host/render_view_host_impl.h" // Temporary
18 #include "content/browser/site_instance_impl.h" 18 #include "content/browser/site_instance_impl.h"
19 #include "content/browser/web_contents/debug_urls.h" 19 #include "content/browser/web_contents/debug_urls.h"
20 #include "content/browser/web_contents/interstitial_page_impl.h" 20 #include "content/browser/web_contents/interstitial_page_impl.h"
21 #include "content/browser/web_contents/navigation_entry_impl.h" 21 #include "content/browser/web_contents/navigation_entry_impl.h"
22 #include "content/browser/web_contents/web_contents_impl.h" 22 #include "content/browser/web_contents/web_contents_impl.h"
23 #include "content/common/view_messages.h" 23 #include "content/common/view_messages.h"
24 #include "content/public/browser/browser_context.h" 24 #include "content/public/browser/browser_context.h"
25 #include "content/public/browser/content_browser_client.h"
25 #include "content/public/browser/invalidate_type.h" 26 #include "content/public/browser/invalidate_type.h"
26 #include "content/public/browser/navigation_details.h" 27 #include "content/public/browser/navigation_details.h"
27 #include "content/public/browser/notification_service.h" 28 #include "content/public/browser/notification_service.h"
28 #include "content/public/browser/notification_types.h" 29 #include "content/public/browser/notification_types.h"
29 #include "content/public/browser/user_metrics.h" 30 #include "content/public/browser/user_metrics.h"
30 #include "content/public/browser/web_contents_delegate.h" 31 #include "content/public/browser/web_contents_delegate.h"
32 #include "content/public/common/content_client.h"
31 #include "content/public/common/content_constants.h" 33 #include "content/public/common/content_constants.h"
32 #include "content/public/common/url_constants.h" 34 #include "content/public/common/url_constants.h"
33 #include "net/base/escape.h" 35 #include "net/base/escape.h"
34 #include "net/base/mime_util.h" 36 #include "net/base/mime_util.h"
35 #include "net/base/net_util.h" 37 #include "net/base/net_util.h"
36 #include "webkit/glue/webkit_glue.h" 38 #include "webkit/glue/webkit_glue.h"
37 39
38 using content::BrowserContext; 40 using content::BrowserContext;
39 using content::DOMStorageContext; 41 using content::DOMStorageContext;
42 using content::GetContentClient;
40 using content::GlobalRequestID; 43 using content::GlobalRequestID;
41 using content::NavigationController; 44 using content::NavigationController;
42 using content::NavigationEntry; 45 using content::NavigationEntry;
43 using content::NavigationEntryImpl; 46 using content::NavigationEntryImpl;
44 using content::RenderViewHostImpl; 47 using content::RenderViewHostImpl;
45 using content::SessionStorageNamespace; 48 using content::SessionStorageNamespace;
49 using content::SessionStorageNamespaceMap;
46 using content::SiteInstance; 50 using content::SiteInstance;
47 using content::UserMetricsAction; 51 using content::UserMetricsAction;
48 using content::WebContents; 52 using content::WebContents;
49 53
50 namespace { 54 namespace {
51 55
52 const int kInvalidateAll = 0xFFFFFFFF; 56 const int kInvalidateAll = 0xFFFFFFFF;
53 57
54 // Invoked when entries have been pruned, or removed. For example, if the 58 // Invoked when entries have been pruned, or removed. For example, if the
55 // current entries are [google, digg, yahoo], with the current entry google, 59 // current entries are [google, digg, yahoo], with the current entry google,
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 175
172 // static 176 // static
173 void NavigationController::DisablePromptOnRepost() { 177 void NavigationController::DisablePromptOnRepost() {
174 g_check_for_repost = false; 178 g_check_for_repost = false;
175 } 179 }
176 180
177 } // namespace content 181 } // namespace content
178 182
179 NavigationControllerImpl::NavigationControllerImpl( 183 NavigationControllerImpl::NavigationControllerImpl(
180 WebContentsImpl* web_contents, 184 WebContentsImpl* web_contents,
181 BrowserContext* browser_context, 185 BrowserContext* browser_context)
182 SessionStorageNamespaceImpl* session_storage_namespace)
183 : browser_context_(browser_context), 186 : browser_context_(browser_context),
184 pending_entry_(NULL), 187 pending_entry_(NULL),
185 last_committed_entry_index_(-1), 188 last_committed_entry_index_(-1),
186 pending_entry_index_(-1), 189 pending_entry_index_(-1),
187 transient_entry_index_(-1), 190 transient_entry_index_(-1),
188 web_contents_(web_contents), 191 web_contents_(web_contents),
189 max_restored_page_id_(-1), 192 max_restored_page_id_(-1),
190 ALLOW_THIS_IN_INITIALIZER_LIST(ssl_manager_(this)), 193 ALLOW_THIS_IN_INITIALIZER_LIST(ssl_manager_(this)),
191 needs_reload_(false), 194 needs_reload_(false),
192 session_storage_namespace_(session_storage_namespace),
193 pending_reload_(NO_RELOAD) { 195 pending_reload_(NO_RELOAD) {
194 DCHECK(browser_context_); 196 DCHECK(browser_context_);
195 if (!session_storage_namespace_) {
196 session_storage_namespace_ = new SessionStorageNamespaceImpl(
197 static_cast<DOMStorageContextImpl*>(
198 BrowserContext::GetDefaultDOMStorageContext(browser_context_)));
199 }
200 } 197 }
201 198
202 NavigationControllerImpl::~NavigationControllerImpl() { 199 NavigationControllerImpl::~NavigationControllerImpl() {
203 DiscardNonCommittedEntriesInternal(); 200 DiscardNonCommittedEntriesInternal();
204 } 201 }
205 202
206 WebContents* NavigationControllerImpl::GetWebContents() const { 203 WebContents* NavigationControllerImpl::GetWebContents() const {
207 return web_contents_; 204 return web_contents_;
208 } 205 }
209 206
(...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after
1123 static_cast<const NavigationControllerImpl&>(temp); 1120 static_cast<const NavigationControllerImpl&>(temp);
1124 // Verify that we look new. 1121 // Verify that we look new.
1125 DCHECK(GetEntryCount() == 0 && !GetPendingEntry()); 1122 DCHECK(GetEntryCount() == 0 && !GetPendingEntry());
1126 1123
1127 if (source.GetEntryCount() == 0) 1124 if (source.GetEntryCount() == 0)
1128 return; // Nothing new to do. 1125 return; // Nothing new to do.
1129 1126
1130 needs_reload_ = true; 1127 needs_reload_ = true;
1131 InsertEntriesFrom(source, source.GetEntryCount()); 1128 InsertEntriesFrom(source, source.GetEntryCount());
1132 1129
1133 session_storage_namespace_ = source.session_storage_namespace_->Clone(); 1130 for (SessionStorageNamespaceMap::const_iterator it =
1131 source.session_storage_namespace_map_.begin();
1132 it != source.session_storage_namespace_map_.end();
1133 ++it) {
1134 SessionStorageNamespaceImpl* source_namespace =
1135 static_cast<SessionStorageNamespaceImpl*>(it->second.get());
1136 session_storage_namespace_map_.insert(
1137 make_pair(it->first, source_namespace->Clone()));
1138 }
1134 1139
1135 FinishRestore(source.last_committed_entry_index_, false); 1140 FinishRestore(source.last_committed_entry_index_, false);
1136 1141
1137 // Copy the max page id map from the old tab to the new tab. This ensures 1142 // Copy the max page id map from the old tab to the new tab. This ensures
1138 // that new and existing navigations in the tab's current SiteInstances 1143 // that new and existing navigations in the tab's current SiteInstances
1139 // are identified properly. 1144 // are identified properly.
1140 web_contents_->CopyMaxPageIDsFrom(source.web_contents()); 1145 web_contents_->CopyMaxPageIDsFrom(source.web_contents());
1141 } 1146 }
1142 1147
1143 void NavigationControllerImpl::CopyStateFromAndPrune( 1148 void NavigationControllerImpl::CopyStateFromAndPrune(
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1244 1249
1245 if (web_contents_->GetInterstitialPage()) { 1250 if (web_contents_->GetInterstitialPage()) {
1246 // Normally the interstitial page hides itself if the user doesn't proceeed. 1251 // Normally the interstitial page hides itself if the user doesn't proceeed.
1247 // This would result in showing a NavigationEntry we just removed. Set this 1252 // This would result in showing a NavigationEntry we just removed. Set this
1248 // so the interstitial triggers a reload if the user doesn't proceed. 1253 // so the interstitial triggers a reload if the user doesn't proceed.
1249 static_cast<InterstitialPageImpl*>(web_contents_->GetInterstitialPage())-> 1254 static_cast<InterstitialPageImpl*>(web_contents_->GetInterstitialPage())->
1250 set_reload_on_dont_proceed(true); 1255 set_reload_on_dont_proceed(true);
1251 } 1256 }
1252 } 1257 }
1253 1258
1259 void NavigationControllerImpl::SetSessionStorageNamespace(
1260 const std::string& partition_id,
1261 content::SessionStorageNamespace* session_storage_namespace) {
1262 if (!session_storage_namespace)
1263 return;
1264
1265 // We can't overwrite an existing SessionStorage without violating spec.
1266 // Attempts to do so may give a tab access to another tab's session storage
1267 // so die hard on an error.
1268 bool successful_insert = session_storage_namespace_map_.insert(
1269 make_pair(partition_id,
1270 static_cast<SessionStorageNamespaceImpl*>(
1271 session_storage_namespace)))
1272 .second;
1273 CHECK(successful_insert) << "Cannot replace existing SessionStorageNamespace";
1274 }
1275
1254 void NavigationControllerImpl::SetMaxRestoredPageID(int32 max_id) { 1276 void NavigationControllerImpl::SetMaxRestoredPageID(int32 max_id) {
1255 max_restored_page_id_ = max_id; 1277 max_restored_page_id_ = max_id;
1256 } 1278 }
1257 1279
1258 int32 NavigationControllerImpl::GetMaxRestoredPageID() const { 1280 int32 NavigationControllerImpl::GetMaxRestoredPageID() const {
1259 return max_restored_page_id_; 1281 return max_restored_page_id_;
1260 } 1282 }
1261 1283
1262 SessionStorageNamespace* 1284 SessionStorageNamespace*
1263 NavigationControllerImpl::GetSessionStorageNamespace() const { 1285 NavigationControllerImpl::GetSessionStorageNamespace(
1264 return session_storage_namespace_; 1286 content::SiteInstance* instance) {
1287 std::string partition_id;
1288 if (instance) {
1289 // TODO(ajwong): When GetDefaultSessionStorageNamespace() goes away, remove
1290 // this if statement so |instance| must not be NULL.
1291 partition_id =
1292 GetContentClient()->browser()->GetStoragePartitionIdForSiteInstance(
1293 browser_context_, instance);
1294 }
1295
1296 SessionStorageNamespaceMap::const_iterator it =
1297 session_storage_namespace_map_.find(partition_id);
1298 if (it != session_storage_namespace_map_.end())
1299 return it->second.get();
1300
1301 // Create one if no one has accessed session storage for this partition yet.
1302 SessionStorageNamespaceImpl* session_storage_namespace =
1303 new SessionStorageNamespaceImpl(
1304 static_cast<DOMStorageContextImpl*>(
1305 BrowserContext::GetDOMStorageContextByPartitionId(
1306 browser_context_, partition_id)));
1307 session_storage_namespace_map_[partition_id] = session_storage_namespace;
1308
1309 return session_storage_namespace;
1310 }
1311
1312 SessionStorageNamespace*
1313 NavigationControllerImpl::GetDefaultSessionStorageNamespace() {
1314 // TODO(ajwong): Remove if statement in GetSessionStorageNamespace().
1315 return GetSessionStorageNamespace(NULL);
1316 }
1317
1318 const SessionStorageNamespaceMap&
1319 NavigationControllerImpl::GetSessionStorageNamespaceMap() const {
1320 return session_storage_namespace_map_;
1265 } 1321 }
1266 1322
1267 bool NavigationControllerImpl::NeedsReload() const { 1323 bool NavigationControllerImpl::NeedsReload() const {
1268 return needs_reload_; 1324 return needs_reload_;
1269 } 1325 }
1270 1326
1271 void NavigationControllerImpl::RemoveEntryAtIndexInternal(int index) { 1327 void NavigationControllerImpl::RemoveEntryAtIndexInternal(int index) {
1272 DCHECK(index < GetEntryCount()); 1328 DCHECK(index < GetEntryCount());
1273 DCHECK(index != last_committed_entry_index_); 1329 DCHECK(index != last_committed_entry_index_);
1274 1330
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
1515 for (int i = 0; i < max_index; i++) { 1571 for (int i = 0; i < max_index; i++) {
1516 // When cloning a tab, copy all entries except interstitial pages 1572 // When cloning a tab, copy all entries except interstitial pages
1517 if (source.entries_[i].get()->GetPageType() != 1573 if (source.entries_[i].get()->GetPageType() !=
1518 content::PAGE_TYPE_INTERSTITIAL) { 1574 content::PAGE_TYPE_INTERSTITIAL) {
1519 entries_.insert(entries_.begin() + insert_index++, 1575 entries_.insert(entries_.begin() + insert_index++,
1520 linked_ptr<NavigationEntryImpl>( 1576 linked_ptr<NavigationEntryImpl>(
1521 new NavigationEntryImpl(*source.entries_[i]))); 1577 new NavigationEntryImpl(*source.entries_[i])));
1522 } 1578 }
1523 } 1579 }
1524 } 1580 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698