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/net/chrome_cookie_policy.h" | 5 #include "chrome/browser/net/chrome_cookie_policy.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
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/cookie_prompt_modal_dialog_delegate.h" | 10 #include "chrome/browser/cookie_prompt_modal_dialog_delegate.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 // may have several prompts pending. | 24 // may have several prompts pending. |
25 class ChromeCookiePolicy::PromptDelegate | 25 class ChromeCookiePolicy::PromptDelegate |
26 : public CookiePromptModalDialogDelegate { | 26 : public CookiePromptModalDialogDelegate { |
27 public: | 27 public: |
28 PromptDelegate(ChromeCookiePolicy* cookie_policy, const std::string& host) | 28 PromptDelegate(ChromeCookiePolicy* cookie_policy, const std::string& host) |
29 : cookie_policy_(cookie_policy), | 29 : cookie_policy_(cookie_policy), |
30 host_(host) { | 30 host_(host) { |
31 } | 31 } |
32 | 32 |
33 // CookiesPromptViewDelegate methods: | 33 // CookiesPromptViewDelegate methods: |
34 virtual void AllowSiteData(bool remember, bool session_expire); | 34 virtual void AllowSiteData(bool session_expire); |
35 virtual void BlockSiteData(bool remember); | 35 virtual void BlockSiteData(); |
36 | 36 |
37 private: | 37 private: |
38 void NotifyDone(int policy, bool remember); | 38 void NotifyDone(int policy); |
39 | 39 |
40 scoped_refptr<ChromeCookiePolicy> cookie_policy_; | 40 scoped_refptr<ChromeCookiePolicy> cookie_policy_; |
41 std::string host_; | 41 std::string host_; |
42 }; | 42 }; |
43 | 43 |
44 void ChromeCookiePolicy::PromptDelegate::AllowSiteData(bool remember, | 44 void ChromeCookiePolicy::PromptDelegate::AllowSiteData(bool session_expire) { |
45 bool session_expire) { | |
46 int policy = net::OK; | 45 int policy = net::OK; |
47 if (session_expire) | 46 if (session_expire) |
48 policy = net::OK_FOR_SESSION_ONLY; | 47 policy = net::OK_FOR_SESSION_ONLY; |
49 NotifyDone(policy, remember); | 48 NotifyDone(policy); |
50 } | 49 } |
51 | 50 |
52 void ChromeCookiePolicy::PromptDelegate::BlockSiteData(bool remember) { | 51 void ChromeCookiePolicy::PromptDelegate::BlockSiteData() { |
53 NotifyDone(net::ERR_ACCESS_DENIED, remember); | 52 NotifyDone(net::ERR_ACCESS_DENIED); |
54 } | 53 } |
55 | 54 |
56 void ChromeCookiePolicy::PromptDelegate::NotifyDone(int policy, bool remember) { | 55 void ChromeCookiePolicy::PromptDelegate::NotifyDone(int policy) { |
57 cookie_policy_->DidPromptForSetCookie(host_, policy, remember); | 56 cookie_policy_->DidPromptForSetCookie(host_, policy); |
58 delete this; | 57 delete this; |
59 } | 58 } |
60 | 59 |
61 // ---------------------------------------------------------------------------- | 60 // ---------------------------------------------------------------------------- |
62 | 61 |
63 ChromeCookiePolicy::ChromeCookiePolicy(HostContentSettingsMap* map) | 62 ChromeCookiePolicy::ChromeCookiePolicy(HostContentSettingsMap* map) |
64 : host_content_settings_map_(map) { | 63 : host_content_settings_map_(map) { |
65 } | 64 } |
66 | 65 |
67 ChromeCookiePolicy::~ChromeCookiePolicy() { | 66 ChromeCookiePolicy::~ChromeCookiePolicy() { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 cookie_line)); | 156 cookie_line)); |
158 return; | 157 return; |
159 } | 158 } |
160 | 159 |
161 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | 160 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
162 const std::string& host = url.host(); | 161 const std::string& host = url.host(); |
163 | 162 |
164 // The policy may have changed (due to the "remember" option) | 163 // The policy may have changed (due to the "remember" option) |
165 int policy = CheckPolicy(url); | 164 int policy = CheckPolicy(url); |
166 if (policy != net::ERR_IO_PENDING) { | 165 if (policy != net::ERR_IO_PENDING) { |
167 DidPromptForSetCookie(host, policy, false); | 166 DidPromptForSetCookie(host, policy); |
168 return; | 167 return; |
169 } | 168 } |
170 | 169 |
171 // Show the prompt on top of the current tab. | 170 // Show the prompt on top of the current tab. |
172 Browser* browser = BrowserList::GetLastActive(); | 171 Browser* browser = BrowserList::GetLastActive(); |
173 if (!browser || !browser->GetSelectedTabContents()) { | 172 if (!browser || !browser->GetSelectedTabContents()) { |
174 DidPromptForSetCookie(host, net::ERR_ACCESS_DENIED, false); | 173 DidPromptForSetCookie(host, net::ERR_ACCESS_DENIED); |
175 return; | 174 return; |
176 } | 175 } |
177 | 176 |
178 #if defined(OS_WIN) | 177 #if defined(OS_WIN) |
179 RunCookiePrompt(browser->GetSelectedTabContents(), url, cookie_line, | 178 RunCookiePrompt(browser->GetSelectedTabContents(), |
| 179 host_content_settings_map_, url, cookie_line, |
180 new PromptDelegate(this, host)); | 180 new PromptDelegate(this, host)); |
181 #else | 181 #else |
182 // TODO(darin): Enable prompting for other ports. | 182 // TODO(darin): Enable prompting for other ports. |
183 DidPromptForSetCookie(host, net::ERR_ACCESS_DENIED, false); | 183 DidPromptForSetCookie(host, net::ERR_ACCESS_DENIED); |
184 #endif | 184 #endif |
185 } | 185 } |
186 | 186 |
187 void ChromeCookiePolicy::DidPromptForSetCookie(const std::string& host, | 187 void ChromeCookiePolicy::DidPromptForSetCookie(const std::string& host, |
188 int policy, bool remember) { | 188 int policy) { |
189 if (!ChromeThread::CurrentlyOn(ChromeThread::IO)) { | 189 if (!ChromeThread::CurrentlyOn(ChromeThread::IO)) { |
190 // Process the remember flag immediately. | |
191 if (remember) { | |
192 ContentSetting content_setting = CONTENT_SETTING_BLOCK; | |
193 if (policy == net::OK || policy == net::OK_FOR_SESSION_ONLY) | |
194 content_setting = CONTENT_SETTING_ALLOW; | |
195 host_content_settings_map_->SetContentSetting( | |
196 host, CONTENT_SETTINGS_TYPE_COOKIES, content_setting); | |
197 } | |
198 | |
199 ChromeThread::PostTask( | 190 ChromeThread::PostTask( |
200 ChromeThread::IO, FROM_HERE, | 191 ChromeThread::IO, FROM_HERE, |
201 NewRunnableMethod(this, &ChromeCookiePolicy::DidPromptForSetCookie, | 192 NewRunnableMethod(this, &ChromeCookiePolicy::DidPromptForSetCookie, |
202 host, policy, remember)); | 193 host, policy)); |
203 return; | 194 return; |
204 } | 195 } |
205 | 196 |
206 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | 197 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
207 | 198 |
208 // Notify all callbacks, starting with the first until we hit another that | 199 // Notify all callbacks, starting with the first until we hit another that |
209 // is for a 'set-cookie'. | 200 // is for a 'set-cookie'. |
210 HostCompletionsMap::iterator it = host_completions_map_.find(host); | 201 HostCompletionsMap::iterator it = host_completions_map_.find(host); |
211 CHECK(it != host_completions_map_.end()); | 202 CHECK(it != host_completions_map_.end()); |
212 | 203 |
(...skipping 13 matching lines...) Expand all Loading... |
226 callbacks.push_back(completions[i].callback()); | 217 callbacks.push_back(completions[i].callback()); |
227 } | 218 } |
228 completions.erase(completions.begin(), completions.begin() + i); | 219 completions.erase(completions.begin(), completions.begin() + i); |
229 | 220 |
230 if (completions.empty()) | 221 if (completions.empty()) |
231 host_completions_map_.erase(it); | 222 host_completions_map_.erase(it); |
232 | 223 |
233 for (size_t j = 0; j < callbacks.size(); ++j) | 224 for (size_t j = 0; j < callbacks.size(); ++j) |
234 callbacks[j]->Run(policy); | 225 callbacks[j]->Run(policy); |
235 } | 226 } |
OLD | NEW |