OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "core/loader/resource/ImageResourceContent.h" | 5 #include "core/loader/resource/ImageResourceContent.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "core/loader/resource/ImageResource.h" | 9 #include "core/loader/resource/ImageResource.h" |
10 #include "core/loader/resource/ImageResourceInfo.h" | 10 #include "core/loader/resource/ImageResourceInfo.h" |
(...skipping 20 matching lines...) Expand all Loading... | |
31 public: | 31 public: |
32 NullImageResourceInfo() {} | 32 NullImageResourceInfo() {} |
33 | 33 |
34 DEFINE_INLINE_VIRTUAL_TRACE() { ImageResourceInfo::trace(visitor); } | 34 DEFINE_INLINE_VIRTUAL_TRACE() { ImageResourceInfo::trace(visitor); } |
35 | 35 |
36 private: | 36 private: |
37 const KURL& url() const override { return m_url; } | 37 const KURL& url() const override { return m_url; } |
38 bool hasDevicePixelRatioHeaderValue() const override { return false; } | 38 bool hasDevicePixelRatioHeaderValue() const override { return false; } |
39 float devicePixelRatioHeaderValue() const override { return 1.0; } | 39 float devicePixelRatioHeaderValue() const override { return 1.0; } |
40 const ResourceResponse& response() const override { return m_response; } | 40 const ResourceResponse& response() const override { return m_response; } |
41 ResourceStatus getStatus() const override { return ResourceStatus::Cached; } | |
42 bool shouldShowPlaceholder() const override { return false; } | 41 bool shouldShowPlaceholder() const override { return false; } |
43 bool isCacheValidator() const override { return false; } | 42 bool isCacheValidator() const override { return false; } |
44 bool isAccessAllowed( | 43 bool isAccessAllowed( |
45 SecurityOrigin*, | 44 SecurityOrigin*, |
46 DoesCurrentFrameHaveSingleSecurityOrigin) const override { | 45 DoesCurrentFrameHaveSingleSecurityOrigin) const override { |
47 return true; | 46 return true; |
48 } | 47 } |
49 bool hasCacheControlNoStoreHeader() const override { return false; } | 48 bool hasCacheControlNoStoreHeader() const override { return false; } |
50 const ResourceError& resourceError() const override { return m_error; } | 49 const ResourceError& resourceError() const override { return m_error; } |
51 | 50 |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
284 int64_t length = m_image->data() ? m_image->data()->size() : 0; | 283 int64_t length = m_image->data() ? m_image->data()->size() : 0; |
285 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-length); | 284 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-length); |
286 | 285 |
287 // If our Image has an observer, it's always us so we need to clear the back | 286 // If our Image has an observer, it's always us so we need to clear the back |
288 // pointer before dropping our reference. | 287 // pointer before dropping our reference. |
289 m_image->clearImageObserver(); | 288 m_image->clearImageObserver(); |
290 m_image.clear(); | 289 m_image.clear(); |
291 m_sizeAvailable = Image::SizeUnavailable; | 290 m_sizeAvailable = Image::SizeUnavailable; |
292 } | 291 } |
293 | 292 |
293 // |status| is the status of corresponding ImageResource. | |
294 void ImageResourceContent::updateStatus(ResourceStatus status, | |
295 NotifyFinishOption notifyFinishOption) { | |
296 switch (notifyFinishOption) { | |
297 case ShouldNotifyFinish: | |
298 // When |ShouldNotifyFinish|, we set |m_status| to a loaded | |
kouhei (in TOK)
2017/03/15 11:18:53
Can we have switch(status) here to ensure all stat
hiroshige
2017/05/04 20:21:57
Done.
| |
299 // ResourceStatus. | |
300 if (status == ResourceStatus::LoadError || | |
301 status == ResourceStatus::DecodeError) { | |
302 // In case of error, Resource's status is set to an error status before | |
303 // updateImage() and thus we use the error status also as | |
304 // ImageResourceContent's status. | |
305 m_status = status; | |
306 } else { | |
307 // In case of successful load, Resource's status might not be set to | |
308 // Cached here. Therefore we set |m_status| to Cached, regardless of | |
309 // |status|. | |
310 m_status = ResourceStatus::Cached; | |
311 } | |
312 break; | |
313 case DoNotNotifyFinish: | |
314 if (m_status == ResourceStatus::NotStarted) | |
kouhei (in TOK)
2017/03/15 11:18:53
Ditto
yhirano
2017/03/17 13:47:25
Can you tell me why this is needed? Setting the st
yhirano
2017/03/17 13:47:25
Is |status| arbitrary here? Can we put some DCHECK
hiroshige
2017/05/04 20:21:57
Right. I removed the transition in DoNotNotifyFini
hiroshige
2017/05/04 20:21:57
|status| shouldn't be kNotStarted.
Also, |status|
hiroshige
2017/05/04 20:21:57
Removed.
| |
315 m_status = ResourceStatus::Pending; | |
316 break; | |
317 } | |
318 } | |
319 | |
294 ImageResourceContent::UpdateImageResult ImageResourceContent::updateImage( | 320 ImageResourceContent::UpdateImageResult ImageResourceContent::updateImage( |
295 PassRefPtr<SharedBuffer> data, | 321 PassRefPtr<SharedBuffer> data, |
322 ResourceStatus status, | |
296 UpdateImageOption updateImageOption, | 323 UpdateImageOption updateImageOption, |
297 bool allDataReceived) { | 324 bool allDataReceived) { |
298 TRACE_EVENT0("blink", "ImageResourceContent::updateImage"); | 325 TRACE_EVENT0("blink", "ImageResourceContent::updateImage"); |
299 | 326 |
300 #if DCHECK_IS_ON() | 327 #if DCHECK_IS_ON() |
301 DCHECK(!m_isUpdateImageBeingCalled); | 328 DCHECK(!m_isUpdateImageBeingCalled); |
302 AutoReset<bool> scope(&m_isUpdateImageBeingCalled, true); | 329 AutoReset<bool> scope(&m_isUpdateImageBeingCalled, true); |
303 #endif | 330 #endif |
304 | 331 |
305 // Clears the existing image, if instructed by |updateImageOption|. | 332 // Clears the existing image, if instructed by |updateImageOption|. |
(...skipping 20 matching lines...) Expand all Loading... | |
326 if (data) { | 353 if (data) { |
327 if (!m_image) | 354 if (!m_image) |
328 m_image = createImage(); | 355 m_image = createImage(); |
329 DCHECK(m_image); | 356 DCHECK(m_image); |
330 m_sizeAvailable = m_image->setData(std::move(data), allDataReceived); | 357 m_sizeAvailable = m_image->setData(std::move(data), allDataReceived); |
331 } | 358 } |
332 | 359 |
333 // Go ahead and tell our observers to try to draw if we have either | 360 // Go ahead and tell our observers to try to draw if we have either |
334 // received all the data or the size is known. Each chunk from the network | 361 // received all the data or the size is known. Each chunk from the network |
335 // causes observers to repaint, which will force that chunk to decode. | 362 // causes observers to repaint, which will force that chunk to decode. |
336 if (m_sizeAvailable == Image::SizeUnavailable && !allDataReceived) | 363 if (m_sizeAvailable == Image::SizeUnavailable && !allDataReceived) { |
364 updateStatus(status, DoNotNotifyFinish); | |
337 return UpdateImageResult::NoDecodeError; | 365 return UpdateImageResult::NoDecodeError; |
366 } | |
338 | 367 |
339 if (m_info->shouldShowPlaceholder() && allDataReceived) { | 368 if (m_info->shouldShowPlaceholder() && allDataReceived) { |
340 if (m_image && !m_image->isNull()) { | 369 if (m_image && !m_image->isNull()) { |
341 IntSize dimensions = m_image->size(); | 370 IntSize dimensions = m_image->size(); |
342 clearImage(); | 371 clearImage(); |
343 m_image = PlaceholderImage::create(this, dimensions); | 372 m_image = PlaceholderImage::create(this, dimensions); |
344 } | 373 } |
345 } | 374 } |
346 | 375 |
347 if (!m_image || m_image->isNull()) { | 376 if (!m_image || m_image->isNull()) { |
348 clearImage(); | 377 clearImage(); |
378 updateStatus(status, DoNotNotifyFinish); | |
349 return UpdateImageResult::ShouldDecodeError; | 379 return UpdateImageResult::ShouldDecodeError; |
350 } | 380 } |
351 break; | 381 break; |
352 } | 382 } |
353 | 383 |
354 // Notifies the observers. | 384 // Notifies the observers. |
355 // It would be nice to only redraw the decoded band of the image, but with the | 385 // It would be nice to only redraw the decoded band of the image, but with the |
356 // current design (decoding delayed until painting) that seems hard. | 386 // current design (decoding delayed until painting) that seems hard. |
357 notifyObservers(allDataReceived ? ShouldNotifyFinish : DoNotNotifyFinish); | 387 |
388 NotifyFinishOption notifyFinishOption = | |
389 allDataReceived ? ShouldNotifyFinish : DoNotNotifyFinish; | |
390 updateStatus(status, notifyFinishOption); | |
391 notifyObservers(notifyFinishOption); | |
358 return UpdateImageResult::NoDecodeError; | 392 return UpdateImageResult::NoDecodeError; |
359 } | 393 } |
360 | 394 |
395 void ImageResourceContent::notifyStartLoad() { | |
yhirano
2017/03/17 13:47:25
DCHECK_EQ(m_status, NotStarted)?
hiroshige
2017/05/04 20:21:57
Not necessarily NotStarted, e.g. in the case of re
| |
396 m_status = ResourceStatus::Pending; | |
kouhei (in TOK)
2017/03/15 11:18:53
Can we always update status via updateStatus?
hiroshige
2017/05/04 20:21:57
I removed UpdateStatus(kDoNotNotifyFinish) case an
| |
397 } | |
398 | |
361 void ImageResourceContent::decodedSizeChangedTo(const blink::Image* image, | 399 void ImageResourceContent::decodedSizeChangedTo(const blink::Image* image, |
362 size_t newSize) { | 400 size_t newSize) { |
363 if (!image || image != m_image) | 401 if (!image || image != m_image) |
364 return; | 402 return; |
365 | 403 |
366 m_info->setDecodedSize(newSize); | 404 m_info->setDecodedSize(newSize); |
367 } | 405 } |
368 | 406 |
369 bool ImageResourceContent::shouldPauseAnimation(const blink::Image* image) { | 407 bool ImageResourceContent::shouldPauseAnimation(const blink::Image* image) { |
370 if (!image || image != m_image) | 408 if (!image || image != m_image) |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
443 bool ImageResourceContent::errorOccurred() const { | 481 bool ImageResourceContent::errorOccurred() const { |
444 return getStatus() == ResourceStatus::LoadError || | 482 return getStatus() == ResourceStatus::LoadError || |
445 getStatus() == ResourceStatus::DecodeError; | 483 getStatus() == ResourceStatus::DecodeError; |
446 } | 484 } |
447 | 485 |
448 bool ImageResourceContent::loadFailedOrCanceled() const { | 486 bool ImageResourceContent::loadFailedOrCanceled() const { |
449 return getStatus() == ResourceStatus::LoadError; | 487 return getStatus() == ResourceStatus::LoadError; |
450 } | 488 } |
451 | 489 |
452 ResourceStatus ImageResourceContent::getStatus() const { | 490 ResourceStatus ImageResourceContent::getStatus() const { |
453 return m_info->getStatus(); | 491 return m_status; |
454 } | 492 } |
455 | 493 |
456 const KURL& ImageResourceContent::url() const { | 494 const KURL& ImageResourceContent::url() const { |
457 return m_info->url(); | 495 return m_info->url(); |
458 } | 496 } |
459 | 497 |
460 bool ImageResourceContent::hasCacheControlNoStoreHeader() const { | 498 bool ImageResourceContent::hasCacheControlNoStoreHeader() const { |
461 return m_info->hasCacheControlNoStoreHeader(); | 499 return m_info->hasCacheControlNoStoreHeader(); |
462 } | 500 } |
463 | 501 |
464 float ImageResourceContent::devicePixelRatioHeaderValue() const { | 502 float ImageResourceContent::devicePixelRatioHeaderValue() const { |
465 return m_info->devicePixelRatioHeaderValue(); | 503 return m_info->devicePixelRatioHeaderValue(); |
466 } | 504 } |
467 | 505 |
468 bool ImageResourceContent::hasDevicePixelRatioHeaderValue() const { | 506 bool ImageResourceContent::hasDevicePixelRatioHeaderValue() const { |
469 return m_info->hasDevicePixelRatioHeaderValue(); | 507 return m_info->hasDevicePixelRatioHeaderValue(); |
470 } | 508 } |
471 | 509 |
472 const ResourceResponse& ImageResourceContent::response() const { | 510 const ResourceResponse& ImageResourceContent::response() const { |
473 return m_info->response(); | 511 return m_info->response(); |
474 } | 512 } |
475 | 513 |
476 const ResourceError& ImageResourceContent::resourceError() const { | 514 const ResourceError& ImageResourceContent::resourceError() const { |
477 return m_info->resourceError(); | 515 return m_info->resourceError(); |
478 } | 516 } |
479 | 517 |
480 } // namespace blink | 518 } // namespace blink |
OLD | NEW |