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 Apple Inc. All rights reserved. | 6 Copyright (C) 2004, 2005, 2006, 2007 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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 // about to be reloaded. | 232 // about to be reloaded. |
233 if (m_isSchedulingReload || shouldReloadBrokenPlaceholder()) | 233 if (m_isSchedulingReload || shouldReloadBrokenPlaceholder()) |
234 return; | 234 return; |
235 | 235 |
236 Resource::didAddClient(client); | 236 Resource::didAddClient(client); |
237 } | 237 } |
238 | 238 |
239 void ImageResource::destroyDecodedDataForFailedRevalidation() { | 239 void ImageResource::destroyDecodedDataForFailedRevalidation() { |
240 // Clears the image, as we must create a new image for the failed | 240 // Clears the image, as we must create a new image for the failed |
241 // revalidation response. | 241 // revalidation response. |
242 getContent()->updateImage(nullptr, ImageResourceContent::ClearAndUpdateImage, | 242 updateImage(nullptr, ImageResourceContent::ClearAndUpdateImage, false); |
243 false); | |
244 setDecodedSize(0); | 243 setDecodedSize(0); |
245 } | 244 } |
246 | 245 |
247 void ImageResource::destroyDecodedDataIfPossible() { | 246 void ImageResource::destroyDecodedDataIfPossible() { |
248 getContent()->destroyDecodedData(); | 247 getContent()->destroyDecodedData(); |
249 if (getContent()->hasImage() && !isPreloaded() && | 248 if (getContent()->hasImage() && !isPreloaded() && |
250 getContent()->isRefetchableDataFromDiskCache()) { | 249 getContent()->isRefetchableDataFromDiskCache()) { |
251 UMA_HISTOGRAM_MEMORY_KB("Memory.Renderer.EstimatedDroppableEncodedSize", | 250 UMA_HISTOGRAM_MEMORY_KB("Memory.Renderer.EstimatedDroppableEncodedSize", |
252 encodedSize() / 1024); | 251 encodedSize() / 1024); |
253 } | 252 } |
(...skipping 24 matching lines...) Expand all Loading... |
278 | 277 |
279 void ImageResource::appendData(const char* data, size_t length) { | 278 void ImageResource::appendData(const char* data, size_t length) { |
280 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(length); | 279 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(length); |
281 if (m_multipartParser) { | 280 if (m_multipartParser) { |
282 m_multipartParser->appendData(data, length); | 281 m_multipartParser->appendData(data, length); |
283 } else { | 282 } else { |
284 Resource::appendData(data, length); | 283 Resource::appendData(data, length); |
285 | 284 |
286 // Update the image immediately if needed. | 285 // Update the image immediately if needed. |
287 if (getContent()->shouldUpdateImageImmediately()) { | 286 if (getContent()->shouldUpdateImageImmediately()) { |
288 getContent()->updateImage(this->data(), ImageResourceContent::UpdateImage, | 287 updateImage(this->data(), ImageResourceContent::UpdateImage, false); |
289 false); | |
290 return; | 288 return; |
291 } | 289 } |
292 | 290 |
293 // For other cases, only update at |kFlushDelaySeconds| intervals. This | 291 // For other cases, only update at |kFlushDelaySeconds| intervals. This |
294 // throttles how frequently we update |m_image| and how frequently we | 292 // throttles how frequently we update |m_image| and how frequently we |
295 // inform the clients which causes an invalidation of this image. In other | 293 // inform the clients which causes an invalidation of this image. In other |
296 // words, we only invalidate this image every |kFlushDelaySeconds| seconds | 294 // words, we only invalidate this image every |kFlushDelaySeconds| seconds |
297 // while loading. | 295 // while loading. |
298 if (!m_flushTimer.isActive()) { | 296 if (!m_flushTimer.isActive()) { |
299 double now = WTF::monotonicallyIncreasingTime(); | 297 double now = WTF::monotonicallyIncreasingTime(); |
300 if (!m_lastFlushTime) | 298 if (!m_lastFlushTime) |
301 m_lastFlushTime = now; | 299 m_lastFlushTime = now; |
302 | 300 |
303 DCHECK_LE(m_lastFlushTime, now); | 301 DCHECK_LE(m_lastFlushTime, now); |
304 double flushDelay = m_lastFlushTime - now + kFlushDelaySeconds; | 302 double flushDelay = m_lastFlushTime - now + kFlushDelaySeconds; |
305 if (flushDelay < 0.) | 303 if (flushDelay < 0.) |
306 flushDelay = 0.; | 304 flushDelay = 0.; |
307 m_flushTimer.startOneShot(flushDelay, BLINK_FROM_HERE); | 305 m_flushTimer.startOneShot(flushDelay, BLINK_FROM_HERE); |
308 } | 306 } |
309 } | 307 } |
310 } | 308 } |
311 | 309 |
312 void ImageResource::flushImageIfNeeded(TimerBase*) { | 310 void ImageResource::flushImageIfNeeded(TimerBase*) { |
313 // We might have already loaded the image fully, in which case we don't need | 311 // We might have already loaded the image fully, in which case we don't need |
314 // to call |updateImage()|. | 312 // to call |updateImage()|. |
315 if (isLoading()) { | 313 if (isLoading()) { |
316 m_lastFlushTime = WTF::monotonicallyIncreasingTime(); | 314 m_lastFlushTime = WTF::monotonicallyIncreasingTime(); |
317 getContent()->updateImage(this->data(), ImageResourceContent::UpdateImage, | 315 updateImage(this->data(), ImageResourceContent::UpdateImage, false); |
318 false); | |
319 } | 316 } |
320 } | 317 } |
321 | 318 |
322 bool ImageResource::willPaintBrokenImage() const { | 319 bool ImageResource::willPaintBrokenImage() const { |
323 return errorOccurred(); | 320 return errorOccurred(); |
324 } | 321 } |
325 | 322 |
326 void ImageResource::decodeError(bool allDataReceived) { | 323 void ImageResource::decodeError(bool allDataReceived) { |
327 size_t size = encodedSize(); | 324 size_t size = encodedSize(); |
328 | 325 |
329 clearData(); | 326 clearData(); |
330 setEncodedSize(0); | 327 setEncodedSize(0); |
331 if (!errorOccurred()) | 328 if (!errorOccurred()) |
332 setStatus(DecodeError); | 329 setStatus(DecodeError); |
333 | 330 |
334 if (!allDataReceived && loader()) { | 331 if (!allDataReceived && loader()) { |
335 // TODO(hiroshige): Do not call didFinishLoading() directly. | 332 // TODO(hiroshige): Do not call didFinishLoading() directly. |
336 loader()->didFinishLoading(monotonicallyIncreasingTime(), size, size); | 333 loader()->didFinishLoading(monotonicallyIncreasingTime(), size, size); |
337 } | 334 } |
338 | 335 |
339 memoryCache()->remove(this); | 336 memoryCache()->remove(this); |
340 } | 337 } |
341 | 338 |
342 void ImageResource::updateImageAndClearBuffer() { | 339 void ImageResource::updateImageAndClearBuffer() { |
343 getContent()->updateImage(data(), ImageResourceContent::ClearAndUpdateImage, | 340 updateImage(data(), ImageResourceContent::ClearAndUpdateImage, true); |
344 true); | |
345 clearData(); | 341 clearData(); |
346 } | 342 } |
347 | 343 |
348 void ImageResource::finish(double loadFinishTime) { | 344 void ImageResource::finish(double loadFinishTime) { |
349 if (m_multipartParser) { | 345 if (m_multipartParser) { |
350 m_multipartParser->finish(); | 346 m_multipartParser->finish(); |
351 if (data()) | 347 if (data()) |
352 updateImageAndClearBuffer(); | 348 updateImageAndClearBuffer(); |
353 } else { | 349 } else { |
354 getContent()->updateImage(data(), ImageResourceContent::UpdateImage, true); | 350 updateImage(data(), ImageResourceContent::UpdateImage, true); |
355 // As encoded image data can be created from m_image (see | 351 // As encoded image data can be created from m_image (see |
356 // ImageResource::resourceBuffer(), we don't have to keep m_data. Let's | 352 // ImageResource::resourceBuffer(), we don't have to keep m_data. Let's |
357 // clear this. As for the lifetimes of m_image and m_data, see this | 353 // clear this. As for the lifetimes of m_image and m_data, see this |
358 // document: | 354 // document: |
359 // https://docs.google.com/document/d/1v0yTAZ6wkqX2U_M6BNIGUJpM1s0TIw1Vsqpxo
L7aciY/edit?usp=sharing | 355 // https://docs.google.com/document/d/1v0yTAZ6wkqX2U_M6BNIGUJpM1s0TIw1Vsqpxo
L7aciY/edit?usp=sharing |
360 clearData(); | 356 clearData(); |
361 } | 357 } |
362 Resource::finish(loadFinishTime); | 358 Resource::finish(loadFinishTime); |
363 } | 359 } |
364 | 360 |
365 void ImageResource::error(const ResourceError& error) { | 361 void ImageResource::error(const ResourceError& error) { |
366 if (m_multipartParser) | 362 if (m_multipartParser) |
367 m_multipartParser->cancel(); | 363 m_multipartParser->cancel(); |
368 // TODO(hiroshige): Move setEncodedSize() call to Resource::error() if it | 364 // TODO(hiroshige): Move setEncodedSize() call to Resource::error() if it |
369 // is really needed, or remove it otherwise. | 365 // is really needed, or remove it otherwise. |
370 setEncodedSize(0); | 366 setEncodedSize(0); |
371 Resource::error(error); | 367 Resource::error(error); |
372 getContent()->updateImage(nullptr, ImageResourceContent::ClearImageOnly, | 368 updateImage(nullptr, ImageResourceContent::ClearImageOnly, true); |
373 true); | |
374 } | 369 } |
375 | 370 |
376 void ImageResource::responseReceived( | 371 void ImageResource::responseReceived( |
377 const ResourceResponse& response, | 372 const ResourceResponse& response, |
378 std::unique_ptr<WebDataConsumerHandle> handle) { | 373 std::unique_ptr<WebDataConsumerHandle> handle) { |
379 DCHECK(!handle); | 374 DCHECK(!handle); |
380 DCHECK(!m_multipartParser); | 375 DCHECK(!m_multipartParser); |
381 // If there's no boundary, just handle the request normally. | 376 // If there's no boundary, just handle the request normally. |
382 if (response.isMultipart() && !response.multipartBoundary().isEmpty()) { | 377 if (response.isMultipart() && !response.multipartBoundary().isEmpty()) { |
383 m_multipartParser = new MultipartImageResourceParser( | 378 m_multipartParser = new MultipartImageResourceParser( |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 } | 427 } |
433 | 428 |
434 if (isLoading()) { | 429 if (isLoading()) { |
435 loader()->cancel(); | 430 loader()->cancel(); |
436 // Canceling the loader causes error() to be called, which in turn calls | 431 // Canceling the loader causes error() to be called, which in turn calls |
437 // clear() and notifyObservers(), so there's no need to call these again | 432 // clear() and notifyObservers(), so there's no need to call these again |
438 // here. | 433 // here. |
439 } else { | 434 } else { |
440 clearData(); | 435 clearData(); |
441 setEncodedSize(0); | 436 setEncodedSize(0); |
442 getContent()->updateImage(nullptr, ImageResourceContent::ClearImageOnly, | 437 updateImage(nullptr, ImageResourceContent::ClearImageOnly, false); |
443 false); | |
444 } | 438 } |
445 | 439 |
446 setStatus(NotStarted); | 440 setStatus(NotStarted); |
447 | 441 |
448 DCHECK(m_isSchedulingReload); | 442 DCHECK(m_isSchedulingReload); |
449 m_isSchedulingReload = false; | 443 m_isSchedulingReload = false; |
450 | 444 |
451 fetcher->startLoad(this); | 445 fetcher->startLoad(this); |
452 } | 446 } |
453 | 447 |
454 void ImageResource::onePartInMultipartReceived( | 448 void ImageResource::onePartInMultipartReceived( |
455 const ResourceResponse& response) { | 449 const ResourceResponse& response) { |
456 DCHECK(m_multipartParser); | 450 DCHECK(m_multipartParser); |
457 | 451 |
458 setResponse(response); | 452 setResponse(response); |
459 if (m_multipartParsingState == MultipartParsingState::WaitingForFirstPart) { | 453 if (m_multipartParsingState == MultipartParsingState::WaitingForFirstPart) { |
460 // We have nothing to do because we don't have any data. | 454 // We have nothing to do because we don't have any data. |
461 m_multipartParsingState = MultipartParsingState::ParsingFirstPart; | 455 m_multipartParsingState = MultipartParsingState::ParsingFirstPart; |
462 return; | 456 return; |
463 } | 457 } |
464 updateImageAndClearBuffer(); | 458 updateImageAndClearBuffer(); |
| 459 // We should create a new image again when the data for the next part arrive, |
| 460 // so reset |m_isUpdateImageCalled| here. |
| 461 m_isUpdateImageCalled = false; |
465 | 462 |
466 if (m_multipartParsingState == MultipartParsingState::ParsingFirstPart) { | 463 if (m_multipartParsingState == MultipartParsingState::ParsingFirstPart) { |
467 m_multipartParsingState = MultipartParsingState::FinishedParsingFirstPart; | 464 m_multipartParsingState = MultipartParsingState::FinishedParsingFirstPart; |
468 // Notify finished when the first part ends. | 465 // Notify finished when the first part ends. |
469 if (!errorOccurred()) | 466 if (!errorOccurred()) |
470 setStatus(Cached); | 467 setStatus(Cached); |
471 // We notify clients and observers of finish in checkNotify() and | 468 // We notify clients and observers of finish in checkNotify() and |
472 // updateImageAndClearBuffer(), respectively, and they will not be | 469 // updateImageAndClearBuffer(), respectively, and they will not be |
473 // notified again in Resource::finish()/error(). | 470 // notified again in Resource::finish()/error(). |
474 checkNotify(); | 471 checkNotify(); |
(...skipping 28 matching lines...) Expand all Loading... |
503 } | 500 } |
504 | 501 |
505 const ImageResourceContent* ImageResource::getContent() const { | 502 const ImageResourceContent* ImageResource::getContent() const { |
506 return m_content; | 503 return m_content; |
507 } | 504 } |
508 | 505 |
509 ResourcePriority ImageResource::priorityFromObservers() { | 506 ResourcePriority ImageResource::priorityFromObservers() { |
510 return getContent()->priorityFromObservers(); | 507 return getContent()->priorityFromObservers(); |
511 } | 508 } |
512 | 509 |
| 510 void ImageResource::updateImage( |
| 511 PassRefPtr<SharedBuffer> sharedBuffer, |
| 512 ImageResourceContent::UpdateImageOption updateImageOption, |
| 513 bool allDataReceived) { |
| 514 if (!m_isUpdateImageCalled && |
| 515 updateImageOption == ImageResourceContent::UpdateImage) |
| 516 updateImageOption = ImageResourceContent::ClearAndUpdateImage; |
| 517 m_isUpdateImageCalled = true; |
| 518 getContent()->updateImage(std::move(sharedBuffer), updateImageOption, |
| 519 allDataReceived); |
| 520 } |
| 521 |
513 } // namespace blink | 522 } // namespace blink |
OLD | NEW |