Commit d0a50678 authored by commit-queue@webkit.org's avatar commit-queue@webkit.org
Browse files

Add in-place reload behavior to ImagesEnabled setting

https://bugs.webkit.org/show_bug.cgi?id=95478

.:

Patch by Bo Liu <boliu@chromium.org> on 2012-09-14
Reviewed by Adam Barth.

Export WebCore::Settings::setImagesEnabled symbol.

* Source/autotools/symbols.filter:

Source/WebCore:

Patch by Bo Liu <boliu@chromium.org> on 2012-09-14
Reviewed by Adam Barth.

Store ImagesEnabled setting in CachedResourceLoader similar to
AutoLoadImages. Move FrameLoaderClient::allowImage to after a
CachedImage has been created and store the cache for reload if it is
blocked.

Make sure when image loads are deferred by either ImagesEnabled or
LoadImagesAutomatically, onload is not called.

Added ImagesEnabled to InternalSettings for layout tests.

Tests: fast/loader/display-image-unset-can-block-image-and-can-reload-in-place.html
       fast/loader/images-enabled-unset-can-block-image-and-can-reload-in-place.html

* WebCore.exp.in:
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::didBeginDocument):
* loader/SubresourceLoader.cpp:
(WebCore::SubresourceLoader::willSendRequest):
* loader/cache/CachedImage.cpp:
(WebCore::CachedImage::load):
* loader/cache/CachedImage.h:
* loader/cache/CachedResource.cpp:
(WebCore::CachedResource::didAddClient):
* loader/cache/CachedResource.h:
(WebCore::CachedResource::stillNeedsLoad):
* loader/cache/CachedResourceLoader.cpp:
(WebCore::CachedResourceLoader::CachedResourceLoader):
(WebCore::CachedResourceLoader::requestImage):
(WebCore::CachedResourceLoader::canRequest):
(WebCore::CachedResourceLoader::determineRevalidationPolicy):
(WebCore::CachedResourceLoader::setAutoLoadImages):
(WebCore):
(WebCore::CachedResourceLoader::setImagesEnabled):
(WebCore::CachedResourceLoader::shouldDeferImageLoad):
(WebCore::CachedResourceLoader::reloadImagesIfNotDeferred):
* loader/cache/CachedResourceLoader.h:
(CachedResourceLoader):
(WebCore::CachedResourceLoader::imagesEnabled):
* page/Settings.cpp:
(WebCore::setImageLoadingSettings):
(WebCore::Settings::Settings):
(WebCore::Settings::setLoadsImagesAutomatically):
(WebCore::Settings::imageLoadingSettingsTimerFired):
(WebCore::Settings::setImagesEnabled):
* page/Settings.h:
(Settings):
* testing/InternalSettings.cpp:
(WebCore::InternalSettings::setImagesEnabled):
(WebCore):
* testing/InternalSettings.h:
(InternalSettings):
* testing/InternalSettings.idl:

Source/WebKit2:

Patch by Bo Liu <boliu@chromium.org> on 2012-09-14
Reviewed by Adam Barth.

Export WebCore::Settings::setImagesEnabled symbol.

* win/WebKit2.def:

LayoutTests:

Add tests to check autoLoadImages and imagesEnabled can block
images and can reload them in place when setting is set to unblock.

image-permissions tests are updated to reflect that onerror will no
longer be called when images are blocked.

Patch by Bo Liu <boliu@chromium.org> on 2012-09-14
Reviewed by Adam Barth.

