OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
3 // LICENSE file. | 3 // LICENSE file. |
4 | 4 |
5 #include "chrome/browser/in_process_webkit/dom_storage_dispatcher_host.h" | 5 #include "chrome/browser/in_process_webkit/dom_storage_dispatcher_host.h" |
6 | 6 |
7 #include "base/nullable_string16.h" | 7 #include "base/nullable_string16.h" |
8 #include "chrome/browser/chrome_thread.h" | 8 #include "chrome/browser/chrome_thread.h" |
9 #include "chrome/browser/in_process_webkit/dom_storage_area.h" | 9 #include "chrome/browser/in_process_webkit/dom_storage_area.h" |
10 #include "chrome/browser/in_process_webkit/dom_storage_context.h" | 10 #include "chrome/browser/in_process_webkit/dom_storage_context.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 &DOMStorageDispatcherHost::OnStorageEvent, params)); | 105 &DOMStorageDispatcherHost::OnStorageEvent, params)); |
106 } | 106 } |
107 | 107 |
108 bool DOMStorageDispatcherHost::OnMessageReceived(const IPC::Message& message, | 108 bool DOMStorageDispatcherHost::OnMessageReceived(const IPC::Message& message, |
109 bool *msg_is_ok) { | 109 bool *msg_is_ok) { |
110 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | 110 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
111 DCHECK(process_handle_); | 111 DCHECK(process_handle_); |
112 | 112 |
113 bool handled = true; | 113 bool handled = true; |
114 IPC_BEGIN_MESSAGE_MAP_EX(DOMStorageDispatcherHost, message, *msg_is_ok) | 114 IPC_BEGIN_MESSAGE_MAP_EX(DOMStorageDispatcherHost, message, *msg_is_ok) |
115 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_DOMStorageNamespaceId, | |
116 OnNamespaceId) | |
117 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_DOMStorageCloneNamespaceId, | |
118 OnCloneNamespaceId) | |
119 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_DOMStorageStorageAreaId, | 115 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_DOMStorageStorageAreaId, |
120 OnStorageAreaId) | 116 OnStorageAreaId) |
121 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_DOMStorageLength, OnLength) | 117 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_DOMStorageLength, OnLength) |
122 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_DOMStorageKey, OnKey) | 118 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_DOMStorageKey, OnKey) |
123 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_DOMStorageGetItem, OnGetItem) | 119 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_DOMStorageGetItem, OnGetItem) |
124 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_DOMStorageSetItem, OnSetItem) | 120 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_DOMStorageSetItem, OnSetItem) |
125 IPC_MESSAGE_HANDLER(ViewHostMsg_DOMStorageRemoveItem, OnRemoveItem) | 121 IPC_MESSAGE_HANDLER(ViewHostMsg_DOMStorageRemoveItem, OnRemoveItem) |
126 IPC_MESSAGE_HANDLER(ViewHostMsg_DOMStorageClear, OnClear) | 122 IPC_MESSAGE_HANDLER(ViewHostMsg_DOMStorageClear, OnClear) |
127 IPC_MESSAGE_UNHANDLED(handled = false) | 123 IPC_MESSAGE_UNHANDLED(handled = false) |
128 IPC_END_MESSAGE_MAP() | 124 IPC_END_MESSAGE_MAP() |
129 return handled; | 125 return handled; |
130 } | 126 } |
131 | 127 |
| 128 int64 DOMStorageDispatcherHost::CloneSessionStorage(int64 original_id) { |
| 129 return Context()->CloneSessionStorage(original_id); |
| 130 } |
| 131 |
132 void DOMStorageDispatcherHost::Send(IPC::Message* message) { | 132 void DOMStorageDispatcherHost::Send(IPC::Message* message) { |
133 if (!message_sender_) { | 133 if (!message_sender_) { |
134 delete message; | 134 delete message; |
135 return; | 135 return; |
136 } | 136 } |
137 | 137 |
138 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { | 138 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { |
139 message_sender_->Send(message); | 139 message_sender_->Send(message); |
140 return; | 140 return; |
141 } | 141 } |
142 | 142 |
143 // The IO thread can't go away while the WebKit thread is still running. | 143 // The IO thread can't go away while the WebKit thread is still running. |
144 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); | 144 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); |
145 ChromeThread::PostTask( | 145 ChromeThread::PostTask( |
146 ChromeThread::IO, FROM_HERE, | 146 ChromeThread::IO, FROM_HERE, |
147 NewRunnableMethod(this, &DOMStorageDispatcherHost::Send, message)); | 147 NewRunnableMethod(this, &DOMStorageDispatcherHost::Send, message)); |
148 } | 148 } |
149 | 149 |
150 void DOMStorageDispatcherHost::OnNamespaceId(DOMStorageType storage_type, | |
151 IPC::Message* reply_msg) { | |
152 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { | |
153 ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod( | |
154 this, &DOMStorageDispatcherHost::OnNamespaceId, storage_type, | |
155 reply_msg)); | |
156 return; | |
157 } | |
158 | |
159 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); | |
160 DOMStorageNamespace* new_namespace; | |
161 if (storage_type == DOM_STORAGE_LOCAL) | |
162 new_namespace = Context()->LocalStorage(); | |
163 else | |
164 new_namespace = Context()->NewSessionStorage(); | |
165 ViewHostMsg_DOMStorageNamespaceId::WriteReplyParams(reply_msg, | |
166 new_namespace->id()); | |
167 Send(reply_msg); | |
168 } | |
169 | |
170 void DOMStorageDispatcherHost::OnCloneNamespaceId(int64 namespace_id, | |
171 IPC::Message* reply_msg) { | |
172 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { | |
173 ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod( | |
174 this, &DOMStorageDispatcherHost::OnCloneNamespaceId, namespace_id, | |
175 reply_msg)); | |
176 return; | |
177 } | |
178 | |
179 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); | |
180 DOMStorageNamespace* existing_namespace = | |
181 Context()->GetStorageNamespace(namespace_id); | |
182 if (!existing_namespace) { | |
183 BrowserRenderProcessHost::BadMessageTerminateProcess( | |
184 ViewHostMsg_DOMStorageCloneNamespaceId::ID, process_handle_); | |
185 delete reply_msg; | |
186 return; | |
187 } | |
188 DOMStorageNamespace* new_namespace = existing_namespace->Copy(); | |
189 ViewHostMsg_DOMStorageCloneNamespaceId::WriteReplyParams(reply_msg, | |
190 new_namespace->id()); | |
191 Send(reply_msg); | |
192 } | |
193 | |
194 void DOMStorageDispatcherHost::OnStorageAreaId(int64 namespace_id, | 150 void DOMStorageDispatcherHost::OnStorageAreaId(int64 namespace_id, |
195 const string16& origin, | 151 const string16& origin, |
196 IPC::Message* reply_msg) { | 152 IPC::Message* reply_msg) { |
197 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { | 153 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { |
198 ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod( | 154 ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod( |
199 this, &DOMStorageDispatcherHost::OnStorageAreaId, namespace_id, origin, | 155 this, &DOMStorageDispatcherHost::OnStorageAreaId, namespace_id, origin, |
200 reply_msg)); | 156 reply_msg)); |
201 return; | 157 return; |
202 } | 158 } |
203 | 159 |
204 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); | 160 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); |
205 DOMStorageNamespace* storage_namespace = | 161 DOMStorageNamespace* storage_namespace = |
206 Context()->GetStorageNamespace(namespace_id); | 162 Context()->GetStorageNamespace(namespace_id, true); |
207 if (!storage_namespace) { | 163 if (!storage_namespace) { |
208 BrowserRenderProcessHost::BadMessageTerminateProcess( | 164 BrowserRenderProcessHost::BadMessageTerminateProcess( |
209 ViewHostMsg_DOMStorageStorageAreaId::ID, process_handle_); | 165 ViewHostMsg_DOMStorageStorageAreaId::ID, process_handle_); |
210 delete reply_msg; | 166 delete reply_msg; |
211 return; | 167 return; |
212 } | 168 } |
213 DOMStorageArea* storage_area = storage_namespace->GetStorageArea(origin); | 169 DOMStorageArea* storage_area = storage_namespace->GetStorageArea(origin); |
214 ViewHostMsg_DOMStorageCloneNamespaceId::WriteReplyParams(reply_msg, | 170 ViewHostMsg_DOMStorageStorageAreaId::WriteReplyParams(reply_msg, |
215 storage_area->id()); | 171 storage_area->id()); |
216 Send(reply_msg); | 172 Send(reply_msg); |
217 } | 173 } |
218 | 174 |
219 void DOMStorageDispatcherHost::OnLength(int64 storage_area_id, | 175 void DOMStorageDispatcherHost::OnLength(int64 storage_area_id, |
220 IPC::Message* reply_msg) { | 176 IPC::Message* reply_msg) { |
221 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { | 177 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { |
222 ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod( | 178 ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod( |
223 this, &DOMStorageDispatcherHost::OnLength, storage_area_id, reply_msg)); | 179 this, &DOMStorageDispatcherHost::OnLength, storage_area_id, reply_msg)); |
224 return; | 180 return; |
225 } | 181 } |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 const ViewMsg_DOMStorageEvent_Params& params) { | 307 const ViewMsg_DOMStorageEvent_Params& params) { |
352 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | 308 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
353 const DOMStorageContext::DispatcherHostSet* set = | 309 const DOMStorageContext::DispatcherHostSet* set = |
354 Context()->GetDispatcherHostSet(); | 310 Context()->GetDispatcherHostSet(); |
355 DOMStorageContext::DispatcherHostSet::const_iterator cur = set->begin(); | 311 DOMStorageContext::DispatcherHostSet::const_iterator cur = set->begin(); |
356 while (cur != set->end()) { | 312 while (cur != set->end()) { |
357 (*cur)->Send(new ViewMsg_DOMStorageEvent(params)); | 313 (*cur)->Send(new ViewMsg_DOMStorageEvent(params)); |
358 ++cur; | 314 ++cur; |
359 } | 315 } |
360 } | 316 } |
OLD | NEW |