Add in-place reload behavior to ImagesEnabled setting
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 14 Sep 2012 20:04:30 +0000 (20:04 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 14 Sep 2012 20:04:30 +0000 (20:04 +0000)
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: https://svn.webkit.org/repository/webkit/trunk@128645 268f45cc-cd09-0410-ab3c-d52691b4dbfc

28 files changed:
ChangeLog
LayoutTests/ChangeLog
LayoutTests/fast/loader/display-image-unset-can-block-image-and-can-reload-in-place-expected.txt [new file with mode: 0644]
LayoutTests/fast/loader/display-image-unset-can-block-image-and-can-reload-in-place.html [new file with mode: 0644]
LayoutTests/fast/loader/images-enabled-unset-can-block-image-and-can-reload-in-place-expected.txt [new file with mode: 0644]
LayoutTests/fast/loader/images-enabled-unset-can-block-image-and-can-reload-in-place.html [new file with mode: 0644]
LayoutTests/platform/chromium/http/tests/permissionclient/image-permissions-expected.txt
LayoutTests/platform/chromium/permissionclient/image-permissions-expected.txt
LayoutTests/platform/chromium/permissionclient/image-permissions.html
LayoutTests/platform/chromium/permissionclient/resources/image.html
Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/loader/FrameLoader.cpp
Source/WebCore/loader/SubresourceLoader.cpp
Source/WebCore/loader/cache/CachedImage.cpp
Source/WebCore/loader/cache/CachedImage.h
Source/WebCore/loader/cache/CachedResource.cpp
Source/WebCore/loader/cache/CachedResource.h
Source/WebCore/loader/cache/CachedResourceLoader.cpp
Source/WebCore/loader/cache/CachedResourceLoader.h
Source/WebCore/page/Settings.cpp
Source/WebCore/page/Settings.h
Source/WebCore/testing/InternalSettings.cpp
Source/WebCore/testing/InternalSettings.h
Source/WebCore/testing/InternalSettings.idl
Source/WebKit2/ChangeLog
Source/WebKit2/win/WebKit2.def
Source/autotools/symbols.filter

index a7d823e..43992c9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+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
index 17d20a0..5cc6a92 100644 (file)
@@ -1,3 +1,25 @@
+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
diff --git a/LayoutTests/fast/loader/display-image-unset-can-block-image-and-can-reload-in-place-expected.txt b/LayoutTests/fast/loader/display-image-unset-can-block-image-and-can-reload-in-place-expected.txt
new file mode 100644 (file)
index 0000000..7a9ef53
--- /dev/null
@@ -0,0 +1,3 @@
+Test that DisplayImages disabled can block http image and can be reloaded in-place when toggled.
+SUCCESS
+
diff --git a/LayoutTests/fast/loader/display-image-unset-can-block-image-and-can-reload-in-place.html b/LayoutTests/fast/loader/display-image-unset-can-block-image-and-can-reload-in-place.html
new file mode 100644 (file)
index 0000000..312f509
--- /dev/null
@@ -0,0 +1,47 @@
+<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>
+
diff --git a/LayoutTests/fast/loader/images-enabled-unset-can-block-image-and-can-reload-in-place-expected.txt b/LayoutTests/fast/loader/images-enabled-unset-can-block-image-and-can-reload-in-place-expected.txt
new file mode 100644 (file)
index 0000000..951d460
--- /dev/null
@@ -0,0 +1,3 @@
+Test that EnableImages unset can block image and can be reloaded in-place when toggled.
+SUCCESS
+
diff --git a/LayoutTests/fast/loader/images-enabled-unset-can-block-image-and-can-reload-in-place.html b/LayoutTests/fast/loader/images-enabled-unset-can-block-image-and-can-reload-in-place.html
new file mode 100644 (file)
index 0000000..3f48e62
--- /dev/null
@@ -0,0 +1,47 @@
+<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>
+
index 5ccac4a..e7caa9a 100644 (file)
@@ -1,4 +1,5 @@
 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.
 
index 60e76a5..181dc81 100644 (file)
@@ -1,10 +1,14 @@
 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
 
index 7b5e2c5..f57a3b7 100644 (file)
@@ -1,6 +1,9 @@
 <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>
index e2adfe3..2397717 100644 (file)
@@ -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>
index e000eef..cc2dfdc 100644 (file)
@@ -1,3 +1,63 @@
+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
index 4069d02..cac3bff 100644 (file)
@@ -849,6 +849,7 @@ __ZN7WebCore8GradientC1ERKNS_10FloatPointES3_
 __ZN7WebCore8PositionC1EN3WTF10PassRefPtrINS_4NodeEEEiNS0_10AnchorTypeE
 __ZN7WebCore8Settings14setJavaEnabledEb
 __ZN7WebCore8Settings15setWebGLEnabledEb
+__ZN7WebCore8Settings16setImagesEnabledEb
 __ZN7WebCore8Settings16setScriptEnabledEb
 __ZN7WebCore8Settings16setUsesPageCacheEb
 __ZN7WebCore8Settings17setPluginsEnabledEb
index 7d2ed49..8473bc3 100644 (file)
@@ -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) {
index 6273a8d..817b0a1 100644 (file)
@@ -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();
     }
 }
 
