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 "content/browser/loader/async_resource_handler.h" | 5 #include "content/browser/loader/async_resource_handler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 : net::WrappedIOBuffer(memory), | 71 : net::WrappedIOBuffer(memory), |
72 backing_(backing) { | 72 backing_(backing) { |
73 } | 73 } |
74 private: | 74 private: |
75 virtual ~DependentIOBuffer() {} | 75 virtual ~DependentIOBuffer() {} |
76 scoped_refptr<ResourceBuffer> backing_; | 76 scoped_refptr<ResourceBuffer> backing_; |
77 }; | 77 }; |
78 | 78 |
79 AsyncResourceHandler::AsyncResourceHandler( | 79 AsyncResourceHandler::AsyncResourceHandler( |
80 ResourceMessageFilter* filter, | 80 ResourceMessageFilter* filter, |
| 81 ResourceContext* resource_context, |
81 net::URLRequest* request, | 82 net::URLRequest* request, |
82 ResourceDispatcherHostImpl* rdh) | 83 ResourceDispatcherHostImpl* rdh) |
83 : ResourceMessageDelegate(request), | 84 : ResourceMessageDelegate(request), |
84 filter_(filter), | 85 filter_(filter), |
| 86 resource_context_(resource_context), |
85 request_(request), | 87 request_(request), |
86 rdh_(rdh), | 88 rdh_(rdh), |
87 pending_data_count_(0), | 89 pending_data_count_(0), |
88 allocation_size_(0), | 90 allocation_size_(0), |
89 did_defer_(false), | 91 did_defer_(false), |
90 has_checked_for_sufficient_resources_(false), | 92 has_checked_for_sufficient_resources_(false), |
91 sent_received_response_msg_(false), | 93 sent_received_response_msg_(false), |
92 sent_first_data_msg_(false) { | 94 sent_first_data_msg_(false) { |
93 InitializeResourceBufferConstants(); | 95 InitializeResourceBufferConstants(); |
94 } | 96 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 size)); | 143 size)); |
142 } | 144 } |
143 | 145 |
144 bool AsyncResourceHandler::OnRequestRedirected(int request_id, | 146 bool AsyncResourceHandler::OnRequestRedirected(int request_id, |
145 const GURL& new_url, | 147 const GURL& new_url, |
146 ResourceResponse* response, | 148 ResourceResponse* response, |
147 bool* defer) { | 149 bool* defer) { |
148 *defer = did_defer_ = true; | 150 *defer = did_defer_ = true; |
149 | 151 |
150 if (rdh_->delegate()) { | 152 if (rdh_->delegate()) { |
151 rdh_->delegate()->OnRequestRedirected(new_url, request_, | 153 rdh_->delegate()->OnRequestRedirected( |
152 filter_->resource_context(), | 154 new_url, request_, resource_context_, response); |
153 response); | |
154 } | 155 } |
155 | 156 |
156 DevToolsNetLogObserver::PopulateResponseInfo(request_, response); | 157 DevToolsNetLogObserver::PopulateResponseInfo(request_, response); |
157 response->head.request_start = request_->creation_time(); | 158 response->head.request_start = request_->creation_time(); |
158 response->head.response_start = TimeTicks::Now(); | 159 response->head.response_start = TimeTicks::Now(); |
159 return filter_->Send(new ResourceMsg_ReceivedRedirect( | 160 return filter_->Send(new ResourceMsg_ReceivedRedirect( |
160 request_id, new_url, response->head)); | 161 request_id, new_url, response->head)); |
161 } | 162 } |
162 | 163 |
163 bool AsyncResourceHandler::OnResponseStarted(int request_id, | 164 bool AsyncResourceHandler::OnResponseStarted(int request_id, |
164 ResourceResponse* response, | 165 ResourceResponse* response, |
165 bool* defer) { | 166 bool* defer) { |
166 // For changes to the main frame, inform the renderer of the new URL's | 167 // For changes to the main frame, inform the renderer of the new URL's |
167 // per-host settings before the request actually commits. This way the | 168 // per-host settings before the request actually commits. This way the |
168 // renderer will be able to set these precisely at the time the | 169 // renderer will be able to set these precisely at the time the |
169 // request commits, avoiding the possibility of e.g. zooming the old content | 170 // request commits, avoiding the possibility of e.g. zooming the old content |
170 // or of having to layout the new content twice. | 171 // or of having to layout the new content twice. |
171 | 172 |
172 ResourceContext* resource_context = filter_->resource_context(); | |
173 if (rdh_->delegate()) { | 173 if (rdh_->delegate()) { |
174 rdh_->delegate()->OnResponseStarted( | 174 rdh_->delegate()->OnResponseStarted( |
175 request_, resource_context, response, filter_.get()); | 175 request_, resource_context_, response, filter_.get()); |
176 } | 176 } |
177 | 177 |
178 DevToolsNetLogObserver::PopulateResponseInfo(request_, response); | 178 DevToolsNetLogObserver::PopulateResponseInfo(request_, response); |
179 | 179 |
180 HostZoomMap* host_zoom_map = | 180 HostZoomMap* host_zoom_map = |
181 GetHostZoomMapForResourceContext(resource_context); | 181 GetHostZoomMapForResourceContext(resource_context_); |
182 | 182 |
183 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request_); | 183 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request_); |
184 if (info->GetResourceType() == ResourceType::MAIN_FRAME && host_zoom_map) { | 184 if (info->GetResourceType() == ResourceType::MAIN_FRAME && host_zoom_map) { |
185 const GURL& request_url = request_->url(); | 185 const GURL& request_url = request_->url(); |
186 filter_->Send(new ViewMsg_SetZoomLevelForLoadingURL( | 186 filter_->Send(new ViewMsg_SetZoomLevelForLoadingURL( |
187 info->GetRouteID(), | 187 info->GetRouteID(), |
188 request_url, host_zoom_map->GetZoomLevelForHostAndScheme( | 188 request_url, host_zoom_map->GetZoomLevelForHostAndScheme( |
189 request_url.scheme(), | 189 request_url.scheme(), |
190 net::GetHostOrSpecFromURL(request_url)))); | 190 net::GetHostOrSpecFromURL(request_url)))); |
191 } | 191 } |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 } | 352 } |
353 | 353 |
354 void AsyncResourceHandler::ResumeIfDeferred() { | 354 void AsyncResourceHandler::ResumeIfDeferred() { |
355 if (did_defer_) { | 355 if (did_defer_) { |
356 did_defer_ = false; | 356 did_defer_ = false; |
357 controller()->Resume(); | 357 controller()->Resume(); |
358 } | 358 } |
359 } | 359 } |
360 | 360 |
361 } // namespace content | 361 } // namespace content |
OLD | NEW |