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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 if (IPC_MESSAGE_CLASS(message) != DOMStorageMsgStart) | 75 if (IPC_MESSAGE_CLASS(message) != DOMStorageMsgStart) |
76 return false; | 76 return false; |
77 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); | 77 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); |
78 DCHECK(host_.get()); | 78 DCHECK(host_.get()); |
79 | 79 |
80 bool handled = true; | 80 bool handled = true; |
81 IPC_BEGIN_MESSAGE_MAP_EX(DOMStorageMessageFilter, message, *message_was_ok) | 81 IPC_BEGIN_MESSAGE_MAP_EX(DOMStorageMessageFilter, message, *message_was_ok) |
82 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_OpenStorageArea, OnOpenStorageArea) | 82 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_OpenStorageArea, OnOpenStorageArea) |
83 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_CloseStorageArea, OnCloseStorageArea) | 83 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_CloseStorageArea, OnCloseStorageArea) |
84 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_LoadStorageArea, OnLoadStorageArea) | 84 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_LoadStorageArea, OnLoadStorageArea) |
85 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_Length, OnLength) | |
86 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_Key, OnKey) | |
87 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_GetItem, OnGetItem) | |
88 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_SetItem, OnSetItem) | 85 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_SetItem, OnSetItem) |
89 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_SetItemAsync, OnSetItemAsync) | |
90 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_RemoveItem, OnRemoveItem) | 86 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_RemoveItem, OnRemoveItem) |
91 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_RemoveItemAsync, OnRemoveItemAsync) | |
92 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_Clear, OnClear) | 87 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_Clear, OnClear) |
93 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_ClearAsync, OnClearAsync) | 88 IPC_MESSAGE_HANDLER(DOMStorageHostMsg_FlushMessages, OnFlushMessages) |
94 IPC_MESSAGE_UNHANDLED(handled = false) | 89 IPC_MESSAGE_UNHANDLED(handled = false) |
95 IPC_END_MESSAGE_MAP() | 90 IPC_END_MESSAGE_MAP() |
96 return handled; | 91 return handled; |
97 } | 92 } |
98 | 93 |
99 void DOMStorageMessageFilter::OnOpenStorageArea(int connection_id, | 94 void DOMStorageMessageFilter::OnOpenStorageArea(int connection_id, |
100 int64 namespace_id, | 95 int64 namespace_id, |
101 const GURL& origin) { | 96 const GURL& origin) { |
102 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); | 97 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); |
103 if (!host_->OpenStorageArea(connection_id, namespace_id, origin)) { | 98 if (!host_->OpenStorageArea(connection_id, namespace_id, origin)) { |
104 content::RecordAction(UserMetricsAction("BadMessageTerminate_DSMF_1")); | 99 content::RecordAction(UserMetricsAction("BadMessageTerminate_DSMF_1")); |
105 BadMessageReceived(); | 100 BadMessageReceived(); |
106 } | 101 } |
107 } | 102 } |
108 | 103 |
109 void DOMStorageMessageFilter::OnCloseStorageArea(int connection_id) { | 104 void DOMStorageMessageFilter::OnCloseStorageArea(int connection_id) { |
110 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); | 105 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); |
111 host_->CloseStorageArea(connection_id); | 106 host_->CloseStorageArea(connection_id); |
112 } | 107 } |
113 | 108 |
114 void DOMStorageMessageFilter::OnLoadStorageArea(int connection_id, | 109 void DOMStorageMessageFilter::OnLoadStorageArea(int connection_id, |
115 dom_storage::ValuesMap* map) { | 110 dom_storage::ValuesMap* map) { |
116 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); | 111 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); |
117 if (!host_->ExtractAreaValues(connection_id, map)) { | 112 if (!host_->ExtractAreaValues(connection_id, map)) { |
118 content::RecordAction(UserMetricsAction("BadMessageTerminate_DSMF_2")); | 113 content::RecordAction(UserMetricsAction("BadMessageTerminate_DSMF_2")); |
119 BadMessageReceived(); | 114 BadMessageReceived(); |
120 } | 115 } |
121 } | 116 Send(new DOMStorageMsg_AsyncOperationComplete(true)); |
122 | |
123 void DOMStorageMessageFilter::OnLength(int connection_id, | |
124 unsigned* length) { | |
125 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
126 *length = host_->GetAreaLength(connection_id); | |
127 } | |
128 | |
129 void DOMStorageMessageFilter::OnKey(int connection_id, unsigned index, | |
130 NullableString16* key) { | |
131 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
132 *key = host_->GetAreaKey(connection_id, index); | |
133 } | |
134 | |
135 void DOMStorageMessageFilter::OnGetItem(int connection_id, | |
136 const string16& key, | |
137 NullableString16* value) { | |
138 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
139 *value = host_->GetAreaItem(connection_id, key); | |
140 } | 117 } |
141 | 118 |
142 void DOMStorageMessageFilter::OnSetItem( | 119 void DOMStorageMessageFilter::OnSetItem( |
143 int connection_id, const string16& key, | 120 int connection_id, const string16& key, |
144 const string16& value, const GURL& page_url, | |
145 WebKit::WebStorageArea::Result* result, NullableString16* old_value) { | |
146 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
147 DCHECK_EQ(0, connection_dispatching_message_for_); | |
148 AutoReset<int> auto_reset(&connection_dispatching_message_for_, | |
149 connection_id); | |
150 *old_value = NullableString16(true); | |
151 if (host_->SetAreaItem(connection_id, key, value, page_url, old_value)) | |
152 *result = WebKit::WebStorageArea::ResultOK; | |
153 else | |
154 *result = WebKit::WebStorageArea::ResultBlockedByQuota; | |
155 } | |
156 | |
157 void DOMStorageMessageFilter::OnSetItemAsync( | |
158 int connection_id, int operation_id, const string16& key, | |
159 const string16& value, const GURL& page_url) { | 121 const string16& value, const GURL& page_url) { |
160 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); | 122 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); |
161 DCHECK_EQ(0, connection_dispatching_message_for_); | 123 DCHECK_EQ(0, connection_dispatching_message_for_); |
162 AutoReset<int> auto_reset(&connection_dispatching_message_for_, | 124 AutoReset<int> auto_reset(&connection_dispatching_message_for_, |
163 connection_id); | 125 connection_id); |
164 NullableString16 not_used; | 126 NullableString16 not_used; |
165 bool success = host_->SetAreaItem(connection_id, key, value, | 127 bool success = host_->SetAreaItem(connection_id, key, value, |
166 page_url, ¬_used); | 128 page_url, ¬_used); |
167 Send(new DOMStorageMsg_AsyncOperationComplete(operation_id, success)); | 129 Send(new DOMStorageMsg_AsyncOperationComplete(success)); |
168 } | 130 } |
169 | 131 |
170 void DOMStorageMessageFilter::OnRemoveItem( | 132 void DOMStorageMessageFilter::OnRemoveItem( |
171 int connection_id, const string16& key, const GURL& page_url, | 133 int connection_id, const string16& key, |
172 NullableString16* old_value) { | |
173 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
174 DCHECK_EQ(0, connection_dispatching_message_for_); | |
175 AutoReset<int> auto_reset(&connection_dispatching_message_for_, | |
176 connection_id); | |
177 string16 old_string_value; | |
178 if (host_->RemoveAreaItem(connection_id, key, page_url, &old_string_value)) | |
179 *old_value = NullableString16(old_string_value, false); | |
180 else | |
181 *old_value = NullableString16(true); | |
182 } | |
183 | |
184 void DOMStorageMessageFilter::OnRemoveItemAsync( | |
185 int connection_id, int operation_id, const string16& key, | |
186 const GURL& page_url) { | 134 const GURL& page_url) { |
187 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); | 135 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); |
188 DCHECK_EQ(0, connection_dispatching_message_for_); | 136 DCHECK_EQ(0, connection_dispatching_message_for_); |
189 AutoReset<int> auto_reset(&connection_dispatching_message_for_, | 137 AutoReset<int> auto_reset(&connection_dispatching_message_for_, |
190 connection_id); | 138 connection_id); |
191 string16 not_used; | 139 string16 not_used; |
192 host_->RemoveAreaItem(connection_id, key, page_url, ¬_used); | 140 host_->RemoveAreaItem(connection_id, key, page_url, ¬_used); |
193 Send(new DOMStorageMsg_AsyncOperationComplete(operation_id, true)); | 141 Send(new DOMStorageMsg_AsyncOperationComplete(true)); |
194 } | 142 } |
195 | 143 |
196 void DOMStorageMessageFilter::OnClear(int connection_id, const GURL& page_url, | 144 void DOMStorageMessageFilter::OnClear( |
197 bool* something_cleared) { | 145 int connection_id, const GURL& page_url) { |
198 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
199 DCHECK_EQ(0, connection_dispatching_message_for_); | |
200 AutoReset<int> auto_reset(&connection_dispatching_message_for_, | |
201 connection_id); | |
202 *something_cleared = host_->ClearArea(connection_id, page_url); | |
203 } | |
204 | |
205 void DOMStorageMessageFilter::OnClearAsync( | |
206 int connection_id, int operation_id, const GURL& page_url) { | |
207 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); | 146 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); |
208 DCHECK_EQ(0, connection_dispatching_message_for_); | 147 DCHECK_EQ(0, connection_dispatching_message_for_); |
209 AutoReset<int> auto_reset(&connection_dispatching_message_for_, | 148 AutoReset<int> auto_reset(&connection_dispatching_message_for_, |
210 connection_id); | 149 connection_id); |
211 host_->ClearArea(connection_id, page_url); | 150 host_->ClearArea(connection_id, page_url); |
212 Send(new DOMStorageMsg_AsyncOperationComplete(operation_id, true)); | 151 Send(new DOMStorageMsg_AsyncOperationComplete(true)); |
| 152 } |
| 153 |
| 154 void DOMStorageMessageFilter::OnFlushMessages() { |
| 155 // Intentionally empty method body. |
213 } | 156 } |
214 | 157 |
215 void DOMStorageMessageFilter::OnDomStorageItemSet( | 158 void DOMStorageMessageFilter::OnDomStorageItemSet( |
216 const dom_storage::DomStorageArea* area, | 159 const dom_storage::DomStorageArea* area, |
217 const string16& key, | 160 const string16& key, |
218 const string16& new_value, | 161 const string16& new_value, |
219 const NullableString16& old_value, | 162 const NullableString16& old_value, |
220 const GURL& page_url) { | 163 const GURL& page_url) { |
221 SendDomStorageEvent(area, page_url, | 164 SendDomStorageEvent(area, page_url, |
222 NullableString16(key, false), | 165 NullableString16(key, false), |
(...skipping 21 matching lines...) Expand all Loading... |
244 NullableString16(true)); | 187 NullableString16(true)); |
245 } | 188 } |
246 | 189 |
247 void DOMStorageMessageFilter::SendDomStorageEvent( | 190 void DOMStorageMessageFilter::SendDomStorageEvent( |
248 const dom_storage::DomStorageArea* area, | 191 const dom_storage::DomStorageArea* area, |
249 const GURL& page_url, | 192 const GURL& page_url, |
250 const NullableString16& key, | 193 const NullableString16& key, |
251 const NullableString16& new_value, | 194 const NullableString16& new_value, |
252 const NullableString16& old_value) { | 195 const NullableString16& old_value) { |
253 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); | 196 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); |
254 if (area->namespace_id() != dom_storage::kLocalStorageNamespaceId && | 197 // Only send mutation events to processes which have the area open. |
255 !connection_dispatching_message_for_) { | 198 bool originated_in_process = connection_dispatching_message_for_ != 0; |
256 return; // No need to broadcast session storage events across processes. | 199 if (originated_in_process || |
| 200 host_->HasAreaOpen(area->namespace_id(), area->origin())) { |
| 201 DOMStorageMsg_Event_Params params; |
| 202 params.origin = area->origin(); |
| 203 params.page_url = page_url; |
| 204 params.connection_id = connection_dispatching_message_for_; |
| 205 params.key = key; |
| 206 params.new_value = new_value; |
| 207 params.old_value = old_value; |
| 208 params.namespace_id = area->namespace_id(); |
| 209 Send(new DOMStorageMsg_Event(params)); |
257 } | 210 } |
258 DOMStorageMsg_Event_Params params; | |
259 params.origin = area->origin(); | |
260 params.page_url = page_url; | |
261 params.connection_id = connection_dispatching_message_for_; | |
262 params.key = key; | |
263 params.new_value = new_value; | |
264 params.old_value = old_value; | |
265 params.namespace_id = area->namespace_id(); | |
266 Send(new DOMStorageMsg_Event(params)); | |
267 } | 211 } |
OLD | NEW |