| 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_context.h" | 9 #include "chrome/browser/in_process_webkit/dom_storage_context.h" |
| 10 #include "chrome/browser/in_process_webkit/storage_area.h" | 10 #include "chrome/browser/in_process_webkit/storage_area.h" |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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, | 150 void DOMStorageDispatcherHost::OnNamespaceId(DOMStorageType storage_type, |
| 151 IPC::Message* reply_msg) { | 151 IPC::Message* reply_msg) { |
| 152 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { | 152 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { |
| 153 PostTaskToWebKitThread(FROM_HERE, NewRunnableMethod(this, | 153 ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod( |
| 154 &DOMStorageDispatcherHost::OnNamespaceId, | 154 this, &DOMStorageDispatcherHost::OnNamespaceId, storage_type, |
| 155 storage_type, reply_msg)); | 155 reply_msg)); |
| 156 return; | 156 return; |
| 157 } | 157 } |
| 158 | 158 |
| 159 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); | 159 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); |
| 160 StorageNamespace* new_namespace; | 160 StorageNamespace* new_namespace; |
| 161 if (storage_type == DOM_STORAGE_LOCAL) | 161 if (storage_type == DOM_STORAGE_LOCAL) |
| 162 new_namespace = Context()->LocalStorage(); | 162 new_namespace = Context()->LocalStorage(); |
| 163 else | 163 else |
| 164 new_namespace = Context()->NewSessionStorage(); | 164 new_namespace = Context()->NewSessionStorage(); |
| 165 ViewHostMsg_DOMStorageNamespaceId::WriteReplyParams(reply_msg, | 165 ViewHostMsg_DOMStorageNamespaceId::WriteReplyParams(reply_msg, |
| 166 new_namespace->id()); | 166 new_namespace->id()); |
| 167 Send(reply_msg); | 167 Send(reply_msg); |
| 168 } | 168 } |
| 169 | 169 |
| 170 void DOMStorageDispatcherHost::OnCloneNamespaceId(int64 namespace_id, | 170 void DOMStorageDispatcherHost::OnCloneNamespaceId(int64 namespace_id, |
| 171 IPC::Message* reply_msg) { | 171 IPC::Message* reply_msg) { |
| 172 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { | 172 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { |
| 173 PostTaskToWebKitThread(FROM_HERE, NewRunnableMethod(this, | 173 ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod( |
| 174 &DOMStorageDispatcherHost::OnCloneNamespaceId, | 174 this, &DOMStorageDispatcherHost::OnCloneNamespaceId, namespace_id, |
| 175 namespace_id, reply_msg)); | 175 reply_msg)); |
| 176 return; | 176 return; |
| 177 } | 177 } |
| 178 | 178 |
| 179 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); | 179 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); |
| 180 StorageNamespace* existing_namespace = | 180 StorageNamespace* existing_namespace = |
| 181 Context()->GetStorageNamespace(namespace_id); | 181 Context()->GetStorageNamespace(namespace_id); |
| 182 if (!existing_namespace) { | 182 if (!existing_namespace) { |
| 183 BrowserRenderProcessHost::BadMessageTerminateProcess( | 183 BrowserRenderProcessHost::BadMessageTerminateProcess( |
| 184 ViewHostMsg_DOMStorageCloneNamespaceId::ID, process_handle_); | 184 ViewHostMsg_DOMStorageCloneNamespaceId::ID, process_handle_); |
| 185 delete reply_msg; | 185 delete reply_msg; |
| 186 return; | 186 return; |
| 187 } | 187 } |
| 188 StorageNamespace* new_namespace = existing_namespace->Copy(); | 188 StorageNamespace* new_namespace = existing_namespace->Copy(); |
| 189 ViewHostMsg_DOMStorageCloneNamespaceId::WriteReplyParams(reply_msg, | 189 ViewHostMsg_DOMStorageCloneNamespaceId::WriteReplyParams(reply_msg, |
| 190 new_namespace->id()); | 190 new_namespace->id()); |
| 191 Send(reply_msg); | 191 Send(reply_msg); |
| 192 } | 192 } |
| 193 | 193 |
| 194 void DOMStorageDispatcherHost::OnStorageAreaId(int64 namespace_id, | 194 void DOMStorageDispatcherHost::OnStorageAreaId(int64 namespace_id, |
| 195 const string16& origin, | 195 const string16& origin, |
| 196 IPC::Message* reply_msg) { | 196 IPC::Message* reply_msg) { |
| 197 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { | 197 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { |
| 198 PostTaskToWebKitThread(FROM_HERE, NewRunnableMethod(this, | 198 ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod( |
| 199 &DOMStorageDispatcherHost::OnStorageAreaId, | 199 this, &DOMStorageDispatcherHost::OnStorageAreaId, namespace_id, origin, |
| 200 namespace_id, origin, reply_msg)); | 200 reply_msg)); |
| 201 return; | 201 return; |
| 202 } | 202 } |
| 203 | 203 |
| 204 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); | 204 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); |
| 205 StorageNamespace* storage_namespace = | 205 StorageNamespace* storage_namespace = |
| 206 Context()->GetStorageNamespace(namespace_id); | 206 Context()->GetStorageNamespace(namespace_id); |
| 207 if (!storage_namespace) { | 207 if (!storage_namespace) { |
| 208 BrowserRenderProcessHost::BadMessageTerminateProcess( | 208 BrowserRenderProcessHost::BadMessageTerminateProcess( |
| 209 ViewHostMsg_DOMStorageStorageAreaId::ID, process_handle_); | 209 ViewHostMsg_DOMStorageStorageAreaId::ID, process_handle_); |
| 210 delete reply_msg; | 210 delete reply_msg; |
| 211 return; | 211 return; |
| 212 } | 212 } |
| 213 StorageArea* storage_area = storage_namespace->GetStorageArea(origin); | 213 StorageArea* storage_area = storage_namespace->GetStorageArea(origin); |
| 214 ViewHostMsg_DOMStorageCloneNamespaceId::WriteReplyParams(reply_msg, | 214 ViewHostMsg_DOMStorageCloneNamespaceId::WriteReplyParams(reply_msg, |
| 215 storage_area->id()); | 215 storage_area->id()); |
| 216 Send(reply_msg); | 216 Send(reply_msg); |
| 217 } | 217 } |
| 218 | 218 |
| 219 void DOMStorageDispatcherHost::OnLength(int64 storage_area_id, | 219 void DOMStorageDispatcherHost::OnLength(int64 storage_area_id, |
| 220 IPC::Message* reply_msg) { | 220 IPC::Message* reply_msg) { |
| 221 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { | 221 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { |
| 222 PostTaskToWebKitThread(FROM_HERE, NewRunnableMethod(this, | 222 ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod( |
| 223 &DOMStorageDispatcherHost::OnLength, storage_area_id, reply_msg)); | 223 this, &DOMStorageDispatcherHost::OnLength, storage_area_id, reply_msg)); |
| 224 return; | 224 return; |
| 225 } | 225 } |
| 226 | 226 |
| 227 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); | 227 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); |
| 228 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id); | 228 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id); |
| 229 if (!storage_area) { | 229 if (!storage_area) { |
| 230 BrowserRenderProcessHost::BadMessageTerminateProcess( | 230 BrowserRenderProcessHost::BadMessageTerminateProcess( |
| 231 ViewHostMsg_DOMStorageLength::ID, process_handle_); | 231 ViewHostMsg_DOMStorageLength::ID, process_handle_); |
| 232 delete reply_msg; | 232 delete reply_msg; |
| 233 return; | 233 return; |
| 234 } | 234 } |
| 235 unsigned length = storage_area->Length(); | 235 unsigned length = storage_area->Length(); |
| 236 ViewHostMsg_DOMStorageLength::WriteReplyParams(reply_msg, length); | 236 ViewHostMsg_DOMStorageLength::WriteReplyParams(reply_msg, length); |
| 237 Send(reply_msg); | 237 Send(reply_msg); |
| 238 } | 238 } |
| 239 | 239 |
| 240 void DOMStorageDispatcherHost::OnKey(int64 storage_area_id, unsigned index, | 240 void DOMStorageDispatcherHost::OnKey(int64 storage_area_id, unsigned index, |
| 241 IPC::Message* reply_msg) { | 241 IPC::Message* reply_msg) { |
| 242 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { | 242 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { |
| 243 PostTaskToWebKitThread(FROM_HERE, NewRunnableMethod(this, | 243 ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod( |
| 244 &DOMStorageDispatcherHost::OnKey, storage_area_id, index, reply_msg)); | 244 this, &DOMStorageDispatcherHost::OnKey, storage_area_id, index, |
| 245 reply_msg)); |
| 245 return; | 246 return; |
| 246 } | 247 } |
| 247 | 248 |
| 248 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); | 249 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); |
| 249 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id); | 250 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id); |
| 250 if (!storage_area) { | 251 if (!storage_area) { |
| 251 BrowserRenderProcessHost::BadMessageTerminateProcess( | 252 BrowserRenderProcessHost::BadMessageTerminateProcess( |
| 252 ViewHostMsg_DOMStorageKey::ID, process_handle_); | 253 ViewHostMsg_DOMStorageKey::ID, process_handle_); |
| 253 delete reply_msg; | 254 delete reply_msg; |
| 254 return; | 255 return; |
| 255 } | 256 } |
| 256 const NullableString16& key = storage_area->Key(index); | 257 const NullableString16& key = storage_area->Key(index); |
| 257 ViewHostMsg_DOMStorageKey::WriteReplyParams(reply_msg, key); | 258 ViewHostMsg_DOMStorageKey::WriteReplyParams(reply_msg, key); |
| 258 Send(reply_msg); | 259 Send(reply_msg); |
| 259 } | 260 } |
| 260 | 261 |
| 261 void DOMStorageDispatcherHost::OnGetItem(int64 storage_area_id, | 262 void DOMStorageDispatcherHost::OnGetItem(int64 storage_area_id, |
| 262 const string16& key, | 263 const string16& key, |
| 263 IPC::Message* reply_msg) { | 264 IPC::Message* reply_msg) { |
| 264 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { | 265 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { |
| 265 PostTaskToWebKitThread(FROM_HERE, NewRunnableMethod(this, | 266 ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod( |
| 266 &DOMStorageDispatcherHost::OnGetItem, | 267 this, &DOMStorageDispatcherHost::OnGetItem, storage_area_id, key, |
| 267 storage_area_id, key, reply_msg)); | 268 reply_msg)); |
| 268 return; | 269 return; |
| 269 } | 270 } |
| 270 | 271 |
| 271 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); | 272 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); |
| 272 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id); | 273 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id); |
| 273 if (!storage_area) { | 274 if (!storage_area) { |
| 274 BrowserRenderProcessHost::BadMessageTerminateProcess( | 275 BrowserRenderProcessHost::BadMessageTerminateProcess( |
| 275 ViewHostMsg_DOMStorageGetItem::ID, process_handle_); | 276 ViewHostMsg_DOMStorageGetItem::ID, process_handle_); |
| 276 delete reply_msg; | 277 delete reply_msg; |
| 277 return; | 278 return; |
| 278 } | 279 } |
| 279 const NullableString16& value = storage_area->GetItem(key); | 280 const NullableString16& value = storage_area->GetItem(key); |
| 280 ViewHostMsg_DOMStorageGetItem::WriteReplyParams(reply_msg, value); | 281 ViewHostMsg_DOMStorageGetItem::WriteReplyParams(reply_msg, value); |
| 281 Send(reply_msg); | 282 Send(reply_msg); |
| 282 } | 283 } |
| 283 | 284 |
| 284 void DOMStorageDispatcherHost::OnSetItem( | 285 void DOMStorageDispatcherHost::OnSetItem( |
| 285 int64 storage_area_id, const string16& key, const string16& value, | 286 int64 storage_area_id, const string16& key, const string16& value, |
| 286 const GURL& url, IPC::Message* reply_msg) { | 287 const GURL& url, IPC::Message* reply_msg) { |
| 287 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { | 288 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { |
| 288 PostTaskToWebKitThread(FROM_HERE, NewRunnableMethod(this, | 289 ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod( |
| 289 &DOMStorageDispatcherHost::OnSetItem, storage_area_id, key, value, | 290 this, &DOMStorageDispatcherHost::OnSetItem, storage_area_id, key, value, |
| 290 url, reply_msg)); | 291 url, reply_msg)); |
| 291 return; | 292 return; |
| 292 } | 293 } |
| 293 | 294 |
| 294 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); | 295 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); |
| 295 bool quota_exception = false; | 296 bool quota_exception = false; |
| 296 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id); | 297 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id); |
| 297 if (!storage_area) { | 298 if (!storage_area) { |
| 298 BrowserRenderProcessHost::BadMessageTerminateProcess( | 299 BrowserRenderProcessHost::BadMessageTerminateProcess( |
| 299 ViewHostMsg_DOMStorageSetItem::ID, process_handle_); | 300 ViewHostMsg_DOMStorageSetItem::ID, process_handle_); |
| 300 return; | 301 return; |
| 301 } | 302 } |
| 302 | 303 |
| 303 ScopedStorageEventContext scope(this, &url); | 304 ScopedStorageEventContext scope(this, &url); |
| 304 storage_area->SetItem(key, value, "a_exception); | 305 storage_area->SetItem(key, value, "a_exception); |
| 305 ViewHostMsg_DOMStorageSetItem::WriteReplyParams(reply_msg, quota_exception); | 306 ViewHostMsg_DOMStorageSetItem::WriteReplyParams(reply_msg, quota_exception); |
| 306 Send(reply_msg); | 307 Send(reply_msg); |
| 307 } | 308 } |
| 308 | 309 |
| 309 void DOMStorageDispatcherHost::OnRemoveItem( | 310 void DOMStorageDispatcherHost::OnRemoveItem( |
| 310 int64 storage_area_id, const string16& key, const GURL& url) { | 311 int64 storage_area_id, const string16& key, const GURL& url) { |
| 311 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { | 312 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { |
| 312 PostTaskToWebKitThread(FROM_HERE, NewRunnableMethod(this, | 313 ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod( |
| 313 &DOMStorageDispatcherHost::OnRemoveItem, storage_area_id, key, url)); | 314 this, &DOMStorageDispatcherHost::OnRemoveItem, storage_area_id, key, |
| 315 url)); |
| 314 return; | 316 return; |
| 315 } | 317 } |
| 316 | 318 |
| 317 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); | 319 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); |
| 318 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id); | 320 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id); |
| 319 if (!storage_area) { | 321 if (!storage_area) { |
| 320 BrowserRenderProcessHost::BadMessageTerminateProcess( | 322 BrowserRenderProcessHost::BadMessageTerminateProcess( |
| 321 ViewHostMsg_DOMStorageRemoveItem::ID, process_handle_); | 323 ViewHostMsg_DOMStorageRemoveItem::ID, process_handle_); |
| 322 return; | 324 return; |
| 323 } | 325 } |
| 324 | 326 |
| 325 ScopedStorageEventContext scope(this, &url); | 327 ScopedStorageEventContext scope(this, &url); |
| 326 storage_area->RemoveItem(key); | 328 storage_area->RemoveItem(key); |
| 327 } | 329 } |
| 328 | 330 |
| 329 void DOMStorageDispatcherHost::OnClear(int64 storage_area_id, const GURL& url) { | 331 void DOMStorageDispatcherHost::OnClear(int64 storage_area_id, const GURL& url) { |
| 330 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { | 332 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { |
| 331 PostTaskToWebKitThread(FROM_HERE, NewRunnableMethod(this, | 333 ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod( |
| 332 &DOMStorageDispatcherHost::OnClear, storage_area_id, url)); | 334 this, &DOMStorageDispatcherHost::OnClear, storage_area_id, url)); |
| 333 return; | 335 return; |
| 334 } | 336 } |
| 335 | 337 |
| 336 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); | 338 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); |
| 337 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id); | 339 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id); |
| 338 if (!storage_area) { | 340 if (!storage_area) { |
| 339 BrowserRenderProcessHost::BadMessageTerminateProcess( | 341 BrowserRenderProcessHost::BadMessageTerminateProcess( |
| 340 ViewHostMsg_DOMStorageClear::ID, process_handle_); | 342 ViewHostMsg_DOMStorageClear::ID, process_handle_); |
| 341 return; | 343 return; |
| 342 } | 344 } |
| 343 | 345 |
| 344 ScopedStorageEventContext scope(this, &url); | 346 ScopedStorageEventContext scope(this, &url); |
| 345 storage_area->Clear(); | 347 storage_area->Clear(); |
| 346 } | 348 } |
| 347 | 349 |
| 348 void DOMStorageDispatcherHost::OnStorageEvent( | 350 void DOMStorageDispatcherHost::OnStorageEvent( |
| 349 const ViewMsg_DOMStorageEvent_Params& params) { | 351 const ViewMsg_DOMStorageEvent_Params& params) { |
| 350 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | 352 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
| 351 const DOMStorageContext::DispatcherHostSet* set = | 353 const DOMStorageContext::DispatcherHostSet* set = |
| 352 Context()->GetDispatcherHostSet(); | 354 Context()->GetDispatcherHostSet(); |
| 353 DOMStorageContext::DispatcherHostSet::const_iterator cur = set->begin(); | 355 DOMStorageContext::DispatcherHostSet::const_iterator cur = set->begin(); |
| 354 while (cur != set->end()) { | 356 while (cur != set->end()) { |
| 355 (*cur)->Send(new ViewMsg_DOMStorageEvent(params)); | 357 (*cur)->Send(new ViewMsg_DOMStorageEvent(params)); |
| 356 ++cur; | 358 ++cur; |
| 357 } | 359 } |
| 358 } | 360 } |
| 359 | |
| 360 void DOMStorageDispatcherHost::PostTaskToWebKitThread( | |
| 361 const tracked_objects::Location& from_here, Task* task) { | |
| 362 webkit_thread_->EnsureInitialized(); | |
| 363 ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, task); | |
| 364 } | |
| OLD | NEW |