| OLD | NEW |
| 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 "webkit/dom_storage/dom_storage_host.h" | 5 #include "webkit/dom_storage/dom_storage_host.h" |
| 6 | 6 |
| 7 #include "googleurl/src/gurl.h" | 7 #include "googleurl/src/gurl.h" |
| 8 #include "webkit/dom_storage/dom_storage_area.h" | 8 #include "webkit/dom_storage/dom_storage_area.h" |
| 9 #include "webkit/dom_storage/dom_storage_context.h" | 9 #include "webkit/dom_storage/dom_storage_context.h" |
| 10 #include "webkit/dom_storage/dom_storage_namespace.h" | 10 #include "webkit/dom_storage/dom_storage_namespace.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 connections_.clear(); // Clear prior to releasing the context_ | 23 connections_.clear(); // Clear prior to releasing the context_ |
| 24 } | 24 } |
| 25 | 25 |
| 26 bool DomStorageHost::OpenStorageArea(int connection_id, int namespace_id, | 26 bool DomStorageHost::OpenStorageArea(int connection_id, int namespace_id, |
| 27 const GURL& origin) { | 27 const GURL& origin) { |
| 28 DCHECK(!GetOpenArea(connection_id)); | 28 DCHECK(!GetOpenArea(connection_id)); |
| 29 if (GetOpenArea(connection_id)) | 29 if (GetOpenArea(connection_id)) |
| 30 return false; // Indicates the renderer gave us very bad data. | 30 return false; // Indicates the renderer gave us very bad data. |
| 31 NamespaceAndArea references; | 31 NamespaceAndArea references; |
| 32 references.namespace_ = context_->GetStorageNamespace(namespace_id); | 32 references.namespace_ = context_->GetStorageNamespace(namespace_id); |
| 33 if (!references.namespace_) | 33 if (!references.namespace_) { |
| 34 return true; // TODO(michaeln): investigate returning false here | 34 // TODO(michaeln): Fix crbug/134003 and return false here. |
| 35 // Until then return true to avoid crashing the renderer for |
| 36 // sending a bad message. |
| 37 return true; |
| 38 } |
| 35 references.area_ = references.namespace_->OpenStorageArea(origin); | 39 references.area_ = references.namespace_->OpenStorageArea(origin); |
| 36 DCHECK(references.area_); | 40 DCHECK(references.area_); |
| 37 connections_[connection_id] = references; | 41 connections_[connection_id] = references; |
| 38 return true; | 42 return true; |
| 39 } | 43 } |
| 40 | 44 |
| 41 void DomStorageHost::CloseStorageArea(int connection_id) { | 45 void DomStorageHost::CloseStorageArea(int connection_id) { |
| 42 AreaMap::iterator found = connections_.find(connection_id); | 46 AreaMap::iterator found = connections_.find(connection_id); |
| 43 if (found == connections_.end()) | 47 if (found == connections_.end()) |
| 44 return; | 48 return; |
| 45 found->second.namespace_->CloseStorageArea( | 49 found->second.namespace_->CloseStorageArea( |
| 46 found->second.area_); | 50 found->second.area_); |
| 47 connections_.erase(found); | 51 connections_.erase(found); |
| 48 } | 52 } |
| 49 | 53 |
| 50 bool DomStorageHost::ExtractAreaValues( | 54 bool DomStorageHost::ExtractAreaValues( |
| 51 int connection_id, ValuesMap* map) { | 55 int connection_id, ValuesMap* map) { |
| 52 map->clear(); | 56 map->clear(); |
| 53 AreaMap::iterator found = connections_.find(connection_id); | 57 DomStorageArea* area = GetOpenArea(connection_id); |
| 54 if (found == connections_.end()) | 58 if (!area) { |
| 55 return false; // Indicates the renderer gave us very bad data. | 59 // TODO(michaeln): Fix crbug/134003 and return false here. |
| 56 found->second.area_->ExtractValues(map); | 60 // Until then return true to avoid crashing the renderer |
| 61 // for sending a bad message. |
| 62 return true; |
| 63 } |
| 64 area->ExtractValues(map); |
| 57 return true; | 65 return true; |
| 58 } | 66 } |
| 59 | 67 |
| 60 unsigned DomStorageHost::GetAreaLength(int connection_id) { | 68 unsigned DomStorageHost::GetAreaLength(int connection_id) { |
| 61 DomStorageArea* area = GetOpenArea(connection_id); | 69 DomStorageArea* area = GetOpenArea(connection_id); |
| 62 if (!area) | 70 if (!area) |
| 63 return 0; | 71 return 0; |
| 64 return area->Length(); | 72 return area->Length(); |
| 65 } | 73 } |
| 66 | 74 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 77 if (!area) | 85 if (!area) |
| 78 return NullableString16(true); | 86 return NullableString16(true); |
| 79 return area->GetItem(key); | 87 return area->GetItem(key); |
| 80 } | 88 } |
| 81 | 89 |
| 82 bool DomStorageHost::SetAreaItem( | 90 bool DomStorageHost::SetAreaItem( |
| 83 int connection_id, const string16& key, | 91 int connection_id, const string16& key, |
| 84 const string16& value, const GURL& page_url, | 92 const string16& value, const GURL& page_url, |
| 85 NullableString16* old_value) { | 93 NullableString16* old_value) { |
| 86 DomStorageArea* area = GetOpenArea(connection_id); | 94 DomStorageArea* area = GetOpenArea(connection_id); |
| 87 if (!area) | 95 if (!area) { |
| 88 return false; | 96 // TODO(michaeln): Fix crbug/134003 and return false here. |
| 97 // Until then return true to allow the renderer to operate |
| 98 // to a limited degree out of its cache. |
| 99 return true; |
| 100 } |
| 89 if (!area->SetItem(key, value, old_value)) | 101 if (!area->SetItem(key, value, old_value)) |
| 90 return false; | 102 return false; |
| 91 if (old_value->is_null() || old_value->string() != value) | 103 if (old_value->is_null() || old_value->string() != value) |
| 92 context_->NotifyItemSet(area, key, value, *old_value, page_url); | 104 context_->NotifyItemSet(area, key, value, *old_value, page_url); |
| 93 return true; | 105 return true; |
| 94 } | 106 } |
| 95 | 107 |
| 96 bool DomStorageHost::RemoveAreaItem( | 108 bool DomStorageHost::RemoveAreaItem( |
| 97 int connection_id, const string16& key, const GURL& page_url, | 109 int connection_id, const string16& key, const GURL& page_url, |
| 98 string16* old_value) { | 110 string16* old_value) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 return NULL; | 145 return NULL; |
| 134 return found->second.area_; | 146 return found->second.area_; |
| 135 } | 147 } |
| 136 | 148 |
| 137 // NamespaceAndArea | 149 // NamespaceAndArea |
| 138 | 150 |
| 139 DomStorageHost::NamespaceAndArea::NamespaceAndArea() {} | 151 DomStorageHost::NamespaceAndArea::NamespaceAndArea() {} |
| 140 DomStorageHost::NamespaceAndArea::~NamespaceAndArea() {} | 152 DomStorageHost::NamespaceAndArea::~NamespaceAndArea() {} |
| 141 | 153 |
| 142 } // namespace dom_storage | 154 } // namespace dom_storage |
| OLD | NEW |