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 "content/browser/dom_storage/dom_storage_message_filter.h" | 5 #include "content/browser/dom_storage/dom_storage_message_filter.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/nullable_string16.h" | 9 #include "base/nullable_string16.h" |
10 #include "base/threading/sequenced_worker_pool.h" | 10 #include "base/threading/sequenced_worker_pool.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 DCHECK_EQ(0, connection_dispatching_message_for_); | 79 DCHECK_EQ(0, connection_dispatching_message_for_); |
80 | 80 |
81 // The connection_id is always the first param. | 81 // The connection_id is always the first param. |
82 int connection_id = IPC::MessageIterator(message).NextInt(); | 82 int connection_id = IPC::MessageIterator(message).NextInt(); |
83 AutoReset<int> auto_reset(&connection_dispatching_message_for_, | 83 AutoReset<int> auto_reset(&connection_dispatching_message_for_, |
84 connection_id); | 84 connection_id); |
85 bool handled = true; | 85 bool handled = true; |
86 IPC_BEGIN_MESSAGE_MAP_EX(DOMStorageMessageFilter, message, *message_was_ok) | 86 IPC_BEGIN_MESSAGE_MAP_EX(DOMStorageMessageFilter, message, *message_was_ok) |
87 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_OpenStorageArea, OnOpenStorageArea) | 87 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_OpenStorageArea, OnOpenStorageArea) |
88 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_CloseStorageArea, OnCloseStorageArea) | 88 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_CloseStorageArea, OnCloseStorageArea) |
| 89 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_LoadStorageArea, OnLoadStorageArea) |
89 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_Length, OnLength) | 90 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_Length, OnLength) |
90 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_Key, OnKey) | 91 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_Key, OnKey) |
91 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_GetItem, OnGetItem) | 92 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_GetItem, OnGetItem) |
92 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_SetItem, OnSetItem) | 93 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_SetItem, OnSetItem) |
| 94 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_SetItemAsync, OnSetItemAsync) |
93 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_RemoveItem, OnRemoveItem) | 95 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_RemoveItem, OnRemoveItem) |
| 96 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_RemoveItemAsync, OnRemoveItemAsync) |
94 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_Clear, OnClear) | 97 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_Clear, OnClear) |
| 98 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_ClearAsync, OnClearAsync) |
95 IPC_MESSAGE_UNHANDLED(handled = false) | 99 IPC_MESSAGE_UNHANDLED(handled = false) |
96 IPC_END_MESSAGE_MAP() | 100 IPC_END_MESSAGE_MAP() |
97 return handled; | 101 return handled; |
98 } | 102 } |
99 | 103 |
100 void DOMStorageMessageFilter::OnOpenStorageArea(int connection_id, | 104 void DOMStorageMessageFilter::OnOpenStorageArea(int connection_id, |
101 int64 namespace_id, | 105 int64 namespace_id, |
102 const GURL& origin) { | 106 const GURL& origin) { |
103 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); | 107 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); |
104 if (!host_->OpenStorageArea(connection_id, namespace_id, origin)) { | 108 if (!host_->OpenStorageArea(connection_id, namespace_id, origin)) { |
105 content::RecordAction(UserMetricsAction("BadMessageTerminate_DSMF")); | 109 content::RecordAction(UserMetricsAction("BadMessageTerminate_DSMF_1")); |
106 BadMessageReceived(); | 110 BadMessageReceived(); |
107 } | 111 } |
108 } | 112 } |
109 | 113 |
110 void DOMStorageMessageFilter::OnCloseStorageArea(int connection_id) { | 114 void DOMStorageMessageFilter::OnCloseStorageArea(int connection_id) { |
111 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); | 115 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); |
112 host_->CloseStorageArea(connection_id); | 116 host_->CloseStorageArea(connection_id); |
113 } | 117 } |
114 | 118 |
| 119 void DOMStorageMessageFilter::OnLoadStorageArea(int connection_id, |
| 120 dom_storage::ValuesMap* map) { |
| 121 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 122 if (!host_->ExtractAreaValues(connection_id, map)) { |
| 123 content::RecordAction(UserMetricsAction("BadMessageTerminate_DSMF_2")); |
| 124 BadMessageReceived(); |
| 125 } |
| 126 } |
| 127 |
115 void DOMStorageMessageFilter::OnLength(int connection_id, | 128 void DOMStorageMessageFilter::OnLength(int connection_id, |
116 unsigned* length) { | 129 unsigned* length) { |
117 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); | 130 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); |
118 *length = host_->GetAreaLength(connection_id); | 131 *length = host_->GetAreaLength(connection_id); |
119 } | 132 } |
120 | 133 |
121 void DOMStorageMessageFilter::OnKey(int connection_id, unsigned index, | 134 void DOMStorageMessageFilter::OnKey(int connection_id, unsigned index, |
122 NullableString16* key) { | 135 NullableString16* key) { |
123 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); | 136 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); |
124 *key = host_->GetAreaKey(connection_id, index); | 137 *key = host_->GetAreaKey(connection_id, index); |
(...skipping 11 matching lines...) Expand all Loading... |
136 const string16& value, const GURL& page_url, | 149 const string16& value, const GURL& page_url, |
137 WebKit::WebStorageArea::Result* result, NullableString16* old_value) { | 150 WebKit::WebStorageArea::Result* result, NullableString16* old_value) { |
138 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); | 151 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); |
139 *old_value = NullableString16(true); | 152 *old_value = NullableString16(true); |
140 if (host_->SetAreaItem(connection_id, key, value, page_url, old_value)) | 153 if (host_->SetAreaItem(connection_id, key, value, page_url, old_value)) |
141 *result = WebKit::WebStorageArea::ResultOK; | 154 *result = WebKit::WebStorageArea::ResultOK; |
142 else | 155 else |
143 *result = WebKit::WebStorageArea::ResultBlockedByQuota; | 156 *result = WebKit::WebStorageArea::ResultBlockedByQuota; |
144 } | 157 } |
145 | 158 |
| 159 void DOMStorageMessageFilter::OnSetItemAsync( |
| 160 int connection_id, int operation_id, const string16& key, |
| 161 const string16& value, const GURL& page_url) { |
| 162 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 163 NullableString16 not_used; |
| 164 bool success = host_->SetAreaItem(connection_id, key, value, |
| 165 page_url, ¬_used); |
| 166 Send(new DOMStorageMsg_AsyncOperationComplete(operation_id, success)); |
| 167 } |
| 168 |
146 void DOMStorageMessageFilter::OnRemoveItem( | 169 void DOMStorageMessageFilter::OnRemoveItem( |
147 int connection_id, const string16& key, const GURL& pageUrl, | 170 int connection_id, const string16& key, const GURL& page_url, |
148 NullableString16* old_value) { | 171 NullableString16* old_value) { |
149 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); | 172 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); |
150 string16 old_string_value; | 173 string16 old_string_value; |
151 if (host_->RemoveAreaItem(connection_id, key, pageUrl, &old_string_value)) | 174 if (host_->RemoveAreaItem(connection_id, key, page_url, &old_string_value)) |
152 *old_value = NullableString16(old_string_value, false); | 175 *old_value = NullableString16(old_string_value, false); |
153 else | 176 else |
154 *old_value = NullableString16(true); | 177 *old_value = NullableString16(true); |
155 } | 178 } |
156 | 179 |
| 180 void DOMStorageMessageFilter::OnRemoveItemAsync( |
| 181 int connection_id, int operation_id, const string16& key, |
| 182 const GURL& page_url) { |
| 183 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 184 string16 not_used; |
| 185 host_->RemoveAreaItem(connection_id, key, page_url, ¬_used); |
| 186 Send(new DOMStorageMsg_AsyncOperationComplete(operation_id, true)); |
| 187 } |
| 188 |
157 void DOMStorageMessageFilter::OnClear(int connection_id, const GURL& page_url, | 189 void DOMStorageMessageFilter::OnClear(int connection_id, const GURL& page_url, |
158 bool* something_cleared) { | 190 bool* something_cleared) { |
159 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); | 191 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); |
160 *something_cleared = host_->ClearArea(connection_id, page_url); | 192 *something_cleared = host_->ClearArea(connection_id, page_url); |
161 } | 193 } |
162 | 194 |
| 195 void DOMStorageMessageFilter::OnClearAsync( |
| 196 int connection_id, int operation_id, const GURL& page_url) { |
| 197 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 198 host_->ClearArea(connection_id, page_url); |
| 199 Send(new DOMStorageMsg_AsyncOperationComplete(operation_id, true)); |
| 200 } |
| 201 |
163 void DOMStorageMessageFilter::OnDomStorageItemSet( | 202 void DOMStorageMessageFilter::OnDomStorageItemSet( |
164 const dom_storage::DomStorageArea* area, | 203 const dom_storage::DomStorageArea* area, |
165 const string16& key, | 204 const string16& key, |
166 const string16& new_value, | 205 const string16& new_value, |
167 const NullableString16& old_value, | 206 const NullableString16& old_value, |
168 const GURL& page_url) { | 207 const GURL& page_url) { |
169 SendDomStorageEvent(area, page_url, | 208 SendDomStorageEvent(area, page_url, |
170 NullableString16(key, false), | 209 NullableString16(key, false), |
171 NullableString16(new_value, false), | 210 NullableString16(new_value, false), |
172 old_value); | 211 old_value); |
(...skipping 28 matching lines...) Expand all Loading... |
201 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); | 240 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); |
202 DOMStorageMsg_Event_Params params; | 241 DOMStorageMsg_Event_Params params; |
203 params.origin = area->origin(); | 242 params.origin = area->origin(); |
204 params.page_url = page_url; | 243 params.page_url = page_url; |
205 params.connection_id = connection_dispatching_message_for_; | 244 params.connection_id = connection_dispatching_message_for_; |
206 params.key = key; | 245 params.key = key; |
207 params.new_value = new_value; | 246 params.new_value = new_value; |
208 params.old_value = old_value; | 247 params.old_value = old_value; |
209 Send(new DOMStorageMsg_Event(params)); | 248 Send(new DOMStorageMsg_Event(params)); |
210 } | 249 } |
OLD | NEW |