* fast/loader/display-image-unset-can-block-image-and-can-reload-in-place-expected.txt: Added.
* fast/loader/display-image-unset-can-block-image-and-can-reload-in-place.html: Added.
* fast/loader/images-enabled-unset-can-block-image-and-can-reload-in-place-expected.txt: Added.
* fast/loader/images-enabled-unset-can-block-image-and-can-reload-in-place.html: Added.
* platform/chromium/http/tests/permissionclient/image-permissions-expected.txt:
* platform/chromium/permissionclient/image-permissions-expected.txt:
* platform/chromium/permissionclient/image-permissions.html:
* platform/chromium/permissionclient/resources/image.html:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@128645 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 957a0d9b
2012-09-14 Bo Liu <boliu@chromium.org>
Add in-place reload behavior to ImagesEnabled setting
https://bugs.webkit.org/show_bug.cgi?id=95478
Reviewed by Adam Barth.
Export WebCore::Settings::setImagesEnabled symbol.
* Source/autotools/symbols.filter:
2012-09-14 Tor Arne Vestbø <tor.arne.vestbo@nokia.com>
[Qt] Fix handling of debug/release/debug_and_release/build_all
......
2012-09-14 Bo Liu <boliu@chromium.org>
Add in-place reload behavior to ImagesEnabled setting
https://bugs.webkit.org/show_bug.cgi?id=95478
Add tests to check autoLoadImages and imagesEnabled can block
images and can reload them in place when setting is set to unblock.
image-permissions tests are updated to reflect that onerror will no
longer be called when images are blocked.
Reviewed by Adam Barth.
* fast/loader/display-image-unset-can-block-image-and-can-reload-in-place-expected.txt: Added.
* fast/loader/display-image-unset-can-block-image-and-can-reload-in-place.html: Added.
* fast/loader/images-enabled-unset-can-block-image-and-can-reload-in-place-expected.txt: Added.
* fast/loader/images-enabled-unset-can-block-image-and-can-reload-in-place.html: Added.
* platform/chromium/http/tests/permissionclient/image-permissions-expected.txt:
* platform/chromium/permissionclient/image-permissions-expected.txt:
* platform/chromium/permissionclient/image-permissions.html:
* platform/chromium/permissionclient/resources/image.html:
2012-09-14 Emil A Eklund <eae@chromium.org>
 
