| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2010, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2010, 2011 Apple Inc. All rights reserved. |
| 3 * (C) 2007 Graham Dennis (graham.dennis@gmail.com) | 3 * (C) 2007 Graham Dennis (graham.dennis@gmail.com) |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 m_deferredRequest = m_request; | 141 m_deferredRequest = m_request; |
| 142 return; | 142 return; |
| 143 } | 143 } |
| 144 | 144 |
| 145 if (m_state == Terminated) | 145 if (m_state == Terminated) |
| 146 return; | 146 return; |
| 147 | 147 |
| 148 RELEASE_ASSERT(m_connectionState == ConnectionStateNew); | 148 RELEASE_ASSERT(m_connectionState == ConnectionStateNew); |
| 149 m_connectionState = ConnectionStateStarted; | 149 m_connectionState = ConnectionStateStarted; |
| 150 | 150 |
| 151 m_loader = adoptPtr(WebKit::Platform::current()->createURLLoader()); | 151 m_loader = adoptPtr(blink::Platform::current()->createURLLoader()); |
| 152 ASSERT(m_loader); | 152 ASSERT(m_loader); |
| 153 WebKit::WrappedResourceRequest wrappedRequest(m_request); | 153 blink::WrappedResourceRequest wrappedRequest(m_request); |
| 154 wrappedRequest.setAllowStoredCredentials(m_options.allowCredentials == Allow
StoredCredentials); | 154 wrappedRequest.setAllowStoredCredentials(m_options.allowCredentials == Allow
StoredCredentials); |
| 155 m_loader->loadAsynchronously(wrappedRequest, this); | 155 m_loader->loadAsynchronously(wrappedRequest, this); |
| 156 } | 156 } |
| 157 | 157 |
| 158 void ResourceLoader::changeToSynchronous() | 158 void ResourceLoader::changeToSynchronous() |
| 159 { | 159 { |
| 160 ASSERT(m_options.synchronousPolicy == RequestAsynchronously); | 160 ASSERT(m_options.synchronousPolicy == RequestAsynchronously); |
| 161 ASSERT(m_loader); | 161 ASSERT(m_loader); |
| 162 m_loader->cancel(); | 162 m_loader->cancel(); |
| 163 m_loader.clear(); | 163 m_loader.clear(); |
| 164 m_request.setPriority(ResourceLoadPriorityHighest); | 164 m_request.setPriority(ResourceLoadPriorityHighest); |
| 165 m_connectionState = ConnectionStateNew; | 165 m_connectionState = ConnectionStateNew; |
| 166 requestSynchronously(); | 166 requestSynchronously(); |
| 167 } | 167 } |
| 168 | 168 |
| 169 void ResourceLoader::setDefersLoading(bool defers) | 169 void ResourceLoader::setDefersLoading(bool defers) |
| 170 { | 170 { |
| 171 m_defersLoading = defers; | 171 m_defersLoading = defers; |
| 172 if (m_loader) | 172 if (m_loader) |
| 173 m_loader->setDefersLoading(defers); | 173 m_loader->setDefersLoading(defers); |
| 174 if (!defers && !m_deferredRequest.isNull()) { | 174 if (!defers && !m_deferredRequest.isNull()) { |
| 175 m_request = m_deferredRequest; | 175 m_request = m_deferredRequest; |
| 176 m_deferredRequest = ResourceRequest(); | 176 m_deferredRequest = ResourceRequest(); |
| 177 start(); | 177 start(); |
| 178 } | 178 } |
| 179 } | 179 } |
| 180 | 180 |
| 181 void ResourceLoader::didDownloadData(WebKit::WebURLLoader*, int length, int enco
dedDataLength) | 181 void ResourceLoader::didDownloadData(blink::WebURLLoader*, int length, int encod
edDataLength) |
| 182 { | 182 { |
| 183 RefPtr<ResourceLoader> protect(this); | 183 RefPtr<ResourceLoader> protect(this); |
| 184 RELEASE_ASSERT(m_connectionState == ConnectionStateReceivedResponse); | 184 RELEASE_ASSERT(m_connectionState == ConnectionStateReceivedResponse); |
| 185 m_resource->didDownloadData(length); | 185 m_resource->didDownloadData(length); |
| 186 } | 186 } |
| 187 | 187 |
| 188 void ResourceLoader::didFinishLoadingOnePart(double finishTime) | 188 void ResourceLoader::didFinishLoadingOnePart(double finishTime) |
| 189 { | 189 { |
| 190 // If load has been cancelled after finishing (which could happen with a | 190 // If load has been cancelled after finishing (which could happen with a |
| 191 // JavaScript that changes the window location), do nothing. | 191 // JavaScript that changes the window location), do nothing. |
| 192 if (m_state == Terminated) | 192 if (m_state == Terminated) |
| 193 return; | 193 return; |
| 194 | 194 |
| 195 if (m_notifiedLoadComplete) | 195 if (m_notifiedLoadComplete) |
| 196 return; | 196 return; |
| 197 m_notifiedLoadComplete = true; | 197 m_notifiedLoadComplete = true; |
| 198 m_host->didFinishLoading(m_resource, finishTime, m_options); | 198 m_host->didFinishLoading(m_resource, finishTime, m_options); |
| 199 } | 199 } |
| 200 | 200 |
| 201 void ResourceLoader::didChangePriority(ResourceLoadPriority loadPriority) | 201 void ResourceLoader::didChangePriority(ResourceLoadPriority loadPriority) |
| 202 { | 202 { |
| 203 if (m_loader) { | 203 if (m_loader) { |
| 204 m_host->didChangeLoadingPriority(m_resource, loadPriority); | 204 m_host->didChangeLoadingPriority(m_resource, loadPriority); |
| 205 m_loader->didChangePriority(static_cast<WebKit::WebURLRequest::Priority>
(loadPriority)); | 205 m_loader->didChangePriority(static_cast<blink::WebURLRequest::Priority>(
loadPriority)); |
| 206 } | 206 } |
| 207 } | 207 } |
| 208 | 208 |
| 209 void ResourceLoader::cancelIfNotFinishing() | 209 void ResourceLoader::cancelIfNotFinishing() |
| 210 { | 210 { |
| 211 if (m_state != Initialized) | 211 if (m_state != Initialized) |
| 212 return; | 212 return; |
| 213 cancel(); | 213 cancel(); |
| 214 } | 214 } |
| 215 | 215 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 246 } | 246 } |
| 247 | 247 |
| 248 m_host->didFailLoading(m_resource, nonNullError, m_options); | 248 m_host->didFailLoading(m_resource, nonNullError, m_options); |
| 249 | 249 |
| 250 if (m_state == Finishing) | 250 if (m_state == Finishing) |
| 251 m_resource->error(Resource::LoadError); | 251 m_resource->error(Resource::LoadError); |
| 252 if (m_state != Terminated) | 252 if (m_state != Terminated) |
| 253 releaseResources(); | 253 releaseResources(); |
| 254 } | 254 } |
| 255 | 255 |
| 256 void ResourceLoader::willSendRequest(WebKit::WebURLLoader*, WebKit::WebURLReques
t& passedRequest, const WebKit::WebURLResponse& passedRedirectResponse) | 256 void ResourceLoader::willSendRequest(blink::WebURLLoader*, blink::WebURLRequest&
passedRequest, const blink::WebURLResponse& passedRedirectResponse) |
| 257 { | 257 { |
| 258 RefPtr<ResourceLoader> protect(this); | 258 RefPtr<ResourceLoader> protect(this); |
| 259 | 259 |
| 260 ResourceRequest& request(passedRequest.toMutableResourceRequest()); | 260 ResourceRequest& request(passedRequest.toMutableResourceRequest()); |
| 261 ASSERT(!request.isNull()); | 261 ASSERT(!request.isNull()); |
| 262 const ResourceResponse& redirectResponse(passedRedirectResponse.toResourceRe
sponse()); | 262 const ResourceResponse& redirectResponse(passedRedirectResponse.toResourceRe
sponse()); |
| 263 ASSERT(!redirectResponse.isNull()); | 263 ASSERT(!redirectResponse.isNull()); |
| 264 if (!m_host->shouldRequest(m_resource, request, m_options)) { | 264 if (!m_host->shouldRequest(m_resource, request, m_options)) { |
| 265 cancel(); | 265 cancel(); |
| 266 return; | 266 return; |
| 267 } | 267 } |
| 268 m_host->redirectReceived(m_resource, redirectResponse); | 268 m_host->redirectReceived(m_resource, redirectResponse); |
| 269 m_resource->willSendRequest(request, redirectResponse); | 269 m_resource->willSendRequest(request, redirectResponse); |
| 270 if (request.isNull() || m_state == Terminated) | 270 if (request.isNull() || m_state == Terminated) |
| 271 return; | 271 return; |
| 272 | 272 |
| 273 m_host->willSendRequest(m_resource->identifier(), request, redirectResponse,
m_options); | 273 m_host->willSendRequest(m_resource->identifier(), request, redirectResponse,
m_options); |
| 274 request.setReportLoadTiming(true); | 274 request.setReportLoadTiming(true); |
| 275 ASSERT(!request.isNull()); | 275 ASSERT(!request.isNull()); |
| 276 m_request = request; | 276 m_request = request; |
| 277 } | 277 } |
| 278 | 278 |
| 279 void ResourceLoader::didReceiveCachedMetadata(WebKit::WebURLLoader*, const char*
data, int length) | 279 void ResourceLoader::didReceiveCachedMetadata(blink::WebURLLoader*, const char*
data, int length) |
| 280 { | 280 { |
| 281 RELEASE_ASSERT(m_connectionState == ConnectionStateReceivedResponse || m_con
nectionState == ConnectionStateReceivingData); | 281 RELEASE_ASSERT(m_connectionState == ConnectionStateReceivedResponse || m_con
nectionState == ConnectionStateReceivingData); |
| 282 ASSERT(m_state == Initialized); | 282 ASSERT(m_state == Initialized); |
| 283 m_resource->setSerializedCachedMetadata(data, length); | 283 m_resource->setSerializedCachedMetadata(data, length); |
| 284 } | 284 } |
| 285 | 285 |
| 286 void ResourceLoader::didSendData(WebKit::WebURLLoader*, unsigned long long bytes
Sent, unsigned long long totalBytesToBeSent) | 286 void ResourceLoader::didSendData(blink::WebURLLoader*, unsigned long long bytesS
ent, unsigned long long totalBytesToBeSent) |
| 287 { | 287 { |
| 288 ASSERT(m_state == Initialized); | 288 ASSERT(m_state == Initialized); |
| 289 RefPtr<ResourceLoader> protect(this); | 289 RefPtr<ResourceLoader> protect(this); |
| 290 m_resource->didSendData(bytesSent, totalBytesToBeSent); | 290 m_resource->didSendData(bytesSent, totalBytesToBeSent); |
| 291 } | 291 } |
| 292 | 292 |
| 293 void ResourceLoader::didReceiveResponse(WebKit::WebURLLoader*, const WebKit::Web
URLResponse& response) | 293 void ResourceLoader::didReceiveResponse(blink::WebURLLoader*, const blink::WebUR
LResponse& response) |
| 294 { | 294 { |
| 295 ASSERT(!response.isNull()); | 295 ASSERT(!response.isNull()); |
| 296 ASSERT(m_state == Initialized); | 296 ASSERT(m_state == Initialized); |
| 297 | 297 |
| 298 bool isMultipartPayload = response.isMultipartPayload(); | 298 bool isMultipartPayload = response.isMultipartPayload(); |
| 299 bool isValidStateTransition = (m_connectionState == ConnectionStateStarted |
| m_connectionState == ConnectionStateReceivedResponse); | 299 bool isValidStateTransition = (m_connectionState == ConnectionStateStarted |
| m_connectionState == ConnectionStateReceivedResponse); |
| 300 // In the case of multipart loads, calls to didReceiveData & didReceiveRespo
nse can be interleaved. | 300 // In the case of multipart loads, calls to didReceiveData & didReceiveRespo
nse can be interleaved. |
| 301 RELEASE_ASSERT(isMultipartPayload || isValidStateTransition); | 301 RELEASE_ASSERT(isMultipartPayload || isValidStateTransition); |
| 302 m_connectionState = ConnectionStateReceivedResponse; | 302 m_connectionState = ConnectionStateReceivedResponse; |
| 303 | 303 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 324 didFinishLoadingOnePart(0); | 324 didFinishLoadingOnePart(0); |
| 325 } | 325 } |
| 326 | 326 |
| 327 if (m_resource->response().httpStatusCode() < 400 || m_resource->shouldIgnor
eHTTPStatusCodeErrors()) | 327 if (m_resource->response().httpStatusCode() < 400 || m_resource->shouldIgnor
eHTTPStatusCodeErrors()) |
| 328 return; | 328 return; |
| 329 m_state = Finishing; | 329 m_state = Finishing; |
| 330 m_resource->error(Resource::LoadError); | 330 m_resource->error(Resource::LoadError); |
| 331 cancel(); | 331 cancel(); |
| 332 } | 332 } |
| 333 | 333 |
| 334 void ResourceLoader::didReceiveData(WebKit::WebURLLoader*, const char* data, int
length, int encodedDataLength) | 334 void ResourceLoader::didReceiveData(blink::WebURLLoader*, const char* data, int
length, int encodedDataLength) |
| 335 { | 335 { |
| 336 RELEASE_ASSERT(m_connectionState == ConnectionStateReceivedResponse || m_con
nectionState == ConnectionStateReceivingData); | 336 RELEASE_ASSERT(m_connectionState == ConnectionStateReceivedResponse || m_con
nectionState == ConnectionStateReceivingData); |
| 337 m_connectionState = ConnectionStateReceivingData; | 337 m_connectionState = ConnectionStateReceivingData; |
| 338 | 338 |
| 339 // It is possible to receive data on uninitialized resources if it had an er
ror status code, and we are running a nested message | 339 // It is possible to receive data on uninitialized resources if it had an er
ror status code, and we are running a nested message |
| 340 // loop. When this occurs, ignoring the data is the correct action. | 340 // loop. When this occurs, ignoring the data is the correct action. |
| 341 if (m_resource->response().httpStatusCode() >= 400 && !m_resource->shouldIgn
oreHTTPStatusCodeErrors()) | 341 if (m_resource->response().httpStatusCode() >= 400 && !m_resource->shouldIgn
oreHTTPStatusCodeErrors()) |
| 342 return; | 342 return; |
| 343 ASSERT(m_state == Initialized); | 343 ASSERT(m_state == Initialized); |
| 344 | 344 |
| 345 // Reference the object in this method since the additional processing can d
o | 345 // Reference the object in this method since the additional processing can d
o |
| 346 // anything including removing the last reference to this object. | 346 // anything including removing the last reference to this object. |
| 347 RefPtr<ResourceLoader> protect(this); | 347 RefPtr<ResourceLoader> protect(this); |
| 348 | 348 |
| 349 // FIXME: If we get a resource with more than 2B bytes, this code won't do t
he right thing. | 349 // FIXME: If we get a resource with more than 2B bytes, this code won't do t
he right thing. |
| 350 // However, with today's computers and networking speeds, this won't happen
in practice. | 350 // However, with today's computers and networking speeds, this won't happen
in practice. |
| 351 // Could be an issue with a giant local file. | 351 // Could be an issue with a giant local file. |
| 352 m_host->didReceiveData(m_resource, data, length, encodedDataLength, m_option
s); | 352 m_host->didReceiveData(m_resource, data, length, encodedDataLength, m_option
s); |
| 353 m_resource->appendData(data, length); | 353 m_resource->appendData(data, length); |
| 354 } | 354 } |
| 355 | 355 |
| 356 void ResourceLoader::didFinishLoading(WebKit::WebURLLoader*, double finishTime) | 356 void ResourceLoader::didFinishLoading(blink::WebURLLoader*, double finishTime) |
| 357 { | 357 { |
| 358 RELEASE_ASSERT(m_connectionState == ConnectionStateReceivedResponse || m_con
nectionState == ConnectionStateReceivingData); | 358 RELEASE_ASSERT(m_connectionState == ConnectionStateReceivedResponse || m_con
nectionState == ConnectionStateReceivingData); |
| 359 m_connectionState = ConnectionStateFinishedLoading; | 359 m_connectionState = ConnectionStateFinishedLoading; |
| 360 if (m_state != Initialized) | 360 if (m_state != Initialized) |
| 361 return; | 361 return; |
| 362 ASSERT(m_state != Terminated); | 362 ASSERT(m_state != Terminated); |
| 363 LOG(ResourceLoading, "Received '%s'.", m_resource->url().string().latin1().d
ata()); | 363 LOG(ResourceLoading, "Received '%s'.", m_resource->url().string().latin1().d
ata()); |
| 364 | 364 |
| 365 RefPtr<ResourceLoader> protect(this); | 365 RefPtr<ResourceLoader> protect(this); |
| 366 ResourcePtr<Resource> protectResource(m_resource); | 366 ResourcePtr<Resource> protectResource(m_resource); |
| 367 m_state = Finishing; | 367 m_state = Finishing; |
| 368 m_resource->finish(finishTime); | 368 m_resource->finish(finishTime); |
| 369 didFinishLoadingOnePart(finishTime); | 369 didFinishLoadingOnePart(finishTime); |
| 370 | 370 |
| 371 // If the load has been cancelled by a delegate in response to didFinishLoad
(), do not release | 371 // If the load has been cancelled by a delegate in response to didFinishLoad
(), do not release |
| 372 // the resources a second time, they have been released by cancel. | 372 // the resources a second time, they have been released by cancel. |
| 373 if (m_state == Terminated) | 373 if (m_state == Terminated) |
| 374 return; | 374 return; |
| 375 releaseResources(); | 375 releaseResources(); |
| 376 } | 376 } |
| 377 | 377 |
| 378 void ResourceLoader::didFail(WebKit::WebURLLoader*, const WebKit::WebURLError& e
rror) | 378 void ResourceLoader::didFail(blink::WebURLLoader*, const blink::WebURLError& err
or) |
| 379 { | 379 { |
| 380 m_connectionState = ConnectionStateFailed; | 380 m_connectionState = ConnectionStateFailed; |
| 381 ASSERT(m_state != Terminated); | 381 ASSERT(m_state != Terminated); |
| 382 LOG(ResourceLoading, "Failed to load '%s'.\n", m_resource->url().string().la
tin1().data()); | 382 LOG(ResourceLoading, "Failed to load '%s'.\n", m_resource->url().string().la
tin1().data()); |
| 383 | 383 |
| 384 RefPtr<ResourceLoader> protect(this); | 384 RefPtr<ResourceLoader> protect(this); |
| 385 RefPtr<ResourceLoaderHost> protectHost(m_host); | 385 RefPtr<ResourceLoaderHost> protectHost(m_host); |
| 386 ResourcePtr<Resource> protectResource(m_resource); | 386 ResourcePtr<Resource> protectResource(m_resource); |
| 387 m_state = Finishing; | 387 m_state = Finishing; |
| 388 m_resource->setResourceError(error); | 388 m_resource->setResourceError(error); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 399 releaseResources(); | 399 releaseResources(); |
| 400 } | 400 } |
| 401 | 401 |
| 402 bool ResourceLoader::isLoadedBy(ResourceLoaderHost* loader) const | 402 bool ResourceLoader::isLoadedBy(ResourceLoaderHost* loader) const |
| 403 { | 403 { |
| 404 return m_host->isLoadedBy(loader); | 404 return m_host->isLoadedBy(loader); |
| 405 } | 405 } |
| 406 | 406 |
| 407 void ResourceLoader::requestSynchronously() | 407 void ResourceLoader::requestSynchronously() |
| 408 { | 408 { |
| 409 OwnPtr<WebKit::WebURLLoader> loader = adoptPtr(WebKit::Platform::current()->
createURLLoader()); | 409 OwnPtr<blink::WebURLLoader> loader = adoptPtr(blink::Platform::current()->cr
eateURLLoader()); |
| 410 ASSERT(loader); | 410 ASSERT(loader); |
| 411 | 411 |
| 412 RefPtr<ResourceLoader> protect(this); | 412 RefPtr<ResourceLoader> protect(this); |
| 413 RefPtr<ResourceLoaderHost> protectHost(m_host); | 413 RefPtr<ResourceLoaderHost> protectHost(m_host); |
| 414 ResourcePtr<Resource> protectResource(m_resource); | 414 ResourcePtr<Resource> protectResource(m_resource); |
| 415 | 415 |
| 416 RELEASE_ASSERT(m_connectionState == ConnectionStateNew); | 416 RELEASE_ASSERT(m_connectionState == ConnectionStateNew); |
| 417 m_connectionState = ConnectionStateStarted; | 417 m_connectionState = ConnectionStateStarted; |
| 418 | 418 |
| 419 WebKit::WrappedResourceRequest requestIn(m_request); | 419 blink::WrappedResourceRequest requestIn(m_request); |
| 420 requestIn.setAllowStoredCredentials(m_options.allowCredentials == AllowStore
dCredentials); | 420 requestIn.setAllowStoredCredentials(m_options.allowCredentials == AllowStore
dCredentials); |
| 421 WebKit::WebURLResponse responseOut; | 421 blink::WebURLResponse responseOut; |
| 422 responseOut.initialize(); | 422 responseOut.initialize(); |
| 423 WebKit::WebURLError errorOut; | 423 blink::WebURLError errorOut; |
| 424 WebKit::WebData dataOut; | 424 blink::WebData dataOut; |
| 425 loader->loadSynchronously(requestIn, responseOut, errorOut, dataOut); | 425 loader->loadSynchronously(requestIn, responseOut, errorOut, dataOut); |
| 426 if (errorOut.reason) { | 426 if (errorOut.reason) { |
| 427 didFail(0, errorOut); | 427 didFail(0, errorOut); |
| 428 return; | 428 return; |
| 429 } | 429 } |
| 430 didReceiveResponse(0, responseOut); | 430 didReceiveResponse(0, responseOut); |
| 431 if (m_state == Terminated) | 431 if (m_state == Terminated) |
| 432 return; | 432 return; |
| 433 RefPtr<ResourceLoadInfo> resourceLoadInfo = responseOut.toResourceResponse()
.resourceLoadInfo(); | 433 RefPtr<ResourceLoadInfo> resourceLoadInfo = responseOut.toResourceResponse()
.resourceLoadInfo(); |
| 434 m_host->didReceiveData(m_resource, dataOut.data(), dataOut.size(), resourceL
oadInfo ? resourceLoadInfo->encodedDataLength : -1, m_options); | 434 m_host->didReceiveData(m_resource, dataOut.data(), dataOut.size(), resourceL
oadInfo ? resourceLoadInfo->encodedDataLength : -1, m_options); |
| 435 m_resource->setResourceBuffer(dataOut); | 435 m_resource->setResourceBuffer(dataOut); |
| 436 didFinishLoading(0, monotonicallyIncreasingTime()); | 436 didFinishLoading(0, monotonicallyIncreasingTime()); |
| 437 } | 437 } |
| 438 | 438 |
| 439 } | 439 } |
| OLD | NEW |