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..00534300cc2c7a1cda3c2b4ea2e3decb8f4d54d5 100644 |
| --- a/content/browser/in_process_webkit/dom_storage_namespace.cc |
| +++ b/content/browser/in_process_webkit/dom_storage_namespace.cc |
| @@ -54,19 +54,29 @@ DOMStorageNamespace::~DOMStorageNamespace() { |
| } |
| } |
| -DOMStorageArea* DOMStorageNamespace::GetStorageArea(const string16& origin) { |
| +DOMStorageArea* DOMStorageNamespace::GetStorageArea( |
| + const string16& origin, |
| + bool enforce_session_only_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.) |
| + 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 (enforce_session_only_storage && ShouldHaveSessionOnlyLocalStorage()) { |
| + EnsureSessionOnlyLocalStorageCreated(); |
| + return session_only_local_storage_->CreateStorageArea(origin); |
| + } |
| + return CreateStorageArea(origin); |
| } |
| DOMStorageNamespace* DOMStorageNamespace::Copy(int64 id) { |
| @@ -107,3 +117,40 @@ 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; |
| +} |
| + |
| +bool DOMStorageNamespace::ShouldHaveSessionOnlyLocalStorage() const { |
| + if (dom_storage_type_ == DOM_STORAGE_LOCAL && !data_dir_path_.isEmpty()) { |
| + // This DOMStorageNamespace represents a permanent localStorage; it should |
| + // have a sibling DOMStorageNamespace that represents the corresponding |
| + // session-only storage. |
| + return true; |
|
michaeln
2011/08/04 20:21:51
maybe simplify as
return (type == LOCAL) && !path.
marja
2011/08/05 13:15:53
Done.
|
| + } |
| + return false; |
| +} |
| + |
| +void DOMStorageNamespace::EnsureSessionOnlyLocalStorageCreated() { |
| + if (session_only_local_storage_.get() == NULL) { |
| + session_only_local_storage_.reset( |
| + new DOMStorageNamespace(dom_storage_context_, |
| + id_, |
| + WebString(), |
| + dom_storage_type_)); |
| + } |
| +} |