| 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..9c217fd90931779b7ed6be78409e120c08b218b1 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,34 @@ 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 {
|
| + return (dom_storage_type_ == DOM_STORAGE_LOCAL && !data_dir_path_.isEmpty());
|
| +}
|
| +
|
| +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_));
|
| + }
|
| +}
|
|
|