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 29 matching lines...) Expand all Loading... | |
40 #include "platform/loader/fetch/ResourceLoaderOptions.h" | 40 #include "platform/loader/fetch/ResourceLoaderOptions.h" |
41 #include "platform/loader/fetch/ResourceLoadingLog.h" | 41 #include "platform/loader/fetch/ResourceLoadingLog.h" |
42 #include "platform/network/HTTPParsers.h" | 42 #include "platform/network/HTTPParsers.h" |
43 #include "platform/weborigin/SecurityViolationReportingPolicy.h" | 43 #include "platform/weborigin/SecurityViolationReportingPolicy.h" |
44 #include "platform/wtf/CurrentTime.h" | 44 #include "platform/wtf/CurrentTime.h" |
45 #include "platform/wtf/StdLibExtras.h" | 45 #include "platform/wtf/StdLibExtras.h" |
46 #include "public/platform/Platform.h" | 46 #include "public/platform/Platform.h" |
47 #include "v8/include/v8.h" | 47 #include "v8/include/v8.h" |
48 | 48 |
49 namespace blink { | 49 namespace blink { |
50 | |
50 namespace { | 51 namespace { |
52 | |
51 // The amount of time to wait before informing the clients that the image has | 53 // The amount of time to wait before informing the clients that the image has |
52 // been updated (in seconds). This effectively throttles invalidations that | 54 // been updated (in seconds). This effectively throttles invalidations that |
53 // result from new data arriving for this image. | 55 // result from new data arriving for this image. |
54 constexpr double kFlushDelaySeconds = 1.; | 56 constexpr double kFlushDelaySeconds = 1.; |
57 | |
58 bool HasServerLoFiResponseHeaders(const ResourceResponse& response) { | |
59 return response.HttpHeaderField("chrome-proxy-content-transform") | |
60 .Contains("empty-image") || | |
61 response.HttpHeaderField("chrome-proxy").Contains("q=low"); | |
megjablon
2017/06/13 19:26:14
Can you add a comment that we still check q=low be
sclittle
2017/06/13 20:53:23
Done.
| |
62 } | |
63 | |
55 } // namespace | 64 } // namespace |
56 | 65 |
57 class ImageResource::ImageResourceInfoImpl final | 66 class ImageResource::ImageResourceInfoImpl final |
58 : public GarbageCollectedFinalized<ImageResourceInfoImpl>, | 67 : public GarbageCollectedFinalized<ImageResourceInfoImpl>, |
59 public ImageResourceInfo { | 68 public ImageResourceInfo { |
60 USING_GARBAGE_COLLECTED_MIXIN(ImageResourceInfoImpl); | 69 USING_GARBAGE_COLLECTED_MIXIN(ImageResourceInfoImpl); |
61 | 70 |
62 public: | 71 public: |
63 ImageResourceInfoImpl(ImageResource* resource) : resource_(resource) { | 72 ImageResourceInfoImpl(ImageResource* resource) : resource_(resource) { |
64 DCHECK(resource_); | 73 DCHECK(resource_); |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
442 // Don't treat a complete and broken image as a placeholder if the | 451 // Don't treat a complete and broken image as a placeholder if the |
443 // response code is something other than a 4xx or 5xx error. | 452 // response code is something other than a 4xx or 5xx error. |
444 // This is done to prevent reissuing the request in cases like | 453 // This is done to prevent reissuing the request in cases like |
445 // "204 No Content" responses to tracking requests triggered by <img> | 454 // "204 No Content" responses to tracking requests triggered by <img> |
446 // tags, and <img> tags used to preload non-image resources. | 455 // tags, and <img> tags used to preload non-image resources. |
447 placeholder_option_ = PlaceholderOption::kDoNotReloadPlaceholder; | 456 placeholder_option_ = PlaceholderOption::kDoNotReloadPlaceholder; |
448 } else { | 457 } else { |
449 placeholder_option_ = PlaceholderOption::kReloadPlaceholderOnDecodeError; | 458 placeholder_option_ = PlaceholderOption::kReloadPlaceholderOnDecodeError; |
450 } | 459 } |
451 } | 460 } |
461 | |
462 // Ensure that the PreviewsState bit for Server Lo-Fi is set iff we received | |
463 // the appropriate Server Lo-Fi response headers for this image. | |
464 if (HasServerLoFiResponseHeaders(this->GetResponse())) { | |
megjablon
2017/06/13 19:26:14
Shouldn't this already be set? We wouldn't have go
sclittle
2017/06/13 20:53:23
Normally the bit should be set if we're getting th
megjablon
2017/06/13 21:27:05
Ah ok. Can you add a comment of this effect?
sclittle
2017/06/13 21:42:31
Done.
| |
465 SetPreviewsState(GetResourceRequest().GetPreviewsState() | | |
466 WebURLRequest::kServerLoFiOn); | |
467 } else if (GetResourceRequest().GetPreviewsState() & | |
468 WebURLRequest::kServerLoFiOn) { | |
469 WebURLRequest::PreviewsState new_previews_state = | |
470 GetResourceRequest().GetPreviewsState(); | |
471 | |
472 new_previews_state &= ~WebURLRequest::kServerLoFiOn; | |
473 if (new_previews_state == WebURLRequest::kPreviewsUnspecified) | |
474 new_previews_state = WebURLRequest::kPreviewsOff; | |
475 | |
476 SetPreviewsState(new_previews_state); | |
477 } | |
452 } | 478 } |
453 | 479 |
454 bool ImageResource::ShouldShowPlaceholder() const { | 480 bool ImageResource::ShouldShowPlaceholder() const { |
megjablon
2017/06/13 19:26:14
Is this method only called if you're in the client
sclittle
2017/06/13 20:53:23
It's called by ImageResourceContent::UpdateImage w
megjablon
2017/06/13 21:27:05
Is this approved to roll out for server lo-fi with
sclittle
2017/06/13 21:42:31
Good point - I'll confirm and clarify with server
| |
481 // Show Client Lo-Fi placeholder images in place of Server Lo-Fi | |
482 // responses. This is done so that all Lo-Fi images have a consistent | |
483 // appearance. | |
484 if (GetResourceRequest().GetPreviewsState() & WebURLRequest::kServerLoFiOn) | |
485 return true; | |
486 | |
455 switch (placeholder_option_) { | 487 switch (placeholder_option_) { |
456 case PlaceholderOption::kShowAndReloadPlaceholderAlways: | 488 case PlaceholderOption::kShowAndReloadPlaceholderAlways: |
457 return true; | 489 return true; |
458 case PlaceholderOption::kReloadPlaceholderOnDecodeError: | 490 case PlaceholderOption::kReloadPlaceholderOnDecodeError: |
459 case PlaceholderOption::kDoNotReloadPlaceholder: | 491 case PlaceholderOption::kDoNotReloadPlaceholder: |
460 return false; | 492 return false; |
461 } | 493 } |
462 NOTREACHED(); | 494 NOTREACHED(); |
463 return false; | 495 return false; |
464 } | 496 } |
465 | 497 |
466 bool ImageResource::ShouldReloadBrokenPlaceholder() const { | 498 bool ImageResource::ShouldReloadBrokenPlaceholder() const { |
467 switch (placeholder_option_) { | 499 switch (placeholder_option_) { |
468 case PlaceholderOption::kShowAndReloadPlaceholderAlways: | 500 case PlaceholderOption::kShowAndReloadPlaceholderAlways: |
469 return ErrorOccurred(); | 501 return ErrorOccurred(); |
470 case PlaceholderOption::kReloadPlaceholderOnDecodeError: | 502 case PlaceholderOption::kReloadPlaceholderOnDecodeError: |
471 return GetStatus() == ResourceStatus::kDecodeError; | 503 return GetStatus() == ResourceStatus::kDecodeError; |
472 case PlaceholderOption::kDoNotReloadPlaceholder: | 504 case PlaceholderOption::kDoNotReloadPlaceholder: |
473 return false; | 505 return false; |
474 } | 506 } |
475 NOTREACHED(); | 507 NOTREACHED(); |
476 return false; | 508 return false; |
477 } | 509 } |
478 | 510 |
479 static bool IsLoFiImage(const ImageResource& resource) { | |
480 if (resource.IsLoaded()) { | |
481 return resource.GetResponse() | |
482 .HttpHeaderField("chrome-proxy-content-transform") | |
483 .Contains("empty-image") || | |
484 resource.GetResponse() | |
485 .HttpHeaderField("chrome-proxy") | |
486 .Contains("q=low"); | |
487 } | |
488 return resource.GetResourceRequest().GetPreviewsState() & | |
489 WebURLRequest::kServerLoFiOn; | |
490 } | |
491 | |
492 void ImageResource::ReloadIfLoFiOrPlaceholderImage( | 511 void ImageResource::ReloadIfLoFiOrPlaceholderImage( |
493 ResourceFetcher* fetcher, | 512 ResourceFetcher* fetcher, |
494 ReloadLoFiOrPlaceholderPolicy policy) { | 513 ReloadLoFiOrPlaceholderPolicy policy) { |
495 if (policy == kReloadIfNeeded && !ShouldReloadBrokenPlaceholder()) | 514 if (policy == kReloadIfNeeded && !ShouldReloadBrokenPlaceholder()) |
496 return; | 515 return; |
497 | 516 |
517 DCHECK(!IsLoaded() || | |
518 HasServerLoFiResponseHeaders(GetResponse()) == | |
519 static_cast<bool>(GetResourceRequest().GetPreviewsState() & | |
520 WebURLRequest::kServerLoFiOn)); | |
521 | |
498 if (placeholder_option_ == PlaceholderOption::kDoNotReloadPlaceholder && | 522 if (placeholder_option_ == PlaceholderOption::kDoNotReloadPlaceholder && |
499 !IsLoFiImage(*this)) | 523 !(GetResourceRequest().GetPreviewsState() & WebURLRequest::kServerLoFiOn)) |
500 return; | 524 return; |
501 | 525 |
502 // Prevent clients and observers from being notified of completion while the | 526 // Prevent clients and observers from being notified of completion while the |
503 // reload is being scheduled, so that e.g. canceling an existing load in | 527 // reload is being scheduled, so that e.g. canceling an existing load in |
504 // progress doesn't cause clients and observers to be notified of completion | 528 // progress doesn't cause clients and observers to be notified of completion |
505 // prematurely. | 529 // prematurely. |
506 DCHECK(!is_scheduling_reload_); | 530 DCHECK(!is_scheduling_reload_); |
507 is_scheduling_reload_ = true; | 531 is_scheduling_reload_ = true; |
508 | 532 |
509 SetCachePolicyBypassingCache(); | 533 SetCachePolicyBypassingCache(); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
626 // reloading in Step 3 due to notifyObservers()'s | 650 // reloading in Step 3 due to notifyObservers()'s |
627 // schedulingReloadOrShouldReloadBrokenPlaceholder() check. | 651 // schedulingReloadOrShouldReloadBrokenPlaceholder() check. |
628 // 3. reloadIfLoFiOrPlaceholderImage() is called via ResourceFetcher | 652 // 3. reloadIfLoFiOrPlaceholderImage() is called via ResourceFetcher |
629 // (a) via didFinishLoading() called in decodeError(), or | 653 // (a) via didFinishLoading() called in decodeError(), or |
630 // (b) after returning ImageResource::updateImage(). | 654 // (b) after returning ImageResource::updateImage(). |
631 DecodeError(all_data_received); | 655 DecodeError(all_data_received); |
632 } | 656 } |
633 } | 657 } |
634 | 658 |
635 } // namespace blink | 659 } // namespace blink |
OLD | NEW |