Title: [135872] trunk
Revision
135872
Author
[email protected]
Date
2012-11-27 10:00:58 -0800 (Tue, 27 Nov 2012)

Log Message

Add callbacks to the FrameLoaderClient when a resource is requested
https://bugs.webkit.org/show_bug.cgi?id=92761

Patch by Marja Hölttä <[email protected]> on 2012-11-27
Reviewed by Adam Barth.

In Chromium, when an extension script cancels a network
request (which happens out of process), we'd like to
notify content scripts running on the current page about
which elements failed to load because the requests were
cancelled (as opposed to e.g. the network request just
didn't work). Since the resource request itself does not
carry any information what DOM element is was made for,
currently a content script has to search the DOM tree and
guess which requests will be cancelled by its counter
part. By adding these callbacks, the embedder can make
this connection explictly.

Source/WebCore:

Test: platform/chromium/fast/loader/resource-request-callbacks.html

* loader/FrameLoaderClient.h:
(WebCore):
(WebCore::FrameLoaderClient::dispatchWillRequestResource):
(FrameLoaderClient):
* loader/cache/CachedResourceLoader.cpp:
(WebCore::CachedResourceLoader::requestResource):

Source/WebKit/chromium:

* WebKit.gyp:
* public/WebCachedURLRequest.h: Added.
(WebKit):
(WebCachedURLRequest):
(WebKit::WebCachedURLRequest::~WebCachedURLRequest):
* public/WebFrameClient.h:
(WebKit):
(WebFrameClient):
(WebKit::WebFrameClient::willRequestResource):
* src/FrameLoaderClientImpl.cpp:
(WebKit::FrameLoaderClientImpl::dispatchWillRequestResource):
(WebKit):
* src/FrameLoaderClientImpl.h:
(FrameLoaderClientImpl):
* src/WebCachedURLRequest.cpp: Added.
(WebKit):
(WebKit::WebCachedURLRequest::reset):
(WebKit::WebCachedURLRequest::urlRequest):
(WebKit::WebCachedURLRequest::charset):
(WebKit::WebCachedURLRequest::forPreload):
(WebKit::WebCachedURLRequest::initiatorName):
(WebKit::WebCachedURLRequest::initiatorElement):
(WebKit::WebCachedURLRequest::WebCachedURLRequest):

Tools:

* DumpRenderTree/chromium/DRTTestRunner.cpp:
(DRTTestRunner::DRTTestRunner):
(DRTTestRunner::dumpResourceRequestCallbacks):
(DRTTestRunner::reset):
* DumpRenderTree/chromium/DRTTestRunner.h:
(DRTTestRunner):
(DRTTestRunner::setShouldDumpResourceRequestCallbacks):
(DRTTestRunner::shouldDumpResourceRequestCallbacks):
* DumpRenderTree/chromium/TestShell.h:
(TestShell::shouldDumpResourceRequestCallbacks):
* DumpRenderTree/chromium/WebViewHost.cpp:
(WebViewHost::willRequestResource):
* DumpRenderTree/chromium/WebViewHost.h:
(WebViewHost):

LayoutTests:

* platform/chromium/fast/loader/resource-request-callbacks-expected.txt: Added.
* platform/chromium/fast/loader/resource-request-callbacks.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (135871 => 135872)


--- trunk/LayoutTests/ChangeLog	2012-11-27 17:59:01 UTC (rev 135871)
+++ trunk/LayoutTests/ChangeLog	2012-11-27 18:00:58 UTC (rev 135872)
@@ -1,3 +1,25 @@
+2012-11-27  Marja Hölttä  <[email protected]>
+
+        Add callbacks to the FrameLoaderClient when a resource is requested
+        https://bugs.webkit.org/show_bug.cgi?id=92761
+
+        Reviewed by Adam Barth.
+
+        In Chromium, when an extension script cancels a network
+        request (which happens out of process), we'd like to
+        notify content scripts running on the current page about
+        which elements failed to load because the requests were
+        cancelled (as opposed to e.g. the network request just
+        didn't work). Since the resource request itself does not
+        carry any information what DOM element is was made for,
+        currently a content script has to search the DOM tree and
+        guess which requests will be cancelled by its counter
+        part. By adding these callbacks, the embedder can make
+        this connection explictly.
+
+        * platform/chromium/fast/loader/resource-request-callbacks-expected.txt: Added.
+        * platform/chromium/fast/loader/resource-request-callbacks.html: Added.
+
 2012-11-27  Dan Carney  <[email protected]>
 
         Fix world-reuse test for mac build

Added: trunk/LayoutTests/platform/chromium/fast/loader/resource-request-callbacks-expected.txt (0 => 135872)


--- trunk/LayoutTests/platform/chromium/fast/loader/resource-request-callbacks-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/chromium/fast/loader/resource-request-callbacks-expected.txt	2012-11-27 18:00:58 UTC (rev 135872)
@@ -0,0 +1,21 @@
+main frame - css requested 'gw432047.ttf'
+main frame - css requested 'greenbox-hotspot35-4.cur'
+main frame - element with id 'with-background' requested 'lenna.png'
+main frame - element with id 'img-normal' requested 'dice.png'
+main frame - element with id 'img-changing' requested 'dice.png'
+main frame - element with id 'img-not-there' requested 'not-existing.png'
+main frame - element with no id requested 'js-test-post.js'
+main frame - element with id 'img-changing' requested 'mu.png'
+main frame - element with id 'img-created' requested 'oval.png'
+main frame - element with id 'img-created-2' requested 'png_per_row_alpha.png'
+main frame - element with id 'script-created' requested 'empty-script.js'
+main frame - element with id 'with-background' requested 'palatted-color-png-gamma-one-color-profile.png'
+This test checks that the correct callbacks for resource requests are invoked. It passes if you see the callbacks for eight resources.
+
+    
+
+PASS 
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/platform/chromium/fast/loader/resource-request-callbacks.html (0 => 135872)


--- trunk/LayoutTests/platform/chromium/fast/loader/resource-request-callbacks.html	                        (rev 0)
+++ trunk/LayoutTests/platform/chromium/fast/loader/resource-request-callbacks.html	2012-11-27 18:00:58 UTC (rev 135872)
@@ -0,0 +1,77 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script>
+window.jsTestIsAsync = true;
+if (window.testRunner) {
+    testRunner.dumpAsText();
+    testRunner.dumpResourceRequestCallbacks();
+} else {
+    document.write("This test cannot run without a testRunner");
+}
+
+function requestMoreResources() {
+    document.getElementById("img-changing").src = ""
+
+    var createdImage = document.createElement("img");
+    createdImage.id = "img-created";
+    createdImage.src = ""
+    document.getElementById("images").appendChild(createdImage);
+
+    document.getElementById("with-background").style.backgroundImage = "url(../../../../fast/images/resources/palatted-color-png-gamma-one-color-profile.png)";
+
+    document.getElementById("more-images").innerHTML = "<img id='img-created-2' src=''>";
+
+    var createdScript = document.createElement("script");
+    createdScript.id = "script-created";
+    createdScript.src = ""
+    document.head.appendChild(createdScript);
+
+    setTimeout(finishTest, 0);
+}
+
+function finishTest() {
+    testPassed("");
+    finishJSTest();
+}
+</script>
+<style>
+#with-background
+{
+    background-image:url("../../../../fast/images/resources/lenna.png");
+}
+body
+{
+    cursor:url("../../../../fast/events/resources/greenbox-hotspot35-4.cur"), pointer;
+}
+@font-face
+{
+    font-family: custom_font;
+    src: url("../../../../fast/text/resources/gw432047.ttf");
+}
+p
+{
+    font-family: custom_font;
+}
+</style>
+</head>
+<body _onload_="setTimeout(requestMoreResources, 100);">
+<div id="with-background">
+<p>
+    This test checks that the correct callbacks for resource requests are
+    invoked. It passes if you see the callbacks for eight resources.
+</p>
+</div>
+<div id="images">
+<img id="img-normal" src="" />
+<img id="img-changing" src="" />
+<img id="img-fail" />
+<img id="img-not-there" src="" />
+</div>
+<div id="more-images">
+</div>
+<div id="console"></div>
+<script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (135871 => 135872)


--- trunk/Source/WebCore/ChangeLog	2012-11-27 17:59:01 UTC (rev 135871)
+++ trunk/Source/WebCore/ChangeLog	2012-11-27 18:00:58 UTC (rev 135872)
@@ -1,3 +1,31 @@
+2012-11-27  Marja Hölttä  <[email protected]>
+
+        Add callbacks to the FrameLoaderClient when a resource is requested
+        https://bugs.webkit.org/show_bug.cgi?id=92761
+
+        Reviewed by Adam Barth.
+
+        In Chromium, when an extension script cancels a network
+        request (which happens out of process), we'd like to
+        notify content scripts running on the current page about
+        which elements failed to load because the requests were
+        cancelled (as opposed to e.g. the network request just
+        didn't work). Since the resource request itself does not
+        carry any information what DOM element is was made for,
+        currently a content script has to search the DOM tree and
+        guess which requests will be cancelled by its counter
+        part. By adding these callbacks, the embedder can make
+        this connection explictly.
+
+        Test: platform/chromium/fast/loader/resource-request-callbacks.html
+
+        * loader/FrameLoaderClient.h:
+        (WebCore):
+        (WebCore::FrameLoaderClient::dispatchWillRequestResource):
+        (FrameLoaderClient):
+        * loader/cache/CachedResourceLoader.cpp:
+        (WebCore::CachedResourceLoader::requestResource):
+
 2012-11-27  Dean Jackson  <[email protected]>
 
         Unreviewed build fix for r135866.

Modified: trunk/Source/WebCore/loader/FrameLoaderClient.h (135871 => 135872)


--- trunk/Source/WebCore/loader/FrameLoaderClient.h	2012-11-27 17:59:01 UTC (rev 135871)
+++ trunk/Source/WebCore/loader/FrameLoaderClient.h	2012-11-27 18:00:58 UTC (rev 135872)
@@ -63,6 +63,7 @@
 
     class AuthenticationChallenge;
     class CachedFrame;
+    class CachedResourceRequest;
     class Color;
     class DOMWindowExtension;
     class DOMWrapperWorld;
@@ -179,6 +180,8 @@
 
         virtual void dispatchUnableToImplementPolicy(const ResourceError&) = 0;
 
+        virtual void dispatchWillRequestResource(CachedResourceRequest*) { }
+
         virtual void dispatchWillSendSubmitEvent(PassRefPtr<FormState>) = 0;
         virtual void dispatchWillSubmitForm(FramePolicyFunction, PassRefPtr<FormState>) = 0;
 

Modified: trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp (135871 => 135872)


--- trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp	2012-11-27 17:59:01 UTC (rev 135871)
+++ trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp	2012-11-27 18:00:58 UTC (rev 135872)
@@ -423,6 +423,9 @@
     if (!canRequest(type, url, request.forPreload()))
         return 0;
 
+    if (Frame* f = frame())
+        f->loader()->client()->dispatchWillRequestResource(&request);
+
     if (memoryCache()->disabled()) {
         DocumentResourceMap::iterator it = m_documentResources.find(url.string());
         if (it != m_documentResources.end()) {

Modified: trunk/Source/WebKit/chromium/ChangeLog (135871 => 135872)


--- trunk/Source/WebKit/chromium/ChangeLog	2012-11-27 17:59:01 UTC (rev 135871)
+++ trunk/Source/WebKit/chromium/ChangeLog	2012-11-27 18:00:58 UTC (rev 135872)
@@ -1,3 +1,46 @@
+2012-11-27  Marja Hölttä  <[email protected]>
+
+        Add callbacks to the FrameLoaderClient when a resource is requested
+        https://bugs.webkit.org/show_bug.cgi?id=92761
+
+        Reviewed by Adam Barth.
+
+        In Chromium, when an extension script cancels a network
+        request (which happens out of process), we'd like to
+        notify content scripts running on the current page about
+        which elements failed to load because the requests were
+        cancelled (as opposed to e.g. the network request just
+        didn't work). Since the resource request itself does not
+        carry any information what DOM element is was made for,
+        currently a content script has to search the DOM tree and
+        guess which requests will be cancelled by its counter
+        part. By adding these callbacks, the embedder can make
+        this connection explictly.
+
+        * WebKit.gyp:
+        * public/WebCachedURLRequest.h: Added.
+        (WebKit):
+        (WebCachedURLRequest):
+        (WebKit::WebCachedURLRequest::~WebCachedURLRequest):
+        * public/WebFrameClient.h:
+        (WebKit):
+        (WebFrameClient):
+        (WebKit::WebFrameClient::willRequestResource):
+        * src/FrameLoaderClientImpl.cpp:
+        (WebKit::FrameLoaderClientImpl::dispatchWillRequestResource):
+        (WebKit):
+        * src/FrameLoaderClientImpl.h:
+        (FrameLoaderClientImpl):
+        * src/WebCachedURLRequest.cpp: Added.
+        (WebKit):
+        (WebKit::WebCachedURLRequest::reset):
+        (WebKit::WebCachedURLRequest::urlRequest):
+        (WebKit::WebCachedURLRequest::charset):
+        (WebKit::WebCachedURLRequest::forPreload):
+        (WebKit::WebCachedURLRequest::initiatorName):
+        (WebKit::WebCachedURLRequest::initiatorElement):
+        (WebKit::WebCachedURLRequest::WebCachedURLRequest):
+
 2012-11-27  Keishi Hattori  <[email protected]>
 
         Add WebLocalizedString for validation type badinput

Modified: trunk/Source/WebKit/chromium/WebKit.gyp (135871 => 135872)


--- trunk/Source/WebKit/chromium/WebKit.gyp	2012-11-27 17:59:01 UTC (rev 135871)
+++ trunk/Source/WebKit/chromium/WebKit.gyp	2012-11-27 18:00:58 UTC (rev 135872)
@@ -108,6 +108,7 @@
                 'public/WebBindings.h',
                 'public/WebBlob.h',
                 'public/WebCache.h',
+                'public/WebCachedURLRequest.h',
                 'public/WebColorChooser.h',
                 'public/WebColorChooserClient.h',
                 'public/WebColorName.h',
@@ -491,6 +492,7 @@
                 'src/WebBlob.cpp',
                 'src/WebBlobData.cpp',
                 'src/WebCache.cpp',
+                'src/WebCachedURLRequest.cpp',
                 'src/WebColorName.cpp',
                 'src/WebCommon.cpp',
                 'src/WebCompositorInputHandlerImpl.cpp',

Added: trunk/Source/WebKit/chromium/public/WebCachedURLRequest.h (0 => 135872)


--- trunk/Source/WebKit/chromium/public/WebCachedURLRequest.h	                        (rev 0)
+++ trunk/Source/WebKit/chromium/public/WebCachedURLRequest.h	2012-11-27 18:00:58 UTC (rev 135872)
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebCachedURLRequest_h
+#define WebCachedURLRequest_h
+
+#include "WebElement.h"
+#include "platform/WebCommon.h"
+#include "platform/WebPrivateOwnPtr.h"
+#include "platform/WebString.h"
+
+namespace WebCore { class CachedResourceRequest; }
+
+namespace WebKit {
+
+class WebElement;
+class WebString;
+class WebURLRequest;
+class WrappedResourceRequest;
+
+class WebCachedURLRequest {
+public:
+    ~WebCachedURLRequest() { reset(); }
+    WEBKIT_EXPORT void reset();
+
+    WEBKIT_EXPORT const WebURLRequest& urlRequest() const;
+    WEBKIT_EXPORT WebString charset() const;
+    WEBKIT_EXPORT bool forPreload() const;
+    WEBKIT_EXPORT WebString initiatorName() const;
+    WEBKIT_EXPORT WebElement initiatorElement() const;
+
+#if WEBKIT_IMPLEMENTATION
+    explicit WebCachedURLRequest(WebCore::CachedResourceRequest*);
+#endif
+
+private:
+    WebCachedURLRequest(const WebCachedURLRequest&);
+    WebCachedURLRequest& operator=(const WebCachedURLRequest&);
+
+    WebCore::CachedResourceRequest* m_private;
+    mutable WebPrivateOwnPtr<WrappedResourceRequest> m_resourceRequestWrapper;
+};
+
+} // namespace WebKit
+
+#endif

Modified: trunk/Source/WebKit/chromium/public/WebFrameClient.h (135871 => 135872)


--- trunk/Source/WebKit/chromium/public/WebFrameClient.h	2012-11-27 17:59:01 UTC (rev 135871)
+++ trunk/Source/WebKit/chromium/public/WebFrameClient.h	2012-11-27 18:00:58 UTC (rev 135872)
@@ -50,6 +50,7 @@
 
 class WebApplicationCacheHost;
 class WebApplicationCacheHostClient;
+class WebCachedURLRequest;
 class WebCookieJar;
 class WebDataSource;
 class WebDOMEvent;
@@ -251,6 +252,9 @@
      // the client keeps such an association.
      virtual void removeIdentifierForRequest(unsigned identifier) { }
 
+    // An element will request a resource.
+    virtual void willRequestResource(WebFrame*, const WebCachedURLRequest&) { }
+
     // A request is about to be sent out, and the client may modify it.  Request
     // is writable, and changes to the URL, for example, will change the request
     // made.  If this request is the result of a redirect, then redirectResponse

Modified: trunk/Source/WebKit/chromium/src/FrameLoaderClientImpl.cpp (135871 => 135872)


--- trunk/Source/WebKit/chromium/src/FrameLoaderClientImpl.cpp	2012-11-27 17:59:01 UTC (rev 135871)
+++ trunk/Source/WebKit/chromium/src/FrameLoaderClientImpl.cpp	2012-11-27 18:00:58 UTC (rev 135872)
@@ -65,6 +65,7 @@
 #if ENABLE(REQUEST_AUTOCOMPLETE)
 #include "WebAutofillClient.h"
 #endif
+#include "WebCachedURLRequest.h"
 #include "WebDOMEvent.h"
 #include "WebDataSourceImpl.h"
 #include "WebDevToolsAgentPrivate.h"
@@ -1048,6 +1049,12 @@
     m_webFrame->client()->unableToImplementPolicyWithError(m_webFrame, error);
 }
 
+void FrameLoaderClientImpl::dispatchWillRequestResource(CachedResourceRequest* request)
+{
+    if (m_webFrame->client())
+        m_webFrame->client()->willRequestResource(m_webFrame, WebCachedURLRequest(request));
+}
+
 void FrameLoaderClientImpl::dispatchWillSendSubmitEvent(PassRefPtr<FormState> prpFormState)
 {
     if (m_webFrame->client())

Modified: trunk/Source/WebKit/chromium/src/FrameLoaderClientImpl.h (135871 => 135872)


--- trunk/Source/WebKit/chromium/src/FrameLoaderClientImpl.h	2012-11-27 17:59:01 UTC (rev 135871)
+++ trunk/Source/WebKit/chromium/src/FrameLoaderClientImpl.h	2012-11-27 18:00:58 UTC (rev 135872)
@@ -118,6 +118,7 @@
     virtual void dispatchDecidePolicyForNavigationAction(WebCore::FramePolicyFunction function, const WebCore::NavigationAction& action, const WebCore::ResourceRequest& request, PassRefPtr<WebCore::FormState> form_state);
     virtual void cancelPolicyCheck();
     virtual void dispatchUnableToImplementPolicy(const WebCore::ResourceError&);
+    virtual void dispatchWillRequestResource(WebCore::CachedResourceRequest*);
     virtual void dispatchWillSendSubmitEvent(PassRefPtr<WebCore::FormState>);
     virtual void dispatchWillSubmitForm(WebCore::FramePolicyFunction, PassRefPtr<WebCore::FormState>);
     virtual void revertToProvisionalState(WebCore::DocumentLoader*) { }

Added: trunk/Source/WebKit/chromium/src/WebCachedURLRequest.cpp (0 => 135872)


--- trunk/Source/WebKit/chromium/src/WebCachedURLRequest.cpp	                        (rev 0)
+++ trunk/Source/WebKit/chromium/src/WebCachedURLRequest.cpp	2012-11-27 18:00:58 UTC (rev 135872)
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebCachedURLRequest.h"
+
+#include "CachedResourceRequest.h"
+#include "Element.h"
+#include "WrappedResourceRequest.h"
+#include <public/WebURLRequest.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+void WebCachedURLRequest::reset()
+{
+    m_resourceRequestWrapper.reset(0);
+    m_private = 0;
+}
+
+const WebURLRequest& WebCachedURLRequest::urlRequest() const
+{
+    if (!m_resourceRequestWrapper.get())
+        m_resourceRequestWrapper.reset(new WrappedResourceRequest(m_private->resourceRequest()));
+    else
+        m_resourceRequestWrapper->bind(m_private->resourceRequest());
+    return *m_resourceRequestWrapper.get();
+}
+
+WebString WebCachedURLRequest::charset() const
+{
+    return WebString(m_private->charset());
+}
+
+bool WebCachedURLRequest::forPreload() const
+{
+    return m_private->forPreload();
+}
+
+WebString WebCachedURLRequest::initiatorName() const
+{
+    return WebString(m_private->initiatorName());
+}
+
+WebElement WebCachedURLRequest::initiatorElement() const
+{
+    return WebElement(m_private->initiatorElement());
+}
+
+WebCachedURLRequest::WebCachedURLRequest(CachedResourceRequest* request)
+    : m_private(request)
+{
+}
+
+} // namespace WebKit

Modified: trunk/Tools/ChangeLog (135871 => 135872)


--- trunk/Tools/ChangeLog	2012-11-27 17:59:01 UTC (rev 135871)
+++ trunk/Tools/ChangeLog	2012-11-27 18:00:58 UTC (rev 135872)
@@ -1,3 +1,37 @@
+2012-11-27  Marja Hölttä  <[email protected]>
+
+        Add callbacks to the FrameLoaderClient when a resource is requested
+        https://bugs.webkit.org/show_bug.cgi?id=92761
+
+        Reviewed by Adam Barth.
+
+        In Chromium, when an extension script cancels a network
+        request (which happens out of process), we'd like to
+        notify content scripts running on the current page about
+        which elements failed to load because the requests were
+        cancelled (as opposed to e.g. the network request just
+        didn't work). Since the resource request itself does not
+        carry any information what DOM element is was made for,
+        currently a content script has to search the DOM tree and
+        guess which requests will be cancelled by its counter
+        part. By adding these callbacks, the embedder can make
+        this connection explictly.
+
+        * DumpRenderTree/chromium/DRTTestRunner.cpp:
+        (DRTTestRunner::DRTTestRunner):
+        (DRTTestRunner::dumpResourceRequestCallbacks):
+        (DRTTestRunner::reset):
+        * DumpRenderTree/chromium/DRTTestRunner.h:
+        (DRTTestRunner):
+        (DRTTestRunner::setShouldDumpResourceRequestCallbacks):
+        (DRTTestRunner::shouldDumpResourceRequestCallbacks):
+        * DumpRenderTree/chromium/TestShell.h:
+        (TestShell::shouldDumpResourceRequestCallbacks):
+        * DumpRenderTree/chromium/WebViewHost.cpp:
+        (WebViewHost::willRequestResource):
+        * DumpRenderTree/chromium/WebViewHost.h:
+        (WebViewHost):
+
 2012-11-27  Víctor Manuel Jáquez Leal  <[email protected]>
 
         [GStreamer] Verify if GStreamer was previously initialized

Modified: trunk/Tools/DumpRenderTree/chromium/DRTTestRunner.cpp (135871 => 135872)


--- trunk/Tools/DumpRenderTree/chromium/DRTTestRunner.cpp	2012-11-27 17:59:01 UTC (rev 135871)
+++ trunk/Tools/DumpRenderTree/chromium/DRTTestRunner.cpp	2012-11-27 18:00:58 UTC (rev 135872)
@@ -139,6 +139,7 @@
     bindMethod("dumpProgressFinishedCallback", &DRTTestRunner::dumpProgressFinishedCallback);
     bindMethod("dumpUserGestureInFrameLoadCallbacks", &DRTTestRunner::dumpUserGestureInFrameLoadCallbacks);
     bindMethod("dumpResourceLoadCallbacks", &DRTTestRunner::dumpResourceLoadCallbacks);
+    bindMethod("dumpResourceRequestCallbacks", &DRTTestRunner::dumpResourceRequestCallbacks);
     bindMethod("dumpResourceResponseMIMETypes", &DRTTestRunner::dumpResourceResponseMIMETypes);
     bindMethod("dumpSelectionRect", &DRTTestRunner::dumpSelectionRect);
     bindMethod("dumpStatusCallbacks", &DRTTestRunner::dumpWindowStatusChanges);
@@ -322,6 +323,12 @@
     result->setNull();
 }
 
+void DRTTestRunner::dumpResourceRequestCallbacks(const CppArgumentList&, CppVariant* result)
+{
+    m_dumpResourceRequestCallbacks = true;
+    result->setNull();
+}
+
 void DRTTestRunner::dumpResourceResponseMIMETypes(const CppArgumentList&, CppVariant* result)
 {
     m_dumpResourceResponseMIMETypes = true;
@@ -556,6 +563,7 @@
     m_dumpProgressFinishedCallback = false;
     m_dumpUserGestureInFrameLoadCallbacks = false;
     m_dumpResourceLoadCallbacks = false;
+    m_dumpResourceRequestCallbacks = false;
     m_dumpResourceResponseMIMETypes = false;
     m_dumpBackForwardList = false;
     m_dumpChildFrameScrollPositions = false;

Modified: trunk/Tools/DumpRenderTree/chromium/DRTTestRunner.h (135871 => 135872)


--- trunk/Tools/DumpRenderTree/chromium/DRTTestRunner.h	2012-11-27 17:59:01 UTC (rev 135871)
+++ trunk/Tools/DumpRenderTree/chromium/DRTTestRunner.h	2012-11-27 18:00:58 UTC (rev 135872)
@@ -116,7 +116,12 @@
     // line for each resource load callback. It takes no arguments, and ignores
     // any that may be present.
     void dumpResourceLoadCallbacks(const CppArgumentList&, CppVariant*);    
-    
+
+    // This function sets a flag that tells the test_shell to print a line of
+    // descriptive text for each element that requested a resource. It takes no
+    // arguments, and ignores any that may be present.
+    void dumpResourceRequestCallbacks(const CppArgumentList&, CppVariant*);
+
     // This function sets a flag that tells the test_shell to dump the MIME type
     // for each resource that was loaded. It takes no arguments, and ignores any
     // that may be present.
@@ -318,6 +323,8 @@
     bool shouldDumpUserGestureInFrameLoadCallbacks() { return m_dumpUserGestureInFrameLoadCallbacks; }
     void setShouldDumpUserGestureInFrameLoadCallbacks(bool value) { m_dumpUserGestureInFrameLoadCallbacks = value; }
     bool shouldDumpResourceLoadCallbacks() {return m_dumpResourceLoadCallbacks; }
+    void setShouldDumpResourceRequestCallbacks(bool value) { m_dumpResourceRequestCallbacks = value; }
+    bool shouldDumpResourceRequestCallbacks() { return m_dumpResourceRequestCallbacks; }
     void setShouldDumpResourceResponseMIMETypes(bool value) { m_dumpResourceResponseMIMETypes = value; }
     bool shouldDumpResourceResponseMIMETypes() {return m_dumpResourceResponseMIMETypes; }
     bool shouldDumpStatusCallbacks() { return m_dumpWindowStatusChanges; }
@@ -451,7 +458,11 @@
     // If true, the test_shell will output a descriptive line for each resource
     // load callback.
     bool m_dumpResourceLoadCallbacks;
-    
+
+    // If true, the test_shell will output a descriptive line for each resource
+    // request callback.
+    bool m_dumpResourceRequestCallbacks;
+
     // If true, the test_shell will output the MIME type for each resource that 
     // was loaded.
     bool m_dumpResourceResponseMIMETypes;

Modified: trunk/Tools/DumpRenderTree/chromium/TestShell.h (135871 => 135872)


--- trunk/Tools/DumpRenderTree/chromium/TestShell.h	2012-11-27 17:59:01 UTC (rev 135871)
+++ trunk/Tools/DumpRenderTree/chromium/TestShell.h	2012-11-27 18:00:58 UTC (rev 135872)
@@ -112,6 +112,7 @@
 
     void setFocus(WebKit::WebWidget*, bool enable);
     bool shouldDumpFrameLoadCallbacks() const { return (m_testIsPreparing || m_testIsPending) && testRunner()->shouldDumpFrameLoadCallbacks(); }
+    bool shouldDumpResourceRequestCallbacks() const { return (m_testIsPreparing || m_testIsPending) && testRunner()->shouldDumpResourceRequestCallbacks(); }
     bool shouldDumpUserGestureInFrameLoadCallbacks() const { return (m_testIsPreparing || m_testIsPending) && testRunner()->shouldDumpUserGestureInFrameLoadCallbacks(); }
     bool shouldDumpResourceLoadCallbacks() const  { return (m_testIsPreparing || m_testIsPending) && testRunner()->shouldDumpResourceLoadCallbacks(); }
     bool shouldDumpResourceResponseMIMETypes() const  { return (m_testIsPreparing || m_testIsPending) && testRunner()->shouldDumpResourceResponseMIMETypes(); }

Modified: trunk/Tools/DumpRenderTree/chromium/WebViewHost.cpp (135871 => 135872)


--- trunk/Tools/DumpRenderTree/chromium/WebViewHost.cpp	2012-11-27 17:59:01 UTC (rev 135871)
+++ trunk/Tools/DumpRenderTree/chromium/WebViewHost.cpp	2012-11-27 18:00:58 UTC (rev 135872)
@@ -39,6 +39,7 @@
 #include "TestNavigationController.h"
 #include "TestShell.h"
 #include "TestWebPlugin.h"
+#include "WebCachedURLRequest.h"
 #include "WebConsoleMessage.h"
 #include "WebContextMenuData.h"
 #include "WebDOMMessageEvent.h"
@@ -1139,6 +1140,23 @@
     return host == "255.255.255.255";
 }
 
+void WebViewHost::willRequestResource(WebKit::WebFrame* frame, const WebKit::WebCachedURLRequest& request)
+{
+    if (m_shell->shouldDumpResourceRequestCallbacks()) {
+        printFrameDescription(frame);
+        WebElement element = request.initiatorElement();
+        if (!element.isNull()) {
+            printf(" - element with ");
+            if (element.hasAttribute("id"))
+                printf("id '%s'", element.getAttribute("id").utf8().data());
+            else
+                printf("no id");
+        } else
+            printf(" - %s", request.initiatorName().utf8().data());
+        printf(" requested '%s'\n", URLDescription(request.urlRequest().url()).c_str());
+    }
+}
+
 void WebViewHost::willSendRequest(WebFrame* frame, unsigned identifier, WebURLRequest& request, const WebURLResponse& redirectResponse)
 {
     // Need to use GURL for host() and SchemeIs()

Modified: trunk/Tools/DumpRenderTree/chromium/WebViewHost.h (135871 => 135872)


--- trunk/Tools/DumpRenderTree/chromium/WebViewHost.h	2012-11-27 17:59:01 UTC (rev 135871)
+++ trunk/Tools/DumpRenderTree/chromium/WebViewHost.h	2012-11-27 18:00:58 UTC (rev 135872)
@@ -260,6 +260,7 @@
     virtual void didChangeLocationWithinPage(WebKit::WebFrame*);
     virtual void assignIdentifierToRequest(WebKit::WebFrame*, unsigned identifier, const WebKit::WebURLRequest&);
     virtual void removeIdentifierForRequest(unsigned identifier);
+    virtual void willRequestResource(WebKit::WebFrame*, const WebKit::WebCachedURLRequest&);
     virtual void willSendRequest(WebKit::WebFrame*, unsigned identifier, WebKit::WebURLRequest&, const WebKit::WebURLResponse&);
     virtual void didReceiveResponse(WebKit::WebFrame*, unsigned identifier, const WebKit::WebURLResponse&);
     virtual void didFinishResourceLoad(WebKit::WebFrame*, unsigned identifier);
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to