| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // This file contains an implementation of the ResourceLoaderBridge class. | 5 // This file contains an implementation of the ResourceLoaderBridge class. |
| 6 // The class is implemented using URLRequest, meaning it is a "simple" version | 6 // The class is implemented using URLRequest, meaning it is a "simple" version |
| 7 // that directly issues requests. The more complicated one used in the | 7 // that directly issues requests. The more complicated one used in the |
| 8 // browser uses IPC. | 8 // browser uses IPC. |
| 9 // | 9 // |
| 10 // Because URLRequest only provides an asynchronous resource loading API, this | 10 // Because URLRequest only provides an asynchronous resource loading API, this |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 MessageLoop::current() == io_thread->message_loop()); | 146 MessageLoop::current() == io_thread->message_loop()); |
| 147 } | 147 } |
| 148 | 148 |
| 149 // -------------------------------------------------------------------------- | 149 // -------------------------------------------------------------------------- |
| 150 // The following methods are called on the owner's thread in response to | 150 // The following methods are called on the owner's thread in response to |
| 151 // various URLRequest callbacks. The event hooks, defined below, trigger | 151 // various URLRequest callbacks. The event hooks, defined below, trigger |
| 152 // these methods asynchronously. | 152 // these methods asynchronously. |
| 153 | 153 |
| 154 void NotifyReceivedRedirect(const GURL& new_url, | 154 void NotifyReceivedRedirect(const GURL& new_url, |
| 155 const ResourceLoaderBridge::ResponseInfo& info) { | 155 const ResourceLoaderBridge::ResponseInfo& info) { |
| 156 bool has_new_first_party_for_cookies = false; |
| 156 GURL new_first_party_for_cookies; | 157 GURL new_first_party_for_cookies; |
| 157 if (peer_ && peer_->OnReceivedRedirect(new_url, info, | 158 if (peer_ && peer_->OnReceivedRedirect(new_url, info, |
| 159 &has_new_first_party_for_cookies, |
| 158 &new_first_party_for_cookies)) { | 160 &new_first_party_for_cookies)) { |
| 159 io_thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( | 161 io_thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( |
| 160 this, &RequestProxy::AsyncFollowDeferredRedirect, | 162 this, &RequestProxy::AsyncFollowDeferredRedirect, |
| 161 new_first_party_for_cookies)); | 163 has_new_first_party_for_cookies, new_first_party_for_cookies)); |
| 162 } else { | 164 } else { |
| 163 Cancel(); | 165 Cancel(); |
| 164 } | 166 } |
| 165 } | 167 } |
| 166 | 168 |
| 167 void NotifyReceivedResponse(const ResourceLoaderBridge::ResponseInfo& info, | 169 void NotifyReceivedResponse(const ResourceLoaderBridge::ResponseInfo& info, |
| 168 bool content_filtered) { | 170 bool content_filtered) { |
| 169 if (peer_) | 171 if (peer_) |
| 170 peer_->OnReceivedResponse(info, content_filtered); | 172 peer_->OnReceivedResponse(info, content_filtered); |
| 171 } | 173 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 | 236 |
| 235 void AsyncCancel() { | 237 void AsyncCancel() { |
| 236 // This can be null in cases where the request is already done. | 238 // This can be null in cases where the request is already done. |
| 237 if (!request_.get()) | 239 if (!request_.get()) |
| 238 return; | 240 return; |
| 239 | 241 |
| 240 request_->Cancel(); | 242 request_->Cancel(); |
| 241 Done(); | 243 Done(); |
| 242 } | 244 } |
| 243 | 245 |
| 244 void AsyncFollowDeferredRedirect(const GURL& new_first_party_for_cookies) { | 246 void AsyncFollowDeferredRedirect(bool has_new_first_party_for_cookies, |
| 247 const GURL& new_first_party_for_cookies) { |
| 245 // This can be null in cases where the request is already done. | 248 // This can be null in cases where the request is already done. |
| 246 if (!request_.get()) | 249 if (!request_.get()) |
| 247 return; | 250 return; |
| 248 | 251 |
| 249 if (!new_first_party_for_cookies.is_empty()) | 252 if (has_new_first_party_for_cookies) |
| 250 request_->set_first_party_for_cookies(new_first_party_for_cookies); | 253 request_->set_first_party_for_cookies(new_first_party_for_cookies); |
| 251 request_->FollowDeferredRedirect(); | 254 request_->FollowDeferredRedirect(); |
| 252 } | 255 } |
| 253 | 256 |
| 254 void AsyncReadData() { | 257 void AsyncReadData() { |
| 255 // This can be null in cases where the request is already done. | 258 // This can be null in cases where the request is already done. |
| 256 if (!request_.get()) | 259 if (!request_.get()) |
| 257 return; | 260 return; |
| 258 | 261 |
| 259 if (request_->status().is_success()) { | 262 if (request_->status().is_success()) { |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 options.message_loop_type = MessageLoop::TYPE_IO; | 744 options.message_loop_type = MessageLoop::TYPE_IO; |
| 742 return io_thread->StartWithOptions(options); | 745 return io_thread->StartWithOptions(options); |
| 743 } | 746 } |
| 744 | 747 |
| 745 // static | 748 // static |
| 746 void SimpleResourceLoaderBridge::SetAcceptAllCookies(bool accept_all_cookies) { | 749 void SimpleResourceLoaderBridge::SetAcceptAllCookies(bool accept_all_cookies) { |
| 747 CookiePolicy::Type policy_type = accept_all_cookies ? | 750 CookiePolicy::Type policy_type = accept_all_cookies ? |
| 748 CookiePolicy::ALLOW_ALL_COOKIES : CookiePolicy::BLOCK_THIRD_PARTY_COOKIES; | 751 CookiePolicy::ALLOW_ALL_COOKIES : CookiePolicy::BLOCK_THIRD_PARTY_COOKIES; |
| 749 request_context->cookie_policy()->set_type(policy_type); | 752 request_context->cookie_policy()->set_type(policy_type); |
| 750 } | 753 } |
| OLD | NEW |