index 1527a63..85b4a73 100644 (file)
@@ -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);
index 4865c7e..0c452c4 100644 (file)
@@ -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
index 83bc8ee..cbc6525 100755 (executable)
@@ -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);
 }
 
index 0cad3ee..7edafd5 100644 (file)
@@ -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(); }
 
index 5fd7c50..a4a3667 100644 (file)
@@ -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());
         }
     }
index f4755c2..5781130 100644 (file)
@@ -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;
 };
 
index f25150b..7e053f1 100644 (file)
@@ -46,10 +46,12 @@ using namespace std;
 
 namespace WebCore {
 
-static void setLoadsImagesAutomaticallyInAllFrames(Page* page)
+static void setImageLoadingSettings(Page* page)
 {
-    for (Frame* frame = page->mainFrame(); frame; frame = frame->tree()->traverseNext())
+    for (Frame* frame = page->mainFrame(); frame; frame = frame->tree()->traverseNext()) {
+        frame->document()->cachedResourceLoader()->setImagesEnabled(page->settings()->areImagesEnabled());
         frame->document()->cachedResourceLoader()->setAutoLoadImages(page->settings()->loadsImagesAutomatically());
+    }
 }
 
 // Sets the entry in the font map for the given script. If family is the empty string, removes the entry instead.
@@ -286,7 +288,7 @@ Settings::Settings(Page* page)
     , m_windowFocusRestricted(true)
     , m_diagnosticLoggingEnabled(false)
     , m_scrollingPerformanceLoggingEnabled(false)
-    , m_loadsImagesAutomaticallyTimer(this, &Settings::loadsImagesAutomaticallyTimerFired)
+    , m_setImageLoadingSettingsTimer(this, &Settings::imageLoadingSettingsTimerFired)
     , m_incrementalRenderingSuppressionTimeoutInSeconds(defaultIncrementalRenderingSuppressionTimeoutInSeconds)
 {
     // A Frame may not have been created yet, so we initialize the AtomicString
@@ -452,12 +454,12 @@ void Settings::setLoadsImagesAutomatically(bool loadsImagesAutomatically)
     // Starting these loads synchronously is not important.  By putting it on a 0-delay, properly closing the Page cancels them
     // before they have a chance to really start.
     // See http://webkit.org/b/60572 for more discussion.
-    m_loadsImagesAutomaticallyTimer.startOneShot(0);
+    m_setImageLoadingSettingsTimer.startOneShot(0);
 }
 
-void Settings::loadsImagesAutomaticallyTimerFired(Timer<Settings>*)
+void Settings::imageLoadingSettingsTimerFired(Timer<Settings>*)
 {
-    setLoadsImagesAutomaticallyInAllFrames(m_page);
+    setImageLoadingSettings(m_page);
 }
 
 void Settings::setLoadsSiteIconsIgnoringImageLoadingSetting(bool loadsSiteIcons)
@@ -503,6 +505,9 @@ void Settings::setJavaEnabledForLocalFiles(bool isJavaEnabledForLocalFiles)
 void Settings::setImagesEnabled(bool areImagesEnabled)
 {
     m_areImagesEnabled = areImagesEnabled;
+
+    // See comment in setLoadsImagesAutomatically.
+    m_setImageLoadingSettingsTimer.startOneShot(0);
 }
 
 void Settings::setMediaEnabled(bool isMediaEnabled)
index 9681e27..45d1cc1 100644 (file)
@@ -800,8 +800,8 @@ namespace WebCore {
 
         bool m_scrollingPerformanceLoggingEnabled : 1;
 
-        Timer<Settings> m_loadsImagesAutomaticallyTimer;
-        void loadsImagesAutomaticallyTimerFired(Timer<Settings>*);
+        Timer<Settings> m_setImageLoadingSettingsTimer;
+        void imageLoadingSettingsTimerFired(Timer<Settings>*);
         
         double m_incrementalRenderingSuppressionTimeoutInSeconds;
 
index 7108d9c..64ba2ea 100755 (executable)
@@ -102,6 +102,7 @@ InternalSettings::Backup::Backup(Page* page, Settings* settings)
     // FIXME: This is a workaround for Apple Windows crash.
     , m_langAttributeAwareFormControlUIEnabled(RuntimeEnabledFeatures::langAttributeAwareFormControlUIEnabled())
 #endif
+    , m_imagesEnabled(settings->areImagesEnabled())
 {
 }
 
@@ -138,6 +139,7 @@ void InternalSettings::Backup::restoreTo(Page* page, Settings* settings)
 #if ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS)
     RuntimeEnabledFeatures::setLangAttributeAwareFormControlUIEnabled(m_langAttributeAwareFormControlUIEnabled);
 #endif
+    settings->setImagesEnabled(m_imagesEnabled);
 }
 
 InternalSettings* InternalSettings::from(Page* page)
@@ -660,4 +662,10 @@ void InternalSettings::setLangAttributeAwareFormControlUIEnabled(bool enabled)
 #endif
 }
 
