| 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_permission_request.h" | 5 #include "chrome/browser/renderer_host/database_permission_request.h" |
| 6 | 6 |
| 7 | 7 |
| 8 #include "chrome/browser/browser_list.h" | 8 #include "chrome/browser/browser_list.h" |
| 9 #include "chrome/browser/chrome_thread.h" | 9 #include "chrome/browser/chrome_thread.h" |
| 10 #include "chrome/browser/host_content_settings_map.h" | 10 #include "chrome/browser/host_content_settings_map.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 ChromeThread::UI, FROM_HERE, NewRunnableMethod( | 34 ChromeThread::UI, FROM_HERE, NewRunnableMethod( |
| 35 this, &DatabasePermissionRequest::RequestPermission)); | 35 this, &DatabasePermissionRequest::RequestPermission)); |
| 36 return; | 36 return; |
| 37 } | 37 } |
| 38 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | 38 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 39 | 39 |
| 40 // Cookie settings may have changed. | 40 // Cookie settings may have changed. |
| 41 ContentSetting setting = host_content_settings_map_->GetContentSetting( | 41 ContentSetting setting = host_content_settings_map_->GetContentSetting( |
| 42 url_, CONTENT_SETTINGS_TYPE_COOKIES); | 42 url_, CONTENT_SETTINGS_TYPE_COOKIES); |
| 43 if (setting != CONTENT_SETTING_ASK) { | 43 if (setting != CONTENT_SETTING_ASK) { |
| 44 SendResponse(setting, false); | 44 SendResponse(setting); |
| 45 return; | 45 return; |
| 46 } | 46 } |
| 47 | 47 |
| 48 Browser* browser = BrowserList::GetLastActive(); | 48 Browser* browser = BrowserList::GetLastActive(); |
| 49 if (!browser || !browser->GetSelectedTabContents()) { | 49 if (!browser || !browser->GetSelectedTabContents()) { |
| 50 BlockSiteData(false); | 50 BlockSiteData(); |
| 51 return; | 51 return; |
| 52 } | 52 } |
| 53 | 53 |
| 54 #if defined(OS_WIN) | 54 #if defined(OS_WIN) |
| 55 self_ref_ = this; | 55 self_ref_ = this; |
| 56 // Will call either AllowSiteData or BlockSiteData which will NULL out our | 56 // Will call either AllowSiteData or BlockSiteData which will NULL out our |
| 57 // self reference. | 57 // self reference. |
| 58 RunDatabasePrompt(browser->GetSelectedTabContents(), url_, | 58 RunDatabasePrompt(browser->GetSelectedTabContents(), |
| 59 database_name_, this); | 59 host_content_settings_map_, url_, database_name_, this); |
| 60 #else | 60 #else |
| 61 // TODO(jorlow): Enable prompting for other ports. | 61 // TODO(jorlow): Enable prompting for other ports. |
| 62 BlockSiteData(false); | 62 BlockSiteData(); |
| 63 #endif | 63 #endif |
| 64 } | 64 } |
| 65 | 65 |
| 66 void DatabasePermissionRequest::AllowSiteData(bool remember, | 66 void DatabasePermissionRequest::AllowSiteData(bool session_expire) { |
| 67 bool session_expire) { | 67 SendResponse(CONTENT_SETTING_ALLOW); |
| 68 SendResponse(CONTENT_SETTING_ALLOW, remember); | |
| 69 } | 68 } |
| 70 | 69 |
| 71 void DatabasePermissionRequest::BlockSiteData(bool remember) { | 70 void DatabasePermissionRequest::BlockSiteData() { |
| 72 SendResponse(CONTENT_SETTING_BLOCK, remember); | 71 SendResponse(CONTENT_SETTING_BLOCK); |
| 73 } | 72 } |
| 74 | 73 |
| 75 void DatabasePermissionRequest::SendResponse(ContentSetting content_setting, | 74 void DatabasePermissionRequest::SendResponse(ContentSetting content_setting) { |
| 76 bool remember) { | |
| 77 if (remember) { | |
| 78 host_content_settings_map_->SetContentSetting( | |
| 79 url_.host(), CONTENT_SETTINGS_TYPE_COOKIES, content_setting); | |
| 80 } | |
| 81 | |
| 82 if (content_setting == CONTENT_SETTING_ALLOW) { | 75 if (content_setting == CONTENT_SETTING_ALLOW) { |
| 83 ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, on_allow_.release()); | 76 ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, on_allow_.release()); |
| 84 } else { | 77 } else { |
| 85 DCHECK(content_setting == CONTENT_SETTING_BLOCK); | 78 DCHECK(content_setting == CONTENT_SETTING_BLOCK); |
| 86 ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, on_block_.release()); | 79 ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, on_block_.release()); |
| 87 } | 80 } |
| 88 | 81 |
| 89 // Release all resources. | 82 // Release all resources. |
| 90 on_allow_.reset(); | 83 on_allow_.reset(); |
| 91 on_block_.reset(); | 84 on_block_.reset(); |
| 92 | 85 |
| 93 // This seems safer than possibly being deleted while in method(s) related to | 86 // This seems safer than possibly being deleted while in method(s) related to |
| 94 // this object. Any thread will do, but UI is always around and can be | 87 // this object. Any thread will do, but UI is always around and can be |
| 95 // posted without locking, so we'll ask it to do the release. | 88 // posted without locking, so we'll ask it to do the release. |
| 96 ChromeThread::ReleaseSoon(ChromeThread::UI, FROM_HERE, self_ref_.release()); | 89 ChromeThread::ReleaseSoon(ChromeThread::UI, FROM_HERE, self_ref_.release()); |
| 97 } | 90 } |
| OLD | NEW |