Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/renderer_host/database_dispatcher_host.h" | 5 #include "chrome/browser/renderer_host/database_dispatcher_host.h" |
| 6 | 6 |
| 7 #if defined(OS_POSIX) | 7 #if defined(OS_POSIX) |
| 8 #include "base/file_descriptor_posix.h" | 8 #include "base/file_descriptor_posix.h" |
| 9 #endif | 9 #endif |
| 10 | 10 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 IPC_BEGIN_MESSAGE_MAP_EX(DatabaseDispatcherHost, message, *message_was_ok) | 90 IPC_BEGIN_MESSAGE_MAP_EX(DatabaseDispatcherHost, message, *message_was_ok) |
| 91 IPC_MESSAGE_HANDLER(ViewHostMsg_DatabaseOpenFile, OnDatabaseOpenFile) | 91 IPC_MESSAGE_HANDLER(ViewHostMsg_DatabaseOpenFile, OnDatabaseOpenFile) |
| 92 IPC_MESSAGE_HANDLER(ViewHostMsg_DatabaseDeleteFile, OnDatabaseDeleteFile) | 92 IPC_MESSAGE_HANDLER(ViewHostMsg_DatabaseDeleteFile, OnDatabaseDeleteFile) |
| 93 IPC_MESSAGE_HANDLER(ViewHostMsg_DatabaseGetFileAttributes, | 93 IPC_MESSAGE_HANDLER(ViewHostMsg_DatabaseGetFileAttributes, |
| 94 OnDatabaseGetFileAttributes) | 94 OnDatabaseGetFileAttributes) |
| 95 IPC_MESSAGE_HANDLER(ViewHostMsg_DatabaseGetFileSize, | 95 IPC_MESSAGE_HANDLER(ViewHostMsg_DatabaseGetFileSize, |
| 96 OnDatabaseGetFileSize) | 96 OnDatabaseGetFileSize) |
| 97 IPC_MESSAGE_HANDLER(ViewHostMsg_DatabaseOpened, OnDatabaseOpened) | 97 IPC_MESSAGE_HANDLER(ViewHostMsg_DatabaseOpened, OnDatabaseOpened) |
| 98 IPC_MESSAGE_HANDLER(ViewHostMsg_DatabaseModified, OnDatabaseModified) | 98 IPC_MESSAGE_HANDLER(ViewHostMsg_DatabaseModified, OnDatabaseModified) |
| 99 IPC_MESSAGE_HANDLER(ViewHostMsg_DatabaseClosed, OnDatabaseClosed) | 99 IPC_MESSAGE_HANDLER(ViewHostMsg_DatabaseClosed, OnDatabaseClosed) |
| 100 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_AllowDatabase, OnAllowDatabase) | |
| 100 IPC_MESSAGE_UNHANDLED(handled = false) | 101 IPC_MESSAGE_UNHANDLED(handled = false) |
| 101 IPC_END_MESSAGE_MAP_EX() | 102 IPC_END_MESSAGE_MAP_EX() |
| 102 return handled; | 103 return handled; |
| 103 } | 104 } |
| 104 | 105 |
| 105 void DatabaseDispatcherHost::ReceivedBadMessage(uint32 msg_type) { | 106 void DatabaseDispatcherHost::ReceivedBadMessage(uint32 msg_type) { |
| 106 BrowserRenderProcessHost::BadMessageTerminateProcess( | 107 BrowserRenderProcessHost::BadMessageTerminateProcess( |
| 107 msg_type, process_handle_); | 108 msg_type, process_handle_); |
| 108 } | 109 } |
| 109 | 110 |
| 110 // Scheduled by the file thread on the IO thread. | 111 void DatabaseDispatcherHost::Send(IPC::Message* message) { |
| 111 // Sends back to the renderer process the given message. | 112 if (!ChromeThread::CurrentlyOn(ChromeThread::IO)) { |
| 112 void DatabaseDispatcherHost::SendMessage(IPC::Message* message) { | 113 if (!ChromeThread::PostTask( |
| 113 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | 114 ChromeThread::IO, FROM_HERE, |
| 114 if (!shutdown_) | 115 NewRunnableMethod(this, |
| 116 &DatabaseDispatcherHost::Send, | |
| 117 message))) | |
| 118 delete message; | |
| 119 return; | |
| 120 } | |
| 121 | |
| 122 if (!shutdown_ && resource_message_filter_) | |
| 115 resource_message_filter_->Send(message); | 123 resource_message_filter_->Send(message); |
| 116 else | 124 else |
| 117 delete message; | 125 delete message; |
| 118 } | 126 } |
| 119 | 127 |
| 120 void DatabaseDispatcherHost::OnDatabaseOpenFile(const string16& vfs_file_name, | 128 void DatabaseDispatcherHost::OnDatabaseOpenFile(const string16& vfs_file_name, |
| 121 int desired_flags, | 129 int desired_flags, |
| 122 int32 message_id) { | 130 int32 message_id) { |
| 123 if (!observer_added_) { | 131 if (!observer_added_) { |
| 124 observer_added_ = true; | 132 observer_added_ = true; |
| 125 ChromeThread::PostTask( | 133 ChromeThread::PostTask( |
| 126 ChromeThread::FILE, FROM_HERE, | 134 ChromeThread::FILE, FROM_HERE, |
| 127 NewRunnableMethod(this, &DatabaseDispatcherHost::AddObserver)); | 135 NewRunnableMethod(this, &DatabaseDispatcherHost::AddObserver)); |
| 128 } | 136 } |
| 129 | 137 |
| 130 // Only ask permission on the main database file in read/write mode. | 138 ChromeThread::PostTask( |
| 131 if (!VfsBackend::FileTypeIsMainDB(desired_flags) || | 139 ChromeThread::FILE, FROM_HERE, |
| 132 !VfsBackend::OpenTypeIsReadWrite(desired_flags)) { | 140 NewRunnableMethod(this, |
| 133 OnDatabaseOpenFileAllowed(vfs_file_name, desired_flags, message_id); | 141 &DatabaseDispatcherHost::DatabaseOpenFile, |
| 134 return; | 142 vfs_file_name, |
| 135 } | 143 desired_flags, |
| 136 | 144 message_id)); |
| 137 string16 origin_identifier; | |
| 138 string16 database_name; | |
| 139 bool ok = DatabaseUtil::CrackVfsFileName(vfs_file_name, | |
| 140 &origin_identifier, | |
| 141 &database_name, | |
| 142 NULL); | |
| 143 DCHECK(ok); // Should we assume this is an attack and kill the renderer? | |
| 144 if (!ok) { | |
| 145 OnDatabaseOpenFileBlocked(message_id); | |
| 146 return; | |
| 147 } | |
| 148 | |
| 149 // TODO(jorlow): createFromDatabaseIdentifier should not return a pointer. | |
| 150 scoped_ptr<WebSecurityOrigin> security_origin( | |
| 151 WebSecurityOrigin::createFromDatabaseIdentifier(origin_identifier)); | |
| 152 string16 origin(security_origin->toString()); | |
| 153 GURL url = GURL(origin); | |
| 154 | |
| 155 HostContentSettingsMap* host_content_settings_map = resource_message_filter_-> | |
| 156 GetRequestContextForURL(url)->host_content_settings_map(); | |
| 157 ContentSetting content_setting = host_content_settings_map->GetContentSetting( | |
| 158 url.host(), CONTENT_SETTINGS_TYPE_COOKIES); | |
| 159 | |
| 160 if (content_setting == CONTENT_SETTING_ASK) { | |
| 161 // Create a task for each possible outcome. | |
| 162 scoped_ptr<Task> on_allow(NewRunnableMethod( | |
| 163 this, &DatabaseDispatcherHost::OnDatabaseOpenFileAllowed, | |
| 164 vfs_file_name, desired_flags, message_id)); | |
| 165 scoped_ptr<Task> on_block(NewRunnableMethod( | |
| 166 this, &DatabaseDispatcherHost::OnDatabaseOpenFileBlocked, message_id)); | |
| 167 // And then let the permission request object do the rest. | |
| 168 scoped_refptr<DatabasePermissionRequest> request( | |
| 169 new DatabasePermissionRequest(url, database_name, on_allow.release(), | |
| 170 on_block.release(), | |
| 171 host_content_settings_map)); | |
| 172 request->RequestPermission(); | |
| 173 } else if (content_setting == CONTENT_SETTING_ALLOW) { | |
| 174 OnDatabaseOpenFileAllowed(vfs_file_name, desired_flags, message_id); | |
| 175 } else { | |
| 176 DCHECK(content_setting == CONTENT_SETTING_BLOCK); | |
| 177 OnDatabaseOpenFileBlocked(message_id); | |
| 178 } | |
| 179 } | 145 } |
| 180 | 146 |
| 181 static void SetOpenFileResponseParams( | 147 static void SetOpenFileResponseParams( |
| 182 ViewMsg_DatabaseOpenFileResponse_Params* params, | 148 ViewMsg_DatabaseOpenFileResponse_Params* params, |
| 183 base::PlatformFile file_handle, | 149 base::PlatformFile file_handle, |
| 184 base::PlatformFile dir_handle) { | 150 base::PlatformFile dir_handle) { |
| 185 #if defined(OS_WIN) | 151 #if defined(OS_WIN) |
| 186 params->file_handle = file_handle; | 152 params->file_handle = file_handle; |
| 187 #elif defined(OS_POSIX) | 153 #elif defined(OS_POSIX) |
| 188 params->file_handle = base::FileDescriptor(file_handle, true); | 154 params->file_handle = base::FileDescriptor(file_handle, true); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 213 FilePath db_file = | 179 FilePath db_file = |
| 214 DatabaseUtil::GetFullFilePathForVfsFile(db_tracker_, vfs_file_name); | 180 DatabaseUtil::GetFullFilePathForVfsFile(db_tracker_, vfs_file_name); |
| 215 if (!db_file.empty()) { | 181 if (!db_file.empty()) { |
| 216 VfsBackend::OpenFile(db_file, desired_flags, process_handle_, | 182 VfsBackend::OpenFile(db_file, desired_flags, process_handle_, |
| 217 &target_handle, &target_dir_handle); | 183 &target_handle, &target_dir_handle); |
| 218 } | 184 } |
| 219 } | 185 } |
| 220 | 186 |
| 221 ViewMsg_DatabaseOpenFileResponse_Params response_params; | 187 ViewMsg_DatabaseOpenFileResponse_Params response_params; |
| 222 SetOpenFileResponseParams(&response_params, target_handle, target_dir_handle); | 188 SetOpenFileResponseParams(&response_params, target_handle, target_dir_handle); |
| 223 ChromeThread::PostTask( | 189 Send(new ViewMsg_DatabaseOpenFileResponse(message_id, response_params)); |
| 224 ChromeThread::IO, FROM_HERE, | |
| 225 NewRunnableMethod(this, | |
| 226 &DatabaseDispatcherHost::SendMessage, | |
| 227 new ViewMsg_DatabaseOpenFileResponse( | |
| 228 message_id, response_params))); | |
| 229 } | 190 } |
| 230 | 191 |
| 231 void DatabaseDispatcherHost::OnDatabaseDeleteFile(const string16& vfs_file_name, | 192 void DatabaseDispatcherHost::OnDatabaseDeleteFile(const string16& vfs_file_name, |
| 232 const bool& sync_dir, | 193 const bool& sync_dir, |
| 233 int32 message_id) { | 194 int32 message_id) { |
| 234 ChromeThread::PostTask( | 195 ChromeThread::PostTask( |
| 235 ChromeThread::FILE, FROM_HERE, | 196 ChromeThread::FILE, FROM_HERE, |
| 236 NewRunnableMethod(this, | 197 NewRunnableMethod(this, |
| 237 &DatabaseDispatcherHost::DatabaseDeleteFile, | 198 &DatabaseDispatcherHost::DatabaseDeleteFile, |
| 238 vfs_file_name, | 199 vfs_file_name, |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 266 &DatabaseDispatcherHost::DatabaseDeleteFile, | 227 &DatabaseDispatcherHost::DatabaseDeleteFile, |
| 267 vfs_file_name, | 228 vfs_file_name, |
| 268 sync_dir, | 229 sync_dir, |
| 269 message_id, | 230 message_id, |
| 270 reschedule_count - 1), | 231 reschedule_count - 1), |
| 271 kDelayDeleteRetryMs); | 232 kDelayDeleteRetryMs); |
| 272 return; | 233 return; |
| 273 } | 234 } |
| 274 } | 235 } |
| 275 | 236 |
| 276 ChromeThread::PostTask( | 237 Send(new ViewMsg_DatabaseDeleteFileResponse(message_id, error_code)); |
| 277 ChromeThread::IO, FROM_HERE, | |
| 278 NewRunnableMethod(this, | |
| 279 &DatabaseDispatcherHost::SendMessage, | |
| 280 new ViewMsg_DatabaseDeleteFileResponse( | |
| 281 message_id, error_code))); | |
| 282 } | 238 } |
| 283 | 239 |
| 284 void DatabaseDispatcherHost::OnDatabaseGetFileAttributes( | 240 void DatabaseDispatcherHost::OnDatabaseGetFileAttributes( |
| 285 const string16& vfs_file_name, | 241 const string16& vfs_file_name, |
| 286 int32 message_id) { | 242 int32 message_id) { |
| 287 ChromeThread::PostTask( | 243 ChromeThread::PostTask( |
| 288 ChromeThread::FILE, FROM_HERE, | 244 ChromeThread::FILE, FROM_HERE, |
| 289 NewRunnableMethod(this, | 245 NewRunnableMethod(this, |
| 290 &DatabaseDispatcherHost::DatabaseGetFileAttributes, | 246 &DatabaseDispatcherHost::DatabaseGetFileAttributes, |
| 291 vfs_file_name, | 247 vfs_file_name, |
| 292 message_id)); | 248 message_id)); |
| 293 } | 249 } |
| 294 | 250 |
| 295 // Scheduled by the IO thread on the file thread. | 251 // Scheduled by the IO thread on the file thread. |
| 296 // Gets the attributes of the given database file, then schedules | 252 // Gets the attributes of the given database file, then schedules |
| 297 // a task on the IO thread's message loop to send an IPC back to | 253 // a task on the IO thread's message loop to send an IPC back to |
| 298 // corresponding renderer process. | 254 // corresponding renderer process. |
| 299 void DatabaseDispatcherHost::DatabaseGetFileAttributes( | 255 void DatabaseDispatcherHost::DatabaseGetFileAttributes( |
| 300 const string16& vfs_file_name, | 256 const string16& vfs_file_name, |
| 301 int32 message_id) { | 257 int32 message_id) { |
| 302 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); | 258 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); |
| 303 int32 attributes = -1; | 259 int32 attributes = -1; |
| 304 FilePath db_file = | 260 FilePath db_file = |
| 305 DatabaseUtil::GetFullFilePathForVfsFile(db_tracker_, vfs_file_name); | 261 DatabaseUtil::GetFullFilePathForVfsFile(db_tracker_, vfs_file_name); |
| 306 if (!db_file.empty()) | 262 if (!db_file.empty()) |
| 307 attributes = VfsBackend::GetFileAttributes(db_file); | 263 attributes = VfsBackend::GetFileAttributes(db_file); |
| 308 ChromeThread::PostTask( | 264 Send(new ViewMsg_DatabaseGetFileAttributesResponse(message_id, attributes)); |
| 309 ChromeThread::IO, FROM_HERE, | |
| 310 NewRunnableMethod(this, | |
| 311 &DatabaseDispatcherHost::SendMessage, | |
| 312 new ViewMsg_DatabaseGetFileAttributesResponse( | |
| 313 message_id, attributes))); | |
| 314 } | 265 } |
| 315 | 266 |
| 316 void DatabaseDispatcherHost::OnDatabaseGetFileSize( | 267 void DatabaseDispatcherHost::OnDatabaseGetFileSize( |
| 317 const string16& vfs_file_name, int32 message_id) { | 268 const string16& vfs_file_name, int32 message_id) { |
| 318 ChromeThread::PostTask( | 269 ChromeThread::PostTask( |
| 319 ChromeThread::FILE, FROM_HERE, | 270 ChromeThread::FILE, FROM_HERE, |
| 320 NewRunnableMethod(this, | 271 NewRunnableMethod(this, |
| 321 &DatabaseDispatcherHost::DatabaseGetFileSize, | 272 &DatabaseDispatcherHost::DatabaseGetFileSize, |
| 322 vfs_file_name, | 273 vfs_file_name, |
| 323 message_id)); | 274 message_id)); |
| 324 } | 275 } |
| 325 | 276 |
| 326 // Scheduled by the IO thread on the file thread. | 277 // Scheduled by the IO thread on the file thread. |
| 327 // Gets the size of the given file, then schedules a task | 278 // Gets the size of the given file, then schedules a task |
| 328 // on the IO thread's message loop to send an IPC back to | 279 // on the IO thread's message loop to send an IPC back to |
| 329 // the corresponding renderer process. | 280 // the corresponding renderer process. |
| 330 void DatabaseDispatcherHost::DatabaseGetFileSize(const string16& vfs_file_name, | 281 void DatabaseDispatcherHost::DatabaseGetFileSize(const string16& vfs_file_name, |
| 331 int32 message_id) { | 282 int32 message_id) { |
| 332 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); | 283 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); |
| 333 int64 size = 0; | 284 int64 size = 0; |
| 334 FilePath db_file = | 285 FilePath db_file = |
| 335 DatabaseUtil::GetFullFilePathForVfsFile(db_tracker_, vfs_file_name); | 286 DatabaseUtil::GetFullFilePathForVfsFile(db_tracker_, vfs_file_name); |
| 336 if (!db_file.empty()) | 287 if (!db_file.empty()) |
| 337 size = VfsBackend::GetFileSize(db_file); | 288 size = VfsBackend::GetFileSize(db_file); |
| 338 ChromeThread::PostTask( | 289 Send(new ViewMsg_DatabaseGetFileSizeResponse(message_id, size)); |
| 339 ChromeThread::IO, FROM_HERE, | |
| 340 NewRunnableMethod(this, | |
| 341 &DatabaseDispatcherHost::SendMessage, | |
| 342 new ViewMsg_DatabaseGetFileSizeResponse( | |
| 343 message_id, size))); | |
| 344 } | 290 } |
| 345 | 291 |
| 346 void DatabaseDispatcherHost::OnDatabaseOpened(const string16& origin_identifier, | 292 void DatabaseDispatcherHost::OnDatabaseOpened(const string16& origin_identifier, |
| 347 const string16& database_name, | 293 const string16& database_name, |
| 348 const string16& description, | 294 const string16& description, |
| 349 int64 estimated_size) { | 295 int64 estimated_size) { |
| 350 ChromeThread::PostTask( | 296 ChromeThread::PostTask( |
| 351 ChromeThread::FILE, FROM_HERE, | 297 ChromeThread::FILE, FROM_HERE, |
| 352 NewRunnableMethod(this, | 298 NewRunnableMethod(this, |
| 353 &DatabaseDispatcherHost::DatabaseOpened, | 299 &DatabaseDispatcherHost::DatabaseOpened, |
| 354 origin_identifier, | 300 origin_identifier, |
| 355 database_name, | 301 database_name, |
| 356 description, | 302 description, |
| 357 estimated_size)); | 303 estimated_size)); |
| 358 } | 304 } |
| 359 | 305 |
| 360 void DatabaseDispatcherHost::DatabaseOpened(const string16& origin_identifier, | 306 void DatabaseDispatcherHost::DatabaseOpened(const string16& origin_identifier, |
| 361 const string16& database_name, | 307 const string16& database_name, |
| 362 const string16& description, | 308 const string16& description, |
| 363 int64 estimated_size) { | 309 int64 estimated_size) { |
| 364 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); | 310 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); |
| 365 int64 database_size = 0; | 311 int64 database_size = 0; |
| 366 int64 space_available = 0; | 312 int64 space_available = 0; |
| 367 database_connections_.AddConnection(origin_identifier, database_name); | 313 database_connections_.AddConnection(origin_identifier, database_name); |
| 368 db_tracker_->DatabaseOpened(origin_identifier, database_name, description, | 314 db_tracker_->DatabaseOpened(origin_identifier, database_name, description, |
| 369 estimated_size, &database_size, &space_available); | 315 estimated_size, &database_size, &space_available); |
| 370 ChromeThread::PostTask( | 316 Send(new ViewMsg_DatabaseUpdateSize(origin_identifier, database_name, |
| 371 ChromeThread::IO, FROM_HERE, | 317 database_size, space_available)); |
| 372 NewRunnableMethod(this, | |
| 373 &DatabaseDispatcherHost::SendMessage, | |
| 374 new ViewMsg_DatabaseUpdateSize( | |
| 375 origin_identifier, database_name, | |
| 376 database_size, space_available))); | |
| 377 } | 318 } |
| 378 | 319 |
| 379 void DatabaseDispatcherHost::OnDatabaseModified( | 320 void DatabaseDispatcherHost::OnDatabaseModified( |
| 380 const string16& origin_identifier, | 321 const string16& origin_identifier, |
| 381 const string16& database_name) { | 322 const string16& database_name) { |
| 382 ChromeThread::PostTask( | 323 ChromeThread::PostTask( |
| 383 ChromeThread::FILE, FROM_HERE, | 324 ChromeThread::FILE, FROM_HERE, |
| 384 NewRunnableMethod(this, | 325 NewRunnableMethod(this, |
| 385 &DatabaseDispatcherHost::DatabaseModified, | 326 &DatabaseDispatcherHost::DatabaseModified, |
| 386 origin_identifier, | 327 origin_identifier, |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 402 void DatabaseDispatcherHost::OnDatabaseClosed(const string16& origin_identifier, | 343 void DatabaseDispatcherHost::OnDatabaseClosed(const string16& origin_identifier, |
| 403 const string16& database_name) { | 344 const string16& database_name) { |
| 404 ChromeThread::PostTask( | 345 ChromeThread::PostTask( |
| 405 ChromeThread::FILE, FROM_HERE, | 346 ChromeThread::FILE, FROM_HERE, |
| 406 NewRunnableMethod(this, | 347 NewRunnableMethod(this, |
| 407 &DatabaseDispatcherHost::DatabaseClosed, | 348 &DatabaseDispatcherHost::DatabaseClosed, |
| 408 origin_identifier, | 349 origin_identifier, |
| 409 database_name)); | 350 database_name)); |
| 410 } | 351 } |
| 411 | 352 |
| 353 void DatabaseDispatcherHost::OnAllowDatabase(const std::string& origin, | |
|
michaeln
2010/03/30 19:46:19
Since every other call here uses 'origin_identifie
jochen (gone - plz use gerrit)
2010/03/31 07:36:34
Done.
| |
| 354 const string16& name, | |
| 355 const string16& display_name, | |
| 356 unsigned long estimated_size, | |
| 357 IPC::Message* reply_msg) { | |
| 358 GURL url = GURL(origin); | |
| 359 HostContentSettingsMap* host_content_settings_map = resource_message_filter_-> | |
| 360 GetRequestContextForURL(url)->host_content_settings_map(); | |
| 361 ContentSetting content_setting = host_content_settings_map->GetContentSetting( | |
| 362 url.host(), CONTENT_SETTINGS_TYPE_COOKIES); | |
| 363 | |
| 364 if (content_setting == CONTENT_SETTING_ASK) { | |
| 365 // Create a task for each possible outcome. | |
| 366 scoped_ptr<Task> on_allow(NewRunnableMethod( | |
| 367 this, &DatabaseDispatcherHost::AllowDatabaseResponse, | |
| 368 reply_msg, CONTENT_SETTING_ALLOW)); | |
| 369 scoped_ptr<Task> on_block(NewRunnableMethod( | |
| 370 this, &DatabaseDispatcherHost::AllowDatabaseResponse, | |
| 371 reply_msg, CONTENT_SETTING_BLOCK)); | |
| 372 // And then let the permission request object do the rest. | |
| 373 scoped_refptr<DatabasePermissionRequest> request( | |
| 374 new DatabasePermissionRequest(url, name, display_name, estimated_size, | |
| 375 on_allow.release(), on_block.release(), | |
| 376 host_content_settings_map)); | |
| 377 request->RequestPermission(); | |
| 378 | |
| 379 // Tell the renderer that it needs to run a nested message loop. | |
| 380 Send(new ViewMsg_SignalCookiePromptEvent()); | |
| 381 return; | |
| 382 } | |
| 383 | |
| 384 AllowDatabaseResponse(reply_msg, content_setting); | |
| 385 } | |
| 386 | |
| 387 void DatabaseDispatcherHost::AllowDatabaseResponse( | |
| 388 IPC::Message* reply_msg, ContentSetting content_setting) { | |
| 389 DCHECK((content_setting == CONTENT_SETTING_ALLOW) || | |
| 390 (content_setting == CONTENT_SETTING_BLOCK)); | |
| 391 ViewHostMsg_AllowDatabase::WriteReplyParams( | |
| 392 reply_msg, content_setting == CONTENT_SETTING_ALLOW); | |
| 393 Send(reply_msg); | |
| 394 } | |
| 395 | |
| 412 void DatabaseDispatcherHost::DatabaseClosed(const string16& origin_identifier, | 396 void DatabaseDispatcherHost::DatabaseClosed(const string16& origin_identifier, |
| 413 const string16& database_name) { | 397 const string16& database_name) { |
| 414 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); | 398 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); |
| 415 if (!database_connections_.IsDatabaseOpened( | 399 if (!database_connections_.IsDatabaseOpened( |
| 416 origin_identifier, database_name)) { | 400 origin_identifier, database_name)) { |
| 417 ReceivedBadMessage(ViewHostMsg_DatabaseClosed::ID); | 401 ReceivedBadMessage(ViewHostMsg_DatabaseClosed::ID); |
| 418 return; | 402 return; |
| 419 } | 403 } |
| 420 | 404 |
| 421 db_tracker_->DatabaseClosed(origin_identifier, database_name); | 405 db_tracker_->DatabaseClosed(origin_identifier, database_name); |
| 422 database_connections_.RemoveConnection(origin_identifier, database_name); | 406 database_connections_.RemoveConnection(origin_identifier, database_name); |
| 423 } | 407 } |
| 424 | 408 |
| 425 void DatabaseDispatcherHost::OnDatabaseSizeChanged( | 409 void DatabaseDispatcherHost::OnDatabaseSizeChanged( |
| 426 const string16& origin_identifier, | 410 const string16& origin_identifier, |
| 427 const string16& database_name, | 411 const string16& database_name, |
| 428 int64 database_size, | 412 int64 database_size, |
| 429 int64 space_available) { | 413 int64 space_available) { |
| 430 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); | 414 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); |
| 431 if (database_connections_.IsOriginUsed(origin_identifier)) { | 415 if (database_connections_.IsOriginUsed(origin_identifier)) { |
| 432 ChromeThread::PostTask( | 416 Send(new ViewMsg_DatabaseUpdateSize(origin_identifier, database_name, |
| 433 ChromeThread::IO, FROM_HERE, | 417 database_size, space_available)); |
| 434 NewRunnableMethod(this, | |
| 435 &DatabaseDispatcherHost::SendMessage, | |
| 436 new ViewMsg_DatabaseUpdateSize( | |
| 437 origin_identifier, database_name, | |
| 438 database_size, space_available))); | |
| 439 } | 418 } |
| 440 } | 419 } |
| 441 | 420 |
| 442 void DatabaseDispatcherHost::OnDatabaseScheduledForDeletion( | 421 void DatabaseDispatcherHost::OnDatabaseScheduledForDeletion( |
| 443 const string16& origin_identifier, | 422 const string16& origin_identifier, |
| 444 const string16& database_name) { | 423 const string16& database_name) { |
| 445 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); | 424 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); |
| 446 ChromeThread::PostTask( | 425 Send(new ViewMsg_DatabaseCloseImmediately(origin_identifier, database_name)); |
| 447 ChromeThread::IO, FROM_HERE, | |
| 448 NewRunnableMethod(this, | |
| 449 &DatabaseDispatcherHost::SendMessage, | |
| 450 new ViewMsg_DatabaseCloseImmediately( | |
| 451 origin_identifier, database_name))); | |
| 452 } | 426 } |
| 453 | |
| 454 void DatabaseDispatcherHost::OnDatabaseOpenFileAllowed( | |
| 455 const string16& vfs_file_name, int desired_flags, int32 message_id) { | |
| 456 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | |
| 457 if (shutdown_) | |
| 458 return; | |
| 459 | |
| 460 ChromeThread::PostTask( | |
| 461 ChromeThread::FILE, FROM_HERE, | |
| 462 NewRunnableMethod(this, | |
| 463 &DatabaseDispatcherHost::DatabaseOpenFile, | |
| 464 vfs_file_name, | |
| 465 desired_flags, | |
| 466 message_id)); | |
| 467 } | |
| 468 | |
| 469 void DatabaseDispatcherHost::OnDatabaseOpenFileBlocked(int32 message_id) { | |
| 470 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | |
| 471 if (shutdown_) | |
| 472 return; | |
| 473 | |
| 474 // This will result in failed transactions NOT a failed window.openDatabase | |
| 475 // call. | |
| 476 ViewMsg_DatabaseOpenFileResponse_Params response_params; | |
| 477 SetOpenFileResponseParams(&response_params, | |
| 478 base::kInvalidPlatformFileValue, | |
| 479 base::kInvalidPlatformFileValue); | |
| 480 SendMessage(new ViewMsg_DatabaseOpenFileResponse(message_id, | |
| 481 response_params)); | |
| 482 } | |
| OLD | NEW |