+void InternalSettings::setImagesEnabled(bool enabled, ExceptionCode& ec)
+{
+    InternalSettingsGuardForSettings();
+    settings()->setImagesEnabled(enabled);
+}
+
 }
index 2e862b1..c8722a4 100755 (executable)
@@ -83,6 +83,7 @@ public:
 #if ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS)
         bool m_langAttributeAwareFormControlUIEnabled;
 #endif
+        bool m_imagesEnabled;
     };
 
     typedef RefCountedSupplement<Page, InternalSettings> SuperType;
@@ -147,6 +148,8 @@ public:
     void setMemoryInfoEnabled(bool, ExceptionCode&);
     void setStorageBlockingPolicy(const String&, ExceptionCode&);
     void setLangAttributeAwareFormControlUIEnabled(bool);
+    void setImagesEnabled(bool enabled, ExceptionCode&);
+
 private:
     explicit InternalSettings(Page*);
     virtual void hostDestroyed() OVERRIDE { m_page = 0; }
index 8f97f89..c7455fe 100755 (executable)
@@ -81,6 +81,7 @@ module window {
 #endif
         void setMemoryInfoEnabled(in boolean enabled) raises(DOMException);
         void setStorageBlockingPolicy(in DOMString policy) raises(DOMException);
+        void setImagesEnabled(in boolean enabled) raises(DOMException);
     };
 }
 
index d4a5aa4..3343dbc 100644 (file)
@@ -1,3 +1,14 @@
+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.
+
+        * win/WebKit2.def:
+
 2012-09-14  Sudarsana Nagineni  <sudarsana.nagineni@linux.intel.com>
 
         [EFL] RefPtr<Evas_Object> unit tests fails
index aa3bac0..d61288d 100644 (file)
@@ -223,6 +223,7 @@ EXPORTS
         ?setDOMException@WebCore@@YAXPAVExecState@JSC@@H@Z
         ?setFantasyFontFamily@Settings@WebCore@@QAEXABVAtomicString@WTF@@W4UScriptCode@@@Z
         ?setFixedFontFamily@Settings@WebCore@@QAEXABVAtomicString@WTF@@W4UScriptCode@@@Z
+        ?setImagesEnabled@Settings@WebCore@@QAEX_N@Z
         ?setMockScrollbarsEnabled@Settings@WebCore@@SAX_N@Z
         ?mockScrollbarsEnabled@Settings@WebCore@@SA_NXZ
         ?setPageScaleFactor@Page@WebCore@@QAEXMABVIntPoint@2@@Z
index 7fd612b..031cd7f 100644 (file)
@@ -145,6 +145,7 @@ _ZN7WebCore14ScrollableArea28setScrollOffsetFromInternalsERKNS_8IntPointE;
 _ZN7WebCore10ScrollView23setScrollbarsSuppressedEbb;
 _ZN7WebCore10ScrollView21setDelegatesScrollingEb;
 _ZN7WebCore4Node14removedLastRefEv;
+_ZN7WebCore8Settings16setImagesEnabledEb;
 _ZN7WebCore8Settings18setFixedFontFamilyERKN3WTF12AtomicStringE11UScriptCode;
 _ZN7WebCore8Settings18setSerifFontFamilyERKN3WTF12AtomicStringE11UScriptCode;
 _ZN7WebCore8Settings20setCursiveFontFamilyERKN3WTF12AtomicStringE11UScriptCode;