https://bugs.webkit.org/show_bug.cgi?id=96226
Test that DisplayImages disabled can block http image and can be reloaded in-place when toggled.
SUCCESS
<html>
<head>
<script>
// Setting WebKitDisplayImagesKey is asynchronous, so using queueReload and setInterval to check when the setting actually take effect.
var intervalId;
var imageOnloadFired = 0;
if (window.testRunner) {
testRunner.dumpAsText();
window.internals.settings.setImagesEnabled(true);
testRunner.overridePreference('WebKitDisplayImagesKey', 0);
testRunner.queueReload();
}
function runTest()
{
var image = document.getElementById('image');
if (image.naturalHeight != 0 || image.naturalWidth != 0 || imageOnloadFired != 0) {
document.getElementById('result').innerHTML = 'FAILURE: Image should not be loaded when DisplayImage is unset';
return;
}
testRunner.overridePreference('WebKitDisplayImagesKey', 1);
document.getElementById('result').innerHTML = 'FAILURE: Image should reload in-place when DispalyImage is changes from unset to set';
testRunner.waitUntilDone();
intervalId = window.setInterval(runTestRest, 10);
}
function runTestRest()
{
var image = document.getElementById('image');
if (image.naturalHeight == 33 && image.naturalWidth == 37 && imageOnloadFired == 1) {
document.getElementById('result').innerHTML = 'SUCCESS';
window.clearInterval(intervalId);
testRunner.notifyDone();
}
}
</script>
</head>
<body onload="runTest()">
Test that DisplayImages disabled can block http image and can be reloaded in-place when toggled.
<div id="result">FAILURE: Test script didn't run.</div>
<img id="image" src="../images/resources/oval.png" onload="imageOnloadFired=1;">
</body>
</html>
Test that EnableImages unset can block image and can be reloaded in-place when toggled.
SUCCESS
<html>
<head>
<script>
// Setting ImagesEnabled is asynchronous, so using queueReload and setInterval to check when the setting actually take effect.
var intervalId;
var imageOnloadFired = 0;
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.overridePreference('WebKitDisplayImagesKey', 1);
window.internals.settings.setImagesEnabled(false);
testRunner.queueReload();
}
function runTest()
{
var image = document.getElementById('image');
if (image.naturalHeight != 0 || image.naturalWidth != 0 || imageOnloadFired != 0) {
document.getElementById('result').innerHTML = 'FAILURE: Image should not be loaded when ImagesEnabled is unset';
return;
}
window.internals.settings.setImagesEnabled(true);
document.getElementById('result').innerHTML = 'FAILURE: Image should reload in-place when ImagesEnabled is changes from unset to set';
testRunner.waitUntilDone();
intervalId = window.setInterval(runTestRest, 10);
}
function runTestRest()
{
var image = document.getElementById('image');
if (image.naturalHeight == 33 && image.naturalWidth == 37 || imageOnloadFired == 1) {
document.getElementById('result').innerHTML = 'SUCCESS';
window.clearInterval(intervalId);
testRunner.notifyDone();
}
}
</script>
</head>
<body onload="runTest()">
Test that EnableImages unset can block image and can be reloaded in-place when toggled.
<div id="result">FAILURE: Test script didn't run.</div>
<img id="image" src="../images/resources/oval.png" onload="imageOnloadFired=1;">
</body>
</html>
PERMISSION CLIENT: allowImage(http://127.0.0.1:8000/permissionclient/resources/redir.php?url=http://127.0.0.1:8000/permissionclient/resources/boston.gif): true
PERMISSION CLIENT: allowImage(http://127.0.0.1:8000/permissionclient/resources/redir.php?url=http://127.0.0.1:8000/permissionclient/resources/boston.gif): true
PERMISSION CLIENT: allowImage(http://127.0.0.1:8000/permissionclient/resources/boston.gif): true
This test checks that all URLs in a redirect chain are passed to the PermissionClient.
......
PERMISSION CLIENT: allowImage((file test):platform/chromium/permissionclient/resources/boston.gif): true
PERMISSION CLIENT: allowImage((file test):platform/chromium/permissionclient/resources/boston.gif): true
PERMISSION CLIENT: allowImage((file test):platform/chromium/permissionclient/resources/boston.gif?nocache): false
PERMISSION CLIENT: allowImage((file test):platform/chromium/permissionclient/resources/boston.gif?nocache): false
PERMISSION CLIENT: allowImage((file test):platform/chromium/permissionclient/resources/boston.gif): false
PERMISSION CLIENT: allowImage((file test):platform/chromium/permissionclient/resources/boston.gif): false
PERMISSION CLIENT: allowImage((file test):platform/chromium/permissionclient/resources/boston.gif): false
PERMISSION CLIENT: allowImage((file test):platform/chromium/permissionclient/resources/boston.gif): false
PERMISSION CLIENT: allowImage((file test):platform/chromium/permissionclient/resources/boston.gif): false
PERMISSION CLIENT: allowImage((file test):platform/chromium/permissionclient/resources/boston.gif): false
PASS: first image loaded
PASS: error event for not cached image
PASS: error event for image from cache
<html>
<head>
<script>
// Blocked images can be reloaded, so neither onload nor onerror is called.
// Only check here that onload is never called when image is blocked.
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.dumpPermissionClientCallbacks();
......@@ -21,14 +24,12 @@ function loaded()
// Load an image not in cache.
var img = document.createElement('img');
img.onerror = function () { log("PASS: error event for not cached image"); }
img.onload = function () { log("FAIL: not cached image loaded"); }
img.src = "resources/boston.gif?nocache";
document.getElementById("img").appendChild(img);
// Load an image from cache.
var imgFromCache = document.createElement('img');
imgFromCache.onerror = function () { log("PASS: error event for image from cache"); }
imgFromCache.onload = function () { log("FAIL: image from cache loaded"); }
imgFromCache.src = "resources/boston.gif";
document.getElementById("img").appendChild(imgFromCache);
......@@ -41,7 +42,7 @@ function loaded()
</script>
</head>
<body>
<img src="resources/boston.gif" onload="loaded()" onerror="log('FAIL: error event for first image')">
<img src="resources/boston.gif" onload="loaded()">
<div id="img"></div>
<div id="results"></div>
</body>
......
......@@ -8,7 +8,7 @@ function log(a)
</script>
</head>
<body>
<img src="boston.gif" onload="log('FAIL: load event for iframed image)" onerror="log('FAIL: error event for iframed image')">
<img src="boston.gif" onload="log('FAIL: load event for iframed image')">
<div id="results"></div>
</body>
</html>
2012-09-14 Bo Liu <boliu@chromium.org>
Add in-place reload behavior to ImagesEnabled setting
https://bugs.webkit.org/show_bug.cgi?id=95478
Reviewed by Adam Barth.
Store ImagesEnabled setting in CachedResourceLoader similar to
AutoLoadImages. Move FrameLoaderClient::allowImage to after a
CachedImage has been created and store the cache for reload if it is
blocked.
Make sure when image loads are deferred by either ImagesEnabled or
LoadImagesAutomatically, onload is not called.
Added ImagesEnabled to InternalSettings for layout tests.
Tests: fast/loader/display-image-unset-can-block-image-and-can-reload-in-place.html
fast/loader/images-enabled-unset-can-block-image-and-can-reload-in-place.html
* WebCore.exp.in:
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::didBeginDocument):
* loader/SubresourceLoader.cpp:
(WebCore::SubresourceLoader::willSendRequest):
* loader/cache/CachedImage.cpp:
(WebCore::CachedImage::load):
* loader/cache/CachedImage.h:
* loader/cache/CachedResource.cpp:
(WebCore::CachedResource::didAddClient):
* loader/cache/CachedResource.h:
(WebCore::CachedResource::stillNeedsLoad):
* loader/cache/CachedResourceLoader.cpp:
(WebCore::CachedResourceLoader::CachedResourceLoader):
(WebCore::CachedResourceLoader::requestImage):
(WebCore::CachedResourceLoader::canRequest):
(WebCore::CachedResourceLoader::determineRevalidationPolicy):
(WebCore::CachedResourceLoader::setAutoLoadImages):
(WebCore):
(WebCore::CachedResourceLoader::setImagesEnabled):
(WebCore::CachedResourceLoader::shouldDeferImageLoad):
(WebCore::CachedResourceLoader::reloadImagesIfNotDeferred):
* loader/cache/CachedResourceLoader.h:
(CachedResourceLoader):
(WebCore::CachedResourceLoader::imagesEnabled):
* page/Settings.cpp:
(WebCore::setImageLoadingSettings):
(WebCore::Settings::Settings):
(WebCore::Settings::setLoadsImagesAutomatically):
(WebCore::Settings::imageLoadingSettingsTimerFired):
(WebCore::Settings::setImagesEnabled):
* page/Settings.h:
(Settings):
* testing/InternalSettings.cpp:
(WebCore::InternalSettings::setImagesEnabled):
(WebCore):
* testing/InternalSettings.h:
(InternalSettings):
* testing/InternalSettings.idl:
2012-09-14 Emil A Eklund <eae@chromium.org>
 
https://bugs.webkit.org/show_bug.cgi?id=96226
......@@ -849,6 +849,7 @@ __ZN7WebCore8GradientC1ERKNS_10FloatPointES3_
__ZN7WebCore8PositionC1EN3WTF10PassRefPtrINS_4NodeEEEiNS0_10AnchorTypeE
__ZN7WebCore8Settings14setJavaEnabledEb
__ZN7WebCore8Settings15setWebGLEnabledEb
__ZN7WebCore8Settings16setImagesEnabledEb
__ZN7WebCore8Settings16setScriptEnabledEb
__ZN7WebCore8Settings16setUsesPageCacheEb
__ZN7WebCore8Settings17setPluginsEnabledEb
......
......@@ -647,6 +647,7 @@ void FrameLoader::didBeginDocument(bool dispatch)
m_frame->document()->initContentSecurityPolicy();
Settings* settings = m_frame->document()->settings();
m_frame->document()->cachedResourceLoader()->setImagesEnabled(!settings || settings->areImagesEnabled());
m_frame->document()->cachedResourceLoader()->setAutoLoadImages(settings && settings->loadsImagesAutomatically());
if (m_documentLoader) {
......
......@@ -167,11 +167,13 @@ void SubresourceLoader::willSendRequest(ResourceRequest& newRequest, const Resou
ResourceLoader::willSendRequest(newRequest, redirectResponse);
if (!previousURL.isNull() && !newRequest.isNull() && previousURL != newRequest.url()) {
if (!m_document->cachedResourceLoader()->canRequest(m_resource->type(), newRequest.url())) {
cancel();
return;
if (m_document->cachedResourceLoader()->canRequest(m_resource->type(), newRequest.url())) {
if (m_resource->type() != CachedResource::ImageResource || !m_document->cachedResourceLoader()->shouldDeferImageLoad(newRequest.url())) {
m_resource->willSendRequest(newRequest, redirectResponse);
return;
}
}
m_resource->willSendRequest(newRequest, redirectResponse);
cancel();
}
}
......
......@@ -79,7 +79,7 @@ CachedImage::~CachedImage()
void CachedImage::load(CachedResourceLoader* cachedResourceLoader, const ResourceLoaderOptions& options)
{
if (!cachedResourceLoader || cachedResourceLoader->autoLoadImages())
if (!cachedResourceLoader || !cachedResourceLoader->shouldDeferImageLoad(m_resourceRequest.url()))
CachedResource::load(cachedResourceLoader, options);
else
setLoading(false);
......
......@@ -82,7 +82,7 @@ public:
virtual bool shouldIgnoreHTTPStatusCodeErrors() const { return true; }
virtual bool isImage() const { return true; }
bool stillNeedsLoad() const { return !errorOccurred() && status() == Unknown && !isLoading(); }
virtual bool stillNeedsLoad() const OVERRIDE { return !errorOccurred() && status() == Unknown && !isLoading(); }
void load();
// ImageObserver
......
......@@ -390,7 +390,7 @@ void CachedResource::didAddClient(CachedResourceClient* c)
m_clients.add(c);
m_clientsAwaitingCallback.remove(c);
}
if (!isLoading())
if (!isLoading() && !stillNeedsLoad())
c->notifyFinished(this);
}
......
......@@ -144,6 +144,7 @@ public:
bool isLoading() const { return m_loading; }
void setLoading(bool b) { m_loading = b; }
virtual bool stillNeedsLoad() const { return false; }
SubresourceLoader* loader() { return m_loader.get(); }
......
......@@ -46,6 +46,7 @@
#include "MemoryCache.h"
#include "PingLoader.h"
#include "ResourceLoadScheduler.h"
#include "SchemeRegistry.h"
#include "SecurityOrigin.h"
#include "Settings.h"
#include <wtf/UnusedParam.h>
......@@ -115,6 +116,7 @@ CachedResourceLoader::CachedResourceLoader(Document* document)
, m_requestCount(0)
, m_garbageCollectDocumentResourcesTimer(this, &CachedResourceLoader::garbageCollectDocumentResourcesTimerFired)
, m_autoLoadImages(true)
, m_imagesEnabled(true)
, m_allowStaleResources(false)
{
}
......@@ -160,7 +162,7 @@ CachedResourceHandle<CachedImage> CachedResourceLoader::requestImage(ResourceReq
}
}
CachedResourceHandle<CachedImage> resource(static_cast<CachedImage*>(requestResource(CachedResource::ImageResource, request, String(), defaultCachedResourceOptions()).get()));
if (autoLoadImages() && resource && resource->stillNeedsLoad())
if (!shouldDeferImageLoad(request.url()) && resource && resource->stillNeedsLoad())
resource->load(this, defaultCachedResourceOptions());
return resource;
}
......@@ -362,12 +364,6 @@ bool CachedResourceLoader::canRequest(CachedResource::Type type, const KURL& url
case CachedResource::ImageResource:
if (!m_document->contentSecurityPolicy()->allowImageFromSource(url))
return false;
if (frame()) {
Settings* settings = frame()->settings();
if (!frame()->loader()->client()->allowImage(!settings || settings->areImagesEnabled(), url))
return false;
}
break;
case CachedResource::FontResource: {
if (!m_document->contentSecurityPolicy()->allowFontFromSource(url))
......@@ -514,11 +510,11 @@ CachedResourceLoader::RevalidationPolicy CachedResourceLoader::determineRevalida
{
if (!existingResource)
return Load;
// We already have a preload going for this URL.
if (forPreload && existingResource->isPreloaded())
return Use;
// If the same URL has been loaded as a different type, we need to reload.
if (existingResource->type() != type) {
LOG(ResourceLoading, "CachedResourceLoader::determineRevalidationPolicy reloading due to type mismatch.");
......@@ -533,6 +529,11 @@ CachedResourceLoader::RevalidationPolicy CachedResourceLoader::determineRevalida
// of things about how revalidation works that manual headers violate, so punt to Reload instead.
if (request.isConditional())
return Reload;
// Do not load from cache if images are not enabled. The load for this image will be blocked
// in requestImage.
if (existingResource->type() == CachedResource::ImageResource && shouldDeferImageLoad(existingResource->url()))
return Reload;
// Don't reload resources while pasting.
if (m_allowStaleResources)
......@@ -629,13 +630,39 @@ void CachedResourceLoader::setAutoLoadImages(bool enable)
if (!m_autoLoadImages)
return;
reloadImagesIfNotDeferred();
}
void CachedResourceLoader::setImagesEnabled(bool enable)
{
if (enable == m_imagesEnabled)
return;
m_imagesEnabled = enable;
if (!m_imagesEnabled)
return;
reloadImagesIfNotDeferred();
}
bool CachedResourceLoader::shouldDeferImageLoad(const KURL& url) const
{
if (frame() && !frame()->loader()->client()->allowImage(m_imagesEnabled, url))
return true;
return !m_autoLoadImages;
}
void CachedResourceLoader::reloadImagesIfNotDeferred()
{
DocumentResourceMap::iterator end = m_documentResources.end();
for (DocumentResourceMap::iterator it = m_documentResources.begin(); it != end; ++it) {
CachedResource* resource = it->second.get();
if (resource->type() == CachedResource::ImageResource) {
CachedImage* image = const_cast<CachedImage*>(static_cast<const CachedImage*>(resource));
if (image->stillNeedsLoad())
if (image->stillNeedsLoad() && !shouldDeferImageLoad(image->url()))
image->load(this, defaultCachedResourceOptions());
}
}
......
......@@ -97,6 +97,11 @@ public:
bool autoLoadImages() const { return m_autoLoadImages; }
void setAutoLoadImages(bool);
bool imagesEnabled() const { return m_imagesEnabled; }
void setImagesEnabled(bool);
bool shouldDeferImageLoad(const KURL&) const;
CachePolicy cachePolicy() const;
......@@ -135,6 +140,8 @@ private:
void garbageCollectDocumentResourcesTimerFired(Timer<CachedResourceLoader>*);
void performPostLoadActions();
void reloadImagesIfNotDeferred();
HashSet<String> m_validatedURLs;
mutable DocumentResourceMap m_documentResources;
......@@ -152,8 +159,9 @@ private:
Timer<CachedResourceLoader> m_garbageCollectDocumentResourcesTimer;
// 30 bits left
// 29 bits left
bool m_autoLoadImages : 1;
bool m_imagesEnabled : 1;
bool m_allowStaleResources : 1;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment