| 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/appcache/chrome_appcache_service.h" | 5 #include "chrome/browser/appcache/chrome_appcache_service.h" |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "chrome/browser/browser_list.h" | 9 #include "chrome/browser/browser_list.h" |
| 10 #include "chrome/browser/cookie_prompt_modal_dialog_delegate.h" | |
| 11 #include "chrome/browser/message_box_handler.h" | |
| 12 #include "chrome/browser/net/chrome_url_request_context.h" | 10 #include "chrome/browser/net/chrome_url_request_context.h" |
| 13 #include "chrome/common/chrome_constants.h" | 11 #include "chrome/common/chrome_constants.h" |
| 14 #include "chrome/common/notification_service.h" | 12 #include "chrome/common/notification_service.h" |
| 15 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
| 16 #include "webkit/appcache/appcache_thread.h" | 14 #include "webkit/appcache/appcache_thread.h" |
| 17 | 15 |
| 18 static bool has_initialized_thread_ids; | 16 static bool has_initialized_thread_ids; |
| 19 | 17 |
| 20 // ChromeAppCacheService cannot just subclass the delegate interface | |
| 21 // because we may have several prompts pending. | |
| 22 class ChromeAppCacheService::PromptDelegate | |
| 23 : public CookiePromptModalDialogDelegate { | |
| 24 public: | |
| 25 PromptDelegate(ChromeAppCacheService* service, | |
| 26 const GURL& manifest_url, net::CompletionCallback* callback) | |
| 27 : service_(service), manifest_url_(manifest_url), callback_(callback) { | |
| 28 } | |
| 29 | |
| 30 virtual void AllowSiteData(bool session_expire) { | |
| 31 service_->DidPrompt(net::OK, manifest_url_, callback_); | |
| 32 delete this; | |
| 33 } | |
| 34 | |
| 35 virtual void BlockSiteData() { | |
| 36 service_->DidPrompt(net::ERR_ACCESS_DENIED, manifest_url_, callback_); | |
| 37 delete this; | |
| 38 } | |
| 39 | |
| 40 private: | |
| 41 scoped_refptr<ChromeAppCacheService> service_; | |
| 42 GURL manifest_url_; | |
| 43 net::CompletionCallback* callback_; | |
| 44 }; | |
| 45 | |
| 46 // ---------------------------------------------------------------------------- | 18 // ---------------------------------------------------------------------------- |
| 47 | 19 |
| 48 ChromeAppCacheService::ChromeAppCacheService() { | 20 ChromeAppCacheService::ChromeAppCacheService() { |
| 49 } | 21 } |
| 50 | 22 |
| 51 void ChromeAppCacheService::InitializeOnIOThread( | 23 void ChromeAppCacheService::InitializeOnIOThread( |
| 52 const FilePath& profile_path, bool is_incognito, | 24 const FilePath& profile_path, bool is_incognito, |
| 53 scoped_refptr<HostContentSettingsMap> content_settings_map) { | 25 scoped_refptr<HostContentSettingsMap> content_settings_map) { |
| 54 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | 26 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
| 55 | 27 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 // We don't prompt for read access. | 71 // We don't prompt for read access. |
| 100 return setting != CONTENT_SETTING_BLOCK; | 72 return setting != CONTENT_SETTING_BLOCK; |
| 101 } | 73 } |
| 102 | 74 |
| 103 int ChromeAppCacheService::CanCreateAppCache( | 75 int ChromeAppCacheService::CanCreateAppCache( |
| 104 const GURL& manifest_url, net::CompletionCallback* callback) { | 76 const GURL& manifest_url, net::CompletionCallback* callback) { |
| 105 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | 77 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
| 106 ContentSetting setting = host_contents_settings_map_->GetContentSetting( | 78 ContentSetting setting = host_contents_settings_map_->GetContentSetting( |
| 107 manifest_url, CONTENT_SETTINGS_TYPE_COOKIES, ""); | 79 manifest_url, CONTENT_SETTINGS_TYPE_COOKIES, ""); |
| 108 DCHECK(setting != CONTENT_SETTING_DEFAULT); | 80 DCHECK(setting != CONTENT_SETTING_DEFAULT); |
| 109 if (setting == CONTENT_SETTING_ASK) { | |
| 110 ChromeThread::PostTask( | |
| 111 ChromeThread::UI, FROM_HERE, | |
| 112 NewRunnableMethod(this, &ChromeAppCacheService::DoPrompt, | |
| 113 manifest_url, callback)); | |
| 114 return net::ERR_IO_PENDING; | |
| 115 } | |
| 116 return (setting != CONTENT_SETTING_BLOCK) ? net::OK : | 81 return (setting != CONTENT_SETTING_BLOCK) ? net::OK : |
| 117 net::ERR_ACCESS_DENIED; | 82 net::ERR_ACCESS_DENIED; |
| 118 } | 83 } |
| 119 | 84 |
| 120 void ChromeAppCacheService::DoPrompt( | |
| 121 const GURL& manifest_url, net::CompletionCallback* callback) { | |
| 122 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | |
| 123 | |
| 124 // The setting may have changed (due to the "remember" option) | |
| 125 ContentSetting setting = host_contents_settings_map_->GetContentSetting( | |
| 126 manifest_url, CONTENT_SETTINGS_TYPE_COOKIES, ""); | |
| 127 if (setting != CONTENT_SETTING_ASK) { | |
| 128 int rv = (setting != CONTENT_SETTING_BLOCK) ? net::OK : | |
| 129 net::ERR_ACCESS_DENIED; | |
| 130 DidPrompt(rv, manifest_url, callback); | |
| 131 return; | |
| 132 } | |
| 133 | |
| 134 // Show the prompt on top of the current tab. | |
| 135 Browser* browser = BrowserList::GetLastActive(); | |
| 136 if (!browser || !browser->GetSelectedTabContents()) { | |
| 137 DidPrompt(net::ERR_ACCESS_DENIED, manifest_url, callback); | |
| 138 return; | |
| 139 } | |
| 140 | |
| 141 RunAppCachePrompt(browser->GetSelectedTabContents(), | |
| 142 host_contents_settings_map_, manifest_url, | |
| 143 new PromptDelegate(this, manifest_url, callback)); | |
| 144 } | |
| 145 | |
| 146 void ChromeAppCacheService::DidPrompt( | |
| 147 int rv, const GURL& manifest_url, net::CompletionCallback* callback) { | |
| 148 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | |
| 149 ChromeThread::PostTask( | |
| 150 ChromeThread::IO, FROM_HERE, | |
| 151 NewRunnableMethod(this, &ChromeAppCacheService::CallCallback, | |
| 152 rv, callback)); | |
| 153 } | |
| 154 | |
| 155 void ChromeAppCacheService::CallCallback( | |
| 156 int rv, net::CompletionCallback* callback) { | |
| 157 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | |
| 158 callback->Run(rv); | |
| 159 } | |
| 160 | |
| 161 void ChromeAppCacheService::Observe(NotificationType type, | 85 void ChromeAppCacheService::Observe(NotificationType type, |
| 162 const NotificationSource& source, | 86 const NotificationSource& source, |
| 163 const NotificationDetails& details) { | 87 const NotificationDetails& details) { |
| 164 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | 88 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
| 165 DCHECK(type == NotificationType::PURGE_MEMORY); | 89 DCHECK(type == NotificationType::PURGE_MEMORY); |
| 166 PurgeMemory(); | 90 PurgeMemory(); |
| 167 } | 91 } |
| 168 | 92 |
| 169 // ---------------------------------------------------------------------------- | 93 // ---------------------------------------------------------------------------- |
| 170 | 94 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 183 const tracked_objects::Location& from_here, | 107 const tracked_objects::Location& from_here, |
| 184 Task* task) { | 108 Task* task) { |
| 185 return ChromeThread::PostTask(ToChromeThreadID(id), from_here, task); | 109 return ChromeThread::PostTask(ToChromeThreadID(id), from_here, task); |
| 186 } | 110 } |
| 187 | 111 |
| 188 bool AppCacheThread::CurrentlyOn(int id) { | 112 bool AppCacheThread::CurrentlyOn(int id) { |
| 189 return ChromeThread::CurrentlyOn(ToChromeThreadID(id)); | 113 return ChromeThread::CurrentlyOn(ToChromeThreadID(id)); |
| 190 } | 114 } |
| 191 | 115 |
| 192 } // namespace appcache | 116 } // namespace appcache |
| OLD | NEW |