| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_frame/urlmon_url_request.h" | 5 #include "chrome_frame/urlmon_url_request.h" |
| 6 | 6 |
| 7 #include <urlmon.h> | 7 #include <urlmon.h> |
| 8 #include <wininet.h> | 8 #include <wininet.h> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 1188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1199 download_params->bind_ctx = bind_ctx; | 1199 download_params->bind_ctx = bind_ctx; |
| 1200 download_params->moniker = moniker; | 1200 download_params->moniker = moniker; |
| 1201 download_params->post_data = post_data; | 1201 download_params->post_data = post_data; |
| 1202 if (request_headers) { | 1202 if (request_headers) { |
| 1203 download_params->request_headers = request_headers; | 1203 download_params->request_headers = request_headers; |
| 1204 } | 1204 } |
| 1205 ::PostMessage(notification_window_, WM_DOWNLOAD_IN_HOST, | 1205 ::PostMessage(notification_window_, WM_DOWNLOAD_IN_HOST, |
| 1206 reinterpret_cast<WPARAM>(download_params), 0); | 1206 reinterpret_cast<WPARAM>(download_params), 0); |
| 1207 } | 1207 } |
| 1208 | 1208 |
| 1209 void UrlmonUrlRequestManager::GetCookiesForUrl(const GURL& url, int cookie_id) { | |
| 1210 DWORD cookie_size = 0; | |
| 1211 bool success = true; | |
| 1212 std::string cookie_string; | |
| 1213 | |
| 1214 int32 cookie_action = COOKIEACTION_READ; | |
| 1215 BOOL result = InternetGetCookieA(url.spec().c_str(), NULL, NULL, | |
| 1216 &cookie_size); | |
| 1217 DWORD error = 0; | |
| 1218 if (cookie_size) { | |
| 1219 scoped_ptr<char[]> cookies(new char[cookie_size + 1]); | |
| 1220 if (!InternetGetCookieA(url.spec().c_str(), NULL, cookies.get(), | |
| 1221 &cookie_size)) { | |
| 1222 success = false; | |
| 1223 error = GetLastError(); | |
| 1224 NOTREACHED() << "InternetGetCookie failed. Error: " << error; | |
| 1225 } else { | |
| 1226 cookie_string = cookies.get(); | |
| 1227 } | |
| 1228 } else { | |
| 1229 success = false; | |
| 1230 error = GetLastError(); | |
| 1231 DVLOG(1) << "InternetGetCookie failed. Error: " << error; | |
| 1232 } | |
| 1233 | |
| 1234 OnCookiesRetrieved(success, url, cookie_string, cookie_id); | |
| 1235 if (!success && !error) | |
| 1236 cookie_action = COOKIEACTION_SUPPRESS; | |
| 1237 | |
| 1238 AddPrivacyDataForUrl(url.spec(), "", cookie_action); | |
| 1239 } | |
| 1240 | |
| 1241 void UrlmonUrlRequestManager::SetCookiesForUrl(const GURL& url, | |
| 1242 const std::string& cookie) { | |
| 1243 DCHECK(container_); | |
| 1244 // Grab a reference on the container to ensure that we don't get destroyed in | |
| 1245 // case the InternetSetCookie call below puts up a dialog box, which can | |
| 1246 // happen if the cookie policy is set to prompt. | |
| 1247 if (container_) { | |
| 1248 container_->AddRef(); | |
| 1249 } | |
| 1250 | |
| 1251 InternetCookieState cookie_state = static_cast<InternetCookieState>( | |
| 1252 InternetSetCookieExA(url.spec().c_str(), NULL, cookie.c_str(), | |
| 1253 INTERNET_COOKIE_EVALUATE_P3P, NULL)); | |
| 1254 | |
| 1255 int32 cookie_action = MapCookieStateToCookieAction(cookie_state); | |
| 1256 AddPrivacyDataForUrl(url.spec(), "", cookie_action); | |
| 1257 | |
| 1258 if (container_) { | |
| 1259 container_->Release(); | |
| 1260 } | |
| 1261 } | |
| 1262 | |
| 1263 void UrlmonUrlRequestManager::EndRequest(int request_id) { | 1209 void UrlmonUrlRequestManager::EndRequest(int request_id) { |
| 1264 DVLOG(1) << __FUNCTION__ << " id: " << request_id; | 1210 DVLOG(1) << __FUNCTION__ << " id: " << request_id; |
| 1265 scoped_refptr<UrlmonUrlRequest> request = LookupRequest(request_id, | 1211 scoped_refptr<UrlmonUrlRequest> request = LookupRequest(request_id, |
| 1266 &request_map_); | 1212 &request_map_); |
| 1267 if (request) { | 1213 if (request) { |
| 1268 request_map_.erase(request_id); | 1214 request_map_.erase(request_id); |
| 1269 request->Stop(); | 1215 request->Stop(); |
| 1270 } else if (background_worker_thread_enabled_) { | 1216 } else if (background_worker_thread_enabled_) { |
| 1271 base::AutoLock lock(background_resource_map_lock_); | 1217 base::AutoLock lock(background_resource_map_lock_); |
| 1272 request = LookupRequest(request_id, &background_request_map_); | 1218 request = LookupRequest(request_id, &background_request_map_); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1376 erased_count = background_request_map_.erase(request_id); | 1322 erased_count = background_request_map_.erase(request_id); |
| 1377 if (erased_count != 1u) { | 1323 if (erased_count != 1u) { |
| 1378 DLOG(WARNING) << __FUNCTION__ | 1324 DLOG(WARNING) << __FUNCTION__ |
| 1379 << " Failed to find request id:" | 1325 << " Failed to find request id:" |
| 1380 << request_id; | 1326 << request_id; |
| 1381 } | 1327 } |
| 1382 } | 1328 } |
| 1383 delegate_->OnResponseEnd(request_id, status); | 1329 delegate_->OnResponseEnd(request_id, status); |
| 1384 } | 1330 } |
| 1385 | 1331 |
| 1386 void UrlmonUrlRequestManager::OnCookiesRetrieved(bool success, const GURL& url, | |
| 1387 const std::string& cookie_string, int cookie_id) { | |
| 1388 DCHECK(url.is_valid()); | |
| 1389 delegate_->OnCookiesRetrieved(success, url, cookie_string, cookie_id); | |
| 1390 } | |
| 1391 | |
| 1392 scoped_refptr<UrlmonUrlRequest> UrlmonUrlRequestManager::LookupRequest( | 1332 scoped_refptr<UrlmonUrlRequest> UrlmonUrlRequestManager::LookupRequest( |
| 1393 int request_id, RequestMap* request_map) { | 1333 int request_id, RequestMap* request_map) { |
| 1394 RequestMap::iterator it = request_map->find(request_id); | 1334 RequestMap::iterator it = request_map->find(request_id); |
| 1395 if (request_map->end() != it) | 1335 if (request_map->end() != it) |
| 1396 return it->second; | 1336 return it->second; |
| 1397 return NULL; | 1337 return NULL; |
| 1398 } | 1338 } |
| 1399 | 1339 |
| 1400 UrlmonUrlRequestManager::UrlmonUrlRequestManager() | 1340 UrlmonUrlRequestManager::UrlmonUrlRequestManager() |
| 1401 : stopping_(false), notification_window_(NULL), | 1341 : stopping_(false), notification_window_(NULL), |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1439 privacy_info_.privacy_records[UTF8ToWide(url)]; | 1379 privacy_info_.privacy_records[UTF8ToWide(url)]; |
| 1440 | 1380 |
| 1441 privacy_entry.flags |= flags; | 1381 privacy_entry.flags |= flags; |
| 1442 privacy_entry.policy_ref = UTF8ToWide(policy_ref); | 1382 privacy_entry.policy_ref = UTF8ToWide(policy_ref); |
| 1443 | 1383 |
| 1444 if (fire_privacy_event && IsWindow(notification_window_)) { | 1384 if (fire_privacy_event && IsWindow(notification_window_)) { |
| 1445 PostMessage(notification_window_, WM_FIRE_PRIVACY_CHANGE_NOTIFICATION, 1, | 1385 PostMessage(notification_window_, WM_FIRE_PRIVACY_CHANGE_NOTIFICATION, 1, |
| 1446 0); | 1386 0); |
| 1447 } | 1387 } |
| 1448 } | 1388 } |
| OLD | NEW |