Chromium Code Reviews| Index: content/browser/in_process_webkit/dom_storage_namespace.cc |
| diff --git a/content/browser/in_process_webkit/dom_storage_namespace.cc b/content/browser/in_process_webkit/dom_storage_namespace.cc |
| index 508786f1aaf58d7d8ba23b01793775028de8a052..a4b49a475b0a9ffe2cc69fd2f22d2d1a7d41d282 100644 |
| --- a/content/browser/in_process_webkit/dom_storage_namespace.cc |
| +++ b/content/browser/in_process_webkit/dom_storage_namespace.cc |
| @@ -41,6 +41,15 @@ DOMStorageNamespace::DOMStorageNamespace(DOMStorageContext* dom_storage_context, |
| id_(id), |
| data_dir_path_(data_dir_path), |
| dom_storage_type_(dom_storage_type) { |
| + if (dom_storage_type == DOM_STORAGE_LOCAL && !data_dir_path.isEmpty()) { |
| + // This DOMStorageNamespace represents a permanent localStorage; create a |
| + // sibling namespace that represents the corresponding session-only storage. |
| + session_only_local_storage_.reset( |
|
michaeln
2011/08/02 19:47:41
can this be more lazily created, i imagine most us
marja
2011/08/03 09:14:15
Done.
|
| + new DOMStorageNamespace(dom_storage_context, |
| + id, |
| + WebString(), |
| + dom_storage_type)); |
| + } |
| DCHECK(dom_storage_context_); |
| } |
| @@ -54,19 +63,28 @@ DOMStorageNamespace::~DOMStorageNamespace() { |
| } |
| } |
| -DOMStorageArea* DOMStorageNamespace::GetStorageArea(const string16& origin) { |
| +DOMStorageArea* DOMStorageNamespace::GetStorageArea( |
| + const string16& origin, |
| + bool allow_permanent_storage) { |
| // We may have already created it for another dispatcher host. |
| - OriginToStorageAreaMap::iterator iter = origin_to_storage_area_.find(origin); |
| - if (iter != origin_to_storage_area_.end()) |
| - return iter->second; |
| + DOMStorageArea* storage_area = GetExistingStorageArea(origin); |
| + if (storage_area) |
| + return storage_area; |
| - // We need to create a new one. |
| - int64 id = dom_storage_context_->AllocateStorageAreaId(); |
| - DCHECK(!dom_storage_context_->GetStorageArea(id)); |
| - DOMStorageArea* storage_area = new DOMStorageArea(origin, id, this); |
| - origin_to_storage_area_[origin] = storage_area; |
| - dom_storage_context_->RegisterStorageArea(storage_area); |
| - return storage_area; |
| + // Also, our session-only sibling might have it. (This is independent of what |
| + // the content settings say; it might be that the settings were changed after |
| + // the DOMStorageArea was created.) |
|
michaeln
2011/08/02 19:47:41
This blurs the lines between the sessionOnly and l
marja
2011/08/03 09:14:15
I guess that would confuse some web pages, if the
|
| + if (session_only_local_storage_.get()) { |
| + storage_area = session_only_local_storage_->GetExistingStorageArea(origin); |
| + if (storage_area) |
| + return storage_area; |
| + } |
| + |
| + // Else, we need to create a new DOMStorageArea. |
| + if (!allow_permanent_storage && session_only_local_storage_.get()) { |
| + return session_only_local_storage_->CreateStorageArea(origin); |
| + } |
| + return CreateStorageArea(origin); |
| } |
| DOMStorageNamespace* DOMStorageNamespace::Copy(int64 id) { |
| @@ -107,3 +125,20 @@ void DOMStorageNamespace::CreateWebStorageNamespaceIfNecessary() { |
| WebStorageNamespace::m_sessionStorageQuota)); |
| } |
| } |
| + |
| +DOMStorageArea* DOMStorageNamespace::GetExistingStorageArea( |
| + const string16& origin) { |
| + OriginToStorageAreaMap::iterator iter = origin_to_storage_area_.find(origin); |
| + if (iter != origin_to_storage_area_.end()) |
| + return iter->second; |
| + return NULL; |
| +} |
| + |
| +DOMStorageArea* DOMStorageNamespace::CreateStorageArea(const string16& origin) { |
| + int64 id = dom_storage_context_->AllocateStorageAreaId(); |
| + DCHECK(!dom_storage_context_->GetStorageArea(id)); |
| + DOMStorageArea* storage_area = new DOMStorageArea(origin, id, this); |
| + origin_to_storage_area_[origin] = storage_area; |
| + dom_storage_context_->RegisterStorageArea(storage_area); |
| + return storage_area; |
| +} |