Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) | 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) |
| 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) | 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) |
| 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) | 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) |
| 5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) | 5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
| 6 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. | 6 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. |
| 7 | 7 |
| 8 This library is free software; you can redistribute it and/or | 8 This library is free software; you can redistribute it and/or |
| 9 modify it under the terms of the GNU Library General Public | 9 modify it under the terms of the GNU Library General Public |
| 10 License as published by the Free Software Foundation; either | 10 License as published by the Free Software Foundation; either |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 197 { | 197 { |
| 198 InspectorInstrumentation::removedResourceFromMemoryCache(this); | 198 InspectorInstrumentation::removedResourceFromMemoryCache(this); |
| 199 } | 199 } |
| 200 | 200 |
| 201 DEFINE_TRACE(Resource) | 201 DEFINE_TRACE(Resource) |
| 202 { | 202 { |
| 203 visitor->trace(m_loader); | 203 visitor->trace(m_loader); |
| 204 #if ENABLE(OILPAN) | 204 #if ENABLE(OILPAN) |
| 205 visitor->trace(m_cacheHandler); | 205 visitor->trace(m_cacheHandler); |
| 206 #endif | 206 #endif |
| 207 visitor->trace(m_multipartParser); | |
| 208 MultipartImageResourceParser::Client::trace(visitor); | |
| 209 } | 207 } |
| 210 | 208 |
| 211 void Resource::load(ResourceFetcher* fetcher, const ResourceLoaderOptions& optio ns) | 209 void Resource::load(ResourceFetcher* fetcher, const ResourceLoaderOptions& optio ns) |
| 212 { | 210 { |
| 213 m_options = options; | 211 m_options = options; |
| 214 m_loading = true; | 212 m_loading = true; |
| 215 | 213 |
| 216 ResourceRequest request(m_revalidatingRequest.isNull() ? m_resourceRequest : m_revalidatingRequest); | 214 ResourceRequest request(m_revalidatingRequest.isNull() ? m_resourceRequest : m_revalidatingRequest); |
| 217 if (!accept().isEmpty()) | 215 if (!accept().isEmpty()) |
| 218 request.setHTTPAccept(accept()); | 216 request.setHTTPAccept(accept()); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 242 return; | 240 return; |
| 243 | 241 |
| 244 ResourceClientWalker<ResourceClient> w(m_clients); | 242 ResourceClientWalker<ResourceClient> w(m_clients); |
| 245 while (ResourceClient* c = w.next()) | 243 while (ResourceClient* c = w.next()) |
| 246 c->notifyFinished(this); | 244 c->notifyFinished(this); |
| 247 } | 245 } |
| 248 | 246 |
| 249 void Resource::appendData(const char* data, size_t length) | 247 void Resource::appendData(const char* data, size_t length) |
| 250 { | 248 { |
| 251 TRACE_EVENT0("blink", "Resource::appendData"); | 249 TRACE_EVENT0("blink", "Resource::appendData"); |
| 252 if (isMultipartImage()) { | |
| 253 m_multipartParser->addData(data, length); | |
| 254 return; | |
| 255 } | |
| 256 appendDataInternal(data, length); | |
| 257 } | |
| 258 | |
| 259 void Resource::appendDataInternal(const char* data, size_t length) | |
| 260 { | |
| 261 ASSERT(m_revalidatingRequest.isNull()); | 250 ASSERT(m_revalidatingRequest.isNull()); |
| 262 ASSERT(!errorOccurred()); | 251 ASSERT(!errorOccurred()); |
| 263 if (m_options.dataBufferingPolicy == DoNotBufferData) | 252 if (m_options.dataBufferingPolicy == DoNotBufferData) |
| 264 return; | 253 return; |
| 265 if (m_data) | 254 if (m_data) |
| 266 m_data->append(data, length); | 255 m_data->append(data, length); |
| 267 else | 256 else |
| 268 m_data = SharedBuffer::createPurgeable(data, length); | 257 m_data = SharedBuffer::createPurgeable(data, length); |
| 269 setEncodedSize(m_data->size()); | 258 setEncodedSize(m_data->size()); |
| 270 } | 259 } |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 291 HashCountedSet<ResourceClient*>::iterator it = m_clients.begin(); | 280 HashCountedSet<ResourceClient*>::iterator it = m_clients.begin(); |
| 292 for (int i = it->value; i; i--) { | 281 for (int i = it->value; i; i--) { |
| 293 m_finishedClients.add(it->key); | 282 m_finishedClients.add(it->key); |
| 294 m_clients.remove(it); | 283 m_clients.remove(it); |
| 295 } | 284 } |
| 296 } | 285 } |
| 297 } | 286 } |
| 298 | 287 |
| 299 void Resource::error(Resource::Status status) | 288 void Resource::error(Resource::Status status) |
| 300 { | 289 { |
| 301 if (m_multipartParser) | |
| 302 m_multipartParser->cancel(); | |
| 303 | |
| 304 if (!m_revalidatingRequest.isNull()) | 290 if (!m_revalidatingRequest.isNull()) |
| 305 m_revalidatingRequest = ResourceRequest(); | 291 m_revalidatingRequest = ResourceRequest(); |
| 306 | 292 |
| 307 if (!m_error.isNull() && (m_error.isCancellation() || !isPreloaded())) | 293 if (!m_error.isNull() && (m_error.isCancellation() || !isPreloaded())) |
| 308 memoryCache()->remove(this); | 294 memoryCache()->remove(this); |
| 309 | 295 |
| 310 setStatus(status); | 296 setStatus(status); |
| 311 ASSERT(errorOccurred()); | 297 ASSERT(errorOccurred()); |
| 312 m_data.clear(); | 298 m_data.clear(); |
| 313 | 299 |
| 314 setLoading(false); | 300 setLoading(false); |
| 315 checkNotify(); | 301 checkNotify(); |
| 316 markClientsFinished(); | 302 markClientsFinished(); |
| 317 } | 303 } |
| 318 | 304 |
| 319 void Resource::finishOnePart() | |
| 320 { | |
| 321 setLoading(false); | |
| 322 checkNotify(); | |
| 323 } | |
| 324 | |
| 325 void Resource::finish() | 305 void Resource::finish() |
| 326 { | 306 { |
| 327 ASSERT(m_revalidatingRequest.isNull()); | 307 ASSERT(m_revalidatingRequest.isNull()); |
| 328 ASSERT(!errorOccurred()); | 308 setLoading(false); |
|
hiroshige
2016/02/26 19:03:35
What is the reason for removing ASSERT(!errorOccur
yhirano
2016/02/27 02:03:20
It's possible that m_status is modified in ImageRe
| |
| 329 if (m_multipartParser) | 309 checkNotify(); |
| 330 m_multipartParser->finish(); | |
| 331 | |
| 332 finishOnePart(); | |
| 333 markClientsFinished(); | 310 markClientsFinished(); |
| 334 if (!errorOccurred()) | 311 if (!errorOccurred()) |
| 335 m_status = Cached; | 312 m_status = Cached; |
| 336 } | 313 } |
| 337 | 314 |
| 338 bool Resource::passesAccessControlCheck(SecurityOrigin* securityOrigin) const | 315 bool Resource::passesAccessControlCheck(SecurityOrigin* securityOrigin) const |
| 339 { | 316 { |
| 340 String ignoredErrorDescription; | 317 String ignoredErrorDescription; |
| 341 return passesAccessControlCheck(securityOrigin, ignoredErrorDescription); | 318 return passesAccessControlCheck(securityOrigin, ignoredErrorDescription); |
| 342 } | 319 } |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 466 { | 443 { |
| 467 m_responseTimestamp = currentTime(); | 444 m_responseTimestamp = currentTime(); |
| 468 | 445 |
| 469 if (!m_revalidatingRequest.isNull()) { | 446 if (!m_revalidatingRequest.isNull()) { |
| 470 if (response.httpStatusCode() == 304) { | 447 if (response.httpStatusCode() == 304) { |
| 471 revalidationSucceeded(response); | 448 revalidationSucceeded(response); |
| 472 return; | 449 return; |
| 473 } | 450 } |
| 474 revalidationFailed(); | 451 revalidationFailed(); |
| 475 } | 452 } |
| 476 // If there's no boundary, just handle the request normally. In the gecko | |
| 477 // code, nsMultiMixedConv::OnStartRequest throws an exception. | |
| 478 if (response.isMultipart() && !response.multipartBoundary().isEmpty() && (m_ type == Resource::Image || m_type == Resource::MainResource) && !m_multipartPars er) | |
| 479 m_multipartParser = new MultipartImageResourceParser(response, response. multipartBoundary(), this); | |
| 480 setResponse(response); | 453 setResponse(response); |
| 481 String encoding = response.textEncodingName(); | 454 String encoding = response.textEncodingName(); |
| 482 if (!encoding.isNull()) | 455 if (!encoding.isNull()) |
| 483 setEncoding(encoding); | 456 setEncoding(encoding); |
| 484 } | 457 } |
| 485 | 458 |
| 486 void Resource::setSerializedCachedMetadata(const char* data, size_t size) | 459 void Resource::setSerializedCachedMetadata(const char* data, size_t size) |
| 487 { | 460 { |
| 488 // We only expect to receive cached metadata from the platform once. | 461 // We only expect to receive cached metadata from the platform once. |
| 489 // If this triggers, it indicates an efficiency problem which is most | 462 // If this triggers, it indicates an efficiency problem which is most |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 529 | 502 |
| 530 WeakPtrWillBeRawPtr<Resource> Resource::asWeakPtr() | 503 WeakPtrWillBeRawPtr<Resource> Resource::asWeakPtr() |
| 531 { | 504 { |
| 532 #if ENABLE(OILPAN) | 505 #if ENABLE(OILPAN) |
| 533 return this; | 506 return this; |
| 534 #else | 507 #else |
| 535 return m_weakPtrFactory.createWeakPtr(); | 508 return m_weakPtrFactory.createWeakPtr(); |
| 536 #endif | 509 #endif |
| 537 } | 510 } |
| 538 | 511 |
| 539 bool Resource::isMultipartImage() const | |
| 540 { | |
| 541 return m_multipartParser; | |
| 542 } | |
| 543 | |
| 544 void Resource::didReceiveResponse(const ResourceResponse& response) | |
| 545 { | |
| 546 ASSERT(isMultipartImage()); | |
| 547 responseReceived(response, nullptr); | |
| 548 if (response.isMultipartPayload()) { | |
| 549 // Since a subresource loader does not load multipart sections progressi vely, data was delivered to the loader all at once. | |
| 550 // After the first multipart section is complete, signal to delegates th at this load is "finished" | |
| 551 m_loader->fetcher()->subresourceLoaderFinishedLoadingOnePart(m_loader); | |
| 552 if (m_loader) | |
| 553 m_loader->didFinishLoadingOnePart(0, WebURLLoaderClient::kUnknownEnc odedDataLength); | |
| 554 } | |
| 555 } | |
| 556 | |
| 557 void Resource::didReceiveData(const char* bytes, size_t size) | |
| 558 { | |
| 559 ASSERT(isMultipartImage()); | |
| 560 appendDataInternal(bytes, size); | |
| 561 } | |
| 562 | |
| 563 String Resource::reasonNotDeletable() const | 512 String Resource::reasonNotDeletable() const |
| 564 { | 513 { |
| 565 StringBuilder builder; | 514 StringBuilder builder; |
| 566 if (hasClients()) { | 515 if (hasClients()) { |
| 567 builder.append("hasClients("); | 516 builder.append("hasClients("); |
| 568 builder.appendNumber(m_clients.size()); | 517 builder.appendNumber(m_clients.size()); |
| 569 if (!m_clientsAwaitingCallback.isEmpty()) { | 518 if (!m_clientsAwaitingCallback.isEmpty()) { |
| 570 builder.append(", AwaitingCallback="); | 519 builder.append(", AwaitingCallback="); |
| 571 builder.appendNumber(m_clientsAwaitingCallback.size()); | 520 builder.appendNumber(m_clientsAwaitingCallback.size()); |
| 572 } | 521 } |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 706 | 655 |
| 707 void Resource::allClientsRemoved() | 656 void Resource::allClientsRemoved() |
| 708 { | 657 { |
| 709 if (!m_loader) | 658 if (!m_loader) |
| 710 return; | 659 return; |
| 711 if (m_type == MainResource || m_type == Raw || !memoryCache()->contains(this )) | 660 if (m_type == MainResource || m_type == Raw || !memoryCache()->contains(this )) |
| 712 cancelTimerFired(&m_cancelTimer); | 661 cancelTimerFired(&m_cancelTimer); |
| 713 else if (!m_cancelTimer.isActive()) | 662 else if (!m_cancelTimer.isActive()) |
| 714 m_cancelTimer.startOneShot(0, BLINK_FROM_HERE); | 663 m_cancelTimer.startOneShot(0, BLINK_FROM_HERE); |
| 715 | 664 |
| 716 if (m_multipartParser) | |
| 717 m_multipartParser->cancel(); | |
| 718 unlock(); | 665 unlock(); |
| 719 } | 666 } |
| 720 | 667 |
| 721 void Resource::cancelTimerFired(Timer<Resource>* timer) | 668 void Resource::cancelTimerFired(Timer<Resource>* timer) |
| 722 { | 669 { |
| 723 ASSERT_UNUSED(timer, timer == &m_cancelTimer); | 670 ASSERT_UNUSED(timer, timer == &m_cancelTimer); |
| 724 if (hasClients() || !m_loader) | 671 if (hasClients() || !m_loader) |
| 725 return; | 672 return; |
| 726 RefPtrWillBeRawPtr<Resource> protect(this); | 673 RefPtrWillBeRawPtr<Resource> protect(this); |
| 727 m_loader->cancelIfNotFinishing(); | 674 m_loader->cancelIfNotFinishing(); |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1157 case Resource::Media: | 1104 case Resource::Media: |
| 1158 return "Media"; | 1105 return "Media"; |
| 1159 case Resource::Manifest: | 1106 case Resource::Manifest: |
| 1160 return "Manifest"; | 1107 return "Manifest"; |
| 1161 } | 1108 } |
| 1162 ASSERT_NOT_REACHED(); | 1109 ASSERT_NOT_REACHED(); |
| 1163 return "Unknown"; | 1110 return "Unknown"; |
| 1164 } | 1111 } |
| 1165 | 1112 |
| 1166 } // namespace blink | 1113 } // namespace blink |
| OLD | NEW |