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/strings/nullable_string16.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "base/threading/sequenced_worker_pool.h" | 11 #include "base/threading/sequenced_worker_pool.h" |
12 #include "content/browser/dom_storage/dom_storage_context_impl.h" | 12 #include "content/browser/dom_storage/dom_storage_context_impl.h" |
13 #include "content/common/dom_storage_messages.h" | 13 #include "content/common/dom_storage_messages.h" |
14 #include "content/public/browser/user_metrics.h" | 14 #include "content/public/browser/user_metrics.h" |
15 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
16 #include "webkit/browser/dom_storage/dom_storage_area.h" | 16 #include "webkit/browser/dom_storage/dom_storage_area.h" |
17 #include "webkit/browser/dom_storage/dom_storage_host.h" | 17 #include "webkit/browser/dom_storage/dom_storage_host.h" |
18 #include "webkit/browser/dom_storage/dom_storage_task_runner.h" | 18 #include "webkit/browser/dom_storage/dom_storage_task_runner.h" |
19 | 19 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 Send(new DOMStorageMsg_AsyncOperationComplete(true)); | 115 Send(new DOMStorageMsg_AsyncOperationComplete(true)); |
116 } | 116 } |
117 | 117 |
118 void DOMStorageMessageFilter::OnSetItem( | 118 void DOMStorageMessageFilter::OnSetItem( |
119 int connection_id, const string16& key, | 119 int connection_id, const string16& key, |
120 const string16& value, const GURL& page_url) { | 120 const string16& value, const GURL& page_url) { |
121 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); | 121 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); |
122 DCHECK_EQ(0, connection_dispatching_message_for_); | 122 DCHECK_EQ(0, connection_dispatching_message_for_); |
123 base::AutoReset<int> auto_reset(&connection_dispatching_message_for_, | 123 base::AutoReset<int> auto_reset(&connection_dispatching_message_for_, |
124 connection_id); | 124 connection_id); |
125 NullableString16 not_used; | 125 base::NullableString16 not_used; |
126 bool success = host_->SetAreaItem(connection_id, key, value, | 126 bool success = host_->SetAreaItem(connection_id, key, value, |
127 page_url, ¬_used); | 127 page_url, ¬_used); |
128 Send(new DOMStorageMsg_AsyncOperationComplete(success)); | 128 Send(new DOMStorageMsg_AsyncOperationComplete(success)); |
129 } | 129 } |
130 | 130 |
131 void DOMStorageMessageFilter::OnRemoveItem( | 131 void DOMStorageMessageFilter::OnRemoveItem( |
132 int connection_id, const string16& key, | 132 int connection_id, const string16& key, |
133 const GURL& page_url) { | 133 const GURL& page_url) { |
134 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); | 134 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); |
135 DCHECK_EQ(0, connection_dispatching_message_for_); | 135 DCHECK_EQ(0, connection_dispatching_message_for_); |
(...skipping 15 matching lines...) Expand all Loading... |
151 } | 151 } |
152 | 152 |
153 void DOMStorageMessageFilter::OnFlushMessages() { | 153 void DOMStorageMessageFilter::OnFlushMessages() { |
154 // Intentionally empty method body. | 154 // Intentionally empty method body. |
155 } | 155 } |
156 | 156 |
157 void DOMStorageMessageFilter::OnDomStorageItemSet( | 157 void DOMStorageMessageFilter::OnDomStorageItemSet( |
158 const dom_storage::DomStorageArea* area, | 158 const dom_storage::DomStorageArea* area, |
159 const string16& key, | 159 const string16& key, |
160 const string16& new_value, | 160 const string16& new_value, |
161 const NullableString16& old_value, | 161 const base::NullableString16& old_value, |
162 const GURL& page_url) { | 162 const GURL& page_url) { |
163 SendDomStorageEvent(area, page_url, | 163 SendDomStorageEvent(area, page_url, |
164 NullableString16(key, false), | 164 base::NullableString16(key, false), |
165 NullableString16(new_value, false), | 165 base::NullableString16(new_value, false), |
166 old_value); | 166 old_value); |
167 } | 167 } |
168 | 168 |
169 void DOMStorageMessageFilter::OnDomStorageItemRemoved( | 169 void DOMStorageMessageFilter::OnDomStorageItemRemoved( |
170 const dom_storage::DomStorageArea* area, | 170 const dom_storage::DomStorageArea* area, |
171 const string16& key, | 171 const string16& key, |
172 const string16& old_value, | 172 const string16& old_value, |
173 const GURL& page_url) { | 173 const GURL& page_url) { |
174 SendDomStorageEvent(area, page_url, | 174 SendDomStorageEvent(area, page_url, |
175 NullableString16(key, false), | 175 base::NullableString16(key, false), |
176 NullableString16(true), | 176 base::NullableString16(true), |
177 NullableString16(old_value, false)); | 177 base::NullableString16(old_value, false)); |
178 } | 178 } |
179 | 179 |
180 void DOMStorageMessageFilter::OnDomStorageAreaCleared( | 180 void DOMStorageMessageFilter::OnDomStorageAreaCleared( |
181 const dom_storage::DomStorageArea* area, | 181 const dom_storage::DomStorageArea* area, |
182 const GURL& page_url) { | 182 const GURL& page_url) { |
183 SendDomStorageEvent(area, page_url, | 183 SendDomStorageEvent(area, page_url, |
184 NullableString16(true), | 184 base::NullableString16(true), |
185 NullableString16(true), | 185 base::NullableString16(true), |
186 NullableString16(true)); | 186 base::NullableString16(true)); |
187 } | 187 } |
188 | 188 |
189 void DOMStorageMessageFilter::SendDomStorageEvent( | 189 void DOMStorageMessageFilter::SendDomStorageEvent( |
190 const dom_storage::DomStorageArea* area, | 190 const dom_storage::DomStorageArea* area, |
191 const GURL& page_url, | 191 const GURL& page_url, |
192 const NullableString16& key, | 192 const base::NullableString16& key, |
193 const NullableString16& new_value, | 193 const base::NullableString16& new_value, |
194 const NullableString16& old_value) { | 194 const base::NullableString16& old_value) { |
195 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); | 195 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO)); |
196 // Only send mutation events to processes which have the area open. | 196 // Only send mutation events to processes which have the area open. |
197 bool originated_in_process = connection_dispatching_message_for_ != 0; | 197 bool originated_in_process = connection_dispatching_message_for_ != 0; |
198 if (originated_in_process || | 198 if (originated_in_process || |
199 host_->HasAreaOpen(area->namespace_id(), area->origin())) { | 199 host_->HasAreaOpen(area->namespace_id(), area->origin())) { |
200 DOMStorageMsg_Event_Params params; | 200 DOMStorageMsg_Event_Params params; |
201 params.origin = area->origin(); | 201 params.origin = area->origin(); |
202 params.page_url = page_url; | 202 params.page_url = page_url; |
203 params.connection_id = connection_dispatching_message_for_; | 203 params.connection_id = connection_dispatching_message_for_; |
204 params.key = key; | 204 params.key = key; |
205 params.new_value = new_value; | 205 params.new_value = new_value; |
206 params.old_value = old_value; | 206 params.old_value = old_value; |
207 params.namespace_id = area->namespace_id(); | 207 params.namespace_id = area->namespace_id(); |
208 Send(new DOMStorageMsg_Event(params)); | 208 Send(new DOMStorageMsg_Event(params)); |
209 } | 209 } |
210 } | 210 } |
211 | 211 |
212 } // namespace content | 212 } // namespace content |
OLD | NEW |